Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: webkit/plugins/ppapi/content_decryptor_delegate.cc

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

Powered by Google App Engine
This is Rietveld 408576698