Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" | 5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( | 88 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( |
| 89 const cdm::InputBuffer& input_buffer) { | 89 const cdm::InputBuffer& input_buffer) { |
| 90 if (!input_buffer.data) { | 90 if (!input_buffer.data) { |
| 91 DCHECK(!input_buffer.data_size); | 91 DCHECK(!input_buffer.data_size); |
| 92 return media::DecoderBuffer::CreateEOSBuffer(); | 92 return media::DecoderBuffer::CreateEOSBuffer(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // TODO(xhwang): Get rid of this copy. | 95 // TODO(xhwang): Get rid of this copy. |
| 96 scoped_refptr<media::DecoderBuffer> output_buffer = | 96 scoped_refptr<media::DecoderBuffer> output_buffer = |
| 97 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); | 97 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); |
| 98 | |
| 99 std::vector<media::SubsampleEntry> subsamples; | |
| 100 for (uint32_t i = 0; i < input_buffer.num_subsamples; ++i) { | |
| 101 subsamples.push_back( | |
| 102 media::SubsampleEntry(input_buffer.subsamples[i].clear_bytes, | |
| 103 input_buffer.subsamples[i].cipher_bytes)); | |
| 104 } | |
| 105 | |
| 106 std::unique_ptr<media::DecryptConfig> decrypt_config(new media::DecryptConfig( | |
| 107 std::string(reinterpret_cast<const char*>(input_buffer.key_id), | |
| 108 input_buffer.key_id_size), | |
| 109 std::string(reinterpret_cast<const char*>(input_buffer.iv), | |
| 110 input_buffer.iv_size), | |
| 111 subsamples)); | |
| 112 | |
| 113 output_buffer->set_decrypt_config(std::move(decrypt_config)); | |
| 114 output_buffer->set_timestamp( | 98 output_buffer->set_timestamp( |
| 115 base::TimeDelta::FromMicroseconds(input_buffer.timestamp)); | 99 base::TimeDelta::FromMicroseconds(input_buffer.timestamp)); |
| 116 | 100 |
| 101 if (input_buffer.iv_size != 0) { | |
|
ddorwin
2017/02/12 04:28:52
Should we have a similar TODO as below here?
Or a
xhwang
2017/02/14 23:59:32
Done.
| |
| 102 DCHECK_GT(input_buffer.key_id_size, 0u); | |
| 103 std::vector<media::SubsampleEntry> subsamples; | |
| 104 for (uint32_t i = 0; i < input_buffer.num_subsamples; ++i) { | |
| 105 subsamples.push_back( | |
| 106 media::SubsampleEntry(input_buffer.subsamples[i].clear_bytes, | |
| 107 input_buffer.subsamples[i].cipher_bytes)); | |
| 108 } | |
| 109 | |
| 110 std::unique_ptr<media::DecryptConfig> decrypt_config( | |
| 111 new media::DecryptConfig( | |
| 112 std::string(reinterpret_cast<const char*>(input_buffer.key_id), | |
| 113 input_buffer.key_id_size), | |
| 114 std::string(reinterpret_cast<const char*>(input_buffer.iv), | |
| 115 input_buffer.iv_size), | |
| 116 subsamples)); | |
| 117 | |
| 118 output_buffer->set_decrypt_config(std::move(decrypt_config)); | |
| 119 } | |
| 120 | |
| 117 return output_buffer; | 121 return output_buffer; |
| 118 } | 122 } |
| 119 | 123 |
| 120 static std::string GetUnitTestResultMessage(bool success) { | 124 static std::string GetUnitTestResultMessage(bool success) { |
| 121 std::string message(kUnitTestResultHeader); | 125 std::string message(kUnitTestResultHeader); |
| 122 message += success ? '1' : '0'; | 126 message += success ? '1' : '0'; |
| 123 return message; | 127 return message; |
| 124 } | 128 } |
| 125 | 129 |
| 126 static cdm::Error ConvertException( | 130 static cdm::Error ConvertException( |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 timer_delay_ms_ = std::min(2 * timer_delay_ms_, kMaxTimerDelayMs); | 670 timer_delay_ms_ = std::min(2 * timer_delay_ms_, kMaxTimerDelayMs); |
| 667 } | 671 } |
| 668 | 672 |
| 669 cdm::Status ClearKeyCdm::DecryptToMediaDecoderBuffer( | 673 cdm::Status ClearKeyCdm::DecryptToMediaDecoderBuffer( |
| 670 const cdm::InputBuffer& encrypted_buffer, | 674 const cdm::InputBuffer& encrypted_buffer, |
| 671 scoped_refptr<media::DecoderBuffer>* decrypted_buffer) { | 675 scoped_refptr<media::DecoderBuffer>* decrypted_buffer) { |
| 672 DCHECK(decrypted_buffer); | 676 DCHECK(decrypted_buffer); |
| 673 scoped_refptr<media::DecoderBuffer> buffer = | 677 scoped_refptr<media::DecoderBuffer> buffer = |
| 674 CopyDecoderBufferFrom(encrypted_buffer); | 678 CopyDecoderBufferFrom(encrypted_buffer); |
| 675 | 679 |
| 676 if (buffer->end_of_stream()) { | 680 // TODO(xhwang): Unify how to check whether a buffer is encrypted. |
| 681 // See http://crbug.com/675003 | |
| 682 if (buffer->end_of_stream() || !buffer->decrypt_config() || | |
| 683 !buffer->decrypt_config()->is_encrypted()) { | |
| 677 *decrypted_buffer = buffer; | 684 *decrypted_buffer = buffer; |
| 678 return cdm::kSuccess; | 685 return cdm::kSuccess; |
| 679 } | 686 } |
| 680 | 687 |
| 681 // Callback is called synchronously, so we can use variables on the stack. | 688 // Callback is called synchronously, so we can use variables on the stack. |
| 682 media::Decryptor::Status status = media::Decryptor::kError; | 689 media::Decryptor::Status status = media::Decryptor::kError; |
| 683 // The AesDecryptor does not care what the stream type is. Pass kVideo | 690 // The AesDecryptor does not care what the stream type is. Pass kVideo |
| 684 // for both audio and video decryption. | 691 // for both audio and video decryption. |
| 685 decryptor_->Decrypt( | 692 decryptor_->Decrypt( |
| 686 media::Decryptor::kVideo, buffer, | 693 media::Decryptor::kVideo, buffer, |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 976 is_running_platform_verification_test_ = true; | 983 is_running_platform_verification_test_ = true; |
| 977 | 984 |
| 978 std::string service_id = "test_service_id"; | 985 std::string service_id = "test_service_id"; |
| 979 std::string challenge = "test_challenge"; | 986 std::string challenge = "test_challenge"; |
| 980 | 987 |
| 981 host_->SendPlatformChallenge(service_id.data(), service_id.size(), | 988 host_->SendPlatformChallenge(service_id.data(), service_id.size(), |
| 982 challenge.data(), challenge.size()); | 989 challenge.data(), challenge.size()); |
| 983 } | 990 } |
| 984 | 991 |
| 985 } // namespace media | 992 } // namespace media |
| OLD | NEW |