PEMFactory.h (2462B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 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 7 #if !defined(PEMFactory_h_) 8 # define PEMFactory_h_ 9 10 # include "MediaCodecsSupport.h" 11 # include "PlatformEncoderModule.h" 12 13 namespace mozilla { 14 15 class StaticMutex; 16 enum class RemoteMediaIn; 17 18 using PEMCreateEncoderPromise = PlatformEncoderModule::CreateEncoderPromise; 19 20 class PEMFactory final { 21 public: 22 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PEMFactory) 23 24 PEMFactory(); 25 26 // Factory method that creates the appropriate PlatformEncoderModule for 27 // the platform we're running on. Caller is responsible for deleting this 28 // instance. It's expected that there will be multiple 29 // PlatformEncoderModules alive at the same time. 30 already_AddRefed<MediaDataEncoder> CreateEncoder( 31 const EncoderConfig& aConfig, const RefPtr<TaskQueue>& aTaskQueue); 32 33 RefPtr<PlatformEncoderModule::CreateEncoderPromise> CreateEncoderAsync( 34 const EncoderConfig& aConfig, const RefPtr<TaskQueue>& aTaskQueue); 35 36 media::EncodeSupportSet Supports(const EncoderConfig& aConfig) const; 37 media::EncodeSupportSet SupportsCodec(CodecType aCodec) const; 38 39 static media::MediaCodecsSupported Supported(bool aForceRefresh = false); 40 static media::EncodeSupportSet SupportsCodec( 41 CodecType aCodec, const media::MediaCodecsSupported& aSupported, 42 RemoteMediaIn aLocation); 43 44 private: 45 void InitGpuPEMs(); 46 void InitRddPEMs(); 47 void InitUtilityPEMs(); 48 void InitContentPEMs(); 49 void InitDefaultPEMs(); 50 51 RefPtr<PlatformEncoderModule::CreateEncoderPromise> 52 CheckAndMaybeCreateEncoder(const EncoderConfig& aConfig, uint32_t aIndex, 53 const RefPtr<TaskQueue>& aTaskQueue); 54 55 RefPtr<PlatformEncoderModule::CreateEncoderPromise> CreateEncoderWithPEM( 56 PlatformEncoderModule* aPEM, const EncoderConfig& aConfig, 57 const RefPtr<TaskQueue>& aTaskQueue); 58 virtual ~PEMFactory() = default; 59 // Returns the first PEM in our list supporting the codec. 60 already_AddRefed<PlatformEncoderModule> FindPEM( 61 const EncoderConfig& aConfig) const; 62 63 nsTArray<RefPtr<PlatformEncoderModule>> mCurrentPEMs; 64 65 static StaticMutex sSupportedMutex; 66 }; 67 68 } // namespace mozilla 69 70 #endif /* PEMFactory_h_ */