summaryrefslogtreecommitdiffstats
path: root/services/audioflinger/Tracks.cpp
diff options
context:
space:
mode:
authorAndy Hung <hunga@google.com>2014-09-09 18:07:55 -0700
committerAndy Hung <hunga@google.com>2014-11-17 18:06:10 -0800
commit27876c02c21cd3ab7ef01bdd1fc5400c5143584a (patch)
tree3c096ec71dfdb81fcafe4a68165006f1371fdf5d /services/audioflinger/Tracks.cpp
parent97e6ca1a0be83e420ab238d9a1c31d3112126646 (diff)
downloadframeworks_av-27876c02c21cd3ab7ef01bdd1fc5400c5143584a.zip
frameworks_av-27876c02c21cd3ab7ef01bdd1fc5400c5143584a.tar.gz
frameworks_av-27876c02c21cd3ab7ef01bdd1fc5400c5143584a.tar.bz2
Prevent stopped audio tracks from mixing data
Static tracks should have zero framesReady when stopping or stopped, to prevent mixer from running potentially indefinitely with loop mode. Bug: 16070883 Change-Id: Iab9968044d1a6f8543bbcbfb246f49f27d68cace
Diffstat (limited to 'services/audioflinger/Tracks.cpp')
-rw-r--r--services/audioflinger/Tracks.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index b9308fa..037c73b 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -611,15 +611,16 @@ status_t AudioFlinger::PlaybackThread::Track::getNextBuffer(
// ExtendedAudioBufferProvider interface
-// Note that framesReady() takes a mutex on the control block using tryLock().
-// This could result in priority inversion if framesReady() is called by the normal mixer,
-// as the normal mixer thread runs at lower
-// priority than the client's callback thread: there is a short window within framesReady()
-// during which the normal mixer could be preempted, and the client callback would block.
-// Another problem can occur if framesReady() is called by the fast mixer:
-// the tryLock() could block for up to 1 ms, and a sequence of these could delay fast mixer.
-// FIXME Replace AudioTrackShared control block implementation by a non-blocking FIFO queue.
+// framesReady() may return an approximation of the number of frames if called
+// from a different thread than the one calling Proxy->obtainBuffer() and
+// Proxy->releaseBuffer(). Also note there is no mutual exclusion in the
+// AudioTrackServerProxy so be especially careful calling with FastTracks.
size_t AudioFlinger::PlaybackThread::Track::framesReady() const {
+ if (mSharedBuffer != 0 && (isStopped() || isStopping())) {
+ // Static tracks return zero frames immediately upon stopping (for FastTracks).
+ // The remainder of the buffer is not drained.
+ return 0;
+ }
return mAudioTrackServerProxy->framesReady();
}