Bug 1193614 - Schedule State Machine when VideoQueue() is low. r=cpearce, a=sylvestre
authorDan Glastonbury <dglastonbury@mozilla.com>
Wed, 21 Oct 2015 02:53:00 +0200
changeset 289602 849483c937b8
parent 289601 1fd5bf9d2f18
child 289603 451d4a04dae4
push id5211
push usercbook@mozilla.com
push date2015-10-21 14:44 +0000
treeherdermozilla-beta@849483c937b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, sylvestre
bugs1193614
milestone42.0
Bug 1193614 - Schedule State Machine when VideoQueue() is low. r=cpearce, a=sylvestre If UpdateRenderedVideoFrames() can't find a frame in VideoQueue() that is `in the future`, ie. has a time stamp that is greater than clock time, the thread is scheduled in 40ms. The logic in UpdateRenderedVideoFrames() always leaves the current frame sent to the compositor at the head of the queue. It's time stamp is always less than clock time. Because there's always one, old frame in the queue, the logic in OnVideoDecoded() needs to reschedule the state machine when queue size is two, after adding the new frame.
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1,8 +1,9 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifdef XP_WIN
 // Include Windows headers required for enabling high precision timers.
 #include "windows.h"
@@ -849,24 +850,26 @@ MediaDecoderStateMachine::OnVideoDecoded
       Push(video);
       if (MaybeFinishDecodeFirstFrame()) {
         return;
       }
       if (mIsVideoPrerolling && DonePrerollingVideo()) {
         StopPrerollingVideo();
       }
 
-      // Schedule the state machine to send stream data as soon as possible or
-      // the VideoQueue() is empty before the Push().
-      // VideoQueue() is empty implies the state machine thread doesn't have
-      // precise time information about video frames. Once the first video
-      // frame pushed in the queue, schedule the state machine as soon as
-      // possible to render the video frame or delay the state machine thread
-      // accurately.
-      if (mAudioCaptured || VideoQueue().GetSize() == 1) {
+      // Schedule the state machine to send stream data as soon as possible if
+      // the VideoQueue() is empty or contains one frame before the Push().
+      //
+      // The state machine threads requires a frame in VideoQueue() that is `in
+      // the future` to gather precise timing information. The head of
+      // VideoQueue() is always `in the past`.
+      //
+      // Schedule the state machine as soon as possible to render the video
+      // frame or delay the state machine thread accurately.
+      if (mAudioCaptured || VideoQueue().GetSize() <= 2) {
         ScheduleStateMachine();
       }
 
       // For non async readers, if the requested video sample was slow to
       // arrive, increase the amount of audio we buffer to ensure that we
       // don't run out of audio. This is unnecessary for async readers,
       // since they decode audio and video on different threads so they
       // are unlikely to run out of decoded audio.