| 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" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 const cdm::InputBuffer& encrypted_buffer, | 206 const cdm::InputBuffer& encrypted_buffer, |
| 207 cdm::DecryptedBlock* decrypted_block) { | 207 cdm::DecryptedBlock* decrypted_block) { |
| 208 DVLOG(1) << "Decrypt()"; | 208 DVLOG(1) << "Decrypt()"; |
| 209 | 209 |
| 210 scoped_refptr<media::DecoderBuffer> decoder_buffer = | 210 scoped_refptr<media::DecoderBuffer> decoder_buffer = |
| 211 CopyDecoderBufferFrom(encrypted_buffer); | 211 CopyDecoderBufferFrom(encrypted_buffer); |
| 212 | 212 |
| 213 // Callback is called synchronously, so we can use variables on the stack. | 213 // Callback is called synchronously, so we can use variables on the stack. |
| 214 media::Decryptor::Status status; | 214 media::Decryptor::Status status; |
| 215 scoped_refptr<media::DecoderBuffer> buffer; | 215 scoped_refptr<media::DecoderBuffer> buffer; |
| 216 decryptor_.Decrypt(decoder_buffer, | 216 // We don't care what stream type it is here. So just pick video. |
| 217 decryptor_.Decrypt(media::Decryptor::kVideo, |
| 218 decoder_buffer, |
| 217 base::Bind(&CopyDecryptResults, &status, &buffer)); | 219 base::Bind(&CopyDecryptResults, &status, &buffer)); |
| 218 | 220 |
| 219 if (status == media::Decryptor::kError) | 221 if (status == media::Decryptor::kError) |
| 220 return cdm::kDecryptError; | 222 return cdm::kDecryptError; |
| 221 | 223 |
| 222 if (status == media::Decryptor::kNoKey) | 224 if (status == media::Decryptor::kNoKey) |
| 223 return cdm::kNoKey; | 225 return cdm::kNoKey; |
| 224 | 226 |
| 225 DCHECK(buffer); | 227 DCHECK(buffer); |
| 226 int data_size = buffer->GetDataSize(); | 228 int data_size = buffer->GetDataSize(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 video_frame->set_format(cdm::kEmptyVideoFrame); | 262 video_frame->set_format(cdm::kEmptyVideoFrame); |
| 261 return cdm::kSuccess; | 263 return cdm::kSuccess; |
| 262 } | 264 } |
| 263 | 265 |
| 264 scoped_refptr<media::DecoderBuffer> decoder_buffer = | 266 scoped_refptr<media::DecoderBuffer> decoder_buffer = |
| 265 CopyDecoderBufferFrom(encrypted_buffer); | 267 CopyDecoderBufferFrom(encrypted_buffer); |
| 266 | 268 |
| 267 // Callback is called synchronously, so we can use variables on the stack. | 269 // Callback is called synchronously, so we can use variables on the stack. |
| 268 media::Decryptor::Status status; | 270 media::Decryptor::Status status; |
| 269 scoped_refptr<media::DecoderBuffer> buffer; | 271 scoped_refptr<media::DecoderBuffer> buffer; |
| 270 decryptor_.Decrypt(decoder_buffer, | 272 decryptor_.Decrypt(media::Decryptor::kVideo, |
| 273 decoder_buffer, |
| 271 base::Bind(&CopyDecryptResults, &status, &buffer)); | 274 base::Bind(&CopyDecryptResults, &status, &buffer)); |
| 272 | 275 |
| 273 if (status == media::Decryptor::kError) | 276 if (status == media::Decryptor::kError) |
| 274 return cdm::kDecryptError; | 277 return cdm::kDecryptError; |
| 275 | 278 |
| 276 if (status == media::Decryptor::kNoKey) | 279 if (status == media::Decryptor::kNoKey) |
| 277 return cdm::kNoKey; | 280 return cdm::kNoKey; |
| 278 | 281 |
| 279 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) | 282 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
| 280 NOTIMPLEMENTED(); | 283 NOTIMPLEMENTED(); |
| 281 return cdm::kDecodeError; | 284 return cdm::kDecodeError; |
| 282 #else | 285 #else |
| 283 GenerateFakeVideoFrame(decoder_buffer->GetTimestamp(), video_frame); | 286 GenerateFakeVideoFrame(decoder_buffer->GetTimestamp(), video_frame); |
| 284 return cdm::kSuccess; | 287 return cdm::kSuccess; |
| 285 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER | 288 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER |
| 286 } | 289 } |
| 287 | 290 |
| 288 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) | 291 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
| 289 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp, | 292 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp, |
| 290 cdm::VideoFrame* video_frame) { | 293 cdm::VideoFrame* video_frame) { |
| 291 // Choose non-zero alignment and padding on purpose for testing. | 294 // Choose non-zero alignment and padding on purpose for testing. |
| 292 const int kAlignment = 8; | 295 const int kAlignment = 8; |
| 293 const int kPadding = 16; | 296 const int kPadding = 16; |
| 294 const int kPlanePadding = 128; | 297 const int kPlanePadding = 128; |
| 295 | 298 |
| 296 int width = video_size_.width; | 299 int width = video_size_.width; |
| 297 int height = video_size_.height; | 300 int height = video_size_.height; |
| 298 DCHECK(width % 2 == 0); | 301 DCHECK_EQ(width % 2, 0); |
| 299 DCHECK(height % 2 == 0); | 302 DCHECK_EQ(height % 2, 0); |
| 300 | 303 |
| 301 int y_stride = (width + kAlignment - 1) / kAlignment * kAlignment + kPadding; | 304 int y_stride = (width + kAlignment - 1) / kAlignment * kAlignment + kPadding; |
| 302 int uv_stride = | 305 int uv_stride = |
| 303 (width / 2 + kAlignment - 1) / kAlignment * kAlignment + kPadding; | 306 (width / 2 + kAlignment - 1) / kAlignment * kAlignment + kPadding; |
| 304 int y_rows = height; | 307 int y_rows = height; |
| 305 int uv_rows = height / 2; | 308 int uv_rows = height / 2; |
| 306 int y_offset = 0; | 309 int y_offset = 0; |
| 307 int v_offset = y_stride * y_rows + kPlanePadding; | 310 int v_offset = y_stride * y_rows + kPlanePadding; |
| 308 int u_offset = v_offset + uv_stride * uv_rows + kPlanePadding; | 311 int u_offset = v_offset + uv_stride * uv_rows + kPlanePadding; |
| 309 int frame_size = u_offset + uv_stride * uv_rows + kPlanePadding; | 312 int frame_size = u_offset + uv_stride * uv_rows + kPlanePadding; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 321 | 324 |
| 322 static unsigned char color = 0; | 325 static unsigned char color = 0; |
| 323 color += 10; | 326 color += 10; |
| 324 | 327 |
| 325 memset(reinterpret_cast<void*>(video_frame->frame_buffer()->data()), | 328 memset(reinterpret_cast<void*>(video_frame->frame_buffer()->data()), |
| 326 color, frame_size); | 329 color, frame_size); |
| 327 } | 330 } |
| 328 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER | 331 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER |
| 329 | 332 |
| 330 } // namespace webkit_media | 333 } // namespace webkit_media |
| OLD | NEW |