| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( | 92 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( |
| 93 const cdm::InputBuffer& input_buffer) { | 93 const cdm::InputBuffer& input_buffer) { |
| 94 if (!input_buffer.data) { | 94 if (!input_buffer.data) { |
| 95 DCHECK(!input_buffer.data_size); | 95 DCHECK(!input_buffer.data_size); |
| 96 return media::DecoderBuffer::CreateEOSBuffer(); | 96 return media::DecoderBuffer::CreateEOSBuffer(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // TODO(xhwang): Get rid of this copy. | 99 // TODO(xhwang): Get rid of this copy. |
| 100 scoped_refptr<media::DecoderBuffer> output_buffer = | 100 scoped_refptr<media::DecoderBuffer> output_buffer = |
| 101 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); | 101 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); |
| 102 | |
| 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(new media::DecryptConfig( | |
| 111 std::string(reinterpret_cast<const char*>(input_buffer.key_id), | |
| 112 input_buffer.key_id_size), | |
| 113 std::string(reinterpret_cast<const char*>(input_buffer.iv), | |
| 114 input_buffer.iv_size), | |
| 115 subsamples)); | |
| 116 | |
| 117 output_buffer->set_decrypt_config(std::move(decrypt_config)); | |
| 118 output_buffer->set_timestamp( | 102 output_buffer->set_timestamp( |
| 119 base::TimeDelta::FromMicroseconds(input_buffer.timestamp)); | 103 base::TimeDelta::FromMicroseconds(input_buffer.timestamp)); |
| 120 | 104 |
| 105 // TODO(xhwang): Unify how to check whether a buffer is encrypted. |
| 106 // See http://crbug.com/675003 |
| 107 if (input_buffer.iv_size != 0) { |
| 108 DCHECK_GT(input_buffer.key_id_size, 0u); |
| 109 std::vector<media::SubsampleEntry> subsamples; |
| 110 for (uint32_t i = 0; i < input_buffer.num_subsamples; ++i) { |
| 111 subsamples.push_back( |
| 112 media::SubsampleEntry(input_buffer.subsamples[i].clear_bytes, |
| 113 input_buffer.subsamples[i].cipher_bytes)); |
| 114 } |
| 115 |
| 116 std::unique_ptr<media::DecryptConfig> decrypt_config( |
| 117 new media::DecryptConfig( |
| 118 std::string(reinterpret_cast<const char*>(input_buffer.key_id), |
| 119 input_buffer.key_id_size), |
| 120 std::string(reinterpret_cast<const char*>(input_buffer.iv), |
| 121 input_buffer.iv_size), |
| 122 subsamples)); |
| 123 |
| 124 output_buffer->set_decrypt_config(std::move(decrypt_config)); |
| 125 } |
| 126 |
| 121 return output_buffer; | 127 return output_buffer; |
| 122 } | 128 } |
| 123 | 129 |
| 124 static std::string GetUnitTestResultMessage(bool success) { | 130 static std::string GetUnitTestResultMessage(bool success) { |
| 125 std::string message(kUnitTestResultHeader); | 131 std::string message(kUnitTestResultHeader); |
| 126 message += success ? '1' : '0'; | 132 message += success ? '1' : '0'; |
| 127 return message; | 133 return message; |
| 128 } | 134 } |
| 129 | 135 |
| 130 static cdm::Error ConvertException( | 136 static cdm::Error ConvertException( |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 timer_delay_ms_ = std::min(2 * timer_delay_ms_, kMaxTimerDelayMs); | 728 timer_delay_ms_ = std::min(2 * timer_delay_ms_, kMaxTimerDelayMs); |
| 723 } | 729 } |
| 724 | 730 |
| 725 cdm::Status ClearKeyCdm::DecryptToMediaDecoderBuffer( | 731 cdm::Status ClearKeyCdm::DecryptToMediaDecoderBuffer( |
| 726 const cdm::InputBuffer& encrypted_buffer, | 732 const cdm::InputBuffer& encrypted_buffer, |
| 727 scoped_refptr<media::DecoderBuffer>* decrypted_buffer) { | 733 scoped_refptr<media::DecoderBuffer>* decrypted_buffer) { |
| 728 DCHECK(decrypted_buffer); | 734 DCHECK(decrypted_buffer); |
| 729 scoped_refptr<media::DecoderBuffer> buffer = | 735 scoped_refptr<media::DecoderBuffer> buffer = |
| 730 CopyDecoderBufferFrom(encrypted_buffer); | 736 CopyDecoderBufferFrom(encrypted_buffer); |
| 731 | 737 |
| 732 if (buffer->end_of_stream()) { | 738 // TODO(xhwang): Unify how to check whether a buffer is encrypted. |
| 739 // See http://crbug.com/675003 |
| 740 if (buffer->end_of_stream() || !buffer->decrypt_config() || |
| 741 !buffer->decrypt_config()->is_encrypted()) { |
| 733 *decrypted_buffer = buffer; | 742 *decrypted_buffer = buffer; |
| 734 return cdm::kSuccess; | 743 return cdm::kSuccess; |
| 735 } | 744 } |
| 736 | 745 |
| 737 // Callback is called synchronously, so we can use variables on the stack. | 746 // Callback is called synchronously, so we can use variables on the stack. |
| 738 media::Decryptor::Status status = media::Decryptor::kError; | 747 media::Decryptor::Status status = media::Decryptor::kError; |
| 739 // The AesDecryptor does not care what the stream type is. Pass kVideo | 748 // The AesDecryptor does not care what the stream type is. Pass kVideo |
| 740 // for both audio and video decryption. | 749 // for both audio and video decryption. |
| 741 decryptor_->Decrypt( | 750 decryptor_->Decrypt( |
| 742 media::Decryptor::kVideo, buffer, | 751 media::Decryptor::kVideo, buffer, |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 challenge.data(), challenge.size()); | 1047 challenge.data(), challenge.size()); |
| 1039 } | 1048 } |
| 1040 | 1049 |
| 1041 void ClearKeyCdm::VerifyCdmHostTest() { | 1050 void ClearKeyCdm::VerifyCdmHostTest() { |
| 1042 // VerifyCdmHost() should have already been called and test result stored | 1051 // VerifyCdmHost() should have already been called and test result stored |
| 1043 // in |g_verify_host_files_result|. | 1052 // in |g_verify_host_files_result|. |
| 1044 OnUnitTestComplete(g_verify_host_files_result); | 1053 OnUnitTestComplete(g_verify_host_files_result); |
| 1045 } | 1054 } |
| 1046 | 1055 |
| 1047 } // namespace media | 1056 } // namespace media |
| OLD | NEW |