Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1208)

Side by Side Diff: webkit/media/crypto/ppapi/clear_key_cdm.cc

Issue 10914028: Add CDM allocator interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactored... quite a bit. Sorry for rebase noise on top of everything else! Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 scoped_refptr<media::DecoderBuffer> output_buffer = 18 scoped_refptr<media::DecoderBuffer> output_buffer =
19 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); 19 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size);
ddorwin 2012/09/07 09:48:48 We'll want to avoid this copy too. Should .data be
Tom Finegan 2012/09/08 01:02:47 Done, added TODO.
20 20
21 std::vector<media::SubsampleEntry> subsamples; 21 std::vector<media::SubsampleEntry> subsamples;
22 for (uint32_t i = 0; i < input_buffer.num_subsamples; ++i) { 22 for (int32_t i = 0; i < input_buffer.num_subsamples; ++i) {
23 media::SubsampleEntry subsample; 23 media::SubsampleEntry subsample;
24 subsample.clear_bytes = input_buffer.subsamples[i].clear_bytes; 24 subsample.clear_bytes = input_buffer.subsamples[i].clear_bytes;
25 subsample.cypher_bytes = input_buffer.subsamples[i].cipher_bytes; 25 subsample.cypher_bytes = input_buffer.subsamples[i].cipher_bytes;
26 subsamples.push_back(subsample); 26 subsamples.push_back(subsample);
27 } 27 }
28 28
29 scoped_ptr<media::DecryptConfig> decrypt_config(new media::DecryptConfig( 29 scoped_ptr<media::DecryptConfig> decrypt_config(new media::DecryptConfig(
30 std::string(reinterpret_cast<const char*>(input_buffer.key_id), 30 std::string(reinterpret_cast<const char*>(input_buffer.key_id),
31 input_buffer.key_id_size), 31 input_buffer.key_id_size),
32 std::string(reinterpret_cast<const char*>(input_buffer.iv), 32 std::string(reinterpret_cast<const char*>(input_buffer.iv),
(...skipping 23 matching lines...) Expand all
56 }; 56 };
57 57
58 template<typename Type> 58 template<typename Type>
59 static Type* AllocateAndCopy(const Type* data, int size) { 59 static Type* AllocateAndCopy(const Type* data, int size) {
60 COMPILE_ASSERT(sizeof(Type) == 1, type_size_is_not_one); 60 COMPILE_ASSERT(sizeof(Type) == 1, type_size_is_not_one);
61 Type* copy = new Type[size]; 61 Type* copy = new Type[size];
62 memcpy(copy, data, size); 62 memcpy(copy, data, size);
63 return copy; 63 return copy;
64 } 64 }
65 65
66 cdm::ContentDecryptionModule* CreateCdmInstance() { 66 cdm::ContentDecryptionModule* CreateCdmInstance(cdm::CdmAllocator* allocator) {
67 return new webkit_media::ClearKeyCdm(); 67 return new webkit_media::ClearKeyCdm(allocator);
68 } 68 }
69 69
70 void DestroyCdmInstance(cdm::ContentDecryptionModule* instance) { 70 void DestroyCdmInstance(cdm::ContentDecryptionModule* instance) {
71 delete instance; 71 delete instance;
72 } 72 }
73 73
74 const char* GetCdmVersion() { 74 const char* GetCdmVersion() {
75 return kClearKeyCdmVersion; 75 return kClearKeyCdmVersion;
76 } 76 }
77 77
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 void ClearKeyCdm::Client::NeedKey(const std::string& key_system, 117 void ClearKeyCdm::Client::NeedKey(const std::string& key_system,
118 const std::string& session_id, 118 const std::string& session_id,
119 scoped_array<uint8> init_data, 119 scoped_array<uint8> init_data,
120 int init_data_length) { 120 int init_data_length) {
121 // In the current implementation of AesDecryptor, NeedKey is not used. 121 // 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 122 // If no key is available to decrypt an input buffer, it returns kNoKey to
123 // the caller instead of firing NeedKey. 123 // the caller instead of firing NeedKey.
124 NOTREACHED(); 124 NOTREACHED();
125 } 125 }
126 126
127 ClearKeyCdm::ClearKeyCdm() : decryptor_(&client_) {} 127 ClearKeyCdm::ClearKeyCdm() : decryptor_(&client_), allocator_(NULL) {
128 NOTREACHED();
ddorwin 2012/09/07 09:48:48 Why does this constructor exist? If you don't decl
Tom Finegan 2012/09/08 01:02:47 Removed.
129 }
130
131 ClearKeyCdm::ClearKeyCdm(cdm::CdmAllocator* allocator)
132 : decryptor_(&client_), allocator_(allocator) {
133 DCHECK(allocator_);
134 }
128 135
129 ClearKeyCdm::~ClearKeyCdm() {} 136 ClearKeyCdm::~ClearKeyCdm() {}
130 137
131 cdm::Status ClearKeyCdm::GenerateKeyRequest(const uint8_t* init_data, 138 cdm::Status ClearKeyCdm::GenerateKeyRequest(const uint8_t* init_data,
132 int init_data_size, 139 int init_data_size,
133 cdm::KeyMessage* key_request) { 140 cdm::KeyMessage* key_request) {
134 DVLOG(1) << "GenerateKeyRequest()"; 141 DVLOG(1) << "GenerateKeyRequest()";
135 base::AutoLock auto_lock(client_lock_); 142 base::AutoLock auto_lock(client_lock_);
136 ScopedResetter<Client> auto_resetter(&client_); 143 ScopedResetter<Client> auto_resetter(&client_);
137 decryptor_.GenerateKeyRequest("", init_data, init_data_size); 144 decryptor_.GenerateKeyRequest("", init_data, init_data_size);
138 145
139 if (client_.status() != Client::kKeyMessage) 146 if (client_.status() != Client::kKeyMessage)
140 return cdm::kError; 147 return cdm::kError;
141 148
142 DCHECK(key_request); 149 DCHECK(key_request);
143 key_request->session_id = AllocateAndCopy(client_.session_id().data(), 150 key_request->session_id = AllocateAndCopy(client_.session_id().data(),
144 client_.session_id().size()); 151 client_.session_id().size());
145 key_request->session_id_size = client_.session_id().size(); 152 key_request->session_id_size = client_.session_id().size();
153
154 // TODO(tomfinegan): Replace this |AllocateAndCopy()|. |message| should be
155 // a CdmBuffer, not a raw pointer.
146 key_request->message = AllocateAndCopy(client_.key_message(), 156 key_request->message = AllocateAndCopy(client_.key_message(),
147 client_.key_message_length()); 157 client_.key_message_length());
148 key_request->message_size = client_.key_message_length(); 158 key_request->message_size = client_.key_message_length();
159
149 key_request->default_url = AllocateAndCopy(client_.default_url().data(), 160 key_request->default_url = AllocateAndCopy(client_.default_url().data(),
150 client_.default_url().size()); 161 client_.default_url().size());
151 key_request->default_url_size = client_.default_url().size(); 162 key_request->default_url_size = client_.default_url().size();
152 return cdm::kSuccess; 163 return cdm::kSuccess;
153 } 164 }
154 165
155 cdm::Status ClearKeyCdm::AddKey(const char* session_id, 166 cdm::Status ClearKeyCdm::AddKey(const char* session_id,
156 int session_id_size, 167 int session_id_size,
157 const uint8_t* key, 168 const uint8_t* key,
158 int key_size, 169 int key_size,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 base::Bind(&CopyDecryptResults, &status, &buffer)); 214 base::Bind(&CopyDecryptResults, &status, &buffer));
204 215
205 if (status == media::Decryptor::kError) 216 if (status == media::Decryptor::kError)
206 return cdm::kError; 217 return cdm::kError;
207 218
208 if (status == media::Decryptor::kNoKey) 219 if (status == media::Decryptor::kNoKey)
209 return cdm::kNoKey; 220 return cdm::kNoKey;
210 221
211 DCHECK(buffer); 222 DCHECK(buffer);
212 int data_size = buffer->GetDataSize(); 223 int data_size = buffer->GetDataSize();
213 decrypted_buffer->data = AllocateAndCopy(buffer->GetData(), data_size); 224
214 decrypted_buffer->data_size = data_size; 225 const cdm::CdmBuffer& cdm_buffer = allocator_->Allocate(data_size);
226 DCHECK(cdm_buffer.buffer());
ddorwin 2012/09/07 09:48:48 This can fail, so you should check and return an e
Tom Finegan 2012/09/08 01:02:47 Done-- also removed the DCHECKs, since they seem l
227 DCHECK_EQ(data_size, cdm_buffer.size());
228 decrypted_buffer->buffer_id = cdm_buffer.id();
ddorwin 2012/09/07 09:48:48 After addressing comment in CDM.h, just copy the C
Tom Finegan 2012/09/08 01:02:47 Done, but it's just a pointer assignment.
229 decrypted_buffer->data = cdm_buffer.buffer();
230
231 // TODO(tomfinegan): Write a CopyDecoderBufferFrom that has a target buffer
ddorwin 2012/09/07 09:48:48 I don't understand this comment. What you really n
Tom Finegan 2012/09/08 01:02:47 Fixed TODO.
232 // argument, and get rid of this memcpy.
233 memcpy(reinterpret_cast<void*>(decrypted_buffer->data),
234 buffer->GetData(),
235 data_size);
236
215 decrypted_buffer->timestamp = buffer->GetTimestamp().InMicroseconds(); 237 decrypted_buffer->timestamp = buffer->GetTimestamp().InMicroseconds();
216 return cdm::kSuccess; 238 return cdm::kSuccess;
217 } 239 }
218 240
219 cdm::Status ClearKeyCdm::InitializeVideoDecoder( 241 cdm::Status ClearKeyCdm::InitializeVideoDecoder(
220 const cdm::VideoDecoderConfig& video_decoder_config) { 242 const cdm::VideoDecoderConfig& video_decoder_config) {
221 NOTIMPLEMENTED(); 243 NOTIMPLEMENTED();
222 return cdm::kError; 244 return cdm::kError;
223 } 245 }
224 246
225 cdm::Status ClearKeyCdm::DecryptAndDecodeVideo( 247 cdm::Status ClearKeyCdm::DecryptAndDecodeVideo(
226 const cdm::InputBuffer& encrypted_buffer, 248 const cdm::InputBuffer& encrypted_buffer,
227 cdm::VideoFrame* video_frame) { 249 cdm::VideoFrame* video_frame) {
228 NOTIMPLEMENTED(); 250 NOTIMPLEMENTED();
229 return cdm::kError; 251 return cdm::kError;
230 } 252 }
231 253
232 void ClearKeyCdm::ResetVideoDecoder() { 254 void ClearKeyCdm::ResetVideoDecoder() {
233 NOTIMPLEMENTED(); 255 NOTIMPLEMENTED();
234 } 256 }
235 257
236 void ClearKeyCdm::StopVideoDecoder() { 258 void ClearKeyCdm::StopVideoDecoder() {
237 NOTIMPLEMENTED(); 259 NOTIMPLEMENTED();
238 } 260 }
239 261
240 } // namespace webkit_media 262 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698