Bug 1568058 - pt 1 - Add DecoderTraits::CreateDemuxer and use it in CreateReader. r=jya
authorMichael Froman <mfroman@mozilla.com>
Thu, 14 Nov 2019 16:06:29 +0000
changeset 502085 ff0b20be880be24af649b8b776608a2672346615
parent 502084 152f204eda63b35bb0d12b989141dd7261d32452
child 502086 08c7f0dd63c8f09cd5c3f678920c9b89622637bc
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1568058
milestone72.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 1568058 - pt 1 - Add DecoderTraits::CreateDemuxer and use it in CreateReader. r=jya CreateDemuxer will be used in MediaBufferDecoder as we remove MediaFormatReader. Differential Revision: https://phabricator.services.mozilla.com/D45094
dom/media/DecoderTraits.cpp
dom/media/DecoderTraits.h
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -223,43 +223,60 @@ bool DecoderTraits::ShouldHandleMediaTyp
       return false;
     }
   }
 
   return CanHandleMediaType(*containerType, aDiagnostics) != CANPLAY_NO;
 }
 
 /* static */
-MediaFormatReader* DecoderTraits::CreateReader(const MediaContainerType& aType,
-                                               MediaFormatReaderInit& aInit) {
+already_AddRefed<MediaDataDemuxer> DecoderTraits::CreateDemuxer(
+    const MediaContainerType& aType, MediaResource* aResource) {
   MOZ_ASSERT(NS_IsMainThread());
-  MediaFormatReader* decoderReader = nullptr;
-  MediaResource* resource = aInit.mResource;
+  RefPtr<MediaDataDemuxer> demuxer;
 
 #ifdef MOZ_FMP4
   if (MP4Decoder::IsSupportedType(aType,
                                   /* DecoderDoctorDiagnostics* */ nullptr)) {
-    decoderReader = new MediaFormatReader(aInit, new MP4Demuxer(resource));
+    demuxer = new MP4Demuxer(aResource);
   } else
 #endif
       if (MP3Decoder::IsSupportedType(aType)) {
-    decoderReader = new MediaFormatReader(aInit, new MP3Demuxer(resource));
+    demuxer = new MP3Demuxer(aResource);
   } else if (ADTSDecoder::IsSupportedType(aType)) {
-    decoderReader = new MediaFormatReader(aInit, new ADTSDemuxer(resource));
+    demuxer = new ADTSDemuxer(aResource);
   } else if (WaveDecoder::IsSupportedType(aType)) {
-    decoderReader = new MediaFormatReader(aInit, new WAVDemuxer(resource));
+    demuxer = new WAVDemuxer(aResource);
   } else if (FlacDecoder::IsSupportedType(aType)) {
-    decoderReader = new MediaFormatReader(aInit, new FlacDemuxer(resource));
+    demuxer = new FlacDemuxer(aResource);
   } else if (OggDecoder::IsSupportedType(aType)) {
-    RefPtr<OggDemuxer> demuxer = new OggDemuxer(resource);
-    decoderReader = new MediaFormatReader(aInit, demuxer);
-    demuxer->SetChainingEvents(&decoderReader->TimedMetadataProducer(),
-                               &decoderReader->MediaNotSeekableProducer());
+    demuxer = new OggDemuxer(aResource);
   } else if (WebMDecoder::IsSupportedType(aType)) {
-    decoderReader = new MediaFormatReader(aInit, new WebMDemuxer(resource));
+    demuxer = new WebMDemuxer(aResource);
+  }
+
+  return demuxer.forget();
+}
+
+/* static */
+MediaFormatReader* DecoderTraits::CreateReader(const MediaContainerType& aType,
+                                               MediaFormatReaderInit& aInit) {
+  MOZ_ASSERT(NS_IsMainThread());
+
+  RefPtr<MediaDataDemuxer> demuxer = CreateDemuxer(aType, aInit.mResource);
+  if (!demuxer) {
+    return nullptr;
+  }
+
+  MediaFormatReader* decoderReader = new MediaFormatReader(aInit, demuxer);
+
+  if (OggDecoder::IsSupportedType(aType)) {
+    static_cast<OggDemuxer*>(demuxer.get())
+        ->SetChainingEvents(&decoderReader->TimedMetadataProducer(),
+                            &decoderReader->MediaNotSeekableProducer());
   }
 
   return decoderReader;
 }
 
 /* static */
 bool DecoderTraits::IsSupportedType(const MediaContainerType& aType) {
   typedef bool (*IsSupportedFunction)(const MediaContainerType& aType);
--- a/dom/media/DecoderTraits.h
+++ b/dom/media/DecoderTraits.h
@@ -10,18 +10,20 @@
 #include "mozilla/UniquePtr.h"
 #include "nsStringFwd.h"
 #include "nsTArray.h"
 
 namespace mozilla {
 
 class DecoderDoctorDiagnostics;
 class MediaContainerType;
+class MediaDataDemuxer;
 struct MediaFormatReaderInit;
 class MediaFormatReader;
+class MediaResource;
 class TrackInfo;
 
 enum CanPlayStatus { CANPLAY_NO, CANPLAY_MAYBE, CANPLAY_YES };
 
 class DecoderTraits {
  public:
   // Returns the CanPlayStatus indicating if we can handle this container type.
   static CanPlayStatus CanHandleContainerType(
@@ -30,16 +32,21 @@ class DecoderTraits {
 
   // Returns true if we should handle this MIME type when it appears
   // as an <object> or as a toplevel page. If, in practice, our support
   // for the type is more limited than appears in the wild, we should return
   // false here even if CanHandleMediaType would return true.
   static bool ShouldHandleMediaType(const char* aMIMEType,
                                     DecoderDoctorDiagnostics* aDiagnostics);
 
+  // Create a demuxer for the given MIME type aType.  Returns null if we
+  // were unable to create the demuxer.
+  static already_AddRefed<MediaDataDemuxer> CreateDemuxer(
+      const MediaContainerType& aType, MediaResource* aResource);
+
   // Create a reader for thew given MIME type aType. Returns null
   // if we were unable to create the reader.
   static MediaFormatReader* CreateReader(const MediaContainerType& aType,
                                          MediaFormatReaderInit& aInit);
 
   // Returns true if MIME type aType is supported in video documents,
   // or false otherwise. Not all platforms support all MIME types, and
   // vice versa.