| 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 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 | 330 |
| 331 // static | 331 // static |
| 332 void CdmAdapter::Create( | 332 void CdmAdapter::Create( |
| 333 const std::string& key_system, | 333 const std::string& key_system, |
| 334 const base::FilePath& cdm_path, | 334 const base::FilePath& cdm_path, |
| 335 const CdmConfig& cdm_config, | 335 const CdmConfig& cdm_config, |
| 336 std::unique_ptr<CdmAllocator> allocator, | 336 std::unique_ptr<CdmAllocator> allocator, |
| 337 const CreateCdmFileIOCB& create_cdm_file_io_cb, | 337 const CreateCdmFileIOCB& create_cdm_file_io_cb, |
| 338 const SessionMessageCB& session_message_cb, | 338 const SessionMessageCB& session_message_cb, |
| 339 const SessionClosedCB& session_closed_cb, | 339 const SessionClosedCB& session_closed_cb, |
| 340 const LegacySessionErrorCB& legacy_session_error_cb, | |
| 341 const SessionKeysChangeCB& session_keys_change_cb, | 340 const SessionKeysChangeCB& session_keys_change_cb, |
| 342 const SessionExpirationUpdateCB& session_expiration_update_cb, | 341 const SessionExpirationUpdateCB& session_expiration_update_cb, |
| 343 const CdmCreatedCB& cdm_created_cb) { | 342 const CdmCreatedCB& cdm_created_cb) { |
| 344 DCHECK(!key_system.empty()); | 343 DCHECK(!key_system.empty()); |
| 345 DCHECK(!session_message_cb.is_null()); | 344 DCHECK(!session_message_cb.is_null()); |
| 346 DCHECK(!session_closed_cb.is_null()); | 345 DCHECK(!session_closed_cb.is_null()); |
| 347 DCHECK(!legacy_session_error_cb.is_null()); | |
| 348 DCHECK(!session_keys_change_cb.is_null()); | 346 DCHECK(!session_keys_change_cb.is_null()); |
| 349 DCHECK(!session_expiration_update_cb.is_null()); | 347 DCHECK(!session_expiration_update_cb.is_null()); |
| 350 | 348 |
| 351 scoped_refptr<CdmAdapter> cdm = new CdmAdapter( | 349 scoped_refptr<CdmAdapter> cdm = new CdmAdapter( |
| 352 key_system, cdm_config, std::move(allocator), create_cdm_file_io_cb, | 350 key_system, cdm_config, std::move(allocator), create_cdm_file_io_cb, |
| 353 session_message_cb, session_closed_cb, legacy_session_error_cb, | 351 session_message_cb, session_closed_cb, session_keys_change_cb, |
| 354 session_keys_change_cb, session_expiration_update_cb); | 352 session_expiration_update_cb); |
| 355 | 353 |
| 356 // |cdm| ownership passed to the promise. | 354 // |cdm| ownership passed to the promise. |
| 357 std::unique_ptr<CdmInitializedPromise> cdm_created_promise( | 355 std::unique_ptr<CdmInitializedPromise> cdm_created_promise( |
| 358 new CdmInitializedPromise(cdm_created_cb, cdm)); | 356 new CdmInitializedPromise(cdm_created_cb, cdm)); |
| 359 | 357 |
| 360 cdm->Initialize(cdm_path, std::move(cdm_created_promise)); | 358 cdm->Initialize(cdm_path, std::move(cdm_created_promise)); |
| 361 } | 359 } |
| 362 | 360 |
| 363 CdmAdapter::CdmAdapter( | 361 CdmAdapter::CdmAdapter( |
| 364 const std::string& key_system, | 362 const std::string& key_system, |
| 365 const CdmConfig& cdm_config, | 363 const CdmConfig& cdm_config, |
| 366 std::unique_ptr<CdmAllocator> allocator, | 364 std::unique_ptr<CdmAllocator> allocator, |
| 367 const CreateCdmFileIOCB& create_cdm_file_io_cb, | 365 const CreateCdmFileIOCB& create_cdm_file_io_cb, |
| 368 const SessionMessageCB& session_message_cb, | 366 const SessionMessageCB& session_message_cb, |
| 369 const SessionClosedCB& session_closed_cb, | 367 const SessionClosedCB& session_closed_cb, |
| 370 const LegacySessionErrorCB& legacy_session_error_cb, | |
| 371 const SessionKeysChangeCB& session_keys_change_cb, | 368 const SessionKeysChangeCB& session_keys_change_cb, |
| 372 const SessionExpirationUpdateCB& session_expiration_update_cb) | 369 const SessionExpirationUpdateCB& session_expiration_update_cb) |
| 373 : key_system_(key_system), | 370 : key_system_(key_system), |
| 374 cdm_config_(cdm_config), | 371 cdm_config_(cdm_config), |
| 375 session_message_cb_(session_message_cb), | 372 session_message_cb_(session_message_cb), |
| 376 session_closed_cb_(session_closed_cb), | 373 session_closed_cb_(session_closed_cb), |
| 377 legacy_session_error_cb_(legacy_session_error_cb), | |
| 378 session_keys_change_cb_(session_keys_change_cb), | 374 session_keys_change_cb_(session_keys_change_cb), |
| 379 session_expiration_update_cb_(session_expiration_update_cb), | 375 session_expiration_update_cb_(session_expiration_update_cb), |
| 380 audio_samples_per_second_(0), | 376 audio_samples_per_second_(0), |
| 381 audio_channel_layout_(CHANNEL_LAYOUT_NONE), | 377 audio_channel_layout_(CHANNEL_LAYOUT_NONE), |
| 382 allocator_(std::move(allocator)), | 378 allocator_(std::move(allocator)), |
| 383 create_cdm_file_io_cb_(create_cdm_file_io_cb), | 379 create_cdm_file_io_cb_(create_cdm_file_io_cb), |
| 384 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 380 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 385 weak_factory_(this) { | 381 weak_factory_(this) { |
| 386 DCHECK(!key_system_.empty()); | 382 DCHECK(!key_system_.empty()); |
| 387 DCHECK(!session_message_cb_.is_null()); | 383 DCHECK(!session_message_cb_.is_null()); |
| 388 DCHECK(!session_closed_cb_.is_null()); | 384 DCHECK(!session_closed_cb_.is_null()); |
| 389 DCHECK(!legacy_session_error_cb_.is_null()); | |
| 390 DCHECK(!session_keys_change_cb_.is_null()); | 385 DCHECK(!session_keys_change_cb_.is_null()); |
| 391 DCHECK(!session_expiration_update_cb_.is_null()); | 386 DCHECK(!session_expiration_update_cb_.is_null()); |
| 392 DCHECK(allocator_); | 387 DCHECK(allocator_); |
| 393 } | 388 } |
| 394 | 389 |
| 395 CdmAdapter::~CdmAdapter() {} | 390 CdmAdapter::~CdmAdapter() {} |
| 396 | 391 |
| 397 CdmWrapper* CdmAdapter::CreateCdmInstance(const std::string& key_system, | 392 CdmWrapper* CdmAdapter::CreateCdmInstance(const std::string& key_system, |
| 398 const base::FilePath& cdm_path) { | 393 const base::FilePath& cdm_path) { |
| 399 DCHECK(task_runner_->BelongsToCurrentThread()); | 394 DCHECK(task_runner_->BelongsToCurrentThread()); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 } | 760 } |
| 766 | 761 |
| 767 void CdmAdapter::OnSessionMessage(const char* session_id, | 762 void CdmAdapter::OnSessionMessage(const char* session_id, |
| 768 uint32_t session_id_size, | 763 uint32_t session_id_size, |
| 769 cdm::MessageType message_type, | 764 cdm::MessageType message_type, |
| 770 const char* message, | 765 const char* message, |
| 771 uint32_t message_size, | 766 uint32_t message_size, |
| 772 const char* legacy_destination_url, | 767 const char* legacy_destination_url, |
| 773 uint32_t legacy_destination_url_size) { | 768 uint32_t legacy_destination_url_size) { |
| 774 DCHECK(task_runner_->BelongsToCurrentThread()); | 769 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 775 DCHECK(legacy_destination_url_size == 0 || | 770 // |legacy_destination_url| is obsolete and will be removed as part of |
| 776 message_type != cdm::MessageType::kLicenseRequest); | 771 // https://crbug.com/570216. |
| 777 | |
| 778 GURL verified_gurl = | |
| 779 GURL(std::string(legacy_destination_url, legacy_destination_url_size)); | |
| 780 if (!verified_gurl.is_valid()) { | |
| 781 DLOG(WARNING) << "SessionMessage legacy_destination_url is invalid : " | |
| 782 << verified_gurl.possibly_invalid_spec(); | |
| 783 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. | |
| 784 } | |
| 785 | 772 |
| 786 const uint8_t* message_ptr = reinterpret_cast<const uint8_t*>(message); | 773 const uint8_t* message_ptr = reinterpret_cast<const uint8_t*>(message); |
| 787 session_message_cb_.Run( | 774 session_message_cb_.Run( |
| 788 std::string(session_id, session_id_size), | 775 std::string(session_id, session_id_size), |
| 789 ToMediaMessageType(message_type), | 776 ToMediaMessageType(message_type), |
| 790 std::vector<uint8_t>(message_ptr, message_ptr + message_size), | 777 std::vector<uint8_t>(message_ptr, message_ptr + message_size)); |
| 791 verified_gurl); | |
| 792 } | 778 } |
| 793 | 779 |
| 794 void CdmAdapter::OnSessionKeysChange(const char* session_id, | 780 void CdmAdapter::OnSessionKeysChange(const char* session_id, |
| 795 uint32_t session_id_size, | 781 uint32_t session_id_size, |
| 796 bool has_additional_usable_key, | 782 bool has_additional_usable_key, |
| 797 const cdm::KeyInformation* keys_info, | 783 const cdm::KeyInformation* keys_info, |
| 798 uint32_t keys_info_count) { | 784 uint32_t keys_info_count) { |
| 799 DCHECK(task_runner_->BelongsToCurrentThread()); | 785 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 800 | 786 |
| 801 CdmKeysInfo keys; | 787 CdmKeysInfo keys; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 session_closed_cb_.Run(std::string(session_id, session_id_size)); | 822 session_closed_cb_.Run(std::string(session_id, session_id_size)); |
| 837 } | 823 } |
| 838 | 824 |
| 839 void CdmAdapter::OnLegacySessionError(const char* session_id, | 825 void CdmAdapter::OnLegacySessionError(const char* session_id, |
| 840 uint32_t session_id_size, | 826 uint32_t session_id_size, |
| 841 cdm::Error error, | 827 cdm::Error error, |
| 842 uint32_t system_code, | 828 uint32_t system_code, |
| 843 const char* error_message, | 829 const char* error_message, |
| 844 uint32_t error_message_size) { | 830 uint32_t error_message_size) { |
| 845 DCHECK(task_runner_->BelongsToCurrentThread()); | 831 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 846 | 832 // Obsolete and will be removed as part of https://crbug.com/570216. |
| 847 legacy_session_error_cb_.Run(std::string(session_id, session_id_size), | |
| 848 ToMediaExceptionType(error), system_code, | |
| 849 std::string(error_message, error_message_size)); | |
| 850 } | 833 } |
| 851 | 834 |
| 852 void CdmAdapter::SendPlatformChallenge(const char* service_id, | 835 void CdmAdapter::SendPlatformChallenge(const char* service_id, |
| 853 uint32_t service_id_size, | 836 uint32_t service_id_size, |
| 854 const char* challenge, | 837 const char* challenge, |
| 855 uint32_t challenge_size) { | 838 uint32_t challenge_size) { |
| 856 DCHECK(task_runner_->BelongsToCurrentThread()); | 839 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 857 | 840 |
| 858 // TODO(jrummell): If platform verification is available, use it. | 841 // TODO(jrummell): If platform verification is available, use it. |
| 859 NOTIMPLEMENTED(); | 842 NOTIMPLEMENTED(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 result_frames->push_back(frame); | 942 result_frames->push_back(frame); |
| 960 | 943 |
| 961 data += frame_size; | 944 data += frame_size; |
| 962 bytes_left -= frame_size; | 945 bytes_left -= frame_size; |
| 963 } while (bytes_left > 0); | 946 } while (bytes_left > 0); |
| 964 | 947 |
| 965 return true; | 948 return true; |
| 966 } | 949 } |
| 967 | 950 |
| 968 } // namespace media | 951 } // namespace media |
| OLD | NEW |