Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2010, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | #define LOG_TAG "Visualizer" |
| 21 | #include <utils/Log.h> |
| 22 | |
| 23 | #include <stdint.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <limits.h> |
| 26 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 27 | #include <cutils/bitops.h> |
| 28 | |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 29 | #include <media/Visualizer.h> |
Glenn Kasten | 3f6448e | 2012-01-16 13:11:50 -0800 | [diff] [blame] | 30 | #include <audio_utils/fixedfft.h> |
Glenn Kasten | 1ab85ec | 2013-05-31 09:18:43 -0700 | [diff] [blame] | 31 | #include <utils/Thread.h> |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | // --------------------------------------------------------------------------- |
| 36 | |
Svet Ganov | be71aa2 | 2015-04-28 12:06:02 -0700 | [diff] [blame] | 37 | Visualizer::Visualizer (const String16& opPackageName, |
| 38 | int32_t priority, |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 39 | effect_callback_t cbf, |
| 40 | void* user, |
| 41 | int sessionId) |
Svet Ganov | be71aa2 | 2015-04-28 12:06:02 -0700 | [diff] [blame] | 42 | : AudioEffect(SL_IID_VISUALIZATION, opPackageName, NULL, priority, cbf, user, sessionId), |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 43 | mCaptureRate(CAPTURE_RATE_DEF), |
| 44 | mCaptureSize(CAPTURE_SIZE_DEF), |
| 45 | mSampleRate(44100000), |
Jean-Michel Trivi | 3476de6 | 2012-04-15 17:15:07 -0700 | [diff] [blame] | 46 | mScalingMode(VISUALIZER_SCALING_MODE_NORMALIZED), |
Jean-Michel Trivi | 09647d2 | 2013-09-20 11:58:40 -0700 | [diff] [blame] | 47 | mMeasurementMode(MEASUREMENT_MODE_NONE), |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 48 | mCaptureCallBack(NULL), |
| 49 | mCaptureCbkUser(NULL) |
| 50 | { |
| 51 | initCaptureSize(); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | Visualizer::~Visualizer() |
| 55 | { |
Haynes Mathew George | 63f6ffb | 2014-09-25 10:33:12 -0700 | [diff] [blame] | 56 | ALOGV("Visualizer::~Visualizer()"); |
Ricardo Garcia | 9b030df | 2015-06-18 21:01:53 -0700 | [diff] [blame] | 57 | setEnabled(false); |
| 58 | setCaptureCallBack(NULL, NULL, 0, 0, true); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | status_t Visualizer::setEnabled(bool enabled) |
| 62 | { |
Glenn Kasten | a9b21c5 | 2012-01-17 10:06:38 -0800 | [diff] [blame] | 63 | Mutex::Autolock _l(mCaptureLock); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 64 | |
| 65 | sp<CaptureThread> t = mCaptureThread; |
| 66 | if (t != 0) { |
| 67 | if (enabled) { |
| 68 | if (t->exitPending()) { |
| 69 | if (t->requestExitAndWait() == WOULD_BLOCK) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 70 | ALOGE("Visualizer::enable() called from thread"); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 71 | return INVALID_OPERATION; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | t->mLock.lock(); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 76 | } |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 77 | |
| 78 | status_t status = AudioEffect::setEnabled(enabled); |
| 79 | |
| 80 | if (status == NO_ERROR) { |
| 81 | if (t != 0) { |
| 82 | if (enabled) { |
Glenn Kasten | 9096f34 | 2012-01-19 08:14:08 -0800 | [diff] [blame] | 83 | t->run("Visualizer"); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 84 | } else { |
| 85 | t->requestExit(); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | if (t != 0) { |
| 91 | t->mLock.unlock(); |
| 92 | } |
| 93 | |
| 94 | return status; |
| 95 | } |
| 96 | |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 97 | status_t Visualizer::setCaptureCallBack(capture_cbk_t cbk, void* user, uint32_t flags, |
Ricardo Garcia | 9b030df | 2015-06-18 21:01:53 -0700 | [diff] [blame] | 98 | uint32_t rate, bool force) |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 99 | { |
| 100 | if (rate > CAPTURE_RATE_MAX) { |
| 101 | return BAD_VALUE; |
| 102 | } |
Glenn Kasten | a9b21c5 | 2012-01-17 10:06:38 -0800 | [diff] [blame] | 103 | Mutex::Autolock _l(mCaptureLock); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 104 | |
Ricardo Garcia | 9b030df | 2015-06-18 21:01:53 -0700 | [diff] [blame] | 105 | if (force || mEnabled) { |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 106 | return INVALID_OPERATION; |
| 107 | } |
| 108 | |
Haynes Mathew George | 63f6ffb | 2014-09-25 10:33:12 -0700 | [diff] [blame] | 109 | if (mCaptureThread != 0) { |
| 110 | mCaptureLock.unlock(); |
| 111 | mCaptureThread->requestExitAndWait(); |
| 112 | mCaptureLock.lock(); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 113 | } |
Haynes Mathew George | 63f6ffb | 2014-09-25 10:33:12 -0700 | [diff] [blame] | 114 | |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 115 | mCaptureThread.clear(); |
| 116 | mCaptureCallBack = cbk; |
| 117 | mCaptureCbkUser = user; |
| 118 | mCaptureFlags = flags; |
| 119 | mCaptureRate = rate; |
| 120 | |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 121 | if (cbk != NULL) { |
| 122 | mCaptureThread = new CaptureThread(*this, rate, ((flags & CAPTURE_CALL_JAVA) != 0)); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 123 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 124 | ALOGV("setCaptureCallBack() rate: %d thread %p flags 0x%08x", |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 125 | rate, mCaptureThread.get(), mCaptureFlags); |
| 126 | return NO_ERROR; |
| 127 | } |
| 128 | |
| 129 | status_t Visualizer::setCaptureSize(uint32_t size) |
| 130 | { |
| 131 | if (size > VISUALIZER_CAPTURE_SIZE_MAX || |
| 132 | size < VISUALIZER_CAPTURE_SIZE_MIN || |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 133 | popcount(size) != 1) { |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 134 | return BAD_VALUE; |
| 135 | } |
| 136 | |
Glenn Kasten | a9b21c5 | 2012-01-17 10:06:38 -0800 | [diff] [blame] | 137 | Mutex::Autolock _l(mCaptureLock); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 138 | if (mEnabled) { |
| 139 | return INVALID_OPERATION; |
| 140 | } |
| 141 | |
| 142 | uint32_t buf32[sizeof(effect_param_t) / sizeof(uint32_t) + 2]; |
| 143 | effect_param_t *p = (effect_param_t *)buf32; |
| 144 | |
| 145 | p->psize = sizeof(uint32_t); |
| 146 | p->vsize = sizeof(uint32_t); |
Eric Laurent | 6d8b694 | 2011-06-24 07:01:31 -0700 | [diff] [blame] | 147 | *(int32_t *)p->data = VISUALIZER_PARAM_CAPTURE_SIZE; |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 148 | *((int32_t *)p->data + 1)= size; |
| 149 | status_t status = setParameter(p); |
| 150 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 151 | ALOGV("setCaptureSize size %d status %d p->status %d", size, status, p->status); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 152 | |
| 153 | if (status == NO_ERROR) { |
| 154 | status = p->status; |
Jean-Michel Trivi | 3476de6 | 2012-04-15 17:15:07 -0700 | [diff] [blame] | 155 | if (status == NO_ERROR) { |
| 156 | mCaptureSize = size; |
| 157 | } |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 158 | } |
Jean-Michel Trivi | 3476de6 | 2012-04-15 17:15:07 -0700 | [diff] [blame] | 159 | |
| 160 | return status; |
| 161 | } |
| 162 | |
| 163 | status_t Visualizer::setScalingMode(uint32_t mode) { |
| 164 | if ((mode != VISUALIZER_SCALING_MODE_NORMALIZED) |
| 165 | && (mode != VISUALIZER_SCALING_MODE_AS_PLAYED)) { |
| 166 | return BAD_VALUE; |
| 167 | } |
| 168 | |
| 169 | Mutex::Autolock _l(mCaptureLock); |
| 170 | |
| 171 | uint32_t buf32[sizeof(effect_param_t) / sizeof(uint32_t) + 2]; |
| 172 | effect_param_t *p = (effect_param_t *)buf32; |
| 173 | |
| 174 | p->psize = sizeof(uint32_t); |
| 175 | p->vsize = sizeof(uint32_t); |
| 176 | *(int32_t *)p->data = VISUALIZER_PARAM_SCALING_MODE; |
| 177 | *((int32_t *)p->data + 1)= mode; |
| 178 | status_t status = setParameter(p); |
| 179 | |
| 180 | ALOGV("setScalingMode mode %d status %d p->status %d", mode, status, p->status); |
| 181 | |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 182 | if (status == NO_ERROR) { |
Jean-Michel Trivi | 3476de6 | 2012-04-15 17:15:07 -0700 | [diff] [blame] | 183 | status = p->status; |
| 184 | if (status == NO_ERROR) { |
| 185 | mScalingMode = mode; |
| 186 | } |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | return status; |
| 190 | } |
| 191 | |
Jean-Michel Trivi | 09647d2 | 2013-09-20 11:58:40 -0700 | [diff] [blame] | 192 | status_t Visualizer::setMeasurementMode(uint32_t mode) { |
| 193 | if ((mode != MEASUREMENT_MODE_NONE) |
| 194 | //Note: needs to be handled as a mask when more measurement modes are added |
| 195 | && ((mode & MEASUREMENT_MODE_PEAK_RMS) != mode)) { |
| 196 | return BAD_VALUE; |
| 197 | } |
| 198 | |
| 199 | Mutex::Autolock _l(mCaptureLock); |
| 200 | |
| 201 | uint32_t buf32[sizeof(effect_param_t) / sizeof(uint32_t) + 2]; |
| 202 | effect_param_t *p = (effect_param_t *)buf32; |
| 203 | |
| 204 | p->psize = sizeof(uint32_t); |
| 205 | p->vsize = sizeof(uint32_t); |
| 206 | *(int32_t *)p->data = VISUALIZER_PARAM_MEASUREMENT_MODE; |
| 207 | *((int32_t *)p->data + 1)= mode; |
| 208 | status_t status = setParameter(p); |
| 209 | |
| 210 | ALOGV("setMeasurementMode mode %d status %d p->status %d", mode, status, p->status); |
| 211 | |
| 212 | if (status == NO_ERROR) { |
| 213 | status = p->status; |
| 214 | if (status == NO_ERROR) { |
| 215 | mMeasurementMode = mode; |
| 216 | } |
| 217 | } |
| 218 | return status; |
| 219 | } |
| 220 | |
| 221 | status_t Visualizer::getIntMeasurements(uint32_t type, uint32_t number, int32_t *measurements) { |
| 222 | if (mMeasurementMode == MEASUREMENT_MODE_NONE) { |
| 223 | ALOGE("Cannot retrieve int measurements, no measurement mode set"); |
| 224 | return INVALID_OPERATION; |
| 225 | } |
| 226 | if (!(mMeasurementMode & type)) { |
| 227 | // measurement type has not been set on this Visualizer |
| 228 | ALOGE("Cannot retrieve int measurements, requested measurement mode 0x%x not set(0x%x)", |
| 229 | type, mMeasurementMode); |
| 230 | return INVALID_OPERATION; |
| 231 | } |
| 232 | // only peak+RMS measurement supported |
| 233 | if ((type != MEASUREMENT_MODE_PEAK_RMS) |
| 234 | // for peak+RMS measurement, the results are 2 int32_t values |
| 235 | || (number != 2)) { |
| 236 | ALOGE("Cannot retrieve int measurements, MEASUREMENT_MODE_PEAK_RMS returns 2 ints, not %d", |
| 237 | number); |
| 238 | return BAD_VALUE; |
| 239 | } |
| 240 | |
| 241 | status_t status = NO_ERROR; |
| 242 | if (mEnabled) { |
| 243 | uint32_t replySize = number * sizeof(int32_t); |
| 244 | status = command(VISUALIZER_CMD_MEASURE, |
| 245 | sizeof(uint32_t) /*cmdSize*/, |
| 246 | &type /*cmdData*/, |
| 247 | &replySize, measurements); |
| 248 | ALOGV("getMeasurements() command returned %d", status); |
| 249 | if ((status == NO_ERROR) && (replySize == 0)) { |
| 250 | status = NOT_ENOUGH_DATA; |
| 251 | } |
| 252 | } else { |
| 253 | ALOGV("getMeasurements() disabled"); |
| 254 | return INVALID_OPERATION; |
| 255 | } |
| 256 | return status; |
| 257 | } |
| 258 | |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 259 | status_t Visualizer::getWaveForm(uint8_t *waveform) |
| 260 | { |
| 261 | if (waveform == NULL) { |
| 262 | return BAD_VALUE; |
| 263 | } |
| 264 | if (mCaptureSize == 0) { |
| 265 | return NO_INIT; |
| 266 | } |
| 267 | |
| 268 | status_t status = NO_ERROR; |
| 269 | if (mEnabled) { |
Eric Laurent | 25f4395 | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 270 | uint32_t replySize = mCaptureSize; |
Eric Laurent | 6d8b694 | 2011-06-24 07:01:31 -0700 | [diff] [blame] | 271 | status = command(VISUALIZER_CMD_CAPTURE, 0, NULL, &replySize, waveform); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 272 | ALOGV("getWaveForm() command returned %d", status); |
John Grossman | af7d818 | 2012-01-11 12:23:42 -0800 | [diff] [blame] | 273 | if ((status == NO_ERROR) && (replySize == 0)) { |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 274 | status = NOT_ENOUGH_DATA; |
| 275 | } |
| 276 | } else { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 277 | ALOGV("getWaveForm() disabled"); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 278 | memset(waveform, 0x80, mCaptureSize); |
| 279 | } |
| 280 | return status; |
| 281 | } |
| 282 | |
| 283 | status_t Visualizer::getFft(uint8_t *fft) |
| 284 | { |
| 285 | if (fft == NULL) { |
| 286 | return BAD_VALUE; |
| 287 | } |
| 288 | if (mCaptureSize == 0) { |
| 289 | return NO_INIT; |
| 290 | } |
| 291 | |
| 292 | status_t status = NO_ERROR; |
| 293 | if (mEnabled) { |
| 294 | uint8_t buf[mCaptureSize]; |
Eric Laurent | 0fa449c | 2010-09-24 11:52:04 -0700 | [diff] [blame] | 295 | status = getWaveForm(buf); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 296 | if (status == NO_ERROR) { |
| 297 | status = doFft(fft, buf); |
| 298 | } |
| 299 | } else { |
| 300 | memset(fft, 0, mCaptureSize); |
| 301 | } |
| 302 | return status; |
| 303 | } |
| 304 | |
| 305 | status_t Visualizer::doFft(uint8_t *fft, uint8_t *waveform) |
| 306 | { |
Chia-chi Yeh | dbd2b7e | 2010-08-19 15:34:10 +0800 | [diff] [blame] | 307 | int32_t workspace[mCaptureSize >> 1]; |
| 308 | int32_t nonzero = 0; |
| 309 | |
| 310 | for (uint32_t i = 0; i < mCaptureSize; i += 2) { |
Chia-chi Yeh | 6b6a736 | 2010-11-01 10:56:45 +0800 | [diff] [blame] | 311 | workspace[i >> 1] = |
| 312 | ((waveform[i] ^ 0x80) << 24) | ((waveform[i + 1] ^ 0x80) << 8); |
Chia-chi Yeh | dbd2b7e | 2010-08-19 15:34:10 +0800 | [diff] [blame] | 313 | nonzero |= workspace[i >> 1]; |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Chia-chi Yeh | dbd2b7e | 2010-08-19 15:34:10 +0800 | [diff] [blame] | 316 | if (nonzero) { |
| 317 | fixed_fft_real(mCaptureSize >> 1, workspace); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 318 | } |
Chia-chi Yeh | dbd2b7e | 2010-08-19 15:34:10 +0800 | [diff] [blame] | 319 | |
| 320 | for (uint32_t i = 0; i < mCaptureSize; i += 2) { |
Marco Nelissen | 209821c | 2011-01-18 16:44:28 -0800 | [diff] [blame] | 321 | short tmp = workspace[i >> 1] >> 21; |
| 322 | while (tmp > 127 || tmp < -128) tmp >>= 1; |
| 323 | fft[i] = tmp; |
| 324 | tmp = workspace[i >> 1]; |
| 325 | tmp >>= 5; |
| 326 | while (tmp > 127 || tmp < -128) tmp >>= 1; |
| 327 | fft[i + 1] = tmp; |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 328 | } |
Chia-chi Yeh | dbd2b7e | 2010-08-19 15:34:10 +0800 | [diff] [blame] | 329 | |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 330 | return NO_ERROR; |
| 331 | } |
| 332 | |
| 333 | void Visualizer::periodicCapture() |
| 334 | { |
Glenn Kasten | a9b21c5 | 2012-01-17 10:06:38 -0800 | [diff] [blame] | 335 | Mutex::Autolock _l(mCaptureLock); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 336 | ALOGV("periodicCapture() %p mCaptureCallBack %p mCaptureFlags 0x%08x", |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 337 | this, mCaptureCallBack, mCaptureFlags); |
| 338 | if (mCaptureCallBack != NULL && |
| 339 | (mCaptureFlags & (CAPTURE_WAVEFORM|CAPTURE_FFT)) && |
| 340 | mCaptureSize != 0) { |
| 341 | uint8_t waveform[mCaptureSize]; |
| 342 | status_t status = getWaveForm(waveform); |
| 343 | if (status != NO_ERROR) { |
| 344 | return; |
| 345 | } |
| 346 | uint8_t fft[mCaptureSize]; |
| 347 | if (mCaptureFlags & CAPTURE_FFT) { |
| 348 | status = doFft(fft, waveform); |
| 349 | } |
| 350 | if (status != NO_ERROR) { |
| 351 | return; |
| 352 | } |
| 353 | uint8_t *wavePtr = NULL; |
| 354 | uint8_t *fftPtr = NULL; |
| 355 | uint32_t waveSize = 0; |
| 356 | uint32_t fftSize = 0; |
| 357 | if (mCaptureFlags & CAPTURE_WAVEFORM) { |
| 358 | wavePtr = waveform; |
| 359 | waveSize = mCaptureSize; |
| 360 | } |
| 361 | if (mCaptureFlags & CAPTURE_FFT) { |
| 362 | fftPtr = fft; |
| 363 | fftSize = mCaptureSize; |
| 364 | } |
| 365 | mCaptureCallBack(mCaptureCbkUser, waveSize, wavePtr, fftSize, fftPtr, mSampleRate); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | uint32_t Visualizer::initCaptureSize() |
| 370 | { |
| 371 | uint32_t buf32[sizeof(effect_param_t) / sizeof(uint32_t) + 2]; |
| 372 | effect_param_t *p = (effect_param_t *)buf32; |
| 373 | |
| 374 | p->psize = sizeof(uint32_t); |
| 375 | p->vsize = sizeof(uint32_t); |
Eric Laurent | 6d8b694 | 2011-06-24 07:01:31 -0700 | [diff] [blame] | 376 | *(int32_t *)p->data = VISUALIZER_PARAM_CAPTURE_SIZE; |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 377 | status_t status = getParameter(p); |
| 378 | |
| 379 | if (status == NO_ERROR) { |
| 380 | status = p->status; |
| 381 | } |
| 382 | |
| 383 | uint32_t size = 0; |
| 384 | if (status == NO_ERROR) { |
| 385 | size = *((int32_t *)p->data + 1); |
| 386 | } |
| 387 | mCaptureSize = size; |
| 388 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 389 | ALOGV("initCaptureSize size %d status %d", mCaptureSize, status); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 390 | |
| 391 | return size; |
| 392 | } |
| 393 | |
Jean-Michel Trivi | 3476de6 | 2012-04-15 17:15:07 -0700 | [diff] [blame] | 394 | void Visualizer::controlStatusChanged(bool controlGranted) { |
| 395 | if (controlGranted) { |
| 396 | // this Visualizer instance regained control of the effect, reset the scaling mode |
| 397 | // and capture size as has been cached through it. |
| 398 | ALOGV("controlStatusChanged(true) causes effect parameter reset:"); |
| 399 | ALOGV(" scaling mode reset to %d", mScalingMode); |
| 400 | setScalingMode(mScalingMode); |
| 401 | ALOGV(" capture size reset to %d", mCaptureSize); |
| 402 | setCaptureSize(mCaptureSize); |
| 403 | } |
| 404 | AudioEffect::controlStatusChanged(controlGranted); |
| 405 | } |
| 406 | |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 407 | //------------------------------------------------------------------------- |
| 408 | |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 409 | Visualizer::CaptureThread::CaptureThread(Visualizer& receiver, uint32_t captureRate, |
| 410 | bool bCanCallJava) |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 411 | : Thread(bCanCallJava), mReceiver(receiver) |
| 412 | { |
| 413 | mSleepTimeUs = 1000000000 / captureRate; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 414 | ALOGV("CaptureThread cstor %p captureRate %d mSleepTimeUs %d", this, captureRate, mSleepTimeUs); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | bool Visualizer::CaptureThread::threadLoop() |
| 418 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 419 | ALOGV("CaptureThread %p enter", this); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 420 | while (!exitPending()) |
| 421 | { |
| 422 | usleep(mSleepTimeUs); |
| 423 | mReceiver.periodicCapture(); |
| 424 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 425 | ALOGV("CaptureThread %p exiting", this); |
Eric Laurent | da7581b | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 426 | return false; |
| 427 | } |
| 428 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 429 | } // namespace android |