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