RemoteDecoderModule.cpp (4205B)
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 #include "RemoteDecoderModule.h" 7 8 #ifdef MOZ_AV1 9 # include "AOMDecoder.h" 10 #endif 11 #include "RemoteAudioDecoder.h" 12 #include "RemoteMediaDataDecoder.h" 13 #include "RemoteMediaManagerChild.h" 14 #include "RemoteVideoDecoder.h" 15 #include "VideoUtils.h" 16 #include "gfxConfig.h" 17 #include "mozilla/RemoteDecodeUtils.h" 18 19 namespace mozilla { 20 21 using namespace ipc; 22 using namespace layers; 23 24 already_AddRefed<PlatformDecoderModule> RemoteDecoderModule::Create( 25 RemoteMediaIn aLocation) { 26 MOZ_ASSERT(!XRE_IsGPUProcess() && !XRE_IsRDDProcess(), 27 "Should not be created in GPU or RDD process."); 28 if (!XRE_IsContentProcess()) { 29 // For now, the RemoteDecoderModule is only available in the content 30 // process. 31 return nullptr; 32 } 33 return MakeAndAddRef<RemoteDecoderModule>(aLocation); 34 } 35 36 RemoteDecoderModule::RemoteDecoderModule(RemoteMediaIn aLocation) 37 : mLocation(aLocation) {} 38 39 const char* RemoteDecoderModule::Name() const { 40 switch (mLocation) { 41 case RemoteMediaIn::Unspecified: 42 return "Remote: Unspecified"; 43 case RemoteMediaIn::RddProcess: 44 return "Remote: RddProcess"; 45 case RemoteMediaIn::GpuProcess: 46 return "Remote: GpuProcess"; 47 case RemoteMediaIn::UtilityProcess_Generic: 48 return "Remote: Utility_Generic"; 49 case RemoteMediaIn::UtilityProcess_AppleMedia: 50 return "Remote: Utility_AppleMedia"; 51 case RemoteMediaIn::UtilityProcess_WMF: 52 return "Remote: Utility_WMF"; 53 case RemoteMediaIn::UtilityProcess_MFMediaEngineCDM: 54 return "Remote: Utility_MFMediaEngineCDM"; 55 default: 56 MOZ_CRASH("Missing enum handling"); 57 } 58 } 59 60 media::DecodeSupportSet RemoteDecoderModule::SupportsMimeType( 61 const nsACString& aMimeType, DecoderDoctorDiagnostics* aDiagnostics) const { 62 MOZ_CRASH("Deprecated: Use RemoteDecoderModule::Supports"); 63 } // namespace mozilla 64 65 media::DecodeSupportSet RemoteDecoderModule::Supports( 66 const SupportDecoderParams& aParams, 67 DecoderDoctorDiagnostics* aDiagnostics) const { 68 bool supports = 69 RemoteMediaManagerChild::Supports(mLocation, aParams, aDiagnostics); 70 #ifdef MOZ_WMF_CDM 71 // This should only be supported by mf media engine cdm process. 72 if (aParams.mMediaEngineId && 73 mLocation != RemoteMediaIn::UtilityProcess_MFMediaEngineCDM) { 74 supports = false; 75 } 76 #endif 77 #ifdef ANDROID 78 if ((aParams.mCDM && mLocation != RemoteMediaIn::RddProcess) || 79 (!aParams.mCDM && aParams.mConfig.IsAudio() && 80 mLocation != RemoteMediaIn::UtilityProcess_Generic)) { 81 supports = false; 82 } 83 #endif 84 MOZ_LOG( 85 sPDMLog, LogLevel::Debug, 86 ("Sandbox %s decoder %s requested type %s", RemoteMediaInToStr(mLocation), 87 supports ? "supports" : "rejects", aParams.MimeType().get())); 88 if (supports) { 89 // TODO: Note that we do not yet distinguish between SW/HW decode support. 90 // Will be done in bug 1754239. 91 return media::DecodeSupport::SoftwareDecode; 92 } 93 return media::DecodeSupportSet{}; 94 } 95 96 RefPtr<RemoteDecoderModule::CreateDecoderPromise> 97 RemoteDecoderModule::AsyncCreateDecoder(const CreateDecoderParams& aParams) { 98 if (aParams.mConfig.IsAudio()) { 99 // OpusDataDecoder will check this option to provide the same info 100 // that IsDefaultPlaybackDeviceMono provides. We want to avoid calls 101 // to IsDefaultPlaybackDeviceMono on RDD because initializing audio 102 // backends on RDD will be blocked by the sandbox. 103 if (aParams.mConfig.mMimeType.Equals("audio/opus") && 104 IsDefaultPlaybackDeviceMono()) { 105 CreateDecoderParams params = aParams; 106 params.mOptions += CreateDecoderParams::Option::DefaultPlaybackDeviceMono; 107 return RemoteMediaManagerChild::CreateAudioDecoder(params, mLocation); 108 } 109 return RemoteMediaManagerChild::CreateAudioDecoder(aParams, mLocation); 110 } 111 return RemoteMediaManagerChild::CreateVideoDecoder(aParams, mLocation); 112 } 113 114 } // namespace mozilla