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