| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/cdm_adapter.h" | 5 #include "media/cdm/cdm_adapter.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "media/base/audio_decoder_config.h" | 16 #include "media/base/audio_decoder_config.h" |
| 16 #include "media/base/cdm_initialized_promise.h" | 17 #include "media/base/cdm_initialized_promise.h" |
| 17 #include "media/base/cdm_key_information.h" | 18 #include "media/base/cdm_key_information.h" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 340 |
| 340 scoped_refptr<CdmAdapter> cdm = | 341 scoped_refptr<CdmAdapter> cdm = |
| 341 new CdmAdapter(key_system, cdm_config, session_message_cb, | 342 new CdmAdapter(key_system, cdm_config, session_message_cb, |
| 342 session_closed_cb, legacy_session_error_cb, | 343 session_closed_cb, legacy_session_error_cb, |
| 343 session_keys_change_cb, session_expiration_update_cb); | 344 session_keys_change_cb, session_expiration_update_cb); |
| 344 | 345 |
| 345 // |cdm| ownership passed to the promise. | 346 // |cdm| ownership passed to the promise. |
| 346 scoped_ptr<CdmInitializedPromise> cdm_created_promise( | 347 scoped_ptr<CdmInitializedPromise> cdm_created_promise( |
| 347 new CdmInitializedPromise(cdm_created_cb, cdm)); | 348 new CdmInitializedPromise(cdm_created_cb, cdm)); |
| 348 | 349 |
| 349 cdm->Initialize(cdm_path, cdm_created_promise.Pass()); | 350 cdm->Initialize(cdm_path, std::move(cdm_created_promise)); |
| 350 } | 351 } |
| 351 | 352 |
| 352 CdmAdapter::CdmAdapter( | 353 CdmAdapter::CdmAdapter( |
| 353 const std::string& key_system, | 354 const std::string& key_system, |
| 354 const CdmConfig& cdm_config, | 355 const CdmConfig& cdm_config, |
| 355 const SessionMessageCB& session_message_cb, | 356 const SessionMessageCB& session_message_cb, |
| 356 const SessionClosedCB& session_closed_cb, | 357 const SessionClosedCB& session_closed_cb, |
| 357 const LegacySessionErrorCB& legacy_session_error_cb, | 358 const LegacySessionErrorCB& legacy_session_error_cb, |
| 358 const SessionKeysChangeCB& session_keys_change_cb, | 359 const SessionKeysChangeCB& session_keys_change_cb, |
| 359 const SessionExpirationUpdateCB& session_expiration_update_cb) | 360 const SessionExpirationUpdateCB& session_expiration_update_cb) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 scoped_ptr<SimpleCdmPromise> promise) { | 427 scoped_ptr<SimpleCdmPromise> promise) { |
| 427 DCHECK(task_runner_->BelongsToCurrentThread()); | 428 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 428 | 429 |
| 429 if (certificate.size() < limits::kMinCertificateLength || | 430 if (certificate.size() < limits::kMinCertificateLength || |
| 430 certificate.size() > limits::kMaxCertificateLength) { | 431 certificate.size() > limits::kMaxCertificateLength) { |
| 431 promise->reject(MediaKeys::INVALID_ACCESS_ERROR, 0, | 432 promise->reject(MediaKeys::INVALID_ACCESS_ERROR, 0, |
| 432 "Incorrect certificate."); | 433 "Incorrect certificate."); |
| 433 return; | 434 return; |
| 434 } | 435 } |
| 435 | 436 |
| 436 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | 437 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); |
| 437 cdm_->SetServerCertificate(promise_id, certificate.data(), | 438 cdm_->SetServerCertificate(promise_id, certificate.data(), |
| 438 certificate.size()); | 439 certificate.size()); |
| 439 } | 440 } |
| 440 | 441 |
| 441 void CdmAdapter::CreateSessionAndGenerateRequest( | 442 void CdmAdapter::CreateSessionAndGenerateRequest( |
| 442 SessionType session_type, | 443 SessionType session_type, |
| 443 EmeInitDataType init_data_type, | 444 EmeInitDataType init_data_type, |
| 444 const std::vector<uint8_t>& init_data, | 445 const std::vector<uint8_t>& init_data, |
| 445 scoped_ptr<NewSessionCdmPromise> promise) { | 446 scoped_ptr<NewSessionCdmPromise> promise) { |
| 446 DCHECK(task_runner_->BelongsToCurrentThread()); | 447 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 447 | 448 |
| 448 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | 449 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); |
| 449 cdm_->CreateSessionAndGenerateRequest( | 450 cdm_->CreateSessionAndGenerateRequest( |
| 450 promise_id, ToCdmSessionType(session_type), | 451 promise_id, ToCdmSessionType(session_type), |
| 451 ToCdmInitDataType(init_data_type), init_data.data(), init_data.size()); | 452 ToCdmInitDataType(init_data_type), init_data.data(), init_data.size()); |
| 452 } | 453 } |
| 453 | 454 |
| 454 void CdmAdapter::LoadSession(SessionType session_type, | 455 void CdmAdapter::LoadSession(SessionType session_type, |
| 455 const std::string& session_id, | 456 const std::string& session_id, |
| 456 scoped_ptr<NewSessionCdmPromise> promise) { | 457 scoped_ptr<NewSessionCdmPromise> promise) { |
| 457 DCHECK(task_runner_->BelongsToCurrentThread()); | 458 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 458 | 459 |
| 459 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | 460 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); |
| 460 cdm_->LoadSession(promise_id, ToCdmSessionType(session_type), | 461 cdm_->LoadSession(promise_id, ToCdmSessionType(session_type), |
| 461 session_id.data(), session_id.size()); | 462 session_id.data(), session_id.size()); |
| 462 } | 463 } |
| 463 | 464 |
| 464 void CdmAdapter::UpdateSession(const std::string& session_id, | 465 void CdmAdapter::UpdateSession(const std::string& session_id, |
| 465 const std::vector<uint8_t>& response, | 466 const std::vector<uint8_t>& response, |
| 466 scoped_ptr<SimpleCdmPromise> promise) { | 467 scoped_ptr<SimpleCdmPromise> promise) { |
| 467 DCHECK(task_runner_->BelongsToCurrentThread()); | 468 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 468 DCHECK(!session_id.empty()); | 469 DCHECK(!session_id.empty()); |
| 469 DCHECK(!response.empty()); | 470 DCHECK(!response.empty()); |
| 470 | 471 |
| 471 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | 472 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); |
| 472 cdm_->UpdateSession(promise_id, session_id.data(), session_id.size(), | 473 cdm_->UpdateSession(promise_id, session_id.data(), session_id.size(), |
| 473 response.data(), response.size()); | 474 response.data(), response.size()); |
| 474 } | 475 } |
| 475 | 476 |
| 476 void CdmAdapter::CloseSession(const std::string& session_id, | 477 void CdmAdapter::CloseSession(const std::string& session_id, |
| 477 scoped_ptr<SimpleCdmPromise> promise) { | 478 scoped_ptr<SimpleCdmPromise> promise) { |
| 478 DCHECK(task_runner_->BelongsToCurrentThread()); | 479 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 479 DCHECK(!session_id.empty()); | 480 DCHECK(!session_id.empty()); |
| 480 | 481 |
| 481 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | 482 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); |
| 482 cdm_->CloseSession(promise_id, session_id.data(), session_id.size()); | 483 cdm_->CloseSession(promise_id, session_id.data(), session_id.size()); |
| 483 } | 484 } |
| 484 | 485 |
| 485 void CdmAdapter::RemoveSession(const std::string& session_id, | 486 void CdmAdapter::RemoveSession(const std::string& session_id, |
| 486 scoped_ptr<SimpleCdmPromise> promise) { | 487 scoped_ptr<SimpleCdmPromise> promise) { |
| 487 DCHECK(task_runner_->BelongsToCurrentThread()); | 488 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 488 DCHECK(!session_id.empty()); | 489 DCHECK(!session_id.empty()); |
| 489 | 490 |
| 490 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); | 491 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); |
| 491 cdm_->RemoveSession(promise_id, session_id.data(), session_id.size()); | 492 cdm_->RemoveSession(promise_id, session_id.data(), session_id.size()); |
| 492 } | 493 } |
| 493 | 494 |
| 494 CdmContext* CdmAdapter::GetCdmContext() { | 495 CdmContext* CdmAdapter::GetCdmContext() { |
| 495 DCHECK(task_runner_->BelongsToCurrentThread()); | 496 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 496 return this; | 497 return this; |
| 497 } | 498 } |
| 498 | 499 |
| 499 Decryptor* CdmAdapter::GetDecryptor() { | 500 Decryptor* CdmAdapter::GetDecryptor() { |
| 500 DCHECK(task_runner_->BelongsToCurrentThread()); | 501 DCHECK(task_runner_->BelongsToCurrentThread()); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 | 639 |
| 639 const Decryptor::AudioFrames empty_frames; | 640 const Decryptor::AudioFrames empty_frames; |
| 640 if (status != cdm::kSuccess) { | 641 if (status != cdm::kSuccess) { |
| 641 DVLOG(1) << __FUNCTION__ << " failed with cdm::Error " << status; | 642 DVLOG(1) << __FUNCTION__ << " failed with cdm::Error " << status; |
| 642 audio_decode_cb.Run(ToMediaDecryptorStatus(status), empty_frames); | 643 audio_decode_cb.Run(ToMediaDecryptorStatus(status), empty_frames); |
| 643 return; | 644 return; |
| 644 } | 645 } |
| 645 | 646 |
| 646 Decryptor::AudioFrames audio_frame_list; | 647 Decryptor::AudioFrames audio_frame_list; |
| 647 DCHECK(audio_frames->FrameBuffer()); | 648 DCHECK(audio_frames->FrameBuffer()); |
| 648 if (!AudioFramesDataToAudioFrames(audio_frames.Pass(), &audio_frame_list)) { | 649 if (!AudioFramesDataToAudioFrames(std::move(audio_frames), |
| 650 &audio_frame_list)) { |
| 649 DVLOG(1) << __FUNCTION__ << " unable to convert Audio Frames"; | 651 DVLOG(1) << __FUNCTION__ << " unable to convert Audio Frames"; |
| 650 audio_decode_cb.Run(Decryptor::kError, empty_frames); | 652 audio_decode_cb.Run(Decryptor::kError, empty_frames); |
| 651 return; | 653 return; |
| 652 } | 654 } |
| 653 | 655 |
| 654 audio_decode_cb.Run(Decryptor::kSuccess, audio_frame_list); | 656 audio_decode_cb.Run(Decryptor::kSuccess, audio_frame_list); |
| 655 } | 657 } |
| 656 | 658 |
| 657 void CdmAdapter::DecryptAndDecodeVideo( | 659 void CdmAdapter::DecryptAndDecodeVideo( |
| 658 const scoped_refptr<DecoderBuffer>& encrypted, | 660 const scoped_refptr<DecoderBuffer>& encrypted, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 // TODO(jrummell): Handling resume playback should be done in the media | 803 // TODO(jrummell): Handling resume playback should be done in the media |
| 802 // player, not in the Decryptors. http://crbug.com/413413. | 804 // player, not in the Decryptors. http://crbug.com/413413. |
| 803 if (has_additional_usable_key) { | 805 if (has_additional_usable_key) { |
| 804 if (!new_audio_key_cb_.is_null()) | 806 if (!new_audio_key_cb_.is_null()) |
| 805 new_audio_key_cb_.Run(); | 807 new_audio_key_cb_.Run(); |
| 806 if (!new_video_key_cb_.is_null()) | 808 if (!new_video_key_cb_.is_null()) |
| 807 new_video_key_cb_.Run(); | 809 new_video_key_cb_.Run(); |
| 808 } | 810 } |
| 809 | 811 |
| 810 session_keys_change_cb_.Run(std::string(session_id, session_id_size), | 812 session_keys_change_cb_.Run(std::string(session_id, session_id_size), |
| 811 has_additional_usable_key, keys.Pass()); | 813 has_additional_usable_key, std::move(keys)); |
| 812 } | 814 } |
| 813 | 815 |
| 814 void CdmAdapter::OnExpirationChange(const char* session_id, | 816 void CdmAdapter::OnExpirationChange(const char* session_id, |
| 815 uint32_t session_id_size, | 817 uint32_t session_id_size, |
| 816 cdm::Time new_expiry_time) { | 818 cdm::Time new_expiry_time) { |
| 817 DCHECK(task_runner_->BelongsToCurrentThread()); | 819 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 818 | 820 |
| 819 session_expiration_update_cb_.Run(std::string(session_id, session_id_size), | 821 session_expiration_update_cb_.Run(std::string(session_id, session_id_size), |
| 820 base::Time::FromDoubleT(new_expiry_time)); | 822 base::Time::FromDoubleT(new_expiry_time)); |
| 821 } | 823 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 result_frames->push_back(frame); | 951 result_frames->push_back(frame); |
| 950 | 952 |
| 951 data += frame_size; | 953 data += frame_size; |
| 952 bytes_left -= frame_size; | 954 bytes_left -= frame_size; |
| 953 } while (bytes_left > 0); | 955 } while (bytes_left > 0); |
| 954 | 956 |
| 955 return true; | 957 return true; |
| 956 } | 958 } |
| 957 | 959 |
| 958 } // namespace media | 960 } // namespace media |
| OLD | NEW |