Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: media/cdm/cdm_wrapper.h

Issue 1402413005: Rename cdm_adapter to ppapi_cdm_adapter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/cdm/DEPS ('k') | media/cdm/ppapi/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ 5 #ifndef MEDIA_CDM_CDM_WRAPPER_H_
6 #define MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ 6 #define MEDIA_CDM_CDM_WRAPPER_H_
7 7
8 #include <map>
9 #include <queue>
10 #include <string> 8 #include <string>
11 9
12 #include "base/basictypes.h" 10 #include "base/basictypes.h"
13 #include "media/cdm/api/content_decryption_module.h" 11 #include "media/cdm/api/content_decryption_module.h"
14 #include "media/cdm/ppapi/cdm_helpers.h" 12 #include "media/cdm/supported_cdm_versions.h"
15 #include "media/cdm/ppapi/supported_cdm_versions.h" 13
14 #if defined(PLUGIN_IMPLEMENTATION)
xhwang 2015/10/23 17:15:29 Thinking it again PLUGIN_IMPLEMENTATION seems too
jrummell 2015/10/23 23:41:36 Done.
16 #include "ppapi/cpp/logging.h" 15 #include "ppapi/cpp/logging.h"
16 #define PLATFORM_DCHECK PP_DCHECK
17 #else
18 #include "base/logging.h"
19 #define PLATFORM_DCHECK DCHECK
20 #endif
17 21
18 namespace media { 22 namespace media {
19 23
20 // CdmWrapper wraps different versions of ContentDecryptionModule interfaces and 24 // CdmWrapper wraps different versions of ContentDecryptionModule interfaces and
21 // exposes a common interface to the caller. 25 // exposes a common interface to the caller.
22 // 26 //
23 // The caller should call CdmWrapper::Create() to create a CDM instance. 27 // The caller should call CdmWrapper::Create() to create a CDM instance.
24 // CdmWrapper will first try to create a CDM instance that supports the latest 28 // CdmWrapper will first try to create a CDM instance that supports the latest
25 // CDM interface (ContentDecryptionModule). If such an instance cannot be 29 // CDM interface (ContentDecryptionModule). If such an instance cannot be
26 // created (e.g. an older CDM was loaded), CdmWrapper will try to create a CDM 30 // created (e.g. an older CDM was loaded), CdmWrapper will try to create a CDM
27 // that supports an older version of CDM interface (e.g. 31 // that supports an older version of CDM interface (e.g.
28 // ContentDecryptionModule_*). Internally CdmWrapper converts the CdmWrapper 32 // ContentDecryptionModule_*). Internally CdmWrapper converts the CdmWrapper
29 // calls to corresponding ContentDecryptionModule calls. 33 // calls to corresponding ContentDecryptionModule calls.
30 // 34 //
31 // Note that CdmWrapper interface always reflects the latest state of content
32 // decryption related PPAPI APIs (e.g. pp::ContentDecryptor_Private).
33 //
34 // Since this file is highly templated and default implementations are short 35 // Since this file is highly templated and default implementations are short
35 // (just a shim layer in most cases), everything is done in this header file. 36 // (just a shim layer in most cases), everything is done in this header file.
36 class CdmWrapper { 37 class CdmWrapper {
37 public: 38 public:
38 static CdmWrapper* Create(const char* key_system, 39 static CdmWrapper* Create(const char* key_system,
39 uint32_t key_system_size, 40 uint32_t key_system_size,
40 GetCdmHostFunc get_cdm_host_func, 41 GetCdmHostFunc get_cdm_host_func,
41 void* user_data); 42 void* user_data);
42 43
43 virtual ~CdmWrapper() {}; 44 virtual ~CdmWrapper(){};
44 45
45 virtual void Initialize(bool allow_distinctive_identifier, 46 virtual void Initialize(bool allow_distinctive_identifier,
46 bool allow_persistent_state) = 0; 47 bool allow_persistent_state) = 0;
47 virtual void SetServerCertificate(uint32_t promise_id, 48 virtual void SetServerCertificate(uint32_t promise_id,
48 const uint8_t* server_certificate_data, 49 const uint8_t* server_certificate_data,
49 uint32_t server_certificate_data_size) = 0; 50 uint32_t server_certificate_data_size) = 0;
50 virtual void CreateSessionAndGenerateRequest(uint32_t promise_id, 51 virtual void CreateSessionAndGenerateRequest(uint32_t promise_id,
51 cdm::SessionType session_type, 52 cdm::SessionType session_type,
52 cdm::InitDataType init_data_type, 53 cdm::InitDataType init_data_type,
53 const uint8_t* init_data, 54 const uint8_t* init_data,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // Template class that does the CdmWrapper -> CdmInterface conversion. Default 100 // Template class that does the CdmWrapper -> CdmInterface conversion. Default
100 // implementations are provided. Any methods that need special treatment should 101 // implementations are provided. Any methods that need special treatment should
101 // be specialized. 102 // be specialized.
102 template <class CdmInterface> 103 template <class CdmInterface>
103 class CdmWrapperImpl : public CdmWrapper { 104 class CdmWrapperImpl : public CdmWrapper {
104 public: 105 public:
105 static CdmWrapper* Create(const char* key_system, 106 static CdmWrapper* Create(const char* key_system,
106 uint32_t key_system_size, 107 uint32_t key_system_size,
107 GetCdmHostFunc get_cdm_host_func, 108 GetCdmHostFunc get_cdm_host_func,
108 void* user_data) { 109 void* user_data) {
109 void* cdm_instance = ::CreateCdmInstance( 110 void* cdm_instance =
110 CdmInterface::kVersion, key_system, key_system_size, get_cdm_host_func, 111 ::CreateCdmInstance(CdmInterface::kVersion, key_system, key_system_size,
111 user_data); 112 get_cdm_host_func, user_data);
112 if (!cdm_instance) 113 if (!cdm_instance)
113 return NULL; 114 return NULL;
114 115
115 return new CdmWrapperImpl<CdmInterface>( 116 return new CdmWrapperImpl<CdmInterface>(
116 static_cast<CdmInterface*>(cdm_instance)); 117 static_cast<CdmInterface*>(cdm_instance));
117 } 118 }
118 119
119 ~CdmWrapperImpl() override { 120 ~CdmWrapperImpl() override { cdm_->Destroy(); }
120 cdm_->Destroy();
121 }
122 121
123 void Initialize(bool allow_distinctive_identifier, 122 void Initialize(bool allow_distinctive_identifier,
124 bool allow_persistent_state) override { 123 bool allow_persistent_state) override {
125 cdm_->Initialize(allow_distinctive_identifier, allow_persistent_state); 124 cdm_->Initialize(allow_distinctive_identifier, allow_persistent_state);
126 } 125 }
127 126
128 void SetServerCertificate( 127 void SetServerCertificate(uint32_t promise_id,
129 uint32_t promise_id, 128 const uint8_t* server_certificate_data,
130 const uint8_t* server_certificate_data, 129 uint32_t server_certificate_data_size) override {
131 uint32_t server_certificate_data_size) override { 130 cdm_->SetServerCertificate(promise_id, server_certificate_data,
132 cdm_->SetServerCertificate( 131 server_certificate_data_size);
133 promise_id, server_certificate_data, server_certificate_data_size);
134 } 132 }
135 133
136 void CreateSessionAndGenerateRequest( 134 void CreateSessionAndGenerateRequest(uint32_t promise_id,
137 uint32_t promise_id, 135 cdm::SessionType session_type,
138 cdm::SessionType session_type, 136 cdm::InitDataType init_data_type,
139 cdm::InitDataType init_data_type, 137 const uint8_t* init_data,
140 const uint8_t* init_data, 138 uint32_t init_data_size) override {
141 uint32_t init_data_size) override {
142 cdm_->CreateSessionAndGenerateRequest( 139 cdm_->CreateSessionAndGenerateRequest(
143 promise_id, session_type, init_data_type, init_data, init_data_size); 140 promise_id, session_type, init_data_type, init_data, init_data_size);
144 } 141 }
145 142
146 void LoadSession(uint32_t promise_id, 143 void LoadSession(uint32_t promise_id,
147 cdm::SessionType session_type, 144 cdm::SessionType session_type,
148 const char* session_id, 145 const char* session_id,
149 uint32_t session_id_size) override { 146 uint32_t session_id_size) override {
150 cdm_->LoadSession(promise_id, session_type, session_id, session_id_size); 147 cdm_->LoadSession(promise_id, session_type, session_id, session_id_size);
151 } 148 }
152 149
153 void UpdateSession(uint32_t promise_id, 150 void UpdateSession(uint32_t promise_id,
154 const char* session_id, 151 const char* session_id,
155 uint32_t session_id_size, 152 uint32_t session_id_size,
156 const uint8_t* response, 153 const uint8_t* response,
157 uint32_t response_size) override { 154 uint32_t response_size) override {
158 cdm_->UpdateSession(promise_id, session_id, session_id_size, response, 155 cdm_->UpdateSession(promise_id, session_id, session_id_size, response,
159 response_size); 156 response_size);
160 } 157 }
161 158
162 void CloseSession(uint32_t promise_id, 159 void CloseSession(uint32_t promise_id,
163 const char* session_id, 160 const char* session_id,
164 uint32_t session_id_size) override { 161 uint32_t session_id_size) override {
165 cdm_->CloseSession(promise_id, session_id, session_id_size); 162 cdm_->CloseSession(promise_id, session_id, session_id_size);
166 } 163 }
167 164
168 void RemoveSession(uint32_t promise_id, 165 void RemoveSession(uint32_t promise_id,
169 const char* session_id, 166 const char* session_id,
170 uint32_t session_id_size) override { 167 uint32_t session_id_size) override {
171 cdm_->RemoveSession(promise_id, session_id, session_id_size); 168 cdm_->RemoveSession(promise_id, session_id, session_id_size);
172 } 169 }
173 170
174 void TimerExpired(void* context) override { 171 void TimerExpired(void* context) override { cdm_->TimerExpired(context); }
175 cdm_->TimerExpired(context);
176 }
177 172
178 cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, 173 cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer,
179 cdm::DecryptedBlock* decrypted_buffer) override { 174 cdm::DecryptedBlock* decrypted_buffer) override {
180 return cdm_->Decrypt(encrypted_buffer, decrypted_buffer); 175 return cdm_->Decrypt(encrypted_buffer, decrypted_buffer);
181 } 176 }
182 177
183 cdm::Status InitializeAudioDecoder( 178 cdm::Status InitializeAudioDecoder(
184 const cdm::AudioDecoderConfig& audio_decoder_config) override { 179 const cdm::AudioDecoderConfig& audio_decoder_config) override {
185 return cdm_->InitializeAudioDecoder(audio_decoder_config); 180 return cdm_->InitializeAudioDecoder(audio_decoder_config);
186 } 181 }
187 182
188 cdm::Status InitializeVideoDecoder( 183 cdm::Status InitializeVideoDecoder(
189 const cdm::VideoDecoderConfig& video_decoder_config) override { 184 const cdm::VideoDecoderConfig& video_decoder_config) override {
190 return cdm_->InitializeVideoDecoder(video_decoder_config); 185 return cdm_->InitializeVideoDecoder(video_decoder_config);
191 } 186 }
192 187
193 void DeinitializeDecoder(cdm::StreamType decoder_type) override { 188 void DeinitializeDecoder(cdm::StreamType decoder_type) override {
194 cdm_->DeinitializeDecoder(decoder_type); 189 cdm_->DeinitializeDecoder(decoder_type);
195 } 190 }
196 191
197 void ResetDecoder(cdm::StreamType decoder_type) override { 192 void ResetDecoder(cdm::StreamType decoder_type) override {
198 cdm_->ResetDecoder(decoder_type); 193 cdm_->ResetDecoder(decoder_type);
199 } 194 }
200 195
201 cdm::Status DecryptAndDecodeFrame( 196 cdm::Status DecryptAndDecodeFrame(const cdm::InputBuffer& encrypted_buffer,
202 const cdm::InputBuffer& encrypted_buffer, 197 cdm::VideoFrame* video_frame) override {
203 cdm::VideoFrame* video_frame) override {
204 return cdm_->DecryptAndDecodeFrame(encrypted_buffer, video_frame); 198 return cdm_->DecryptAndDecodeFrame(encrypted_buffer, video_frame);
205 } 199 }
206 200
207 cdm::Status DecryptAndDecodeSamples( 201 cdm::Status DecryptAndDecodeSamples(const cdm::InputBuffer& encrypted_buffer,
208 const cdm::InputBuffer& encrypted_buffer, 202 cdm::AudioFrames* audio_frames) override {
209 cdm::AudioFrames* audio_frames) override {
210 return cdm_->DecryptAndDecodeSamples(encrypted_buffer, audio_frames); 203 return cdm_->DecryptAndDecodeSamples(encrypted_buffer, audio_frames);
211 } 204 }
212 205
213 void OnPlatformChallengeResponse( 206 void OnPlatformChallengeResponse(
214 const cdm::PlatformChallengeResponse& response) override { 207 const cdm::PlatformChallengeResponse& response) override {
215 cdm_->OnPlatformChallengeResponse(response); 208 cdm_->OnPlatformChallengeResponse(response);
216 } 209 }
217 210
218 void OnQueryOutputProtectionStatus( 211 void OnQueryOutputProtectionStatus(cdm::QueryResult result,
219 cdm::QueryResult result, 212 uint32_t link_mask,
220 uint32_t link_mask, 213 uint32_t output_protection_mask) override {
221 uint32_t output_protection_mask) override {
222 cdm_->OnQueryOutputProtectionStatus(result, link_mask, 214 cdm_->OnQueryOutputProtectionStatus(result, link_mask,
223 output_protection_mask); 215 output_protection_mask);
224 } 216 }
225 217
226 private: 218 private:
227 CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm) { 219 CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm) { PLATFORM_DCHECK(cdm_); }
228 PP_DCHECK(cdm_);
229 }
230 220
231 CdmInterface* cdm_; 221 CdmInterface* cdm_;
232 222
233 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl); 223 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl);
234 }; 224 };
235 225
236 // Overrides for the cdm::Host_7 methods. 226 // Overrides for the cdm::Host_7 methods.
237 // TODO(jrummell): Remove these once Host_7 interface is removed. 227 // TODO(jrummell): Remove these once Host_7 interface is removed.
238 228
239 template <> 229 template <>
240 void CdmWrapperImpl<cdm::ContentDecryptionModule_7>::Initialize( 230 void CdmWrapperImpl<cdm::ContentDecryptionModule_7>::Initialize(
241 bool allow_distinctive_identifier, 231 bool allow_distinctive_identifier,
242 bool allow_persistent_state) { 232 bool allow_persistent_state) {}
243 }
244 233
245 template <> 234 template <>
246 void CdmWrapperImpl<cdm::ContentDecryptionModule_7>:: 235 void CdmWrapperImpl<cdm::ContentDecryptionModule_7>::
247 CreateSessionAndGenerateRequest(uint32_t promise_id, 236 CreateSessionAndGenerateRequest(uint32_t promise_id,
248 cdm::SessionType session_type, 237 cdm::SessionType session_type,
249 cdm::InitDataType init_data_type, 238 cdm::InitDataType init_data_type,
250 const uint8_t* init_data, 239 const uint8_t* init_data,
251 uint32_t init_data_size) { 240 uint32_t init_data_size) {
252 std::string init_data_type_as_string = "unknown"; 241 std::string init_data_type_as_string = "unknown";
253 switch (init_data_type) { 242 switch (init_data_type) {
(...skipping 18 matching lines...) Expand all
272 GetCdmHostFunc get_cdm_host_func, 261 GetCdmHostFunc get_cdm_host_func,
273 void* user_data) { 262 void* user_data) {
274 static_assert(cdm::ContentDecryptionModule::kVersion == 263 static_assert(cdm::ContentDecryptionModule::kVersion ==
275 cdm::ContentDecryptionModule_8::kVersion, 264 cdm::ContentDecryptionModule_8::kVersion,
276 "update the code below"); 265 "update the code below");
277 266
278 // Ensure IsSupportedCdmInterfaceVersion() matches this implementation. 267 // Ensure IsSupportedCdmInterfaceVersion() matches this implementation.
279 // Always update this DCHECK when updating this function. 268 // Always update this DCHECK when updating this function.
280 // If this check fails, update this function and DCHECK or update 269 // If this check fails, update this function and DCHECK or update
281 // IsSupportedCdmInterfaceVersion(). 270 // IsSupportedCdmInterfaceVersion().
282 PP_DCHECK(!IsSupportedCdmInterfaceVersion( 271 PLATFORM_DCHECK(!IsSupportedCdmInterfaceVersion(
283 cdm::ContentDecryptionModule_8::kVersion + 1) && 272 cdm::ContentDecryptionModule_8::kVersion + 1) &&
284 IsSupportedCdmInterfaceVersion( 273 IsSupportedCdmInterfaceVersion(
285 cdm::ContentDecryptionModule_8::kVersion) && 274 cdm::ContentDecryptionModule_8::kVersion) &&
286 IsSupportedCdmInterfaceVersion( 275 IsSupportedCdmInterfaceVersion(
287 cdm::ContentDecryptionModule_7::kVersion) && 276 cdm::ContentDecryptionModule_7::kVersion) &&
288 !IsSupportedCdmInterfaceVersion( 277 !IsSupportedCdmInterfaceVersion(
289 cdm::ContentDecryptionModule_7::kVersion - 1)); 278 cdm::ContentDecryptionModule_7::kVersion - 1));
290 279
291 // Try to create the CDM using the latest CDM interface version. 280 // Try to create the CDM using the latest CDM interface version.
292 CdmWrapper* cdm_wrapper = 281 CdmWrapper* cdm_wrapper =
293 CdmWrapperImpl<cdm::ContentDecryptionModule>::Create( 282 CdmWrapperImpl<cdm::ContentDecryptionModule>::Create(
294 key_system, key_system_size, get_cdm_host_func, user_data); 283 key_system, key_system_size, get_cdm_host_func, user_data);
295 284
296 // If |cdm_wrapper| is NULL, try to create the CDM using older supported 285 // If |cdm_wrapper| is NULL, try to create the CDM using older supported
297 // versions of the CDM interface here. 286 // versions of the CDM interface here.
298 if (!cdm_wrapper) { 287 if (!cdm_wrapper) {
299 cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_7>::Create( 288 cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_7>::Create(
300 key_system, key_system_size, get_cdm_host_func, user_data); 289 key_system, key_system_size, get_cdm_host_func, user_data);
301 } 290 }
302 291
303 return cdm_wrapper; 292 return cdm_wrapper;
304 } 293 }
305 294
306 // When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain 295 // When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain
307 // stub implementations for new or modified methods that the older CDM interface 296 // stub implementations for new or modified methods that the older CDM interface
308 // does not have. 297 // does not have.
309 // Also update supported_cdm_versions.h. 298 // Also update supported_cdm_versions.h.
310 static_assert(cdm::ContentDecryptionModule::kVersion == 299 static_assert(cdm::ContentDecryptionModule::kVersion ==
311 cdm::ContentDecryptionModule_8::kVersion, 300 cdm::ContentDecryptionModule_8::kVersion,
312 "ensure cdm wrapper templates have old version support"); 301 "ensure cdm wrapper templates have old version support");
313 302
314 } // namespace media 303 } // namespace media
315 304
316 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ 305 #endif // MEDIA_CDM_CDM_WRAPPER_H_
OLDNEW
« no previous file with comments | « media/cdm/DEPS ('k') | media/cdm/ppapi/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698