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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 const int64 kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; | 67 const int64 kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; |
68 // Heart beat message header. If a key message starts with |kHeartBeatHeader|, | 68 // Heart beat message header. If a key message starts with |kHeartBeatHeader|, |
69 // it's a heart beat message. Otherwise, it's a key request. | 69 // it's a heart beat message. Otherwise, it's a key request. |
70 const char kHeartBeatHeader[] = "HEARTBEAT"; | 70 const char kHeartBeatHeader[] = "HEARTBEAT"; |
71 | 71 |
72 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is | 72 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is |
73 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. | 73 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. |
74 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( | 74 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( |
75 const cdm::InputBuffer& input_buffer) { | 75 const cdm::InputBuffer& input_buffer) { |
76 if (!input_buffer.data) { | 76 if (!input_buffer.data) { |
77 DCHECK_EQ(input_buffer.data_size, 0); | 77 DCHECK(!input_buffer.data_size); |
78 return media::DecoderBuffer::CreateEOSBuffer(); | 78 return media::DecoderBuffer::CreateEOSBuffer(); |
79 } | 79 } |
80 | 80 |
81 // TODO(tomfinegan): Get rid of this copy. | 81 // TODO(tomfinegan): Get rid of this copy. |
82 scoped_refptr<media::DecoderBuffer> output_buffer = | 82 scoped_refptr<media::DecoderBuffer> output_buffer = |
83 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); | 83 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); |
84 | 84 |
85 std::vector<media::SubsampleEntry> subsamples; | 85 std::vector<media::SubsampleEntry> subsamples; |
86 for (int32_t i = 0; i < input_buffer.num_subsamples; ++i) { | 86 for (uint32_t i = 0; i < input_buffer.num_subsamples; ++i) { |
87 media::SubsampleEntry subsample; | 87 media::SubsampleEntry subsample; |
88 subsample.clear_bytes = input_buffer.subsamples[i].clear_bytes; | 88 subsample.clear_bytes = input_buffer.subsamples[i].clear_bytes; |
89 subsample.cypher_bytes = input_buffer.subsamples[i].cipher_bytes; | 89 subsample.cypher_bytes = input_buffer.subsamples[i].cipher_bytes; |
90 subsamples.push_back(subsample); | 90 subsamples.push_back(subsample); |
91 } | 91 } |
92 | 92 |
93 scoped_ptr<media::DecryptConfig> decrypt_config(new media::DecryptConfig( | 93 scoped_ptr<media::DecryptConfig> decrypt_config(new media::DecryptConfig( |
94 std::string(reinterpret_cast<const char*>(input_buffer.key_id), | 94 std::string(reinterpret_cast<const char*>(input_buffer.key_id), |
95 input_buffer.key_id_size), | 95 input_buffer.key_id_size), |
96 std::string(reinterpret_cast<const char*>(input_buffer.iv), | 96 std::string(reinterpret_cast<const char*>(input_buffer.iv), |
(...skipping 23 matching lines...) Expand all Loading... |
120 DVLOG(2) << "FFmpeg libraries initialized: " << g_ffmpeg_lib_initialized; | 120 DVLOG(2) << "FFmpeg libraries initialized: " << g_ffmpeg_lib_initialized; |
121 av_register_all(); | 121 av_register_all(); |
122 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER | 122 #endif // CLEAR_KEY_CDM_USE_FFMPEG_DECODER |
123 } | 123 } |
124 | 124 |
125 void DeinitializeCdmModule() { | 125 void DeinitializeCdmModule() { |
126 } | 126 } |
127 | 127 |
128 void* CreateCdmInstance( | 128 void* CreateCdmInstance( |
129 int cdm_interface_version, | 129 int cdm_interface_version, |
130 const char* key_system, int key_system_size, | 130 const char* key_system, uint32_t key_system_size, |
131 GetCdmHostFunc get_cdm_host_func, void* user_data) { | 131 GetCdmHostFunc get_cdm_host_func, void* user_data) { |
132 DVLOG(1) << "CreateCdmInstance()"; | 132 DVLOG(1) << "CreateCdmInstance()"; |
133 | 133 |
134 if (std::string(key_system, key_system_size) != kExternalClearKeyKeySystem) { | 134 if (std::string(key_system, key_system_size) != kExternalClearKeyKeySystem) { |
135 DVLOG(1) << "Unsupported key system."; | 135 DVLOG(1) << "Unsupported key system."; |
136 return NULL; | 136 return NULL; |
137 } | 137 } |
138 | 138 |
139 if (cdm_interface_version != cdm::ContentDecryptionModule_2::kVersion) | 139 if (cdm_interface_version != cdm::ContentDecryptionModule_2::kVersion) |
140 return NULL; | 140 return NULL; |
141 | 141 |
142 cdm::Host* host = static_cast<cdm::Host*>( | 142 cdm::ContentDecryptionModule_2::Host* host = |
143 get_cdm_host_func(cdm::ContentDecryptionModule_2::kVersion, user_data)); | 143 static_cast<cdm::ContentDecryptionModule_2::Host*>(get_cdm_host_func( |
| 144 cdm::ContentDecryptionModule_2::Host::kVersion, user_data)); |
144 if (!host) | 145 if (!host) |
145 return NULL; | 146 return NULL; |
146 | 147 |
147 return new media::ClearKeyCdm(host); | 148 return new media::ClearKeyCdm(host); |
148 } | 149 } |
149 | 150 |
150 const char* GetCdmVersion() { | 151 const char* GetCdmVersion() { |
151 return kClearKeyCdmVersion; | 152 return kClearKeyCdmVersion; |
152 } | 153 } |
153 | 154 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 channel_count_ = 0; | 197 channel_count_ = 0; |
197 bits_per_channel_ = 0; | 198 bits_per_channel_ = 0; |
198 samples_per_second_ = 0; | 199 samples_per_second_ = 0; |
199 output_timestamp_base_in_microseconds_ = kNoTimestamp; | 200 output_timestamp_base_in_microseconds_ = kNoTimestamp; |
200 total_samples_generated_ = 0; | 201 total_samples_generated_ = 0; |
201 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 202 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
202 } | 203 } |
203 | 204 |
204 ClearKeyCdm::~ClearKeyCdm() {} | 205 ClearKeyCdm::~ClearKeyCdm() {} |
205 | 206 |
206 cdm::Status ClearKeyCdm::GenerateKeyRequest(const char* type, int type_size, | 207 cdm::Status ClearKeyCdm::GenerateKeyRequest(const char* type, |
| 208 uint32_t type_size, |
207 const uint8_t* init_data, | 209 const uint8_t* init_data, |
208 int init_data_size) { | 210 uint32_t init_data_size) { |
209 DVLOG(1) << "GenerateKeyRequest()"; | 211 DVLOG(1) << "GenerateKeyRequest()"; |
210 base::AutoLock auto_lock(client_lock_); | 212 base::AutoLock auto_lock(client_lock_); |
211 ScopedResetter<Client> auto_resetter(&client_); | 213 ScopedResetter<Client> auto_resetter(&client_); |
212 decryptor_.GenerateKeyRequest(std::string(type, type_size), | 214 decryptor_.GenerateKeyRequest(std::string(type, type_size), |
213 init_data, init_data_size); | 215 init_data, init_data_size); |
214 | 216 |
215 if (client_.status() != Client::kKeyMessage) { | 217 if (client_.status() != Client::kKeyMessage) { |
216 host_->SendKeyError(NULL, 0, cdm::kUnknownError, 0); | 218 host_->SendKeyError(NULL, 0, cdm::kUnknownError, 0); |
217 return cdm::kSessionError; | 219 return cdm::kSessionError; |
218 } | 220 } |
219 | 221 |
220 host_->SendKeyMessage( | 222 host_->SendKeyMessage( |
221 client_.session_id().data(), client_.session_id().size(), | 223 client_.session_id().data(), client_.session_id().size(), |
222 reinterpret_cast<const char*>(&client_.key_message()[0]), | 224 reinterpret_cast<const char*>(&client_.key_message()[0]), |
223 client_.key_message().size(), | 225 client_.key_message().size(), |
224 client_.default_url().data(), client_.default_url().size()); | 226 client_.default_url().data(), client_.default_url().size()); |
225 | 227 |
226 // Only save the latest session ID for heartbeat messages. | 228 // Only save the latest session ID for heartbeat messages. |
227 heartbeat_session_id_ = client_.session_id(); | 229 heartbeat_session_id_ = client_.session_id(); |
228 | 230 |
229 return cdm::kSuccess; | 231 return cdm::kSuccess; |
230 } | 232 } |
231 | 233 |
232 cdm::Status ClearKeyCdm::AddKey(const char* session_id, | 234 cdm::Status ClearKeyCdm::AddKey(const char* session_id, |
233 int session_id_size, | 235 uint32_t session_id_size, |
234 const uint8_t* key, | 236 const uint8_t* key, |
235 int key_size, | 237 uint32_t key_size, |
236 const uint8_t* key_id, | 238 const uint8_t* key_id, |
237 int key_id_size) { | 239 uint32_t key_id_size) { |
238 DVLOG(1) << "AddKey()"; | 240 DVLOG(1) << "AddKey()"; |
239 base::AutoLock auto_lock(client_lock_); | 241 base::AutoLock auto_lock(client_lock_); |
240 ScopedResetter<Client> auto_resetter(&client_); | 242 ScopedResetter<Client> auto_resetter(&client_); |
241 decryptor_.AddKey(key, key_size, key_id, key_id_size, | 243 decryptor_.AddKey(key, key_size, key_id, key_id_size, |
242 std::string(session_id, session_id_size)); | 244 std::string(session_id, session_id_size)); |
243 | 245 |
244 if (client_.status() != Client::kKeyAdded) | 246 if (client_.status() != Client::kKeyAdded) |
245 return cdm::kSessionError; | 247 return cdm::kSessionError; |
246 | 248 |
247 if (!timer_set_) { | 249 if (!timer_set_) { |
248 ScheduleNextHeartBeat(); | 250 ScheduleNextHeartBeat(); |
249 timer_set_ = true; | 251 timer_set_ = true; |
250 } | 252 } |
251 | 253 |
252 return cdm::kSuccess; | 254 return cdm::kSuccess; |
253 } | 255 } |
254 | 256 |
255 cdm::Status ClearKeyCdm::CancelKeyRequest(const char* session_id, | 257 cdm::Status ClearKeyCdm::CancelKeyRequest(const char* session_id, |
256 int session_id_size) { | 258 uint32_t session_id_size) { |
257 DVLOG(1) << "CancelKeyRequest()"; | 259 DVLOG(1) << "CancelKeyRequest()"; |
258 base::AutoLock auto_lock(client_lock_); | 260 base::AutoLock auto_lock(client_lock_); |
259 ScopedResetter<Client> auto_resetter(&client_); | 261 ScopedResetter<Client> auto_resetter(&client_); |
260 decryptor_.CancelKeyRequest(std::string(session_id, session_id_size)); | 262 decryptor_.CancelKeyRequest(std::string(session_id, session_id_size)); |
261 return cdm::kSuccess; | 263 return cdm::kSuccess; |
262 } | 264 } |
263 | 265 |
264 void ClearKeyCdm::TimerExpired(void* context) { | 266 void ClearKeyCdm::TimerExpired(void* context) { |
265 std::string heartbeat_message; | 267 std::string heartbeat_message; |
266 if (!next_heartbeat_message_.empty() && | 268 if (!next_heartbeat_message_.empty() && |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 int samples_generated = GenerateFakeAudioFramesFromDuration( | 565 int samples_generated = GenerateFakeAudioFramesFromDuration( |
564 timestamp_in_microseconds - CurrentTimeStampInMicroseconds(), | 566 timestamp_in_microseconds - CurrentTimeStampInMicroseconds(), |
565 audio_frames); | 567 audio_frames); |
566 total_samples_generated_ += samples_generated; | 568 total_samples_generated_ += samples_generated; |
567 | 569 |
568 return samples_generated == 0 ? cdm::kNeedMoreData : cdm::kSuccess; | 570 return samples_generated == 0 ? cdm::kNeedMoreData : cdm::kSuccess; |
569 } | 571 } |
570 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER | 572 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER |
571 | 573 |
572 } // namespace media | 574 } // namespace media |
OLD | NEW |