| 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/external_clear_key/clear_key_cdm.h" | 5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 scoped_refptr<media::DecoderBuffer> output_buffer = | 98 scoped_refptr<media::DecoderBuffer> output_buffer = |
| 99 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); | 99 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); |
| 100 | 100 |
| 101 std::vector<media::SubsampleEntry> subsamples; | 101 std::vector<media::SubsampleEntry> subsamples; |
| 102 for (uint32_t i = 0; i < input_buffer.num_subsamples; ++i) { | 102 for (uint32_t i = 0; i < input_buffer.num_subsamples; ++i) { |
| 103 subsamples.push_back( | 103 subsamples.push_back( |
| 104 media::SubsampleEntry(input_buffer.subsamples[i].clear_bytes, | 104 media::SubsampleEntry(input_buffer.subsamples[i].clear_bytes, |
| 105 input_buffer.subsamples[i].cipher_bytes)); | 105 input_buffer.subsamples[i].cipher_bytes)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 scoped_ptr<media::DecryptConfig> decrypt_config(new media::DecryptConfig( | 108 std::unique_ptr<media::DecryptConfig> decrypt_config(new media::DecryptConfig( |
| 109 std::string(reinterpret_cast<const char*>(input_buffer.key_id), | 109 std::string(reinterpret_cast<const char*>(input_buffer.key_id), |
| 110 input_buffer.key_id_size), | 110 input_buffer.key_id_size), |
| 111 std::string(reinterpret_cast<const char*>(input_buffer.iv), | 111 std::string(reinterpret_cast<const char*>(input_buffer.iv), |
| 112 input_buffer.iv_size), | 112 input_buffer.iv_size), |
| 113 subsamples)); | 113 subsamples)); |
| 114 | 114 |
| 115 output_buffer->set_decrypt_config(std::move(decrypt_config)); | 115 output_buffer->set_decrypt_config(std::move(decrypt_config)); |
| 116 output_buffer->set_timestamp( | 116 output_buffer->set_timestamp( |
| 117 base::TimeDelta::FromMicroseconds(input_buffer.timestamp)); | 117 base::TimeDelta::FromMicroseconds(input_buffer.timestamp)); |
| 118 | 118 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 288 } |
| 289 | 289 |
| 290 void ClearKeyCdm::CreateSessionAndGenerateRequest( | 290 void ClearKeyCdm::CreateSessionAndGenerateRequest( |
| 291 uint32_t promise_id, | 291 uint32_t promise_id, |
| 292 cdm::SessionType session_type, | 292 cdm::SessionType session_type, |
| 293 cdm::InitDataType init_data_type, | 293 cdm::InitDataType init_data_type, |
| 294 const uint8_t* init_data, | 294 const uint8_t* init_data, |
| 295 uint32_t init_data_size) { | 295 uint32_t init_data_size) { |
| 296 DVLOG(1) << __FUNCTION__; | 296 DVLOG(1) << __FUNCTION__; |
| 297 | 297 |
| 298 scoped_ptr<media::NewSessionCdmPromise> promise( | 298 std::unique_ptr<media::NewSessionCdmPromise> promise( |
| 299 new media::CdmCallbackPromise<std::string>( | 299 new media::CdmCallbackPromise<std::string>( |
| 300 base::Bind(&ClearKeyCdm::OnSessionCreated, | 300 base::Bind(&ClearKeyCdm::OnSessionCreated, base::Unretained(this), |
| 301 base::Unretained(this), | |
| 302 promise_id), | 301 promise_id), |
| 303 base::Bind(&ClearKeyCdm::OnPromiseFailed, | 302 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), |
| 304 base::Unretained(this), | |
| 305 promise_id))); | 303 promise_id))); |
| 306 decryptor_->CreateSessionAndGenerateRequest( | 304 decryptor_->CreateSessionAndGenerateRequest( |
| 307 ConvertSessionType(session_type), ConvertInitDataType(init_data_type), | 305 ConvertSessionType(session_type), ConvertInitDataType(init_data_type), |
| 308 std::vector<uint8_t>(init_data, init_data + init_data_size), | 306 std::vector<uint8_t>(init_data, init_data + init_data_size), |
| 309 std::move(promise)); | 307 std::move(promise)); |
| 310 | 308 |
| 311 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) | 309 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) |
| 312 StartFileIOTest(); | 310 StartFileIOTest(); |
| 313 } | 311 } |
| 314 | 312 |
| 315 // Loads a emulated stored session. Currently only |kLoadableSessionId| | 313 // Loads a emulated stored session. Currently only |kLoadableSessionId| |
| 316 // (containing a |kLoadableSessionKey| for |kLoadableSessionKeyId|) is | 314 // (containing a |kLoadableSessionKey| for |kLoadableSessionKeyId|) is |
| 317 // supported. | 315 // supported. |
| 318 void ClearKeyCdm::LoadSession(uint32_t promise_id, | 316 void ClearKeyCdm::LoadSession(uint32_t promise_id, |
| 319 cdm::SessionType session_type, | 317 cdm::SessionType session_type, |
| 320 const char* session_id, | 318 const char* session_id, |
| 321 uint32_t session_id_length) { | 319 uint32_t session_id_length) { |
| 322 DVLOG(1) << __FUNCTION__; | 320 DVLOG(1) << __FUNCTION__; |
| 323 DCHECK_EQ(session_type, cdm::kPersistentLicense); | 321 DCHECK_EQ(session_type, cdm::kPersistentLicense); |
| 324 | 322 |
| 325 if (std::string(kLoadableSessionId) != | 323 if (std::string(kLoadableSessionId) != |
| 326 std::string(session_id, session_id_length)) { | 324 std::string(session_id, session_id_length)) { |
| 327 host_->OnResolveNewSessionPromise(promise_id, nullptr, 0); | 325 host_->OnResolveNewSessionPromise(promise_id, nullptr, 0); |
| 328 return; | 326 return; |
| 329 } | 327 } |
| 330 | 328 |
| 331 // Only allowed to successfully load this session once. | 329 // Only allowed to successfully load this session once. |
| 332 DCHECK(session_id_for_emulated_loadsession_.empty()); | 330 DCHECK(session_id_for_emulated_loadsession_.empty()); |
| 333 | 331 |
| 334 scoped_ptr<media::NewSessionCdmPromise> promise( | 332 std::unique_ptr<media::NewSessionCdmPromise> promise( |
| 335 new media::CdmCallbackPromise<std::string>( | 333 new media::CdmCallbackPromise<std::string>( |
| 336 base::Bind(&ClearKeyCdm::OnSessionLoaded, | 334 base::Bind(&ClearKeyCdm::OnSessionLoaded, base::Unretained(this), |
| 337 base::Unretained(this), | |
| 338 promise_id), | 335 promise_id), |
| 339 base::Bind(&ClearKeyCdm::OnPromiseFailed, | 336 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), |
| 340 base::Unretained(this), | |
| 341 promise_id))); | 337 promise_id))); |
| 342 decryptor_->CreateSessionAndGenerateRequest( | 338 decryptor_->CreateSessionAndGenerateRequest( |
| 343 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 339 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
| 344 std::vector<uint8_t>(), std::move(promise)); | 340 std::vector<uint8_t>(), std::move(promise)); |
| 345 } | 341 } |
| 346 | 342 |
| 347 void ClearKeyCdm::UpdateSession(uint32_t promise_id, | 343 void ClearKeyCdm::UpdateSession(uint32_t promise_id, |
| 348 const char* session_id, | 344 const char* session_id, |
| 349 uint32_t session_id_length, | 345 uint32_t session_id_length, |
| 350 const uint8_t* response, | 346 const uint8_t* response, |
| 351 uint32_t response_size) { | 347 uint32_t response_size) { |
| 352 DVLOG(1) << __FUNCTION__; | 348 DVLOG(1) << __FUNCTION__; |
| 353 std::string web_session_str(session_id, session_id_length); | 349 std::string web_session_str(session_id, session_id_length); |
| 354 | 350 |
| 355 // If updating the loadable session, use the actual session id generated. | 351 // If updating the loadable session, use the actual session id generated. |
| 356 if (web_session_str == std::string(kLoadableSessionId)) | 352 if (web_session_str == std::string(kLoadableSessionId)) |
| 357 web_session_str = session_id_for_emulated_loadsession_; | 353 web_session_str = session_id_for_emulated_loadsession_; |
| 358 | 354 |
| 359 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( | 355 std::unique_ptr<media::SimpleCdmPromise> promise( |
| 360 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), | 356 new media::CdmCallbackPromise<>( |
| 361 promise_id), | 357 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), |
| 362 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), | 358 promise_id), |
| 363 promise_id))); | 359 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), |
| 360 promise_id))); |
| 364 decryptor_->UpdateSession( | 361 decryptor_->UpdateSession( |
| 365 web_session_str, std::vector<uint8_t>(response, response + response_size), | 362 web_session_str, std::vector<uint8_t>(response, response + response_size), |
| 366 std::move(promise)); | 363 std::move(promise)); |
| 367 | 364 |
| 368 if (!renewal_timer_set_) { | 365 if (!renewal_timer_set_) { |
| 369 ScheduleNextRenewal(); | 366 ScheduleNextRenewal(); |
| 370 renewal_timer_set_ = true; | 367 renewal_timer_set_ = true; |
| 371 } | 368 } |
| 372 } | 369 } |
| 373 | 370 |
| 374 void ClearKeyCdm::CloseSession(uint32_t promise_id, | 371 void ClearKeyCdm::CloseSession(uint32_t promise_id, |
| 375 const char* session_id, | 372 const char* session_id, |
| 376 uint32_t session_id_length) { | 373 uint32_t session_id_length) { |
| 377 DVLOG(1) << __FUNCTION__; | 374 DVLOG(1) << __FUNCTION__; |
| 378 std::string web_session_str(session_id, session_id_length); | 375 std::string web_session_str(session_id, session_id_length); |
| 379 | 376 |
| 380 // If closing the loadable session, use the actual session id generated. | 377 // If closing the loadable session, use the actual session id generated. |
| 381 if (web_session_str == std::string(kLoadableSessionId)) | 378 if (web_session_str == std::string(kLoadableSessionId)) |
| 382 web_session_str = session_id_for_emulated_loadsession_; | 379 web_session_str = session_id_for_emulated_loadsession_; |
| 383 | 380 |
| 384 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( | 381 std::unique_ptr<media::SimpleCdmPromise> promise( |
| 385 base::Bind( | 382 new media::CdmCallbackPromise<>( |
| 386 &ClearKeyCdm::OnPromiseResolved, base::Unretained(this), promise_id), | 383 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), |
| 387 base::Bind( | 384 promise_id), |
| 388 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); | 385 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), |
| 386 promise_id))); |
| 389 decryptor_->CloseSession(web_session_str, std::move(promise)); | 387 decryptor_->CloseSession(web_session_str, std::move(promise)); |
| 390 } | 388 } |
| 391 | 389 |
| 392 void ClearKeyCdm::RemoveSession(uint32_t promise_id, | 390 void ClearKeyCdm::RemoveSession(uint32_t promise_id, |
| 393 const char* session_id, | 391 const char* session_id, |
| 394 uint32_t session_id_length) { | 392 uint32_t session_id_length) { |
| 395 DVLOG(1) << __FUNCTION__; | 393 DVLOG(1) << __FUNCTION__; |
| 396 std::string web_session_str(session_id, session_id_length); | 394 std::string web_session_str(session_id, session_id_length); |
| 397 | 395 |
| 398 // RemoveSession only allowed for the loadable session. | 396 // RemoveSession only allowed for the loadable session. |
| 399 if (web_session_str == std::string(kLoadableSessionId)) { | 397 if (web_session_str == std::string(kLoadableSessionId)) { |
| 400 web_session_str = session_id_for_emulated_loadsession_; | 398 web_session_str = session_id_for_emulated_loadsession_; |
| 401 } else { | 399 } else { |
| 402 // TODO(jrummell): This should be a DCHECK once blink does the proper | 400 // TODO(jrummell): This should be a DCHECK once blink does the proper |
| 403 // checks. | 401 // checks. |
| 404 std::string message("Not supported for non-persistent sessions."); | 402 std::string message("Not supported for non-persistent sessions."); |
| 405 host_->OnRejectPromise(promise_id, | 403 host_->OnRejectPromise(promise_id, |
| 406 cdm::kInvalidAccessError, | 404 cdm::kInvalidAccessError, |
| 407 0, | 405 0, |
| 408 message.data(), | 406 message.data(), |
| 409 message.length()); | 407 message.length()); |
| 410 return; | 408 return; |
| 411 } | 409 } |
| 412 | 410 |
| 413 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( | 411 std::unique_ptr<media::SimpleCdmPromise> promise( |
| 414 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), | 412 new media::CdmCallbackPromise<>( |
| 415 promise_id), | 413 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), |
| 416 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), | 414 promise_id), |
| 417 promise_id))); | 415 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), |
| 416 promise_id))); |
| 418 decryptor_->RemoveSession(web_session_str, std::move(promise)); | 417 decryptor_->RemoveSession(web_session_str, std::move(promise)); |
| 419 } | 418 } |
| 420 | 419 |
| 421 void ClearKeyCdm::SetServerCertificate(uint32_t promise_id, | 420 void ClearKeyCdm::SetServerCertificate(uint32_t promise_id, |
| 422 const uint8_t* server_certificate_data, | 421 const uint8_t* server_certificate_data, |
| 423 uint32_t server_certificate_data_size) { | 422 uint32_t server_certificate_data_size) { |
| 424 // ClearKey doesn't use a server certificate. | 423 // ClearKey doesn't use a server certificate. |
| 425 host_->OnResolvePromise(promise_id); | 424 host_->OnResolvePromise(promise_id); |
| 426 } | 425 } |
| 427 | 426 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 uint32_t link_mask, | 686 uint32_t link_mask, |
| 688 uint32_t output_protection_mask) { | 687 uint32_t output_protection_mask) { |
| 689 NOTIMPLEMENTED(); | 688 NOTIMPLEMENTED(); |
| 690 }; | 689 }; |
| 691 | 690 |
| 692 void ClearKeyCdm::LoadLoadableSession() { | 691 void ClearKeyCdm::LoadLoadableSession() { |
| 693 std::string jwk_set = GenerateJWKSet(kLoadableSessionKey, | 692 std::string jwk_set = GenerateJWKSet(kLoadableSessionKey, |
| 694 sizeof(kLoadableSessionKey), | 693 sizeof(kLoadableSessionKey), |
| 695 kLoadableSessionKeyId, | 694 kLoadableSessionKeyId, |
| 696 sizeof(kLoadableSessionKeyId) - 1); | 695 sizeof(kLoadableSessionKeyId) - 1); |
| 697 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( | 696 std::unique_ptr<media::SimpleCdmPromise> promise( |
| 698 base::Bind(&ClearKeyCdm::OnLoadSessionUpdated, base::Unretained(this)), | 697 new media::CdmCallbackPromise<>( |
| 699 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), | 698 base::Bind(&ClearKeyCdm::OnLoadSessionUpdated, |
| 700 promise_id_for_emulated_loadsession_))); | 699 base::Unretained(this)), |
| 700 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), |
| 701 promise_id_for_emulated_loadsession_))); |
| 701 decryptor_->UpdateSession( | 702 decryptor_->UpdateSession( |
| 702 session_id_for_emulated_loadsession_, | 703 session_id_for_emulated_loadsession_, |
| 703 std::vector<uint8_t>(jwk_set.begin(), jwk_set.end()), std::move(promise)); | 704 std::vector<uint8_t>(jwk_set.begin(), jwk_set.end()), std::move(promise)); |
| 704 } | 705 } |
| 705 | 706 |
| 706 void ClearKeyCdm::OnSessionMessage(const std::string& session_id, | 707 void ClearKeyCdm::OnSessionMessage(const std::string& session_id, |
| 707 MediaKeys::MessageType message_type, | 708 MediaKeys::MessageType message_type, |
| 708 const std::vector<uint8_t>& message, | 709 const std::vector<uint8_t>& message, |
| 709 const GURL& legacy_destination_url) { | 710 const GURL& legacy_destination_url) { |
| 710 DVLOG(1) << "OnSessionMessage: " << message.size(); | 711 DVLOG(1) << "OnSessionMessage: " << message.size(); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 void ClearKeyCdm::OnFileIOTestComplete(bool success) { | 904 void ClearKeyCdm::OnFileIOTestComplete(bool success) { |
| 904 DVLOG(1) << __FUNCTION__ << ": " << success; | 905 DVLOG(1) << __FUNCTION__ << ": " << success; |
| 905 std::string message = GetFileIOTestResultMessage(success); | 906 std::string message = GetFileIOTestResultMessage(success); |
| 906 host_->OnSessionMessage(last_session_id_.data(), last_session_id_.length(), | 907 host_->OnSessionMessage(last_session_id_.data(), last_session_id_.length(), |
| 907 cdm::kLicenseRequest, message.data(), | 908 cdm::kLicenseRequest, message.data(), |
| 908 message.length(), NULL, 0); | 909 message.length(), NULL, 0); |
| 909 file_io_test_runner_.reset(); | 910 file_io_test_runner_.reset(); |
| 910 } | 911 } |
| 911 | 912 |
| 912 } // namespace media | 913 } // namespace media |
| OLD | NEW |