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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 static bool g_ffmpeg_lib_initialized = InitializeFFmpegLibraries(); | 55 static bool g_ffmpeg_lib_initialized = InitializeFFmpegLibraries(); |
56 | 56 |
57 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER | 57 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER |
58 | 58 |
59 const char kClearKeyCdmVersion[] = "0.1.0.1"; | 59 const char kClearKeyCdmVersion[] = "0.1.0.1"; |
60 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; | 60 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; |
61 | 61 |
62 // Variants of External Clear Key key system to test different scenarios. | 62 // Variants of External Clear Key key system to test different scenarios. |
63 const char kExternalClearKeyDecryptOnlyKeySystem[] = | 63 const char kExternalClearKeyDecryptOnlyKeySystem[] = |
64 "org.chromium.externalclearkey.decryptonly"; | 64 "org.chromium.externalclearkey.decryptonly"; |
| 65 const char kExternalClearKeyRenewalKeySystem[] = |
| 66 "org.chromium.externalclearkey.renewal"; |
65 const char kExternalClearKeyFileIOTestKeySystem[] = | 67 const char kExternalClearKeyFileIOTestKeySystem[] = |
66 "org.chromium.externalclearkey.fileiotest"; | 68 "org.chromium.externalclearkey.fileiotest"; |
67 const char kExternalClearKeyOutputProtectionTestKeySystem[] = | 69 const char kExternalClearKeyOutputProtectionTestKeySystem[] = |
68 "org.chromium.externalclearkey.outputprotectiontest"; | 70 "org.chromium.externalclearkey.outputprotectiontest"; |
69 const char kExternalClearKeyCrashKeySystem[] = | 71 const char kExternalClearKeyCrashKeySystem[] = |
70 "org.chromium.externalclearkey.crash"; | 72 "org.chromium.externalclearkey.crash"; |
71 | 73 |
72 // Constants for the enumalted session that can be loaded by LoadSession(). | 74 // Constants for the enumalted session that can be loaded by LoadSession(). |
73 // These constants need to be in sync with | 75 // These constants need to be in sync with |
74 // chrome/test/data/media/encrypted_media_utils.js | 76 // chrome/test/data/media/encrypted_media_utils.js |
75 const char kLoadableSessionId[] = "LoadableSession"; | 77 const char kLoadableSessionId[] = "LoadableSession"; |
76 const uint8_t kLoadableSessionKeyId[] = "0123456789012345"; | 78 const uint8_t kLoadableSessionKeyId[] = "0123456789012345"; |
77 const uint8_t kLoadableSessionKey[] = {0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, | 79 const uint8_t kLoadableSessionKey[] = {0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, |
78 0xd2, 0x7b, 0x68, 0xef, 0x12, 0x2a, | 80 0xd2, 0x7b, 0x68, 0xef, 0x12, 0x2a, |
79 0xfc, 0xe4, 0xae, 0x3c}; | 81 0xfc, 0xe4, 0xae, 0x3c}; |
80 | 82 |
81 const int64_t kSecondsPerMinute = 60; | 83 const int64_t kSecondsPerMinute = 60; |
82 const int64_t kMsPerSecond = 1000; | 84 const int64_t kMsPerSecond = 1000; |
83 const int64_t kInitialTimerDelayMs = 200; | 85 const int64_t kInitialTimerDelayMs = 200; |
84 const int64_t kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; | 86 const int64_t kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; |
85 // Renewal message header. For prefixed EME, if a key message starts with | |
86 // |kRenewalHeader|, it's a renewal message. Otherwise, it's a key request. | |
87 // FIXME(jrummell): Remove this once prefixed EME goes away. | |
88 const char kRenewalHeader[] = "RENEWAL"; | |
89 | 87 |
90 // CDM unit test result header. Must be in sync with UNIT_TEST_RESULT_HEADER in | 88 // CDM unit test result header. Must be in sync with UNIT_TEST_RESULT_HEADER in |
91 // media/test/data/eme_player_js/globals.js. | 89 // media/test/data/eme_player_js/globals.js. |
92 const char kUnitTestResultHeader[] = "UNIT_TEST_RESULT"; | 90 const char kUnitTestResultHeader[] = "UNIT_TEST_RESULT"; |
93 | 91 |
94 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is | 92 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is |
95 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. | 93 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. |
96 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( | 94 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( |
97 const cdm::InputBuffer& input_buffer) { | 95 const cdm::InputBuffer& input_buffer) { |
98 if (!input_buffer.data) { | 96 if (!input_buffer.data) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 228 |
231 void* CreateCdmInstance(int cdm_interface_version, | 229 void* CreateCdmInstance(int cdm_interface_version, |
232 const char* key_system, uint32_t key_system_size, | 230 const char* key_system, uint32_t key_system_size, |
233 GetCdmHostFunc get_cdm_host_func, | 231 GetCdmHostFunc get_cdm_host_func, |
234 void* user_data) { | 232 void* user_data) { |
235 DVLOG(1) << "CreateCdmInstance()"; | 233 DVLOG(1) << "CreateCdmInstance()"; |
236 | 234 |
237 std::string key_system_string(key_system, key_system_size); | 235 std::string key_system_string(key_system, key_system_size); |
238 if (key_system_string != kExternalClearKeyKeySystem && | 236 if (key_system_string != kExternalClearKeyKeySystem && |
239 key_system_string != kExternalClearKeyDecryptOnlyKeySystem && | 237 key_system_string != kExternalClearKeyDecryptOnlyKeySystem && |
| 238 key_system_string != kExternalClearKeyRenewalKeySystem && |
240 key_system_string != kExternalClearKeyFileIOTestKeySystem && | 239 key_system_string != kExternalClearKeyFileIOTestKeySystem && |
241 key_system_string != kExternalClearKeyOutputProtectionTestKeySystem && | 240 key_system_string != kExternalClearKeyOutputProtectionTestKeySystem && |
242 key_system_string != kExternalClearKeyCrashKeySystem) { | 241 key_system_string != kExternalClearKeyCrashKeySystem) { |
243 DVLOG(1) << "Unsupported key system:" << key_system_string; | 242 DVLOG(1) << "Unsupported key system:" << key_system_string; |
244 return NULL; | 243 return NULL; |
245 } | 244 } |
246 | 245 |
247 if (cdm_interface_version != media::ClearKeyCdmInterface::kVersion) | 246 if (cdm_interface_version != media::ClearKeyCdmInterface::kVersion) |
248 return NULL; | 247 return NULL; |
249 | 248 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 std::unique_ptr<media::SimpleCdmPromise> promise( | 370 std::unique_ptr<media::SimpleCdmPromise> promise( |
372 new media::CdmCallbackPromise<>( | 371 new media::CdmCallbackPromise<>( |
373 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), | 372 base::Bind(&ClearKeyCdm::OnPromiseResolved, base::Unretained(this), |
374 promise_id), | 373 promise_id), |
375 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), | 374 base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), |
376 promise_id))); | 375 promise_id))); |
377 decryptor_->UpdateSession( | 376 decryptor_->UpdateSession( |
378 web_session_str, std::vector<uint8_t>(response, response + response_size), | 377 web_session_str, std::vector<uint8_t>(response, response + response_size), |
379 std::move(promise)); | 378 std::move(promise)); |
380 | 379 |
381 if (!renewal_timer_set_) { | 380 if (key_system_ == kExternalClearKeyRenewalKeySystem && !renewal_timer_set_) { |
382 ScheduleNextRenewal(); | 381 ScheduleNextRenewal(); |
383 renewal_timer_set_ = true; | 382 renewal_timer_set_ = true; |
384 } | 383 } |
385 } | 384 } |
386 | 385 |
387 void ClearKeyCdm::CloseSession(uint32_t promise_id, | 386 void ClearKeyCdm::CloseSession(uint32_t promise_id, |
388 const char* session_id, | 387 const char* session_id, |
389 uint32_t session_id_length) { | 388 uint32_t session_id_length) { |
390 DVLOG(1) << __FUNCTION__; | 389 DVLOG(1) << __FUNCTION__; |
391 std::string web_session_str(session_id, session_id_length); | 390 std::string web_session_str(session_id, session_id_length); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 } | 651 } |
653 | 652 |
654 void ClearKeyCdm::Destroy() { | 653 void ClearKeyCdm::Destroy() { |
655 DVLOG(1) << "Destroy()"; | 654 DVLOG(1) << "Destroy()"; |
656 delete this; | 655 delete this; |
657 } | 656 } |
658 | 657 |
659 void ClearKeyCdm::ScheduleNextRenewal() { | 658 void ClearKeyCdm::ScheduleNextRenewal() { |
660 // Prepare the next renewal message and set timer. | 659 // Prepare the next renewal message and set timer. |
661 std::ostringstream msg_stream; | 660 std::ostringstream msg_stream; |
662 msg_stream << kRenewalHeader << " from ClearKey CDM set at time " | 661 msg_stream << "Renewal from ClearKey CDM set at time " |
663 << host_->GetCurrentWallTime() << "."; | 662 << host_->GetCurrentWallTime() << "."; |
664 next_renewal_message_ = msg_stream.str(); | 663 next_renewal_message_ = msg_stream.str(); |
665 | 664 |
666 host_->SetTimer(timer_delay_ms_, &next_renewal_message_[0]); | 665 host_->SetTimer(timer_delay_ms_, &next_renewal_message_[0]); |
667 | 666 |
668 // Use a smaller timer delay at start-up to facilitate testing. Increase the | 667 // Use a smaller timer delay at start-up to facilitate testing. Increase the |
669 // timer delay up to a limit to avoid message spam. | 668 // timer delay up to a limit to avoid message spam. |
670 if (timer_delay_ms_ < kMaxTimerDelayMs) | 669 if (timer_delay_ms_ < kMaxTimerDelayMs) |
671 timer_delay_ms_ = std::min(2 * timer_delay_ms_, kMaxTimerDelayMs); | 670 timer_delay_ms_ = std::min(2 * timer_delay_ms_, kMaxTimerDelayMs); |
672 } | 671 } |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 OnUnitTestComplete(success); | 955 OnUnitTestComplete(success); |
957 file_io_test_runner_.reset(); | 956 file_io_test_runner_.reset(); |
958 } | 957 } |
959 | 958 |
960 void ClearKeyCdm::StartOutputProtectionTest() { | 959 void ClearKeyCdm::StartOutputProtectionTest() { |
961 is_running_output_protection_test_ = true; | 960 is_running_output_protection_test_ = true; |
962 host_->QueryOutputProtectionStatus(); | 961 host_->QueryOutputProtectionStatus(); |
963 } | 962 } |
964 | 963 |
965 } // namespace media | 964 } // namespace media |
OLD | NEW |