Bug 1374930. P1 - add ChannelMediaDecoder to be the base class which uses channel-based MediaResource. draft
authorJW Wang <jwwang@mozilla.com>
Mon, 19 Jun 2017 15:50:09 +0800
changeset 597905 7ca40d667a8eb72a2f0a416b6dea87b87a25bcbb
parent 597852 2eb624855c9f0185aa688d613c9bba6be3611b6e
child 597906 8a36827a5ac8c3689b676dda9855297918ca5181
push id65083
push userjwwang@mozilla.com
push dateWed, 21 Jun 2017 06:17:02 +0000
bugs1374930
milestone56.0a1
Bug 1374930. P1 - add ChannelMediaDecoder to be the base class which uses channel-based MediaResource. MozReview-Commit-ID: 6L4me2BQkgi
dom/media/ADTSDecoder.h
dom/media/ChannelMediaDecoder.cpp
dom/media/ChannelMediaDecoder.h
dom/media/DecoderTraits.cpp
dom/media/DecoderTraits.h
dom/media/android/AndroidMediaDecoder.cpp
dom/media/android/AndroidMediaDecoder.h
dom/media/flac/FlacDecoder.h
dom/media/fmp4/MP4Decoder.cpp
dom/media/fmp4/MP4Decoder.h
dom/media/hls/HLSDecoder.h
dom/media/moz.build
dom/media/mp3/MP3Decoder.h
dom/media/ogg/OggDecoder.h
dom/media/wave/WaveDecoder.h
dom/media/webm/WebMDecoder.h
--- a/dom/media/ADTSDecoder.h
+++ b/dom/media/ADTSDecoder.h
@@ -2,27 +2,30 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef ADTS_DECODER_H_
 #define ADTS_DECODER_H_
 
-#include "MediaDecoder.h"
+#include "ChannelMediaDecoder.h"
 
 namespace mozilla {
 
 class MediaContainerType;
 
-class ADTSDecoder : public MediaDecoder
+class ADTSDecoder : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
-  explicit ADTSDecoder(MediaDecoderInit& aInit) : MediaDecoder(aInit) {}
+  explicit ADTSDecoder(MediaDecoderInit& aInit)
+    : ChannelMediaDecoder(aInit)
+  {
+  }
   MediaDecoder* Clone(MediaDecoderInit& aInit) override;
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   // Returns true if the ADTS backend is pref'ed on, and we're running on a
   // platform that is likely to have decoders for the format.
   static bool IsEnabled();
   static bool IsSupportedType(const MediaContainerType& aContainerType);
 };
new file mode 100644
--- /dev/null
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -0,0 +1,17 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "ChannelMediaDecoder.h"
+#include "MediaResource.h"
+
+namespace mozilla {
+
+ChannelMediaDecoder::ChannelMediaDecoder(MediaDecoderInit& aInit)
+  : MediaDecoder(aInit)
+{
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/media/ChannelMediaDecoder.h
@@ -0,0 +1,22 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef ChannelMediaDecoder_h_
+#define ChannelMediaDecoder_h_
+
+#include "MediaDecoder.h"
+
+namespace mozilla {
+
+class ChannelMediaDecoder : public MediaDecoder
+{
+public:
+  explicit ChannelMediaDecoder(MediaDecoderInit& aInit);
+};
+
+} // namespace mozilla
+
+#endif // ChannelMediaDecoder_h_
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "ChannelMediaDecoder.h"
 #include "DecoderTraits.h"
 #include "MediaContainerType.h"
-#include "MediaDecoder.h"
 #include "nsMimeTypes.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 
 #include "OggDecoder.h"
 #include "OggDemuxer.h"
 
 #include "WebMDecoder.h"
@@ -258,24 +258,23 @@ bool DecoderTraits::ShouldHandleMediaTyp
       return false;
     }
   }
 
   return CanHandleMediaType(*containerType, aDiagnostics) != CANPLAY_NO;
 }
 
 // Instantiates but does not initialize decoder.
-static
-already_AddRefed<MediaDecoder>
+static already_AddRefed<ChannelMediaDecoder>
 InstantiateDecoder(const MediaContainerType& aType,
                    MediaDecoderInit& aInit,
                    DecoderDoctorDiagnostics* aDiagnostics)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  RefPtr<MediaDecoder> decoder;
+  RefPtr<ChannelMediaDecoder> decoder;
 
 #ifdef MOZ_ANDROID_HLS_SUPPORT
   if (HLSDecoder::IsSupportedType(aType)) {
     decoder = new HLSDecoder(aInit);
     return decoder.forget();
   }
 #endif
 #ifdef MOZ_FMP4
