Bug 1041919 - Always use MP4Reader/PDM in MediaSourceDecoder. r=cpearce
authorMatthew Gregan <kinetik@flim.org>
Tue, 22 Jul 2014 20:20:00 +1200
changeset 217445 4493663d7cfeaed5187439a88152577d41256e83
parent 217444 0a992213834737bb7e6891ca077bae8a8bc5a1fa
child 217446 810b3536cb50995e807269b4349fc1e2b952e65b
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1041919
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 1041919 - Always use MP4Reader/PDM in MediaSourceDecoder. r=cpearce
content/media/mediasource/MediaSourceDecoder.cpp
--- a/content/media/mediasource/MediaSourceDecoder.cpp
+++ b/content/media/mediasource/MediaSourceDecoder.cpp
@@ -19,16 +19,21 @@
 #include "nsIThread.h"
 #include "prlog.h"
 #include "MediaSource.h"
 #include "SubBufferDecoder.h"
 #include "SourceBufferResource.h"
 #include "SourceBufferList.h"
 #include "VideoUtils.h"
 
+#ifdef MOZ_FMP4
+#include "MP4Decoder.h"
+#include "MP4Reader.h"
+#endif
+
 #ifdef PR_LOGGING
 extern PRLogModuleInfo* gMediaSourceLog;
 #define MSE_DEBUG(...) PR_LOG(gMediaSourceLog, PR_LOG_DEBUG, (__VA_ARGS__))
 #else
 #define MSE_DEBUG(...)
 #endif
 
 namespace mozilla {
@@ -413,25 +418,42 @@ MediaSourceReader::InitializePendingDeco
       MSE_DEBUG("%p: Reader %p not activated", this, reader);
     }
   }
   NS_DispatchToMainThread(new ReleaseDecodersTask(mPendingDecoders));
   MOZ_ASSERT(mPendingDecoders.IsEmpty());
   mDecoder->NotifyWaitingForResourcesStatusChanged();
 }
 
+MediaDecoderReader*
+CreateReaderForType(const nsACString& aType, AbstractMediaDecoder* aDecoder)
+{
+#ifdef MOZ_FMP4
+  // The MP4Reader that supports fragmented MP4 and uses
+  // PlatformDecoderModules is hidden behind prefs for regular video
+  // elements, but we always want to use it for MSE, so instantiate it
+  // directly here.
+  if ((aType.LowerCaseEqualsLiteral("video/mp4") ||
+       aType.LowerCaseEqualsLiteral("audio/mp4")) &&
+      MP4Decoder::IsEnabled()) {
+    return new MP4Reader(aDecoder);
+  }
+#endif
+  return DecoderTraits::CreateReader(aType, aDecoder);
+}
+
 already_AddRefed<SubBufferDecoder>
 MediaSourceReader::CreateSubDecoder(const nsACString& aType,
                                     MediaSourceDecoder* aParentDecoder,
                                     MediaTaskQueue* aTaskQueue)
 {
   // 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(DecoderTraits::CreateReader(aType, decoder));
+  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);