diff options
author | Eric Laurent <elaurent@google.com> | 2011-03-21 11:49:00 -0700 |
---|---|---|
committer | Eric Laurent <elaurent@google.com> | 2011-03-21 11:49:00 -0700 |
commit | 9b7d950f1f3b0c526712b713dbceb0e22762c015 (patch) | |
tree | 087e6194a7eb4c3996860312bd340ca06f080cbb /media/libmediaplayerservice/nuplayer | |
parent | ebd5d2541d4e5351fd1f1a23fc9ef047cfa67575 (diff) | |
download | frameworks_av-9b7d950f1f3b0c526712b713dbceb0e22762c015.zip frameworks_av-9b7d950f1f3b0c526712b713dbceb0e22762c015.tar.gz frameworks_av-9b7d950f1f3b0c526712b713dbceb0e22762c015.tar.bz2 |
Fix issue 3483718: audio streaming and A2DP.
The problem is that when switching from A2DP to device speakers or headset,
The AudioTrack binder interface to AudioFlinger must be destroyed and restored
to accomodate new buffer size requirements. Current AudioTrack implementation
did not restore properly the PCM buffer write index which caused a mismatch between
the written frame count in the mediaplayer renderer and the AudioTrack. The renderer
could then believe the AudioTrack buffer was full and stop writing data preventing the
AudioTrack to reach a bufffer full condition and resume playback.
The rendered was also modified to refresh the AudioTrack frame count (buffer size)
inside the write loop in NuPlayer::Renderer::onDrainAudioQueue() as this count can change
from one write to the next.
Also modified AudioTrack::obtainBuffer() to check for track invalidated status before
querying for available space in the buffer. This avoids writing to the old track's
buffer until full before detecting the invalidated condition and create a new track.
Change-Id: I16a857e464e466880847f52f640820aa271539ad
Diffstat (limited to 'media/libmediaplayerservice/nuplayer')
-rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp index 369a3a8..828e008 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp @@ -198,18 +198,21 @@ void NuPlayer::Renderer::signalAudioSinkChanged() { } void NuPlayer::Renderer::onDrainAudioQueue() { - uint32_t numFramesPlayed; - CHECK_EQ(mAudioSink->getPosition(&numFramesPlayed), (status_t)OK); - ssize_t numFramesAvailableToWrite = - mAudioSink->frameCount() - (mNumFramesWritten - numFramesPlayed); + for (;;) { + uint32_t numFramesPlayed; + CHECK_EQ(mAudioSink->getPosition(&numFramesPlayed), (status_t)OK); - CHECK_GE(numFramesAvailableToWrite, 0); + ssize_t numFramesAvailableToWrite = + mAudioSink->frameCount() - (mNumFramesWritten - numFramesPlayed); - size_t numBytesAvailableToWrite = - numFramesAvailableToWrite * mAudioSink->frameSize(); + size_t numBytesAvailableToWrite = + numFramesAvailableToWrite * mAudioSink->frameSize(); + + if (numBytesAvailableToWrite == 0) { + break; + } - while (numBytesAvailableToWrite > 0) { if (mAudioQueue.empty()) { break; } @@ -264,10 +267,10 @@ void NuPlayer::Renderer::onDrainAudioQueue() { if (entry->mOffset == entry->mBuffer->size()) { entry->mNotifyConsumed->post(); mAudioQueue.erase(mAudioQueue.begin()); + entry = NULL; } - numBytesAvailableToWrite -= copy; mNumFramesWritten += copy / mAudioSink->frameSize(); } |