summaryrefslogtreecommitdiffstats
path: root/media/libmedia/AudioSystem.cpp
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2012-03-20 18:36:01 -0700
committerEric Laurent <elaurent@google.com>2012-04-03 16:53:25 -0700
commit1a9ed11a472493cac7f6dfcbfac2064526a493ed (patch)
tree5f4a3c6856f294b3c0371afd87df96277215107b /media/libmedia/AudioSystem.cpp
parent290ca3a767a974ce9d041e5bcb0c69153f7851d5 (diff)
downloadframeworks_av-1a9ed11a472493cac7f6dfcbfac2064526a493ed.zip
frameworks_av-1a9ed11a472493cac7f6dfcbfac2064526a493ed.tar.gz
frameworks_av-1a9ed11a472493cac7f6dfcbfac2064526a493ed.tar.bz2
audio policy: add configuration file
removed outputs to stream mapping cache in audio system: the output for a given stream type must always be queried from audio policy manager as the cache is not always updated fast enough by audioflinger callback. removed AudioFlinger::PlaybackThread::setStreamValid() not used anymore if stream to output mapping is not cached. Change-Id: Ieca720c0b292181f81247259c8a44359bc74c66b
Diffstat (limited to 'media/libmedia/AudioSystem.cpp')
-rw-r--r--media/libmedia/AudioSystem.cpp80
1 files changed, 33 insertions, 47 deletions
diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp
index 33c7d03..2596f07 100644
--- a/media/libmedia/AudioSystem.cpp
+++ b/media/libmedia/AudioSystem.cpp
@@ -36,7 +36,6 @@ sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient;
audio_error_callback AudioSystem::gAudioErrorCallback = NULL;
// Cached values
-DefaultKeyedVector<audio_stream_type_t, audio_io_handle_t> AudioSystem::gStreamOutputMap(0);
DefaultKeyedVector<audio_io_handle_t, AudioSystem::OutputDescriptor *> AudioSystem::gOutputs(0);
// Cached values for recording queries, all protected by gLock
@@ -213,7 +212,6 @@ status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType) {
status_t AudioSystem::getOutputSamplingRate(int* samplingRate, audio_stream_type_t streamType)
{
- OutputDescriptor *outputDesc;
audio_io_handle_t output;
if (streamType == AUDIO_STREAM_DEFAULT) {
@@ -225,6 +223,15 @@ status_t AudioSystem::getOutputSamplingRate(int* samplingRate, audio_stream_type
return PERMISSION_DENIED;
}
+ return getSamplingRate(output, streamType, samplingRate);
+}
+
+status_t AudioSystem::getSamplingRate(audio_io_handle_t output,
+ audio_stream_type_t streamType,
+ int* samplingRate)
+{
+ OutputDescriptor *outputDesc;
+
gLock.lock();
outputDesc = AudioSystem::gOutputs.valueFor(output);
if (outputDesc == NULL) {
@@ -239,7 +246,7 @@ status_t AudioSystem::getOutputSamplingRate(int* samplingRate, audio_stream_type
gLock.unlock();
}
- ALOGV("getOutputSamplingRate() streamType %d, output %d, sampling rate %d", streamType, output, *samplingRate);
+ ALOGV("getSamplingRate() streamType %d, output %d, sampling rate %d", streamType, output, *samplingRate);
return NO_ERROR;
}
@@ -251,7 +258,6 @@ status_t AudioSystem::getOutputFrameCount(int* frameCount, int streamType) {
status_t AudioSystem::getOutputFrameCount(int* frameCount, audio_stream_type_t streamType)
{
- OutputDescriptor *outputDesc;
audio_io_handle_t output;
if (streamType == AUDIO_STREAM_DEFAULT) {
@@ -263,6 +269,15 @@ status_t AudioSystem::getOutputFrameCount(int* frameCount, audio_stream_type_t s
return PERMISSION_DENIED;
}
+ return getFrameCount(output, streamType, frameCount);
+}
+
+status_t AudioSystem::getFrameCount(audio_io_handle_t output,
+ audio_stream_type_t streamType,
+ int* frameCount)
+{
+ OutputDescriptor *outputDesc;
+
gLock.lock();
outputDesc = AudioSystem::gOutputs.valueFor(output);
if (outputDesc == NULL) {
@@ -275,14 +290,13 @@ status_t AudioSystem::getOutputFrameCount(int* frameCount, audio_stream_type_t s
gLock.unlock();
}
- ALOGV("getOutputFrameCount() streamType %d, output %d, frameCount %d", streamType, output, *frameCount);
+ ALOGV("getFrameCount() streamType %d, output %d, frameCount %d", streamType, output, *frameCount);
return NO_ERROR;
}
status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t streamType)
{
- OutputDescriptor *outputDesc;
audio_io_handle_t output;
if (streamType == AUDIO_STREAM_DEFAULT) {
@@ -294,6 +308,15 @@ status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t st
return PERMISSION_DENIED;
}
+ return getLatency(output, streamType, latency);
+}
+
+status_t AudioSystem::getLatency(audio_io_handle_t output,
+ audio_stream_type_t streamType,
+ uint32_t* latency)
+{
+ OutputDescriptor *outputDesc;
+
gLock.lock();
outputDesc = AudioSystem::gOutputs.valueFor(output);
if (outputDesc == NULL) {
@@ -306,7 +329,7 @@ status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t st
gLock.unlock();
}
- ALOGV("getOutputLatency() streamType %d, output %d, latency %d", streamType, output, *latency);
+ ALOGV("getLatency() streamType %d, output %d, latency %d", streamType, output, *latency);
return NO_ERROR;
}
@@ -395,7 +418,6 @@ void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who) {
AudioSystem::gAudioFlinger.clear();
// clear output handles and stream to output map caches
- AudioSystem::gStreamOutputMap.clear();
AudioSystem::gOutputs.clear();
if (gAudioErrorCallback) {
@@ -416,12 +438,6 @@ void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, audio_io_handle
switch (event) {
case STREAM_CONFIG_CHANGED:
- if (param2 == NULL) break;
- stream = *(const audio_stream_type_t *)param2;
- ALOGV("ioConfigChanged() STREAM_CONFIG_CHANGED stream %d, output %d", stream, ioHandle);
- if (gStreamOutputMap.indexOfKey(stream) >= 0) {
- gStreamOutputMap.replaceValueFor(stream, ioHandle);
- }
break;
case OUTPUT_OPENED: {
if (gOutputs.indexOfKey(ioHandle) >= 0) {
@@ -444,11 +460,6 @@ void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, audio_io_handle
ALOGV("ioConfigChanged() output %d closed", ioHandle);
gOutputs.removeItem(ioHandle);
- for (int i = gStreamOutputMap.size() - 1; i >= 0 ; i--) {
- if (gStreamOutputMap.valueAt(i) == ioHandle) {
- gStreamOutputMap.removeItemsAt(i);
- }
- }
} break;
case OUTPUT_CONFIG_CHANGED: {
@@ -580,33 +591,9 @@ audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream,
uint32_t channels,
audio_policy_output_flags_t flags)
{
- audio_io_handle_t output = 0;
- // Do not use stream to output map cache if the direct output
- // flag is set or if we are likely to use a direct output
- // (e.g voice call stream @ 8kHz could use BT SCO device and be routed to
- // a direct output on some platforms).
- // TODO: the output cache and stream to output mapping implementation needs to
- // be reworked for proper operation with direct outputs. This code is too specific
- // to the first use case we want to cover (Voice Recognition and Voice Dialer over
- // Bluetooth SCO
- if ((flags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT) == 0 &&
- ((stream != AUDIO_STREAM_VOICE_CALL && stream != AUDIO_STREAM_BLUETOOTH_SCO) ||
- channels != AUDIO_CHANNEL_OUT_MONO ||
- (samplingRate != 8000 && samplingRate != 16000))) {
- Mutex::Autolock _l(gLock);
- output = AudioSystem::gStreamOutputMap.valueFor(stream);
- ALOGV_IF((output != 0), "getOutput() read %d from cache for stream %d", output, stream);
- }
- if (output == 0) {
- const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
- if (aps == 0) return 0;
- output = aps->getOutput(stream, samplingRate, format, channels, flags);
- if ((flags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT) == 0) {
- Mutex::Autolock _l(gLock);
- AudioSystem::gStreamOutputMap.add(stream, output);
- }
- }
- return output;
+ const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
+ if (aps == 0) return 0;
+ return aps->getOutput(stream, samplingRate, format, channels, flags);
}
status_t AudioSystem::startOutput(audio_io_handle_t output,
@@ -754,7 +741,6 @@ void AudioSystem::clearAudioConfigCache()
{
Mutex::Autolock _l(gLock);
ALOGV("clearAudioConfigCache()");
- gStreamOutputMap.clear();
gOutputs.clear();
}