Bug 1354457 - Stop video frames being forwarded for direct connections when recorder is suspended. r=pehrsons
authorBryce Van Dyk <bvandyk@mozilla.com>
Mon, 01 May 2017 14:29:46 +1200
changeset 359846 09b32ef21528901ccf1d62dcc77422744a7bfa79
parent 359845 fa623e714a039edc02c380a3da81ea529c9c00ec
child 359847 a17bc9ce68bc88b03100d2144616f3e178d75446
push id31859
push userihsiao@mozilla.com
push dateMon, 22 May 2017 03:28:26 +0000
treeherdermozilla-central@367944041b55 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons
bugs1354457
milestone55.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 1354457 - Stop video frames being forwarded for direct connections when recorder is suspended. r=pehrsons MozReview-Commit-ID: 7J6oQf7qn4u
dom/media/encoder/MediaEncoder.cpp
dom/media/encoder/MediaEncoder.h
--- a/dom/media/encoder/MediaEncoder.cpp
+++ b/dom/media/encoder/MediaEncoder.cpp
@@ -28,17 +28,20 @@ mozilla::LazyLogModule gMediaEncoderLog(
 #define LOG(type, msg) MOZ_LOG(gMediaEncoderLog, type, msg)
 
 namespace mozilla {
 
 void
 MediaStreamVideoRecorderSink::SetCurrentFrames(const VideoSegment& aSegment)
 {
   MOZ_ASSERT(mVideoEncoder);
-  mVideoEncoder->SetCurrentFrames(aSegment);
+  // If we're suspended (paused) we don't forward frames
+  if (!mSuspended) {
+    mVideoEncoder->SetCurrentFrames(aSegment);
+  }
 }
 
 void
 MediaEncoder::SetDirectConnect(bool aConnected)
 {
   mDirectConnected = aConnected;
 }
 
--- a/dom/media/encoder/MediaEncoder.h
+++ b/dom/media/encoder/MediaEncoder.h
@@ -19,25 +19,30 @@
 #include "mozilla/Atomics.h"
 
 namespace mozilla {
 
 class MediaStreamVideoRecorderSink : public MediaStreamVideoSink
 {
 public:
   explicit MediaStreamVideoRecorderSink(VideoTrackEncoder* aEncoder)
-    : mVideoEncoder(aEncoder) {}
+    : mVideoEncoder(aEncoder)
+    , mSuspended(false) {}
 
   // MediaStreamVideoSink methods
   virtual void SetCurrentFrames(const VideoSegment& aSegment) override;
   virtual void ClearFrames() override {}
 
+  void Resume() { mSuspended = false; }
+  void Suspend() { mSuspended = true; }
+
 private:
   virtual ~MediaStreamVideoRecorderSink() {}
   VideoTrackEncoder* mVideoEncoder;
+  Atomic<bool> mSuspended;
 };
 
 /**
  * MediaEncoder is the framework of encoding module, it controls and manages
  * procedures between ContainerWriter and TrackEncoder. ContainerWriter packs
  * the encoded track data with a specific container (e.g. ogg, mp4).
  * AudioTrackEncoder and VideoTrackEncoder are subclasses of TrackEncoder, and
  * are responsible for encoding raw data coming from MediaStreamGraph.
@@ -106,28 +111,32 @@ public :
     RECORD_NOT_SUSPENDED,
     RECORD_SUSPENDED,
     RECORD_RESUMED
   };
 
   /* Note - called from control code, not on MSG threads. */
   void Suspend()
   {
+    MOZ_ASSERT(NS_IsMainThread());
     mSuspended = RECORD_SUSPENDED;
+    mVideoSink->Suspend();
   }
 
   /**
    * Note - called from control code, not on MSG threads.
    * Arm to collect the Duration of the next video frame and give it
    * to the next frame, in order to avoid any possible loss of sync. */
   void Resume()
   {
+    MOZ_ASSERT(NS_IsMainThread());
     if (mSuspended == RECORD_SUSPENDED) {
       mSuspended = RECORD_RESUMED;
     }
+    mVideoSink->Resume();
   }
 
   /**
    * Tells us which Notify to pay attention to for media
    */
   void SetDirectConnect(bool aConnected);
 
   /**