Bug 1354457 - Stop video frames being forwarded for direct connections when recorder is suspended. r?pehrsons
MozReview-Commit-ID: 7J6oQf7qn4u
--- 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);
/**