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

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

Issue 446693004: Add support for CDM_6. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
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_PPAPI_CDM_WRAPPER_H_
6 #define MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ 6 #define MEDIA_CDM_PPAPI_CDM_WRAPPER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 uint32_t init_data_size, 49 uint32_t init_data_size,
50 cdm::SessionType session_type) = 0; 50 cdm::SessionType session_type) = 0;
51 virtual void LoadSession(uint32_t promise_id, 51 virtual void LoadSession(uint32_t promise_id,
52 const char* web_session_id, 52 const char* web_session_id,
53 uint32_t web_session_id_size) = 0; 53 uint32_t web_session_id_size) = 0;
54 virtual void UpdateSession(uint32_t promise_id, 54 virtual void UpdateSession(uint32_t promise_id,
55 const char* web_session_id, 55 const char* web_session_id,
56 uint32_t web_session_id_size, 56 uint32_t web_session_id_size,
57 const uint8_t* response, 57 const uint8_t* response,
58 uint32_t response_size) = 0; 58 uint32_t response_size) = 0;
59 virtual void ReleaseSession(uint32_t promise_id, 59 virtual bool GetUsableKeyIds(uint32_t promise_id,
ddorwin 2014/08/07 01:34:44 nit: After RemoveSession to match CDM_6 (and keeps
jrummell 2014/08/07 20:44:31 Done.
60 const char* web_session_id, 60 const char* web_session_id,
61 uint32_t web_session_id_size) = 0; 61 uint32_t web_session_id_size) = 0;
62 virtual void CloseSession(uint32_t promise_id,
63 const char* web_session_id,
64 uint32_t web_session_id_size) = 0;
65 virtual bool RemoveSession(uint32_t promise_id,
66 const char* web_session_id,
67 uint32_t web_session_id_size) = 0;
62 virtual void TimerExpired(void* context) = 0; 68 virtual void TimerExpired(void* context) = 0;
63 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, 69 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer,
64 cdm::DecryptedBlock* decrypted_buffer) = 0; 70 cdm::DecryptedBlock* decrypted_buffer) = 0;
65 virtual cdm::Status InitializeAudioDecoder( 71 virtual cdm::Status InitializeAudioDecoder(
66 const cdm::AudioDecoderConfig& audio_decoder_config) = 0; 72 const cdm::AudioDecoderConfig& audio_decoder_config) = 0;
67 virtual cdm::Status InitializeVideoDecoder( 73 virtual cdm::Status InitializeVideoDecoder(
68 const cdm::VideoDecoderConfig& video_decoder_config) = 0; 74 const cdm::VideoDecoderConfig& video_decoder_config) = 0;
69 virtual void DeinitializeDecoder(cdm::StreamType decoder_type) = 0; 75 virtual void DeinitializeDecoder(cdm::StreamType decoder_type) = 0;
70 virtual void ResetDecoder(cdm::StreamType decoder_type) = 0; 76 virtual void ResetDecoder(cdm::StreamType decoder_type) = 0;
71 virtual cdm::Status DecryptAndDecodeFrame( 77 virtual cdm::Status DecryptAndDecodeFrame(
(...skipping 16 matching lines...) Expand all
88 // Since the callbacks don't come through this interface, cdm_adapter needs to 94 // Since the callbacks don't come through this interface, cdm_adapter needs to
89 // create the mapping (and delete it on release). 95 // create the mapping (and delete it on release).
90 // TODO(jrummell): Remove these once Host_4 interface is removed. 96 // TODO(jrummell): Remove these once Host_4 interface is removed.
91 virtual uint32_t LookupPromiseId(uint32_t session_id) = 0; 97 virtual uint32_t LookupPromiseId(uint32_t session_id) = 0;
92 virtual void AssignWebSessionId(uint32_t session_id, 98 virtual void AssignWebSessionId(uint32_t session_id,
93 const char* web_session_id, 99 const char* web_session_id,
94 uint32_t web_session_id_size) = 0; 100 uint32_t web_session_id_size) = 0;
95 virtual std::string LookupWebSessionId(uint32_t session_id) = 0; 101 virtual std::string LookupWebSessionId(uint32_t session_id) = 0;
96 virtual void DropWebSessionId(std::string web_session_id) = 0; 102 virtual void DropWebSessionId(std::string web_session_id) = 0;
97 103
104 // Helper functions for the cdm::Host_4 and cdm::Host_5 methods.
105 // In cdm::Host_6, resolving LoadSession() and UpdateSession() calls will
ddorwin 2014/08/07 01:34:44 Isn't this more like the following? CDMs using Hos
jrummell 2014/08/07 20:44:30 Done.
106 // also generate an OnSessionUsableKeys() event. This needs to be simulated
107 // for the older calls.
108 virtual bool SessionUsableKeysEventNeeded(uint32_t promise_id,
ddorwin 2014/08/07 01:34:44 // These must not be called for Host_6 and later.
jrummell 2014/08/07 20:44:30 Done.
109 std::string* web_session_id) = 0;
110 virtual void SetSessionUsableKeysEventNeeded(
111 uint32_t promise_id,
112 const char* web_session_id,
113 uint32_t web_session_id_size) = 0;
114
98 protected: 115 protected:
99 CdmWrapper() {} 116 CdmWrapper() {}
100 117
101 private: 118 private:
102 DISALLOW_COPY_AND_ASSIGN(CdmWrapper); 119 DISALLOW_COPY_AND_ASSIGN(CdmWrapper);
103 }; 120 };
104 121
105 // Template class that does the CdmWrapper -> CdmInterface conversion. Default 122 // Template class that does the CdmWrapper -> CdmInterface conversion. Default
106 // implementations are provided. Any methods that need special treatment should 123 // implementations are provided. Any methods that need special treatment should
107 // be specialized. 124 // be specialized.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 uint32_t web_session_id_size, 168 uint32_t web_session_id_size,
152 const uint8_t* response, 169 const uint8_t* response,
153 uint32_t response_size) OVERRIDE { 170 uint32_t response_size) OVERRIDE {
154 cdm_->UpdateSession(promise_id, 171 cdm_->UpdateSession(promise_id,
155 web_session_id, 172 web_session_id,
156 web_session_id_size, 173 web_session_id_size,
157 response, 174 response,
158 response_size); 175 response_size);
159 } 176 }
160 177
161 virtual void ReleaseSession(uint32_t promise_id, 178 virtual bool GetUsableKeyIds(uint32_t promise_id,
162 const char* web_session_id, 179 const char* web_session_id,
163 uint32_t web_session_id_size) OVERRIDE { 180 uint32_t web_session_id_size) OVERRIDE {
164 cdm_->ReleaseSession(promise_id, web_session_id, web_session_id_size); 181 cdm_->GetUsableKeyIds(promise_id, web_session_id, web_session_id_size);
182 return true;
183 }
184
185 virtual void CloseSession(uint32_t promise_id,
186 const char* web_session_id,
187 uint32_t web_session_id_size) OVERRIDE {
188 cdm_->CloseSession(promise_id, web_session_id, web_session_id_size);
189 }
190
191 virtual bool RemoveSession(uint32_t promise_id,
192 const char* web_session_id,
193 uint32_t web_session_id_size) OVERRIDE {
194 cdm_->RemoveSession(promise_id, web_session_id, web_session_id_size);
195 return true;
165 } 196 }
166 197
167 virtual void TimerExpired(void* context) OVERRIDE { 198 virtual void TimerExpired(void* context) OVERRIDE {
168 cdm_->TimerExpired(context); 199 cdm_->TimerExpired(context);
169 } 200 }
170 201
171 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, 202 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer,
172 cdm::DecryptedBlock* decrypted_buffer) OVERRIDE { 203 cdm::DecryptedBlock* decrypted_buffer) OVERRIDE {
173 return cdm_->Decrypt(encrypted_buffer, decrypted_buffer); 204 return cdm_->Decrypt(encrypted_buffer, decrypted_buffer);
174 } 205 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 return it->first; 285 return it->first;
255 } 286 }
256 PP_NOTREACHED(); 287 PP_NOTREACHED();
257 return std::string(); 288 return std::string();
258 } 289 }
259 290
260 virtual void DropWebSessionId(std::string web_session_id) { 291 virtual void DropWebSessionId(std::string web_session_id) {
261 web_session_to_session_id_map_.erase(web_session_id); 292 web_session_to_session_id_map_.erase(web_session_id);
262 } 293 }
263 294
295 virtual bool SessionUsableKeysEventNeeded(uint32_t promise_id,
296 std::string* web_session_id) {
297 std::map<uint32_t, std::string>::iterator it =
298 session_usable_keys_event_needed_.find(promise_id);
299 if (it == session_usable_keys_event_needed_.end())
300 return false;
301 web_session_id->swap(it->second);
302 session_usable_keys_event_needed_.erase(it);
303 return true;
304 }
305
306 virtual void SetSessionUsableKeysEventNeeded(uint32_t promise_id,
307 const char* web_session_id,
308 uint32_t web_session_id_size) {
309 session_usable_keys_event_needed_.insert(std::make_pair(
310 promise_id, std::string(web_session_id, web_session_id_size)));
311 }
312
264 private: 313 private:
265 CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm), next_session_id_(100) { 314 CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm), next_session_id_(100) {
266 PP_DCHECK(cdm_); 315 PP_DCHECK(cdm_);
267 } 316 }
268 317
269 CdmInterface* cdm_; 318 CdmInterface* cdm_;
270 319
271 std::map<uint32_t, uint32_t> promise_to_session_id_map_; 320 std::map<uint32_t, uint32_t> promise_to_session_id_map_;
272 uint32_t next_session_id_; 321 uint32_t next_session_id_;
273 std::map<std::string, uint32_t> web_session_to_session_id_map_; 322 std::map<std::string, uint32_t> web_session_to_session_id_map_;
274 323
324 std::map<uint32_t, std::string> session_usable_keys_event_needed_;
ddorwin 2014/08/07 01:34:44 promises_needing_usable_....?
jrummell 2014/08/07 20:44:30 Done.
325
275 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl); 326 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl);
276 }; 327 };
277 328
329 // Overrides for the cdm::Host_5 methods.
ddorwin 2014/08/07 01:34:44 Why does 5 come before 4?
jrummell 2014/08/07 20:44:30 Done.
330 // TODO(jrummell): Remove these once Host_5 interface is removed.
331
332 template <>
333 void CdmWrapperImpl<cdm::ContentDecryptionModule_5>::LoadSession(
334 uint32_t promise_id,
335 const char* web_session_id,
336 uint32_t web_session_id_size) {
337 SetSessionUsableKeysEventNeeded(
338 promise_id, web_session_id, web_session_id_size);
339 cdm_->LoadSession(promise_id, web_session_id, web_session_id_size);
340 }
341
342 template <>
343 void CdmWrapperImpl<cdm::ContentDecryptionModule_5>::UpdateSession(
344 uint32_t promise_id,
345 const char* web_session_id,
346 uint32_t web_session_id_size,
347 const uint8_t* response,
348 uint32_t response_size) {
349 SetSessionUsableKeysEventNeeded(
ddorwin 2014/08/07 01:34:44 This may be overly aggressive in firing events, bu
jrummell 2014/08/07 20:44:30 Acknowledged.
350 promise_id, web_session_id, web_session_id_size);
351 cdm_->UpdateSession(
352 promise_id, web_session_id, web_session_id_size, response, response_size);
353 }
354
355 template <>
356 bool CdmWrapperImpl<cdm::ContentDecryptionModule_5>::GetUsableKeyIds(
ddorwin 2014/08/07 01:34:44 nit: ditto on order
jrummell 2014/08/07 20:44:30 Done.
357 uint32_t promise_id,
358 const char* web_session_id,
359 uint32_t web_session_id_size) {
360 return false;
361 }
362
363 template <>
364 void CdmWrapperImpl<cdm::ContentDecryptionModule_5>::CloseSession(
365 uint32_t promise_id,
366 const char* web_session_id,
367 uint32_t web_session_id_size) {
368 cdm_->ReleaseSession(promise_id, web_session_id, web_session_id_size);
369 }
370
371 template <>
372 bool CdmWrapperImpl<cdm::ContentDecryptionModule_5>::RemoveSession(
373 uint32_t promise_id,
374 const char* web_session_id,
375 uint32_t web_session_id_size) {
376 return false;
377 }
378
278 // Overrides for the cdm::Host_4 methods. Calls to CreateSession(), 379 // Overrides for the cdm::Host_4 methods. Calls to CreateSession(),
279 // LoadSession(), UpdateSession(), and ReleaseSession() pass in promise ids, 380 // LoadSession(), UpdateSession(), and ReleaseSession() pass in promise ids,
280 // but the CDM interface needs session ids. For create and load, we need to 381 // but the CDM interface needs session ids. For create and load, we need to
281 // create a new session_id to pass to the CDM. For update and release, we need 382 // create a new session_id to pass to the CDM. For update and release, we need
282 // to look up |web_session_id| and convert it into the existing |session_id|. 383 // to look up |web_session_id| and convert it into the existing |session_id|.
283 // Since the callbacks don't come through this interface, cdm_adapter needs to 384 // Since the callbacks don't come through this interface, cdm_adapter needs to
284 // create the mapping (and delete it on release). 385 // create the mapping (and delete it on release).
285 // TODO(jrummell): Remove these once Host_4 interface is removed. 386 // TODO(jrummell): Remove these once Host_4 interface is removed.
286 387
287 template <> 388 template <>
(...skipping 13 matching lines...) Expand all
301 init_data_size); 402 init_data_size);
302 } 403 }
303 404
304 template <> 405 template <>
305 void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::LoadSession( 406 void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::LoadSession(
306 uint32_t promise_id, 407 uint32_t promise_id,
307 const char* web_session_id, 408 const char* web_session_id,
308 uint32_t web_session_id_size) { 409 uint32_t web_session_id_size) {
309 uint32_t session_id = CreateSessionId(); 410 uint32_t session_id = CreateSessionId();
310 RegisterPromise(session_id, promise_id); 411 RegisterPromise(session_id, promise_id);
412 SetSessionUsableKeysEventNeeded(
ddorwin 2014/08/07 01:34:44 ditto here and below.
jrummell 2014/08/07 20:44:30 Acknowledged.
413 promise_id, web_session_id, web_session_id_size);
311 cdm_->LoadSession(session_id, web_session_id, web_session_id_size); 414 cdm_->LoadSession(session_id, web_session_id, web_session_id_size);
312 } 415 }
313 416
314 template <> 417 template <>
315 void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::UpdateSession( 418 void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::UpdateSession(
316 uint32_t promise_id, 419 uint32_t promise_id,
317 const char* web_session_id, 420 const char* web_session_id,
318 uint32_t web_session_id_size, 421 uint32_t web_session_id_size,
319 const uint8_t* response, 422 const uint8_t* response,
320 uint32_t response_size) { 423 uint32_t response_size) {
321 std::string web_session_str(web_session_id, web_session_id_size); 424 std::string web_session_str(web_session_id, web_session_id_size);
322 uint32_t session_id = LookupSessionId(web_session_str); 425 uint32_t session_id = LookupSessionId(web_session_str);
323 RegisterPromise(session_id, promise_id); 426 RegisterPromise(session_id, promise_id);
427 SetSessionUsableKeysEventNeeded(
428 promise_id, web_session_id, web_session_id_size);
324 cdm_->UpdateSession(session_id, response, response_size); 429 cdm_->UpdateSession(session_id, response, response_size);
325 } 430 }
326 431
327 template <> 432 template <>
328 void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::ReleaseSession( 433 bool CdmWrapperImpl<cdm::ContentDecryptionModule_4>::GetUsableKeyIds(
ddorwin 2014/08/07 01:34:44 nit: ditto on order
jrummell 2014/08/07 20:44:30 Done.
329 uint32_t promise_id, 434 uint32_t promise_id,
330 const char* web_session_id, 435 const char* web_session_id,
331 uint32_t web_session_id_size) { 436 uint32_t web_session_id_size) {
437 return false;
438 }
439
440 template <>
441 void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::CloseSession(
442 uint32_t promise_id,
443 const char* web_session_id,
444 uint32_t web_session_id_size) {
332 std::string web_session_str(web_session_id, web_session_id_size); 445 std::string web_session_str(web_session_id, web_session_id_size);
333 uint32_t session_id = LookupSessionId(web_session_str); 446 uint32_t session_id = LookupSessionId(web_session_str);
334 RegisterPromise(session_id, promise_id); 447 RegisterPromise(session_id, promise_id);
335 cdm_->ReleaseSession(session_id); 448 cdm_->ReleaseSession(session_id);
336 } 449 }
337 450
451 template <>
452 bool CdmWrapperImpl<cdm::ContentDecryptionModule_4>::RemoveSession(
453 uint32_t promise_id,
454 const char* web_session_id,
455 uint32_t web_session_id_size) {
456 return false;
457 }
458
338 CdmWrapper* CdmWrapper::Create(const char* key_system, 459 CdmWrapper* CdmWrapper::Create(const char* key_system,
339 uint32_t key_system_size, 460 uint32_t key_system_size,
340 GetCdmHostFunc get_cdm_host_func, 461 GetCdmHostFunc get_cdm_host_func,
341 void* user_data) { 462 void* user_data) {
342 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion == 463 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion ==
343 cdm::ContentDecryptionModule_5::kVersion, 464 cdm::ContentDecryptionModule_6::kVersion,
344 update_code_below); 465 update_code_below);
345 466
346 // Ensure IsSupportedCdmInterfaceVersion() matches this implementation. 467 // Ensure IsSupportedCdmInterfaceVersion() matches this implementation.
347 // Always update this DCHECK when updating this function. 468 // Always update this DCHECK when updating this function.
348 // If this check fails, update this function and DCHECK or update 469 // If this check fails, update this function and DCHECK or update
349 // IsSupportedCdmInterfaceVersion(). 470 // IsSupportedCdmInterfaceVersion().
350 PP_DCHECK( 471 PP_DCHECK(
351 !IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule::kVersion + 472 !IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule::kVersion +
352 1) && 473 1) &&
353 IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule::kVersion) && 474 IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule::kVersion) &&
354 IsSupportedCdmInterfaceVersion( 475 IsSupportedCdmInterfaceVersion(
355 cdm::ContentDecryptionModule_4::kVersion) && 476 cdm::ContentDecryptionModule_4::kVersion) &&
356 !IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule_4::kVersion - 477 !IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule_4::kVersion -
357 1)); 478 1));
358 479
359 // Try to create the CDM using the latest CDM interface version. 480 // Try to create the CDM using the latest CDM interface version.
360 CdmWrapper* cdm_wrapper = 481 CdmWrapper* cdm_wrapper =
361 CdmWrapperImpl<cdm::ContentDecryptionModule>::Create( 482 CdmWrapperImpl<cdm::ContentDecryptionModule>::Create(
362 key_system, key_system_size, get_cdm_host_func, user_data); 483 key_system, key_system_size, get_cdm_host_func, user_data);
363 if (cdm_wrapper) 484 if (cdm_wrapper)
364 return cdm_wrapper; 485 return cdm_wrapper;
365 486
366 // If |cdm_wrapper| is NULL, try to create the CDM using older supported 487 // If |cdm_wrapper| is NULL, try to create the CDM using older supported
367 // versions of the CDM interface. 488 // versions of the CDM interface.
489 cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_5>::Create(
490 key_system, key_system_size, get_cdm_host_func, user_data);
491 if (cdm_wrapper)
492 return cdm_wrapper;
493
368 cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_4>::Create( 494 cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_4>::Create(
369 key_system, key_system_size, get_cdm_host_func, user_data); 495 key_system, key_system_size, get_cdm_host_func, user_data);
370 return cdm_wrapper; 496 return cdm_wrapper;
371 } 497 }
372 498
373 // When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain 499 // When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain
374 // stub implementations for new or modified methods that the older CDM interface 500 // stub implementations for new or modified methods that the older CDM interface
375 // does not have. 501 // does not have.
376 // Also update supported_cdm_versions.h. 502 // Also update supported_cdm_versions.h.
377 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion == 503 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion ==
378 cdm::ContentDecryptionModule_5::kVersion, 504 cdm::ContentDecryptionModule_6::kVersion,
379 ensure_cdm_wrapper_templates_have_old_version_support); 505 ensure_cdm_wrapper_templates_have_old_version_support);
380 506
381 } // namespace media 507 } // namespace media
382 508
383 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ 509 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698