From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/ipc/MFMediaEngineParent.h | 144 ++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 dom/media/ipc/MFMediaEngineParent.h (limited to 'dom/media/ipc/MFMediaEngineParent.h') diff --git a/dom/media/ipc/MFMediaEngineParent.h b/dom/media/ipc/MFMediaEngineParent.h new file mode 100644 index 0000000000..af921d49c5 --- /dev/null +++ b/dom/media/ipc/MFMediaEngineParent.h @@ -0,0 +1,144 @@ +/* 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 DOM_MEDIA_IPC_MFMEDIAENGINEPARENT_H_ +#define DOM_MEDIA_IPC_MFMEDIAENGINEPARENT_H_ + +#include +#include +#include + +#include "MediaInfo.h" +#include "MFMediaEngineExtra.h" +#include "MFMediaEngineNotify.h" +#include "MFMediaEngineUtils.h" +#include "MFMediaSource.h" +#include "PlatformDecoderModule.h" +#include "mozilla/PMFMediaEngineParent.h" + +namespace mozilla { + +class MFCDMProxy; +class MFContentProtectionManager; +class MFMediaEngineExtension; +class MFMediaEngineStreamWrapper; +class MFMediaSource; +class RemoteDecoderManagerParent; + +/** + * MFMediaEngineParent is a wrapper class for a MediaEngine in the MF-CDM + * process. It's responsible to create the media engine and its related classes, + * such as a custom media source, media engine extension, media engine + * notify...e.t.c It communicates with MFMediaEngineChild in the content process + * to receive commands and direct them to the media engine. + * https://docs.microsoft.com/en-us/windows/win32/api/mfmediaengine/nn-mfmediaengine-imfmediaengine + */ +class MFMediaEngineParent final : public PMFMediaEngineParent { + public: + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MFMediaEngineParent); + MFMediaEngineParent(RemoteDecoderManagerParent* aManager, + nsISerialEventTarget* aManagerThread); + + using TrackType = TrackInfo::TrackType; + + static MFMediaEngineParent* GetMediaEngineById(uint64_t aId); + + MFMediaEngineStreamWrapper* GetMediaEngineStream( + TrackType aType, const CreateDecoderParams& aParam); + + uint64_t Id() const { return mMediaEngineId; } + + // Methods for PMFMediaEngineParent + mozilla::ipc::IPCResult RecvInitMediaEngine( + const MediaEngineInfoIPDL& aInfo, InitMediaEngineResolver&& aResolver); + mozilla::ipc::IPCResult RecvNotifyMediaInfo(const MediaInfoIPDL& aInfo); + mozilla::ipc::IPCResult RecvPlay(); + mozilla::ipc::IPCResult RecvPause(); + mozilla::ipc::IPCResult RecvSeek(double aTargetTimeInSecond); + mozilla::ipc::IPCResult RecvSetCDMProxyId(uint64_t aProxyId); + mozilla::ipc::IPCResult RecvSetVolume(double aVolume); + mozilla::ipc::IPCResult RecvSetPlaybackRate(double aPlaybackRate); + mozilla::ipc::IPCResult RecvSetLooping(bool aLooping); + mozilla::ipc::IPCResult RecvNotifyEndOfStream(TrackInfo::TrackType aType); + mozilla::ipc::IPCResult RecvShutdown(); + + void Destroy(); + + private: + ~MFMediaEngineParent(); + + void CreateMediaEngine(); + + void InitializeVirtualVideoWindow(); + void InitializeDXGIDeviceManager(); + + void AssertOnManagerThread() const; + + void HandleMediaEngineEvent(MFMediaEngineEventWrapper aEvent); + void HandleRequestSample(const SampleRequest& aRequest); + + void NotifyError(MF_MEDIA_ENGINE_ERR aError, HRESULT aResult = 0); + + void DestroyEngineIfExists(const Maybe& aError = Nothing()); + + void EnsureDcompSurfaceHandle(); + + void UpdateStatisticsData(); + + void SetMediaSourceOnEngine(); + + // This generates unique id for each MFMediaEngineParent instance, and it + // would be increased monotonically. + static inline uint64_t sMediaEngineIdx = 0; + + const uint64_t mMediaEngineId; + + // The life cycle of this class is determined by the actor in the content + // process, we would hold a reference until the content actor asks us to + // destroy. + RefPtr mIPDLSelfRef; + + const RefPtr mManager; + const RefPtr mManagerThread; + + // Required classes for working with the media engine. + Microsoft::WRL::ComPtr mMediaEngine; + Microsoft::WRL::ComPtr mMediaEngineNotify; + Microsoft::WRL::ComPtr mMediaEngineExtension; + Microsoft::WRL::ComPtr mMediaSource; +#ifdef MOZ_WMF_CDM + Microsoft::WRL::ComPtr mContentProtectionManager; +#endif + + MediaEventListener mMediaEngineEventListener; + MediaEventListener mRequestSampleListener; + bool mIsCreatedMediaEngine = false; + + // A fake window handle passed to MF-based rendering pipeline for OPM. + HWND mVirtualVideoWindow = nullptr; + + Microsoft::WRL::ComPtr mDXGIDeviceManager; + + // These will be always zero for audio playback. + DWORD mDisplayWidth = 0; + DWORD mDisplayHeight = 0; + + // When it's true, the media engine will output decoded video frames to a + // shareable dcomp surface. + bool mIsEnableDcompMode = false; + + float mPlaybackRate = 1.0; + + // When flush happens inside the media engine, it will reset the statistic + // data. Therefore, whenever the statistic data gets reset, we will use + // `mCurrentPlaybackStatisticData` to track new data and store previous data + // to `mPrevPlaybackStatisticData`. The sum of these two data is the total + // statistic data for playback. + StatisticData mCurrentPlaybackStatisticData; + StatisticData mPrevPlaybackStatisticData; +}; + +} // namespace mozilla + +#endif // DOM_MEDIA_IPC_MFMEDIAENGINEPARENT_H_ -- cgit v1.2.3