diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 472f694baa..87454a4686 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -388,7 +388,9 @@ MediaDecoder::MediaDecoder(MediaDecoderOwner* aOwner) , mLogicalPosition(0.0) , mDuration(std::numeric_limits::quiet_NaN()) , mResourceCallback(new ResourceCallback()) +#ifdef MOZ_EME , mCDMProxyPromise(mCDMProxyPromiseHolder.Ensure(__func__)) +#endif , mIgnoreProgressData(false) , mInfiniteStream(false) , mOwner(aOwner) @@ -473,7 +475,9 @@ MediaDecoder::Shutdown() mResourceCallback->Disconnect(); +#ifdef MOZ_EME mCDMProxyPromiseHolder.RejectIfExists(true, __func__); +#endif DiscardOngoingSeekIfExists(); @@ -1547,6 +1551,7 @@ MediaDecoder::CanPlayThrough() return GetStatistics().CanPlayThrough(); } +#ifdef MOZ_EME RefPtr MediaDecoder::RequestCDMProxy() const { @@ -1561,6 +1566,7 @@ MediaDecoder::SetCDMProxy(CDMProxy* aProxy) mCDMProxyPromiseHolder.ResolveIfExists(aProxy, __func__); } +#endif bool MediaDecoder::IsOpusEnabled() diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index ae70ecec17..fa333f25d0 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -7,7 +7,9 @@ #define MediaDecoder_h_ #include "mozilla/Atomics.h" +#ifdef MOZ_EME #include "mozilla/CDMProxy.h" +#endif #include "mozilla/MozPromise.h" #include "mozilla/ReentrantMonitor.h" #include "mozilla/StateMirroring.h" @@ -433,6 +435,7 @@ private: MediaDecoderOwner* GetOwner() const override; +#ifdef MOZ_EME typedef MozPromise, bool /* aIgnored */, /* IsExclusive = */ true> CDMProxyPromise; // Resolved when a CDMProxy is available and the capabilities are known or @@ -440,6 +443,7 @@ private: RefPtr RequestCDMProxy() const; void SetCDMProxy(CDMProxy* aProxy); +#endif static bool IsOggEnabled(); static bool IsOpusEnabled(); @@ -590,8 +594,10 @@ private: RefPtr mResourceCallback; +#ifdef MOZ_EME MozPromiseHolder mCDMProxyPromiseHolder; RefPtr mCDMProxyPromise; +#endif protected: // The promise resolving/rejection is queued as a "micro-task" which will be diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 2fa29432ce..e57a658d17 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -192,7 +192,9 @@ public: virtual State GetState() const = 0; // Event handlers for various events. +#ifdef MOZ_EME virtual void HandleCDMProxyReady() {} +#endif virtual void HandleAudioDecoded(MediaData* aAudio) {} virtual void HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart) {} virtual void HandleEndOfStream() {} @@ -370,7 +372,9 @@ public: return DECODER_STATE_WAIT_FOR_CDM; } +#ifdef MOZ_EME void HandleCDMProxyReady() override; +#endif RefPtr HandleSeek(SeekTarget aTarget) override { @@ -1237,22 +1241,32 @@ DecodeMetadataState::OnMetadataRead(MetadataHolder* aMetadata) // feeding in the CDM, which we need to decode the first frame (and // thus get the metadata). We could fix this if we could compute the start // time by demuxing without necessaring decoding. +#ifdef MOZ_EME bool waitingForCDM = Info().IsEncrypted() && !mMaster->mCDMProxy; +#endif mMaster->mNotifyMetadataBeforeFirstFrame = - mMaster->mDuration.Ref().isSome() || waitingForCDM; + mMaster->mDuration.Ref().isSome() +#ifdef MOZ_EME + || waitingForCDM +#endif +; if (mMaster->mNotifyMetadataBeforeFirstFrame) { mMaster->EnqueueLoadedMetadataEvent(); } +#ifdef MOZ_EME if (waitingForCDM) { // Metadata parsing was successful but we're still waiting for CDM caps // to become available so that we can build the correct decryptor/decoder. SetState(); } else { +#endif SetState(SeekJob{}); +#ifdef MOZ_EME } +#endif } void @@ -1261,18 +1275,24 @@ DormantState::HandlePlayStateChanged(MediaDecoder::PlayState aPlayState) { if (aPlayState == MediaDecoder::PLAY_STATE_PLAYING) { // Exit dormant when the user wants to play. - MOZ_ASSERT(!Info().IsEncrypted() || mMaster->mCDMProxy); + MOZ_ASSERT(!Info().IsEncrypted() +#ifdef MOZ_EME + || mMaster->mCDMProxy +#endif +); MOZ_ASSERT(mMaster->mSentFirstFrameLoadedEvent); SetState(Move(mPendingSeek), EventVisibility::Suppressed); } } +#ifdef MOZ_EME void MediaDecoderStateMachine:: WaitForCDMState::HandleCDMProxyReady() { SetState(Move(mPendingSeek)); } +#endif void MediaDecoderStateMachine:: @@ -1574,7 +1594,9 @@ ShutdownState::Enter() // dispose of the timer. master->mVideoDecodeSuspendTimer.Reset(); +#ifdef MOZ_EME master->mCDMProxyPromise.DisconnectIfExists(); +#endif if (master->IsPlaying()) { master->StopPlayback(); @@ -2128,10 +2150,12 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) mMediaSink = CreateMediaSink(mAudioCaptured); +#ifdef MOZ_EME mCDMProxyPromise.Begin(aDecoder->RequestCDMProxy()->Then( OwnerThread(), __func__, this, &MediaDecoderStateMachine::OnCDMProxyReady, &MediaDecoderStateMachine::OnCDMProxyNotReady)); +#endif nsresult rv = mReader->Init(); NS_ENSURE_SUCCESS(rv, rv); @@ -3107,6 +3131,7 @@ void MediaDecoderStateMachine::OnMediaSinkAudioError(nsresult aResult) DecodeError(MediaResult(NS_ERROR_DOM_MEDIA_MEDIASINK_ERR, __func__)); } +#ifdef MOZ_EME void MediaDecoderStateMachine::OnCDMProxyReady(RefPtr aProxy) { @@ -3123,6 +3148,7 @@ MediaDecoderStateMachine::OnCDMProxyNotReady() MOZ_ASSERT(OnTaskQueue()); mCDMProxyPromise.Complete(); } +#endif void MediaDecoderStateMachine::SetAudioCaptured(bool aCaptured) diff --git a/dom/media/MediaDecoderStateMachine.h b/dom/media/MediaDecoderStateMachine.h index 2da468de64..29da56e57d 100644 --- a/dom/media/MediaDecoderStateMachine.h +++ b/dom/media/MediaDecoderStateMachine.h @@ -767,10 +767,12 @@ private: // Playback will not start when audio is offloading. bool mAudioOffloading; +#ifdef MOZ_EME void OnCDMProxyReady(RefPtr aProxy); void OnCDMProxyNotReady(); RefPtr mCDMProxy; MozPromiseRequestHolder mCDMProxyPromise; +#endif private: // The buffered range. Mirrored from the decoder thread. diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index 26e2fdea16..84be3d5548 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -3,7 +3,9 @@ * 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/. */ +#ifdef MOZ_EME #include "mozilla/CDMProxy.h" +#endif #include "mozilla/ClearOnShutdown.h" #include "mozilla/dom/HTMLMediaElement.h" #include "mozilla/Preferences.h" @@ -617,6 +619,7 @@ private: }; #endif +#ifdef MOZ_EME void MediaFormatReader::SetCDMProxy(CDMProxy* aProxy) { @@ -628,6 +631,7 @@ MediaFormatReader::SetCDMProxy(CDMProxy* aProxy) }); OwnerThread()->Dispatch(r.forget()); } +#endif bool MediaFormatReader::IsWaitingOnCDMResource() { diff --git a/dom/media/MediaFormatReader.h b/dom/media/MediaFormatReader.h index b9b1a3cb12..ccd43f0e6a 100644 --- a/dom/media/MediaFormatReader.h +++ b/dom/media/MediaFormatReader.h @@ -19,7 +19,9 @@ namespace mozilla { +#ifdef MOZ_EME class CDMProxy; +#endif class MediaFormatReader final : public MediaDecoderReader { @@ -90,7 +92,9 @@ public: return mTrackDemuxersMayBlock; } +#ifdef MOZ_EME void SetCDMProxy(CDMProxy* aProxy) override; +#endif // Returns a string describing the state of the decoder data. // Used for debugging purposes. @@ -583,7 +587,9 @@ private: RefPtr mVideoFrameContainer; layers::ImageContainer* GetImageContainer(); +#ifdef MOZ_EME RefPtr mCDMProxy; +#endif #ifdef MOZ_GMP RefPtr mCrashHelper; diff --git a/dom/media/fmp4/MP4Decoder.cpp b/dom/media/fmp4/MP4Decoder.cpp index 6cff40d147..3cfe5b1374 100644 --- a/dom/media/fmp4/MP4Decoder.cpp +++ b/dom/media/fmp4/MP4Decoder.cpp @@ -9,7 +9,9 @@ #include "MP4Demuxer.h" #include "mozilla/Preferences.h" #include "nsCharSeparatedTokenizer.h" +#ifdef MOZ_EME #include "mozilla/CDMProxy.h" +#endif #include "mozilla/Logging.h" #include "mozilla/SharedThreadPool.h" #include "nsMimeTypes.h" diff --git a/dom/media/platforms/PDMFactory.cpp b/dom/media/platforms/PDMFactory.cpp index cf4fba4b01..89968e53ae 100644 --- a/dom/media/platforms/PDMFactory.cpp +++ b/dom/media/platforms/PDMFactory.cpp @@ -22,7 +22,9 @@ #include "GMPDecoderModule.h" #endif +#ifdef MOZ_EME #include "mozilla/CDMProxy.h" +#endif #include "mozilla/ClearOnShutdown.h" #include "mozilla/SharedThreadPool.h" #include "mozilla/StaticPtr.h" @@ -35,7 +37,9 @@ #include "H264Converter.h" #include "AgnosticDecoderModule.h" +#ifdef MOZ_EME #include "EMEDecoderModule.h" +#endif #include "DecoderDoctorDiagnostics.h" @@ -454,11 +458,13 @@ PDMFactory::GetDecoder(const TrackInfo& aTrackInfo, return pdm.forget(); } +#ifdef MOZ_EME void PDMFactory::SetCDMProxy(CDMProxy* aProxy) { RefPtr m = new PDMFactory(); mEMEPDM = new EMEDecoderModule(aProxy, m); } +#endif } // namespace mozilla diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index cc1f16c81f..b15d578fa9 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -283,15 +283,7 @@ WEBIDL_FILES = [ 'MediaDeviceInfo.webidl', 'MediaDevices.webidl', 'MediaElementAudioSourceNode.webidl', - 'MediaEncryptedEvent.webidl', 'MediaError.webidl', - 'MediaKeyError.webidl', - 'MediaKeyMessageEvent.webidl', - 'MediaKeys.webidl', - 'MediaKeySession.webidl', - 'MediaKeysRequestStatus.webidl', - 'MediaKeyStatusMap.webidl', - 'MediaKeySystemAccess.webidl', 'MediaList.webidl', 'MediaQueryList.webidl', 'MediaRecorder.webidl', @@ -583,6 +575,18 @@ WEBIDL_FILES = [ 'XULElement.webidl', ] +if CONFIG['MOZ_EME']: + WEBIDL_FILES += [ + 'MediaEncryptedEvent.webidl', + 'MediaKeyError.webidl', + 'MediaKeyMessageEvent.webidl', + 'MediaKeys.webidl', + 'MediaKeySession.webidl', + 'MediaKeysRequestStatus.webidl', + 'MediaKeyStatusMap.webidl', + 'MediaKeySystemAccess.webidl', + ] + if CONFIG['MOZ_WEBEXTENSIONS']: WEBIDL_FILES += ['AddonManager.webidl']