OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/plugins/ppapi/content_decryptor_delegate.h" | 5 #include "webkit/plugins/ppapi/content_decryptor_delegate.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "media/base/audio_decoder_config.h" | 10 #include "media/base/audio_decoder_config.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 | 33 |
34 namespace webkit { | 34 namespace webkit { |
35 namespace ppapi { | 35 namespace ppapi { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // Fills |resource| with a PPB_Buffer_Impl and copies |data| into the buffer | 39 // Fills |resource| with a PPB_Buffer_Impl and copies |data| into the buffer |
40 // resource. The |*resource|, if valid, will be in the ResourceTracker with a | 40 // resource. The |*resource|, if valid, will be in the ResourceTracker with a |
41 // reference-count of 0. If |data| is NULL, sets |*resource| to NULL. Returns | 41 // reference-count of 0. If |data| is NULL, sets |*resource| to NULL. Returns |
42 // true upon success and false if any error happened. | 42 // true upon success and false if any error happened. |
43 bool MakeBufferResource(PP_Instance instance, | 43 bool MakeBufferResource(PP_Instance instance, const uint8* data, uint32_t size, |
44 const uint8* data, uint32_t size, | |
45 scoped_refptr<PPB_Buffer_Impl>* resource) { | 44 scoped_refptr<PPB_Buffer_Impl>* resource) { |
46 TRACE_EVENT0("eme", "ContentDecryptorDelegate - MakeBufferResource"); | 45 TRACE_EVENT0("eme", "ContentDecryptorDelegate - MakeBufferResource"); |
47 DCHECK(resource); | 46 DCHECK(resource); |
48 | 47 |
49 if (!data || !size) { | 48 if (!data || !size) { |
50 DCHECK(!data && !size); | 49 DCHECK(!data && !size); |
51 resource = NULL; | 50 resource = NULL; |
52 return true; | 51 return true; |
53 } | 52 } |
54 | 53 |
55 scoped_refptr<PPB_Buffer_Impl> buffer( | 54 scoped_refptr<PPB_Buffer_Impl> buffer( |
56 PPB_Buffer_Impl::CreateResource(instance, size)); | 55 PPB_Buffer_Impl::CreateResource(instance, size)); |
57 if (!buffer.get()) | 56 if (!buffer.get()) return false; |
58 return false; | |
59 | 57 |
60 BufferAutoMapper mapper(buffer.get()); | 58 BufferAutoMapper mapper(buffer.get()); |
61 if (!mapper.data() || mapper.size() < size) | 59 if (!mapper.data() || mapper.size() < size) return false; |
62 return false; | |
63 memcpy(mapper.data(), data, size); | 60 memcpy(mapper.data(), data, size); |
64 | 61 |
65 *resource = buffer; | 62 *resource = buffer; |
66 return true; | 63 return true; |
67 } | 64 } |
68 | 65 |
69 // Copies the content of |str| into |array|. | 66 // Copies the content of |str| into |array|. |
70 // Returns true if copy succeeded. Returns false if copy failed, e.g. if the | 67 // Returns true if copy succeeded. Returns false if copy failed, e.g. if the |
71 // |array_size| is smaller than the |str| length. | 68 // |array_size| is smaller than the |str| length. |
72 template <uint32_t array_size> | 69 template <uint32_t array_size> |
73 bool CopyStringToArray(const std::string& str, uint8 (&array)[array_size]) { | 70 bool CopyStringToArray(const std::string& str, uint8 (&array)[array_size]) { |
74 if (array_size < str.size()) | 71 if (array_size < str.size()) return false; |
75 return false; | |
76 | 72 |
77 memcpy(array, str.data(), str.size()); | 73 memcpy(array, str.data(), str.size()); |
78 return true; | 74 return true; |
79 } | 75 } |
80 | 76 |
81 // Fills the |block_info| with information from |encrypted_buffer|. | 77 // Fills the |block_info| with information from |encrypted_buffer|. |
82 // | 78 // |
83 // Returns true if |block_info| is successfully filled. Returns false | 79 // Returns true if |block_info| is successfully filled. Returns false |
84 // otherwise. | 80 // otherwise. |
85 static bool MakeEncryptedBlockInfo( | 81 static bool MakeEncryptedBlockInfo( |
86 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 82 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
87 uint32_t request_id, | 83 uint32_t request_id, PP_EncryptedBlockInfo* block_info) { |
88 PP_EncryptedBlockInfo* block_info) { | |
89 // TODO(xhwang): Fix initialization of PP_EncryptedBlockInfo here and | 84 // TODO(xhwang): Fix initialization of PP_EncryptedBlockInfo here and |
90 // anywhere else. | 85 // anywhere else. |
91 memset(block_info, 0, sizeof(*block_info)); | 86 memset(block_info, 0, sizeof(*block_info)); |
92 block_info->tracking_info.request_id = request_id; | 87 block_info->tracking_info.request_id = request_id; |
93 | 88 |
94 // EOS buffers need a request ID and nothing more. | 89 // EOS buffers need a request ID and nothing more. |
95 if (encrypted_buffer->IsEndOfStream()) | 90 if (encrypted_buffer->IsEndOfStream()) return true; |
96 return true; | |
97 | 91 |
98 DCHECK(encrypted_buffer->GetDataSize()) | 92 DCHECK(encrypted_buffer->GetDataSize()) |
99 << "DecryptConfig is set on an empty buffer"; | 93 << "DecryptConfig is set on an empty buffer"; |
100 | 94 |
101 block_info->tracking_info.timestamp = | 95 block_info->tracking_info.timestamp = |
102 encrypted_buffer->GetTimestamp().InMicroseconds(); | 96 encrypted_buffer->GetTimestamp().InMicroseconds(); |
103 block_info->data_size = encrypted_buffer->GetDataSize(); | 97 block_info->data_size = encrypted_buffer->GetDataSize(); |
104 | 98 |
105 const media::DecryptConfig* decrypt_config = | 99 const media::DecryptConfig* decrypt_config = |
106 encrypted_buffer->GetDecryptConfig(); | 100 encrypted_buffer->GetDecryptConfig(); |
(...skipping 15 matching lines...) Expand all Loading... | |
122 decrypt_config->subsamples()[i].clear_bytes; | 116 decrypt_config->subsamples()[i].clear_bytes; |
123 block_info->subsamples[i].cipher_bytes = | 117 block_info->subsamples[i].cipher_bytes = |
124 decrypt_config->subsamples()[i].cypher_bytes; | 118 decrypt_config->subsamples()[i].cypher_bytes; |
125 } | 119 } |
126 | 120 |
127 return true; | 121 return true; |
128 } | 122 } |
129 | 123 |
130 // Deserializes audio data stored in |audio_frames| into individual audio | 124 // Deserializes audio data stored in |audio_frames| into individual audio |
131 // buffers in |frames|. Returns true upon success. | 125 // buffers in |frames|. Returns true upon success. |
132 bool DeserializeAudioFrames(PP_Resource audio_frames, | 126 bool DeserializeAudioFrames(PP_Resource audio_frames, int data_size, |
133 int data_size, | |
134 media::Decryptor::AudioBuffers* frames) { | 127 media::Decryptor::AudioBuffers* frames) { |
135 DCHECK(frames); | 128 DCHECK(frames); |
136 EnterResourceNoLock<PPB_Buffer_API> enter(audio_frames, true); | 129 EnterResourceNoLock<PPB_Buffer_API> enter(audio_frames, true); |
137 if (!enter.succeeded()) | 130 if (!enter.succeeded()) return false; |
scherkus (not reviewing)
2013/06/21 19:48:38
revert this change -- we don't do single-line ifs
| |
138 return false; | |
139 | 131 |
140 BufferAutoMapper mapper(enter.object()); | 132 BufferAutoMapper mapper(enter.object()); |
141 if (!mapper.data() || !mapper.size() || | 133 if (!mapper.data() || !mapper.size() || |
142 mapper.size() < static_cast<uint32_t>(data_size)) | 134 mapper.size() < static_cast<uint32_t>(data_size)) |
143 return false; | 135 return false; |
144 | 136 |
145 const uint8* cur = static_cast<uint8*>(mapper.data()); | 137 const uint8* cur = static_cast<uint8*>(mapper.data()); |
146 int bytes_left = data_size; | 138 int bytes_left = data_size; |
147 | 139 |
148 do { | 140 do { |
149 int64 timestamp = 0; | 141 int64 timestamp = 0; |
150 int64 frame_size = -1; | 142 int64 frame_size = -1; |
151 const int kHeaderSize = sizeof(timestamp) + sizeof(frame_size); | 143 const int kHeaderSize = sizeof(timestamp) + sizeof(frame_size); |
152 | 144 |
153 if (bytes_left < kHeaderSize) | 145 if (bytes_left < kHeaderSize) return false; |
scherkus (not reviewing)
2013/06/21 19:48:38
revert this change -- we don't do single-line ifs
| |
154 return false; | |
155 | 146 |
156 memcpy(×tamp, cur, sizeof(timestamp)); | 147 memcpy(×tamp, cur, sizeof(timestamp)); |
157 cur += sizeof(timestamp); | 148 cur += sizeof(timestamp); |
158 bytes_left -= sizeof(timestamp); | 149 bytes_left -= sizeof(timestamp); |
159 | 150 |
160 memcpy(&frame_size, cur, sizeof(frame_size)); | 151 memcpy(&frame_size, cur, sizeof(frame_size)); |
161 cur += sizeof(frame_size); | 152 cur += sizeof(frame_size); |
162 bytes_left -= sizeof(frame_size); | 153 bytes_left -= sizeof(frame_size); |
163 | 154 |
164 // We should *not* have empty frame in the list. | 155 // We should *not* have empty frame in the list. |
165 if (frame_size <= 0 || bytes_left < frame_size) | 156 if (frame_size <= 0 || bytes_left < frame_size) return false; |
scherkus (not reviewing)
2013/06/21 19:48:38
revert this change -- we don't do single-line ifs
| |
166 return false; | |
167 | 157 |
168 scoped_refptr<media::DataBuffer> frame = | 158 scoped_refptr<media::DataBuffer> frame = |
169 media::DataBuffer::CopyFrom(cur, frame_size); | 159 media::DataBuffer::CopyFrom(cur, frame_size); |
170 frame->SetTimestamp(base::TimeDelta::FromMicroseconds(timestamp)); | 160 frame->set_timestamp(base::TimeDelta::FromMicroseconds(timestamp)); |
171 frames->push_back(frame); | 161 frames->push_back(frame); |
172 | 162 |
173 cur += frame_size; | 163 cur += frame_size; |
174 bytes_left -= frame_size; | 164 bytes_left -= frame_size; |
175 } while (bytes_left > 0); | 165 } while (bytes_left > 0); |
176 | 166 |
177 return true; | 167 return true; |
178 } | 168 } |
179 | 169 |
180 PP_AudioCodec MediaAudioCodecToPpAudioCodec(media::AudioCodec codec) { | 170 PP_AudioCodec MediaAudioCodecToPpAudioCodec(media::AudioCodec codec) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 : pp_instance_(pp_instance), | 265 : pp_instance_(pp_instance), |
276 plugin_decryption_interface_(plugin_decryption_interface), | 266 plugin_decryption_interface_(plugin_decryption_interface), |
277 next_decryption_request_id_(1), | 267 next_decryption_request_id_(1), |
278 pending_audio_decrypt_request_id_(0), | 268 pending_audio_decrypt_request_id_(0), |
279 pending_video_decrypt_request_id_(0), | 269 pending_video_decrypt_request_id_(0), |
280 pending_audio_decoder_init_request_id_(0), | 270 pending_audio_decoder_init_request_id_(0), |
281 pending_video_decoder_init_request_id_(0), | 271 pending_video_decoder_init_request_id_(0), |
282 pending_audio_decode_request_id_(0), | 272 pending_audio_decode_request_id_(0), |
283 pending_video_decode_request_id_(0), | 273 pending_video_decode_request_id_(0), |
284 weak_ptr_factory_(this), | 274 weak_ptr_factory_(this), |
285 weak_this_(weak_ptr_factory_.GetWeakPtr()) { | 275 weak_this_(weak_ptr_factory_.GetWeakPtr()) {} |
286 } | |
287 | 276 |
288 void ContentDecryptorDelegate::Initialize(const std::string& key_system) { | 277 void ContentDecryptorDelegate::Initialize(const std::string& key_system) { |
289 // TODO(ddorwin): Add an Initialize method to PPP_ContentDecryptor_Private. | 278 // TODO(ddorwin): Add an Initialize method to PPP_ContentDecryptor_Private. |
290 DCHECK(!key_system.empty()); | 279 DCHECK(!key_system.empty()); |
291 key_system_ = key_system; | 280 key_system_ = key_system; |
292 } | 281 } |
293 | 282 |
294 void ContentDecryptorDelegate::SetKeyEventCallbacks( | 283 void ContentDecryptorDelegate::SetKeyEventCallbacks( |
295 const media::KeyAddedCB& key_added_cb, | 284 const media::KeyAddedCB& key_added_cb, |
296 const media::KeyErrorCB& key_error_cb, | 285 const media::KeyErrorCB& key_error_cb, |
297 const media::KeyMessageCB& key_message_cb, | 286 const media::KeyMessageCB& key_message_cb, |
298 const media::NeedKeyCB& need_key_cb) { | 287 const media::NeedKeyCB& need_key_cb) { |
299 key_added_cb_ = key_added_cb; | 288 key_added_cb_ = key_added_cb; |
300 key_error_cb_ = key_error_cb; | 289 key_error_cb_ = key_error_cb; |
301 key_message_cb_ = key_message_cb; | 290 key_message_cb_ = key_message_cb; |
302 need_key_cb_ = need_key_cb; | 291 need_key_cb_ = need_key_cb; |
303 } | 292 } |
304 | 293 |
305 bool ContentDecryptorDelegate::GenerateKeyRequest(const std::string& type, | 294 bool ContentDecryptorDelegate::GenerateKeyRequest(const std::string& type, |
306 const uint8* init_data, | 295 const uint8* init_data, |
307 int init_data_length) { | 296 int init_data_length) { |
308 PP_Var init_data_array = | 297 PP_Var init_data_array = PpapiGlobals::Get()->GetVarTracker() |
309 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 298 ->MakeArrayBufferPPVar(init_data_length, init_data); |
310 init_data_length, init_data); | |
311 | 299 |
312 plugin_decryption_interface_->GenerateKeyRequest( | 300 plugin_decryption_interface_->GenerateKeyRequest( |
313 pp_instance_, | 301 pp_instance_, |
314 StringVar::StringToPPVar(key_system_), // TODO(ddorwin): Remove. | 302 StringVar::StringToPPVar(key_system_), // TODO(ddorwin): Remove. |
315 StringVar::StringToPPVar(type), | 303 StringVar::StringToPPVar(type), init_data_array); |
316 init_data_array); | |
317 return true; | 304 return true; |
318 } | 305 } |
319 | 306 |
320 bool ContentDecryptorDelegate::AddKey(const std::string& session_id, | 307 bool ContentDecryptorDelegate::AddKey(const std::string& session_id, |
321 const uint8* key, | 308 const uint8* key, int key_length, |
322 int key_length, | |
323 const uint8* init_data, | 309 const uint8* init_data, |
324 int init_data_length) { | 310 int init_data_length) { |
325 PP_Var key_array = | 311 PP_Var key_array = PpapiGlobals::Get()->GetVarTracker() |
326 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(key_length, | 312 ->MakeArrayBufferPPVar(key_length, key); |
327 key); | 313 PP_Var init_data_array = PpapiGlobals::Get()->GetVarTracker() |
328 PP_Var init_data_array = | 314 ->MakeArrayBufferPPVar(init_data_length, init_data); |
329 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | |
330 init_data_length, init_data); | |
331 | 315 |
332 plugin_decryption_interface_->AddKey( | 316 plugin_decryption_interface_->AddKey( |
333 pp_instance_, | 317 pp_instance_, StringVar::StringToPPVar(session_id), key_array, |
334 StringVar::StringToPPVar(session_id), | |
335 key_array, | |
336 init_data_array); | 318 init_data_array); |
337 return true; | 319 return true; |
338 } | 320 } |
339 | 321 |
340 bool ContentDecryptorDelegate::CancelKeyRequest(const std::string& session_id) { | 322 bool ContentDecryptorDelegate::CancelKeyRequest(const std::string& session_id) { |
341 plugin_decryption_interface_->CancelKeyRequest( | 323 plugin_decryption_interface_->CancelKeyRequest( |
342 pp_instance_, | 324 pp_instance_, StringVar::StringToPPVar(session_id)); |
343 StringVar::StringToPPVar(session_id)); | |
344 return true; | 325 return true; |
345 } | 326 } |
346 | 327 |
347 // TODO(xhwang): Remove duplication of code in Decrypt(), | 328 // TODO(xhwang): Remove duplication of code in Decrypt(), |
348 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). | 329 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). |
349 bool ContentDecryptorDelegate::Decrypt( | 330 bool ContentDecryptorDelegate::Decrypt( |
350 media::Decryptor::StreamType stream_type, | 331 media::Decryptor::StreamType stream_type, |
351 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 332 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
352 const media::Decryptor::DecryptCB& decrypt_cb) { | 333 const media::Decryptor::DecryptCB& decrypt_cb) { |
353 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; | 334 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; |
354 // |{audio|video}_input_resource_| is not being used by the plugin | 335 // |{audio|video}_input_resource_| is not being used by the plugin |
355 // now because there is only one pending audio/video decrypt request at any | 336 // now because there is only one pending audio/video decrypt request at any |
356 // time. This is enforced by the media pipeline. | 337 // time. This is enforced by the media pipeline. |
357 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; | 338 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
358 if (!MakeMediaBufferResource( | 339 if (!MakeMediaBufferResource(stream_type, encrypted_buffer, |
359 stream_type, encrypted_buffer, &encrypted_resource) || | 340 &encrypted_resource) || |
360 !encrypted_resource.get()) { | 341 !encrypted_resource.get()) { |
361 return false; | 342 return false; |
362 } | 343 } |
363 ScopedPPResource pp_resource(encrypted_resource.get()); | 344 ScopedPPResource pp_resource(encrypted_resource.get()); |
364 | 345 |
365 const uint32_t request_id = next_decryption_request_id_++; | 346 const uint32_t request_id = next_decryption_request_id_++; |
366 DVLOG(2) << "Decrypt() - request_id " << request_id; | 347 DVLOG(2) << "Decrypt() - request_id " << request_id; |
367 | 348 |
368 PP_EncryptedBlockInfo block_info = {}; | 349 PP_EncryptedBlockInfo block_info = {}; |
369 DCHECK(encrypted_buffer->GetDecryptConfig()); | 350 DCHECK(encrypted_buffer->GetDecryptConfig()); |
(...skipping 16 matching lines...) Expand all Loading... | |
386 pending_video_decrypt_request_id_ = request_id; | 367 pending_video_decrypt_request_id_ = request_id; |
387 pending_video_decrypt_cb_ = decrypt_cb; | 368 pending_video_decrypt_cb_ = decrypt_cb; |
388 break; | 369 break; |
389 default: | 370 default: |
390 NOTREACHED(); | 371 NOTREACHED(); |
391 return false; | 372 return false; |
392 } | 373 } |
393 | 374 |
394 SetBufferToFreeInTrackingInfo(&block_info.tracking_info); | 375 SetBufferToFreeInTrackingInfo(&block_info.tracking_info); |
395 | 376 |
396 plugin_decryption_interface_->Decrypt(pp_instance_, | 377 plugin_decryption_interface_->Decrypt(pp_instance_, pp_resource, &block_info); |
397 pp_resource, | |
398 &block_info); | |
399 return true; | 378 return true; |
400 } | 379 } |
401 | 380 |
402 bool ContentDecryptorDelegate::CancelDecrypt( | 381 bool ContentDecryptorDelegate::CancelDecrypt( |
403 media::Decryptor::StreamType stream_type) { | 382 media::Decryptor::StreamType stream_type) { |
404 DVLOG(3) << "CancelDecrypt() - stream_type: " << stream_type; | 383 DVLOG(3) << "CancelDecrypt() - stream_type: " << stream_type; |
405 | 384 |
406 media::Decryptor::DecryptCB decrypt_cb; | 385 media::Decryptor::DecryptCB decrypt_cb; |
407 switch (stream_type) { | 386 switch (stream_type) { |
408 case media::Decryptor::kAudio: | 387 case media::Decryptor::kAudio: |
(...skipping 10 matching lines...) Expand all Loading... | |
419 // buffer. | 398 // buffer. |
420 video_input_resource_ = NULL; | 399 video_input_resource_ = NULL; |
421 pending_video_decrypt_request_id_ = 0; | 400 pending_video_decrypt_request_id_ = 0; |
422 decrypt_cb = base::ResetAndReturn(&pending_video_decrypt_cb_); | 401 decrypt_cb = base::ResetAndReturn(&pending_video_decrypt_cb_); |
423 break; | 402 break; |
424 default: | 403 default: |
425 NOTREACHED(); | 404 NOTREACHED(); |
426 return false; | 405 return false; |
427 } | 406 } |
428 | 407 |
429 if (!decrypt_cb.is_null()) | 408 if (!decrypt_cb.is_null()) decrypt_cb.Run(media::Decryptor::kSuccess, NULL); |
scherkus (not reviewing)
2013/06/21 19:48:38
revert this change -- we don't do single-line ifs
| |
430 decrypt_cb.Run(media::Decryptor::kSuccess, NULL); | |
431 | 409 |
432 return true; | 410 return true; |
433 } | 411 } |
434 | 412 |
435 bool ContentDecryptorDelegate::InitializeAudioDecoder( | 413 bool ContentDecryptorDelegate::InitializeAudioDecoder( |
436 const media::AudioDecoderConfig& decoder_config, | 414 const media::AudioDecoderConfig& decoder_config, |
437 const media::Decryptor::DecoderInitCB& init_cb) { | 415 const media::Decryptor::DecoderInitCB& init_cb) { |
438 PP_AudioDecoderConfig pp_decoder_config; | 416 PP_AudioDecoderConfig pp_decoder_config; |
439 pp_decoder_config.codec = | 417 pp_decoder_config.codec = |
440 MediaAudioCodecToPpAudioCodec(decoder_config.codec()); | 418 MediaAudioCodecToPpAudioCodec(decoder_config.codec()); |
441 pp_decoder_config.channel_count = | 419 pp_decoder_config.channel_count = |
442 media::ChannelLayoutToChannelCount(decoder_config.channel_layout()); | 420 media::ChannelLayoutToChannelCount(decoder_config.channel_layout()); |
443 pp_decoder_config.bits_per_channel = decoder_config.bits_per_channel(); | 421 pp_decoder_config.bits_per_channel = decoder_config.bits_per_channel(); |
444 pp_decoder_config.samples_per_second = decoder_config.samples_per_second(); | 422 pp_decoder_config.samples_per_second = decoder_config.samples_per_second(); |
445 pp_decoder_config.request_id = next_decryption_request_id_++; | 423 pp_decoder_config.request_id = next_decryption_request_id_++; |
446 | 424 |
447 scoped_refptr<PPB_Buffer_Impl> extra_data_resource; | 425 scoped_refptr<PPB_Buffer_Impl> extra_data_resource; |
448 if (!MakeBufferResource(pp_instance_, | 426 if (!MakeBufferResource(pp_instance_, decoder_config.extra_data(), |
449 decoder_config.extra_data(), | |
450 decoder_config.extra_data_size(), | 427 decoder_config.extra_data_size(), |
451 &extra_data_resource)) { | 428 &extra_data_resource)) { |
452 return false; | 429 return false; |
453 } | 430 } |
454 ScopedPPResource pp_resource(extra_data_resource.get()); | 431 ScopedPPResource pp_resource(extra_data_resource.get()); |
455 | 432 |
456 DCHECK_EQ(pending_audio_decoder_init_request_id_, 0u); | 433 DCHECK_EQ(pending_audio_decoder_init_request_id_, 0u); |
457 DCHECK(pending_audio_decoder_init_cb_.is_null()); | 434 DCHECK(pending_audio_decoder_init_cb_.is_null()); |
458 pending_audio_decoder_init_request_id_ = pp_decoder_config.request_id; | 435 pending_audio_decoder_init_request_id_ = pp_decoder_config.request_id; |
459 pending_audio_decoder_init_cb_ = init_cb; | 436 pending_audio_decoder_init_cb_ = init_cb; |
460 | 437 |
461 plugin_decryption_interface_->InitializeAudioDecoder(pp_instance_, | 438 plugin_decryption_interface_->InitializeAudioDecoder( |
462 &pp_decoder_config, | 439 pp_instance_, &pp_decoder_config, pp_resource); |
463 pp_resource); | |
464 return true; | 440 return true; |
465 } | 441 } |
466 | 442 |
467 bool ContentDecryptorDelegate::InitializeVideoDecoder( | 443 bool ContentDecryptorDelegate::InitializeVideoDecoder( |
468 const media::VideoDecoderConfig& decoder_config, | 444 const media::VideoDecoderConfig& decoder_config, |
469 const media::Decryptor::DecoderInitCB& init_cb) { | 445 const media::Decryptor::DecoderInitCB& init_cb) { |
470 PP_VideoDecoderConfig pp_decoder_config; | 446 PP_VideoDecoderConfig pp_decoder_config; |
471 pp_decoder_config.codec = | 447 pp_decoder_config.codec = |
472 MediaVideoCodecToPpVideoCodec(decoder_config.codec()); | 448 MediaVideoCodecToPpVideoCodec(decoder_config.codec()); |
473 pp_decoder_config.profile = | 449 pp_decoder_config.profile = |
474 MediaVideoCodecProfileToPpVideoCodecProfile(decoder_config.profile()); | 450 MediaVideoCodecProfileToPpVideoCodecProfile(decoder_config.profile()); |
475 pp_decoder_config.format = | 451 pp_decoder_config.format = |
476 MediaVideoFormatToPpDecryptedFrameFormat(decoder_config.format()); | 452 MediaVideoFormatToPpDecryptedFrameFormat(decoder_config.format()); |
477 pp_decoder_config.width = decoder_config.coded_size().width(); | 453 pp_decoder_config.width = decoder_config.coded_size().width(); |
478 pp_decoder_config.height = decoder_config.coded_size().height(); | 454 pp_decoder_config.height = decoder_config.coded_size().height(); |
479 pp_decoder_config.request_id = next_decryption_request_id_++; | 455 pp_decoder_config.request_id = next_decryption_request_id_++; |
480 | 456 |
481 scoped_refptr<PPB_Buffer_Impl> extra_data_resource; | 457 scoped_refptr<PPB_Buffer_Impl> extra_data_resource; |
482 if (!MakeBufferResource(pp_instance_, | 458 if (!MakeBufferResource(pp_instance_, decoder_config.extra_data(), |
483 decoder_config.extra_data(), | |
484 decoder_config.extra_data_size(), | 459 decoder_config.extra_data_size(), |
485 &extra_data_resource)) { | 460 &extra_data_resource)) { |
486 return false; | 461 return false; |
487 } | 462 } |
488 ScopedPPResource pp_resource(extra_data_resource.get()); | 463 ScopedPPResource pp_resource(extra_data_resource.get()); |
489 | 464 |
490 DCHECK_EQ(pending_video_decoder_init_request_id_, 0u); | 465 DCHECK_EQ(pending_video_decoder_init_request_id_, 0u); |
491 DCHECK(pending_video_decoder_init_cb_.is_null()); | 466 DCHECK(pending_video_decoder_init_cb_.is_null()); |
492 pending_video_decoder_init_request_id_ = pp_decoder_config.request_id; | 467 pending_video_decoder_init_request_id_ = pp_decoder_config.request_id; |
493 pending_video_decoder_init_cb_ = init_cb; | 468 pending_video_decoder_init_cb_ = init_cb; |
494 | 469 |
495 natural_size_ = decoder_config.natural_size(); | 470 natural_size_ = decoder_config.natural_size(); |
496 | 471 |
497 plugin_decryption_interface_->InitializeVideoDecoder(pp_instance_, | 472 plugin_decryption_interface_->InitializeVideoDecoder( |
498 &pp_decoder_config, | 473 pp_instance_, &pp_decoder_config, pp_resource); |
499 pp_resource); | |
500 return true; | 474 return true; |
501 } | 475 } |
502 | 476 |
503 bool ContentDecryptorDelegate::DeinitializeDecoder( | 477 bool ContentDecryptorDelegate::DeinitializeDecoder( |
504 media::Decryptor::StreamType stream_type) { | 478 media::Decryptor::StreamType stream_type) { |
505 CancelDecode(stream_type); | 479 CancelDecode(stream_type); |
506 | 480 |
507 natural_size_ = gfx::Size(); | 481 natural_size_ = gfx::Size(); |
508 | 482 |
509 // TODO(tomfinegan): Add decoder deinitialize request tracking, and get | 483 // TODO(tomfinegan): Add decoder deinitialize request tracking, and get |
(...skipping 13 matching lines...) Expand all Loading... | |
523 return true; | 497 return true; |
524 } | 498 } |
525 | 499 |
526 bool ContentDecryptorDelegate::DecryptAndDecodeAudio( | 500 bool ContentDecryptorDelegate::DecryptAndDecodeAudio( |
527 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 501 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
528 const media::Decryptor::AudioDecodeCB& audio_decode_cb) { | 502 const media::Decryptor::AudioDecodeCB& audio_decode_cb) { |
529 // |audio_input_resource_| is not being used by the plugin now | 503 // |audio_input_resource_| is not being used by the plugin now |
530 // because there is only one pending audio decode request at any time. | 504 // because there is only one pending audio decode request at any time. |
531 // This is enforced by the media pipeline. | 505 // This is enforced by the media pipeline. |
532 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; | 506 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
533 if (!MakeMediaBufferResource(media::Decryptor::kAudio, | 507 if (!MakeMediaBufferResource(media::Decryptor::kAudio, encrypted_buffer, |
534 encrypted_buffer, | |
535 &encrypted_resource)) { | 508 &encrypted_resource)) { |
536 return false; | 509 return false; |
537 } | 510 } |
538 | 511 |
539 // The resource should not be NULL for non-EOS buffer. | 512 // The resource should not be NULL for non-EOS buffer. |
540 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get()) | 513 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get()) |
541 return false; | 514 return false; |
542 | 515 |
543 const uint32_t request_id = next_decryption_request_id_++; | 516 const uint32_t request_id = next_decryption_request_id_++; |
544 DVLOG(2) << "DecryptAndDecodeAudio() - request_id " << request_id; | 517 DVLOG(2) << "DecryptAndDecodeAudio() - request_id " << request_id; |
545 | 518 |
546 PP_EncryptedBlockInfo block_info = {}; | 519 PP_EncryptedBlockInfo block_info = {}; |
547 if (!MakeEncryptedBlockInfo(encrypted_buffer, request_id, &block_info)) { | 520 if (!MakeEncryptedBlockInfo(encrypted_buffer, request_id, &block_info)) { |
548 return false; | 521 return false; |
549 } | 522 } |
550 | 523 |
551 SetBufferToFreeInTrackingInfo(&block_info.tracking_info); | 524 SetBufferToFreeInTrackingInfo(&block_info.tracking_info); |
552 | 525 |
553 // There is only one pending audio decode request at any time. This is | 526 // There is only one pending audio decode request at any time. This is |
554 // enforced by the media pipeline. If this DCHECK is violated, our buffer | 527 // enforced by the media pipeline. If this DCHECK is violated, our buffer |
555 // reuse policy is not valid, and we may have race problems for the shared | 528 // reuse policy is not valid, and we may have race problems for the shared |
556 // buffer. | 529 // buffer. |
557 DCHECK_EQ(pending_audio_decode_request_id_, 0u); | 530 DCHECK_EQ(pending_audio_decode_request_id_, 0u); |
558 DCHECK(pending_audio_decode_cb_.is_null()); | 531 DCHECK(pending_audio_decode_cb_.is_null()); |
559 pending_audio_decode_request_id_ = request_id; | 532 pending_audio_decode_request_id_ = request_id; |
560 pending_audio_decode_cb_ = audio_decode_cb; | 533 pending_audio_decode_cb_ = audio_decode_cb; |
561 | 534 |
562 ScopedPPResource pp_resource(encrypted_resource.get()); | 535 ScopedPPResource pp_resource(encrypted_resource.get()); |
563 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, | 536 plugin_decryption_interface_->DecryptAndDecode( |
564 PP_DECRYPTORSTREAMTYPE_AUDIO, | 537 pp_instance_, PP_DECRYPTORSTREAMTYPE_AUDIO, pp_resource, &block_info); |
565 pp_resource, | |
566 &block_info); | |
567 return true; | 538 return true; |
568 } | 539 } |
569 | 540 |
570 bool ContentDecryptorDelegate::DecryptAndDecodeVideo( | 541 bool ContentDecryptorDelegate::DecryptAndDecodeVideo( |
571 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 542 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
572 const media::Decryptor::VideoDecodeCB& video_decode_cb) { | 543 const media::Decryptor::VideoDecodeCB& video_decode_cb) { |
573 // |video_input_resource_| is not being used by the plugin now | 544 // |video_input_resource_| is not being used by the plugin now |
574 // because there is only one pending video decode request at any time. | 545 // because there is only one pending video decode request at any time. |
575 // This is enforced by the media pipeline. | 546 // This is enforced by the media pipeline. |
576 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; | 547 scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
577 if (!MakeMediaBufferResource(media::Decryptor::kVideo, | 548 if (!MakeMediaBufferResource(media::Decryptor::kVideo, encrypted_buffer, |
578 encrypted_buffer, | |
579 &encrypted_resource)) { | 549 &encrypted_resource)) { |
580 return false; | 550 return false; |
581 } | 551 } |
582 | 552 |
583 // The resource should not be 0 for non-EOS buffer. | 553 // The resource should not be 0 for non-EOS buffer. |
584 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get()) | 554 if (!encrypted_buffer->IsEndOfStream() && !encrypted_resource.get()) |
585 return false; | 555 return false; |
586 | 556 |
587 const uint32_t request_id = next_decryption_request_id_++; | 557 const uint32_t request_id = next_decryption_request_id_++; |
588 DVLOG(2) << "DecryptAndDecodeVideo() - request_id " << request_id; | 558 DVLOG(2) << "DecryptAndDecodeVideo() - request_id " << request_id; |
(...skipping 11 matching lines...) Expand all Loading... | |
600 // media pipeline. If this DCHECK is violated, our buffer | 570 // media pipeline. If this DCHECK is violated, our buffer |
601 // reuse policy is not valid, and we may have race problems for the shared | 571 // reuse policy is not valid, and we may have race problems for the shared |
602 // buffer. | 572 // buffer. |
603 DCHECK_EQ(pending_video_decode_request_id_, 0u); | 573 DCHECK_EQ(pending_video_decode_request_id_, 0u); |
604 DCHECK(pending_video_decode_cb_.is_null()); | 574 DCHECK(pending_video_decode_cb_.is_null()); |
605 pending_video_decode_request_id_ = request_id; | 575 pending_video_decode_request_id_ = request_id; |
606 pending_video_decode_cb_ = video_decode_cb; | 576 pending_video_decode_cb_ = video_decode_cb; |
607 | 577 |
608 // TODO(tomfinegan): Need to get stream type from media stack. | 578 // TODO(tomfinegan): Need to get stream type from media stack. |
609 ScopedPPResource pp_resource(encrypted_resource.get()); | 579 ScopedPPResource pp_resource(encrypted_resource.get()); |
610 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, | 580 plugin_decryption_interface_->DecryptAndDecode( |
611 PP_DECRYPTORSTREAMTYPE_VIDEO, | 581 pp_instance_, PP_DECRYPTORSTREAMTYPE_VIDEO, pp_resource, &block_info); |
612 pp_resource, | |
613 &block_info); | |
614 return true; | 582 return true; |
615 } | 583 } |
616 | 584 |
617 void ContentDecryptorDelegate::NeedKey(PP_Var key_system_var, | 585 void ContentDecryptorDelegate::NeedKey(PP_Var key_system_var, |
618 PP_Var session_id_var, | 586 PP_Var session_id_var, |
619 PP_Var init_data_var) { | 587 PP_Var init_data_var) { |
620 // TODO(ddorwin): Remove from PPB_ContentDecryptor_Private. | 588 // TODO(ddorwin): Remove from PPB_ContentDecryptor_Private. |
621 NOTREACHED(); | 589 NOTREACHED(); |
622 } | 590 } |
623 | 591 |
624 void ContentDecryptorDelegate::KeyAdded(PP_Var key_system_var, | 592 void ContentDecryptorDelegate::KeyAdded(PP_Var key_system_var, |
625 PP_Var session_id_var) { | 593 PP_Var session_id_var) { |
626 if (key_added_cb_.is_null()) | 594 if (key_added_cb_.is_null()) return; |
scherkus (not reviewing)
2013/06/21 19:48:38
revert this change -- we don't do single-line ifs
| |
627 return; | |
628 | 595 |
629 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 596 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
630 if (!session_id_string) { | 597 if (!session_id_string) { |
631 key_error_cb_.Run(std::string(), media::MediaKeys::kUnknownError, 0); | 598 key_error_cb_.Run(std::string(), media::MediaKeys::kUnknownError, 0); |
632 return; | 599 return; |
633 } | 600 } |
634 | 601 |
635 key_added_cb_.Run(session_id_string->value()); | 602 key_added_cb_.Run(session_id_string->value()); |
636 } | 603 } |
637 | 604 |
638 void ContentDecryptorDelegate::KeyMessage(PP_Var key_system_var, | 605 void ContentDecryptorDelegate::KeyMessage(PP_Var key_system_var, |
639 PP_Var session_id_var, | 606 PP_Var session_id_var, |
640 PP_Var message_var, | 607 PP_Var message_var, |
641 PP_Var default_url_var) { | 608 PP_Var default_url_var) { |
642 if (key_message_cb_.is_null()) | 609 if (key_message_cb_.is_null()) return; |
scherkus (not reviewing)
2013/06/21 19:48:38
revert this change -- we don't do single-line ifs
| |
643 return; | |
644 | 610 |
645 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 611 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
646 | 612 |
647 ArrayBufferVar* message_array_buffer = | 613 ArrayBufferVar* message_array_buffer = ArrayBufferVar::FromPPVar(message_var); |
648 ArrayBufferVar::FromPPVar(message_var); | |
649 | 614 |
650 std::string message; | 615 std::string message; |
651 if (message_array_buffer) { | 616 if (message_array_buffer) { |
652 const char* data = static_cast<const char*>(message_array_buffer->Map()); | 617 const char* data = static_cast<const char*>(message_array_buffer->Map()); |
653 message.assign(data, message_array_buffer->ByteLength()); | 618 message.assign(data, message_array_buffer->ByteLength()); |
654 } | 619 } |
655 | 620 |
656 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); | 621 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); |
657 | 622 |
658 if (!session_id_string || !default_url_string) { | 623 if (!session_id_string || !default_url_string) { |
659 key_error_cb_.Run(std::string(), media::MediaKeys::kUnknownError, 0); | 624 key_error_cb_.Run(std::string(), media::MediaKeys::kUnknownError, 0); |
660 return; | 625 return; |
661 } | 626 } |
662 | 627 |
663 key_message_cb_.Run(session_id_string->value(), | 628 key_message_cb_.Run(session_id_string->value(), message, |
664 message, | |
665 default_url_string->value()); | 629 default_url_string->value()); |
666 } | 630 } |
667 | 631 |
668 void ContentDecryptorDelegate::KeyError(PP_Var key_system_var, | 632 void ContentDecryptorDelegate::KeyError(PP_Var key_system_var, |
669 PP_Var session_id_var, | 633 PP_Var session_id_var, |
670 int32_t media_error, | 634 int32_t media_error, |
671 int32_t system_code) { | 635 int32_t system_code) { |
672 if (key_error_cb_.is_null()) | 636 if (key_error_cb_.is_null()) return; |
scherkus (not reviewing)
2013/06/21 19:48:38
revert this change -- we don't do single-line ifs
| |
673 return; | |
674 | 637 |
675 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 638 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
676 if (!session_id_string) { | 639 if (!session_id_string) { |
677 key_error_cb_.Run(std::string(), media::MediaKeys::kUnknownError, 0); | 640 key_error_cb_.Run(std::string(), media::MediaKeys::kUnknownError, 0); |
678 return; | 641 return; |
679 } | 642 } |
680 | 643 |
681 key_error_cb_.Run(session_id_string->value(), | 644 key_error_cb_.Run(session_id_string->value(), |
682 static_cast<media::MediaKeys::KeyError>(media_error), | 645 static_cast<media::MediaKeys::KeyError>(media_error), |
683 system_code); | 646 system_code); |
684 } | 647 } |
685 | 648 |
686 void ContentDecryptorDelegate::DecoderInitializeDone( | 649 void ContentDecryptorDelegate::DecoderInitializeDone( |
687 PP_DecryptorStreamType decoder_type, | 650 PP_DecryptorStreamType decoder_type, uint32_t request_id, PP_Bool success) { |
688 uint32_t request_id, | |
689 PP_Bool success) { | |
690 if (decoder_type == PP_DECRYPTORSTREAMTYPE_AUDIO) { | 651 if (decoder_type == PP_DECRYPTORSTREAMTYPE_AUDIO) { |
691 // If the request ID is not valid or does not match what's saved, do | 652 // If the request ID is not valid or does not match what's saved, do |
692 // nothing. | 653 // nothing. |
693 if (request_id == 0 || | 654 if (request_id == 0 || request_id != pending_audio_decoder_init_request_id_) |
694 request_id != pending_audio_decoder_init_request_id_) | |
695 return; | 655 return; |
696 | 656 |
697 DCHECK(!pending_audio_decoder_init_cb_.is_null()); | 657 DCHECK(!pending_audio_decoder_init_cb_.is_null()); |
698 pending_audio_decoder_init_request_id_ = 0; | 658 pending_audio_decoder_init_request_id_ = 0; |
699 base::ResetAndReturn( | 659 base::ResetAndReturn(&pending_audio_decoder_init_cb_) |
700 &pending_audio_decoder_init_cb_).Run(PP_ToBool(success)); | 660 .Run(PP_ToBool(success)); |
701 } else { | 661 } else { |
702 if (request_id == 0 || | 662 if (request_id == 0 || request_id != pending_video_decoder_init_request_id_) |
703 request_id != pending_video_decoder_init_request_id_) | |
704 return; | 663 return; |
705 | 664 |
706 if (!success) | 665 if (!success) natural_size_ = gfx::Size(); |
707 natural_size_ = gfx::Size(); | |
708 | 666 |
709 DCHECK(!pending_video_decoder_init_cb_.is_null()); | 667 DCHECK(!pending_video_decoder_init_cb_.is_null()); |
710 pending_video_decoder_init_request_id_ = 0; | 668 pending_video_decoder_init_request_id_ = 0; |
711 base::ResetAndReturn( | 669 base::ResetAndReturn(&pending_video_decoder_init_cb_) |
712 &pending_video_decoder_init_cb_).Run(PP_ToBool(success)); | 670 .Run(PP_ToBool(success)); |
713 } | 671 } |
714 } | 672 } |
715 | 673 |
716 void ContentDecryptorDelegate::DecoderDeinitializeDone( | 674 void ContentDecryptorDelegate::DecoderDeinitializeDone( |
717 PP_DecryptorStreamType decoder_type, | 675 PP_DecryptorStreamType decoder_type, uint32_t request_id) { |
718 uint32_t request_id) { | |
719 // TODO(tomfinegan): Add decoder stop completion handling. | 676 // TODO(tomfinegan): Add decoder stop completion handling. |
720 } | 677 } |
721 | 678 |
722 void ContentDecryptorDelegate::DecoderResetDone( | 679 void ContentDecryptorDelegate::DecoderResetDone( |
723 PP_DecryptorStreamType decoder_type, | 680 PP_DecryptorStreamType decoder_type, uint32_t request_id) { |
724 uint32_t request_id) { | |
725 // TODO(tomfinegan): Add decoder reset completion handling. | 681 // TODO(tomfinegan): Add decoder reset completion handling. |
726 } | 682 } |
727 | 683 |
728 void ContentDecryptorDelegate::DeliverBlock( | 684 void ContentDecryptorDelegate::DeliverBlock( |
729 PP_Resource decrypted_block, | 685 PP_Resource decrypted_block, const PP_DecryptedBlockInfo* block_info) { |
730 const PP_DecryptedBlockInfo* block_info) { | |
731 DCHECK(block_info); | 686 DCHECK(block_info); |
732 | 687 |
733 FreeBuffer(block_info->tracking_info.buffer_id); | 688 FreeBuffer(block_info->tracking_info.buffer_id); |
734 | 689 |
735 const uint32_t request_id = block_info->tracking_info.request_id; | 690 const uint32_t request_id = block_info->tracking_info.request_id; |
736 DVLOG(2) << "DeliverBlock() - request_id: " << request_id; | 691 DVLOG(2) << "DeliverBlock() - request_id: " << request_id; |
737 | 692 |
738 // If the request ID is not valid or does not match what's saved, do nothing. | 693 // If the request ID is not valid or does not match what's saved, do nothing. |
739 if (request_id == 0) { | 694 if (request_id == 0) { |
740 DVLOG(1) << "DeliverBlock() - invalid request_id " << request_id; | 695 DVLOG(1) << "DeliverBlock() - invalid request_id " << request_id; |
(...skipping 29 matching lines...) Expand all Loading... | |
770 BufferAutoMapper mapper(enter.object()); | 725 BufferAutoMapper mapper(enter.object()); |
771 if (!mapper.data() || !mapper.size() || | 726 if (!mapper.data() || !mapper.size() || |
772 mapper.size() < block_info->data_size) { | 727 mapper.size() < block_info->data_size) { |
773 decrypt_cb.Run(media::Decryptor::kError, NULL); | 728 decrypt_cb.Run(media::Decryptor::kError, NULL); |
774 return; | 729 return; |
775 } | 730 } |
776 | 731 |
777 // TODO(tomfinegan): Find a way to take ownership of the shared memory | 732 // TODO(tomfinegan): Find a way to take ownership of the shared memory |
778 // managed by the PPB_Buffer_Dev, and avoid the extra copy. | 733 // managed by the PPB_Buffer_Dev, and avoid the extra copy. |
779 scoped_refptr<media::DecoderBuffer> decrypted_buffer( | 734 scoped_refptr<media::DecoderBuffer> decrypted_buffer( |
780 media::DecoderBuffer::CopyFrom( | 735 media::DecoderBuffer::CopyFrom(static_cast<uint8*>(mapper.data()), |
781 static_cast<uint8*>(mapper.data()), block_info->data_size)); | 736 block_info->data_size)); |
782 decrypted_buffer->SetTimestamp(base::TimeDelta::FromMicroseconds( | 737 decrypted_buffer->SetTimestamp( |
783 block_info->tracking_info.timestamp)); | 738 base::TimeDelta::FromMicroseconds(block_info->tracking_info.timestamp)); |
784 decrypt_cb.Run(media::Decryptor::kSuccess, decrypted_buffer); | 739 decrypt_cb.Run(media::Decryptor::kSuccess, decrypted_buffer); |
785 } | 740 } |
786 | 741 |
787 // Use a non-class-member function here so that if for some reason | 742 // Use a non-class-member function here so that if for some reason |
788 // ContentDecryptorDelegate is destroyed before VideoFrame calls this callback, | 743 // ContentDecryptorDelegate is destroyed before VideoFrame calls this callback, |
789 // we can still get the shared memory unmapped. | 744 // we can still get the shared memory unmapped. |
790 static void BufferNoLongerNeeded( | 745 static void BufferNoLongerNeeded( |
791 const scoped_refptr<PPB_Buffer_Impl>& ppb_buffer, | 746 const scoped_refptr<PPB_Buffer_Impl>& ppb_buffer, |
792 base::Closure buffer_no_longer_needed_cb) { | 747 base::Closure buffer_no_longer_needed_cb) { |
793 ppb_buffer->Unmap(); | 748 ppb_buffer->Unmap(); |
794 buffer_no_longer_needed_cb.Run(); | 749 buffer_no_longer_needed_cb.Run(); |
795 } | 750 } |
796 | 751 |
797 // Enters |resource|, maps shared memory and returns pointer of mapped data. | 752 // Enters |resource|, maps shared memory and returns pointer of mapped data. |
798 // Returns NULL if any error occurs. | 753 // Returns NULL if any error occurs. |
799 static uint8* GetMappedBuffer(PP_Resource resource, | 754 static uint8* GetMappedBuffer(PP_Resource resource, |
800 scoped_refptr<PPB_Buffer_Impl>* ppb_buffer) { | 755 scoped_refptr<PPB_Buffer_Impl>* ppb_buffer) { |
801 EnterResourceNoLock<PPB_Buffer_API> enter(resource, true); | 756 EnterResourceNoLock<PPB_Buffer_API> enter(resource, true); |
802 if (!enter.succeeded()) | 757 if (!enter.succeeded()) return NULL; |
scherkus (not reviewing)
2013/06/21 19:48:38
revert this change -- we don't do single-line ifs
| |
803 return NULL; | |
804 | 758 |
805 uint8* mapped_data = static_cast<uint8*>(enter.object()->Map()); | 759 uint8* mapped_data = static_cast<uint8*>(enter.object()->Map()); |
806 if (!enter.object()->IsMapped() || !mapped_data) | 760 if (!enter.object()->IsMapped() || !mapped_data) return NULL; |
807 return NULL; | |
808 | 761 |
809 uint32_t mapped_size = 0; | 762 uint32_t mapped_size = 0; |
810 if (!enter.object()->Describe(&mapped_size) || !mapped_size) { | 763 if (!enter.object()->Describe(&mapped_size) || !mapped_size) { |
811 enter.object()->Unmap(); | 764 enter.object()->Unmap(); |
812 return NULL; | 765 return NULL; |
813 } | 766 } |
814 | 767 |
815 *ppb_buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); | 768 *ppb_buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); |
816 | 769 |
817 return mapped_data; | 770 return mapped_data; |
818 } | 771 } |
819 | 772 |
820 void ContentDecryptorDelegate::DeliverFrame( | 773 void ContentDecryptorDelegate::DeliverFrame( |
821 PP_Resource decrypted_frame, | 774 PP_Resource decrypted_frame, const PP_DecryptedFrameInfo* frame_info) { |
822 const PP_DecryptedFrameInfo* frame_info) { | |
823 DCHECK(frame_info); | 775 DCHECK(frame_info); |
824 | 776 |
825 const uint32_t request_id = frame_info->tracking_info.request_id; | 777 const uint32_t request_id = frame_info->tracking_info.request_id; |
826 DVLOG(2) << "DeliverFrame() - request_id: " << request_id; | 778 DVLOG(2) << "DeliverFrame() - request_id: " << request_id; |
827 | 779 |
828 // If the request ID is not valid or does not match what's saved, do nothing. | 780 // If the request ID is not valid or does not match what's saved, do nothing. |
829 if (request_id == 0 || request_id != pending_video_decode_request_id_) { | 781 if (request_id == 0 || request_id != pending_video_decode_request_id_) { |
830 DVLOG(1) << "DeliverFrame() - request_id " << request_id << " not found"; | 782 DVLOG(1) << "DeliverFrame() - request_id " << request_id << " not found"; |
831 FreeBuffer(frame_info->tracking_info.buffer_id); | 783 FreeBuffer(frame_info->tracking_info.buffer_id); |
832 return; | 784 return; |
(...skipping 21 matching lines...) Expand all Loading... | |
854 FreeBuffer(frame_info->tracking_info.buffer_id); | 806 FreeBuffer(frame_info->tracking_info.buffer_id); |
855 video_decode_cb.Run(media::Decryptor::kError, NULL); | 807 video_decode_cb.Run(media::Decryptor::kError, NULL); |
856 return; | 808 return; |
857 } | 809 } |
858 | 810 |
859 gfx::Size frame_size(frame_info->width, frame_info->height); | 811 gfx::Size frame_size(frame_info->width, frame_info->height); |
860 DCHECK_EQ(frame_info->format, PP_DECRYPTEDFRAMEFORMAT_YV12); | 812 DCHECK_EQ(frame_info->format, PP_DECRYPTEDFRAMEFORMAT_YV12); |
861 | 813 |
862 scoped_refptr<media::VideoFrame> decoded_frame = | 814 scoped_refptr<media::VideoFrame> decoded_frame = |
863 media::VideoFrame::WrapExternalYuvData( | 815 media::VideoFrame::WrapExternalYuvData( |
864 media::VideoFrame::YV12, | 816 media::VideoFrame::YV12, frame_size, gfx::Rect(frame_size), |
865 frame_size, gfx::Rect(frame_size), natural_size_, | 817 natural_size_, frame_info->strides[PP_DECRYPTEDFRAMEPLANES_Y], |
866 frame_info->strides[PP_DECRYPTEDFRAMEPLANES_Y], | |
867 frame_info->strides[PP_DECRYPTEDFRAMEPLANES_U], | 818 frame_info->strides[PP_DECRYPTEDFRAMEPLANES_U], |
868 frame_info->strides[PP_DECRYPTEDFRAMEPLANES_V], | 819 frame_info->strides[PP_DECRYPTEDFRAMEPLANES_V], |
869 frame_data + frame_info->plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y], | 820 frame_data + frame_info->plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y], |
870 frame_data + frame_info->plane_offsets[PP_DECRYPTEDFRAMEPLANES_U], | 821 frame_data + frame_info->plane_offsets[PP_DECRYPTEDFRAMEPLANES_U], |
871 frame_data + frame_info->plane_offsets[PP_DECRYPTEDFRAMEPLANES_V], | 822 frame_data + frame_info->plane_offsets[PP_DECRYPTEDFRAMEPLANES_V], |
872 base::TimeDelta::FromMicroseconds( | 823 base::TimeDelta::FromMicroseconds( |
873 frame_info->tracking_info.timestamp), | 824 frame_info->tracking_info.timestamp), |
874 media::BindToLoop( | 825 media::BindToLoop( |
875 base::MessageLoopProxy::current(), | 826 base::MessageLoopProxy::current(), |
876 base::Bind(&BufferNoLongerNeeded, ppb_buffer, | 827 base::Bind( |
877 base::Bind(&ContentDecryptorDelegate::FreeBuffer, | 828 &BufferNoLongerNeeded, ppb_buffer, |
878 weak_this_, | 829 base::Bind(&ContentDecryptorDelegate::FreeBuffer, weak_this_, |
879 frame_info->tracking_info.buffer_id)))); | 830 frame_info->tracking_info.buffer_id)))); |
880 | 831 |
881 video_decode_cb.Run(media::Decryptor::kSuccess, decoded_frame); | 832 video_decode_cb.Run(media::Decryptor::kSuccess, decoded_frame); |
882 } | 833 } |
883 | 834 |
884 void ContentDecryptorDelegate::DeliverSamples( | 835 void ContentDecryptorDelegate::DeliverSamples( |
885 PP_Resource audio_frames, | 836 PP_Resource audio_frames, const PP_DecryptedBlockInfo* block_info) { |
886 const PP_DecryptedBlockInfo* block_info) { | |
887 DCHECK(block_info); | 837 DCHECK(block_info); |
888 | 838 |
889 FreeBuffer(block_info->tracking_info.buffer_id); | 839 FreeBuffer(block_info->tracking_info.buffer_id); |
890 | 840 |
891 const uint32_t request_id = block_info->tracking_info.request_id; | 841 const uint32_t request_id = block_info->tracking_info.request_id; |
892 DVLOG(2) << "DeliverSamples() - request_id: " << request_id; | 842 DVLOG(2) << "DeliverSamples() - request_id: " << request_id; |
893 | 843 |
894 // If the request ID is not valid or does not match what's saved, do nothing. | 844 // If the request ID is not valid or does not match what's saved, do nothing. |
895 if (request_id == 0 || request_id != pending_audio_decode_request_id_) { | 845 if (request_id == 0 || request_id != pending_audio_decode_request_id_) { |
896 DVLOG(1) << "DeliverSamples() - request_id " << request_id << " not found"; | 846 DVLOG(1) << "DeliverSamples() - request_id " << request_id << " not found"; |
897 return; | 847 return; |
898 } | 848 } |
899 | 849 |
900 DCHECK(!pending_audio_decode_cb_.is_null()); | 850 DCHECK(!pending_audio_decode_cb_.is_null()); |
901 pending_audio_decode_request_id_ = 0; | 851 pending_audio_decode_request_id_ = 0; |
902 media::Decryptor::AudioDecodeCB audio_decode_cb = | 852 media::Decryptor::AudioDecodeCB audio_decode_cb = |
903 base::ResetAndReturn(&pending_audio_decode_cb_); | 853 base::ResetAndReturn(&pending_audio_decode_cb_); |
904 | 854 |
905 const media::Decryptor::AudioBuffers empty_frames; | 855 const media::Decryptor::AudioBuffers empty_frames; |
906 | 856 |
907 media::Decryptor::Status status = | 857 media::Decryptor::Status status = |
908 PpDecryptResultToMediaDecryptorStatus(block_info->result); | 858 PpDecryptResultToMediaDecryptorStatus(block_info->result); |
909 if (status != media::Decryptor::kSuccess) { | 859 if (status != media::Decryptor::kSuccess) { |
910 audio_decode_cb.Run(status, empty_frames); | 860 audio_decode_cb.Run(status, empty_frames); |
911 return; | 861 return; |
912 } | 862 } |
913 | 863 |
914 media::Decryptor::AudioBuffers audio_frame_list; | 864 media::Decryptor::AudioBuffers audio_frame_list; |
915 if (!DeserializeAudioFrames(audio_frames, | 865 if (!DeserializeAudioFrames(audio_frames, block_info->data_size, |
916 block_info->data_size, | |
917 &audio_frame_list)) { | 866 &audio_frame_list)) { |
918 NOTREACHED() << "CDM did not serialize the buffer correctly."; | 867 NOTREACHED() << "CDM did not serialize the buffer correctly."; |
919 audio_decode_cb.Run(media::Decryptor::kError, empty_frames); | 868 audio_decode_cb.Run(media::Decryptor::kError, empty_frames); |
920 return; | 869 return; |
921 } | 870 } |
922 | 871 |
923 audio_decode_cb.Run(media::Decryptor::kSuccess, audio_frame_list); | 872 audio_decode_cb.Run(media::Decryptor::kSuccess, audio_frame_list); |
924 } | 873 } |
925 | 874 |
926 // TODO(xhwang): Try to remove duplicate logic here and in CancelDecrypt(). | 875 // TODO(xhwang): Try to remove duplicate logic here and in CancelDecrypt(). |
927 void ContentDecryptorDelegate::CancelDecode( | 876 void ContentDecryptorDelegate::CancelDecode( |
928 media::Decryptor::StreamType stream_type) { | 877 media::Decryptor::StreamType stream_type) { |
929 switch (stream_type) { | 878 switch (stream_type) { |
930 case media::Decryptor::kAudio: | 879 case media::Decryptor::kAudio: |
931 // Release the shared memory as it can still be in use by the plugin. | 880 // Release the shared memory as it can still be in use by the plugin. |
932 // The next DecryptAndDecode() call will need to allocate a new shared | 881 // The next DecryptAndDecode() call will need to allocate a new shared |
933 // memory buffer. | 882 // memory buffer. |
934 audio_input_resource_ = NULL; | 883 audio_input_resource_ = NULL; |
935 pending_audio_decode_request_id_ = 0; | 884 pending_audio_decode_request_id_ = 0; |
936 if (!pending_audio_decode_cb_.is_null()) | 885 if (!pending_audio_decode_cb_.is_null()) |
937 base::ResetAndReturn(&pending_audio_decode_cb_).Run( | 886 base::ResetAndReturn(&pending_audio_decode_cb_) |
938 media::Decryptor::kSuccess, media::Decryptor::AudioBuffers()); | 887 .Run(media::Decryptor::kSuccess, media::Decryptor::AudioBuffers()); |
939 break; | 888 break; |
940 case media::Decryptor::kVideo: | 889 case media::Decryptor::kVideo: |
941 // Release the shared memory as it can still be in use by the plugin. | 890 // Release the shared memory as it can still be in use by the plugin. |
942 // The next DecryptAndDecode() call will need to allocate a new shared | 891 // The next DecryptAndDecode() call will need to allocate a new shared |
943 // memory buffer. | 892 // memory buffer. |
944 video_input_resource_ = NULL; | 893 video_input_resource_ = NULL; |
945 pending_video_decode_request_id_ = 0; | 894 pending_video_decode_request_id_ = 0; |
946 if (!pending_video_decode_cb_.is_null()) | 895 if (!pending_video_decode_cb_.is_null()) |
947 base::ResetAndReturn(&pending_video_decode_cb_).Run( | 896 base::ResetAndReturn(&pending_video_decode_cb_) |
948 media::Decryptor::kSuccess, NULL); | 897 .Run(media::Decryptor::kSuccess, NULL); |
949 break; | 898 break; |
950 default: | 899 default: |
951 NOTREACHED(); | 900 NOTREACHED(); |
952 } | 901 } |
953 } | 902 } |
954 | 903 |
955 bool ContentDecryptorDelegate::MakeMediaBufferResource( | 904 bool ContentDecryptorDelegate::MakeMediaBufferResource( |
956 media::Decryptor::StreamType stream_type, | 905 media::Decryptor::StreamType stream_type, |
957 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 906 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
958 scoped_refptr<PPB_Buffer_Impl>* resource) { | 907 scoped_refptr<PPB_Buffer_Impl>* resource) { |
959 TRACE_EVENT0("eme", "ContentDecryptorDelegate::MakeMediaBufferResource"); | 908 TRACE_EVENT0("eme", "ContentDecryptorDelegate::MakeMediaBufferResource"); |
960 | 909 |
961 // End of stream buffers are represented as null resources. | 910 // End of stream buffers are represented as null resources. |
962 if (encrypted_buffer->IsEndOfStream()) { | 911 if (encrypted_buffer->IsEndOfStream()) { |
963 *resource = NULL; | 912 *resource = NULL; |
964 return true; | 913 return true; |
965 } | 914 } |
966 | 915 |
967 DCHECK(stream_type == media::Decryptor::kAudio || | 916 DCHECK(stream_type == media::Decryptor::kAudio || |
968 stream_type == media::Decryptor::kVideo); | 917 stream_type == media::Decryptor::kVideo); |
969 scoped_refptr<PPB_Buffer_Impl>& media_resource = | 918 scoped_refptr<PPB_Buffer_Impl>& media_resource = |
970 (stream_type == media::Decryptor::kAudio) ? audio_input_resource_ : | 919 (stream_type == media::Decryptor::kAudio) ? audio_input_resource_ |
971 video_input_resource_; | 920 : video_input_resource_; |
972 | 921 |
973 const size_t data_size = static_cast<size_t>(encrypted_buffer->GetDataSize()); | 922 const size_t data_size = static_cast<size_t>(encrypted_buffer->GetDataSize()); |
974 if (!media_resource.get() || media_resource->size() < data_size) { | 923 if (!media_resource.get() || media_resource->size() < data_size) { |
975 // Either the buffer hasn't been created yet, or we have one that isn't big | 924 // Either the buffer hasn't been created yet, or we have one that isn't big |
976 // enough to fit |size| bytes. | 925 // enough to fit |size| bytes. |
977 | 926 |
978 // Media resource size starts from |kMinimumMediaBufferSize| and grows | 927 // Media resource size starts from |kMinimumMediaBufferSize| and grows |
979 // exponentially to avoid frequent re-allocation of PPB_Buffer_Impl, | 928 // exponentially to avoid frequent re-allocation of PPB_Buffer_Impl, |
980 // which is usually expensive. Since input media buffers are compressed, | 929 // which is usually expensive. Since input media buffers are compressed, |
981 // they are usually small (compared to outputs). The over-allocated memory | 930 // they are usually small (compared to outputs). The over-allocated memory |
982 // should be negligible. | 931 // should be negligible. |
983 const uint32_t kMinimumMediaBufferSize = 1024; | 932 const uint32_t kMinimumMediaBufferSize = 1024; |
984 uint32_t media_resource_size = | 933 uint32_t media_resource_size = |
985 media_resource.get() ? media_resource->size() : kMinimumMediaBufferSize; | 934 media_resource.get() ? media_resource->size() : kMinimumMediaBufferSize; |
986 while (media_resource_size < data_size) | 935 while (media_resource_size < data_size) media_resource_size *= 2; |
scherkus (not reviewing)
2013/06/21 19:48:38
revert this change -- we don't do single-line whil
| |
987 media_resource_size *= 2; | |
988 | 936 |
989 DVLOG(2) << "Size of media buffer for " | 937 DVLOG(2) << "Size of media buffer for " |
990 << ((stream_type == media::Decryptor::kAudio) ? "audio" : "video") | 938 << ((stream_type == media::Decryptor::kAudio) ? "audio" : "video") |
991 << " stream bumped to " << media_resource_size | 939 << " stream bumped to " << media_resource_size |
992 << " bytes to fit input."; | 940 << " bytes to fit input."; |
993 media_resource = PPB_Buffer_Impl::CreateResource(pp_instance_, | 941 media_resource = |
994 media_resource_size); | 942 PPB_Buffer_Impl::CreateResource(pp_instance_, media_resource_size); |
995 if (!media_resource.get()) | 943 if (!media_resource.get()) return false; |
996 return false; | |
997 } | 944 } |
998 | 945 |
999 BufferAutoMapper mapper(media_resource.get()); | 946 BufferAutoMapper mapper(media_resource.get()); |
1000 if (!mapper.data() || mapper.size() < data_size) { | 947 if (!mapper.data() || mapper.size() < data_size) { |
1001 media_resource = NULL; | 948 media_resource = NULL; |
1002 return false; | 949 return false; |
1003 } | 950 } |
1004 memcpy(mapper.data(), encrypted_buffer->GetData(), data_size); | 951 memcpy(mapper.data(), encrypted_buffer->GetData(), data_size); |
1005 | 952 |
1006 *resource = media_resource; | 953 *resource = media_resource; |
1007 return true; | 954 return true; |
1008 } | 955 } |
1009 | 956 |
1010 void ContentDecryptorDelegate::FreeBuffer(uint32_t buffer_id) { | 957 void ContentDecryptorDelegate::FreeBuffer(uint32_t buffer_id) { |
1011 if (buffer_id) | 958 if (buffer_id) free_buffers_.push(buffer_id); |
scherkus (not reviewing)
2013/06/21 19:48:38
revert this change -- we don't do single-line ifs
| |
1012 free_buffers_.push(buffer_id); | |
1013 } | 959 } |
1014 | 960 |
1015 void ContentDecryptorDelegate::SetBufferToFreeInTrackingInfo( | 961 void ContentDecryptorDelegate::SetBufferToFreeInTrackingInfo( |
1016 PP_DecryptTrackingInfo* tracking_info) { | 962 PP_DecryptTrackingInfo* tracking_info) { |
1017 DCHECK_EQ(tracking_info->buffer_id, 0u); | 963 DCHECK_EQ(tracking_info->buffer_id, 0u); |
1018 | 964 |
1019 if (free_buffers_.empty()) | 965 if (free_buffers_.empty()) return; |
scherkus (not reviewing)
2013/06/21 19:48:38
revert this change -- we don't do single-line ifs
| |
1020 return; | |
1021 | 966 |
1022 tracking_info->buffer_id = free_buffers_.front(); | 967 tracking_info->buffer_id = free_buffers_.front(); |
1023 free_buffers_.pop(); | 968 free_buffers_.pop(); |
1024 } | 969 } |
1025 | 970 |
1026 } // namespace ppapi | 971 } // namespace ppapi |
1027 } // namespace webkit | 972 } // namespace webkit |
OLD | NEW |