Bug 1133167 - Add CancelSeek call to FlushDecoding() r=cpearce,bholley a=lmandel
authorSotaro Ikeda <sikeda@mozilla.com>
Tue, 17 Feb 2015 07:50:49 -0800
changeset 240856 9fb98996305ce5c4a79a511fc1ddba25c6946685
parent 240855 65a768a861a56c191eeb54b0a7d98cb1d0acb980
child 240857 d1446f0958fc76015393f951e38315b1c7c950e4
push id7672
push userrgiles@mozilla.com
push dateMon, 23 Feb 2015 06:50:33 +0000
treeherdermozilla-aurora@d8e630336213 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, bholley, lmandel
bugs1133167
milestone37.0a2
Bug 1133167 - Add CancelSeek call to FlushDecoding() r=cpearce,bholley a=lmandel
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2922,17 +2922,17 @@ MediaDecoderStateMachine::FlushDecoding(
                "Should be on state machine or decode thread.");
   AssertCurrentThreadInMonitor();
 
   {
     // Put a task in the decode queue to abort any decoding operations.
     // The reader is not supposed to put any tasks to deliver samples into
     // the queue after this runs (unless we request another sample from it).
     RefPtr<nsIRunnable> task;
-    task = NS_NewRunnableMethod(mReader, &MediaDecoderReader::ResetDecode);
+    task = NS_NewRunnableMethod(this, &MediaDecoderStateMachine::ResetDecode);
 
     // Wait for the ResetDecode to run and for the decoder to abort
     // decoding operations and run any pending callbacks. This is
     // important, as we don't want any pending tasks posted to the task
     // queue by the reader to deliver any samples after we've posted the
     // reader Shutdown() task below, as the sample-delivery tasks will
     // keep video frames alive until after we've called Reader::Shutdown(),
     // and shutdown on B2G will fail as there are outstanding video frames
@@ -2943,16 +2943,35 @@ MediaDecoderStateMachine::FlushDecoding(
   }
 
   // We must reset playback so that all references to frames queued
   // in the state machine are dropped, else subsequent calls to Shutdown()
   // or ReleaseMediaResources() can fail on B2G.
   ResetPlayback();
 }
 
+void
+MediaDecoderStateMachine::ResetDecode()
+{
+  NS_ASSERTION(OnDecodeThread(), "Should be on decode thread.");
+
+  if (!mReader) {
+    return;
+  }
+
+  {
+    ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
+    if (mWaitingForDecoderSeek && !mCancelingSeek) {
+      mReader->CancelSeek();
+      mCancelingSeek = true;
+    }
+  }
+  mReader->ResetDecode();
+}
+
 void MediaDecoderStateMachine::RenderVideoFrame(VideoData* aData,
                                                 TimeStamp aTarget)
 {
   NS_ASSERTION(OnStateMachineThread() || OnDecodeThread(),
                "Should be on state machine or decode thread.");
   mDecoder->GetReentrantMonitor().AssertNotCurrentThreadIn();
 
   if (aData->mDuplicate) {
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -417,16 +417,19 @@ public:
   }
 
   void OnWaitForDataRejected(WaitForDataRejectValue aRejection)
   {
     ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
     WaitRequestRef(aRejection.mType).Complete();
   }
 
+  // Resets all state related to decoding, emptying all buffers etc.
+  void ResetDecode();
+
 private:
   void AcquireMonitorAndInvokeDecodeError();
 
 protected:
   virtual ~MediaDecoderStateMachine();
 
   void AssertCurrentThreadInMonitor() const { mDecoder->GetReentrantMonitor().AssertCurrentThreadIn(); }