Line data Source code
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 : #include "GMPChild.h"
8 : #include "GMPDecryptorChild.h"
9 : #include "GMPVideoDecoderChild.h"
10 : #include "GMPVideoEncoderChild.h"
11 : #include "ChromiumCDMChild.h"
12 : #include "base/task.h"
13 :
14 : namespace mozilla {
15 : namespace gmp {
16 :
17 0 : GMPContentChild::GMPContentChild(GMPChild* aChild)
18 0 : : mGMPChild(aChild)
19 : {
20 0 : MOZ_COUNT_CTOR(GMPContentChild);
21 0 : }
22 :
23 0 : GMPContentChild::~GMPContentChild()
24 : {
25 0 : MOZ_COUNT_DTOR(GMPContentChild);
26 0 : }
27 :
28 : MessageLoop*
29 0 : GMPContentChild::GMPMessageLoop()
30 : {
31 0 : return mGMPChild->GMPMessageLoop();
32 : }
33 :
34 : void
35 0 : GMPContentChild::CheckThread()
36 : {
37 0 : MOZ_ASSERT(mGMPChild->mGMPMessageLoop == MessageLoop::current());
38 0 : }
39 :
40 : void
41 0 : GMPContentChild::ActorDestroy(ActorDestroyReason aWhy)
42 : {
43 0 : mGMPChild->GMPContentChildActorDestroy(this);
44 0 : }
45 :
46 : void
47 0 : GMPContentChild::ProcessingError(Result aCode, const char* aReason)
48 : {
49 0 : mGMPChild->ProcessingError(aCode, aReason);
50 0 : }
51 :
52 : PGMPDecryptorChild*
53 0 : GMPContentChild::AllocPGMPDecryptorChild()
54 : {
55 0 : GMPDecryptorChild* actor = new GMPDecryptorChild(this);
56 0 : actor->AddRef();
57 0 : return actor;
58 : }
59 :
60 : bool
61 0 : GMPContentChild::DeallocPGMPDecryptorChild(PGMPDecryptorChild* aActor)
62 : {
63 0 : static_cast<GMPDecryptorChild*>(aActor)->Release();
64 0 : return true;
65 : }
66 :
67 : PGMPVideoDecoderChild*
68 0 : GMPContentChild::AllocPGMPVideoDecoderChild(const uint32_t& aDecryptorId)
69 : {
70 0 : GMPVideoDecoderChild* actor = new GMPVideoDecoderChild(this);
71 0 : actor->AddRef();
72 0 : return actor;
73 : }
74 :
75 : bool
76 0 : GMPContentChild::DeallocPGMPVideoDecoderChild(PGMPVideoDecoderChild* aActor)
77 : {
78 0 : static_cast<GMPVideoDecoderChild*>(aActor)->Release();
79 0 : return true;
80 : }
81 :
82 : PGMPVideoEncoderChild*
83 0 : GMPContentChild::AllocPGMPVideoEncoderChild()
84 : {
85 0 : GMPVideoEncoderChild* actor = new GMPVideoEncoderChild(this);
86 0 : actor->AddRef();
87 0 : return actor;
88 : }
89 :
90 : bool
91 0 : GMPContentChild::DeallocPGMPVideoEncoderChild(PGMPVideoEncoderChild* aActor)
92 : {
93 0 : static_cast<GMPVideoEncoderChild*>(aActor)->Release();
94 0 : return true;
95 : }
96 :
97 : PChromiumCDMChild*
98 0 : GMPContentChild::AllocPChromiumCDMChild()
99 : {
100 0 : ChromiumCDMChild* actor = new ChromiumCDMChild(this);
101 0 : actor->AddRef();
102 0 : return actor;
103 : }
104 :
105 : bool
106 0 : GMPContentChild::DeallocPChromiumCDMChild(PChromiumCDMChild* aActor)
107 : {
108 0 : static_cast<ChromiumCDMChild*>(aActor)->Release();
109 0 : return true;
110 : }
111 :
112 : mozilla::ipc::IPCResult
113 0 : GMPContentChild::RecvPGMPDecryptorConstructor(PGMPDecryptorChild* aActor)
114 : {
115 0 : GMPDecryptorChild* child = static_cast<GMPDecryptorChild*>(aActor);
116 :
117 0 : void* ptr = nullptr;
118 0 : GMPErr err = mGMPChild->GetAPI(GMP_API_DECRYPTOR, nullptr, &ptr, child->DecryptorId());
119 0 : if (err != GMPNoErr || !ptr) {
120 0 : NS_WARNING("GMPGetAPI call failed trying to construct decryptor.");
121 0 : return IPC_FAIL_NO_REASON(this);
122 : }
123 0 : child->Init(static_cast<GMPDecryptor*>(ptr));
124 :
125 0 : return IPC_OK();
126 : }
127 :
128 : mozilla::ipc::IPCResult
129 0 : GMPContentChild::RecvPGMPVideoDecoderConstructor(PGMPVideoDecoderChild* aActor,
130 : const uint32_t& aDecryptorId)
131 : {
132 0 : auto vdc = static_cast<GMPVideoDecoderChild*>(aActor);
133 :
134 0 : void* vd = nullptr;
135 0 : GMPErr err = mGMPChild->GetAPI(GMP_API_VIDEO_DECODER, &vdc->Host(), &vd, aDecryptorId);
136 0 : if (err != GMPNoErr || !vd) {
137 0 : NS_WARNING("GMPGetAPI call failed trying to construct decoder.");
138 0 : return IPC_FAIL_NO_REASON(this);
139 : }
140 :
141 0 : vdc->Init(static_cast<GMPVideoDecoder*>(vd));
142 :
143 0 : return IPC_OK();
144 : }
145 :
146 : mozilla::ipc::IPCResult
147 0 : GMPContentChild::RecvPGMPVideoEncoderConstructor(PGMPVideoEncoderChild* aActor)
148 : {
149 0 : auto vec = static_cast<GMPVideoEncoderChild*>(aActor);
150 :
151 0 : void* ve = nullptr;
152 0 : GMPErr err = mGMPChild->GetAPI(GMP_API_VIDEO_ENCODER, &vec->Host(), &ve);
153 0 : if (err != GMPNoErr || !ve) {
154 0 : NS_WARNING("GMPGetAPI call failed trying to construct encoder.");
155 0 : return IPC_FAIL_NO_REASON(this);
156 : }
157 :
158 0 : vec->Init(static_cast<GMPVideoEncoder*>(ve));
159 :
160 0 : return IPC_OK();
161 : }
162 :
163 : mozilla::ipc::IPCResult
164 0 : GMPContentChild::RecvPChromiumCDMConstructor(PChromiumCDMChild* aActor)
165 : {
166 0 : ChromiumCDMChild* child = static_cast<ChromiumCDMChild*>(aActor);
167 0 : cdm::Host_8* host = child;
168 :
169 0 : void* cdm = nullptr;
170 0 : GMPErr err = mGMPChild->GetAPI(CHROMIUM_CDM_API, host, &cdm);
171 0 : if (err != GMPNoErr || !cdm) {
172 0 : NS_WARNING("GMPGetAPI call failed trying to get CDM.");
173 0 : return IPC_FAIL_NO_REASON(this);
174 : }
175 :
176 0 : child->Init(static_cast<cdm::ContentDecryptionModule_8*>(cdm));
177 :
178 0 : return IPC_OK();
179 : }
180 :
181 : void
182 0 : GMPContentChild::CloseActive()
183 : {
184 : // Invalidate and remove any remaining API objects.
185 : const ManagedContainer<PGMPDecryptorChild>& decryptors =
186 0 : ManagedPGMPDecryptorChild();
187 0 : for (auto iter = decryptors.ConstIter(); !iter.Done(); iter.Next()) {
188 0 : iter.Get()->GetKey()->SendShutdown();
189 : }
190 :
191 : const ManagedContainer<PGMPVideoDecoderChild>& videoDecoders =
192 0 : ManagedPGMPVideoDecoderChild();
193 0 : for (auto iter = videoDecoders.ConstIter(); !iter.Done(); iter.Next()) {
194 0 : iter.Get()->GetKey()->SendShutdown();
195 : }
196 :
197 : const ManagedContainer<PGMPVideoEncoderChild>& videoEncoders =
198 0 : ManagedPGMPVideoEncoderChild();
199 0 : for (auto iter = videoEncoders.ConstIter(); !iter.Done(); iter.Next()) {
200 0 : iter.Get()->GetKey()->SendShutdown();
201 : }
202 :
203 0 : const ManagedContainer<PChromiumCDMChild>& cdms = ManagedPChromiumCDMChild();
204 0 : for (auto iter = cdms.ConstIter(); !iter.Done(); iter.Next()) {
205 0 : iter.Get()->GetKey()->SendShutdown();
206 : }
207 0 : }
208 :
209 : bool
210 0 : GMPContentChild::IsUsed()
211 : {
212 0 : return !ManagedPGMPDecryptorChild().IsEmpty() ||
213 0 : !ManagedPGMPVideoDecoderChild().IsEmpty() ||
214 0 : !ManagedPGMPVideoEncoderChild().IsEmpty() ||
215 0 : !ManagedPChromiumCDMChild().IsEmpty();
216 : }
217 :
218 : } // namespace gmp
219 : } // namespace mozilla
|