Bug 1266685 - Don't pass too many frames to the MediaPipelineTransmit VideoFrameConverter. r?jesup
MozReview-Commit-ID: 4XwcfBW9nkY
--- 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);