Bug 1266685 - Don't pass too many frames to the MediaPipelineTransmit VideoFrameConverter. r?jesup draft
authorAndreas Pehrson <pehrsons@gmail.com>
Fri, 15 Apr 2016 16:00:09 +0200
changeset 355366 773c7fc798ae8ab7c358ae3c75b4e5a5a9a790b6
parent 355133 0891f0fa044cba28024849803e170ed7700e01e0
child 519177 8b7d081f2c8e78ec637c3ca68da625e092c7c02e
push id16266
push userpehrsons@gmail.com
push dateFri, 22 Apr 2016 12:45:45 +0000
reviewersjesup
bugs1266685
milestone48.0a1
Bug 1266685 - Don't pass too many frames to the MediaPipelineTransmit VideoFrameConverter. r?jesup MozReview-Commit-ID: 4XwcfBW9nkY
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -124,16 +124,27 @@ public:
     RefPtr<SharedThreadPool> pool =
       SharedThreadPool::Get(NS_LITERAL_CSTRING("VideoFrameConverter"));
 
     mTaskQueue = MakeAndAddRef<TaskQueue>(pool.forget());
   }
 
   void QueueVideoChunk(VideoChunk& aChunk, bool aForceBlack)
   {
+    if (aChunk.IsNull()) {
+      return;
+    }
+
+    // We get passed duplicate frames every ~10ms even with no frame change.
+    int32_t serial = aChunk.mFrame.GetImage()->GetSerial();
+    if (serial == last_img_) {
+      return;
+    }
+    last_img_ = serial;
+
     // A throttling limit of 1 allows us to convert 2 frames concurrently.
     // It's short enough to not build up too significant a delay, while
     // giving us a margin to not cause some machines to drop every other frame.
     const int32_t queueThrottlingLimit = 1;
     if (mLength > queueThrottlingLimit) {
       MOZ_MTLOG(ML_DEBUG, "VideoFrameConverter " << this << " queue is full." <<
                           " Throttling by throwing away a frame.");
 #ifdef DEBUG
@@ -153,20 +164,16 @@ public:
       MOZ_MTLOG(level, "VideoFrameConverter " << this << " stopped" <<
                        " throttling after throwing away " << mThrottleCount <<
                        " frames. Longest throttle so far was " <<
                        mThrottleRecord << " frames.");
       mThrottleCount = 0;
     }
 #endif
 
-    if (aChunk.IsNull()) {
-      return;
-    }
-
     bool forceBlack = aForceBlack || aChunk.mFrame.GetForceBlack();
 
     if (forceBlack) {
       // Reset the last-img check.
       // -1 is not a guaranteed invalid serial. See bug 1262134.
       last_img_ = -1;
 
       if (disabled_frame_sent_) {
@@ -175,23 +182,16 @@ public:
         // that can be avoided. We don't handle resolution changes while
         // disabled for now.
         return;
       }
 
       disabled_frame_sent_ = true;
     } else {
       disabled_frame_sent_ = false;
-
-      // We get passed duplicate frames every ~10ms even with no frame change.
-      int32_t serial = aChunk.mFrame.GetImage()->GetSerial();
-      if (serial == last_img_) {
-        return;
-      }
-      last_img_ = serial;
     }
 
     ++mLength; // Atomic
 
     nsCOMPtr<nsIRunnable> runnable =
       NS_NewRunnableMethodWithArgs<StorensRefPtrPassByPtr<Image>, bool>(
         this, &VideoFrameConverter::ProcessVideoFrame,
         aChunk.mFrame.GetImage(), forceBlack);