summaryrefslogtreecommitdiffstats
path: root/audio
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
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')
-rw-r--r--audio/multizone/AudioHw.cpp86
-rw-r--r--audio/multizone/AudioHw.h10
-rw-r--r--audio/multizone/dra7evm_paths.xml23
3 files changed, 69 insertions, 50 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 {
diff --git a/audio/multizone/AudioHw.h b/audio/multizone/AudioHw.h
index 2a5e296..a0973ad 100644
--- a/audio/multizone/AudioHw.h
+++ b/audio/multizone/AudioHw.h
@@ -53,10 +53,6 @@ class AudioStream {
53 virtual char *getParameters(const char *keys) const = 0; 53 virtual char *getParameters(const char *keys) const = 0;
54 virtual int addAudioEffect(effect_handle_t effect) const = 0; 54 virtual int addAudioEffect(effect_handle_t effect) const = 0;
55 virtual int removeAudioEffect(effect_handle_t effect) const = 0; 55 virtual int removeAudioEffect(effect_handle_t effect) const = 0;
56
57 // FIXME not used
58 static const uint32_t kDefaultSampleRate = 44100;
59 static const uint32_t kDefaultBufferSize = 4096;
60}; 56};
61 57
62class AudioStreamOut : public RefBase, public AudioStream { 58class AudioStreamOut : public RefBase, public AudioStream {
@@ -92,6 +88,9 @@ class AudioStreamOut : public RefBase, public AudioStream {
92 int getNextWriteTimestamp(int64_t *timestamp) const; 88 int getNextWriteTimestamp(int64_t *timestamp) const;
93 89
94 protected: 90 protected:
91 int resume();
92 void idle();
93
95 AudioHwDevice *mHwDev; 94 AudioHwDevice *mHwDev;
96 PcmWriter *mWriter; 95 PcmWriter *mWriter;
97 PcmParams mParams; 96 PcmParams mParams;
@@ -132,6 +131,9 @@ class AudioStreamIn : public RefBase, public AudioStream {
132 uint32_t getInputFramesLost(); 131 uint32_t getInputFramesLost();
133 132
134 protected: 133 protected:
134 int resume();
135 void idle();
136
135 AudioHwDevice *mHwDev; 137 AudioHwDevice *mHwDev;
136 PcmReader *mReader; 138 PcmReader *mReader;
137 PcmParams mParams; 139 PcmParams mParams;
diff --git a/audio/multizone/dra7evm_paths.xml b/audio/multizone/dra7evm_paths.xml
index a64ea4c..7b5f057 100644
--- a/audio/multizone/dra7evm_paths.xml
+++ b/audio/multizone/dra7evm_paths.xml
@@ -31,7 +31,7 @@
31<!-- JAMR3 board, codec-A input: Line-In --> 31<!-- JAMR3 board, codec-A input: Line-In -->
32<ctl name="J3A Left PGA Mixer Line1L Switch" value="1" /> 32<ctl name="J3A Left PGA Mixer Line1L Switch" value="1" />
33<ctl name="J3A Right PGA Mixer Line1R Switch" value="1" /> 33<ctl name="J3A Right PGA Mixer Line1R Switch" value="1" />
34<ctl name="J3A PGA Capture Switch" value="0" /> 34<ctl name="J3A PGA Capture Switch" value="1" />
35<ctl name="J3A PGA Capture Volume" value="0" /> 35<ctl name="J3A PGA Capture Volume" value="0" />
36<ctl name="J3A Left Line1L Mux" value="differential" /> 36<ctl name="J3A Left Line1L Mux" value="differential" />
37<ctl name="J3A Right Line1L Mux" value="differential" /> 37<ctl name="J3A Right Line1L Mux" value="differential" />
@@ -53,7 +53,7 @@
53<ctl name="J3A Right DAC Mux" value="DAC_R1" /> 53<ctl name="J3A Right DAC Mux" value="DAC_R1" />
54<ctl name="J3A Left Line Mixer DACL1 Switch" value="1" /> 54<ctl name="J3A Left Line Mixer DACL1 Switch" value="1" />
55<ctl name="J3A Right Line Mixer DACR1 Switch" value="1" /> 55<ctl name="J3A Right Line Mixer DACR1 Switch" value="1" />
56<ctl name="J3A Line DAC Playback Volume" value="0" /> 56<ctl name="J3A Line DAC Playback Volume" value="118" />
57<ctl name="J3A Line Playback Switch" value="1" /> 57<ctl name="J3A Line Playback Switch" value="1" />
58<ctl name="J3A PCM Playback Volume" value="127" /> 58<ctl name="J3A PCM Playback Volume" value="127" />
59 59
@@ -62,7 +62,7 @@
62<ctl name="J3B Right DAC Mux" value="DAC_R1" /> 62<ctl name="J3B Right DAC Mux" value="DAC_R1" />
63<ctl name="J3B Left Line Mixer DACL1 Switch" value="1" /> 63<ctl name="J3B Left Line Mixer DACL1 Switch" value="1" />
64<ctl name="J3B Right Line Mixer DACR1 Switch" value="1" /> 64<ctl name="J3B Right Line Mixer DACR1 Switch" value="1" />
65<ctl name="J3B Line DAC Playback Volume" value="0" /> 65<ctl name="J3B Line DAC Playback Volume" value="118" />
66<ctl name="J3B Line Playback Switch" value="1" /> 66<ctl name="J3B Line Playback Switch" value="1" />
67<ctl name="J3B PCM Playback Volume" value="127" /> 67<ctl name="J3B PCM Playback Volume" value="127" />
68 68
@@ -71,7 +71,7 @@
71<ctl name="J3C Right DAC Mux" value="DAC_R1" /> 71<ctl name="J3C Right DAC Mux" value="DAC_R1" />
72<ctl name="J3C Left Line Mixer DACL1 Switch" value="1" /> 72<ctl name="J3C Left Line Mixer DACL1 Switch" value="1" />
73<ctl name="J3C Right Line Mixer DACR1 Switch" value="1" /> 73<ctl name="J3C Right Line Mixer DACR1 Switch" value="1" />
74<ctl name="J3C Line DAC Playback Volume" value="0" /> 74<ctl name="J3C Line DAC Playback Volume" value="118" />
75<ctl name="J3C Line Playback Switch" value="1" /> 75<ctl name="J3C Line Playback Switch" value="1" />
76<ctl name="J3C PCM Playback Volume" value="127" /> 76<ctl name="J3C PCM Playback Volume" value="127" />
77 77
@@ -92,19 +92,4 @@
92<ctl name="J3B PGA Capture Switch" id="1" value="1" /> 92<ctl name="J3B PGA Capture Switch" id="1" value="1" />
93</path> 93</path>
94 94
95<!-- On-board output: Line-Out -->
96<path name="AUDIO_DEVICE_OUT_SPEAKER">
97<ctl name="Line DAC Playback Volume" value="118" />
98</path>
99
100<!-- JAMR3 codec B output: Line-Out -->
101<path name="AUDIO_DEVICE_OUT_WIRED_HEADPHONE">
102<ctl name="J3B Line DAC Playback Volume" value="118" />
103</path>
104
105<!-- JAMR3 codec C output: Line-Out -->
106<path name="AUDIO_DEVICE_OUT_WIRED_HEADPHONE2">
107<ctl name="J3C Line DAC Playback Volume" value="118" />
108</path>
109
110</mixer> 95</mixer>