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

Side by Side Diff: content/renderer/pepper/content_decryptor_delegate.cc

Issue 1072403009: Use std::vector<uint8_t> instead of uint8*/int for MediaKeys interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add includes Created 5 years, 8 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 "content/renderer/pepper/content_decryptor_delegate.h" 5 #include "content/renderer/pepper/content_decryptor_delegate.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/metrics/sparse_histogram.h" 9 #include "base/metrics/sparse_histogram.h"
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
11 #include "base/stl_util.h"
11 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
12 #include "content/renderer/pepper/ppb_buffer_impl.h" 13 #include "content/renderer/pepper/ppb_buffer_impl.h"
13 #include "media/base/audio_buffer.h" 14 #include "media/base/audio_buffer.h"
14 #include "media/base/audio_decoder_config.h" 15 #include "media/base/audio_decoder_config.h"
15 #include "media/base/bind_to_current_loop.h" 16 #include "media/base/bind_to_current_loop.h"
16 #include "media/base/cdm_key_information.h" 17 #include "media/base/cdm_key_information.h"
17 #include "media/base/channel_layout.h" 18 #include "media/base/channel_layout.h"
18 #include "media/base/data_buffer.h" 19 #include "media/base/data_buffer.h"
19 #include "media/base/decoder_buffer.h" 20 #include "media/base/decoder_buffer.h"
20 #include "media/base/decrypt_config.h" 21 #include "media/base/decrypt_config.h"
(...skipping 25 matching lines...) Expand all
46 47
47 namespace content { 48 namespace content {
48 49
49 namespace { 50 namespace {
50 51
51 // Fills |resource| with a PPB_Buffer_Impl and copies |data| into the buffer 52 // Fills |resource| with a PPB_Buffer_Impl and copies |data| into the buffer
52 // resource. The |*resource|, if valid, will be in the ResourceTracker with a 53 // resource. The |*resource|, if valid, will be in the ResourceTracker with a
53 // reference-count of 0. If |data| is NULL, sets |*resource| to NULL. Returns 54 // reference-count of 0. If |data| is NULL, sets |*resource| to NULL. Returns
54 // true upon success and false if any error happened. 55 // true upon success and false if any error happened.
55 bool MakeBufferResource(PP_Instance instance, 56 bool MakeBufferResource(PP_Instance instance,
56 const uint8* data, 57 const uint8_t* data,
57 uint32_t size, 58 uint32_t size,
58 scoped_refptr<PPB_Buffer_Impl>* resource) { 59 scoped_refptr<PPB_Buffer_Impl>* resource) {
59 TRACE_EVENT0("media", "ContentDecryptorDelegate - MakeBufferResource"); 60 TRACE_EVENT0("media", "ContentDecryptorDelegate - MakeBufferResource");
60 DCHECK(resource); 61 DCHECK(resource);
61 62
62 if (!data || !size) { 63 if (!data || !size) {
63 DCHECK(!data && !size); 64 DCHECK(!data && !size);
64 resource = NULL; 65 resource = NULL;
65 return true; 66 return true;
66 } 67 }
67 68
68 scoped_refptr<PPB_Buffer_Impl> buffer( 69 scoped_refptr<PPB_Buffer_Impl> buffer(
69 PPB_Buffer_Impl::CreateResource(instance, size)); 70 PPB_Buffer_Impl::CreateResource(instance, size));
70 if (!buffer.get()) 71 if (!buffer.get())
71 return false; 72 return false;
72 73
73 BufferAutoMapper mapper(buffer.get()); 74 BufferAutoMapper mapper(buffer.get());
74 if (!mapper.data() || mapper.size() < size) 75 if (!mapper.data() || mapper.size() < size)
75 return false; 76 return false;
76 memcpy(mapper.data(), data, size); 77 memcpy(mapper.data(), data, size);
77 78
78 *resource = buffer; 79 *resource = buffer;
79 return true; 80 return true;
80 } 81 }
81 82
82 // Copies the content of |str| into |array|. 83 // Copies the content of |str| into |array|.
83 // Returns true if copy succeeded. Returns false if copy failed, e.g. if the 84 // Returns true if copy succeeded. Returns false if copy failed, e.g. if the
84 // |array_size| is smaller than the |str| length. 85 // |array_size| is smaller than the |str| length.
85 template <uint32_t array_size> 86 template <uint32_t array_size>
86 bool CopyStringToArray(const std::string& str, uint8 (&array)[array_size]) { 87 bool CopyStringToArray(const std::string& str, uint8_t(&array)[array_size]) {
87 if (array_size < str.size()) 88 if (array_size < str.size())
88 return false; 89 return false;
89 90
90 memcpy(array, str.data(), str.size()); 91 memcpy(array, str.data(), str.size());
91 return true; 92 return true;
92 } 93 }
93 94
94 // Fills the |block_info| with information from |encrypted_buffer|. 95 // Fills the |block_info| with information from |encrypted_buffer|.
95 // 96 //
96 // Returns true if |block_info| is successfully filled. Returns false 97 // Returns true if |block_info| is successfully filled. Returns false
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 case PP_CDMMESSAGETYPE_LICENSE_RELEASE: 339 case PP_CDMMESSAGETYPE_LICENSE_RELEASE:
339 return MediaKeys::LICENSE_RELEASE; 340 return MediaKeys::LICENSE_RELEASE;
340 default: 341 default:
341 NOTREACHED(); 342 NOTREACHED();
342 return MediaKeys::LICENSE_REQUEST; 343 return MediaKeys::LICENSE_REQUEST;
343 } 344 }
344 } 345 }
345 346
346 // TODO(xhwang): Unify EME UMA reporting code when prefixed EME is deprecated. 347 // TODO(xhwang): Unify EME UMA reporting code when prefixed EME is deprecated.
347 // See http://crbug.com/412987 for details. 348 // See http://crbug.com/412987 for details.
348 void ReportSystemCodeUMA(const std::string& key_system, uint32 system_code) { 349 void ReportSystemCodeUMA(const std::string& key_system, uint32_t system_code) {
349 // Sparse histogram macro does not cache the histogram, so it's safe to use 350 // Sparse histogram macro does not cache the histogram, so it's safe to use
350 // macro with non-static histogram name here. 351 // macro with non-static histogram name here.
351 UMA_HISTOGRAM_SPARSE_SLOWLY( 352 UMA_HISTOGRAM_SPARSE_SLOWLY(
352 "Media.EME." + media::GetKeySystemNameForUMA(key_system) + ".SystemCode", 353 "Media.EME." + media::GetKeySystemNameForUMA(key_system) + ".SystemCode",
353 system_code); 354 system_code);
354 } 355 }
355 356
356 } // namespace 357 } // namespace
357 358
358 ContentDecryptorDelegate::ContentDecryptorDelegate( 359 ContentDecryptorDelegate::ContentDecryptorDelegate(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 PP_FromBool(allow_distinctive_identifier), 399 PP_FromBool(allow_distinctive_identifier),
399 PP_FromBool(allow_persistent_state)); 400 PP_FromBool(allow_persistent_state));
400 } 401 }
401 402
402 void ContentDecryptorDelegate::InstanceCrashed() { 403 void ContentDecryptorDelegate::InstanceCrashed() {
403 fatal_plugin_error_cb_.Run(); 404 fatal_plugin_error_cb_.Run();
404 SatisfyAllPendingCallbacksOnError(); 405 SatisfyAllPendingCallbacksOnError();
405 } 406 }
406 407
407 void ContentDecryptorDelegate::SetServerCertificate( 408 void ContentDecryptorDelegate::SetServerCertificate(
408 const uint8_t* certificate, 409 const std::vector<uint8_t>& certificate,
409 uint32_t certificate_length,
410 scoped_ptr<media::SimpleCdmPromise> promise) { 410 scoped_ptr<media::SimpleCdmPromise> promise) {
411 if (!certificate || 411 if (certificate.size() < media::limits::kMinCertificateLength ||
412 certificate_length < media::limits::kMinCertificateLength || 412 certificate.size() > media::limits::kMaxCertificateLength) {
413 certificate_length > media::limits::kMaxCertificateLength) {
414 promise->reject( 413 promise->reject(
415 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect certificate."); 414 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect certificate.");
416 return; 415 return;
417 } 416 }
418 417
419 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); 418 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass());
420 PP_Var certificate_array = 419 PP_Var certificate_array =
421 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( 420 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
422 certificate_length, certificate); 421 certificate.size(), vector_as_array(&certificate));
bbudge 2015/04/23 17:35:39 You should probably have a base::checked_cast to n
jrummell 2015/04/23 20:22:43 Done.
423 plugin_decryption_interface_->SetServerCertificate( 422 plugin_decryption_interface_->SetServerCertificate(
424 pp_instance_, promise_id, certificate_array); 423 pp_instance_, promise_id, certificate_array);
425 } 424 }
426 425
427 void ContentDecryptorDelegate::CreateSessionAndGenerateRequest( 426 void ContentDecryptorDelegate::CreateSessionAndGenerateRequest(
428 MediaKeys::SessionType session_type, 427 MediaKeys::SessionType session_type,
429 media::EmeInitDataType init_data_type, 428 media::EmeInitDataType init_data_type,
430 const uint8* init_data, 429 const std::vector<uint8_t>& init_data,
431 int init_data_length,
432 scoped_ptr<NewSessionCdmPromise> promise) { 430 scoped_ptr<NewSessionCdmPromise> promise) {
433 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); 431 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass());
434 PP_Var init_data_array = 432 PP_Var init_data_array =
435 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( 433 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
436 init_data_length, init_data); 434 init_data.size(), vector_as_array(&init_data));
437 plugin_decryption_interface_->CreateSessionAndGenerateRequest( 435 plugin_decryption_interface_->CreateSessionAndGenerateRequest(
438 pp_instance_, promise_id, MediaSessionTypeToPpSessionType(session_type), 436 pp_instance_, promise_id, MediaSessionTypeToPpSessionType(session_type),
439 MediaInitDataTypeToPpInitDataType(init_data_type), init_data_array); 437 MediaInitDataTypeToPpInitDataType(init_data_type), init_data_array);
440 } 438 }
441 439
442 void ContentDecryptorDelegate::LoadSession( 440 void ContentDecryptorDelegate::LoadSession(
443 media::MediaKeys::SessionType session_type, 441 media::MediaKeys::SessionType session_type,
444 const std::string& session_id, 442 const std::string& session_id,
445 scoped_ptr<NewSessionCdmPromise> promise) { 443 scoped_ptr<NewSessionCdmPromise> promise) {
446 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); 444 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass());
447 plugin_decryption_interface_->LoadSession( 445 plugin_decryption_interface_->LoadSession(
448 pp_instance_, promise_id, MediaSessionTypeToPpSessionType(session_type), 446 pp_instance_, promise_id, MediaSessionTypeToPpSessionType(session_type),
449 StringVar::StringToPPVar(session_id)); 447 StringVar::StringToPPVar(session_id));
450 } 448 }
451 449
452 void ContentDecryptorDelegate::UpdateSession( 450 void ContentDecryptorDelegate::UpdateSession(
453 const std::string& session_id, 451 const std::string& session_id,
454 const uint8* response, 452 const std::vector<uint8_t>& response,
455 int response_length,
456 scoped_ptr<SimpleCdmPromise> promise) { 453 scoped_ptr<SimpleCdmPromise> promise) {
457 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); 454 uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass());
458 PP_Var response_array = 455 PP_Var response_array =
459 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( 456 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
460 response_length, response); 457 response.size(), vector_as_array(&response));
461 plugin_decryption_interface_->UpdateSession( 458 plugin_decryption_interface_->UpdateSession(
462 pp_instance_, promise_id, StringVar::StringToPPVar(session_id), 459 pp_instance_, promise_id, StringVar::StringToPPVar(session_id),
463 response_array); 460 response_array);
464 } 461 }
465 462
466 void ContentDecryptorDelegate::CloseSession( 463 void ContentDecryptorDelegate::CloseSession(
467 const std::string& session_id, 464 const std::string& session_id,
468 scoped_ptr<SimpleCdmPromise> promise) { 465 scoped_ptr<SimpleCdmPromise> promise) {
469 if (session_id.length() > media::limits::kMaxSessionIdLength) { 466 if (session_id.length() > media::limits::kMaxSessionIdLength) {
470 promise->reject( 467 promise->reject(
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 // buffer. 724 // buffer.
728 video_decode_cb_.Set(request_id, video_decode_cb); 725 video_decode_cb_.Set(request_id, video_decode_cb);
729 726
730 // TODO(tomfinegan): Need to get stream type from media stack. 727 // TODO(tomfinegan): Need to get stream type from media stack.
731 ScopedPPResource pp_resource(encrypted_resource.get()); 728 ScopedPPResource pp_resource(encrypted_resource.get());
732 plugin_decryption_interface_->DecryptAndDecode( 729 plugin_decryption_interface_->DecryptAndDecode(
733 pp_instance_, PP_DECRYPTORSTREAMTYPE_VIDEO, pp_resource, &block_info); 730 pp_instance_, PP_DECRYPTORSTREAMTYPE_VIDEO, pp_resource, &block_info);
734 return true; 731 return true;
735 } 732 }
736 733
737 void ContentDecryptorDelegate::OnPromiseResolved(uint32 promise_id) { 734 void ContentDecryptorDelegate::OnPromiseResolved(uint32_t promise_id) {
738 cdm_promise_adapter_.ResolvePromise(promise_id); 735 cdm_promise_adapter_.ResolvePromise(promise_id);
739 } 736 }
740 737
741 void ContentDecryptorDelegate::OnPromiseResolvedWithSession(uint32 promise_id, 738 void ContentDecryptorDelegate::OnPromiseResolvedWithSession(uint32_t promise_id,
742 PP_Var session_id) { 739 PP_Var session_id) {
743 StringVar* session_id_string = StringVar::FromPPVar(session_id); 740 StringVar* session_id_string = StringVar::FromPPVar(session_id);
744 DCHECK(session_id_string); 741 DCHECK(session_id_string);
745 cdm_promise_adapter_.ResolvePromise(promise_id, session_id_string->value()); 742 cdm_promise_adapter_.ResolvePromise(promise_id, session_id_string->value());
746 } 743 }
747 744
748 void ContentDecryptorDelegate::OnPromiseRejected( 745 void ContentDecryptorDelegate::OnPromiseRejected(
749 uint32 promise_id, 746 uint32_t promise_id,
750 PP_CdmExceptionCode exception_code, 747 PP_CdmExceptionCode exception_code,
751 uint32 system_code, 748 uint32_t system_code,
752 PP_Var error_description) { 749 PP_Var error_description) {
753 ReportSystemCodeUMA(key_system_, system_code); 750 ReportSystemCodeUMA(key_system_, system_code);
754 751
755 StringVar* error_description_string = StringVar::FromPPVar(error_description); 752 StringVar* error_description_string = StringVar::FromPPVar(error_description);
756 DCHECK(error_description_string); 753 DCHECK(error_description_string);
757 cdm_promise_adapter_.RejectPromise( 754 cdm_promise_adapter_.RejectPromise(
758 promise_id, PpExceptionTypeToMediaException(exception_code), system_code, 755 promise_id, PpExceptionTypeToMediaException(exception_code), system_code,
759 error_description_string->value()); 756 error_description_string->value());
760 } 757 }
761 758
762 void ContentDecryptorDelegate::OnSessionMessage(PP_Var session_id, 759 void ContentDecryptorDelegate::OnSessionMessage(PP_Var session_id,
763 PP_CdmMessageType message_type, 760 PP_CdmMessageType message_type,
764 PP_Var message, 761 PP_Var message,
765 PP_Var legacy_destination_url) { 762 PP_Var legacy_destination_url) {
766 if (session_message_cb_.is_null()) 763 if (session_message_cb_.is_null())
767 return; 764 return;
768 765
769 StringVar* session_id_string = StringVar::FromPPVar(session_id); 766 StringVar* session_id_string = StringVar::FromPPVar(session_id);
770 DCHECK(session_id_string); 767 DCHECK(session_id_string);
771 768
772 ArrayBufferVar* message_array_buffer = ArrayBufferVar::FromPPVar(message); 769 ArrayBufferVar* message_array_buffer = ArrayBufferVar::FromPPVar(message);
773 std::vector<uint8> message_vector; 770 std::vector<uint8_t> message_vector;
774 if (message_array_buffer) { 771 if (message_array_buffer) {
775 const uint8* data = static_cast<const uint8*>(message_array_buffer->Map()); 772 const uint8_t* data =
773 static_cast<const uint8_t*>(message_array_buffer->Map());
776 message_vector.assign(data, data + message_array_buffer->ByteLength()); 774 message_vector.assign(data, data + message_array_buffer->ByteLength());
777 } 775 }
778 776
779 StringVar* destination_url_string = 777 StringVar* destination_url_string =
780 StringVar::FromPPVar(legacy_destination_url); 778 StringVar::FromPPVar(legacy_destination_url);
781 if (!destination_url_string) { 779 if (!destination_url_string) {
782 NOTREACHED(); 780 NOTREACHED();
783 return; 781 return;
784 } 782 }
785 783
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 840
843 StringVar* session_id_string = StringVar::FromPPVar(session_id); 841 StringVar* session_id_string = StringVar::FromPPVar(session_id);
844 DCHECK(session_id_string); 842 DCHECK(session_id_string);
845 843
846 session_closed_cb_.Run(session_id_string->value()); 844 session_closed_cb_.Run(session_id_string->value());
847 } 845 }
848 846
849 void ContentDecryptorDelegate::OnLegacySessionError( 847 void ContentDecryptorDelegate::OnLegacySessionError(
850 PP_Var session_id, 848 PP_Var session_id,
851 PP_CdmExceptionCode exception_code, 849 PP_CdmExceptionCode exception_code,
852 uint32 system_code, 850 uint32_t system_code,
853 PP_Var error_description) { 851 PP_Var error_description) {
854 ReportSystemCodeUMA(key_system_, system_code); 852 ReportSystemCodeUMA(key_system_, system_code);
855 853
856 if (legacy_session_error_cb_.is_null()) 854 if (legacy_session_error_cb_.is_null())
857 return; 855 return;
858 856
859 StringVar* session_id_string = StringVar::FromPPVar(session_id); 857 StringVar* session_id_string = StringVar::FromPPVar(session_id);
860 DCHECK(session_id_string); 858 DCHECK(session_id_string);
861 859
862 StringVar* error_description_string = StringVar::FromPPVar(error_description); 860 StringVar* error_description_string = StringVar::FromPPVar(error_description);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 BufferAutoMapper mapper(enter.object()); 940 BufferAutoMapper mapper(enter.object());
943 if (!mapper.data() || !mapper.size() || 941 if (!mapper.data() || !mapper.size() ||
944 mapper.size() < block_info->data_size) { 942 mapper.size() < block_info->data_size) {
945 decrypt_cb.Run(Decryptor::kError, NULL); 943 decrypt_cb.Run(Decryptor::kError, NULL);
946 return; 944 return;
947 } 945 }
948 946
949 // TODO(tomfinegan): Find a way to take ownership of the shared memory 947 // TODO(tomfinegan): Find a way to take ownership of the shared memory
950 // managed by the PPB_Buffer_Dev, and avoid the extra copy. 948 // managed by the PPB_Buffer_Dev, and avoid the extra copy.
951 scoped_refptr<media::DecoderBuffer> decrypted_buffer( 949 scoped_refptr<media::DecoderBuffer> decrypted_buffer(
952 media::DecoderBuffer::CopyFrom(static_cast<uint8*>(mapper.data()), 950 media::DecoderBuffer::CopyFrom(static_cast<uint8_t*>(mapper.data()),
953 block_info->data_size)); 951 block_info->data_size));
954 decrypted_buffer->set_timestamp( 952 decrypted_buffer->set_timestamp(
955 base::TimeDelta::FromMicroseconds(block_info->tracking_info.timestamp)); 953 base::TimeDelta::FromMicroseconds(block_info->tracking_info.timestamp));
956 decrypt_cb.Run(Decryptor::kSuccess, decrypted_buffer); 954 decrypt_cb.Run(Decryptor::kSuccess, decrypted_buffer);
957 } 955 }
958 956
959 // Use a non-class-member function here so that if for some reason 957 // Use a non-class-member function here so that if for some reason
960 // ContentDecryptorDelegate is destroyed before VideoFrame calls this callback, 958 // ContentDecryptorDelegate is destroyed before VideoFrame calls this callback,
961 // we can still get the shared memory unmapped. 959 // we can still get the shared memory unmapped.
962 static void BufferNoLongerNeeded( 960 static void BufferNoLongerNeeded(
963 const scoped_refptr<PPB_Buffer_Impl>& ppb_buffer, 961 const scoped_refptr<PPB_Buffer_Impl>& ppb_buffer,
964 base::Closure buffer_no_longer_needed_cb) { 962 base::Closure buffer_no_longer_needed_cb) {
965 ppb_buffer->Unmap(); 963 ppb_buffer->Unmap();
966 buffer_no_longer_needed_cb.Run(); 964 buffer_no_longer_needed_cb.Run();
967 } 965 }
968 966
969 // Enters |resource|, maps shared memory and returns pointer of mapped data. 967 // Enters |resource|, maps shared memory and returns pointer of mapped data.
970 // Returns NULL if any error occurs. 968 // Returns NULL if any error occurs.
971 static uint8* GetMappedBuffer(PP_Resource resource, 969 static uint8_t* GetMappedBuffer(PP_Resource resource,
972 scoped_refptr<PPB_Buffer_Impl>* ppb_buffer) { 970 scoped_refptr<PPB_Buffer_Impl>* ppb_buffer) {
973 EnterResourceNoLock<PPB_Buffer_API> enter(resource, true); 971 EnterResourceNoLock<PPB_Buffer_API> enter(resource, true);
974 if (!enter.succeeded()) 972 if (!enter.succeeded())
975 return NULL; 973 return NULL;
976 974
977 uint8* mapped_data = static_cast<uint8*>(enter.object()->Map()); 975 uint8_t* mapped_data = static_cast<uint8_t*>(enter.object()->Map());
978 if (!enter.object()->IsMapped() || !mapped_data) 976 if (!enter.object()->IsMapped() || !mapped_data)
979 return NULL; 977 return NULL;
980 978
981 uint32_t mapped_size = 0; 979 uint32_t mapped_size = 0;
982 if (!enter.object()->Describe(&mapped_size) || !mapped_size) { 980 if (!enter.object()->Describe(&mapped_size) || !mapped_size) {
983 enter.object()->Unmap(); 981 enter.object()->Unmap();
984 return NULL; 982 return NULL;
985 } 983 }
986 984
987 *ppb_buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); 985 *ppb_buffer = static_cast<PPB_Buffer_Impl*>(enter.object());
(...skipping 23 matching lines...) Expand all
1011 1009
1012 Decryptor::Status status = 1010 Decryptor::Status status =
1013 PpDecryptResultToMediaDecryptorStatus(frame_info->result); 1011 PpDecryptResultToMediaDecryptorStatus(frame_info->result);
1014 if (status != Decryptor::kSuccess) { 1012 if (status != Decryptor::kSuccess) {
1015 DCHECK(!frame_info->tracking_info.buffer_id); 1013 DCHECK(!frame_info->tracking_info.buffer_id);
1016 video_decode_cb.Run(status, NULL); 1014 video_decode_cb.Run(status, NULL);
1017 return; 1015 return;
1018 } 1016 }
1019 1017
1020 scoped_refptr<PPB_Buffer_Impl> ppb_buffer; 1018 scoped_refptr<PPB_Buffer_Impl> ppb_buffer;
1021 uint8* frame_data = GetMappedBuffer(decrypted_frame, &ppb_buffer); 1019 uint8_t* frame_data = GetMappedBuffer(decrypted_frame, &ppb_buffer);
1022 if (!frame_data) { 1020 if (!frame_data) {
1023 FreeBuffer(frame_info->tracking_info.buffer_id); 1021 FreeBuffer(frame_info->tracking_info.buffer_id);
1024 video_decode_cb.Run(Decryptor::kError, NULL); 1022 video_decode_cb.Run(Decryptor::kError, NULL);
1025 return; 1023 return;
1026 } 1024 }
1027 1025
1028 gfx::Size frame_size(frame_info->width, frame_info->height); 1026 gfx::Size frame_size(frame_info->width, frame_info->height);
1029 DCHECK_EQ(frame_info->format, PP_DECRYPTEDFRAMEFORMAT_YV12); 1027 DCHECK_EQ(frame_info->format, PP_DECRYPTEDFRAMEFORMAT_YV12);
1030 1028
1031 scoped_refptr<media::VideoFrame> decoded_frame = 1029 scoped_refptr<media::VideoFrame> decoded_frame =
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 return false; 1199 return false;
1202 1200
1203 BufferAutoMapper mapper(enter.object()); 1201 BufferAutoMapper mapper(enter.object());
1204 if (!mapper.data() || !mapper.size() || 1202 if (!mapper.data() || !mapper.size() ||
1205 mapper.size() < static_cast<uint32_t>(data_size)) 1203 mapper.size() < static_cast<uint32_t>(data_size))
1206 return false; 1204 return false;
1207 1205
1208 // TODO(jrummell): Pass ownership of data() directly to AudioBuffer to avoid 1206 // TODO(jrummell): Pass ownership of data() directly to AudioBuffer to avoid
1209 // the copy. Since it is possible to get multiple buffers, it would need to be 1207 // the copy. Since it is possible to get multiple buffers, it would need to be
1210 // sliced and ref counted appropriately. http://crbug.com/255576. 1208 // sliced and ref counted appropriately. http://crbug.com/255576.
1211 const uint8* cur = static_cast<uint8*>(mapper.data()); 1209 const uint8_t* cur = static_cast<uint8_t*>(mapper.data());
1212 size_t bytes_left = data_size; 1210 size_t bytes_left = data_size;
1213 1211
1214 const int audio_bytes_per_frame = 1212 const int audio_bytes_per_frame =
1215 media::SampleFormatToBytesPerChannel(sample_format) * 1213 media::SampleFormatToBytesPerChannel(sample_format) *
1216 audio_channel_count_; 1214 audio_channel_count_;
1217 if (audio_bytes_per_frame <= 0) 1215 if (audio_bytes_per_frame <= 0)
1218 return false; 1216 return false;
1219 1217
1220 // Allocate space for the channel pointers given to AudioBuffer. 1218 // Allocate space for the channel pointers given to AudioBuffer.
1221 std::vector<const uint8*> channel_ptrs(audio_channel_count_, 1219 std::vector<const uint8_t*> channel_ptrs(audio_channel_count_,
1222 static_cast<const uint8*>(NULL)); 1220 static_cast<const uint8_t*>(NULL));
bbudge 2015/04/23 17:35:39 As long as you're here, s/NULL/nullptr. Then you c
jrummell 2015/04/23 20:22:43 Done.
1223 do { 1221 do {
1224 int64 timestamp = 0; 1222 int64 timestamp = 0;
1225 int64 frame_size = -1; 1223 int64 frame_size = -1;
1226 const size_t kHeaderSize = sizeof(timestamp) + sizeof(frame_size); 1224 const size_t kHeaderSize = sizeof(timestamp) + sizeof(frame_size);
1227 1225
1228 if (bytes_left < kHeaderSize) 1226 if (bytes_left < kHeaderSize)
1229 return false; 1227 return false;
1230 1228
1231 memcpy(&timestamp, cur, sizeof(timestamp)); 1229 memcpy(&timestamp, cur, sizeof(timestamp));
1232 cur += sizeof(timestamp); 1230 cur += sizeof(timestamp);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 empty_frames); 1286 empty_frames);
1289 } 1287 }
1290 1288
1291 if (!video_decode_cb_.is_null()) 1289 if (!video_decode_cb_.is_null())
1292 video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); 1290 video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL);
1293 1291
1294 cdm_promise_adapter_.Clear(); 1292 cdm_promise_adapter_.Clear();
1295 } 1293 }
1296 1294
1297 } // namespace content 1295 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/content_decryptor_delegate.h ('k') | media/base/android/media_drm_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698