| 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 "webkit/media/crypto/ppapi/clear_key_cdm.h" | 5 #include "webkit/media/crypto/ppapi/clear_key_cdm.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "media/base/decoder_buffer.h" | 12 #include "media/base/decoder_buffer.h" |
| 13 | 13 |
| 14 static const char kClearKeyCdmVersion[] = "0.1.0.0"; | 14 static const char kClearKeyCdmVersion[] = "0.1.0.0"; |
| 15 | 15 |
| 16 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( | 16 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( |
| 17 const cdm::InputBuffer& input_buffer) { | 17 const cdm::InputBuffer& input_buffer) { |
| 18 // TODO(tomfinegan): Get rid of this copy. |
| 18 scoped_refptr<media::DecoderBuffer> output_buffer = | 19 scoped_refptr<media::DecoderBuffer> output_buffer = |
| 19 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); | 20 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); |
| 20 | 21 |
| 21 std::vector<media::SubsampleEntry> subsamples; | 22 std::vector<media::SubsampleEntry> subsamples; |
| 22 for (uint32_t i = 0; i < input_buffer.num_subsamples; ++i) { | 23 for (int32_t i = 0; i < input_buffer.num_subsamples; ++i) { |
| 23 media::SubsampleEntry subsample; | 24 media::SubsampleEntry subsample; |
| 24 subsample.clear_bytes = input_buffer.subsamples[i].clear_bytes; | 25 subsample.clear_bytes = input_buffer.subsamples[i].clear_bytes; |
| 25 subsample.cypher_bytes = input_buffer.subsamples[i].cipher_bytes; | 26 subsample.cypher_bytes = input_buffer.subsamples[i].cipher_bytes; |
| 26 subsamples.push_back(subsample); | 27 subsamples.push_back(subsample); |
| 27 } | 28 } |
| 28 | 29 |
| 29 scoped_ptr<media::DecryptConfig> decrypt_config(new media::DecryptConfig( | 30 scoped_ptr<media::DecryptConfig> decrypt_config(new media::DecryptConfig( |
| 30 std::string(reinterpret_cast<const char*>(input_buffer.key_id), | 31 std::string(reinterpret_cast<const char*>(input_buffer.key_id), |
| 31 input_buffer.key_id_size), | 32 input_buffer.key_id_size), |
| 32 std::string(reinterpret_cast<const char*>(input_buffer.iv), | 33 std::string(reinterpret_cast<const char*>(input_buffer.iv), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 template<typename Type> | 57 template<typename Type> |
| 57 static Type* AllocateAndCopy(const Type* data, int size) { | 58 static Type* AllocateAndCopy(const Type* data, int size) { |
| 58 COMPILE_ASSERT(sizeof(Type) == 1, type_size_is_not_one); | 59 COMPILE_ASSERT(sizeof(Type) == 1, type_size_is_not_one); |
| 59 Type* copy = new Type[size]; | 60 Type* copy = new Type[size]; |
| 60 memcpy(copy, data, size); | 61 memcpy(copy, data, size); |
| 61 return copy; | 62 return copy; |
| 62 } | 63 } |
| 63 | 64 |
| 64 cdm::ContentDecryptionModule* CreateCdmInstance() { | 65 cdm::ContentDecryptionModule* CreateCdmInstance(cdm::Allocator* allocator) { |
| 65 return new webkit_media::ClearKeyCdm(); | 66 return new webkit_media::ClearKeyCdm(allocator); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void DestroyCdmInstance(cdm::ContentDecryptionModule* instance) { | 69 void DestroyCdmInstance(cdm::ContentDecryptionModule* instance) { |
| 69 delete instance; | 70 delete instance; |
| 70 } | 71 } |
| 71 | 72 |
| 72 const char* GetCdmVersion() { | 73 const char* GetCdmVersion() { |
| 73 return kClearKeyCdmVersion; | 74 return kClearKeyCdmVersion; |
| 74 } | 75 } |
| 75 | 76 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 void ClearKeyCdm::Client::NeedKey(const std::string& key_system, | 116 void ClearKeyCdm::Client::NeedKey(const std::string& key_system, |
| 116 const std::string& session_id, | 117 const std::string& session_id, |
| 117 scoped_array<uint8> init_data, | 118 scoped_array<uint8> init_data, |
| 118 int init_data_length) { | 119 int init_data_length) { |
| 119 // In the current implementation of AesDecryptor, NeedKey is not used. | 120 // In the current implementation of AesDecryptor, NeedKey is not used. |
| 120 // If no key is available to decrypt an input buffer, it returns kNoKey to | 121 // If no key is available to decrypt an input buffer, it returns kNoKey to |
| 121 // the caller instead of firing NeedKey. | 122 // the caller instead of firing NeedKey. |
| 122 NOTREACHED(); | 123 NOTREACHED(); |
| 123 } | 124 } |
| 124 | 125 |
| 125 ClearKeyCdm::ClearKeyCdm() : decryptor_(&client_) {} | 126 ClearKeyCdm::ClearKeyCdm(cdm::Allocator* allocator) |
| 127 : decryptor_(&client_), allocator_(allocator) { |
| 128 DCHECK(allocator_); |
| 129 } |
| 126 | 130 |
| 127 ClearKeyCdm::~ClearKeyCdm() {} | 131 ClearKeyCdm::~ClearKeyCdm() {} |
| 128 | 132 |
| 129 cdm::Status ClearKeyCdm::GenerateKeyRequest(const uint8_t* init_data, | 133 cdm::Status ClearKeyCdm::GenerateKeyRequest(const uint8_t* init_data, |
| 130 int init_data_size, | 134 int init_data_size, |
| 131 cdm::KeyMessage* key_request) { | 135 cdm::KeyMessage* key_request) { |
| 132 DVLOG(1) << "GenerateKeyRequest()"; | 136 DVLOG(1) << "GenerateKeyRequest()"; |
| 133 base::AutoLock auto_lock(client_lock_); | 137 base::AutoLock auto_lock(client_lock_); |
| 134 ScopedResetter<Client> auto_resetter(&client_); | 138 ScopedResetter<Client> auto_resetter(&client_); |
| 135 decryptor_.GenerateKeyRequest("", init_data, init_data_size); | 139 decryptor_.GenerateKeyRequest("", init_data, init_data_size); |
| 136 | 140 |
| 137 if (client_.status() != Client::kKeyMessage) | 141 if (client_.status() != Client::kKeyMessage) |
| 138 return cdm::kError; | 142 return cdm::kError; |
| 139 | 143 |
| 140 DCHECK(key_request); | 144 DCHECK(key_request); |
| 141 key_request->session_id = AllocateAndCopy(client_.session_id().data(), | 145 key_request->set_session_id(client_.session_id().data(), |
| 142 client_.session_id().size()); | 146 client_.session_id().size()); |
| 143 key_request->session_id_size = client_.session_id().size(); | 147 |
| 144 key_request->message = AllocateAndCopy(client_.key_message(), | 148 // TODO(tomfinegan): Get rid of this copy. |
| 145 client_.key_message_length()); | 149 key_request->set_message(allocator_->Allocate(client_.key_message_length())); |
| 146 key_request->message_size = client_.key_message_length(); | 150 |
| 147 key_request->default_url = AllocateAndCopy(client_.default_url().data(), | 151 DCHECK(key_request->message()); |
| 148 client_.default_url().size()); | 152 DCHECK_EQ(key_request->message()->size(), client_.key_message_length()); |
| 149 key_request->default_url_size = client_.default_url().size(); | 153 memcpy(reinterpret_cast<void*>(key_request->message()->buffer()), |
| 154 reinterpret_cast<const void*>(client_.key_message()), |
| 155 client_.key_message_length()); |
| 156 |
| 157 key_request->set_default_url(client_.default_url().data(), |
| 158 client_.default_url().size()); |
| 150 return cdm::kSuccess; | 159 return cdm::kSuccess; |
| 151 } | 160 } |
| 152 | 161 |
| 153 cdm::Status ClearKeyCdm::AddKey(const char* session_id, | 162 cdm::Status ClearKeyCdm::AddKey(const char* session_id, |
| 154 int session_id_size, | 163 int session_id_size, |
| 155 const uint8_t* key, | 164 const uint8_t* key, |
| 156 int key_size, | 165 int key_size, |
| 157 const uint8_t* key_id, | 166 const uint8_t* key_id, |
| 158 int key_id_size) { | 167 int key_id_size) { |
| 159 DVLOG(1) << "AddKey()"; | 168 DVLOG(1) << "AddKey()"; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 base::Bind(&CopyDecryptResults, &status, &buffer)); | 210 base::Bind(&CopyDecryptResults, &status, &buffer)); |
| 202 | 211 |
| 203 if (status == media::Decryptor::kError) | 212 if (status == media::Decryptor::kError) |
| 204 return cdm::kError; | 213 return cdm::kError; |
| 205 | 214 |
| 206 if (status == media::Decryptor::kNoKey) | 215 if (status == media::Decryptor::kNoKey) |
| 207 return cdm::kNoKey; | 216 return cdm::kNoKey; |
| 208 | 217 |
| 209 DCHECK(buffer); | 218 DCHECK(buffer); |
| 210 int data_size = buffer->GetDataSize(); | 219 int data_size = buffer->GetDataSize(); |
| 211 decrypted_buffer->data = AllocateAndCopy(buffer->GetData(), data_size); | 220 |
| 212 decrypted_buffer->data_size = data_size; | 221 decrypted_buffer->set_buffer(allocator_->Allocate(data_size)); |
| 213 decrypted_buffer->timestamp = buffer->GetTimestamp().InMicroseconds(); | 222 memcpy(reinterpret_cast<void*>(decrypted_buffer->buffer()->buffer()), |
| 223 buffer->GetData(), |
| 224 data_size); |
| 225 |
| 226 decrypted_buffer->set_timestamp(buffer->GetTimestamp().InMicroseconds()); |
| 214 return cdm::kSuccess; | 227 return cdm::kSuccess; |
| 215 } | 228 } |
| 216 | 229 |
| 217 cdm::Status ClearKeyCdm::InitializeVideoDecoder( | 230 cdm::Status ClearKeyCdm::InitializeVideoDecoder( |
| 218 const cdm::VideoDecoderConfig& video_decoder_config) { | 231 const cdm::VideoDecoderConfig& video_decoder_config) { |
| 219 NOTIMPLEMENTED(); | 232 NOTIMPLEMENTED(); |
| 220 return cdm::kError; | 233 return cdm::kError; |
| 221 } | 234 } |
| 222 | 235 |
| 223 cdm::Status ClearKeyCdm::DecryptAndDecodeVideo( | 236 cdm::Status ClearKeyCdm::DecryptAndDecodeVideo( |
| 224 const cdm::InputBuffer& encrypted_buffer, | 237 const cdm::InputBuffer& encrypted_buffer, |
| 225 cdm::VideoFrame* video_frame) { | 238 cdm::VideoFrame* video_frame) { |
| 226 NOTIMPLEMENTED(); | 239 NOTIMPLEMENTED(); |
| 227 return cdm::kError; | 240 return cdm::kError; |
| 228 } | 241 } |
| 229 | 242 |
| 230 void ClearKeyCdm::ResetVideoDecoder() { | 243 void ClearKeyCdm::ResetVideoDecoder() { |
| 231 NOTIMPLEMENTED(); | 244 NOTIMPLEMENTED(); |
| 232 } | 245 } |
| 233 | 246 |
| 234 void ClearKeyCdm::StopVideoDecoder() { | 247 void ClearKeyCdm::StopVideoDecoder() { |
| 235 NOTIMPLEMENTED(); | 248 NOTIMPLEMENTED(); |
| 236 } | 249 } |
| 237 | 250 |
| 238 } // namespace webkit_media | 251 } // namespace webkit_media |
| OLD | NEW |