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