summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisael Lopez Cruz2013-11-08 01:59:11 -0600
committerMisael Lopez Cruz2013-11-09 18:50:51 -0600
commitd25b28640179643da45a8107efab7922be3d8e54 (patch)
tree226519f8d84e71b19241c7efcf27139cd35bbf1a /audio/multizone/AudioHw.cpp
parentc4388725c6696f1ba600b2fca085927a7a52af00 (diff)
downloaddevice-ti-jacinto6evm-d25b28640179643da45a8107efab7922be3d8e54.tar.gz
device-ti-jacinto6evm-d25b28640179643da45a8107efab7922be3d8e54.tar.xz
device-ti-jacinto6evm-d25b28640179643da45a8107efab7922be3d8e54.zip
audio: Multizone: Refactor stream resume/idle
Refactor the resume (leaving standby on first read/write) and idle (entering standby) in preparation for voice call support. JAMR3 outputs have mixer controls that do not need to change dynamically, so they are moved to the default routes section of the dra7evm paths. Change-Id: I432a69ca67eff0e276ce90170dff4a5201ac181a Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
Diffstat (limited to 'audio/multizone/AudioHw.cpp')
-rw-r--r--audio/multizone/AudioHw.cpp86
1 files changed, 59 insertions, 27 deletions
diff --git a/audio/multizone/AudioHw.cpp b/audio/multizone/AudioHw.cpp
index 78caf77..9b432e9 100644
--- a/audio/multizone/AudioHw.cpp
+++ b/audio/multizone/AudioHw.cpp
@@ -131,6 +131,31 @@ int AudioStreamOut::setFormat(audio_format_t format)
131 return 0; 131 return 0;
132} 132}
133 133
134/* must be called with mLock */
135int AudioStreamOut::resume()
136{
137 int ret = mWriter->registerStream(mStream);
138 if (ret) {
139 ALOGE("AudioStreamOut: failed to register stream %d", ret);
140 return ret;
141 }
142
143 ret = mStream->start();
144 if (ret) {
145 ALOGE("AudioStreamOut: failed to start stream %d", ret);
146 mWriter->unregisterStream(mStream);
147 }
148
149 return ret;
150}
151
152/* must be called with mLock */
153void AudioStreamOut::idle()
154{
155 mStream->stop();
156 mWriter->unregisterStream(mStream);
157}
158
134int AudioStreamOut::standby() 159int AudioStreamOut::standby()
135{ 160{
136 ALOGV("AudioStreamOut: standby()"); 161 ALOGV("AudioStreamOut: standby()");
@@ -138,9 +163,7 @@ int AudioStreamOut::standby()
138 AutoMutex lock(mLock); 163 AutoMutex lock(mLock);
139 164
140 if (!mStandby) { 165 if (!mStandby) {
141 mStream->stop(); 166 idle();
142 mWriter->unregisterStream(mStream);
143 mHwDev->mMixer.setPath(mDevices, false);
144 mStandby = true; 167 mStandby = true;
145 } 168 }
146 169
@@ -229,20 +252,12 @@ ssize_t AudioStreamOut::write(const void* buffer, size_t bytes)
229 AutoMutex lock(mLock); 252 AutoMutex lock(mLock);
230 253
231 if (mStandby) { 254 if (mStandby) {
232 mHwDev->mMixer.setPath(mDevices, true); 255 ret = resume();
233 ret = mWriter->registerStream(mStream);
234 if (ret) { 256 if (ret) {
235 ALOGE("AudioStreamOut: failed to register stream %d", ret); 257 ALOGE("AudioStreamOut: failed to resume stream %d", ret);
236 return ret;
237 }
238 ret = mStream->start();
239 if (ret) {
240 ALOGE("AudioStreamOut: failed to start stream %d", ret);
241 mWriter->unregisterStream(mStream);
242 usleep(usecs); /* limits the rate of error messages */ 258 usleep(usecs); /* limits the rate of error messages */
243 return ret; 259 return ret;
244 } 260 }
245
246 mStandby = false; 261 mStandby = false;
247 } 262 }
248 263
@@ -361,6 +376,34 @@ int AudioStreamIn::setFormat(audio_format_t format)
361 return 0; 376 return 0;
362} 377}
363 378
379/* must be called with mLock */
380int AudioStreamIn::resume()
381{
382 mHwDev->mMixer.setPath(mDevices, true);
383
384 int ret = mReader->registerStream(mStream);
385 if (ret) {
386 ALOGE("AudioStreamIn: failed to register Dest %d", ret);
387 return ret;
388 }
389
390 ret = mStream->start();
391 if (ret) {
392 ALOGE("AudioStreamIn: failed to start stream %d", ret);
393 mReader->unregisterStream(mStream);
394 }
395
396 return ret;
397}
398
399/* must be called with mLock */
400void AudioStreamIn::idle()
401{
402 mStream->stop();
403 mReader->unregisterStream(mStream);
404 mHwDev->mMixer.setPath(mDevices, false);
405}
406
364int AudioStreamIn::standby() 407int AudioStreamIn::standby()
365{ 408{
366 ALOGV("AudioStreamIn: standby()"); 409 ALOGV("AudioStreamIn: standby()");
@@ -368,9 +411,7 @@ int AudioStreamIn::standby()
368 AutoMutex lock(mLock); 411 AutoMutex lock(mLock);
369 412
370 if (!mStandby) { 413 if (!mStandby) {
371 mStream->stop(); 414 idle();
372 mReader->unregisterStream(mStream);
373 mHwDev->mMixer.setPath(mDevices, false);
374 mStandby = true; 415 mStandby = true;
375 } 416 }
376 417
@@ -473,27 +514,18 @@ ssize_t AudioStreamIn::read(void* buffer, size_t bytes)
473 AutoMutex lock(mLock); 514 AutoMutex lock(mLock);
474 515
475 if (mStandby) { 516 if (mStandby) {
476 mHwDev->mMixer.setPath(mDevices, true); 517 ret = resume();
477 ret = mReader->registerStream(mStream);
478 if (ret) { 518 if (ret) {
479 ALOGE("AudioStreamIn: failed to register Dest %d", ret); 519 ALOGE("AudioStreamIn: failed to resume stream %d", ret);
480 return ret;
481 }
482 ret = mStream->start();
483 if (ret) {
484 ALOGE("AudioStreamIn: failed to start stream %d", ret);
485 mReader->unregisterStream(mStream);
486 usleep(usecs); /* limits the rate of error messages */ 520 usleep(usecs); /* limits the rate of error messages */
487 return ret; 521 return ret;
488 } 522 }
489
490 mStandby = false; 523 mStandby = false;
491 } 524 }
492 525
493 ret = mStream->read(buffer, frames); 526 ret = mStream->read(buffer, frames);
494 if (ret < 0) { 527 if (ret < 0) {
495 ALOGE("AudioStreamIn: failed to read data %d", ret); 528 ALOGE("AudioStreamIn: failed to read data %d", ret);
496 uint32_t usecs = (frames * 1000000) / mParams.sampleRate;
497 usleep(usecs); 529 usleep(usecs);
498 bytes = ret; 530 bytes = ret;
499 } else { 531 } else {