From f8343f2b4d4b5d663cb5ffff4d7375906beeb78d Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Tue, 20 Oct 2020 23:26:25 +0000 Subject: [PATCH] Bug 1595994 - P6: Change Supports to take SupportDecoderParams. r=kamidphish This is a subset of the parameters passed via CreateDecoderParams and is so Supports() calls have access to KnowsCompositor and Options when determining if decoding is supported. Depends on D54877 Differential Revision: https://phabricator.services.mozilla.com/D54878 --- dom/media/ipc/GpuDecoderModule.cpp | 4 +- dom/media/ipc/GpuDecoderModule.h | 2 +- .../mediacapabilities/MediaCapabilities.cpp | 3 +- dom/media/mp4/MP4Decoder.cpp | 3 +- dom/media/platforms/PDMFactory.cpp | 21 ++- dom/media/platforms/PDMFactory.h | 6 +- dom/media/platforms/PlatformDecoderModule.h | 155 +++++++++++++----- .../platforms/apple/AppleDecoderModule.cpp | 12 +- .../platforms/apple/AppleDecoderModule.h | 2 +- dom/media/platforms/wmf/WMFDecoderModule.cpp | 21 +-- dom/media/platforms/wmf/WMFDecoderModule.h | 2 +- dom/media/webm/WebMDecoder.cpp | 3 +- 12 files changed, 157 insertions(+), 77 deletions(-) diff --git a/dom/media/ipc/GpuDecoderModule.cpp b/dom/media/ipc/GpuDecoderModule.cpp index d09eb39574a4..0bb809f5e59d 100644 --- a/dom/media/ipc/GpuDecoderModule.cpp +++ b/dom/media/ipc/GpuDecoderModule.cpp @@ -29,9 +29,9 @@ bool GpuDecoderModule::SupportsMimeType( return mWrapped->SupportsMimeType(aMimeType, aDiagnostics); } -bool GpuDecoderModule::Supports(const TrackInfo& aTrackInfo, +bool GpuDecoderModule::Supports(const SupportDecoderParams& aParams, DecoderDoctorDiagnostics* aDiagnostics) const { - return mWrapped->Supports(aTrackInfo, aDiagnostics); + return mWrapped->Supports(aParams, aDiagnostics); } static inline bool IsRemoteAcceleratedCompositor(KnowsCompositor* aKnows) { diff --git a/dom/media/ipc/GpuDecoderModule.h b/dom/media/ipc/GpuDecoderModule.h index 583035516630..2c96de955ca5 100644 --- a/dom/media/ipc/GpuDecoderModule.h +++ b/dom/media/ipc/GpuDecoderModule.h @@ -27,7 +27,7 @@ class GpuDecoderModule : public PlatformDecoderModule { bool SupportsMimeType(const nsACString& aMimeType, DecoderDoctorDiagnostics* aDiagnostics) const override; - bool Supports(const TrackInfo& aTrackInfo, + bool Supports(const SupportDecoderParams& aParams, DecoderDoctorDiagnostics* aDiagnostics) const override; already_AddRefed CreateVideoDecoder( diff --git a/dom/media/mediacapabilities/MediaCapabilities.cpp b/dom/media/mediacapabilities/MediaCapabilities.cpp index f25f3a0dd0cf..10b2e046d08b 100644 --- a/dom/media/mediacapabilities/MediaCapabilities.cpp +++ b/dom/media/mediacapabilities/MediaCapabilities.cpp @@ -215,7 +215,8 @@ already_AddRefed MediaCapabilities::DecodingInfo( // There's no need to create an audio decoder has we only want to know if // such codec is supported RefPtr pdm = new PDMFactory(); - if (!pdm->Supports(*config, nullptr /* decoder doctor */)) { + SupportDecoderParams params{*config}; + if (!pdm->Supports(params, nullptr /* decoder doctor */)) { auto info = MakeUnique( false /* supported */, false /* smooth */, false /* power efficient */); diff --git a/dom/media/mp4/MP4Decoder.cpp b/dom/media/mp4/MP4Decoder.cpp index a1ecebf29c2b..848612063f88 100644 --- a/dom/media/mp4/MP4Decoder.cpp +++ b/dom/media/mp4/MP4Decoder.cpp @@ -171,7 +171,8 @@ bool MP4Decoder::IsSupportedType(const MediaContainerType& aType, // Verify that we have a PDM that supports the whitelisted types. RefPtr platform = new PDMFactory(); for (const auto& track : tracks) { - if (!track || !platform->Supports(*track, aDiagnostics)) { + if (!track || + !platform->Supports(SupportDecoderParams(*track), aDiagnostics)) { return false; } } diff --git a/dom/media/platforms/PDMFactory.cpp b/dom/media/platforms/PDMFactory.cpp index 8a6095a8c6e9..7cc3a0880df2 100644 --- a/dom/media/platforms/PDMFactory.cpp +++ b/dom/media/platforms/PDMFactory.cpp @@ -221,7 +221,7 @@ already_AddRefed PDMFactory::CreateDecoder( } for (auto& current : mCurrentPDMs) { - if (!current->Supports(config, diagnostics)) { + if (!current->Supports(SupportDecoderParams(aParams), diagnostics)) { continue; } decoder = CreateDecoderWithPDM(current, aParams); @@ -313,15 +313,15 @@ bool PDMFactory::SupportsMimeType( if (!trackInfo) { return false; } - return Supports(*trackInfo, aDiagnostics); + return Supports(SupportDecoderParams(*trackInfo), aDiagnostics); } -bool PDMFactory::Supports(const TrackInfo& aTrackInfo, +bool PDMFactory::Supports(const SupportDecoderParams& aParams, DecoderDoctorDiagnostics* aDiagnostics) const { if (mEMEPDM) { - return mEMEPDM->Supports(aTrackInfo, aDiagnostics); + return mEMEPDM->Supports(aParams, aDiagnostics); } - if (VPXDecoder::IsVPX(aTrackInfo.mMimeType, + if (VPXDecoder::IsVPX(aParams.MimeType(), VPXDecoder::VP8 | VPXDecoder::VP9)) { // Work around bug 1521370, where trying to instantiate an external decoder // could cause a crash. @@ -329,7 +329,9 @@ bool PDMFactory::Supports(const TrackInfo& aTrackInfo, // So we can speed up the test by assuming that this codec is supported. return true; } - RefPtr current = GetDecoder(aTrackInfo, aDiagnostics); + + RefPtr current = + GetDecoderModule(aParams, aDiagnostics); return !!current; } @@ -433,8 +435,9 @@ bool PDMFactory::StartupPDM(already_AddRefed aPDM, return false; } -already_AddRefed PDMFactory::GetDecoder( - const TrackInfo& aTrackInfo, DecoderDoctorDiagnostics* aDiagnostics) const { +already_AddRefed PDMFactory::GetDecoderModule( + const SupportDecoderParams& aParams, + DecoderDoctorDiagnostics* aDiagnostics) const { if (aDiagnostics) { // If libraries failed to load, the following loop over mCurrentPDMs // will not even try to use them. So we record failures now. @@ -451,7 +454,7 @@ already_AddRefed PDMFactory::GetDecoder( RefPtr pdm; for (auto& current : mCurrentPDMs) { - if (current->Supports(aTrackInfo, aDiagnostics)) { + if (current->Supports(aParams, aDiagnostics)) { pdm = current; break; } diff --git a/dom/media/platforms/PDMFactory.h b/dom/media/platforms/PDMFactory.h index 4ce09cddf5f7..9ed7d475a349 100644 --- a/dom/media/platforms/PDMFactory.h +++ b/dom/media/platforms/PDMFactory.h @@ -35,7 +35,7 @@ class PDMFactory final { bool SupportsMimeType(const nsACString& aMimeType, DecoderDoctorDiagnostics* aDiagnostics) const; - bool Supports(const TrackInfo& aTrackInfo, + bool Supports(const SupportDecoderParams& aParams, DecoderDoctorDiagnostics* aDiagnostics) const; // Creates a PlatformDecoderModule that uses a CDMProxy to decrypt or @@ -67,8 +67,8 @@ class PDMFactory final { bool StartupPDM(already_AddRefed aPDM, bool aInsertAtBeginning = false); // Returns the first PDM in our list supporting the mimetype. - already_AddRefed GetDecoder( - const TrackInfo& aTrackInfo, + already_AddRefed GetDecoderModule( + const SupportDecoderParams& aParams, DecoderDoctorDiagnostics* aDiagnostics) const; already_AddRefed CreateDecoderWithPDM( diff --git a/dom/media/platforms/PlatformDecoderModule.h b/dom/media/platforms/PlatformDecoderModule.h index 7cc30756c75d..fa1bc9f6a867 100644 --- a/dom/media/platforms/PlatformDecoderModule.h +++ b/dom/media/platforms/PlatformDecoderModule.h @@ -41,45 +41,54 @@ class CDMProxy; static LazyLogModule sPDMLog("PlatformDecoderModule"); +namespace media { + +enum class Option { + Default, + LowLatency, + HardwareDecoderNotAllowed, + FullH264Parsing, + ErrorIfNoInitializationData, // By default frames delivered before + // initialization data are dropped. Pass this + // option to raise an error if frames are + // delivered before initialization data. + DefaultPlaybackDeviceMono, // Currently only used by Opus on RDD to avoid + // initialization of audio backends on RDD + + SENTINEL // one past the last valid value +}; +using OptionSet = EnumSet