@@ -321,17 +320,17 @@ InstantiateDecoder(const MediaContainerT
     // We don't have an HLS decoder.
     Telemetry::Accumulate(Telemetry::MEDIA_HLS_DECODER_SUCCESS, false);
   }
 
   return nullptr;
 }
 
 /* static */
-already_AddRefed<MediaDecoder>
+already_AddRefed<ChannelMediaDecoder>
 DecoderTraits::CreateDecoder(const nsACString& aType,
                              MediaDecoderInit& aInit,
                              DecoderDoctorDiagnostics* aDiagnostics)
 {
   MOZ_ASSERT(NS_IsMainThread());
   Maybe<MediaContainerType> type = MakeMediaContainerType(aType);
   if (!type) {
     return nullptr;
--- a/dom/media/DecoderTraits.h
+++ b/dom/media/DecoderTraits.h
@@ -10,19 +10,19 @@
 #include "nsCOMPtr.h"
 
 class nsAString;
 class nsACString;
 
 namespace mozilla {
 
 class AbstractMediaDecoder;
+class ChannelMediaDecoder;
 class DecoderDoctorDiagnostics;
 class MediaContainerType;
-class MediaDecoder;
 struct MediaDecoderInit;
 class MediaDecoderOwner;
 class MediaDecoderReader;
 
 enum CanPlayStatus {
   CANPLAY_NO,
   CANPLAY_MAYBE,
   CANPLAY_YES
@@ -38,19 +38,20 @@ public:
   // 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 decoder for the given aType. Returns null if we
   // were unable to create the decoder.
-  static already_AddRefed<MediaDecoder> CreateDecoder(const nsACString& aType,
-                                                      MediaDecoderInit& aInit,
-                                                      DecoderDoctorDiagnostics* aDiagnostics);
+  static already_AddRefed<ChannelMediaDecoder> CreateDecoder(
+    const nsACString& aType,
+    MediaDecoderInit& aInit,
+    DecoderDoctorDiagnostics* aDiagnostics);
 
   // Create a reader for thew given MIME type aType. Returns null
   // if we were unable to create the reader.
   static MediaDecoderReader* CreateReader(const MediaContainerType& aType,
                                           AbstractMediaDecoder* aDecoder);
 
   // Returns true if MIME type aType is supported in video documents,
   // or false otherwise. Not all platforms support all MIME types, and
--- a/dom/media/android/AndroidMediaDecoder.cpp
+++ b/dom/media/android/AndroidMediaDecoder.cpp
@@ -7,17 +7,18 @@
 #include "MediaDecoderStateMachine.h"
 #include "AndroidMediaDecoder.h"
 #include "AndroidMediaReader.h"
 
 namespace mozilla {
 
 AndroidMediaDecoder::AndroidMediaDecoder(MediaDecoderInit& aInit,
                                          const MediaContainerType& aType)
-  : MediaDecoder(aInit), mType(aType)
+  : ChannelMediaDecoder(aInit)
+  , mType(aType)
 {
 }
 
 MediaDecoderStateMachine* AndroidMediaDecoder::CreateStateMachine()
 {
   return new MediaDecoderStateMachine(this, new AndroidMediaReader(this, mType));
 }
 
--- a/dom/media/android/AndroidMediaDecoder.h
+++ b/dom/media/android/AndroidMediaDecoder.h
@@ -1,23 +1,23 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 #if !defined(AndroidMediaDecoder_h_)
 #define AndroidMediaDecoder_h_
 
-#include "MediaDecoder.h"
+#include "ChannelMediaDecoder.h"
 #include "AndroidMediaDecoder.h"
 #include "MediaContainerType.h"
 
 namespace mozilla {
 
-class AndroidMediaDecoder : public MediaDecoder
+class AndroidMediaDecoder : public ChannelMediaDecoder
 {
   MediaContainerType mType;
 public:
   AndroidMediaDecoder(MediaDecoderInit& aInit, const MediaContainerType& aType);
 
   MediaDecoder* Clone(MediaDecoderInit& aInit) override {
     return new AndroidMediaDecoder(aInit, mType);
   }
--- a/dom/media/flac/FlacDecoder.h
+++ b/dom/media/flac/FlacDecoder.h
@@ -2,27 +2,30 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef FLAC_DECODER_H_
 #define FLAC_DECODER_H_
 
-#include "MediaDecoder.h"
+#include "ChannelMediaDecoder.h"
 
 namespace mozilla {
 
 class MediaContainerType;
 
-class FlacDecoder : public MediaDecoder
+class FlacDecoder : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
-  explicit FlacDecoder(MediaDecoderInit& aInit) : MediaDecoder(aInit) {}
+  explicit FlacDecoder(MediaDecoderInit& aInit)
+    : ChannelMediaDecoder(aInit)
+  {
+  }
   MediaDecoder* Clone(MediaDecoderInit& aInit) override;
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   // Returns true if the Flac backend is pref'ed on, and we're running on a
   // platform that is likely to have decoders for the format.
   static bool IsEnabled();
   static bool IsSupportedType(const MediaContainerType& aContainerType);
 };
--- a/dom/media/fmp4/MP4Decoder.cpp
+++ b/dom/media/fmp4/MP4Decoder.cpp
@@ -21,17 +21,17 @@
 #endif
 #include "mozilla/layers/LayersTypes.h"
 
 #include "PDMFactory.h"
 
 namespace mozilla {
 
 MP4Decoder::MP4Decoder(MediaDecoderInit& aInit)
-  : MediaDecoder(aInit)
+  : ChannelMediaDecoder(aInit)
 {
 }
 
 MediaDecoderStateMachine* MP4Decoder::CreateStateMachine()
 {
   mReader =
     new MediaFormatReader(this,
                           new MP4Demuxer(GetResource()),
--- a/dom/media/fmp4/MP4Decoder.h
+++ b/dom/media/fmp4/MP4Decoder.h
@@ -1,27 +1,27 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #if !defined(MP4Decoder_h_)
 #define MP4Decoder_h_
 
-#include "MediaDecoder.h"
+#include "ChannelMediaDecoder.h"
 #include "MediaFormatReader.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/layers/KnowsCompositor.h"
 
 namespace mozilla {
 
 class MediaContainerType;
 
 // Decoder that uses a bundled MP4 demuxer and platform decoders to play MP4.
-class MP4Decoder : public MediaDecoder
+class MP4Decoder : public ChannelMediaDecoder
 {
 public:
   explicit MP4Decoder(MediaDecoderInit& aInit);
 
   MediaDecoder* Clone(MediaDecoderInit& aInit) override {
     if (!IsEnabled()) {
       return nullptr;
     }
--- a/dom/media/hls/HLSDecoder.h
+++ b/dom/media/hls/HLSDecoder.h
@@ -2,38 +2,41 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef HLSDecoder_h_
 #define HLSDecoder_h_
 
-#include "MediaDecoder.h"
+#include "ChannelMediaDecoder.h"
 
 namespace mozilla {
 class MediaFormatReader;
 
-class HLSDecoder final : public MediaDecoder
+class HLSDecoder final : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
-    explicit HLSDecoder(MediaDecoderInit& aInit) : MediaDecoder(aInit) { }
+  explicit HLSDecoder(MediaDecoderInit& aInit)
+    : ChannelMediaDecoder(aInit)
+  {
+  }
 
-    MediaDecoder* Clone(MediaDecoderInit& aInit) override;
-
-    MediaDecoderStateMachine* CreateStateMachine() override;
+  MediaDecoder* Clone(MediaDecoderInit& aInit) override;
 
-    // Returns true if the HLS backend is pref'ed on.
-    static bool IsEnabled();
+  MediaDecoderStateMachine* CreateStateMachine() override;
+
+  // Returns true if the HLS backend is pref'ed on.
+  static bool IsEnabled();
 
-    // Returns true if aContainerType is an HLS type that we think we can render
-    // with the a platform decoder backend.
-    // If provided, codecs are checked for support.
-    static bool IsSupportedType(const MediaContainerType& aContainerType);
+  // Returns true if aContainerType is an HLS type that we think we can render
+  // with the a platform decoder backend.
+  // If provided, codecs are checked for support.
+  static bool IsSupportedType(const MediaContainerType& aContainerType);
 
 private:
   RefPtr<MediaFormatReader> mReader;
 };
 
 } // namespace mozilla
 
 #endif /* HLSDecoder_h_ */
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -94,16 +94,17 @@ EXPORTS += [
     'AudioConverter.h',
     'AudioMixer.h',
     'AudioPacketizer.h',
     'AudioSampleFormat.h',
     'AudioSegment.h',
     'AudioStream.h',
     'Benchmark.h',
     'BufferMediaResource.h',
+    'ChannelMediaDecoder.h',
     'CubebUtils.h',
     'DecoderDoctorDiagnostics.h',
     'DecoderTraits.h',
     'DOMMediaStream.h',
     'EncodedBufferCache.h',
     'FileBlockCache.h',
     'FrameStatistics.h',
     'Intervals.h',
@@ -203,16 +204,17 @@ UNIFIED_SOURCES += [
     'AudioConverter.cpp',
     'AudioSegment.cpp',
     'AudioStream.cpp',
     'AudioStreamTrack.cpp',
     'AudioTrack.cpp',
     'AudioTrackList.cpp',
     'Benchmark.cpp',
     'CanvasCaptureMediaStream.cpp',
+    'ChannelMediaDecoder.cpp',
     'CubebUtils.cpp',
     'DecoderDoctorDiagnostics.cpp',
     'DOMMediaStream.cpp',
     'EncodedBufferCache.cpp',
     'FileBlockCache.cpp',
     'GetUserMediaRequest.cpp',
     'GraphDriver.cpp',
     'Latency.cpp',
--- a/dom/media/mp3/MP3Decoder.h
+++ b/dom/media/mp3/MP3Decoder.h
@@ -1,27 +1,30 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef MP3Decoder_h_
 #define MP3Decoder_h_
 
-#include "MediaDecoder.h"
+#include "ChannelMediaDecoder.h"
 
 namespace mozilla {
 
 class MediaContainerType;
 
-class MP3Decoder : public MediaDecoder
+class MP3Decoder : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
-  explicit MP3Decoder(MediaDecoderInit& aInit) : MediaDecoder(aInit) {}
+  explicit MP3Decoder(MediaDecoderInit& aInit)
+    : ChannelMediaDecoder(aInit)
+  {
+  }
   MediaDecoder* Clone(MediaDecoderInit& aInit) override;
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   // Returns true if the MP3 backend is preffed on, and we're running on a
   // platform that is likely to have decoders for the format.
   static bool IsEnabled();
   static bool IsSupportedType(const MediaContainerType& aContainerType);
 };
--- a/dom/media/ogg/OggDecoder.h
+++ b/dom/media/ogg/OggDecoder.h
@@ -1,27 +1,27 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #if !defined(OggDecoder_h_)
 #define OggDecoder_h_
 
-#include "MediaDecoder.h"
+#include "ChannelMediaDecoder.h"
 
 namespace mozilla {
 
 class MediaContainerType;
 
-class OggDecoder : public MediaDecoder
+class OggDecoder : public ChannelMediaDecoder
 {
 public:
   explicit OggDecoder(MediaDecoderInit& aInit)
-    : MediaDecoder(aInit)
+    : ChannelMediaDecoder(aInit)
   {}
 
   MediaDecoder* Clone(MediaDecoderInit& aInit) override {
     if (!IsOggEnabled()) {
       return nullptr;
     }
     return new OggDecoder(aInit);
   }
--- a/dom/media/wave/WaveDecoder.h
+++ b/dom/media/wave/WaveDecoder.h
@@ -1,27 +1,30 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #if !defined(WaveDecoder_h_)
 #define WaveDecoder_h_
 
-#include "MediaDecoder.h"
+#include "ChannelMediaDecoder.h"
 
 namespace mozilla {
 
 class MediaContainerType;
 
-class WaveDecoder : public MediaDecoder
+class WaveDecoder : public ChannelMediaDecoder
 {
 public:
   // MediaDecoder interface.
-  explicit WaveDecoder(MediaDecoderInit& aInit) : MediaDecoder(aInit) {}
+  explicit WaveDecoder(MediaDecoderInit& aInit)
+    : ChannelMediaDecoder(aInit)
+  {
+  }
   MediaDecoder* Clone(MediaDecoderInit& aInit) override;
   MediaDecoderStateMachine* CreateStateMachine() override;
 
   // Returns true if the Wave backend is pref'ed on, and we're running on a
   // platform that is likely to have decoders for the format.
   static bool IsSupportedType(const MediaContainerType& aContainerType);
 };
 
--- a/dom/media/webm/WebMDecoder.h
+++ b/dom/media/webm/WebMDecoder.h
@@ -1,27 +1,30 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #if !defined(WebMDecoder_h_)
 #define WebMDecoder_h_
 
-#include "MediaDecoder.h"
+#include "ChannelMediaDecoder.h"
 #include "MediaFormatReader.h"
 
 namespace mozilla {
 
 class MediaContainerType;
 
-class WebMDecoder : public MediaDecoder
+class WebMDecoder : public ChannelMediaDecoder
 {
 public:
-  explicit WebMDecoder(MediaDecoderInit& aInit) : MediaDecoder(aInit) {}
+  explicit WebMDecoder(MediaDecoderInit& aInit)
+    : ChannelMediaDecoder(aInit)
+  {
+  }
   MediaDecoder* Clone(MediaDecoderInit& aInit) override {
     if (!IsWebMEnabled()) {
       return nullptr;
     }
     return new WebMDecoder(aInit);
   }
   MediaDecoderStateMachine* CreateStateMachine() override;