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 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
16 #include "media/base/cdm_callback_promise.h" | 16 #include "media/base/cdm_callback_promise.h" |
17 #include "media/base/cdm_key_information.h" | 17 #include "media/base/cdm_key_information.h" |
18 #include "media/base/decoder_buffer.h" | 18 #include "media/base/decoder_buffer.h" |
19 #include "media/base/decrypt_config.h" | 19 #include "media/base/decrypt_config.h" |
20 #include "media/base/key_systems.h" | 20 #include "media/base/key_systems.h" |
21 #include "media/cdm/json_web_key.h" | 21 #include "media/cdm/json_web_key.h" |
22 #include "media/cdm/ppapi/cdm_file_io_test.h" | 22 #include "media/cdm/ppapi/cdm_file_io_test.h" |
23 #include "media/cdm/ppapi/external_clear_key/cdm_video_decoder.h" | 23 #include "media/cdm/ppapi/external_clear_key/cdm_video_decoder.h" |
24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
25 | 25 |
26 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) | 26 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) |
27 #include "base/basictypes.h" | 27 const int64_t kNoTimestamp = INT64_t_MIN; |
DaleCurtis
2015/11/25 18:52:25
INT64_T_MIN?
Avi (use Gerrit)
2015/11/25 19:03:22
Fixed; d'oh.
| |
28 const int64 kNoTimestamp = kint64min; | |
29 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 28 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
30 | 29 |
31 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) | 30 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) |
32 #include "base/at_exit.h" | 31 #include "base/at_exit.h" |
33 #include "base/files/file_path.h" | 32 #include "base/files/file_path.h" |
34 #include "base/path_service.h" | 33 #include "base/path_service.h" |
35 #include "media/base/media.h" | 34 #include "media/base/media.h" |
36 #include "media/cdm/ppapi/external_clear_key/ffmpeg_cdm_audio_decoder.h" | 35 #include "media/cdm/ppapi/external_clear_key/ffmpeg_cdm_audio_decoder.h" |
37 #include "media/cdm/ppapi/external_clear_key/ffmpeg_cdm_video_decoder.h" | 36 #include "media/cdm/ppapi/external_clear_key/ffmpeg_cdm_video_decoder.h" |
38 | 37 |
(...skipping 24 matching lines...) Expand all Loading... | |
63 "org.chromium.externalclearkey.decryptonly"; | 62 "org.chromium.externalclearkey.decryptonly"; |
64 const char kExternalClearKeyFileIOTestKeySystem[] = | 63 const char kExternalClearKeyFileIOTestKeySystem[] = |
65 "org.chromium.externalclearkey.fileiotest"; | 64 "org.chromium.externalclearkey.fileiotest"; |
66 const char kExternalClearKeyCrashKeySystem[] = | 65 const char kExternalClearKeyCrashKeySystem[] = |
67 "org.chromium.externalclearkey.crash"; | 66 "org.chromium.externalclearkey.crash"; |
68 | 67 |
69 // Constants for the enumalted session that can be loaded by LoadSession(). | 68 // Constants for the enumalted session that can be loaded by LoadSession(). |
70 // These constants need to be in sync with | 69 // These constants need to be in sync with |
71 // chrome/test/data/media/encrypted_media_utils.js | 70 // chrome/test/data/media/encrypted_media_utils.js |
72 const char kLoadableSessionId[] = "LoadableSession"; | 71 const char kLoadableSessionId[] = "LoadableSession"; |
73 const uint8 kLoadableSessionKeyId[] = "0123456789012345"; | 72 const uint8_t kLoadableSessionKeyId[] = "0123456789012345"; |
74 const uint8 kLoadableSessionKey[] = | 73 const uint8_t kLoadableSessionKey[] = {0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, |
75 {0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b, | 74 0xd2, 0x7b, 0x68, 0xef, 0x12, 0x2a, |
76 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c}; | 75 0xfc, 0xe4, 0xae, 0x3c}; |
77 | 76 |
78 const int64 kSecondsPerMinute = 60; | 77 const int64_t kSecondsPerMinute = 60; |
79 const int64 kMsPerSecond = 1000; | 78 const int64_t kMsPerSecond = 1000; |
80 const int64 kInitialTimerDelayMs = 200; | 79 const int64_t kInitialTimerDelayMs = 200; |
81 const int64 kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; | 80 const int64_t kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; |
82 // Renewal message header. For prefixed EME, if a key message starts with | 81 // Renewal message header. For prefixed EME, if a key message starts with |
83 // |kRenewalHeader|, it's a renewal message. Otherwise, it's a key request. | 82 // |kRenewalHeader|, it's a renewal message. Otherwise, it's a key request. |
84 // FIXME(jrummell): Remove this once prefixed EME goes away. | 83 // FIXME(jrummell): Remove this once prefixed EME goes away. |
85 const char kRenewalHeader[] = "RENEWAL"; | 84 const char kRenewalHeader[] = "RENEWAL"; |
86 // CDM file IO test result header. | 85 // CDM file IO test result header. |
87 const char kFileIOTestResultHeader[] = "FILEIOTESTRESULT"; | 86 const char kFileIOTestResultHeader[] = "FILEIOTESTRESULT"; |
88 | 87 |
89 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is | 88 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is |
90 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. | 89 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. |
91 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( | 90 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 | 281 |
283 ClearKeyCdm::~ClearKeyCdm() {} | 282 ClearKeyCdm::~ClearKeyCdm() {} |
284 | 283 |
285 void ClearKeyCdm::Initialize(bool /* allow_distinctive_identifier */, | 284 void ClearKeyCdm::Initialize(bool /* allow_distinctive_identifier */, |
286 bool /* allow_persistent_state */) { | 285 bool /* allow_persistent_state */) { |
287 // Implementation doesn't use distinctive identifier nor save persistent data, | 286 // Implementation doesn't use distinctive identifier nor save persistent data, |
288 // so nothing to do with these values. | 287 // so nothing to do with these values. |
289 } | 288 } |
290 | 289 |
291 void ClearKeyCdm::CreateSessionAndGenerateRequest( | 290 void ClearKeyCdm::CreateSessionAndGenerateRequest( |
292 uint32 promise_id, | 291 uint32_t promise_id, |
293 cdm::SessionType session_type, | 292 cdm::SessionType session_type, |
294 cdm::InitDataType init_data_type, | 293 cdm::InitDataType init_data_type, |
295 const uint8* init_data, | 294 const uint8_t* init_data, |
296 uint32 init_data_size) { | 295 uint32_t init_data_size) { |
297 DVLOG(1) << __FUNCTION__; | 296 DVLOG(1) << __FUNCTION__; |
298 | 297 |
299 scoped_ptr<media::NewSessionCdmPromise> promise( | 298 scoped_ptr<media::NewSessionCdmPromise> promise( |
300 new media::CdmCallbackPromise<std::string>( | 299 new media::CdmCallbackPromise<std::string>( |
301 base::Bind(&ClearKeyCdm::OnSessionCreated, | 300 base::Bind(&ClearKeyCdm::OnSessionCreated, |
302 base::Unretained(this), | 301 base::Unretained(this), |
303 promise_id), | 302 promise_id), |
304 base::Bind(&ClearKeyCdm::OnPromiseFailed, | 303 base::Bind(&ClearKeyCdm::OnPromiseFailed, |
305 base::Unretained(this), | 304 base::Unretained(this), |
306 promise_id))); | 305 promise_id))); |
307 decryptor_->CreateSessionAndGenerateRequest( | 306 decryptor_->CreateSessionAndGenerateRequest( |
308 ConvertSessionType(session_type), ConvertInitDataType(init_data_type), | 307 ConvertSessionType(session_type), ConvertInitDataType(init_data_type), |
309 std::vector<uint8_t>(init_data, init_data + init_data_size), | 308 std::vector<uint8_t>(init_data, init_data + init_data_size), |
310 promise.Pass()); | 309 promise.Pass()); |
311 | 310 |
312 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) | 311 if (key_system_ == kExternalClearKeyFileIOTestKeySystem) |
313 StartFileIOTest(); | 312 StartFileIOTest(); |
314 } | 313 } |
315 | 314 |
316 // Loads a emulated stored session. Currently only |kLoadableSessionId| | 315 // Loads a emulated stored session. Currently only |kLoadableSessionId| |
317 // (containing a |kLoadableSessionKey| for |kLoadableSessionKeyId|) is | 316 // (containing a |kLoadableSessionKey| for |kLoadableSessionKeyId|) is |
318 // supported. | 317 // supported. |
319 void ClearKeyCdm::LoadSession(uint32 promise_id, | 318 void ClearKeyCdm::LoadSession(uint32_t promise_id, |
320 cdm::SessionType session_type, | 319 cdm::SessionType session_type, |
321 const char* session_id, | 320 const char* session_id, |
322 uint32_t session_id_length) { | 321 uint32_t session_id_length) { |
323 DVLOG(1) << __FUNCTION__; | 322 DVLOG(1) << __FUNCTION__; |
324 DCHECK_EQ(session_type, cdm::kPersistentLicense); | 323 DCHECK_EQ(session_type, cdm::kPersistentLicense); |
325 | 324 |
326 if (std::string(kLoadableSessionId) != | 325 if (std::string(kLoadableSessionId) != |
327 std::string(session_id, session_id_length)) { | 326 std::string(session_id, session_id_length)) { |
328 host_->OnResolveNewSessionPromise(promise_id, nullptr, 0); | 327 host_->OnResolveNewSessionPromise(promise_id, nullptr, 0); |
329 return; | 328 return; |
330 } | 329 } |
331 | 330 |
332 // Only allowed to successfully load this session once. | 331 // Only allowed to successfully load this session once. |
333 DCHECK(session_id_for_emulated_loadsession_.empty()); | 332 DCHECK(session_id_for_emulated_loadsession_.empty()); |
334 | 333 |
335 scoped_ptr<media::NewSessionCdmPromise> promise( | 334 scoped_ptr<media::NewSessionCdmPromise> promise( |
336 new media::CdmCallbackPromise<std::string>( | 335 new media::CdmCallbackPromise<std::string>( |
337 base::Bind(&ClearKeyCdm::OnSessionLoaded, | 336 base::Bind(&ClearKeyCdm::OnSessionLoaded, |
338 base::Unretained(this), | 337 base::Unretained(this), |
339 promise_id), | 338 promise_id), |
340 base::Bind(&ClearKeyCdm::OnPromiseFailed, | 339 base::Bind(&ClearKeyCdm::OnPromiseFailed, |
341 base::Unretained(this), | 340 base::Unretained(this), |
342 promise_id))); | 341 promise_id))); |
343 decryptor_->CreateSessionAndGenerateRequest( | 342 decryptor_->CreateSessionAndGenerateRequest( |
344 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 343 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
345 std::vector<uint8_t>(), promise.Pass()); | 344 std::vector<uint8_t>(), promise.Pass()); |
346 } | 345 } |
347 | 346 |
348 void ClearKeyCdm::UpdateSession(uint32 promise_id, | 347 void ClearKeyCdm::UpdateSession(uint32_t promise_id, |
349 const char* session_id, | 348 const char* session_id, |
350 uint32_t session_id_length, | 349 uint32_t session_id_length, |
351 const uint8* response, | 350 const uint8_t* response, |
352 uint32 response_size) { | 351 uint32_t response_size) { |
353 DVLOG(1) << __FUNCTION__; | 352 DVLOG(1) << __FUNCTION__; |
354 std::string web_session_str(session_id, session_id_length); | 353 std::string web_session_str(session_id, session_id_length); |
355 | 354 |
356 // If updating the loadable session, use the actual session id generated. | 355 // If updating the loadable session, use the actual session id generated. |
357 if (web_session_str == std::string(kLoadableSessionId)) | 356 if (web_session_str == std::string(kLoadableSessionId)) |
358 web_session_str = session_id_for_emulated_loadsession_; | 357 web_session_str = session_id_for_emulated_loadsession_; |
359 | 358 |
360 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( | 359 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( |
361 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), | 360 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), |
362 promise_id), | 361 promise_id), |
363 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), | 362 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), |
364 promise_id))); | 363 promise_id))); |
365 decryptor_->UpdateSession( | 364 decryptor_->UpdateSession( |
366 web_session_str, std::vector<uint8_t>(response, response + response_size), | 365 web_session_str, std::vector<uint8_t>(response, response + response_size), |
367 promise.Pass()); | 366 promise.Pass()); |
368 | 367 |
369 if (!renewal_timer_set_) { | 368 if (!renewal_timer_set_) { |
370 ScheduleNextRenewal(); | 369 ScheduleNextRenewal(); |
371 renewal_timer_set_ = true; | 370 renewal_timer_set_ = true; |
372 } | 371 } |
373 } | 372 } |
374 | 373 |
375 void ClearKeyCdm::CloseSession(uint32 promise_id, | 374 void ClearKeyCdm::CloseSession(uint32_t promise_id, |
376 const char* session_id, | 375 const char* session_id, |
377 uint32_t session_id_length) { | 376 uint32_t session_id_length) { |
378 DVLOG(1) << __FUNCTION__; | 377 DVLOG(1) << __FUNCTION__; |
379 std::string web_session_str(session_id, session_id_length); | 378 std::string web_session_str(session_id, session_id_length); |
380 | 379 |
381 // If closing the loadable session, use the actual session id generated. | 380 // If closing the loadable session, use the actual session id generated. |
382 if (web_session_str == std::string(kLoadableSessionId)) | 381 if (web_session_str == std::string(kLoadableSessionId)) |
383 web_session_str = session_id_for_emulated_loadsession_; | 382 web_session_str = session_id_for_emulated_loadsession_; |
384 | 383 |
385 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( | 384 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( |
386 base::Bind( | 385 base::Bind( |
387 &ClearKeyCdm::OnPromiseResolved, base::Unretained(this), promise_id), | 386 &ClearKeyCdm::OnPromiseResolved, base::Unretained(this), promise_id), |
388 base::Bind( | 387 base::Bind( |
389 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); | 388 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); |
390 decryptor_->CloseSession(web_session_str, promise.Pass()); | 389 decryptor_->CloseSession(web_session_str, promise.Pass()); |
391 } | 390 } |
392 | 391 |
393 void ClearKeyCdm::RemoveSession(uint32 promise_id, | 392 void ClearKeyCdm::RemoveSession(uint32_t promise_id, |
394 const char* session_id, | 393 const char* session_id, |
395 uint32_t session_id_length) { | 394 uint32_t session_id_length) { |
396 DVLOG(1) << __FUNCTION__; | 395 DVLOG(1) << __FUNCTION__; |
397 std::string web_session_str(session_id, session_id_length); | 396 std::string web_session_str(session_id, session_id_length); |
398 | 397 |
399 // RemoveSession only allowed for the loadable session. | 398 // RemoveSession only allowed for the loadable session. |
400 if (web_session_str == std::string(kLoadableSessionId)) { | 399 if (web_session_str == std::string(kLoadableSessionId)) { |
401 web_session_str = session_id_for_emulated_loadsession_; | 400 web_session_str = session_id_for_emulated_loadsession_; |
402 } else { | 401 } else { |
403 // TODO(jrummell): This should be a DCHECK once blink does the proper | 402 // TODO(jrummell): This should be a DCHECK once blink does the proper |
404 // checks. | 403 // checks. |
405 std::string message("Not supported for non-persistent sessions."); | 404 std::string message("Not supported for non-persistent sessions."); |
406 host_->OnRejectPromise(promise_id, | 405 host_->OnRejectPromise(promise_id, |
407 cdm::kInvalidAccessError, | 406 cdm::kInvalidAccessError, |
408 0, | 407 0, |
409 message.data(), | 408 message.data(), |
410 message.length()); | 409 message.length()); |
411 return; | 410 return; |
412 } | 411 } |
413 | 412 |
414 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( | 413 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( |
415 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), | 414 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), |
416 promise_id), | 415 promise_id), |
417 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), | 416 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), |
418 promise_id))); | 417 promise_id))); |
419 decryptor_->RemoveSession(web_session_str, promise.Pass()); | 418 decryptor_->RemoveSession(web_session_str, promise.Pass()); |
420 } | 419 } |
421 | 420 |
422 void ClearKeyCdm::SetServerCertificate(uint32 promise_id, | 421 void ClearKeyCdm::SetServerCertificate(uint32_t promise_id, |
423 const uint8_t* server_certificate_data, | 422 const uint8_t* server_certificate_data, |
424 uint32_t server_certificate_data_size) { | 423 uint32_t server_certificate_data_size) { |
425 // ClearKey doesn't use a server certificate. | 424 // ClearKey doesn't use a server certificate. |
426 host_->OnResolvePromise(promise_id); | 425 host_->OnResolvePromise(promise_id); |
427 } | 426 } |
428 | 427 |
429 void ClearKeyCdm::TimerExpired(void* context) { | 428 void ClearKeyCdm::TimerExpired(void* context) { |
430 if (context == &session_id_for_emulated_loadsession_) { | 429 if (context == &session_id_for_emulated_loadsession_) { |
431 LoadLoadableSession(); | 430 LoadLoadableSession(); |
432 return; | 431 return; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 int32_t size = 0; | 609 int32_t size = 0; |
611 int64_t timestamp = 0; | 610 int64_t timestamp = 0; |
612 if (!buffer->end_of_stream()) { | 611 if (!buffer->end_of_stream()) { |
613 data = buffer->data(); | 612 data = buffer->data(); |
614 size = buffer->data_size(); | 613 size = buffer->data_size(); |
615 timestamp = encrypted_buffer.timestamp; | 614 timestamp = encrypted_buffer.timestamp; |
616 } | 615 } |
617 | 616 |
618 return audio_decoder_->DecodeBuffer(data, size, timestamp, audio_frames); | 617 return audio_decoder_->DecodeBuffer(data, size, timestamp, audio_frames); |
619 #elif defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) | 618 #elif defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) |
620 int64 timestamp_in_microseconds = kNoTimestamp; | 619 int64_t timestamp_in_microseconds = kNoTimestamp; |
621 if (!buffer->end_of_stream()) { | 620 if (!buffer->end_of_stream()) { |
622 timestamp_in_microseconds = buffer->GetTimestamp().InMicroseconds(); | 621 timestamp_in_microseconds = buffer->GetTimestamp().InMicroseconds(); |
623 DCHECK(timestamp_in_microseconds != kNoTimestamp); | 622 DCHECK(timestamp_in_microseconds != kNoTimestamp); |
624 } | 623 } |
625 return GenerateFakeAudioFrames(timestamp_in_microseconds, audio_frames); | 624 return GenerateFakeAudioFrames(timestamp_in_microseconds, audio_frames); |
626 #else | 625 #else |
627 return cdm::kSuccess; | 626 return cdm::kSuccess; |
628 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 627 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
629 } | 628 } |
630 | 629 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
699 base::Bind(&ClearKeyCdm::OnLoadSessionUpdated, base::Unretained(this)), | 698 base::Bind(&ClearKeyCdm::OnLoadSessionUpdated, base::Unretained(this)), |
700 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), | 699 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), |
701 promise_id_for_emulated_loadsession_))); | 700 promise_id_for_emulated_loadsession_))); |
702 decryptor_->UpdateSession( | 701 decryptor_->UpdateSession( |
703 session_id_for_emulated_loadsession_, | 702 session_id_for_emulated_loadsession_, |
704 std::vector<uint8_t>(jwk_set.begin(), jwk_set.end()), promise.Pass()); | 703 std::vector<uint8_t>(jwk_set.begin(), jwk_set.end()), promise.Pass()); |
705 } | 704 } |
706 | 705 |
707 void ClearKeyCdm::OnSessionMessage(const std::string& session_id, | 706 void ClearKeyCdm::OnSessionMessage(const std::string& session_id, |
708 MediaKeys::MessageType message_type, | 707 MediaKeys::MessageType message_type, |
709 const std::vector<uint8>& message, | 708 const std::vector<uint8_t>& message, |
710 const GURL& legacy_destination_url) { | 709 const GURL& legacy_destination_url) { |
711 DVLOG(1) << "OnSessionMessage: " << message.size(); | 710 DVLOG(1) << "OnSessionMessage: " << message.size(); |
712 | 711 |
713 // Ignore the message when we are waiting to update the loadable session. | 712 // Ignore the message when we are waiting to update the loadable session. |
714 if (session_id == session_id_for_emulated_loadsession_) | 713 if (session_id == session_id_for_emulated_loadsession_) |
715 return; | 714 return; |
716 | 715 |
717 // OnSessionMessage() only called during CreateSession(), so no promise | 716 // OnSessionMessage() only called during CreateSession(), so no promise |
718 // involved (OnSessionCreated() called to resolve the CreateSession() | 717 // involved (OnSessionCreated() called to resolve the CreateSession() |
719 // promise). | 718 // promise). |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 vector_as_array(&keys_vector), keys_vector.size()); | 750 vector_as_array(&keys_vector), keys_vector.size()); |
752 } | 751 } |
753 | 752 |
754 void ClearKeyCdm::OnSessionClosed(const std::string& session_id) { | 753 void ClearKeyCdm::OnSessionClosed(const std::string& session_id) { |
755 std::string new_session_id = session_id; | 754 std::string new_session_id = session_id; |
756 if (new_session_id == session_id_for_emulated_loadsession_) | 755 if (new_session_id == session_id_for_emulated_loadsession_) |
757 new_session_id = std::string(kLoadableSessionId); | 756 new_session_id = std::string(kLoadableSessionId); |
758 host_->OnSessionClosed(new_session_id.data(), new_session_id.length()); | 757 host_->OnSessionClosed(new_session_id.data(), new_session_id.length()); |
759 } | 758 } |
760 | 759 |
761 void ClearKeyCdm::OnSessionCreated(uint32 promise_id, | 760 void ClearKeyCdm::OnSessionCreated(uint32_t promise_id, |
762 const std::string& session_id) { | 761 const std::string& session_id) { |
763 // Save the latest session ID for renewal and file IO test messages. | 762 // Save the latest session ID for renewal and file IO test messages. |
764 last_session_id_ = session_id; | 763 last_session_id_ = session_id; |
765 | 764 |
766 host_->OnResolveNewSessionPromise(promise_id, session_id.data(), | 765 host_->OnResolveNewSessionPromise(promise_id, session_id.data(), |
767 session_id.length()); | 766 session_id.length()); |
768 } | 767 } |
769 | 768 |
770 void ClearKeyCdm::OnSessionLoaded(uint32 promise_id, | 769 void ClearKeyCdm::OnSessionLoaded(uint32_t promise_id, |
771 const std::string& session_id) { | 770 const std::string& session_id) { |
772 // Save the latest session ID for renewal and file IO test messages. | 771 // Save the latest session ID for renewal and file IO test messages. |
773 last_session_id_ = session_id; | 772 last_session_id_ = session_id; |
774 | 773 |
775 // |decryptor_| created some session as |session_id|, but going forward | 774 // |decryptor_| created some session as |session_id|, but going forward |
776 // we need to map that to |kLoadableSessionId|, as that is what callers | 775 // we need to map that to |kLoadableSessionId|, as that is what callers |
777 // expect. | 776 // expect. |
778 session_id_for_emulated_loadsession_ = session_id; | 777 session_id_for_emulated_loadsession_ = session_id; |
779 | 778 |
780 // Delay LoadLoadableSession() to test the case where Decrypt*() calls are | 779 // Delay LoadLoadableSession() to test the case where Decrypt*() calls are |
781 // made before the session is fully loaded. | 780 // made before the session is fully loaded. |
782 const int64 kDelayToLoadSessionMs = 500; | 781 const int64_t kDelayToLoadSessionMs = 500; |
783 | 782 |
784 // Defer resolving the promise until the session is loaded. | 783 // Defer resolving the promise until the session is loaded. |
785 promise_id_for_emulated_loadsession_ = promise_id; | 784 promise_id_for_emulated_loadsession_ = promise_id; |
786 | 785 |
787 // Use the address of |session_id_for_emulated_loadsession_| as the timer | 786 // Use the address of |session_id_for_emulated_loadsession_| as the timer |
788 // context so that we can call LoadLoadableSession() when the timer expires. | 787 // context so that we can call LoadLoadableSession() when the timer expires. |
789 host_->SetTimer(kDelayToLoadSessionMs, &session_id_for_emulated_loadsession_); | 788 host_->SetTimer(kDelayToLoadSessionMs, &session_id_for_emulated_loadsession_); |
790 } | 789 } |
791 | 790 |
792 void ClearKeyCdm::OnLoadSessionUpdated() { | 791 void ClearKeyCdm::OnLoadSessionUpdated() { |
(...skipping 18 matching lines...) Expand all Loading... | |
811 keys_info.swap(keys_info_for_emulated_loadsession_); | 810 keys_info.swap(keys_info_for_emulated_loadsession_); |
812 has_received_keys_change_event_for_emulated_loadsession_ = false; | 811 has_received_keys_change_event_for_emulated_loadsession_ = false; |
813 DCHECK(!keys_vector.empty()); | 812 DCHECK(!keys_vector.empty()); |
814 ConvertCdmKeysInfo(keys_info.get(), &keys_vector); | 813 ConvertCdmKeysInfo(keys_info.get(), &keys_vector); |
815 host_->OnSessionKeysChange( | 814 host_->OnSessionKeysChange( |
816 kLoadableSessionId, strlen(kLoadableSessionId), !keys_vector.empty(), | 815 kLoadableSessionId, strlen(kLoadableSessionId), !keys_vector.empty(), |
817 vector_as_array(&keys_vector), keys_vector.size()); | 816 vector_as_array(&keys_vector), keys_vector.size()); |
818 } | 817 } |
819 } | 818 } |
820 | 819 |
821 void ClearKeyCdm::OnPromiseResolved(uint32 promise_id) { | 820 void ClearKeyCdm::OnPromiseResolved(uint32_t promise_id) { |
822 host_->OnResolvePromise(promise_id); | 821 host_->OnResolvePromise(promise_id); |
823 } | 822 } |
824 | 823 |
825 void ClearKeyCdm::OnPromiseFailed(uint32 promise_id, | 824 void ClearKeyCdm::OnPromiseFailed(uint32_t promise_id, |
826 MediaKeys::Exception exception_code, | 825 MediaKeys::Exception exception_code, |
827 uint32 system_code, | 826 uint32_t system_code, |
828 const std::string& error_message) { | 827 const std::string& error_message) { |
829 host_->OnRejectPromise(promise_id, | 828 host_->OnRejectPromise(promise_id, |
830 ConvertException(exception_code), | 829 ConvertException(exception_code), |
831 system_code, | 830 system_code, |
832 error_message.data(), | 831 error_message.data(), |
833 error_message.length()); | 832 error_message.length()); |
834 } | 833 } |
835 | 834 |
836 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) | 835 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) |
837 int64 ClearKeyCdm::CurrentTimeStampInMicroseconds() const { | 836 int64_t ClearKeyCdm::CurrentTimeStampInMicroseconds() const { |
838 return output_timestamp_base_in_microseconds_ + | 837 return output_timestamp_base_in_microseconds_ + |
839 base::Time::kMicrosecondsPerSecond * | 838 base::Time::kMicrosecondsPerSecond * |
840 total_samples_generated_ / samples_per_second_; | 839 total_samples_generated_ / samples_per_second_; |
841 } | 840 } |
842 | 841 |
843 int ClearKeyCdm::GenerateFakeAudioFramesFromDuration( | 842 int ClearKeyCdm::GenerateFakeAudioFramesFromDuration( |
844 int64 duration_in_microseconds, | 843 int64_t duration_in_microseconds, |
845 cdm::AudioFrames* audio_frames) const { | 844 cdm::AudioFrames* audio_frames) const { |
846 int64 samples_to_generate = static_cast<double>(samples_per_second_) * | 845 int64_t samples_to_generate = static_cast<double>(samples_per_second_) * |
847 duration_in_microseconds / base::Time::kMicrosecondsPerSecond + 0.5; | 846 duration_in_microseconds / |
847 base::Time::kMicrosecondsPerSecond + | |
848 0.5; | |
848 if (samples_to_generate <= 0) | 849 if (samples_to_generate <= 0) |
849 return 0; | 850 return 0; |
850 | 851 |
851 int64 bytes_per_sample = channel_count_ * bits_per_channel_ / 8; | 852 int64_t bytes_per_sample = channel_count_ * bits_per_channel_ / 8; |
852 // |frame_size| must be a multiple of |bytes_per_sample|. | 853 // |frame_size| must be a multiple of |bytes_per_sample|. |
853 int64 frame_size = bytes_per_sample * samples_to_generate; | 854 int64_t frame_size = bytes_per_sample * samples_to_generate; |
854 | 855 |
855 int64 timestamp = CurrentTimeStampInMicroseconds(); | 856 int64_t timestamp = CurrentTimeStampInMicroseconds(); |
856 | 857 |
857 const int kHeaderSize = sizeof(timestamp) + sizeof(frame_size); | 858 const int kHeaderSize = sizeof(timestamp) + sizeof(frame_size); |
858 audio_frames->SetFrameBuffer(host_->Allocate(kHeaderSize + frame_size)); | 859 audio_frames->SetFrameBuffer(host_->Allocate(kHeaderSize + frame_size)); |
859 uint8_t* data = audio_frames->FrameBuffer()->Data(); | 860 uint8_t* data = audio_frames->FrameBuffer()->Data(); |
860 | 861 |
861 memcpy(data, ×tamp, sizeof(timestamp)); | 862 memcpy(data, ×tamp, sizeof(timestamp)); |
862 data += sizeof(timestamp); | 863 data += sizeof(timestamp); |
863 memcpy(data, &frame_size, sizeof(frame_size)); | 864 memcpy(data, &frame_size, sizeof(frame_size)); |
864 data += sizeof(frame_size); | 865 data += sizeof(frame_size); |
865 // You won't hear anything because we have all zeros here. But the video | 866 // You won't hear anything because we have all zeros here. But the video |
866 // should play just fine! | 867 // should play just fine! |
867 memset(data, 0, frame_size); | 868 memset(data, 0, frame_size); |
868 | 869 |
869 audio_frames->FrameBuffer()->SetSize(kHeaderSize + frame_size); | 870 audio_frames->FrameBuffer()->SetSize(kHeaderSize + frame_size); |
870 | 871 |
871 return samples_to_generate; | 872 return samples_to_generate; |
872 } | 873 } |
873 | 874 |
874 cdm::Status ClearKeyCdm::GenerateFakeAudioFrames( | 875 cdm::Status ClearKeyCdm::GenerateFakeAudioFrames( |
875 int64 timestamp_in_microseconds, | 876 int64_t timestamp_in_microseconds, |
876 cdm::AudioFrames* audio_frames) { | 877 cdm::AudioFrames* audio_frames) { |
877 if (timestamp_in_microseconds == kNoTimestamp) | 878 if (timestamp_in_microseconds == kNoTimestamp) |
878 return cdm::kNeedMoreData; | 879 return cdm::kNeedMoreData; |
879 | 880 |
880 // Return kNeedMoreData for the first frame because duration is unknown. | 881 // Return kNeedMoreData for the first frame because duration is unknown. |
881 if (output_timestamp_base_in_microseconds_ == kNoTimestamp) { | 882 if (output_timestamp_base_in_microseconds_ == kNoTimestamp) { |
882 output_timestamp_base_in_microseconds_ = timestamp_in_microseconds; | 883 output_timestamp_base_in_microseconds_ = timestamp_in_microseconds; |
883 return cdm::kNeedMoreData; | 884 return cdm::kNeedMoreData; |
884 } | 885 } |
885 | 886 |
(...skipping 16 matching lines...) Expand all Loading... | |
902 void ClearKeyCdm::OnFileIOTestComplete(bool success) { | 903 void ClearKeyCdm::OnFileIOTestComplete(bool success) { |
903 DVLOG(1) << __FUNCTION__ << ": " << success; | 904 DVLOG(1) << __FUNCTION__ << ": " << success; |
904 std::string message = GetFileIOTestResultMessage(success); | 905 std::string message = GetFileIOTestResultMessage(success); |
905 host_->OnSessionMessage(last_session_id_.data(), last_session_id_.length(), | 906 host_->OnSessionMessage(last_session_id_.data(), last_session_id_.length(), |
906 cdm::kLicenseRequest, message.data(), | 907 cdm::kLicenseRequest, message.data(), |
907 message.length(), NULL, 0); | 908 message.length(), NULL, 0); |
908 file_io_test_runner_.reset(); | 909 file_io_test_runner_.reset(); |
909 } | 910 } |
910 | 911 |
911 } // namespace media | 912 } // namespace media |
OLD | NEW |