Add support for deep audio buffers
Allow AudioSink to use deep audio buffering when the
source is audio only and its duration is more than
a certain threshold.
This helps improve battery life but implies higher
audio latency.
Change-Id: Ie79915b61c370292f05aabda9779356570e03cbb
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
index 11cea3b..f1467c4 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
@@ -390,12 +390,30 @@
sampleRate, numChannels);
mAudioSink->close();
+
+ audio_output_flags_t flags;
+ int64_t durationUs;
+ // FIXME: we should handle the case where the video decoder is created after
+ // we receive the format change indication. Current code will just make that
+ // we select deep buffer with video which should not be a problem as it should
+ // not prevent from keeping A/V sync.
+ if (mVideoDecoder == NULL &&
+ mSource->getDuration(&durationUs) == OK &&
+ durationUs > AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US) {
+ flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
+ } else {
+ flags = AUDIO_OUTPUT_FLAG_NONE;
+ }
+
CHECK_EQ(mAudioSink->open(
sampleRate,
numChannels,
CHANNEL_MASK_USE_CHANNEL_ORDER,
AUDIO_FORMAT_PCM_16_BIT,
- 8 /* bufferCount */),
+ 8 /* bufferCount */,
+ NULL,
+ NULL,
+ flags),
(status_t)OK);
mAudioSink->start();