From 38ce1ea2a06d6539fe687c5632935e055fd16b32 Mon Sep 17 00:00:00 2001 From: Phil Ringnalda Date: Wed, 16 Aug 2017 21:33:10 -0700 Subject: [PATCH] Backed out 10 changesets (bug 1390748) for build bustage Backed out changeset 02b36ee5fb17 (bug 1390748) Backed out changeset 84e8bf01c856 (bug 1390748) Backed out changeset fc8989be30f3 (bug 1390748) Backed out changeset 14d421ace6cc (bug 1390748) Backed out changeset 7dadac869038 (bug 1390748) Backed out changeset 0e77809e7bc2 (bug 1390748) Backed out changeset bf78a8dce9c5 (bug 1390748) Backed out changeset 5fa77990472e (bug 1390748) Backed out changeset 5d3b637d2485 (bug 1390748) Backed out changeset 634fe076d134 (bug 1390748) MozReview-Commit-ID: Dxio8vXDCHg --- dom/base/nsContentUtils.cpp | 2 + dom/base/nsDOMWindowUtils.cpp | 3 + dom/html/HTMLMediaElement.cpp | 11 ---- dom/html/HTMLMediaElement.h | 14 +++-- dom/html/HTMLVideoElement.h | 3 - dom/media/ADTSDecoder.cpp | 10 +++ dom/media/ADTSDecoder.h | 13 +++- dom/media/ChannelMediaDecoder.cpp | 4 +- dom/media/ChannelMediaDecoder.h | 6 +- dom/media/DecoderTraits.cpp | 61 ++++++++++--------- dom/media/DecoderTraits.h | 2 - dom/media/MediaDecoder.cpp | 8 --- dom/media/MediaDecoder.h | 7 ++- dom/media/MediaResource.cpp | 1 - dom/media/eme/MediaKeySystemAccess.cpp | 3 + dom/media/eme/MediaKeys.cpp | 3 + dom/media/flac/FlacDecoder.cpp | 11 ++++ dom/media/flac/FlacDecoder.h | 13 +++- dom/media/fmp4/MP4Decoder.cpp | 32 +++++++--- dom/media/fmp4/MP4Decoder.h | 22 +++++-- dom/media/gtest/TestMediaDataDecoder.cpp | 1 + dom/media/mediasource/MediaSourceDecoder.h | 2 +- dom/media/mp3/MP3Decoder.cpp | 12 ++++ dom/media/mp3/MP3Decoder.h | 13 +++- dom/media/ogg/OggDecoder.cpp | 22 ++++++- dom/media/ogg/OggDecoder.h | 19 +++++- .../agnostic/eme/EMEDecoderModule.cpp | 1 + dom/media/wave/WaveDecoder.cpp | 13 +++- dom/media/wave/WaveDecoder.h | 13 +++- dom/media/wave/WaveDemuxer.cpp | 3 +- dom/media/wave/WaveDemuxer.h | 6 +- dom/media/webm/WebMDecoder.cpp | 13 +++- dom/media/webm/WebMDecoder.h | 18 +++++- .../binding/include/mp4_demuxer/ByteReader.h | 5 ++ 34 files changed, 271 insertions(+), 99 deletions(-) diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 27ed38c21212..388ecbb80fae 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -22,6 +22,7 @@ #include "jsfriendapi.h" #include "js/Value.h" #include "Layers.h" +#include "MediaDecoder.h" #include "nsAppRunner.h" // nsNPAPIPluginInstance must be included before nsIDocument.h, which is included in mozAutoDocUpdate.h. #include "nsNPAPIPluginInstance.h" @@ -47,6 +48,7 @@ #include "mozilla/dom/FileSystemSecurity.h" #include "mozilla/dom/FileBlobImpl.h" #include "mozilla/dom/HTMLInputElement.h" +#include "mozilla/dom/HTMLMediaElement.h" #include "mozilla/dom/HTMLTemplateElement.h" #include "mozilla/dom/HTMLContentElement.h" #include "mozilla/dom/HTMLShadowElement.h" diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 98031b6fce0c..96466d68cfd6 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -28,6 +28,9 @@ #include "mozilla/layers/APZCCallbackHelper.h" #include "ClientLayerManager.h" #include "nsQueryObject.h" +#ifdef MOZ_FMP4 +#include "MP4Decoder.h" +#endif #include "CubebUtils.h" #include "nsIScrollableFrame.h" diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 18066bd27b97..9f41f73ed169 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -7153,17 +7153,6 @@ HTMLMediaElement::NextFrameStatus() return NEXT_FRAME_UNINITIALIZED; } - -void -HTMLMediaElement::SetDecoder(MediaDecoder* aDecoder) -{ - MOZ_ASSERT(aDecoder); // Use ShutdownDecoder() to clear. - if (mDecoder) { - ShutdownDecoder(); - } - mDecoder = aDecoder; -} - float HTMLMediaElement::ComputedVolume() const { diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h index 624dac7b3fe4..b80512f7133f 100644 --- a/dom/html/HTMLMediaElement.h +++ b/dom/html/HTMLMediaElement.h @@ -9,8 +9,6 @@ #include "nsAutoPtr.h" #include "nsIDOMHTMLMediaElement.h" #include "nsGenericHTMLElement.h" -#include "MediaEventSource.h" -#include "SeekTarget.h" #include "MediaDecoderOwner.h" #include "nsCycleCollectionParticipant.h" #include "nsIObserver.h" @@ -20,6 +18,7 @@ #include "mozilla/Attributes.h" #include "mozilla/dom/TextTrackManager.h" #include "mozilla/WeakPtr.h" +#include "MediaDecoder.h" #include "mozilla/dom/MediaKeys.h" #include "mozilla/StateWatching.h" #include "nsGkAtoms.h" @@ -50,9 +49,6 @@ class DOMMediaStream; class ErrorResult; class MediaResource; class MediaDecoder; -class MediaInputPort; -class MediaStream; -class MediaStreamGraph; class VideoFrameContainer; namespace dom { class MediaKeys; @@ -812,7 +808,13 @@ protected: MediaDecoderOwner::NextFrameStatus NextFrameStatus(); - void SetDecoder(MediaDecoder* aDecoder); + void SetDecoder(MediaDecoder* aDecoder) { + MOZ_ASSERT(aDecoder); // Use ShutdownDecoder() to clear. + if (mDecoder) { + ShutdownDecoder(); + } + mDecoder = aDecoder; + } class WakeLockBoolWrapper { public: diff --git a/dom/html/HTMLVideoElement.h b/dom/html/HTMLVideoElement.h index a83be6c95a32..8181bc4bc480 100644 --- a/dom/html/HTMLVideoElement.h +++ b/dom/html/HTMLVideoElement.h @@ -11,9 +11,6 @@ #include "mozilla/dom/HTMLMediaElement.h" namespace mozilla { - -class FrameStatistics; - namespace dom { class WakeLock; diff --git a/dom/media/ADTSDecoder.cpp b/dom/media/ADTSDecoder.cpp index 92e0b15bde3a..2db9488342a2 100644 --- a/dom/media/ADTSDecoder.cpp +++ b/dom/media/ADTSDecoder.cpp @@ -5,11 +5,21 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "ADTSDecoder.h" +#include "ADTSDemuxer.h" #include "MediaContainerType.h" #include "PDMFactory.h" namespace mozilla { +ChannelMediaDecoder* +ADTSDecoder::CloneImpl(MediaDecoderInit& aInit) +{ + if (!IsEnabled()) + return nullptr; + + return new ADTSDecoder(aInit); +} + /* static */ bool ADTSDecoder::IsEnabled() { diff --git a/dom/media/ADTSDecoder.h b/dom/media/ADTSDecoder.h index 7356c2e99e4b..809178fea77e 100644 --- a/dom/media/ADTSDecoder.h +++ b/dom/media/ADTSDecoder.h @@ -7,17 +7,28 @@ #ifndef ADTS_DECODER_H_ #define ADTS_DECODER_H_ +#include "ChannelMediaDecoder.h" + namespace mozilla { class MediaContainerType; -class ADTSDecoder +class ADTSDecoder : public ChannelMediaDecoder { public: + // MediaDecoder interface. + explicit ADTSDecoder(MediaDecoderInit& aInit) + : ChannelMediaDecoder(aInit) + { + } + // 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); + +private: + ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override; }; } // namespace mozilla diff --git a/dom/media/ChannelMediaDecoder.cpp b/dom/media/ChannelMediaDecoder.cpp index 3a49b301ea5d..df6ec058eb82 100644 --- a/dom/media/ChannelMediaDecoder.cpp +++ b/dom/media/ChannelMediaDecoder.cpp @@ -174,10 +174,10 @@ ChannelMediaDecoder::CanClone() already_AddRefed ChannelMediaDecoder::Clone(MediaDecoderInit& aInit) { - if (!mResource || !DecoderTraits::IsSupportedType(aInit.mContainerType)) { + if (!mResource) { return nullptr; } - RefPtr decoder = new ChannelMediaDecoder(aInit); + RefPtr decoder = CloneImpl(aInit); if (!decoder) { return nullptr; } diff --git a/dom/media/ChannelMediaDecoder.h b/dom/media/ChannelMediaDecoder.h index bcd889f384b2..37e6cfee1bd0 100644 --- a/dom/media/ChannelMediaDecoder.h +++ b/dom/media/ChannelMediaDecoder.h @@ -67,6 +67,8 @@ protected: public: explicit ChannelMediaDecoder(MediaDecoderInit& aInit); + MediaDecoderStateMachine* CreateStateMachine() override; + MediaResource* GetResource() const override final; void Shutdown() override; @@ -85,9 +87,7 @@ public: void Resume() override; private: - // Create a new state machine to run this decoder. - MediaDecoderStateMachine* CreateStateMachine(); - + virtual ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) = 0; nsresult OpenResource(nsIStreamListener** aStreamListener); nsresult Load(BaseMediaResource* aOriginal); diff --git a/dom/media/DecoderTraits.cpp b/dom/media/DecoderTraits.cpp index cd7756b914d6..5e0d76820711 100644 --- a/dom/media/DecoderTraits.cpp +++ b/dom/media/DecoderTraits.cpp @@ -233,8 +233,36 @@ InstantiateDecoder(MediaDecoderInit& aInit, RefPtr decoder; const MediaContainerType& type = aInit.mContainerType; - if (DecoderTraits::IsSupportedType(type)) { - decoder = new ChannelMediaDecoder(aInit); + +#ifdef MOZ_FMP4 + if (MP4Decoder::IsSupportedType(type, aDiagnostics)) { + decoder = new MP4Decoder(aInit); + return decoder.forget(); + } +#endif + if (MP3Decoder::IsSupportedType(type)) { + decoder = new MP3Decoder(aInit); + return decoder.forget(); + } + if (ADTSDecoder::IsSupportedType(type)) { + decoder = new ADTSDecoder(aInit); + return decoder.forget(); + } + if (OggDecoder::IsSupportedType(type)) { + decoder = new OggDecoder(aInit); + return decoder.forget(); + } + if (WaveDecoder::IsSupportedType(type)) { + decoder = new WaveDecoder(aInit); + return decoder.forget(); + } + if (FlacDecoder::IsSupportedType(type)) { + decoder = new FlacDecoder(aInit); + return decoder.forget(); + } + + if (WebMDecoder::IsSupportedType(type)) { + decoder = new WebMDecoder(aInit); return decoder.forget(); } @@ -283,10 +311,7 @@ DecoderTraits::CreateReader(const MediaContainerType& aType, decoderReader = new MediaFormatReader(aInit, new FlacDemuxer(resource)); } else if (OggDecoder::IsSupportedType(aType)) { - RefPtr demuxer = new OggDemuxer(resource); - decoderReader = new MediaFormatReader(aInit, demuxer); - demuxer->SetChainingEvents(&decoderReader->TimedMetadataProducer(), - &decoderReader->MediaNotSeekableProducer()); + decoderReader = new MediaFormatReader(aInit, new OggDemuxer(resource)); } else if (WebMDecoder::IsSupportedType(aType)) { decoderReader = new MediaFormatReader(aInit, new WebMDemuxer(resource)); @@ -295,30 +320,6 @@ DecoderTraits::CreateReader(const MediaContainerType& aType, return decoderReader; } -/* static */ -bool -DecoderTraits::IsSupportedType(const MediaContainerType& aType) -{ - typedef bool (*IsSupportedFunction)(const MediaContainerType& aType); - static const IsSupportedFunction funcs[] = { - &ADTSDecoder::IsSupportedType, - &FlacDecoder::IsSupportedType, - &MP3Decoder::IsSupportedType, -#ifdef MOZ_FMP4 - &MP4Decoder::IsSupportedTypeWithoutDiagnostics, -#endif - &OggDecoder::IsSupportedType, - &WaveDecoder::IsSupportedType, - &WebMDecoder::IsSupportedType, - }; - for (IsSupportedFunction func : funcs) { - if (func(aType)) { - return true; - } - } - return false; -} - /* static */ bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType) { diff --git a/dom/media/DecoderTraits.h b/dom/media/DecoderTraits.h index f485ae89b9e1..de7890f2d27a 100644 --- a/dom/media/DecoderTraits.h +++ b/dom/media/DecoderTraits.h @@ -65,8 +65,6 @@ public: // Returns true if aType is MIME type of hls. static bool IsHttpLiveStreamingType(const MediaContainerType& aType); - - static bool IsSupportedType(const MediaContainerType& aType); }; } // namespace mozilla diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index e0d2080f2393..2e115a372861 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -1621,14 +1621,6 @@ MediaDecoder::RequestDebugInfo() }); } -void -MediaDecoder::GetMozDebugReaderData(nsACString& aString) -{ - if (mReader) { - mReader->GetMozDebugReaderData(aString); - } -} - void MediaDecoder::NotifyAudibleStateChanged() { diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index 311eb7dfe275..a4514f0c547d 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -108,6 +108,10 @@ public: // Safe to call from any thread. const MediaContainerType& ContainerType() const { return mContainerType; } + // Create a new state machine to run this decoder. + // Subclasses must implement this. + virtual MediaDecoderStateMachine* CreateStateMachine() = 0; + // Cleanup internal data structures. Must be called on the main // thread by the owning object before that object disposes of this object. virtual void Shutdown(); @@ -203,6 +207,7 @@ public: // Must be called before Shutdown(). bool OwnerHasError() const; +public: // Returns true if this media supports random seeking. False for example with // chained ogg files. bool IsMediaSeekable(); @@ -406,7 +411,7 @@ private: // Returns a string describing the state of the media player internal // data. Used for debugging purposes. - virtual void GetMozDebugReaderData(nsACString& aString); + virtual void GetMozDebugReaderData(nsACString& aString) { } virtual void DumpDebugInfo(); diff --git a/dom/media/MediaResource.cpp b/dom/media/MediaResource.cpp index 1f574a4cd0f0..158decfd00e8 100644 --- a/dom/media/MediaResource.cpp +++ b/dom/media/MediaResource.cpp @@ -33,7 +33,6 @@ #include #include "nsProxyRelease.h" #include "nsIContentPolicy.h" -#include "mozilla/ErrorNames.h" using mozilla::media::TimeUnit; diff --git a/dom/media/eme/MediaKeySystemAccess.cpp b/dom/media/eme/MediaKeySystemAccess.cpp index 1a12708784d0..06ca391a1f9e 100644 --- a/dom/media/eme/MediaKeySystemAccess.cpp +++ b/dom/media/eme/MediaKeySystemAccess.cpp @@ -10,6 +10,9 @@ #include "mozilla/Preferences.h" #include "MediaContainerType.h" #include "MediaPrefs.h" +#ifdef MOZ_FMP4 +#include "MP4Decoder.h" +#endif #ifdef XP_WIN #include "WMFDecoderModule.h" #endif diff --git a/dom/media/eme/MediaKeys.cpp b/dom/media/eme/MediaKeys.cpp index 8b91fdc7bc4a..7a79cfff3a13 100644 --- a/dom/media/eme/MediaKeys.cpp +++ b/dom/media/eme/MediaKeys.cpp @@ -23,6 +23,9 @@ #include "nsContentUtils.h" #include "nsIScriptObjectPrincipal.h" #include "nsContentTypeParser.h" +#ifdef MOZ_FMP4 +#include "MP4Decoder.h" +#endif #ifdef XP_WIN #include "mozilla/WindowsVersion.h" #endif diff --git a/dom/media/flac/FlacDecoder.cpp b/dom/media/flac/FlacDecoder.cpp index 9362ba563733..15fd11b6190f 100644 --- a/dom/media/flac/FlacDecoder.cpp +++ b/dom/media/flac/FlacDecoder.cpp @@ -5,11 +5,22 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "FlacDecoder.h" +#include "FlacDemuxer.h" #include "MediaContainerType.h" #include "MediaPrefs.h" namespace mozilla { +ChannelMediaDecoder* +FlacDecoder::CloneImpl(MediaDecoderInit& aInit) +{ + if (!IsEnabled()) { + return nullptr; + } + + return new FlacDecoder(aInit); +} + /* static */ bool FlacDecoder::IsEnabled() { diff --git a/dom/media/flac/FlacDecoder.h b/dom/media/flac/FlacDecoder.h index 9095519121c8..7640d8a3650b 100644 --- a/dom/media/flac/FlacDecoder.h +++ b/dom/media/flac/FlacDecoder.h @@ -7,17 +7,28 @@ #ifndef FLAC_DECODER_H_ #define FLAC_DECODER_H_ +#include "ChannelMediaDecoder.h" + namespace mozilla { class MediaContainerType; -class FlacDecoder +class FlacDecoder : public ChannelMediaDecoder { public: + // MediaDecoder interface. + explicit FlacDecoder(MediaDecoderInit& aInit) + : ChannelMediaDecoder(aInit) + { + } + // 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); + +private: + ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override; }; } // namespace mozilla diff --git a/dom/media/fmp4/MP4Decoder.cpp b/dom/media/fmp4/MP4Decoder.cpp index c8ca166b5bac..47c3027bca74 100644 --- a/dom/media/fmp4/MP4Decoder.cpp +++ b/dom/media/fmp4/MP4Decoder.cpp @@ -6,14 +6,30 @@ #include "MP4Decoder.h" #include "MediaContainerType.h" +#include "MediaFormatReader.h" #include "MP4Demuxer.h" +#include "mozilla/Preferences.h" +#include "nsCharSeparatedTokenizer.h" +#include "mozilla/CDMProxy.h" +#include "mozilla/Logging.h" +#include "mozilla/SharedThreadPool.h" #include "nsMimeTypes.h" #include "VideoUtils.h" +#ifdef MOZ_WIDGET_ANDROID +#include "nsIGfxInfo.h" +#endif +#include "mozilla/layers/LayersTypes.h" + #include "PDMFactory.h" namespace mozilla { +MP4Decoder::MP4Decoder(MediaDecoderInit& aInit) + : ChannelMediaDecoder(aInit) +{ +} + static bool IsWhitelistedH264Codec(const nsAString& aCodec) { @@ -39,14 +55,6 @@ IsWhitelistedH264Codec(const nsAString& aCodec) profile == H264_PROFILE_HIGH); } -/* static */ -bool -MP4Decoder::IsSupportedTypeWithoutDiagnostics( - const MediaContainerType& aContainerType) -{ - return IsSupportedType(aContainerType, nullptr); -} - /* static */ bool MP4Decoder::IsSupportedType(const MediaContainerType& aType, @@ -270,4 +278,12 @@ MP4Decoder::IsVideoAccelerated(layers::KnowsCompositor* aKnowsCompositor, nsIGlo return promise.forget(); } +void +MP4Decoder::GetMozDebugReaderData(nsACString& aString) +{ + if (mReader) { + mReader->GetMozDebugReaderData(aString); + } +} + } // namespace mozilla diff --git a/dom/media/fmp4/MP4Decoder.h b/dom/media/fmp4/MP4Decoder.h index 83f359bb8968..6918d010706c 100644 --- a/dom/media/fmp4/MP4Decoder.h +++ b/dom/media/fmp4/MP4Decoder.h @@ -6,26 +6,26 @@ #if !defined(MP4Decoder_h_) #define MP4Decoder_h_ -class nsACString; +#include "ChannelMediaDecoder.h" +#include "mozilla/dom/Promise.h" +#include "mozilla/layers/KnowsCompositor.h" namespace mozilla { class MediaContainerType; -class DecoderDoctorDiagnostics; // Decoder that uses a bundled MP4 demuxer and platform decoders to play MP4. -class MP4Decoder +class MP4Decoder : public ChannelMediaDecoder { public: + explicit MP4Decoder(MediaDecoderInit& aInit); + // Returns true if aContainerType is an MP4 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, DecoderDoctorDiagnostics* aDiagnostics); - static bool IsSupportedTypeWithoutDiagnostics( - const MediaContainerType& aContainerType); - // Return true if aMimeType is a one of the strings used by our demuxers to // identify H264. Does not parse general content type strings, i.e. white // space matters. @@ -42,6 +42,16 @@ public: static already_AddRefed IsVideoAccelerated(layers::KnowsCompositor* aKnowsCompositor, nsIGlobalObject* aParent); + void GetMozDebugReaderData(nsACString& aString) override; + +private: + ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override + { + if (!IsEnabled()) { + return nullptr; + } + return new MP4Decoder(aInit); + } }; } // namespace mozilla diff --git a/dom/media/gtest/TestMediaDataDecoder.cpp b/dom/media/gtest/TestMediaDataDecoder.cpp index 341c05e29426..4beba01a7f5a 100644 --- a/dom/media/gtest/TestMediaDataDecoder.cpp +++ b/dom/media/gtest/TestMediaDataDecoder.cpp @@ -8,6 +8,7 @@ #include "MockMediaResource.h" #include "DecoderTraits.h" #include "MediaContainerType.h" +#include "MP4Decoder.h" #include "MP4Demuxer.h" #include "WebMDecoder.h" #include "WebMDemuxer.h" diff --git a/dom/media/mediasource/MediaSourceDecoder.h b/dom/media/mediasource/MediaSourceDecoder.h index aa293c9b938a..7dc5b222b7b9 100644 --- a/dom/media/mediasource/MediaSourceDecoder.h +++ b/dom/media/mediasource/MediaSourceDecoder.h @@ -29,6 +29,7 @@ public: MediaResource* GetResource() const override final; + MediaDecoderStateMachine* CreateStateMachine() override; nsresult Load(nsIPrincipal* aPrincipal); media::TimeIntervals GetSeekable() override; media::TimeIntervals GetBuffered() override; @@ -64,7 +65,6 @@ public: void NotifyInitDataArrived(); private: - MediaDecoderStateMachine* CreateStateMachine(); void DoSetMediaSourceDuration(double aDuration); media::TimeInterval ClampIntervalToEnd(const media::TimeInterval& aInterval); bool CanPlayThroughImpl() override; diff --git a/dom/media/mp3/MP3Decoder.cpp b/dom/media/mp3/MP3Decoder.cpp index 2b78a7e9fff4..e0172b184f07 100644 --- a/dom/media/mp3/MP3Decoder.cpp +++ b/dom/media/mp3/MP3Decoder.cpp @@ -1,3 +1,4 @@ + /* -*- 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 @@ -5,11 +6,22 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "MP3Decoder.h" + #include "MediaContainerType.h" +#include "MP3Demuxer.h" #include "PDMFactory.h" namespace mozilla { +ChannelMediaDecoder* +MP3Decoder::CloneImpl(MediaDecoderInit& aInit) +{ + if (!IsEnabled()) { + return nullptr; + } + return new MP3Decoder(aInit); +} + /* static */ bool MP3Decoder::IsEnabled() { diff --git a/dom/media/mp3/MP3Decoder.h b/dom/media/mp3/MP3Decoder.h index 9a99b9b34ea1..ff10eff9b639 100644 --- a/dom/media/mp3/MP3Decoder.h +++ b/dom/media/mp3/MP3Decoder.h @@ -6,17 +6,28 @@ #ifndef MP3Decoder_h_ #define MP3Decoder_h_ +#include "ChannelMediaDecoder.h" + namespace mozilla { class MediaContainerType; -class MP3Decoder +class MP3Decoder : public ChannelMediaDecoder { public: + // MediaDecoder interface. + explicit MP3Decoder(MediaDecoderInit& aInit) + : ChannelMediaDecoder(aInit) + { + } + // 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); + +private: + ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override; }; } // namespace mozilla diff --git a/dom/media/ogg/OggDecoder.cpp b/dom/media/ogg/OggDecoder.cpp index 039be3dd5d1e..1eb9bca46126 100644 --- a/dom/media/ogg/OggDecoder.cpp +++ b/dom/media/ogg/OggDecoder.cpp @@ -4,13 +4,29 @@ * 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 "OggDecoder.h" #include "MediaPrefs.h" #include "MediaContainerType.h" -#include "MediaDecoder.h" +#include "MediaDecoderStateMachine.h" +#include "MediaFormatReader.h" +#include "OggDemuxer.h" +#include "OggDecoder.h" namespace mozilla { +MediaDecoderStateMachine* OggDecoder::CreateStateMachine() +{ + RefPtr demuxer = new OggDemuxer(mResource); + MediaFormatReaderInit init; + init.mVideoFrameContainer = GetVideoFrameContainer(); + init.mKnowsCompositor = GetCompositor(); + init.mCrashHelper = GetOwner()->CreateGMPCrashHelper(); + init.mFrameStats = mFrameStats; + mReader = new MediaFormatReader(init, demuxer); + demuxer->SetChainingEvents(&mReader->TimedMetadataProducer(), + &mReader->MediaNotSeekableProducer()); + return new MediaDecoderStateMachine(this, mReader); +} + /* static */ bool OggDecoder::IsSupportedType(const MediaContainerType& aContainerType) @@ -35,7 +51,7 @@ OggDecoder::IsSupportedType(const MediaContainerType& aContainerType) // Verify that all the codecs specified are ones that we expect that // we can play. for (const auto& codec : codecs.Range()) { - if ((MediaDecoder::IsOpusEnabled() && codec.EqualsLiteral("opus")) || + if ((IsOpusEnabled() && codec.EqualsLiteral("opus")) || codec.EqualsLiteral("vorbis") || (MediaPrefs::FlacInOgg() && codec.EqualsLiteral("flac"))) { continue; diff --git a/dom/media/ogg/OggDecoder.h b/dom/media/ogg/OggDecoder.h index 92a3c9a3f0fd..a773a3b0734b 100644 --- a/dom/media/ogg/OggDecoder.h +++ b/dom/media/ogg/OggDecoder.h @@ -6,17 +6,34 @@ #if !defined(OggDecoder_h_) #define OggDecoder_h_ +#include "ChannelMediaDecoder.h" + namespace mozilla { class MediaContainerType; -class OggDecoder +class OggDecoder : public ChannelMediaDecoder { public: + explicit OggDecoder(MediaDecoderInit& aInit) + : ChannelMediaDecoder(aInit) + {} + + MediaDecoderStateMachine* CreateStateMachine() override; + // Returns true if aContainerType is an Ogg type that we think we can render // with an enabled platform decoder backend. // If provided, codecs are checked for support. static bool IsSupportedType(const MediaContainerType& aContainerType); + +private: + ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override + { + if (!IsOggEnabled()) { + return nullptr; + } + return new OggDecoder(aInit); + } }; } // namespace mozilla diff --git a/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp b/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp index fe1d18975eea..2072b7f1107c 100644 --- a/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp +++ b/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp @@ -8,6 +8,7 @@ #include "EMEVideoDecoder.h" #include "GMPDecoderModule.h" #include "GMPService.h" +#include "MP4Decoder.h" #include "MediaInfo.h" #include "MediaPrefs.h" #include "PDMFactory.h" diff --git a/dom/media/wave/WaveDecoder.cpp b/dom/media/wave/WaveDecoder.cpp index b3c0a7300988..2a44ec898a3c 100644 --- a/dom/media/wave/WaveDecoder.cpp +++ b/dom/media/wave/WaveDecoder.cpp @@ -4,16 +4,23 @@ * 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 "WaveDecoder.h" +#include "WaveDemuxer.h" #include "MediaContainerType.h" -#include "MediaDecoder.h" +#include "WaveDecoder.h" +#include "PDMFactory.h" namespace mozilla { +ChannelMediaDecoder* +WaveDecoder::CloneImpl(MediaDecoderInit& aInit) +{ + return new WaveDecoder(aInit); +} + /* static */ bool WaveDecoder::IsSupportedType(const MediaContainerType& aContainerType) { - if (!MediaDecoder::IsWaveEnabled()) { + if (!IsWaveEnabled()) { return false; } if (aContainerType.Type() == MEDIAMIMETYPE("audio/wave") diff --git a/dom/media/wave/WaveDecoder.h b/dom/media/wave/WaveDecoder.h index 96f1791496d0..745d9e45cdf9 100644 --- a/dom/media/wave/WaveDecoder.h +++ b/dom/media/wave/WaveDecoder.h @@ -6,16 +6,27 @@ #if !defined(WaveDecoder_h_) #define WaveDecoder_h_ +#include "ChannelMediaDecoder.h" + namespace mozilla { class MediaContainerType; -class WaveDecoder +class WaveDecoder : public ChannelMediaDecoder { public: + // MediaDecoder interface. + explicit WaveDecoder(MediaDecoderInit& aInit) + : ChannelMediaDecoder(aInit) + { + } + // 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); + +private: + ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override; }; } // namespace mozilla diff --git a/dom/media/wave/WaveDemuxer.cpp b/dom/media/wave/WaveDemuxer.cpp index 6831a222b6ce..5d835205d676 100644 --- a/dom/media/wave/WaveDemuxer.cpp +++ b/dom/media/wave/WaveDemuxer.cpp @@ -11,13 +11,14 @@ #include "mozilla/Assertions.h" #include "mozilla/EndianUtils.h" -#include "mp4_demuxer/ByteReader.h" #include "nsAutoPtr.h" #include "VideoUtils.h" #include "TimeUnits.h" +#include "prenv.h" using mozilla::media::TimeUnit; using mozilla::media::TimeIntervals; +using mp4_demuxer::ByteReader; namespace mozilla { diff --git a/dom/media/wave/WaveDemuxer.h b/dom/media/wave/WaveDemuxer.h index 927334866e39..df061c26ee7b 100644 --- a/dom/media/wave/WaveDemuxer.h +++ b/dom/media/wave/WaveDemuxer.h @@ -5,12 +5,12 @@ #ifndef WAV_DEMUXER_H_ #define WAV_DEMUXER_H_ +#include "mozilla/Attributes.h" +#include "mozilla/Maybe.h" #include "MediaDataDemuxer.h" #include "MediaResource.h" +#include "mp4_demuxer/ByteReader.h" -namespace mp4_demuxer { -class ByteReader; -} using mp4_demuxer::ByteReader; namespace mozilla { diff --git a/dom/media/webm/WebMDecoder.cpp b/dom/media/webm/WebMDecoder.cpp index 69f3cdb441ef..f0747fbf215f 100644 --- a/dom/media/webm/WebMDecoder.cpp +++ b/dom/media/webm/WebMDecoder.cpp @@ -4,12 +4,15 @@ * 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 "WebMDecoder.h" #include "mozilla/Preferences.h" #ifdef MOZ_AV1 #include "AOMDecoder.h" #endif #include "MediaContainerType.h" +#include "MediaFormatReader.h" +#include "WebMDemuxer.h" +#include "WebMDecoder.h" +#include "VideoUtils.h" namespace mozilla { @@ -55,5 +58,13 @@ WebMDecoder::IsSupportedType(const MediaContainerType& aContainerType) return true; } +void +WebMDecoder::GetMozDebugReaderData(nsACString& aString) +{ + if (mReader) { + mReader->GetMozDebugReaderData(aString); + } +} + } // namespace mozilla diff --git a/dom/media/webm/WebMDecoder.h b/dom/media/webm/WebMDecoder.h index 329d1bdf07f1..42115f1eb6ef 100644 --- a/dom/media/webm/WebMDecoder.h +++ b/dom/media/webm/WebMDecoder.h @@ -6,19 +6,35 @@ #if !defined(WebMDecoder_h_) #define WebMDecoder_h_ +#include "ChannelMediaDecoder.h" + namespace mozilla { class MediaContainerType; -class WebMDecoder +class WebMDecoder : public ChannelMediaDecoder { public: + explicit WebMDecoder(MediaDecoderInit& aInit) + : ChannelMediaDecoder(aInit) + { + } // Returns true if aContainerType is a WebM type that we think we can render // with an enabled platform decoder backend. // If provided, codecs are checked for support. static bool IsSupportedType(const MediaContainerType& aContainerType); + void GetMozDebugReaderData(nsACString& aString) override; + +private: + ChannelMediaDecoder* CloneImpl(MediaDecoderInit& aInit) override + { + if (!IsWebMEnabled()) { + return nullptr; + } + return new WebMDecoder(aInit); + } }; } // namespace mozilla diff --git a/media/libstagefright/binding/include/mp4_demuxer/ByteReader.h b/media/libstagefright/binding/include/mp4_demuxer/ByteReader.h index 9c23a57b5c34..88529a8d18af 100644 --- a/media/libstagefright/binding/include/mp4_demuxer/ByteReader.h +++ b/media/libstagefright/binding/include/mp4_demuxer/ByteReader.h @@ -6,6 +6,7 @@ #define BYTE_READER_H_ #include "mozilla/EndianUtils.h" +#include "mozilla/Vector.h" #include "nsTArray.h" #include "MediaData.h" @@ -15,6 +16,10 @@ class MOZ_RAII ByteReader { public: ByteReader() : mPtr(nullptr), mRemaining(0) {} + explicit ByteReader(const mozilla::Vector& aData) + : mPtr(aData.begin()), mRemaining(aData.length()), mLength(aData.length()) + { + } ByteReader(const uint8_t* aData, size_t aSize) : mPtr(aData), mRemaining(aSize), mLength(aSize) {