diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 868cd33eb02d..9d4172d3cd2d 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -321,6 +321,7 @@ MediaDecoder::Shutdown() mOnPlaybackErrorEvent.Disconnect(); mOnDecoderDoctorEvent.Disconnect(); mOnMediaNotSeekable.Disconnect(); + mOnEncrypted.Disconnect(); mDecoderStateMachine->BeginShutdown() ->Then(mAbstractMainThread, __func__, this, @@ -484,6 +485,9 @@ MediaDecoder::SetStateMachineParameters() mAbstractMainThread, this, &MediaDecoder::OnDecoderDoctorEvent); mOnMediaNotSeekable = mDecoderStateMachine->OnMediaNotSeekable().Connect( mAbstractMainThread, this, &MediaDecoder::OnMediaNotSeekable); + + mOnEncrypted = mReader->OnEncrypted().Connect( + mAbstractMainThread, GetOwner(), &MediaDecoderOwner::DispatchEncrypted); } nsresult diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index 39e7654809a7..fb6cf65d5a96 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -703,6 +703,7 @@ protected: MediaEventListener mOnPlaybackErrorEvent; MediaEventListener mOnDecoderDoctorEvent; MediaEventListener mOnMediaNotSeekable; + MediaEventListener mOnEncrypted; protected: // PlaybackRate and pitch preservation status we should start at. diff --git a/dom/media/MediaDecoderReader.h b/dom/media/MediaDecoderReader.h index 2b2c3f72f5f5..56a36c56412f 100644 --- a/dom/media/MediaDecoderReader.h +++ b/dom/media/MediaDecoderReader.h @@ -275,6 +275,11 @@ public: return mOnTrackWaitingForKey; } + MediaEventSource, nsString>& OnEncrypted() + { + return mOnEncrypted; + } + // Switch the video decoder to NullDecoderModule. It might takes effective // since a few samples later depends on how much demuxed samples are already // queued in the original video decoder. @@ -337,6 +342,8 @@ protected: // Notify if we are waiting for a decryption key. MediaEventProducer mOnTrackWaitingForKey; + MediaEventProducer, nsString> mOnEncrypted; + RefPtr mResource; private: diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index 2efcbf1b22da..3ff51437af1d 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -1224,35 +1224,6 @@ MediaFormatReader::InitInternal() return NS_OK; } -class DispatchKeyNeededEvent : public Runnable -{ -public: - DispatchKeyNeededEvent(AbstractMediaDecoder* aDecoder, - nsTArray& aInitData, - const nsString& aInitDataType) - : Runnable("DispatchKeyNeededEvent") - , mDecoder(aDecoder) - , mInitData(aInitData) - , mInitDataType(aInitDataType) - { - } - NS_IMETHOD Run() override - { - // Note: Null check the owner, as the decoder could have been shutdown - // since this event was dispatched. - MediaDecoderOwner* owner = mDecoder->GetOwner(); - if (owner) { - owner->DispatchEncrypted(mInitData, mInitDataType); - } - mDecoder = nullptr; - return NS_OK; - } -private: - RefPtr mDecoder; - nsTArray mInitData; - nsString mInitDataType; -}; - void MediaFormatReader::SetCDMProxy(CDMProxy* aProxy) { @@ -1380,13 +1351,11 @@ MediaFormatReader::OnDemuxerInitDone(const MediaResult& aResult) } UniquePtr crypto = mDemuxer->GetCrypto(); - if (mDecoder && crypto && crypto->IsEncrypted()) { + if (crypto && crypto->IsEncrypted()) { // Try and dispatch 'encrypted'. Won't go if ready state still HAVE_NOTHING. for (uint32_t i = 0; i < crypto->mInitDatas.Length(); i++) { - nsCOMPtr r = - new DispatchKeyNeededEvent(mDecoder, crypto->mInitDatas[i].mInitData, - crypto->mInitDatas[i].mType); - mDecoder->AbstractMainThread()->Dispatch(r.forget()); + mOnEncrypted.Notify(crypto->mInitDatas[i].mInitData, + crypto->mInitDatas[i].mType); } mInfo.mCrypto = *crypto; }