GMPContentChild.cpp (4279B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "GMPContentChild.h" 7 8 #include "ChromiumCDMChild.h" 9 #include "ChromiumCDMCompat.h" 10 #include "GMPChild.h" 11 #include "GMPUtils.h" 12 #include "GMPVideoDecoderChild.h" 13 #include "GMPVideoEncoderChild.h" 14 #include "base/task.h" 15 16 namespace mozilla::gmp { 17 18 MessageLoop* GMPContentChild::GMPMessageLoop() { 19 return mGMPChild->GMPMessageLoop(); 20 } 21 22 #if defined(MOZ_SANDBOX) && defined(MOZ_DEBUG) && defined(ENABLE_TESTS) 23 mozilla::ipc::IPCResult GMPContentChild::RecvInitSandboxTesting( 24 Endpoint<PSandboxTestingChild>&& aEndpoint) { 25 if (!SandboxTestingChild::Initialize(std::move(aEndpoint))) { 26 return IPC_FAIL( 27 this, "InitSandboxTesting failed to initialise the child process."); 28 } 29 return IPC_OK(); 30 } 31 #endif 32 33 void GMPContentChild::ActorDestroy(ActorDestroyReason aWhy) { 34 mGMPChild->GMPContentChildActorDestroy(this); 35 } 36 37 void GMPContentChild::ProcessingError(Result aCode, const char* aReason) { 38 mGMPChild->ProcessingError(aCode, aReason); 39 } 40 41 already_AddRefed<PGMPVideoDecoderChild> 42 GMPContentChild::AllocPGMPVideoDecoderChild() { 43 return MakeAndAddRef<GMPVideoDecoderChild>(this); 44 } 45 46 already_AddRefed<PGMPVideoEncoderChild> 47 GMPContentChild::AllocPGMPVideoEncoderChild() { 48 return MakeAndAddRef<GMPVideoEncoderChild>(this); 49 } 50 51 already_AddRefed<PChromiumCDMChild> GMPContentChild::AllocPChromiumCDMChild( 52 const nsACString& aKeySystem) { 53 return MakeAndAddRef<ChromiumCDMChild>(this); 54 } 55 56 mozilla::ipc::IPCResult GMPContentChild::RecvPGMPVideoDecoderConstructor( 57 PGMPVideoDecoderChild* aActor) { 58 auto vdc = static_cast<GMPVideoDecoderChild*>(aActor); 59 60 void* vd = nullptr; 61 GMPErr err = mGMPChild->GetAPI(GMP_API_VIDEO_DECODER, &vdc->Host(), &vd); 62 if (err != GMPNoErr || !vd) { 63 return IPC_FAIL(this, "GMPGetAPI call failed trying to construct decoder."); 64 } 65 66 vdc->Init(static_cast<GMPVideoDecoder*>(vd)); 67 68 return IPC_OK(); 69 } 70 71 mozilla::ipc::IPCResult GMPContentChild::RecvPGMPVideoEncoderConstructor( 72 PGMPVideoEncoderChild* aActor) { 73 auto vec = static_cast<GMPVideoEncoderChild*>(aActor); 74 75 void* ve = nullptr; 76 GMPErr err = mGMPChild->GetAPI(GMP_API_VIDEO_ENCODER, &vec->Host(), &ve); 77 if (err != GMPNoErr || !ve) { 78 return IPC_FAIL(this, "GMPGetAPI call failed trying to construct encoder."); 79 } 80 81 vec->Init(static_cast<GMPVideoEncoder*>(ve)); 82 83 return IPC_OK(); 84 } 85 86 mozilla::ipc::IPCResult GMPContentChild::RecvPChromiumCDMConstructor( 87 PChromiumCDMChild* aActor, const nsACString& aKeySystem) { 88 ChromiumCDMChild* child = static_cast<ChromiumCDMChild*>(aActor); 89 90 void* cdm = nullptr; 91 GMPErr err = mGMPChild->GetAPI( 92 CHROMIUM_CDM_API, static_cast<cdm::Host_11*>(child), &cdm, aKeySystem); 93 if (err != GMPNoErr || !cdm) { 94 err = 95 mGMPChild->GetAPI(CHROMIUM_CDM_API_BACKWARD_COMPAT, 96 static_cast<cdm::Host_10*>(child), &cdm, aKeySystem); 97 if (err != GMPNoErr || !cdm) { 98 return IPC_FAIL(this, "GMPGetAPI call failed trying to get CDM."); 99 } 100 101 cdm = new ChromiumCDMCompat( 102 static_cast<cdm::ContentDecryptionModule_10*>(cdm)); 103 } 104 105 child->Init(static_cast<cdm::ContentDecryptionModule_11*>(cdm), 106 mGMPChild->mStorageId); 107 108 return IPC_OK(); 109 } 110 111 void GMPContentChild::CloseActive() { 112 // Invalidate and remove any remaining API objects. 113 const ManagedContainer<PGMPVideoDecoderChild>& videoDecoders = 114 ManagedPGMPVideoDecoderChild(); 115 for (const auto& key : videoDecoders) { 116 key->SendShutdown(); 117 } 118 119 const ManagedContainer<PGMPVideoEncoderChild>& videoEncoders = 120 ManagedPGMPVideoEncoderChild(); 121 for (const auto& key : videoEncoders) { 122 key->SendShutdown(); 123 } 124 125 const ManagedContainer<PChromiumCDMChild>& cdms = ManagedPChromiumCDMChild(); 126 for (const auto& key : cdms) { 127 key->SendShutdown(); 128 } 129 } 130 131 bool GMPContentChild::IsUsed() { 132 return !ManagedPGMPVideoDecoderChild().IsEmpty() || 133 !ManagedPGMPVideoEncoderChild().IsEmpty() || 134 !ManagedPChromiumCDMChild().IsEmpty(); 135 } 136 137 } // namespace mozilla::gmp