PDMFactory.h (3857B)
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(PDMFactory_h_) 8 # define PDMFactory_h_ 9 10 # include "DecoderDoctorDiagnostics.h" 11 # include "MediaCodecsSupport.h" 12 # include "PlatformDecoderModule.h" 13 # include "mozilla/AlreadyAddRefed.h" 14 # include "mozilla/MozPromise.h" 15 # include "mozilla/RefPtr.h" 16 # include "mozilla/ipc/UtilityProcessSandboxing.h" 17 # include "nsISupports.h" 18 # include "nsStringFwd.h" 19 # include "nsTArray.h" 20 21 namespace mozilla { 22 23 class CDMProxy; 24 class MediaDataDecoder; 25 class MediaResult; 26 class StaticMutex; 27 struct CreateDecoderParams; 28 struct CreateDecoderParamsForAsync; 29 struct SupportDecoderParams; 30 enum class RemoteMediaIn; 31 32 using PDMCreateDecoderPromise = PlatformDecoderModule::CreateDecoderPromise; 33 34 class PDMFactory final { 35 public: 36 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PDMFactory) 37 38 PDMFactory(); 39 40 // Factory method that creates the appropriate PlatformDecoderModule for 41 // the platform we're running on. 42 RefPtr<PDMCreateDecoderPromise> CreateDecoder( 43 const CreateDecoderParams& aParams); 44 45 media::DecodeSupportSet SupportsMimeType(const nsACString& aMimeType) const; 46 media::DecodeSupportSet Supports( 47 const SupportDecoderParams& aParams, 48 DecoderDoctorDiagnostics* aDiagnostics) const; 49 50 // Creates a PlatformDecoderModule that uses a CDMProxy to decrypt or 51 // decrypt-and-decode EME encrypted content. If the CDM only decrypts and 52 // does not decode, we create a PDM and use that to create MediaDataDecoders 53 // that we use on on aTaskQueue to decode the decrypted stream. 54 // This is called on the decode task queue. 55 void SetCDMProxy(CDMProxy* aProxy); 56 57 static constexpr int kYUV400 = 0; 58 static constexpr int kYUV420 = 1; 59 static constexpr int kYUV422 = 2; 60 static constexpr int kYUV444 = 3; 61 62 static media::MediaCodecsSupported Supported(bool aForceRefresh = false); 63 static media::DecodeSupportSet SupportsMimeType( 64 const nsACString& aMimeType, 65 const media::MediaCodecsSupported& aSupported, RemoteMediaIn aLocation); 66 67 static bool AllDecodersAreRemote(); 68 69 // For GTests 70 class MOZ_RAII AutoForcePDM { 71 public: 72 explicit AutoForcePDM(PlatformDecoderModule* aPDM) { ForcePDM(aPDM); } 73 ~AutoForcePDM() { ForcePDM(nullptr); } 74 }; 75 76 private: 77 ~PDMFactory(); 78 79 void CreatePDMs(); 80 void CreateNullPDM(); 81 void CreateGpuPDMs(); 82 void CreateRddPDMs(); 83 void CreateUtilityPDMs(); 84 void CreateContentPDMs(); 85 void CreateDefaultPDMs(); 86 87 // Startup the provided PDM and add it to our list if successful. 88 bool StartupPDM(already_AddRefed<PlatformDecoderModule> aPDM, 89 bool aInsertAtBeginning = false); 90 // Returns the first PDM in our list supporting the mimetype. 91 already_AddRefed<PlatformDecoderModule> GetDecoderModule( 92 const SupportDecoderParams& aParams, 93 DecoderDoctorDiagnostics* aDiagnostics) const; 94 95 RefPtr<PDMCreateDecoderPromise> CreateDecoderWithPDM( 96 PlatformDecoderModule* aPDM, const CreateDecoderParams& aParams); 97 RefPtr<PDMCreateDecoderPromise> CheckAndMaybeCreateDecoder( 98 CreateDecoderParamsForAsync&& aParams, uint32_t aIndex, 99 Maybe<MediaResult> aEarlierError = Nothing()); 100 101 nsTArray<RefPtr<PlatformDecoderModule>> mCurrentPDMs; 102 RefPtr<PlatformDecoderModule> mEMEPDM; 103 RefPtr<PlatformDecoderModule> mNullPDM; 104 105 DecoderDoctorDiagnostics::FlagsSet mFailureFlags; 106 107 static StaticMutex sSupportedMutex; 108 109 friend class RemoteVideoDecoderParent; 110 static void EnsureInit(); 111 static void ForcePDM(PlatformDecoderModule* aPDM); 112 }; 113 114 } // namespace mozilla 115 116 #endif /* PDMFactory_h_ */