RemoteMediaDataDecoder.h (3141B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 #ifndef include_dom_media_ipc_RemoteMediaDataDecoder_h 7 #define include_dom_media_ipc_RemoteMediaDataDecoder_h 8 #include "MediaData.h" 9 #include "PlatformDecoderModule.h" 10 #include "mozilla/EnumeratedArray.h" 11 12 namespace mozilla { 13 14 class RemoteDecoderChild; 15 class RemoteDecoderManagerChild; 16 class RemoteMediaDataDecoder; 17 18 DDLoggedTypeCustomNameAndBase(RemoteMediaDataDecoder, RemoteMediaDataDecoder, 19 MediaDataDecoder); 20 21 // A MediaDataDecoder implementation that proxies through IPDL 22 // to a 'real' decoder in the GPU or RDD process. 23 // All requests get forwarded to a *DecoderChild instance that 24 // operates solely on the provided manager and abstract manager threads. 25 class RemoteMediaDataDecoder final 26 : public MediaDataDecoder, 27 public DecoderDoctorLifeLogger<RemoteMediaDataDecoder> { 28 public: 29 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RemoteMediaDataDecoder, final); 30 31 explicit RemoteMediaDataDecoder(RemoteDecoderChild* aChild); 32 33 // MediaDataDecoder 34 RefPtr<InitPromise> Init() override; 35 RefPtr<DecodePromise> Decode(MediaRawData* aSample) override; 36 bool CanDecodeBatch() const override { return true; } 37 RefPtr<DecodePromise> DecodeBatch( 38 nsTArray<RefPtr<MediaRawData>>&& aSamples) override; 39 RefPtr<DecodePromise> Drain() override; 40 RefPtr<FlushPromise> Flush() override; 41 RefPtr<ShutdownPromise> Shutdown() override; 42 bool IsHardwareAccelerated(nsACString& aFailureReason) const override; 43 void SetSeekThreshold(const media::TimeUnit& aTime) override; 44 nsCString GetDescriptionName() const override; 45 nsCString GetProcessName() const override; 46 nsCString GetCodecName() const override; 47 ConversionRequired NeedsConversion() const override; 48 Maybe<PropertyValue> GetDecodeProperty(PropertyName aName) const override; 49 bool ShouldDecoderAlwaysBeRecycled() const override; 50 51 private: 52 ~RemoteMediaDataDecoder(); 53 54 // Only ever written to from the reader task queue (during the constructor and 55 // destructor when we can guarantee no other threads are accessing it). Only 56 // read from the manager thread. 57 RefPtr<RemoteDecoderChild> mChild; 58 59 mutable Mutex mMutex{"RemoteMediaDataDecoder"}; 60 61 // Only ever written/modified during decoder initialisation. 62 nsCString mDescription MOZ_GUARDED_BY(mMutex); 63 nsCString mProcessName MOZ_GUARDED_BY(mMutex); 64 nsCString mCodecName MOZ_GUARDED_BY(mMutex); 65 bool mIsHardwareAccelerated MOZ_GUARDED_BY(mMutex); 66 nsCString mHardwareAcceleratedReason MOZ_GUARDED_BY(mMutex); 67 ConversionRequired mConversion MOZ_GUARDED_BY(mMutex); 68 bool mShouldDecoderAlwaysBeRecycled MOZ_GUARDED_BY(mMutex); 69 EnumeratedArray<PropertyName, Maybe<PropertyValue>, sPropertyNameCount> 70 mDecodeProperties MOZ_GUARDED_BY(mMutex); 71 }; 72 73 } // namespace mozilla 74 75 #endif // include_dom_media_ipc_RemoteMediaDataDecoder_h