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