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

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

Issue 10899021: Add CDM video decoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests on linux. 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"
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/ffmpeg_cdm_video_decoder.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 DCHECK(input_buffer.data); 19 DCHECK(input_buffer.data);
19 // TODO(tomfinegan): Get rid of this copy. 20 // TODO(tomfinegan): Get rid of this copy.
20 scoped_refptr<media::DecoderBuffer> output_buffer = 21 scoped_refptr<media::DecoderBuffer> output_buffer =
21 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); 22 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size);
22 23
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 buffer->GetData(), 233 buffer->GetData(),
233 data_size); 234 data_size);
234 235
235 decrypted_block->set_timestamp(buffer->GetTimestamp().InMicroseconds()); 236 decrypted_block->set_timestamp(buffer->GetTimestamp().InMicroseconds());
236 return cdm::kSuccess; 237 return cdm::kSuccess;
237 } 238 }
238 239
239 cdm::Status ClearKeyCdm::InitializeVideoDecoder( 240 cdm::Status ClearKeyCdm::InitializeVideoDecoder(
240 const cdm::VideoDecoderConfig& video_decoder_config) { 241 const cdm::VideoDecoderConfig& video_decoder_config) {
241 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) 242 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER)
242 NOTIMPLEMENTED(); 243 if (!video_decoder_)
243 return cdm::kSessionError; 244 video_decoder_.reset(new webkit_media::FFmpegCdmVideoDecoder(allocator_));
245
246 if (!video_decoder_->Initialize(video_decoder_config))
247 return cdm::kSessionError;
244 #else 248 #else
245 video_size_ = video_decoder_config.coded_size; 249 video_size_ = video_decoder_config.coded_size;
250 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER
246 return cdm::kSuccess; 251 return cdm::kSuccess;
247 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER
248 } 252 }
249 253
250 void ClearKeyCdm::ResetDecoder(cdm::StreamType) { 254 void ClearKeyCdm::ResetDecoder(cdm::StreamType decoder_type) {
251 NOTIMPLEMENTED(); 255 DCHECK(decoder_type == cdm::kStreamTypeVideo);
256 video_decoder_->Reset();
252 } 257 }
253 258
254 void ClearKeyCdm::DeinitializeDecoder(cdm::StreamType) { 259 void ClearKeyCdm::DeinitializeDecoder(cdm::StreamType decoder_type) {
255 NOTIMPLEMENTED(); 260 DCHECK(decoder_type == cdm::kStreamTypeVideo);
261 video_decoder_->Deinitialize();
256 } 262 }
257 263
258 cdm::Status ClearKeyCdm::DecryptAndDecodeFrame( 264 cdm::Status ClearKeyCdm::DecryptAndDecodeFrame(
259 const cdm::InputBuffer& encrypted_buffer, 265 const cdm::InputBuffer& encrypted_buffer,
260 cdm::VideoFrame* video_frame) { 266 cdm::VideoFrame* decoded_frame) {
261 if (!encrypted_buffer.data) { 267 if (!encrypted_buffer.data) {
262 video_frame->set_format(cdm::kEmptyVideoFrame); 268 decoded_frame->set_format(cdm::kEmptyVideoFrame);
263 return cdm::kSuccess; 269 return cdm::kSuccess;
264 } 270 }
265 271
266 scoped_refptr<media::DecoderBuffer> decoder_buffer = 272 scoped_refptr<media::DecoderBuffer> decoder_buffer =
267 CopyDecoderBufferFrom(encrypted_buffer); 273 CopyDecoderBufferFrom(encrypted_buffer);
268 274
269 // Callback is called synchronously, so we can use variables on the stack. 275 // Callback is called synchronously, so we can use variables on the stack.
270 media::Decryptor::Status status; 276 media::Decryptor::Status status;
271 scoped_refptr<media::DecoderBuffer> buffer; 277 scoped_refptr<media::DecoderBuffer> buffer;
272 decryptor_.Decrypt(media::Decryptor::kVideo, 278 decryptor_.Decrypt(media::Decryptor::kVideo,
273 decoder_buffer, 279 decoder_buffer,
274 base::Bind(&CopyDecryptResults, &status, &buffer)); 280 base::Bind(&CopyDecryptResults, &status, &buffer));
275 281
276 if (status == media::Decryptor::kError) 282 if (status == media::Decryptor::kError)
277 return cdm::kDecryptError; 283 return cdm::kDecryptError;
278 284
279 if (status == media::Decryptor::kNoKey) 285 if (status == media::Decryptor::kNoKey)
280 return cdm::kNoKey; 286 return cdm::kNoKey;
281 287
282 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) 288 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER)
283 NOTIMPLEMENTED(); 289 DCHECK(status == media::Decryptor::kSuccess);
284 return cdm::kDecodeError; 290 DCHECK(buffer);
291 return video_decoder_->DecodeFrame(buffer.get()->GetData(),
292 buffer->GetDataSize(),
293 encrypted_buffer.timestamp,
294 decoded_frame);
285 #else 295 #else
286 GenerateFakeVideoFrame(decoder_buffer->GetTimestamp(), video_frame); 296 GenerateFakeVideoFrame(decoder_buffer->GetTimestamp(), video_frame);
287 return cdm::kSuccess; 297 return cdm::kSuccess;
288 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER 298 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER
289 } 299 }
290 300
291 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) 301 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER)
292 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp, 302 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp,
293 cdm::VideoFrame* video_frame) { 303 cdm::VideoFrame* video_frame) {
294 // Choose non-zero alignment and padding on purpose for testing. 304 // Choose non-zero alignment and padding on purpose for testing.
(...skipping 29 matching lines...) Expand all
324 334
325 static unsigned char color = 0; 335 static unsigned char color = 0;
326 color += 10; 336 color += 10;
327 337
328 memset(reinterpret_cast<void*>(video_frame->frame_buffer()->data()), 338 memset(reinterpret_cast<void*>(video_frame->frame_buffer()->data()),
329 color, frame_size); 339 color, frame_size);
330 } 340 }
331 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER 341 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER
332 342
333 } // namespace webkit_media 343 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698