diff --git a/dom/media/DecoderTraits.cpp b/dom/media/DecoderTraits.cpp index dfb66d69f14c..472d52e49921 100644 --- a/dom/media/DecoderTraits.cpp +++ b/dom/media/DecoderTraits.cpp @@ -339,7 +339,7 @@ DecoderTraits::CreateDecoder(MediaDecoderInit& aInit, /* static */ MediaDecoderReader* DecoderTraits::CreateReader(const MediaContainerType& aType, - const MediaDecoderReaderInit& aInit) + MediaDecoderReaderInit& aInit) { MOZ_ASSERT(NS_IsMainThread()); MediaDecoderReader* decoderReader = nullptr; diff --git a/dom/media/DecoderTraits.h b/dom/media/DecoderTraits.h index f29e73066168..7458d8a10927 100644 --- a/dom/media/DecoderTraits.h +++ b/dom/media/DecoderTraits.h @@ -52,7 +52,7 @@ public: // 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, - const MediaDecoderReaderInit& aInit); + MediaDecoderReaderInit& aInit); // Returns true if MIME type aType is supported in video documents, // or false otherwise. Not all platforms support all MIME types, and diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 6bce928bdef5..7500a43d2075 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -1058,19 +1058,23 @@ MediaDecoder::DurationChanged() } } +already_AddRefed +MediaDecoder::GetCompositor() +{ + MediaDecoderOwner* owner = GetOwner(); + nsIDocument* ownerDoc = owner ? owner->GetDocument() : nullptr; + RefPtr layerManager = + ownerDoc ? nsContentUtils::LayerManagerForDocument(ownerDoc) : nullptr; + RefPtr knows = + layerManager ? layerManager->AsShadowForwarder() : nullptr; + return knows.forget(); +} + void MediaDecoder::NotifyCompositor() { - MediaDecoderOwner* owner = GetOwner(); - NS_ENSURE_TRUE_VOID(owner); - - nsIDocument* ownerDoc = owner->GetDocument(); - NS_ENSURE_TRUE_VOID(ownerDoc); - - RefPtr layerManager = - nsContentUtils::LayerManagerForDocument(ownerDoc); - if (layerManager) { - RefPtr knowsCompositor = layerManager->AsShadowForwarder(); + RefPtr knowsCompositor = GetCompositor(); + if (knowsCompositor) { mCompositorUpdatedEvent.Notify(knowsCompositor); } } diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index 930ce5fcb831..33fbfeceb399 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -512,6 +512,8 @@ protected: return mCurrentPosition.Ref(); } + already_AddRefed GetCompositor(); + // Official duration of the media resource as observed by script. double mDuration; diff --git a/dom/media/MediaDecoderReader.cpp b/dom/media/MediaDecoderReader.cpp index 77be0d875124..452f57ccdf0f 100644 --- a/dom/media/MediaDecoderReader.cpp +++ b/dom/media/MediaDecoderReader.cpp @@ -68,7 +68,7 @@ public: size_t mSize; }; -MediaDecoderReader::MediaDecoderReader(const MediaDecoderReaderInit& aInit) +MediaDecoderReader::MediaDecoderReader(MediaDecoderReaderInit& aInit) : mAudioCompactor(mAudioQueue) , mDecoder(aInit.mDecoder) , mTaskQueue(new TaskQueue( diff --git a/dom/media/MediaDecoderReader.h b/dom/media/MediaDecoderReader.h index 99f02a21d2a0..2470baf01cb8 100644 --- a/dom/media/MediaDecoderReader.h +++ b/dom/media/MediaDecoderReader.h @@ -67,6 +67,7 @@ struct MOZ_STACK_CLASS MediaDecoderReaderInit AbstractMediaDecoder* const mDecoder; MediaResource* mResource = nullptr; VideoFrameContainer* mVideoFrameContainer = nullptr; + already_AddRefed mKnowsCompositor; explicit MediaDecoderReaderInit(AbstractMediaDecoder* aDecoder) : mDecoder(aDecoder) @@ -110,7 +111,7 @@ public: // The caller must ensure that Shutdown() is called before aDecoder is // destroyed. - explicit MediaDecoderReader(const MediaDecoderReaderInit& aInit); + explicit MediaDecoderReader(MediaDecoderReaderInit& aInit); // Initializes the reader, returns NS_OK on success, or NS_ERROR_FAILURE // on failure. diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index 26deae626ec6..d7d0ab7d76ba 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -9,6 +9,7 @@ #include "AutoTaskQueue.h" #include "Layers.h" #include "MediaData.h" +#include "MediaDecoderOwner.h" #include "MediaInfo.h" #include "MediaResource.h" #include "VideoFrameContainer.h" @@ -22,8 +23,6 @@ #include "mozilla/SyncRunnable.h" #include "mozilla/Telemetry.h" #include "mozilla/Unused.h" -#include "mozilla/dom/HTMLMediaElement.h" -#include "mozilla/layers/ShadowLayers.h" #include "nsContentUtils.h" #include "nsPrintfCString.h" #include "nsSize.h" @@ -1094,7 +1093,7 @@ MediaFormatReader::DemuxerProxy::NotifyDataArrived() }); } -MediaFormatReader::MediaFormatReader(const MediaDecoderReaderInit& aInit, +MediaFormatReader::MediaFormatReader(MediaDecoderReaderInit& aInit, MediaDataDemuxer* aDemuxer) : MediaDecoderReader(aInit) , mAudio(this, MediaData::AUDIO_DATA, @@ -1106,6 +1105,7 @@ MediaFormatReader::MediaFormatReader(const MediaDecoderReaderInit& aInit, , mPendingNotifyDataArrived(false) , mLastReportedNumDecodedFrames(0) , mPreviousDecodedKeyframeTime_us(sNoPreviousDecodedKeyframe) + , mKnowsCompositor(aInit.mKnowsCompositor) , mInitDone(false) , mTrackDemuxersMayBlock(false) , mSeekScheduled(false) @@ -1214,38 +1214,11 @@ MediaFormatReader::TearDownDecoders() return MediaDecoderReader::Shutdown(); } -void -MediaFormatReader::InitLayersBackendType() -{ - // Extract the layer manager backend type so that platform decoders - // can determine whether it's worthwhile using hardware accelerated - // video decoding. - if (!mDecoder) { - return; - } - MediaDecoderOwner* owner = mDecoder->GetOwner(); - if (!owner) { - NS_WARNING("MediaFormatReader without a decoder owner, can't get HWAccel"); - return; - } - - dom::HTMLMediaElement* element = owner->GetMediaElement(); - NS_ENSURE_TRUE_VOID(element); - - RefPtr layerManager = - nsContentUtils::LayerManagerForDocument(element->OwnerDoc()); - NS_ENSURE_TRUE_VOID(layerManager); - - mKnowsCompositor = layerManager->AsShadowForwarder(); -} - nsresult MediaFormatReader::InitInternal() { MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread."); - InitLayersBackendType(); - mAudio.mTaskQueue = new TaskQueue( GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER), "MFR::mAudio::mTaskQueue"); diff --git a/dom/media/MediaFormatReader.h b/dom/media/MediaFormatReader.h index fafe9f79a85f..354ea4b46c42 100644 --- a/dom/media/MediaFormatReader.h +++ b/dom/media/MediaFormatReader.h @@ -29,7 +29,7 @@ class MediaFormatReader final : public MediaDecoderReader typedef MozPromise NotifyDataArrivedPromise; public: - MediaFormatReader(const MediaDecoderReaderInit& aInit, MediaDataDemuxer* aDemuxer); + MediaFormatReader(MediaDecoderReaderInit& aInit, MediaDataDemuxer* aDemuxer); virtual ~MediaFormatReader(); diff --git a/dom/media/android/AndroidMediaReader.cpp b/dom/media/android/AndroidMediaReader.cpp index 23d8f1ed467f..7011f4f3c233 100644 --- a/dom/media/android/AndroidMediaReader.cpp +++ b/dom/media/android/AndroidMediaReader.cpp @@ -26,7 +26,7 @@ typedef mozilla::layers::Image Image; typedef mozilla::layers::PlanarYCbCrImage PlanarYCbCrImage; AndroidMediaReader::AndroidMediaReader(const MediaContainerType& aContainerType, - const MediaDecoderReaderInit& aInit) : + MediaDecoderReaderInit& aInit) : MediaDecoderReader(aInit), mType(aContainerType), mPlugin(nullptr), diff --git a/dom/media/android/AndroidMediaReader.h b/dom/media/android/AndroidMediaReader.h index c03fa3c744c9..7705ef792aad 100644 --- a/dom/media/android/AndroidMediaReader.h +++ b/dom/media/android/AndroidMediaReader.h @@ -38,7 +38,7 @@ class AndroidMediaReader : public MediaDecoderReader MozPromiseRequestHolder mSeekRequest; public: AndroidMediaReader(const MediaContainerType& aContainerType, - const MediaDecoderReaderInit& aInit); + MediaDecoderReaderInit& aInit); nsresult ResetDecode(TrackSet aTracks = TrackSet(TrackInfo::kAudioTrack, TrackInfo::kVideoTrack)) override; diff --git a/dom/media/fmp4/MP4Decoder.cpp b/dom/media/fmp4/MP4Decoder.cpp index aae012e38710..5871a2f07c56 100644 --- a/dom/media/fmp4/MP4Decoder.cpp +++ b/dom/media/fmp4/MP4Decoder.cpp @@ -34,6 +34,7 @@ MediaDecoderStateMachine* MP4Decoder::CreateStateMachine() { MediaDecoderReaderInit init(this); init.mVideoFrameContainer = GetVideoFrameContainer(); + init.mKnowsCompositor = GetCompositor(); mReader = new MediaFormatReader(init, new MP4Demuxer(mResource)); return new MediaDecoderStateMachine(this, mReader); } diff --git a/dom/media/hls/HLSDecoder.cpp b/dom/media/hls/HLSDecoder.cpp index 6b15b88603a3..5f5b0948fa42 100644 --- a/dom/media/hls/HLSDecoder.cpp +++ b/dom/media/hls/HLSDecoder.cpp @@ -30,6 +30,7 @@ HLSDecoder::CreateStateMachine() MOZ_ASSERT(resourceWrapper); MediaDecoderReaderInit init(this); init.mVideoFrameContainer = GetVideoFrameContainer(); + init.mKnowsCompositor = GetCompositor(); mReader = new MediaFormatReader(init, new HLSDemuxer(resourceWrapper->GetPlayerId())); diff --git a/dom/media/mediasource/MediaSourceDecoder.cpp b/dom/media/mediasource/MediaSourceDecoder.cpp index e8eea91bce7e..95e64d391515 100644 --- a/dom/media/mediasource/MediaSourceDecoder.cpp +++ b/dom/media/mediasource/MediaSourceDecoder.cpp @@ -41,6 +41,7 @@ MediaSourceDecoder::CreateStateMachine() mDemuxer = new MediaSourceDemuxer(AbstractMainThread()); MediaDecoderReaderInit init(this); init.mVideoFrameContainer = GetVideoFrameContainer(); + init.mKnowsCompositor = GetCompositor(); mReader = new MediaFormatReader(init, mDemuxer); return new MediaDecoderStateMachine(this, mReader); } diff --git a/dom/media/ogg/OggDecoder.cpp b/dom/media/ogg/OggDecoder.cpp index cb3e175b340c..3edbaa8fa4ff 100644 --- a/dom/media/ogg/OggDecoder.cpp +++ b/dom/media/ogg/OggDecoder.cpp @@ -18,6 +18,7 @@ MediaDecoderStateMachine* OggDecoder::CreateStateMachine() RefPtr demuxer = new OggDemuxer(mResource); MediaDecoderReaderInit init(this); init.mVideoFrameContainer = GetVideoFrameContainer(); + init.mKnowsCompositor = GetCompositor(); mReader = new MediaFormatReader(init, demuxer); demuxer->SetChainingEvents(&mReader->TimedMetadataProducer(), &mReader->MediaNotSeekableProducer()); diff --git a/dom/media/webm/WebMDecoder.cpp b/dom/media/webm/WebMDecoder.cpp index cd782a5aa7d7..6123b825bf63 100644 --- a/dom/media/webm/WebMDecoder.cpp +++ b/dom/media/webm/WebMDecoder.cpp @@ -20,6 +20,7 @@ MediaDecoderStateMachine* WebMDecoder::CreateStateMachine() { MediaDecoderReaderInit init(this); init.mVideoFrameContainer = GetVideoFrameContainer(); + init.mKnowsCompositor = GetCompositor(); mReader = new MediaFormatReader(init, new WebMDemuxer(mResource)); return new MediaDecoderStateMachine(this, mReader); }