Bug 1193614 - Schedule State Machine when VideoQueue() is low. r=cpearce a=sylvestre
authorDan Glastonbury <dglastonbury@mozilla.com>
Wed, 14 Oct 2015 14:28:34 +1000
changeset 298213 f2c639d8072504329af341afb8085869f1805611
parent 298212 2e69beaa47cda42cc26f84409151fb33af3efbfe
child 298214 5e6f7c5bd45c08938fe088e6e058e32aaa7495c9
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, sylvestre
bugs1193614
milestone43.0a2
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"
@@ -866,24 +867,26 @@ MediaDecoderStateMachine::OnVideoDecoded
       Push(video, MediaData::VIDEO_DATA);
       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 (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 (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.