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

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: 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
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_DECODER)
240 NOTIMPLEMENTED();
241 return cdm::kSessionError;
242 #else
239 video_size_ = video_decoder_config.coded_size; 243 video_size_ = video_decoder_config.coded_size;
240 return cdm::kSuccess; 244 return cdm::kSuccess;
245 #endif
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
(...skipping 13 matching lines...) Expand all
264 scoped_refptr<media::DecoderBuffer> buffer; 269 scoped_refptr<media::DecoderBuffer> buffer;
265 decryptor_.Decrypt(decoder_buffer, 270 decryptor_.Decrypt(decoder_buffer,
266 base::Bind(&CopyDecryptResults, &status, &buffer)); 271 base::Bind(&CopyDecryptResults, &status, &buffer));
267 272
268 if (status == media::Decryptor::kError) 273 if (status == media::Decryptor::kError)
269 return cdm::kDecryptError; 274 return cdm::kDecryptError;
270 275
271 if (status == media::Decryptor::kNoKey) 276 if (status == media::Decryptor::kNoKey)
272 return cdm::kNoKey; 277 return cdm::kNoKey;
273 278
279 #if !defined(CLEAR_KEY_CDM_USE_FAKE_DECODER)
280 NOTIMPLEMENTED();
281 return cdm::kDecodeError;
282 #else
274 GenerateFakeVideoFrame(decoder_buffer->GetTimestamp(), video_frame); 283 GenerateFakeVideoFrame(decoder_buffer->GetTimestamp(), video_frame);
275 return cdm::kSuccess; 284 return cdm::kSuccess;
285 #endif
276 } 286 }
277 287
288 #if defined(CLEAR_KEY_CDM_USE_FAKE_DECODER)
278 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp, 289 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp,
279 cdm::VideoFrame* video_frame) { 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
280 int width = video_size_.width; 296 int width = video_size_.width;
281 int height = video_size_.height; 297 int height = video_size_.height;
282 int alignment = 8; 298 DCHECK(width % 2 == 0);
283 int padding = 16; 299 DCHECK(height % 2 == 0);
284 int y_stride = (width + alignment - 1) / alignment * alignment + padding; 300
285 int uv_stride = (width / 2 + alignment - 1) / alignment * alignment + padding; 301 int y_stride = (width + kAlignment - 1) / kAlignment * kAlignment + kPadding;
302 int uv_stride =
303 (width / 2 + kAlignment - 1) / kAlignment * kAlignment + kPadding;
286 int y_rows = height; 304 int y_rows = height;
287 int uv_rows = height / 2; 305 int uv_rows = height / 2;
288 int plane_padding = 128;
289 int y_offset = 0; 306 int y_offset = 0;
290 int v_offset = y_stride * y_rows + plane_padding; 307 int v_offset = y_stride * y_rows + kPlanePadding;
291 int u_offset = v_offset + uv_stride * uv_rows + plane_padding; 308 int u_offset = v_offset + uv_stride * uv_rows + kPlanePadding;
292 int frame_size = u_offset + uv_stride * uv_rows + plane_padding; 309 int frame_size = u_offset + uv_stride * uv_rows + kPlanePadding;
293 310
294 video_frame->set_format(cdm::kYv12); 311 video_frame->set_format(cdm::kYv12);
295 video_frame->set_size(video_size_); 312 video_frame->set_size(video_size_);
296 video_frame->set_frame_buffer(allocator_->Allocate(frame_size)); 313 video_frame->set_frame_buffer(allocator_->Allocate(frame_size));
297 video_frame->set_plane_offset(cdm::VideoFrame::kYPlane, y_offset); 314 video_frame->set_plane_offset(cdm::VideoFrame::kYPlane, y_offset);
298 video_frame->set_plane_offset(cdm::VideoFrame::kVPlane, v_offset); 315 video_frame->set_plane_offset(cdm::VideoFrame::kVPlane, v_offset);
299 video_frame->set_plane_offset(cdm::VideoFrame::kUPlane, u_offset); 316 video_frame->set_plane_offset(cdm::VideoFrame::kUPlane, u_offset);
300 video_frame->set_stride(cdm::VideoFrame::kYPlane, y_stride); 317 video_frame->set_stride(cdm::VideoFrame::kYPlane, y_stride);
301 video_frame->set_stride(cdm::VideoFrame::kVPlane, uv_stride); 318 video_frame->set_stride(cdm::VideoFrame::kVPlane, uv_stride);
302 video_frame->set_stride(cdm::VideoFrame::kUPlane, uv_stride); 319 video_frame->set_stride(cdm::VideoFrame::kUPlane, uv_stride);
303 video_frame->set_timestamp(timestamp.InMicroseconds()); 320 video_frame->set_timestamp(timestamp.InMicroseconds());
304 321
305 static unsigned char color = 0; 322 static unsigned char color = 0;
306 color += 10; 323 color += 10;
307 324
308 memset(reinterpret_cast<void*>(video_frame->frame_buffer()->data()), 325 memset(reinterpret_cast<void*>(video_frame->frame_buffer()->data()),
309 color, frame_size); 326 color, frame_size);
310 } 327 }
328 #endif // CLEAR_KEY_CDM_USE_FAKE_DECODER
311 329
312 } // namespace webkit_media 330 } // namespace webkit_media
OLDNEW
« webkit/media/crypto/ppapi/clear_key_cdm.h ('K') | « 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