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> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 CHECK(PathService::Get(base::DIR_MODULE, &file_path)); | 54 CHECK(PathService::Get(base::DIR_MODULE, &file_path)); |
55 CHECK(media::InitializeMediaLibrary(file_path)); | 55 CHECK(media::InitializeMediaLibrary(file_path)); |
56 return true; | 56 return true; |
57 } | 57 } |
58 | 58 |
59 static bool g_ffmpeg_lib_initialized = InitializeFFmpegLibraries(); | 59 static bool g_ffmpeg_lib_initialized = InitializeFFmpegLibraries(); |
60 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER | 60 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER |
61 | 61 |
62 const char kClearKeyCdmVersion[] = "0.1.0.1"; | 62 const char kClearKeyCdmVersion[] = "0.1.0.1"; |
63 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; | 63 const char kExternalClearKeyKeySystem[] = "org.chromium.externalclearkey"; |
64 const char kDecryptOnlyExternalClearKeyKeySystem[] = | |
65 "org.chromium.externalclearkey.decryptonly"; | |
64 const int64 kSecondsPerMinute = 60; | 66 const int64 kSecondsPerMinute = 60; |
65 const int64 kMsPerSecond = 1000; | 67 const int64 kMsPerSecond = 1000; |
66 const int64 kInitialTimerDelayMs = 200; | 68 const int64 kInitialTimerDelayMs = 200; |
67 const int64 kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; | 69 const int64 kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; |
68 // Heart beat message header. If a key message starts with |kHeartBeatHeader|, | 70 // Heart beat message header. If a key message starts with |kHeartBeatHeader|, |
69 // it's a heart beat message. Otherwise, it's a key request. | 71 // it's a heart beat message. Otherwise, it's a key request. |
70 const char kHeartBeatHeader[] = "HEARTBEAT"; | 72 const char kHeartBeatHeader[] = "HEARTBEAT"; |
71 | 73 |
72 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is | 74 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is |
73 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. | 75 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 void INITIALIZE_CDM_MODULE() { | 120 void INITIALIZE_CDM_MODULE() { |
119 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) | 121 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) |
120 DVLOG(2) << "FFmpeg libraries initialized: " << g_ffmpeg_lib_initialized; | 122 DVLOG(2) << "FFmpeg libraries initialized: " << g_ffmpeg_lib_initialized; |
121 av_register_all(); | 123 av_register_all(); |
122 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER | 124 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER |
123 } | 125 } |
124 | 126 |
125 void DeinitializeCdmModule() { | 127 void DeinitializeCdmModule() { |
126 } | 128 } |
127 | 129 |
128 void* CreateCdmInstance( | 130 void* CreateCdmInstance(int cdm_interface_version, |
129 int cdm_interface_version, | 131 const char* key_system, uint32_t key_system_size, |
130 const char* key_system, uint32_t key_system_size, | 132 GetCdmHostFunc get_cdm_host_func, |
131 GetCdmHostFunc get_cdm_host_func, void* user_data) { | 133 void* user_data) { |
132 DVLOG(1) << "CreateCdmInstance()"; | 134 DVLOG(1) << "CreateCdmInstance()"; |
133 | 135 |
134 if (std::string(key_system, key_system_size) != kExternalClearKeyKeySystem) { | 136 std::string key_system_string(key_system, key_system_size); |
137 if (key_system_string != kExternalClearKeyKeySystem && | |
138 key_system_string != kDecryptOnlyExternalClearKeyKeySystem) { | |
135 DVLOG(1) << "Unsupported key system."; | 139 DVLOG(1) << "Unsupported key system."; |
ddorwin
2013/11/21 04:10:58
...system: " << key_system_string;
xhwang
2013/11/22 01:47:36
Done.
| |
136 return NULL; | 140 return NULL; |
137 } | 141 } |
138 | 142 |
139 if (cdm_interface_version != media::ClearKeyCdmInterface::kVersion) | 143 if (cdm_interface_version != media::ClearKeyCdmInterface::kVersion) |
140 return NULL; | 144 return NULL; |
141 | 145 |
142 media::ClearKeyCdmHost* host = static_cast<media::ClearKeyCdmHost*>( | 146 media::ClearKeyCdmHost* host = static_cast<media::ClearKeyCdmHost*>( |
143 get_cdm_host_func(media::ClearKeyCdmHost::kVersion, user_data)); | 147 get_cdm_host_func(media::ClearKeyCdmHost::kVersion, user_data)); |
144 if (!host) | 148 if (!host) |
145 return NULL; | 149 return NULL; |
146 | 150 |
147 return new media::ClearKeyCdm(host); | 151 return new media::ClearKeyCdm( |
152 host, key_system_string == kDecryptOnlyExternalClearKeyKeySystem); | |
148 } | 153 } |
149 | 154 |
150 const char* GetCdmVersion() { | 155 const char* GetCdmVersion() { |
151 return kClearKeyCdmVersion; | 156 return kClearKeyCdmVersion; |
152 } | 157 } |
153 | 158 |
154 namespace media { | 159 namespace media { |
155 | 160 |
156 // Since all the calls to AesDecryptor are synchronous, pass a dummy value for | 161 // Since all the calls to AesDecryptor are synchronous, pass a dummy value for |
157 // reference_id that is never exposed outside this class. | 162 // reference_id that is never exposed outside this class. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 key_message_ = message; | 196 key_message_ = message; |
192 default_url_ = default_url; | 197 default_url_ = default_url; |
193 } | 198 } |
194 | 199 |
195 void ClearKeyCdm::Client::SetSessionId(uint32 reference_id, | 200 void ClearKeyCdm::Client::SetSessionId(uint32 reference_id, |
196 const std::string& session_id) { | 201 const std::string& session_id) { |
197 status_ = static_cast<Status>(status_ | kSetSessionId); | 202 status_ = static_cast<Status>(status_ | kSetSessionId); |
198 session_id_ = session_id; | 203 session_id_ = session_id; |
199 } | 204 } |
200 | 205 |
201 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host) | 206 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, bool decrypt_only) |
202 : decryptor_(base::Bind(&Client::KeyAdded, base::Unretained(&client_)), | 207 : decryptor_(base::Bind(&Client::KeyAdded, base::Unretained(&client_)), |
203 base::Bind(&Client::KeyError, base::Unretained(&client_)), | 208 base::Bind(&Client::KeyError, base::Unretained(&client_)), |
204 base::Bind(&Client::KeyMessage, base::Unretained(&client_)), | 209 base::Bind(&Client::KeyMessage, base::Unretained(&client_)), |
205 base::Bind(&Client::SetSessionId, base::Unretained(&client_))), | 210 base::Bind(&Client::SetSessionId, base::Unretained(&client_))), |
206 host_(host), | 211 host_(host), |
212 decrypt_only_(decrypt_only), | |
207 timer_delay_ms_(kInitialTimerDelayMs), | 213 timer_delay_ms_(kInitialTimerDelayMs), |
208 timer_set_(false) { | 214 timer_set_(false) { |
209 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) | 215 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) |
210 channel_count_ = 0; | 216 channel_count_ = 0; |
211 bits_per_channel_ = 0; | 217 bits_per_channel_ = 0; |
212 samples_per_second_ = 0; | 218 samples_per_second_ = 0; |
213 output_timestamp_base_in_microseconds_ = kNoTimestamp; | 219 output_timestamp_base_in_microseconds_ = kNoTimestamp; |
214 total_samples_generated_ = 0; | 220 total_samples_generated_ = 0; |
215 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 221 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
216 } | 222 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 buffer->data(), | 351 buffer->data(), |
346 buffer->data_size()); | 352 buffer->data_size()); |
347 decrypted_block->DecryptedBuffer()->SetSize(buffer->data_size()); | 353 decrypted_block->DecryptedBuffer()->SetSize(buffer->data_size()); |
348 decrypted_block->SetTimestamp(buffer->timestamp().InMicroseconds()); | 354 decrypted_block->SetTimestamp(buffer->timestamp().InMicroseconds()); |
349 | 355 |
350 return cdm::kSuccess; | 356 return cdm::kSuccess; |
351 } | 357 } |
352 | 358 |
353 cdm::Status ClearKeyCdm::InitializeAudioDecoder( | 359 cdm::Status ClearKeyCdm::InitializeAudioDecoder( |
354 const cdm::AudioDecoderConfig& audio_decoder_config) { | 360 const cdm::AudioDecoderConfig& audio_decoder_config) { |
361 if (decrypt_only_) | |
362 return cdm::kSessionError; | |
363 | |
355 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) | 364 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) |
356 if (!audio_decoder_) | 365 if (!audio_decoder_) |
357 audio_decoder_.reset(new media::FFmpegCdmAudioDecoder(host_)); | 366 audio_decoder_.reset(new media::FFmpegCdmAudioDecoder(host_)); |
358 | 367 |
359 if (!audio_decoder_->Initialize(audio_decoder_config)) | 368 if (!audio_decoder_->Initialize(audio_decoder_config)) |
360 return cdm::kSessionError; | 369 return cdm::kSessionError; |
361 | 370 |
362 return cdm::kSuccess; | 371 return cdm::kSuccess; |
363 #elif defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) | 372 #elif defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) |
364 channel_count_ = audio_decoder_config.channel_count; | 373 channel_count_ = audio_decoder_config.channel_count; |
365 bits_per_channel_ = audio_decoder_config.bits_per_channel; | 374 bits_per_channel_ = audio_decoder_config.bits_per_channel; |
366 samples_per_second_ = audio_decoder_config.samples_per_second; | 375 samples_per_second_ = audio_decoder_config.samples_per_second; |
367 return cdm::kSuccess; | 376 return cdm::kSuccess; |
368 #else | 377 #else |
369 NOTIMPLEMENTED(); | 378 NOTIMPLEMENTED(); |
370 return cdm::kSessionError; | 379 return cdm::kSessionError; |
371 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER | 380 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER |
372 } | 381 } |
373 | 382 |
374 cdm::Status ClearKeyCdm::InitializeVideoDecoder( | 383 cdm::Status ClearKeyCdm::InitializeVideoDecoder( |
375 const cdm::VideoDecoderConfig& video_decoder_config) { | 384 const cdm::VideoDecoderConfig& video_decoder_config) { |
385 if (decrypt_only_) | |
386 return cdm::kSessionError; | |
387 | |
376 if (video_decoder_ && video_decoder_->is_initialized()) { | 388 if (video_decoder_ && video_decoder_->is_initialized()) { |
377 DCHECK(!video_decoder_->is_initialized()); | 389 DCHECK(!video_decoder_->is_initialized()); |
378 return cdm::kSessionError; | 390 return cdm::kSessionError; |
379 } | 391 } |
380 | 392 |
381 // Any uninitialized decoder will be replaced. | 393 // Any uninitialized decoder will be replaced. |
382 video_decoder_ = CreateVideoDecoder(host_, video_decoder_config); | 394 video_decoder_ = CreateVideoDecoder(host_, video_decoder_config); |
383 if (!video_decoder_) | 395 if (!video_decoder_) |
384 return cdm::kSessionError; | 396 return cdm::kSessionError; |
385 | 397 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 int samples_generated = GenerateFakeAudioFramesFromDuration( | 610 int samples_generated = GenerateFakeAudioFramesFromDuration( |
599 timestamp_in_microseconds - CurrentTimeStampInMicroseconds(), | 611 timestamp_in_microseconds - CurrentTimeStampInMicroseconds(), |
600 audio_frames); | 612 audio_frames); |
601 total_samples_generated_ += samples_generated; | 613 total_samples_generated_ += samples_generated; |
602 | 614 |
603 return samples_generated == 0 ? cdm::kNeedMoreData : cdm::kSuccess; | 615 return samples_generated == 0 ? cdm::kNeedMoreData : cdm::kSuccess; |
604 } | 616 } |
605 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 617 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
606 | 618 |
607 } // namespace media | 619 } // namespace media |
OLD | NEW |