Bug 1053674 - Remove subclass of StateMachine and use task queue directly. r=cpearce
authorMatthew Gregan <kinetik@flim.org>
Sun, 17 Aug 2014 23:29:00 +1200
changeset 200048 65c3554ccc07bb6e9ba81a85683955f20ebe5fae
parent 200047 81585a1201ac792f1ae4c5423a952129f9a3d153
child 200049 6b75f748388a317fb7b088613b5990c62757f07b
child 200127 0b83d221b3d3807a78ccdaf84aff75c7715c236b
push id27330
push useremorley@mozilla.com
push dateMon, 18 Aug 2014 13:22:34 +0000
treeherdermozilla-central@6b75f748388a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1053674
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1053674 - Remove subclass of StateMachine and use task queue directly. r=cpearce
content/media/mediasource/MediaSourceDecoder.cpp
content/media/mediasource/MediaSourceDecoder.h
content/media/mediasource/MediaSourceReader.cpp
content/media/mediasource/MediaSourceReader.h
--- a/content/media/mediasource/MediaSourceDecoder.cpp
+++ b/content/media/mediasource/MediaSourceDecoder.cpp
@@ -24,72 +24,34 @@ extern PRLogModuleInfo* GetMediaSourceAP
 #define MSE_DEBUGV(...)
 #define MSE_API(...)
 #endif
 
 namespace mozilla {
 
 class SubBufferDecoder;
 
-class MediaSourceStateMachine : public MediaDecoderStateMachine
-{
-public:
-  MediaSourceStateMachine(MediaDecoder* aDecoder,
-                          MediaDecoderReader* aReader,
-                          bool aRealTime = false)
-    : MediaDecoderStateMachine(aDecoder, aReader, aRealTime)
-  {
-  }
-
-  already_AddRefed<SubBufferDecoder> CreateSubDecoder(const nsACString& aType,
-                                                      MediaSourceDecoder* aParentDecoder) {
-    if (!mReader) {
-      return nullptr;
-    }
-    MediaSourceReader* reader = static_cast<MediaSourceReader*>(mReader.get());
-    return reader->CreateSubDecoder(aType, aParentDecoder, mDecodeTaskQueue);
-  }
-
-  nsresult EnqueueDecoderInitialization() {
-    AssertCurrentThreadInMonitor();
-    if (!mReader) {
-      return NS_ERROR_FAILURE;
-    }
-    RefPtr<nsIRunnable> task =
-      NS_NewRunnableMethod(this, &MediaSourceStateMachine::InitializePendingDecoders);
-    return mDecodeTaskQueue->Dispatch(task);
-  }
-
-private:
-  void InitializePendingDecoders() {
-    if (!mReader) {
-      return;
-    }
-    MediaSourceReader* reader = static_cast<MediaSourceReader*>(mReader.get());
-    reader->InitializePendingDecoders();
-  }
-};
-
 MediaSourceDecoder::MediaSourceDecoder(dom::HTMLMediaElement* aElement)
   : mMediaSource(nullptr)
 {
   Init(aElement);
 }
 
 MediaDecoder*
 MediaSourceDecoder::Clone()
 {
   // TODO: Sort out cloning.
   return nullptr;
 }
 
 MediaDecoderStateMachine*
 MediaSourceDecoder::CreateStateMachine()
 {
-  return new MediaSourceStateMachine(this, new MediaSourceReader(this, mMediaSource));
+  mReader = new MediaSourceReader(this, mMediaSource);
+  return new MediaDecoderStateMachine(this, mReader);
 }
 
 nsresult
 MediaSourceDecoder::Load(nsIStreamListener**, MediaDecoder*)
 {
   MOZ_ASSERT(!mDecoderStateMachine);
   mDecoderStateMachine = CreateStateMachine();
   if (!mDecoderStateMachine) {
@@ -143,26 +105,12 @@ void
 MediaSourceDecoder::DetachMediaSource()
 {
   mMediaSource = nullptr;
 }
 
 already_AddRefed<SubBufferDecoder>
 MediaSourceDecoder::CreateSubDecoder(const nsACString& aType)
 {
-  if (!mDecoderStateMachine) {
-    return nullptr;
-  }
-  MediaSourceStateMachine* sm = static_cast<MediaSourceStateMachine*>(mDecoderStateMachine.get());
-  return sm->CreateSubDecoder(aType, this);
-}
-
-nsresult
-MediaSourceDecoder::EnqueueDecoderInitialization()
-{
-  if (!mDecoderStateMachine) {
-    return NS_ERROR_FAILURE;
-  }
-  MediaSourceStateMachine* sm = static_cast<MediaSourceStateMachine*>(mDecoderStateMachine.get());
-  return sm->EnqueueDecoderInitialization();
+  return mReader->CreateSubDecoder(aType, this);
 }
 
 } // namespace mozilla
--- a/content/media/mediasource/MediaSourceDecoder.h
+++ b/content/media/mediasource/MediaSourceDecoder.h
@@ -13,16 +13,17 @@
 #include "MediaDecoder.h"
 
 class nsIStreamListener;
 
 namespace mozilla {
 
 class MediaResource;
 class MediaDecoderStateMachine;
+class MediaSourceReader;
 class SubBufferDecoder;
 
 namespace dom {
 
 class HTMLMediaElement;
 class MediaSource;
 
 } // namespace dom
@@ -39,20 +40,19 @@ public:
 
   static already_AddRefed<MediaResource> CreateResource();
 
   void AttachMediaSource(dom::MediaSource* aMediaSource);
   void DetachMediaSource();
 
   already_AddRefed<SubBufferDecoder> CreateSubDecoder(const nsACString& aType);
 
-  nsresult EnqueueDecoderInitialization();
-
 private:
   // The owning MediaSource holds a strong reference to this decoder, and
   // calls Attach/DetachMediaSource on this decoder to set and clear
   // mMediaSource.
   dom::MediaSource* mMediaSource;
+  nsRefPtr<MediaSourceReader> mReader;
 };
 
 } // namespace mozilla
 
 #endif /* MOZILLA_MEDIASOURCEDECODER_H_ */
--- a/content/media/mediasource/MediaSourceReader.cpp
+++ b/content/media/mediasource/MediaSourceReader.cpp
@@ -294,40 +294,41 @@ CreateReaderForType(const nsACString& aT
     return new MP4Reader(aDecoder);
   }
 #endif
   return DecoderTraits::CreateReader(aType, aDecoder);
 }
 
 already_AddRefed<SubBufferDecoder>
 MediaSourceReader::CreateSubDecoder(const nsACString& aType,
-                                    MediaSourceDecoder* aParentDecoder,
-                                    MediaTaskQueue* aTaskQueue)
+                                    MediaSourceDecoder* aParentDecoder)
 {
   // XXX: Why/when is mDecoder null here, since it should be equal to aParentDecoder?!
   nsRefPtr<SubBufferDecoder> decoder =
     new SubBufferDecoder(new SourceBufferResource(nullptr, aType), aParentDecoder);
   nsRefPtr<MediaDecoderReader> reader(CreateReaderForType(aType, decoder));
   if (!reader) {
     return nullptr;
   }
   // Set a callback on the subreader that forwards calls to this reader.
   // This reader will then forward them onto the state machine via this
   // reader's callback.
   RefPtr<MediaDataDecodedListener<MediaSourceReader>> callback =
-    new MediaDataDecodedListener<MediaSourceReader>(this, aTaskQueue);
+    new MediaDataDecodedListener<MediaSourceReader>(this, GetTaskQueue());
   reader->SetCallback(callback);
-  reader->SetTaskQueue(aTaskQueue);
+  reader->SetTaskQueue(GetTaskQueue());
   reader->Init(nullptr);
   ReentrantMonitorAutoEnter mon(aParentDecoder->GetReentrantMonitor());
   MSE_DEBUG("MediaSourceReader(%p)::CreateSubDecoder subdecoder %p subreader %p",
             this, decoder.get(), reader.get());
   decoder->SetReader(reader);
   mPendingDecoders.AppendElement(decoder);
-  if (NS_FAILED(static_cast<MediaSourceDecoder*>(mDecoder)->EnqueueDecoderInitialization())) {
+  RefPtr<nsIRunnable> task =
+    NS_NewRunnableMethod(this, &MediaSourceReader::InitializePendingDecoders);
+  if (NS_FAILED(GetTaskQueue()->Dispatch(task))) {
     MSE_DEBUG("MediaSourceReader(%p): Failed to enqueue decoder initialization task", this);
     return nullptr;
   }
   mDecoder->NotifyWaitingForResourcesStatusChanged();
   return decoder.forget();
 }
 
 namespace {
--- a/content/media/mediasource/MediaSourceReader.h
+++ b/content/media/mediasource/MediaSourceReader.h
@@ -66,18 +66,17 @@ public:
   }
 
   bool IsMediaSeekable() { return true; }
 
   nsresult ReadMetadata(MediaInfo* aInfo, MetadataTags** aTags) MOZ_OVERRIDE;
   nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime,
                 int64_t aCurrentTime) MOZ_OVERRIDE;
   already_AddRefed<SubBufferDecoder> CreateSubDecoder(const nsACString& aType,
-                                                      MediaSourceDecoder* aParentDecoder,
-                                                      MediaTaskQueue* aTaskQueue);
+                                                      MediaSourceDecoder* aParentDecoder);
 
   void Shutdown();
 
   virtual void BreakCycles();
 
   void InitializePendingDecoders();
 
   bool IsShutdown()