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 #include "media/cdm/ppapi/cdm_adapter.h" | 5 #include "media/cdm/ppapi/cdm_adapter.h" |
6 | 6 |
7 #include "media/cdm/ppapi/cdm_helpers.h" | 7 #include "media/cdm/ppapi/cdm_helpers.h" |
8 #include "media/cdm/ppapi/supported_cdm_versions.h" | 8 #include "media/cdm/ppapi/supported_cdm_versions.h" |
9 | 9 |
10 #if defined(CHECK_DOCUMENT_URL) | 10 #if defined(CHECK_DOCUMENT_URL) |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 PP_DCHECK(!key_system.empty()); | 240 PP_DCHECK(!key_system.empty()); |
241 PP_DCHECK(key_system_.empty() || (key_system_ == key_system && cdm_)); | 241 PP_DCHECK(key_system_.empty() || (key_system_ == key_system && cdm_)); |
242 | 242 |
243 if (!cdm_ && !CreateCdmInstance(key_system)) | 243 if (!cdm_ && !CreateCdmInstance(key_system)) |
244 return; | 244 return; |
245 | 245 |
246 PP_DCHECK(cdm_); | 246 PP_DCHECK(cdm_); |
247 key_system_ = key_system; | 247 key_system_ = key_system; |
248 } | 248 } |
249 | 249 |
250 void CdmAdapter::CreateSession(uint32_t reference_id, | 250 void CdmAdapter::CreateSession(uint32_t session_id, |
251 const std::string& type, | 251 const std::string& type, |
252 pp::VarArrayBuffer init_data) { | 252 pp::VarArrayBuffer init_data) { |
253 // Initialize() doesn't report an error, so CreateSession() can be called | 253 // Initialize() doesn't report an error, so CreateSession() can be called |
254 // even if Initialize() failed. | 254 // even if Initialize() failed. |
255 if (!cdm_) { | 255 if (!cdm_) { |
256 OnSessionError(reference_id, cdm::kUnknownError, 0); | 256 OnSessionError(session_id, cdm::kUnknownError, 0); |
257 return; | 257 return; |
258 } | 258 } |
259 | 259 |
260 #if defined(CHECK_DOCUMENT_URL) | 260 #if defined(CHECK_DOCUMENT_URL) |
261 PP_URLComponents_Dev url_components = {}; | 261 PP_URLComponents_Dev url_components = {}; |
262 const pp::URLUtil_Dev* url_util = pp::URLUtil_Dev::Get(); | 262 const pp::URLUtil_Dev* url_util = pp::URLUtil_Dev::Get(); |
263 if (!url_util) { | 263 if (!url_util) { |
264 OnSessionError(reference_id, cdm::kUnknownError, 0); | 264 OnSessionError(session_id, cdm::kUnknownError, 0); |
265 return; | 265 return; |
266 } | 266 } |
267 pp::Var href = url_util->GetDocumentURL( | 267 pp::Var href = url_util->GetDocumentURL( |
268 pp::InstanceHandle(pp_instance()), &url_components); | 268 pp::InstanceHandle(pp_instance()), &url_components); |
269 PP_DCHECK(href.is_string()); | 269 PP_DCHECK(href.is_string()); |
270 PP_DCHECK(!href.AsString().empty()); | 270 PP_DCHECK(!href.AsString().empty()); |
271 PP_DCHECK(url_components.host.begin); | 271 PP_DCHECK(url_components.host.begin); |
272 PP_DCHECK(0 < url_components.host.len); | 272 PP_DCHECK(0 < url_components.host.len); |
273 #endif // defined(CHECK_DOCUMENT_URL) | 273 #endif // defined(CHECK_DOCUMENT_URL) |
274 | 274 |
275 cdm_->CreateSession(reference_id, | 275 cdm_->CreateSession(session_id, |
276 type.data(), | 276 type.data(), |
277 type.size(), | 277 type.size(), |
278 static_cast<const uint8_t*>(init_data.Map()), | 278 static_cast<const uint8_t*>(init_data.Map()), |
279 init_data.ByteLength()); | 279 init_data.ByteLength()); |
280 } | 280 } |
281 | 281 |
282 void CdmAdapter::UpdateSession(uint32_t reference_id, | 282 void CdmAdapter::UpdateSession(uint32_t session_id, |
283 pp::VarArrayBuffer response) { | 283 pp::VarArrayBuffer response) { |
284 // TODO(jrummell): In EME WD, AddKey() can only be called on valid sessions. | 284 // TODO(jrummell): In EME WD, AddKey() can only be called on valid sessions. |
285 // We should be able to DCHECK(cdm_) when addressing http://crbug.com/249976. | 285 // We should be able to DCHECK(cdm_) when addressing http://crbug.com/249976. |
286 if (!cdm_) { | 286 if (!cdm_) { |
287 OnSessionError(reference_id, cdm::kUnknownError, 0); | 287 OnSessionError(session_id, cdm::kUnknownError, 0); |
288 return; | 288 return; |
289 } | 289 } |
290 | 290 |
291 const uint8_t* response_ptr = static_cast<const uint8_t*>(response.Map()); | 291 const uint8_t* response_ptr = static_cast<const uint8_t*>(response.Map()); |
292 const uint32_t response_size = response.ByteLength(); | 292 const uint32_t response_size = response.ByteLength(); |
293 | 293 |
294 if (!response_ptr || response_size <= 0) { | 294 if (!response_ptr || response_size <= 0) { |
295 OnSessionError(reference_id, cdm::kUnknownError, 0); | 295 OnSessionError(session_id, cdm::kUnknownError, 0); |
296 return; | 296 return; |
297 } | 297 } |
298 CdmWrapper::Result result = | 298 CdmWrapper::Result result = |
299 cdm_->UpdateSession(reference_id, response_ptr, response_size); | 299 cdm_->UpdateSession(session_id, response_ptr, response_size); |
300 switch (result) { | 300 switch (result) { |
301 case CdmWrapper::NO_ACTION: | 301 case CdmWrapper::NO_ACTION: |
302 break; | 302 break; |
303 case CdmWrapper::CALL_KEY_ADDED: | 303 case CdmWrapper::CALL_KEY_ADDED: |
304 OnSessionReady(reference_id); | 304 OnSessionReady(session_id); |
305 break; | 305 break; |
306 case CdmWrapper::CALL_KEY_ERROR: | 306 case CdmWrapper::CALL_KEY_ERROR: |
307 OnSessionError(reference_id, cdm::kUnknownError, 0); | 307 OnSessionError(session_id, cdm::kUnknownError, 0); |
308 break; | 308 break; |
309 } | 309 } |
310 } | 310 } |
311 | 311 |
312 void CdmAdapter::ReleaseSession(uint32_t reference_id) { | 312 void CdmAdapter::ReleaseSession(uint32_t session_id) { |
313 // TODO(jrummell): In EME WD, AddKey() can only be called on valid sessions. | 313 // TODO(jrummell): In EME WD, AddKey() can only be called on valid sessions. |
314 // We should be able to DCHECK(cdm_) when addressing http://crbug.com/249976. | 314 // We should be able to DCHECK(cdm_) when addressing http://crbug.com/249976. |
315 if (!cdm_) { | 315 if (!cdm_) { |
316 OnSessionError(reference_id, cdm::kUnknownError, 0); | 316 OnSessionError(session_id, cdm::kUnknownError, 0); |
317 return; | 317 return; |
318 } | 318 } |
319 | 319 |
320 CdmWrapper::Result result = cdm_->ReleaseSession(reference_id); | 320 CdmWrapper::Result result = cdm_->ReleaseSession(session_id); |
321 switch (result) { | 321 switch (result) { |
322 case CdmWrapper::NO_ACTION: | 322 case CdmWrapper::NO_ACTION: |
323 break; | 323 break; |
324 case CdmWrapper::CALL_KEY_ADDED: | 324 case CdmWrapper::CALL_KEY_ADDED: |
325 PP_NOTREACHED(); | 325 PP_NOTREACHED(); |
326 break; | 326 break; |
327 case CdmWrapper::CALL_KEY_ERROR: | 327 case CdmWrapper::CALL_KEY_ERROR: |
328 OnSessionError(reference_id, cdm::kUnknownError, 0); | 328 OnSessionError(session_id, cdm::kUnknownError, 0); |
329 break; | 329 break; |
330 } | 330 } |
331 } | 331 } |
332 | 332 |
333 // Note: In the following decryption/decoding related functions, errors are NOT | 333 // Note: In the following decryption/decoding related functions, errors are NOT |
334 // reported via KeyError, but are reported via corresponding PPB calls. | 334 // reported via KeyError, but are reported via corresponding PPB calls. |
335 | 335 |
336 void CdmAdapter::Decrypt(pp::Buffer_Dev encrypted_buffer, | 336 void CdmAdapter::Decrypt(pp::Buffer_Dev encrypted_buffer, |
337 const PP_EncryptedBlockInfo& encrypted_block_info) { | 337 const PP_EncryptedBlockInfo& encrypted_block_info) { |
338 PP_DCHECK(!encrypted_buffer.is_null()); | 338 PP_DCHECK(!encrypted_buffer.is_null()); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 } | 529 } |
530 | 530 |
531 void CdmAdapter::SendKeyMessage( | 531 void CdmAdapter::SendKeyMessage( |
532 const char* session_id, uint32_t session_id_length, | 532 const char* session_id, uint32_t session_id_length, |
533 const char* message, uint32_t message_length, | 533 const char* message, uint32_t message_length, |
534 const char* default_url, uint32_t default_url_length) { | 534 const char* default_url, uint32_t default_url_length) { |
535 PP_DCHECK(!key_system_.empty()); | 535 PP_DCHECK(!key_system_.empty()); |
536 | 536 |
537 std::string session_id_str(session_id, session_id_length); | 537 std::string session_id_str(session_id, session_id_length); |
538 PP_DCHECK(!session_id_str.empty()); | 538 PP_DCHECK(!session_id_str.empty()); |
539 uint32_t reference_id = cdm_->DetermineReferenceId(session_id_str); | 539 uint32_t session_reference_id = cdm_->DetermineReferenceId(session_id_str); |
ddorwin
2013/12/05 00:44:52
Is the naming here intentional?
jrummell
2013/12/06 23:42:35
Yes. The old CDM APIs pass around the string as "s
ddorwin
2013/12/09 18:45:52
So we can rename it when we remove CDM 1 & 2?
jrummell
2013/12/09 21:01:18
It will be removed, since SendKeyMessage() and Sen
| |
540 | 540 |
541 OnSessionCreated(reference_id, session_id, session_id_length); | 541 OnSessionCreated(session_reference_id, session_id, session_id_length); |
542 OnSessionMessage( | 542 OnSessionMessage(session_reference_id, |
543 reference_id, message, message_length, default_url, default_url_length); | 543 message, message_length, |
544 default_url, default_url_length); | |
544 } | 545 } |
545 | 546 |
546 void CdmAdapter::SendKeyError(const char* session_id, | 547 void CdmAdapter::SendKeyError(const char* session_id, |
547 uint32_t session_id_length, | 548 uint32_t session_id_length, |
548 cdm::MediaKeyError error_code, | 549 cdm::MediaKeyError error_code, |
549 uint32_t system_code) { | 550 uint32_t system_code) { |
550 std::string session_id_str(session_id, session_id_length); | 551 std::string session_id_str(session_id, session_id_length); |
551 uint32_t reference_id = cdm_->DetermineReferenceId(session_id_str); | 552 uint32_t session_reference_id = cdm_->DetermineReferenceId(session_id_str); |
552 OnSessionError(reference_id, error_code, system_code); | 553 OnSessionError(session_reference_id, error_code, system_code); |
553 } | 554 } |
554 | 555 |
555 void CdmAdapter::GetPrivateData(int32_t* instance, | 556 void CdmAdapter::GetPrivateData(int32_t* instance, |
556 GetPrivateInterface* get_interface) { | 557 GetPrivateInterface* get_interface) { |
557 *instance = pp_instance(); | 558 *instance = pp_instance(); |
558 *get_interface = pp::Module::Get()->get_browser_interface(); | 559 *get_interface = pp::Module::Get()->get_browser_interface(); |
559 } | 560 } |
560 | 561 |
561 void CdmAdapter::OnSessionCreated(uint32_t reference_id, | 562 void CdmAdapter::OnSessionCreated(uint32_t session_id, |
562 const char* session_id, | 563 const char* web_session_id, |
563 uint32_t session_id_length) { | 564 uint32_t web_session_id_length) { |
564 PostOnMain(callback_factory_.NewCallback( | 565 PostOnMain(callback_factory_.NewCallback( |
565 &CdmAdapter::SendSessionCreatedInternal, | 566 &CdmAdapter::SendSessionCreatedInternal, |
566 reference_id, | 567 session_id, |
567 std::string(session_id, session_id_length))); | 568 std::string(web_session_id, web_session_id_length))); |
568 } | 569 } |
569 | 570 |
570 void CdmAdapter::OnSessionMessage(uint32_t reference_id, | 571 void CdmAdapter::OnSessionMessage(uint32_t session_id, |
571 const char* message, | 572 const char* message, |
572 uint32_t message_length, | 573 uint32_t message_length, |
573 const char* destination_url, | 574 const char* destination_url, |
574 uint32_t destination_url_length) { | 575 uint32_t destination_url_length) { |
575 PostOnMain(callback_factory_.NewCallback( | 576 PostOnMain(callback_factory_.NewCallback( |
576 &CdmAdapter::SendSessionMessageInternal, | 577 &CdmAdapter::SendSessionMessageInternal, |
577 reference_id, | 578 session_id, |
578 std::vector<uint8>(message, message + message_length), | 579 std::vector<uint8>(message, message + message_length), |
579 std::string(destination_url, destination_url_length))); | 580 std::string(destination_url, destination_url_length))); |
580 } | 581 } |
581 | 582 |
582 void CdmAdapter::OnSessionReady(uint32_t reference_id) { | 583 void CdmAdapter::OnSessionReady(uint32_t session_id) { |
583 PostOnMain(callback_factory_.NewCallback( | 584 PostOnMain(callback_factory_.NewCallback( |
584 &CdmAdapter::SendSessionReadyInternal, reference_id)); | 585 &CdmAdapter::SendSessionReadyInternal, session_id)); |
585 } | 586 } |
586 | 587 |
587 void CdmAdapter::OnSessionClosed(uint32_t reference_id) { | 588 void CdmAdapter::OnSessionClosed(uint32_t session_id) { |
588 PostOnMain(callback_factory_.NewCallback( | 589 PostOnMain(callback_factory_.NewCallback( |
589 &CdmAdapter::SendSessionClosedInternal, reference_id)); | 590 &CdmAdapter::SendSessionClosedInternal, session_id)); |
590 } | 591 } |
591 | 592 |
592 void CdmAdapter::OnSessionError(uint32_t reference_id, | 593 void CdmAdapter::OnSessionError(uint32_t session_id, |
593 cdm::MediaKeyError error_code, | 594 cdm::MediaKeyError error_code, |
594 uint32_t system_code) { | 595 uint32_t system_code) { |
595 PostOnMain(callback_factory_.NewCallback( | 596 PostOnMain(callback_factory_.NewCallback( |
596 &CdmAdapter::SendSessionErrorInternal, | 597 &CdmAdapter::SendSessionErrorInternal, |
597 reference_id, | 598 session_id, |
598 error_code, | 599 error_code, |
599 system_code)); | 600 system_code)); |
600 } | 601 } |
601 | 602 |
602 void CdmAdapter::SendSessionCreatedInternal(int32_t result, | 603 void CdmAdapter::SendSessionCreatedInternal(int32_t result, |
603 uint32_t reference_id, | 604 uint32_t session_id, |
604 const std::string& session_id) { | 605 const std::string& web_session_id) { |
605 PP_DCHECK(result == PP_OK); | 606 PP_DCHECK(result == PP_OK); |
606 pp::ContentDecryptor_Private::SessionCreated(reference_id, session_id); | 607 pp::ContentDecryptor_Private::SessionCreated(session_id, web_session_id); |
607 } | 608 } |
608 | 609 |
609 void CdmAdapter::SendSessionMessageInternal(int32_t result, | 610 void CdmAdapter::SendSessionMessageInternal(int32_t result, |
610 uint32_t reference_id, | 611 uint32_t session_id, |
611 const std::vector<uint8>& message, | 612 const std::vector<uint8>& message, |
612 const std::string& default_url) { | 613 const std::string& default_url) { |
613 PP_DCHECK(result == PP_OK); | 614 PP_DCHECK(result == PP_OK); |
614 | 615 |
615 pp::VarArrayBuffer message_array_buffer(message.size()); | 616 pp::VarArrayBuffer message_array_buffer(message.size()); |
616 if (message.size() > 0) { | 617 if (message.size() > 0) { |
617 memcpy(message_array_buffer.Map(), message.data(), message.size()); | 618 memcpy(message_array_buffer.Map(), message.data(), message.size()); |
618 } | 619 } |
619 | 620 |
620 pp::ContentDecryptor_Private::SessionMessage( | 621 pp::ContentDecryptor_Private::SessionMessage( |
621 reference_id, message_array_buffer, default_url); | 622 session_id, message_array_buffer, default_url); |
622 } | 623 } |
623 | 624 |
624 void CdmAdapter::SendSessionReadyInternal(int32_t result, | 625 void CdmAdapter::SendSessionReadyInternal(int32_t result, uint32_t session_id) { |
625 uint32_t reference_id) { | |
626 PP_DCHECK(result == PP_OK); | 626 PP_DCHECK(result == PP_OK); |
627 pp::ContentDecryptor_Private::SessionReady(reference_id); | 627 pp::ContentDecryptor_Private::SessionReady(session_id); |
628 } | 628 } |
629 | 629 |
630 void CdmAdapter::SendSessionClosedInternal(int32_t result, | 630 void CdmAdapter::SendSessionClosedInternal(int32_t result, |
631 uint32_t reference_id) { | 631 uint32_t session_id) { |
632 PP_DCHECK(result == PP_OK); | 632 PP_DCHECK(result == PP_OK); |
633 pp::ContentDecryptor_Private::SessionClosed(reference_id); | 633 pp::ContentDecryptor_Private::SessionClosed(session_id); |
634 } | 634 } |
635 | 635 |
636 void CdmAdapter::SendSessionErrorInternal(int32_t result, | 636 void CdmAdapter::SendSessionErrorInternal(int32_t result, |
637 uint32_t reference_id, | 637 uint32_t session_id, |
638 cdm::MediaKeyError error_code, | 638 cdm::MediaKeyError error_code, |
639 uint32_t system_code) { | 639 uint32_t system_code) { |
640 PP_DCHECK(result == PP_OK); | 640 PP_DCHECK(result == PP_OK); |
641 pp::ContentDecryptor_Private::SessionError( | 641 pp::ContentDecryptor_Private::SessionError( |
642 reference_id, error_code, system_code); | 642 session_id, error_code, system_code); |
643 } | 643 } |
644 | 644 |
645 void CdmAdapter::DeliverBlock(int32_t result, | 645 void CdmAdapter::DeliverBlock(int32_t result, |
646 const cdm::Status& status, | 646 const cdm::Status& status, |
647 const LinkedDecryptedBlock& decrypted_block, | 647 const LinkedDecryptedBlock& decrypted_block, |
648 const PP_DecryptTrackingInfo& tracking_info) { | 648 const PP_DecryptTrackingInfo& tracking_info) { |
649 PP_DCHECK(result == PP_OK); | 649 PP_DCHECK(result == PP_OK); |
650 PP_DecryptedBlockInfo decrypted_block_info; | 650 PP_DecryptedBlockInfo decrypted_block_info; |
651 decrypted_block_info.tracking_info = tracking_info; | 651 decrypted_block_info.tracking_info = tracking_info; |
652 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp(); | 652 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp(); |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1003 } // namespace media | 1003 } // namespace media |
1004 | 1004 |
1005 namespace pp { | 1005 namespace pp { |
1006 | 1006 |
1007 // Factory function for your specialization of the Module object. | 1007 // Factory function for your specialization of the Module object. |
1008 Module* CreateModule() { | 1008 Module* CreateModule() { |
1009 return new media::CdmAdapterModule(); | 1009 return new media::CdmAdapterModule(); |
1010 } | 1010 } |
1011 | 1011 |
1012 } // namespace pp | 1012 } // namespace pp |
OLD | NEW |