Fix race condition when streaming MP2TS to media server
Data transfer between user space and the media server of MP2TS
packets is done through a queue of buffers. This queue tells
the OpenMAX AL player whenever a buffer is available to be filled
so it can be transferred.
When the player is destroyed, this queue is cleared; this is
indicated by the boolean mBuffersHasBeenSet whose role is to
store whether the queue is properly configured.
There is a race condition where the queue could be cleared right
as the availability of a buffer is signaled.
The fix is to only try to use the available buffer when
mBuffersHasBeenSet is true.
Bug 6971102
Change-Id: Ibbe8f58fc954b84bf560f29944d1018dab261895
diff --git a/src/android/android_StreamPlayer.cpp b/src/android/android_StreamPlayer.cpp
index ade5280..86501ae 100644
--- a/src/android/android_StreamPlayer.cpp
+++ b/src/android/android_StreamPlayer.cpp
@@ -77,8 +77,10 @@
{
Mutex::Autolock _l(mLock);
- // assert not needed because if not set, size() will be zero and the CHECK_LT will also fail
- // assert(mBuffersHasBeenSet);
+ if (!mBuffersHasBeenSet) {
+ // no buffers available to push data to from the buffer queue, bail
+ return;
+ }
CHECK_LT(index, mBuffers.size());
#if 0 // enable if needed for debugging
sp<IMemory> mem = mBuffers.itemAt(index);