Merge "audioflinger: improve mmap stream volume" into oc-dev am: 9ba03c881f
am: f417a01ad5
Change-Id: I34d42c70991e76d3f4c398d958ac02c92977d85e
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 9fa0d65..5a8f045 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -8295,22 +8295,24 @@
mEffectChains[0]->setVolume_l(&vol, &vol);
volume = (float)vol / (1 << 24);
}
-
- mOutput->stream->setVolume(volume, volume);
-
- sp<MmapStreamCallback> callback = mCallback.promote();
- if (callback != 0) {
- int channelCount;
- if (isOutput()) {
- channelCount = audio_channel_count_from_out_mask(mChannelMask);
+ // Try to use HW volume control and fall back to SW control if not implemented
+ if (mOutput->stream->setVolume(volume, volume) != NO_ERROR) {
+ sp<MmapStreamCallback> callback = mCallback.promote();
+ if (callback != 0) {
+ int channelCount;
+ if (isOutput()) {
+ channelCount = audio_channel_count_from_out_mask(mChannelMask);
+ } else {
+ channelCount = audio_channel_count_from_in_mask(mChannelMask);
+ }
+ Vector<float> values;
+ for (int i = 0; i < channelCount; i++) {
+ values.add(volume);
+ }
+ callback->onVolumeChanged(mChannelMask, values);
} else {
- channelCount = audio_channel_count_from_in_mask(mChannelMask);
+ ALOGW("Could not set MMAP stream volume: no volume callback!");
}
- Vector<float> values;
- for (int i = 0; i < channelCount; i++) {
- values.add(volume);
- }
- callback->onVolumeChanged(mChannelMask, values);
}
}
}