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

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

Issue 11147032: Fake video decoder in clearkey CDM. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops, more fixes Created 8 years, 2 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
« no previous file with comments | « webkit/media/crypto/ppapi/clear_key_cdm.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 memcpy(reinterpret_cast<void*>(decrypted_block->buffer()->data()), 229 memcpy(reinterpret_cast<void*>(decrypted_block->buffer()->data()),
230 buffer->GetData(), 230 buffer->GetData(),
231 data_size); 231 data_size);
232 232
233 decrypted_block->set_timestamp(buffer->GetTimestamp().InMicroseconds()); 233 decrypted_block->set_timestamp(buffer->GetTimestamp().InMicroseconds());
234 return cdm::kSuccess; 234 return cdm::kSuccess;
235 } 235 }
236 236
237 cdm::Status ClearKeyCdm::InitializeVideoDecoder( 237 cdm::Status ClearKeyCdm::InitializeVideoDecoder(
238 const cdm::VideoDecoderConfig& video_decoder_config) { 238 const cdm::VideoDecoderConfig& video_decoder_config) {
239 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER)
239 NOTIMPLEMENTED(); 240 NOTIMPLEMENTED();
240 return cdm::kSessionError; 241 return cdm::kSessionError;
242 #else
243 video_size_ = video_decoder_config.coded_size;
244 return cdm::kSuccess;
245 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER
241 } 246 }
242 247
243 void ClearKeyCdm::ResetDecoder(cdm::StreamType) { 248 void ClearKeyCdm::ResetDecoder(cdm::StreamType) {
244 NOTIMPLEMENTED(); 249 NOTIMPLEMENTED();
245 } 250 }
246 251
247 void ClearKeyCdm::DeinitializeDecoder(cdm::StreamType) { 252 void ClearKeyCdm::DeinitializeDecoder(cdm::StreamType) {
248 NOTIMPLEMENTED(); 253 NOTIMPLEMENTED();
249 } 254 }
250 255
251 cdm::Status ClearKeyCdm::DecryptAndDecodeFrame( 256 cdm::Status ClearKeyCdm::DecryptAndDecodeFrame(
252 const cdm::InputBuffer& encrypted_buffer, 257 const cdm::InputBuffer& encrypted_buffer,
253 cdm::VideoFrame* video_frame) { 258 cdm::VideoFrame* video_frame) {
259 if (!encrypted_buffer.data) {
260 video_frame->set_format(cdm::kEmptyVideoFrame);
261 return cdm::kSuccess;
262 }
263
264 scoped_refptr<media::DecoderBuffer> decoder_buffer =
265 CopyDecoderBufferFrom(encrypted_buffer);
266
267 // Callback is called synchronously, so we can use variables on the stack.
268 media::Decryptor::Status status;
269 scoped_refptr<media::DecoderBuffer> buffer;
270 decryptor_.Decrypt(decoder_buffer,
271 base::Bind(&CopyDecryptResults, &status, &buffer));
272
273 if (status == media::Decryptor::kError)
274 return cdm::kDecryptError;
275
276 if (status == media::Decryptor::kNoKey)
277 return cdm::kNoKey;
278
279 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER)
254 NOTIMPLEMENTED(); 280 NOTIMPLEMENTED();
255 return cdm::kDecryptError; 281 return cdm::kDecodeError;
282 #else
283 GenerateFakeVideoFrame(decoder_buffer->GetTimestamp(), video_frame);
284 return cdm::kSuccess;
285 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER
256 } 286 }
257 287
288 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER)
289 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp,
290 cdm::VideoFrame* video_frame) {
291 // Choose non-zero alignment and padding on purpose for testing.
292 const int kAlignment = 8;
293 const int kPadding = 16;
294 const int kPlanePadding = 128;
295
296 int width = video_size_.width;
297 int height = video_size_.height;
298 DCHECK(width % 2 == 0);
299 DCHECK(height % 2 == 0);
300
301 int y_stride = (width + kAlignment - 1) / kAlignment * kAlignment + kPadding;
302 int uv_stride =
303 (width / 2 + kAlignment - 1) / kAlignment * kAlignment + kPadding;
304 int y_rows = height;
305 int uv_rows = height / 2;
306 int y_offset = 0;
307 int v_offset = y_stride * y_rows + kPlanePadding;
308 int u_offset = v_offset + uv_stride * uv_rows + kPlanePadding;
309 int frame_size = u_offset + uv_stride * uv_rows + kPlanePadding;
310
311 video_frame->set_format(cdm::kYv12);
312 video_frame->set_size(video_size_);
313 video_frame->set_frame_buffer(allocator_->Allocate(frame_size));
314 video_frame->set_plane_offset(cdm::VideoFrame::kYPlane, y_offset);
315 video_frame->set_plane_offset(cdm::VideoFrame::kVPlane, v_offset);
316 video_frame->set_plane_offset(cdm::VideoFrame::kUPlane, u_offset);
317 video_frame->set_stride(cdm::VideoFrame::kYPlane, y_stride);
318 video_frame->set_stride(cdm::VideoFrame::kVPlane, uv_stride);
319 video_frame->set_stride(cdm::VideoFrame::kUPlane, uv_stride);
320 video_frame->set_timestamp(timestamp.InMicroseconds());
321
322 static unsigned char color = 0;
323 color += 10;
324
325 memset(reinterpret_cast<void*>(video_frame->frame_buffer()->data()),
326 color, frame_size);
327 }
328 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER
329
258 } // namespace webkit_media 330 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/crypto/ppapi/clear_key_cdm.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698