Bug 962878 - 1. Reduce the two successive PushBlobRunnable at the end of recording to one. 2. Refine the code flow in Session:Extract for the accuracy of the blob time. r=roc
authorBenjamin Chen <bechen@mozilla.com>
Tue, 24 Jun 2014 14:05:49 +0800 (2014-06-24)
changeset 190402 7e5778b9a81be5a51901bb3218f65a2518377b06
parent 190401 7e074262b0623ee5c00396523dcc5df099032ecf
child 190403 e36cf3ad5704e90a5b171984b51efbfa5c7c1188
push id45302
push usercbook@mozilla.com
push dateTue, 24 Jun 2014 08:54:34 +0000 (2014-06-24)
treeherdermozilla-inbound@e36cf3ad5704 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs962878
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 962878 - 1. Reduce the two successive PushBlobRunnable at the end of recording to one. 2. Refine the code flow in Session:Extract for the accuracy of the blob time. r=roc
content/media/MediaRecorder.cpp
--- a/content/media/MediaRecorder.cpp
+++ b/content/media/MediaRecorder.cpp
@@ -124,23 +124,23 @@ class MediaRecorder::Session: public nsI
   public:
     ExtractRunnable(Session *aSession)
       : mSession(aSession) {}
 
     NS_IMETHODIMP Run()
     {
       MOZ_ASSERT(NS_GetCurrentThread() == mSession->mReadThread);
 
-      mSession->Extract();
       LOG(PR_LOG_DEBUG, ("Session.ExtractRunnable shutdown = %d", mSession->mEncoder->IsShutdown()));
       if (!mSession->mEncoder->IsShutdown()) {
+        mSession->Extract(false);
         NS_DispatchToCurrentThread(new ExtractRunnable(mSession));
       } else {
-        // Flush out remainding encoded data.
-        NS_DispatchToMainThread(new PushBlobRunnable(mSession));
+        // Flush out remaining encoded data.
+        mSession->Extract(true);
         // Destroy this Session object in main thread.
         NS_DispatchToMainThread(new DestroyRunnable(already_AddRefed<Session>(mSession)));
       }
       return NS_OK;
     }
 
   private:
     nsRefPtr<Session> mSession;
@@ -295,39 +295,44 @@ public:
     if (mEncoder && mEncoder->HasError()) {
       return true;
     }
     return false;
   }
 
 private:
 
-  // Pull encoded meida data from MediaEncoder and put into EncodedBufferCache.
+  // Pull encoded media data from MediaEncoder and put into EncodedBufferCache.
   // Destroy this session object in the end of this function.
-  void Extract()
+  // If the bool aForceFlush is true, we will force to dispatch a
+  // PushBlobRunnable to main thread.
+  void Extract(bool aForceFlush)
   {
     MOZ_ASSERT(NS_GetCurrentThread() == mReadThread);
     LOG(PR_LOG_DEBUG, ("Session.Extract %p", this));
-    // Whether push encoded data back to onDataAvailable automatically.
-    const bool pushBlob = (mTimeSlice > 0) ? true : false;
 
     // Pull encoded media data from MediaEncoder
     nsTArray<nsTArray<uint8_t> > encodedBuf;
     mEncoder->GetEncodedData(&encodedBuf, mMimeType);
 
     // Append pulled data into cache buffer.
     for (uint32_t i = 0; i < encodedBuf.Length(); i++) {
       mEncodedBufferCache->AppendBuffer(encodedBuf[i]);
     }
 
-    if (pushBlob) {
-      if ((TimeStamp::Now() - mLastBlobTimeStamp).ToMilliseconds() > mTimeSlice) {
-        NS_DispatchToMainThread(new PushBlobRunnable(this));
-        mLastBlobTimeStamp = TimeStamp::Now();
-      }
+    // Whether push encoded data back to onDataAvailable automatically or we
+    // need a flush.
+    bool pushBlob = false;
+    if ((mTimeSlice > 0) &&
+        ((TimeStamp::Now()-mLastBlobTimeStamp).ToMilliseconds() > mTimeSlice)) {
+      pushBlob = true;
+    }
+    if (pushBlob || aForceFlush) {
+      NS_DispatchToMainThread(new PushBlobRunnable(this));
+      mLastBlobTimeStamp = TimeStamp::Now();
     }
   }
 
   // Bind media source with MediaEncoder to receive raw media data.
   void SetupStreams()
   {
     MOZ_ASSERT(NS_IsMainThread());