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/clear_key_cdm.h" | 5 #include "media/cdm/ppapi/clear_key_cdm.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "media/base/decoder_buffer.h" | 16 #include "media/base/decoder_buffer.h" |
17 #include "media/base/decrypt_config.h" | 17 #include "media/base/decrypt_config.h" |
18 #include "media/cdm/ppapi/cdm_file_io_test.h" | |
18 #include "media/cdm/ppapi/cdm_video_decoder.h" | 19 #include "media/cdm/ppapi/cdm_video_decoder.h" |
19 | 20 |
20 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) | 21 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) |
21 #include "base/basictypes.h" | 22 #include "base/basictypes.h" |
22 const int64 kNoTimestamp = kint64min; | 23 const int64 kNoTimestamp = kint64min; |
23 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 24 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
24 | 25 |
25 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) | 26 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) |
26 #include "base/at_exit.h" | 27 #include "base/at_exit.h" |
27 #include "base/files/file_path.h" | 28 #include "base/files/file_path.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 | 62 |
62 const char kClearKeyCdmVersion[] = "0.1.0.1"; | 63 const char kClearKeyCdmVersion[] = "0.1.0.1"; |
63 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; | 64 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; |
64 const int64 kSecondsPerMinute = 60; | 65 const int64 kSecondsPerMinute = 60; |
65 const int64 kMsPerSecond = 1000; | 66 const int64 kMsPerSecond = 1000; |
66 const int64 kInitialTimerDelayMs = 200; | 67 const int64 kInitialTimerDelayMs = 200; |
67 const int64 kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; | 68 const int64 kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; |
68 // Heart beat message header. If a key message starts with |kHeartBeatHeader|, | 69 // Heart beat message header. If a key message starts with |kHeartBeatHeader|, |
69 // it's a heart beat message. Otherwise, it's a key request. | 70 // it's a heart beat message. Otherwise, it's a key request. |
70 const char kHeartBeatHeader[] = "HEARTBEAT"; | 71 const char kHeartBeatHeader[] = "HEARTBEAT"; |
72 // CDM file IO test result header. | |
73 const char kCdmFileIOTestResultHeader[] = "CDMFILEIOTESTRESULT"; | |
71 | 74 |
72 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is | 75 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is |
73 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. | 76 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. |
74 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( | 77 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( |
75 const cdm::InputBuffer& input_buffer) { | 78 const cdm::InputBuffer& input_buffer) { |
76 if (!input_buffer.data) { | 79 if (!input_buffer.data) { |
77 DCHECK(!input_buffer.data_size); | 80 DCHECK(!input_buffer.data_size); |
78 return media::DecoderBuffer::CreateEOSBuffer(); | 81 return media::DecoderBuffer::CreateEOSBuffer(); |
79 } | 82 } |
80 | 83 |
(...skipping 17 matching lines...) Expand all Loading... | |
98 input_buffer.data_offset, | 101 input_buffer.data_offset, |
99 subsamples)); | 102 subsamples)); |
100 | 103 |
101 output_buffer->set_decrypt_config(decrypt_config.Pass()); | 104 output_buffer->set_decrypt_config(decrypt_config.Pass()); |
102 output_buffer->set_timestamp( | 105 output_buffer->set_timestamp( |
103 base::TimeDelta::FromMicroseconds(input_buffer.timestamp)); | 106 base::TimeDelta::FromMicroseconds(input_buffer.timestamp)); |
104 | 107 |
105 return output_buffer; | 108 return output_buffer; |
106 } | 109 } |
107 | 110 |
111 std::string GetCdmFileIOTestResultMessage(bool success) { | |
112 std::string message(kCdmFileIOTestResultHeader); | |
113 message += success ? '1' : '0'; | |
114 return message; | |
115 } | |
116 | |
108 template<typename Type> | 117 template<typename Type> |
109 class ScopedResetter { | 118 class ScopedResetter { |
110 public: | 119 public: |
111 explicit ScopedResetter(Type* object) : object_(object) {} | 120 explicit ScopedResetter(Type* object) : object_(object) {} |
112 ~ScopedResetter() { object_->Reset(); } | 121 ~ScopedResetter() { object_->Reset(); } |
113 | 122 |
114 private: | 123 private: |
115 Type* const object_; | 124 Type* const object_; |
116 }; | 125 }; |
117 | 126 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 | 239 |
231 if (client_.status() != (Client::kKeyMessage | Client::kSetSessionId)) { | 240 if (client_.status() != (Client::kKeyMessage | Client::kSetSessionId)) { |
232 // Use values returned to client if possible. | 241 // Use values returned to client if possible. |
233 host_->SendKeyError(client_.session_id().data(), | 242 host_->SendKeyError(client_.session_id().data(), |
234 client_.session_id().size(), | 243 client_.session_id().size(), |
235 static_cast<cdm::MediaKeyError>(client_.error_code()), | 244 static_cast<cdm::MediaKeyError>(client_.error_code()), |
236 client_.system_code()); | 245 client_.system_code()); |
237 return cdm::kSessionError; | 246 return cdm::kSessionError; |
238 } | 247 } |
239 | 248 |
249 std::string session_id = client_.session_id(); | |
250 | |
240 host_->SendKeyMessage( | 251 host_->SendKeyMessage( |
241 client_.session_id().data(), client_.session_id().size(), | 252 session_id.data(), session_id.size(), |
242 reinterpret_cast<const char*>(&client_.key_message()[0]), | 253 reinterpret_cast<const char*>(&client_.key_message()[0]), |
243 client_.key_message().size(), | 254 client_.key_message().size(), |
244 client_.default_url().data(), client_.default_url().size()); | 255 client_.default_url().data(), client_.default_url().size()); |
245 | 256 |
246 // Only save the latest session ID for heartbeat messages. | 257 // Save the latest session ID for heartbeat and file IO test messages. |
247 heartbeat_session_id_ = client_.session_id(); | 258 last_session_id_ = client_.session_id(); |
259 | |
260 StartCdmFileIOTest(); | |
248 | 261 |
249 return cdm::kSuccess; | 262 return cdm::kSuccess; |
250 } | 263 } |
251 | 264 |
252 cdm::Status ClearKeyCdm::AddKey(const char* session_id, | 265 cdm::Status ClearKeyCdm::AddKey(const char* session_id, |
253 uint32_t session_id_size, | 266 uint32_t session_id_size, |
254 const uint8_t* key, | 267 const uint8_t* key, |
255 uint32_t key_size, | 268 uint32_t key_size, |
256 const uint8_t* key_id, | 269 const uint8_t* key_id, |
257 uint32_t key_id_size) { | 270 uint32_t key_id_size) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 heartbeat_message = next_heartbeat_message_; | 316 heartbeat_message = next_heartbeat_message_; |
304 } else { | 317 } else { |
305 heartbeat_message = "ERROR: Invalid timer context found!"; | 318 heartbeat_message = "ERROR: Invalid timer context found!"; |
306 } | 319 } |
307 | 320 |
308 // This URL is only used for testing the code path for defaultURL. | 321 // This URL is only used for testing the code path for defaultURL. |
309 // There is no service at this URL, so applications should ignore it. | 322 // There is no service at this URL, so applications should ignore it. |
310 const char url[] = "http://test.externalclearkey.chromium.org"; | 323 const char url[] = "http://test.externalclearkey.chromium.org"; |
311 | 324 |
312 host_->SendKeyMessage( | 325 host_->SendKeyMessage( |
313 heartbeat_session_id_.data(), heartbeat_session_id_.size(), | 326 last_session_id_.data(), last_session_id_.size(), |
314 heartbeat_message.data(), heartbeat_message.size(), | 327 heartbeat_message.data(), heartbeat_message.size(), |
315 url, arraysize(url) - 1); | 328 url, arraysize(url) - 1); |
316 | 329 |
317 ScheduleNextHeartBeat(); | 330 ScheduleNextHeartBeat(); |
318 } | 331 } |
319 | 332 |
320 static void CopyDecryptResults( | 333 static void CopyDecryptResults( |
321 media::Decryptor::Status* status_copy, | 334 media::Decryptor::Status* status_copy, |
322 scoped_refptr<media::DecoderBuffer>* buffer_copy, | 335 scoped_refptr<media::DecoderBuffer>* buffer_copy, |
323 media::Decryptor::Status status, | 336 media::Decryptor::Status status, |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 | 610 |
598 int samples_generated = GenerateFakeAudioFramesFromDuration( | 611 int samples_generated = GenerateFakeAudioFramesFromDuration( |
599 timestamp_in_microseconds - CurrentTimeStampInMicroseconds(), | 612 timestamp_in_microseconds - CurrentTimeStampInMicroseconds(), |
600 audio_frames); | 613 audio_frames); |
601 total_samples_generated_ += samples_generated; | 614 total_samples_generated_ += samples_generated; |
602 | 615 |
603 return samples_generated == 0 ? cdm::kNeedMoreData : cdm::kSuccess; | 616 return samples_generated == 0 ? cdm::kNeedMoreData : cdm::kSuccess; |
604 } | 617 } |
605 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 618 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
606 | 619 |
620 void ClearKeyCdm::StartCdmFileIOTest() { | |
621 cdm_file_io_test_.reset(new CdmFileIOTest()); | |
622 | |
623 cdm::CdmFileIO* cdm_file_io = host_->GetCdmFileIO(cdm_file_io_test_.get()); | |
ddorwin
2013/12/04 05:27:08
Could/should we encapsulate this in the test file
xhwang
2013/12/10 01:24:25
Done.
| |
624 if (!cdm_file_io) { | |
625 DVLOG(1) << "Cannot get CDM File IO interface"; | |
626 OnCdmFileIOTestComplete(false); | |
627 return; | |
628 } | |
629 | |
630 cdm_file_io_test_->Run(cdm_file_io, | |
631 base::Bind(&ClearKeyCdm::OnCdmFileIOTestComplete, | |
632 base::Unretained(this))); | |
633 } | |
634 | |
635 void ClearKeyCdm::OnCdmFileIOTestComplete(bool success) { | |
636 DVLOG(1) << __FUNCTION__ << ": " << success; | |
637 std::string message = GetCdmFileIOTestResultMessage(success); | |
638 host_->SendKeyMessage(last_session_id_.data(), last_session_id_.size(), | |
639 message.data(), message.size(), | |
640 NULL, 0); | |
641 cdm_file_io_test_.reset(); | |
642 } | |
643 | |
607 } // namespace media | 644 } // namespace media |
OLD | NEW |