Chromium Code Reviews| 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 #include "webkit/media/crypto/ppapi/cdm_allocator.h" | |
| 13 | 14 |
| 14 static const char kClearKeyCdmVersion[] = "0.1.0.0"; | 15 static const char kClearKeyCdmVersion[] = "0.1.0.0"; |
| 15 | 16 |
| 16 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( | 17 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( |
| 17 const cdm::InputBuffer& input_buffer) { | 18 const cdm::InputBuffer& input_buffer) { |
| 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 (uint32_t i = 0; i < input_buffer.num_subsamples; ++i) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 void ClearKeyCdm::Client::NeedKey(const std::string& key_system, | 118 void ClearKeyCdm::Client::NeedKey(const std::string& key_system, |
| 118 const std::string& session_id, | 119 const std::string& session_id, |
| 119 scoped_array<uint8> init_data, | 120 scoped_array<uint8> init_data, |
| 120 int init_data_length) { | 121 int init_data_length) { |
| 121 // In the current implementation of AesDecryptor, NeedKey is not used. | 122 // In the current implementation of AesDecryptor, NeedKey is not used. |
| 122 // If no key is available to decrypt an input buffer, it returns kNoKey to | 123 // If no key is available to decrypt an input buffer, it returns kNoKey to |
| 123 // the caller instead of firing NeedKey. | 124 // the caller instead of firing NeedKey. |
| 124 NOTREACHED(); | 125 NOTREACHED(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 ClearKeyCdm::ClearKeyCdm() : decryptor_(&client_) {} | 128 ClearKeyCdm::ClearKeyCdm() : decryptor_(&client_), allocator_iface_(NULL) {} |
| 128 | 129 |
| 129 ClearKeyCdm::~ClearKeyCdm() {} | 130 ClearKeyCdm::~ClearKeyCdm() {} |
| 130 | 131 |
| 132 bool ClearKeyCdm::Initialize(CdmAllocator* allocator) { | |
|
ddorwin
2012/09/04 09:53:15
Is there a reason we can't do this in the construc
Tom Finegan
2012/09/07 00:46:36
Nope, done. Also, I made the default constructor p
| |
| 133 if (!allocator) { | |
|
ddorwin
2012/09/04 09:53:15
Seems like a DCHECK. And can remove return type (o
Tom Finegan
2012/09/07 00:46:36
Moved to constructor, and I put a DCHECK there.
| |
| 134 return false; | |
| 135 } | |
| 136 allocator_iface_ = allocator; | |
| 137 return true; | |
| 138 } | |
| 139 | |
| 131 cdm::Status ClearKeyCdm::GenerateKeyRequest(const uint8_t* init_data, | 140 cdm::Status ClearKeyCdm::GenerateKeyRequest(const uint8_t* init_data, |
| 132 int init_data_size, | 141 int init_data_size, |
| 133 cdm::KeyMessage* key_request) { | 142 cdm::KeyMessage* key_request) { |
| 134 DVLOG(1) << "GenerateKeyRequest()"; | 143 DVLOG(1) << "GenerateKeyRequest()"; |
| 135 base::AutoLock auto_lock(client_lock_); | 144 base::AutoLock auto_lock(client_lock_); |
| 136 ScopedResetter<Client> auto_resetter(&client_); | 145 ScopedResetter<Client> auto_resetter(&client_); |
| 137 decryptor_.GenerateKeyRequest("", init_data, init_data_size); | 146 decryptor_.GenerateKeyRequest("", init_data, init_data_size); |
| 138 | 147 |
| 139 if (client_.status() != Client::kKeyMessage) | 148 if (client_.status() != Client::kKeyMessage) |
| 140 return cdm::kErrorUnknown; | 149 return cdm::kErrorUnknown; |
| 141 | 150 |
| 142 DCHECK(key_request); | 151 DCHECK(key_request); |
| 143 key_request->session_id = AllocateAndCopy(client_.session_id().data(), | 152 key_request->session_id = AllocateAndCopy(client_.session_id().data(), |
|
ddorwin
2012/09/04 09:53:15
These are still problematic. You can add a TODO fo
Tom Finegan
2012/09/07 00:46:36
Added TODO for message. The other two are Vars-- m
| |
| 144 client_.session_id().size()); | 153 client_.session_id().size()); |
| 145 key_request->session_id_size = client_.session_id().size(); | 154 key_request->session_id_size = client_.session_id().size(); |
| 146 key_request->message = AllocateAndCopy(client_.key_message(), | 155 key_request->message = AllocateAndCopy(client_.key_message(), |
| 147 client_.key_message_length()); | 156 client_.key_message_length()); |
| 148 key_request->message_size = client_.key_message_length(); | 157 key_request->message_size = client_.key_message_length(); |
| 149 key_request->default_url = AllocateAndCopy(client_.default_url().data(), | 158 key_request->default_url = AllocateAndCopy(client_.default_url().data(), |
| 150 client_.default_url().size()); | 159 client_.default_url().size()); |
| 151 key_request->default_url_size = client_.default_url().size(); | 160 key_request->default_url_size = client_.default_url().size(); |
| 152 return cdm::kSuccess; | 161 return cdm::kSuccess; |
| 153 } | 162 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 base::Bind(&CopyDecryptResults, &status, &buffer)); | 212 base::Bind(&CopyDecryptResults, &status, &buffer)); |
| 204 | 213 |
| 205 if (status == media::Decryptor::kError) | 214 if (status == media::Decryptor::kError) |
| 206 return cdm::kErrorUnknown; | 215 return cdm::kErrorUnknown; |
| 207 | 216 |
| 208 if (status == media::Decryptor::kNoKey) | 217 if (status == media::Decryptor::kNoKey) |
| 209 return cdm::kErrorNoKey; | 218 return cdm::kErrorNoKey; |
| 210 | 219 |
| 211 DCHECK(buffer); | 220 DCHECK(buffer); |
| 212 int data_size = buffer->GetDataSize(); | 221 int data_size = buffer->GetDataSize(); |
| 213 decrypted_buffer->data = AllocateAndCopy(buffer->GetData(), data_size); | 222 |
| 214 decrypted_buffer->data_size = data_size; | 223 decrypted_buffer->data = |
| 224 allocator_iface_->Allocate(data_size, | |
| 225 &decrypted_buffer->buffer_id); | |
| 226 memcpy(reinterpret_cast<void*>(decrypted_buffer->data), | |
|
ddorwin
2012/09/04 09:53:15
Copy = boo!
Maybe a TODO to make CopyDecoderBuffer
Tom Finegan
2012/09/07 00:46:36
TODO added.
| |
| 227 buffer->GetData(), | |
| 228 data_size); | |
| 229 | |
| 215 decrypted_buffer->timestamp = buffer->GetTimestamp().InMicroseconds(); | 230 decrypted_buffer->timestamp = buffer->GetTimestamp().InMicroseconds(); |
| 216 return cdm::kSuccess; | 231 return cdm::kSuccess; |
| 217 } | 232 } |
| 218 | 233 |
| 219 } // namespace webkit_media | 234 } // namespace webkit_media |
| OLD | NEW |