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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; | 64 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; |
64 const char kExternalClearKeyDecryptOnlyKeySystem[] = | 65 const char kExternalClearKeyDecryptOnlyKeySystem[] = |
65 "org.chromium.externalclearkey.decryptonly"; | 66 "org.chromium.externalclearkey.decryptonly"; |
66 const int64 kSecondsPerMinute = 60; | 67 const int64 kSecondsPerMinute = 60; |
67 const int64 kMsPerSecond = 1000; | 68 const int64 kMsPerSecond = 1000; |
68 const int64 kInitialTimerDelayMs = 200; | 69 const int64 kInitialTimerDelayMs = 200; |
69 const int64 kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; | 70 const int64 kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; |
70 // Heart beat message header. If a key message starts with |kHeartBeatHeader|, | 71 // Heart beat message header. If a key message starts with |kHeartBeatHeader|, |
71 // it's a heart beat message. Otherwise, it's a key request. | 72 // it's a heart beat message. Otherwise, it's a key request. |
72 const char kHeartBeatHeader[] = "HEARTBEAT"; | 73 const char kHeartBeatHeader[] = "HEARTBEAT"; |
74 // CDM file IO test result header. | |
75 const char kFileIOTestResultHeader[] = "FILEIOTESTRESULT"; | |
73 | 76 |
74 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is | 77 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is |
75 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. | 78 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. |
76 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( | 79 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( |
77 const cdm::InputBuffer& input_buffer) { | 80 const cdm::InputBuffer& input_buffer) { |
78 if (!input_buffer.data) { | 81 if (!input_buffer.data) { |
79 DCHECK(!input_buffer.data_size); | 82 DCHECK(!input_buffer.data_size); |
80 return media::DecoderBuffer::CreateEOSBuffer(); | 83 return media::DecoderBuffer::CreateEOSBuffer(); |
81 } | 84 } |
82 | 85 |
(...skipping 17 matching lines...) Expand all Loading... | |
100 input_buffer.data_offset, | 103 input_buffer.data_offset, |
101 subsamples)); | 104 subsamples)); |
102 | 105 |
103 output_buffer->set_decrypt_config(decrypt_config.Pass()); | 106 output_buffer->set_decrypt_config(decrypt_config.Pass()); |
104 output_buffer->set_timestamp( | 107 output_buffer->set_timestamp( |
105 base::TimeDelta::FromMicroseconds(input_buffer.timestamp)); | 108 base::TimeDelta::FromMicroseconds(input_buffer.timestamp)); |
106 | 109 |
107 return output_buffer; | 110 return output_buffer; |
108 } | 111 } |
109 | 112 |
113 static std::string GetFileIOTestResultMessage(bool success) { | |
114 std::string message(kFileIOTestResultHeader); | |
115 message += success ? '1' : '0'; | |
116 return message; | |
117 } | |
118 | |
110 template<typename Type> | 119 template<typename Type> |
111 class ScopedResetter { | 120 class ScopedResetter { |
112 public: | 121 public: |
113 explicit ScopedResetter(Type* object) : object_(object) {} | 122 explicit ScopedResetter(Type* object) : object_(object) {} |
114 ~ScopedResetter() { object_->Reset(); } | 123 ~ScopedResetter() { object_->Reset(); } |
115 | 124 |
116 private: | 125 private: |
117 Type* const object_; | 126 Type* const object_; |
118 }; | 127 }; |
119 | 128 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 | 251 |
243 if (client_.status() != (Client::kMessage | Client::kCreated)) { | 252 if (client_.status() != (Client::kMessage | Client::kCreated)) { |
244 // Use values returned to client if possible. | 253 // Use values returned to client if possible. |
245 host_->SendKeyError(client_.session_id().data(), | 254 host_->SendKeyError(client_.session_id().data(), |
246 client_.session_id().size(), | 255 client_.session_id().size(), |
247 static_cast<cdm::MediaKeyError>(client_.error_code()), | 256 static_cast<cdm::MediaKeyError>(client_.error_code()), |
248 client_.system_code()); | 257 client_.system_code()); |
249 return cdm::kSessionError; | 258 return cdm::kSessionError; |
250 } | 259 } |
251 | 260 |
261 std::string session_id = client_.session_id(); | |
262 | |
252 host_->SendKeyMessage( | 263 host_->SendKeyMessage( |
253 client_.session_id().data(), client_.session_id().size(), | 264 session_id.data(), session_id.size(), |
254 reinterpret_cast<const char*>(&client_.message()[0]), | 265 reinterpret_cast<const char*>(&client_.message()[0]), |
255 client_.message().size(), | 266 client_.message().size(), |
256 client_.destination_url().data(), client_.destination_url().size()); | 267 client_.destination_url().data(), client_.destination_url().size()); |
257 | 268 |
258 // Only save the latest session ID for heartbeat messages. | 269 // Save the latest session ID for heartbeat and file IO test messages. |
259 heartbeat_session_id_ = client_.session_id(); | 270 last_session_id_ = client_.session_id(); |
271 | |
272 StartCdmFileIOTest(); | |
260 | 273 |
261 return cdm::kSuccess; | 274 return cdm::kSuccess; |
262 } | 275 } |
263 | 276 |
264 cdm::Status ClearKeyCdm::AddKey(const char* session_id, | 277 cdm::Status ClearKeyCdm::AddKey(const char* session_id, |
265 uint32_t session_id_size, | 278 uint32_t session_id_size, |
266 const uint8_t* key, | 279 const uint8_t* key, |
267 uint32_t key_size, | 280 uint32_t key_size, |
268 const uint8_t* key_id, | 281 const uint8_t* key_id, |
269 uint32_t key_id_size) { | 282 uint32_t key_id_size) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 heartbeat_message = next_heartbeat_message_; | 327 heartbeat_message = next_heartbeat_message_; |
315 } else { | 328 } else { |
316 heartbeat_message = "ERROR: Invalid timer context found!"; | 329 heartbeat_message = "ERROR: Invalid timer context found!"; |
317 } | 330 } |
318 | 331 |
319 // This URL is only used for testing the code path for defaultURL. | 332 // This URL is only used for testing the code path for defaultURL. |
320 // There is no service at this URL, so applications should ignore it. | 333 // There is no service at this URL, so applications should ignore it. |
321 const char url[] = "http://test.externalclearkey.chromium.org"; | 334 const char url[] = "http://test.externalclearkey.chromium.org"; |
322 | 335 |
323 host_->SendKeyMessage( | 336 host_->SendKeyMessage( |
324 heartbeat_session_id_.data(), heartbeat_session_id_.size(), | 337 last_session_id_.data(), last_session_id_.size(), |
325 heartbeat_message.data(), heartbeat_message.size(), | 338 heartbeat_message.data(), heartbeat_message.size(), |
326 url, arraysize(url) - 1); | 339 url, arraysize(url) - 1); |
327 | 340 |
328 ScheduleNextHeartBeat(); | 341 ScheduleNextHeartBeat(); |
329 } | 342 } |
330 | 343 |
331 static void CopyDecryptResults( | 344 static void CopyDecryptResults( |
332 media::Decryptor::Status* status_copy, | 345 media::Decryptor::Status* status_copy, |
333 scoped_refptr<media::DecoderBuffer>* buffer_copy, | 346 scoped_refptr<media::DecoderBuffer>* buffer_copy, |
334 media::Decryptor::Status status, | 347 media::Decryptor::Status status, |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 | 627 |
615 int samples_generated = GenerateFakeAudioFramesFromDuration( | 628 int samples_generated = GenerateFakeAudioFramesFromDuration( |
616 timestamp_in_microseconds - CurrentTimeStampInMicroseconds(), | 629 timestamp_in_microseconds - CurrentTimeStampInMicroseconds(), |
617 audio_frames); | 630 audio_frames); |
618 total_samples_generated_ += samples_generated; | 631 total_samples_generated_ += samples_generated; |
619 | 632 |
620 return samples_generated == 0 ? cdm::kNeedMoreData : cdm::kSuccess; | 633 return samples_generated == 0 ? cdm::kNeedMoreData : cdm::kSuccess; |
621 } | 634 } |
622 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 635 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
623 | 636 |
637 void ClearKeyCdm::StartCdmFileIOTest() { | |
638 cdm_file_io_test_.reset(new CdmFileIOTest(host_)); | |
ddorwin
2013/12/11 21:16:17
Doh. I'm the one that asked you to encapsulate Fil
xhwang
2013/12/13 02:51:47
Now I pass in a callback for CreateFileIO. But I d
| |
639 cdm_file_io_test_->Run( | |
640 base::Bind(&ClearKeyCdm::OnFileIOTestComplete, base::Unretained(this))); | |
641 } | |
642 | |
643 void ClearKeyCdm::OnFileIOTestComplete(bool success) { | |
644 DVLOG(1) << __FUNCTION__ << ": " << success; | |
645 std::string message = GetFileIOTestResultMessage(success); | |
646 host_->SendKeyMessage(last_session_id_.data(), last_session_id_.size(), | |
647 message.data(), message.size(), | |
648 NULL, 0); | |
649 cdm_file_io_test_.reset(); | |
650 } | |
651 | |
624 } // namespace media | 652 } // namespace media |
OLD | NEW |