tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MFMediaEngineParent.h (5039B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef DOM_MEDIA_IPC_MFMEDIAENGINEPARENT_H_
      6 #define DOM_MEDIA_IPC_MFMEDIAENGINEPARENT_H_
      7 
      8 #include <Mfidl.h>
      9 #include <winnt.h>
     10 #include <wrl.h>
     11 
     12 #include "MFMediaEngineExtra.h"
     13 #include "MFMediaEngineNotify.h"
     14 #include "MFMediaEngineUtils.h"
     15 #include "MFMediaSource.h"
     16 #include "MediaInfo.h"
     17 #include "PlatformDecoderModule.h"
     18 #include "mozilla/PMFMediaEngineParent.h"
     19 
     20 namespace mozilla {
     21 
     22 class MFCDMProxy;
     23 class MFContentProtectionManager;
     24 class MFMediaEngineExtension;
     25 class MFMediaEngineStreamWrapper;
     26 class MFMediaSource;
     27 class RemoteMediaManagerParent;
     28 
     29 /**
     30 * MFMediaEngineParent is a wrapper class for a MediaEngine in the MF-CDM
     31 * process. It's responsible to create the media engine and its related classes,
     32 * such as a custom media source, media engine extension, media engine
     33 * notify...e.t.c It communicates with MFMediaEngineChild in the content process
     34 * to receive commands and direct them to the media engine.
     35 * https://docs.microsoft.com/en-us/windows/win32/api/mfmediaengine/nn-mfmediaengine-imfmediaengine
     36 */
     37 class MFMediaEngineParent final : public PMFMediaEngineParent {
     38 public:
     39  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MFMediaEngineParent);
     40  MFMediaEngineParent(RemoteMediaManagerParent* aManager,
     41                      nsISerialEventTarget* aManagerThread);
     42 
     43  using TrackType = TrackInfo::TrackType;
     44 
     45  static MFMediaEngineParent* GetMediaEngineById(uint64_t aId);
     46 
     47  MFMediaEngineStreamWrapper* GetMediaEngineStream(
     48      TrackType aType, const CreateDecoderParams& aParam);
     49 
     50  uint64_t Id() const { return mMediaEngineId; }
     51 
     52  // Methods for PMFMediaEngineParent
     53  mozilla::ipc::IPCResult RecvInitMediaEngine(
     54      const MediaEngineInfoIPDL& aInfo, InitMediaEngineResolver&& aResolver);
     55  mozilla::ipc::IPCResult RecvPlay();
     56  mozilla::ipc::IPCResult RecvPause();
     57  mozilla::ipc::IPCResult RecvSeek(double aTargetTimeInSecond);
     58  mozilla::ipc::IPCResult RecvSetCDMProxyId(uint64_t aProxyId);
     59  mozilla::ipc::IPCResult RecvSetVolume(double aVolume);
     60  mozilla::ipc::IPCResult RecvSetPlaybackRate(double aPlaybackRate);
     61  mozilla::ipc::IPCResult RecvSetLooping(bool aLooping);
     62  mozilla::ipc::IPCResult RecvNotifyEndOfStream(TrackInfo::TrackType aType);
     63  mozilla::ipc::IPCResult RecvShutdown();
     64 
     65  void Destroy();
     66 
     67 private:
     68  ~MFMediaEngineParent();
     69 
     70  void CreateMediaEngine();
     71  HRESULT SetMediaInfo(const MediaInfoIPDL& aInfo, bool aIsEncryptedCustomInit);
     72 
     73  void InitializeDXGIDeviceManager();
     74 
     75  void AssertOnManagerThread() const;
     76 
     77  void HandleMediaEngineEvent(MFMediaEngineEventWrapper aEvent);
     78  void HandleRequestSample(const SampleRequest& aRequest);
     79 
     80  void NotifyError(MF_MEDIA_ENGINE_ERR aError, HRESULT aResult = 0);
     81 
     82  void DestroyEngineIfExists(const Maybe<MediaResult>& aError = Nothing());
     83 
     84  void EnsureDcompSurfaceHandle();
     85 
     86  void UpdateStatisticsData();
     87 
     88  void SetMediaSourceOnEngine();
     89 
     90  Maybe<gfx::IntSize> DetectVideoSizeChange();
     91  void NotifyVideoResizing();
     92 
     93 #ifdef MOZ_WMF_CDM
     94  // We will disable HWDRM when receiving error MSPR_E_NO_DECRYPTOR_AVAILABLE.
     95  void NotifyDisableHWDRM();
     96 #endif
     97 
     98  // This generates unique id for each MFMediaEngineParent instance, and it
     99  // would be increased monotonically.
    100  static inline uint64_t sMediaEngineIdx = 0;
    101 
    102  const uint64_t mMediaEngineId;
    103 
    104  // The life cycle of this class is determined by the actor in the content
    105  // process, we would hold a reference until the content actor asks us to
    106  // destroy.
    107  RefPtr<MFMediaEngineParent> mIPDLSelfRef;
    108 
    109  const RefPtr<RemoteMediaManagerParent> mManager;
    110  const RefPtr<nsISerialEventTarget> mManagerThread;
    111 
    112  // Required classes for working with the media engine.
    113  Microsoft::WRL::ComPtr<IMFMediaEngine> mMediaEngine;
    114  Microsoft::WRL::ComPtr<MFMediaEngineNotify> mMediaEngineNotify;
    115  Microsoft::WRL::ComPtr<MFMediaEngineExtension> mMediaEngineExtension;
    116  Microsoft::WRL::ComPtr<MFMediaSource> mMediaSource;
    117 #ifdef MOZ_WMF_CDM
    118  Microsoft::WRL::ComPtr<MFContentProtectionManager> mContentProtectionManager;
    119 #endif
    120 
    121  MediaEventListener mMediaEngineEventListener;
    122  MediaEventListener mRequestSampleListener;
    123  bool mIsCreatedMediaEngine = false;
    124 
    125  Microsoft::WRL::ComPtr<IMFDXGIDeviceManager> mDXGIDeviceManager;
    126 
    127  // These will be always zero for audio playback.
    128  DWORD mDisplayWidth = 0;
    129  DWORD mDisplayHeight = 0;
    130 
    131  float mPlaybackRate = 1.0;
    132 
    133  // When flush happens inside the media engine, it will reset the statistic
    134  // data. Therefore, whenever the statistic data gets reset, we will use
    135  // `mCurrentPlaybackStatisticData` to track new data and store previous data
    136  // to `mPrevPlaybackStatisticData`. The sum of these two data is the total
    137  // statistic data for playback.
    138  StatisticData mCurrentPlaybackStatisticData;
    139  StatisticData mPrevPlaybackStatisticData;
    140 };
    141 
    142 }  // namespace mozilla
    143 
    144 #endif  // DOM_MEDIA_IPC_MFMEDIAENGINEPARENT_H_