Bug 968016 - Call MediaDecoderStateMachine::Init() in MediaSourceDecoder::Load(), like MediaDecoder. r=kinetik
authorChris Pearce <cpearce@mozilla.com>
Tue, 18 Feb 2014 11:53:51 +1300
changeset 169506 0f78e7bb808cd11027647b99c8ab428ad67549d3
parent 169505 b732738b75f89122d9ad0cab4396194d7ca27de0
child 169507 406b7fde02e24c786ebe70f6019a88a7e30b3ef9
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewerskinetik
bugs968016
milestone30.0a1
Bug 968016 - Call MediaDecoderStateMachine::Init() in MediaSourceDecoder::Load(), like MediaDecoder. r=kinetik Load() is called by the media load algorithm, and this behaviour matches the existing MediaDecoder. Calling MediaDecoderStateMachine::Init() ensures that we'll be able to init the state machine properly (i.e. its soon to be added shared thread pools) before we decode.
content/media/mediasource/MediaSourceDecoder.cpp
--- a/content/media/mediasource/MediaSourceDecoder.cpp
+++ b/content/media/mediasource/MediaSourceDecoder.cpp
@@ -40,17 +40,20 @@ class MediaSourceReader : public MediaDe
 public:
   MediaSourceReader(MediaSourceDecoder* aDecoder)
     : MediaDecoderReader(aDecoder)
   {
   }
 
   nsresult Init(MediaDecoderReader* aCloneDonor) MOZ_OVERRIDE
   {
-    return NS_ERROR_NOT_IMPLEMENTED;
+    // Although we technically don't implement anything here, we return NS_OK
+    // so that when the state machine initializes and calls this function
+    // we don't return an error code back to the media element.
+    return NS_OK;
   }
 
   bool DecodeAudioData() MOZ_OVERRIDE
   {
     if (GetAudioReader()) {
       return GetAudioReader()->DecodeAudioData();
     }
     return false;
@@ -143,17 +146,24 @@ MediaDecoderStateMachine*
 MediaSourceDecoder::CreateStateMachine()
 {
   return new MediaDecoderStateMachine(this, new MediaSourceReader(this));
 }
 
 nsresult
 MediaSourceDecoder::Load(nsIStreamListener**, MediaDecoder*)
 {
-  return NS_OK;
+  MOZ_ASSERT(!mDecoderStateMachine);
+  mDecoderStateMachine = CreateStateMachine();
+  if (!mDecoderStateMachine) {
+    NS_WARNING("Failed to create state machine!");
+    return NS_ERROR_FAILURE;
+  }
+
+  return mDecoderStateMachine->Init(nullptr);
 }
 
 nsresult
 MediaSourceDecoder::GetSeekable(dom::TimeRanges* aSeekable)
 {
   double duration = mMediaSource->Duration();
   if (IsNaN(duration)) {
     // Return empty range.
@@ -167,17 +177,16 @@ MediaSourceDecoder::GetSeekable(dom::Tim
   return NS_OK;
 }
 
 void
 MediaSourceDecoder::AttachMediaSource(dom::MediaSource* aMediaSource)
 {
   MOZ_ASSERT(!mMediaSource && !mDecoderStateMachine);
   mMediaSource = aMediaSource;
-  mDecoderStateMachine = CreateStateMachine();
 }
 
 void
 MediaSourceDecoder::DetachMediaSource()
 {
   mMediaSource = nullptr;
 }