Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 const char* web_session_id, | 120 const char* web_session_id, |
| 121 uint32_t web_session_id_size) = 0; | 121 uint32_t web_session_id_size) = 0; |
| 122 | 122 |
| 123 // cdm::Host_6 introduces InputBuffer_2 (aka InputBuffer). cdm::Host_4 and | 123 // cdm::Host_6 introduces InputBuffer_2 (aka InputBuffer). cdm::Host_4 and |
| 124 // cdm::Host_5 methods still use InputBuffer_1, so this helper function | 124 // cdm::Host_5 methods still use InputBuffer_1, so this helper function |
| 125 // converts InputBuffer_2 to InputBuffer_1. | 125 // converts InputBuffer_2 to InputBuffer_1. |
| 126 // TODO(jrummell): Remove these once Host_4 and Host_5 interfaces are removed. | 126 // TODO(jrummell): Remove these once Host_4 and Host_5 interfaces are removed. |
| 127 virtual void ConvertInputBuffer(const cdm::InputBuffer& v2, | 127 virtual void ConvertInputBuffer(const cdm::InputBuffer& v2, |
| 128 cdm::InputBuffer_1* v1) = 0; | 128 cdm::InputBuffer_1* v1) = 0; |
| 129 | 129 |
| 130 // Starting in cdm::Host_6 |init_data_type| is a registered type instead of a | |
|
ddorwin
2014/08/13 20:59:55
"Prior to CDM_6, |init_data_type| was a mime type.
sandersd (OOO until July 31)
2014/08/13 21:36:19
Done.
| |
| 131 // content type. This helper convererts an |init_data_type| to a content type. | |
| 132 // TODO(sandersd): Remove once Host_4 and Host_5 interfaces are removed. | |
| 133 virtual const char* ConvertInitDataTypeToContentType( | |
| 134 const char* init_data_type) const = 0; | |
| 135 | |
| 130 protected: | 136 protected: |
| 131 CdmWrapper() {} | 137 CdmWrapper() {} |
| 132 | 138 |
| 133 private: | 139 private: |
| 134 DISALLOW_COPY_AND_ASSIGN(CdmWrapper); | 140 DISALLOW_COPY_AND_ASSIGN(CdmWrapper); |
| 135 }; | 141 }; |
| 136 | 142 |
| 137 // Template class that does the CdmWrapper -> CdmInterface conversion. Default | 143 // Template class that does the CdmWrapper -> CdmInterface conversion. Default |
| 138 // implementations are provided. Any methods that need special treatment should | 144 // implementations are provided. Any methods that need special treatment should |
| 139 // be specialized. | 145 // be specialized. |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 v1->data_offset = 0; | 338 v1->data_offset = 0; |
| 333 v1->key_id = v2.key_id; | 339 v1->key_id = v2.key_id; |
| 334 v1->key_id_size = v2.key_id_size; | 340 v1->key_id_size = v2.key_id_size; |
| 335 v1->iv = v2.iv; | 341 v1->iv = v2.iv; |
| 336 v1->iv_size = v2.iv_size; | 342 v1->iv_size = v2.iv_size; |
| 337 v1->subsamples = v2.subsamples; | 343 v1->subsamples = v2.subsamples; |
| 338 v1->num_subsamples = v2.num_subsamples; | 344 v1->num_subsamples = v2.num_subsamples; |
| 339 v1->timestamp = v2.timestamp; | 345 v1->timestamp = v2.timestamp; |
| 340 } | 346 } |
| 341 | 347 |
| 348 virtual const char* ConvertInitDataTypeToContentType( | |
| 349 const char* init_data_type) const { | |
| 350 if (!strcmp(init_data_type, "cenc")) | |
| 351 return "video/mp4"; | |
| 352 if (!strcmp(init_data_type, "webm")) | |
| 353 return "video/webm"; | |
| 354 return init_data_type; | |
| 355 } | |
| 356 | |
| 342 private: | 357 private: |
| 343 CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm), next_session_id_(100) { | 358 CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm), next_session_id_(100) { |
| 344 PP_DCHECK(cdm_); | 359 PP_DCHECK(cdm_); |
| 345 } | 360 } |
| 346 | 361 |
| 347 CdmInterface* cdm_; | 362 CdmInterface* cdm_; |
| 348 | 363 |
| 349 std::map<uint32_t, uint32_t> promise_to_session_id_map_; | 364 std::map<uint32_t, uint32_t> promise_to_session_id_map_; |
| 350 uint32_t next_session_id_; | 365 uint32_t next_session_id_; |
| 351 std::map<std::string, uint32_t> web_session_to_session_id_map_; | 366 std::map<std::string, uint32_t> web_session_to_session_id_map_; |
| 352 | 367 |
| 353 std::map<uint32_t, std::string> promises_needing_usable_keys_event_; | 368 std::map<uint32_t, std::string> promises_needing_usable_keys_event_; |
| 354 | 369 |
| 355 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl); | 370 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl); |
| 356 }; | 371 }; |
| 357 | 372 |
| 358 // Overrides for the cdm::Host_4 methods. Calls to CreateSession(), | 373 // Overrides for the cdm::Host_4 methods. Calls to CreateSession(), |
| 359 // LoadSession(), UpdateSession(), and ReleaseSession() pass in promise ids, | 374 // LoadSession(), UpdateSession(), and ReleaseSession() pass in promise ids, |
| 360 // but the CDM interface needs session ids. For create and load, we need to | 375 // but the CDM interface needs session ids. For create and load, we need to |
| 361 // create a new session_id to pass to the CDM. For update and release, we need | 376 // create a new session_id to pass to the CDM. For update and release, we need |
| 362 // to look up |web_session_id| and convert it into the existing |session_id|. | 377 // to look up |web_session_id| and convert it into the existing |session_id|. |
| 363 // Since the callbacks don't come through this interface, cdm_adapter needs to | 378 // Since the callbacks don't come through this interface, cdm_adapter needs to |
| 364 // create the mapping (and delete it on release). | 379 // create the mapping (and delete it on release). Finally, for create, we need |
| 380 // to translate |init_data_type| to a MIME type. | |
| 365 // TODO(jrummell): Remove these once Host_4 interface is removed. | 381 // TODO(jrummell): Remove these once Host_4 interface is removed. |
| 366 | 382 |
| 367 template <> | 383 template <> |
| 368 void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::CreateSession( | 384 void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::CreateSession( |
| 369 uint32_t promise_id, | 385 uint32_t promise_id, |
| 370 const char* init_data_type, | 386 const char* init_data_type, |
| 371 uint32_t init_data_type_size, | 387 uint32_t init_data_type_size, |
| 372 const uint8_t* init_data, | 388 const uint8_t* init_data, |
| 373 uint32_t init_data_size, | 389 uint32_t init_data_size, |
| 374 cdm::SessionType session_type) { | 390 cdm::SessionType session_type) { |
| 375 uint32_t session_id = CreateSessionId(); | 391 uint32_t session_id = CreateSessionId(); |
| 376 RegisterPromise(session_id, promise_id); | 392 RegisterPromise(session_id, promise_id); |
| 377 cdm_->CreateSession(session_id, | 393 cdm_->CreateSession(session_id, |
| 378 init_data_type, | 394 ConvertInitDataTypeToContentType(init_data_type), |
| 379 init_data_type_size, | 395 init_data_type_size, |
| 380 init_data, | 396 init_data, |
| 381 init_data_size); | 397 init_data_size); |
| 382 } | 398 } |
| 383 | 399 |
| 384 template <> | 400 template <> |
| 385 void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::LoadSession( | 401 void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::LoadSession( |
| 386 uint32_t promise_id, | 402 uint32_t promise_id, |
| 387 const char* web_session_id, | 403 const char* web_session_id, |
| 388 uint32_t web_session_id_size) { | 404 uint32_t web_session_id_size) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 cdm::AudioFrames* audio_frames) { | 481 cdm::AudioFrames* audio_frames) { |
| 466 cdm::InputBuffer_1 buffer; | 482 cdm::InputBuffer_1 buffer; |
| 467 ConvertInputBuffer(encrypted_buffer, &buffer); | 483 ConvertInputBuffer(encrypted_buffer, &buffer); |
| 468 return cdm_->DecryptAndDecodeSamples(buffer, audio_frames); | 484 return cdm_->DecryptAndDecodeSamples(buffer, audio_frames); |
| 469 } | 485 } |
| 470 | 486 |
| 471 // Overrides for the cdm::Host_5 methods. | 487 // Overrides for the cdm::Host_5 methods. |
| 472 // TODO(jrummell): Remove these once Host_5 interface is removed. | 488 // TODO(jrummell): Remove these once Host_5 interface is removed. |
| 473 | 489 |
| 474 template <> | 490 template <> |
| 491 void CdmWrapperImpl<cdm::ContentDecryptionModule_5>::CreateSession( | |
| 492 uint32_t promise_id, | |
| 493 const char* init_data_type, | |
| 494 uint32_t init_data_type_size, | |
| 495 const uint8_t* init_data, | |
| 496 uint32_t init_data_size, | |
| 497 cdm::SessionType session_type) { | |
| 498 cdm_->CreateSession(promise_id, | |
| 499 ConvertInitDataTypeToContentType(init_data_type), | |
| 500 init_data_type_size, | |
| 501 init_data, | |
| 502 init_data_size); | |
| 503 } | |
| 504 | |
| 505 template <> | |
| 475 void CdmWrapperImpl<cdm::ContentDecryptionModule_5>::LoadSession( | 506 void CdmWrapperImpl<cdm::ContentDecryptionModule_5>::LoadSession( |
| 476 uint32_t promise_id, | 507 uint32_t promise_id, |
| 477 const char* web_session_id, | 508 const char* web_session_id, |
| 478 uint32_t web_session_id_size) { | 509 uint32_t web_session_id_size) { |
| 479 // As CDM_5 doesn't support OnSessionUsableKeysChange(), make sure to generate | 510 // As CDM_5 doesn't support OnSessionUsableKeysChange(), make sure to generate |
| 480 // one when the promise is resolved. This may be overly aggressive. | 511 // one when the promise is resolved. This may be overly aggressive. |
| 481 SetSessionUsableKeysEventNeeded( | 512 SetSessionUsableKeysEventNeeded( |
| 482 promise_id, web_session_id, web_session_id_size); | 513 promise_id, web_session_id, web_session_id_size); |
| 483 cdm_->LoadSession(promise_id, web_session_id, web_session_id_size); | 514 cdm_->LoadSession(promise_id, web_session_id, web_session_id_size); |
| 484 } | 515 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 // stub implementations for new or modified methods that the older CDM interface | 626 // stub implementations for new or modified methods that the older CDM interface |
| 596 // does not have. | 627 // does not have. |
| 597 // Also update supported_cdm_versions.h. | 628 // Also update supported_cdm_versions.h. |
| 598 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion == | 629 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion == |
| 599 cdm::ContentDecryptionModule_6::kVersion, | 630 cdm::ContentDecryptionModule_6::kVersion, |
| 600 ensure_cdm_wrapper_templates_have_old_version_support); | 631 ensure_cdm_wrapper_templates_have_old_version_support); |
| 601 | 632 |
| 602 } // namespace media | 633 } // namespace media |
| 603 | 634 |
| 604 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ | 635 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ |
| OLD | NEW |