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/. */
7 #if !defined(PDMFactory_h_)
10 # include "DecoderDoctorDiagnostics.h"
11 # include "MediaCodecsSupport.h"
12 # include "PlatformDecoderModule.h"
13 # include "mozilla/AlreadyAddRefed.h"
14 # include "mozilla/EnumSet.h"
15 # include "mozilla/MozPromise.h"
16 # include "mozilla/RefPtr.h"
17 # include "mozilla/ipc/UtilityProcessSandboxing.h"
18 # include "nsISupports.h"
19 # include "nsStringFwd.h"
20 # include "nsTArray.h"
26 class MediaDataDecoder
;
29 struct CreateDecoderParams
;
30 struct CreateDecoderParamsForAsync
;
31 struct SupportDecoderParams
;
32 enum class RemoteDecodeIn
;
34 using PDMCreateDecoderPromise
= PlatformDecoderModule::CreateDecoderPromise
;
36 class PDMFactory final
{
38 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PDMFactory
)
42 // Factory method that creates the appropriate PlatformDecoderModule for
43 // the platform we're running on.
44 RefPtr
<PDMCreateDecoderPromise
> CreateDecoder(
45 const CreateDecoderParams
& aParams
);
47 media::DecodeSupportSet
SupportsMimeType(const nsACString
& aMimeType
) const;
48 media::DecodeSupportSet
Supports(
49 const SupportDecoderParams
& aParams
,
50 DecoderDoctorDiagnostics
* aDiagnostics
) const;
52 // Creates a PlatformDecoderModule that uses a CDMProxy to decrypt or
53 // decrypt-and-decode EME encrypted content. If the CDM only decrypts and
54 // does not decode, we create a PDM and use that to create MediaDataDecoders
55 // that we use on on aTaskQueue to decode the decrypted stream.
56 // This is called on the decode task queue.
57 void SetCDMProxy(CDMProxy
* aProxy
);
59 static constexpr int kYUV400
= 0;
60 static constexpr int kYUV420
= 1;
61 static constexpr int kYUV422
= 2;
62 static constexpr int kYUV444
= 3;
64 static media::MediaCodecsSupported
Supported(bool aForceRefresh
= false);
65 static media::DecodeSupportSet
SupportsMimeType(
66 const nsACString
& aMimeType
,
67 const media::MediaCodecsSupported
& aSupported
, RemoteDecodeIn aLocation
);
69 static bool AllDecodersAreRemote();
72 virtual ~PDMFactory();
78 void CreateUtilityPDMs();
79 void CreateContentPDMs();
80 void CreateDefaultPDMs();
82 template <typename DECODER_MODULE
, typename
... ARGS
>
83 bool CreateAndStartupPDM(ARGS
&&... aArgs
) {
84 return StartupPDM(DECODER_MODULE::Create(std::forward
<ARGS
>(aArgs
)...));
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;
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());
101 nsTArray
<RefPtr
<PlatformDecoderModule
>> mCurrentPDMs
;
102 RefPtr
<PlatformDecoderModule
> mEMEPDM
;
103 RefPtr
<PlatformDecoderModule
> mNullPDM
;
105 DecoderDoctorDiagnostics::FlagsSet mFailureFlags
;
107 friend class RemoteVideoDecoderParent
;
108 static void EnsureInit();
111 } // namespace mozilla
113 #endif /* PDMFactory_h_ */