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

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: Make KeyMessage and OutputBuffer interfaces... 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 // 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 23 matching lines...) Expand all
56 }; 57 };
57 58
58 template<typename Type> 59 template<typename Type>
59 static Type* AllocateAndCopy(const Type* data, int size) { 60 static Type* AllocateAndCopy(const Type* data, int size) {
60 COMPILE_ASSERT(sizeof(Type) == 1, type_size_is_not_one); 61 COMPILE_ASSERT(sizeof(Type) == 1, type_size_is_not_one);
61 Type* copy = new Type[size]; 62 Type* copy = new Type[size];
62 memcpy(copy, data, size); 63 memcpy(copy, data, size);
63 return copy; 64 return copy;
64 } 65 }
65 66
66 cdm::ContentDecryptionModule* CreateCdmInstance() { 67 cdm::ContentDecryptionModule* CreateCdmInstance(cdm::Allocator* allocator) {
67 return new webkit_media::ClearKeyCdm(); 68 return new webkit_media::ClearKeyCdm(allocator);
68 } 69 }
69 70
70 void DestroyCdmInstance(cdm::ContentDecryptionModule* instance) { 71 void DestroyCdmInstance(cdm::ContentDecryptionModule* instance) {
71 delete instance; 72 delete instance;
72 } 73 }
73 74
74 const char* GetCdmVersion() { 75 const char* GetCdmVersion() {
75 return kClearKeyCdmVersion; 76 return kClearKeyCdmVersion;
76 } 77 }
77 78
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(cdm::Allocator* allocator)
129 : decryptor_(&client_), allocator_(allocator) {
130 DCHECK(allocator_);
131 }
128 132
129 ClearKeyCdm::~ClearKeyCdm() {} 133 ClearKeyCdm::~ClearKeyCdm() {}
130 134
131 cdm::Status ClearKeyCdm::GenerateKeyRequest(const uint8_t* init_data, 135 cdm::Status ClearKeyCdm::GenerateKeyRequest(const uint8_t* init_data,
132 int init_data_size, 136 int init_data_size,
133 cdm::KeyMessage* key_request) { 137 cdm::KeyMessage* key_request) {
134 DVLOG(1) << "GenerateKeyRequest()"; 138 DVLOG(1) << "GenerateKeyRequest()";
135 base::AutoLock auto_lock(client_lock_); 139 base::AutoLock auto_lock(client_lock_);
136 ScopedResetter<Client> auto_resetter(&client_); 140 ScopedResetter<Client> auto_resetter(&client_);
137 decryptor_.GenerateKeyRequest("", init_data, init_data_size); 141 decryptor_.GenerateKeyRequest("", init_data, init_data_size);
138 142
139 if (client_.status() != Client::kKeyMessage) 143 if (client_.status() != Client::kKeyMessage)
140 return cdm::kError; 144 return cdm::kError;
141 145
142 DCHECK(key_request); 146 DCHECK(key_request);
143 key_request->session_id = AllocateAndCopy(client_.session_id().data(), 147
144 client_.session_id().size()); 148 if (!key_request->set_session_id(client_.session_id().data(),
145 key_request->session_id_size = client_.session_id().size(); 149 client_.session_id().size()))
146 key_request->message = AllocateAndCopy(client_.key_message(), 150 return cdm::kError;
147 client_.key_message_length()); 151
148 key_request->message_size = client_.key_message_length(); 152 // TODO(tomfinegan): Get rid of this copy.
149 key_request->default_url = AllocateAndCopy(client_.default_url().data(), 153 if (!key_request->set_message(
150 client_.default_url().size()); 154 allocator_->Allocate(client_.key_message_length())))
151 key_request->default_url_size = client_.default_url().size(); 155 return cdm::kError;
156
157 DCHECK(key_request->message());
158 DCHECK_EQ(key_request->message()->size(), client_.key_message_length());
159 memcpy(reinterpret_cast<void*>(key_request->message()->buffer()),
160 reinterpret_cast<const void*>(client_.key_message()),
161 client_.key_message_length());
162
163 if (!key_request->set_default_url(client_.default_url().data(),
164 client_.default_url().size()))
165 return cdm::kError;
166
152 return cdm::kSuccess; 167 return cdm::kSuccess;
153 } 168 }
154 169
155 cdm::Status ClearKeyCdm::AddKey(const char* session_id, 170 cdm::Status ClearKeyCdm::AddKey(const char* session_id,
156 int session_id_size, 171 int session_id_size,
157 const uint8_t* key, 172 const uint8_t* key,
158 int key_size, 173 int key_size,
159 const uint8_t* key_id, 174 const uint8_t* key_id,
160 int key_id_size) { 175 int key_id_size) {
161 DVLOG(1) << "AddKey()"; 176 DVLOG(1) << "AddKey()";
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 base::Bind(&CopyDecryptResults, &status, &buffer)); 218 base::Bind(&CopyDecryptResults, &status, &buffer));
204 219
205 if (status == media::Decryptor::kError) 220 if (status == media::Decryptor::kError)
206 return cdm::kError; 221 return cdm::kError;
207 222
208 if (status == media::Decryptor::kNoKey) 223 if (status == media::Decryptor::kNoKey)
209 return cdm::kNoKey; 224 return cdm::kNoKey;
210 225
211 DCHECK(buffer); 226 DCHECK(buffer);
212 int data_size = buffer->GetDataSize(); 227 int data_size = buffer->GetDataSize();
213 decrypted_buffer->data = AllocateAndCopy(buffer->GetData(), data_size); 228
214 decrypted_buffer->data_size = data_size; 229 if (!decrypted_buffer->set_buffer(allocator_->Allocate(data_size)))
215 decrypted_buffer->timestamp = buffer->GetTimestamp().InMicroseconds(); 230 return cdm::kError;
231
232 memcpy(reinterpret_cast<void*>(decrypted_buffer->buffer()->buffer()),
233 buffer->GetData(),
234 data_size);
235
236 decrypted_buffer->set_timestamp(buffer->GetTimestamp().InMicroseconds());
216 return cdm::kSuccess; 237 return cdm::kSuccess;
217 } 238 }
218 239
219 cdm::Status ClearKeyCdm::InitializeVideoDecoder( 240 cdm::Status ClearKeyCdm::InitializeVideoDecoder(
220 const cdm::VideoDecoderConfig& video_decoder_config) { 241 const cdm::VideoDecoderConfig& video_decoder_config) {
221 NOTIMPLEMENTED(); 242 NOTIMPLEMENTED();
222 return cdm::kError; 243 return cdm::kError;
223 } 244 }
224 245
225 cdm::Status ClearKeyCdm::DecryptAndDecodeVideo( 246 cdm::Status ClearKeyCdm::DecryptAndDecodeVideo(
226 const cdm::InputBuffer& encrypted_buffer, 247 const cdm::InputBuffer& encrypted_buffer,
227 cdm::VideoFrame* video_frame) { 248 cdm::VideoFrame* video_frame) {
228 NOTIMPLEMENTED(); 249 NOTIMPLEMENTED();
229 return cdm::kError; 250 return cdm::kError;
230 } 251 }
231 252
232 void ClearKeyCdm::ResetVideoDecoder() { 253 void ClearKeyCdm::ResetVideoDecoder() {
233 NOTIMPLEMENTED(); 254 NOTIMPLEMENTED();
234 } 255 }
235 256
236 void ClearKeyCdm::StopVideoDecoder() { 257 void ClearKeyCdm::StopVideoDecoder() {
237 NOTIMPLEMENTED(); 258 NOTIMPLEMENTED();
238 } 259 }
239 260
240 } // namespace webkit_media 261 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698