Bug 963624 - Always release video's media buffer in ReleaseAllPendingVideoBuffersLocked() and same thread. r=doublec, a=1.3+
authorSotaro Ikeda <sikeda@mozilla.com>
Tue, 28 Jan 2014 21:20:58 -0500
changeset 175084 27d4e681c33f430887de5ead598ec95a1e49f4d5
parent 175083 f4a23af7c5c72442b091aa3fa77bfb63fb7c84b5
child 175085 79cbd6fb82054dbf34ef637ce37a9753df011900
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdoublec, 1
bugs963624
milestone28.0a2
Bug 963624 - Always release video's media buffer in ReleaseAllPendingVideoBuffersLocked() and same thread. r=doublec, a=1.3+
content/media/omx/OmxDecoder.cpp
--- a/content/media/omx/OmxDecoder.cpp
+++ b/content/media/omx/OmxDecoder.cpp
@@ -173,19 +173,28 @@ VideoGraphicBuffer::VideoGraphicBuffer(c
     mMediaBuffer(aBuffer),
     mOmxDecoder(aOmxDecoder)
 {
   mMediaBuffer->add_ref();
 }
 
 VideoGraphicBuffer::~VideoGraphicBuffer()
 {
-  if (mMediaBuffer) {
+  android::sp<android::OmxDecoder> omxDecoder = mOmxDecoder.promote();
+  if (mMediaBuffer && omxDecoder.get()) {
+    // Post kNotifyPostReleaseVideoBuffer message to OmxDecoder via ALooper.
+    // The message is delivered to OmxDecoder on ALooper thread.
+    // MediaBuffer::release() could take a very long time.
+    // PostReleaseVideoBuffer() prevents long time locking.
+    omxDecoder->PostReleaseVideoBuffer(mMediaBuffer, mReleaseFenceHandle);
+  } else if (mMediaBuffer) {
+    NS_WARNING("OmxDecoder is not present");
     mMediaBuffer->release();
   }
+  mMediaBuffer = nullptr;
 }
 
 void
 VideoGraphicBuffer::Unlock()
 {
   android::sp<android::OmxDecoder> omxDecoder = mOmxDecoder.promote();
   if (omxDecoder.get()) {
     // Post kNotifyPostReleaseVideoBuffer message to OmxDecoder via ALooper.
@@ -761,17 +770,17 @@ bool OmxDecoder::ReadVideo(VideoFrame *a
       mIsVideoSeeking = true;
     }
     MediaSource::ReadOptions options;
     options.setSeekTo(aTimeUs, MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC);
     err = mVideoSource->read(&mVideoBuffer, &options);
     {
       Mutex::Autolock autoLock(mSeekLock);
       mIsVideoSeeking = false;
-      ReleaseAllPendingVideoBuffersLocked();
+      PostReleaseVideoBuffer(nullptr, FenceHandle());
     }
 
     aDoSeek = false;
   } else {
     err = mVideoSource->read(&mVideoBuffer);
   }
 
   aFrame->mSize = 0;
@@ -988,17 +997,19 @@ void OmxDecoder::onMessageReceived(const
       break;
   }
 }
 
 void OmxDecoder::PostReleaseVideoBuffer(MediaBuffer *aBuffer, const FenceHandle& aReleaseFenceHandle)
 {
   {
     Mutex::Autolock autoLock(mPendingVideoBuffersLock);
-    mPendingVideoBuffers.push(BufferItem(aBuffer, aReleaseFenceHandle));
+    if (aBuffer) {
+      mPendingVideoBuffers.push(BufferItem(aBuffer, aReleaseFenceHandle));
+    }
   }
 
   sp<AMessage> notify =
             new AMessage(kNotifyPostReleaseVideoBuffer, mReflector->id());
   // post AMessage to OmxDecoder via ALooper.
   notify->post();
 }