summaryrefslogtreecommitdiffstats
path: root/media/libmediaplayerservice/MediaPlayerService.cpp
diff options
context:
space:
mode:
authorAndy Hung <hunga@google.com>2015-05-31 22:49:46 -0700
committerAndy Hung <hunga@google.com>2015-06-03 22:26:44 -0700
commit179652ee2a508361df1aa18e99000373886f0816 (patch)
treecab9a40399ab43231c8a9b9fc00985b2efaf600c /media/libmediaplayerservice/MediaPlayerService.cpp
parenta7f03353d5f172016f324e2a01f301cca6794152 (diff)
downloadframeworks_av-179652ee2a508361df1aa18e99000373886f0816.zip
frameworks_av-179652ee2a508361df1aa18e99000373886f0816.tar.gz
frameworks_av-179652ee2a508361df1aa18e99000373886f0816.tar.bz2
NuPlayer: Add audio sink buffer configuration
Property media.stagefright.audio.sink (in milliseconds) Also change the default buffer size for PCM playback to 500 ms. Bug: 21198655 Change-Id: I5781288f59bf08fbecd9263a26c919570b58be0f
Diffstat (limited to 'media/libmediaplayerservice/MediaPlayerService.cpp')
-rw-r--r--media/libmediaplayerservice/MediaPlayerService.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index 02c1c38..c0b35e8 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -1482,20 +1482,11 @@ status_t MediaPlayerService::AudioOutput::open(
AudioCallback cb, void *cookie,
audio_output_flags_t flags,
const audio_offload_info_t *offloadInfo,
- bool doNotReconnect)
+ bool doNotReconnect,
+ uint32_t suggestedFrameCount)
{
- mCallback = cb;
- mCallbackCookie = cookie;
-
- // Check argument "bufferCount" against the mininum buffer count
- if (bufferCount < mMinBufferCount) {
- ALOGD("bufferCount (%d) is too small and increased to %d", bufferCount, mMinBufferCount);
- bufferCount = mMinBufferCount;
-
- }
ALOGV("open(%u, %d, 0x%x, 0x%x, %d, %d 0x%x)", sampleRate, channelCount, channelMask,
format, bufferCount, mSessionId, flags);
- size_t frameCount;
// offloading is only supported in callback mode for now.
// offloadInfo must be present if offload flag is set
@@ -1504,20 +1495,36 @@ status_t MediaPlayerService::AudioOutput::open(
return BAD_VALUE;
}
+ // compute frame count for the AudioTrack internal buffer
+ size_t frameCount;
if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) {
frameCount = 0; // AudioTrack will get frame count from AudioFlinger
} else {
+ // try to estimate the buffer processing fetch size from AudioFlinger.
+ // framesPerBuffer is approximate and generally correct, except when it's not :-).
uint32_t afSampleRate;
size_t afFrameCount;
-
if (AudioSystem::getOutputFrameCount(&afFrameCount, mStreamType) != NO_ERROR) {
return NO_INIT;
}
if (AudioSystem::getOutputSamplingRate(&afSampleRate, mStreamType) != NO_ERROR) {
return NO_INIT;
}
+ const size_t framesPerBuffer =
+ (unsigned long long)sampleRate * afFrameCount / afSampleRate;
- frameCount = (sampleRate*afFrameCount*bufferCount)/afSampleRate;
+ if (bufferCount == 0) {
+ // use suggestedFrameCount
+ bufferCount = (suggestedFrameCount + framesPerBuffer - 1) / framesPerBuffer;
+ }
+ // Check argument bufferCount against the mininum buffer count
+ if (bufferCount != 0 && bufferCount < mMinBufferCount) {
+ ALOGV("bufferCount (%d) increased to %d", bufferCount, mMinBufferCount);
+ bufferCount = mMinBufferCount;
+ }
+ // if frameCount is 0, then AudioTrack will get frame count from AudioFlinger
+ // which will be the minimum size permitted.
+ frameCount = bufferCount * framesPerBuffer;
}
if (channelMask == CHANNEL_MASK_USE_CHANNEL_ORDER) {
@@ -1528,6 +1535,9 @@ status_t MediaPlayerService::AudioOutput::open(
}
}
+ mCallback = cb;
+ mCallbackCookie = cookie;
+
// Check whether we can recycle the track
bool reuse = false;
bool bothOffloaded = false;