OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" | 5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <sstream> | 9 #include <sstream> |
10 #include <string> | 10 #include <string> |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 const int64 kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; | 88 const int64 kMaxTimerDelayMs = 1 * kSecondsPerMinute * kMsPerSecond; |
89 // Heart beat message header. If a key message starts with |kHeartBeatHeader|, | 89 // Heart beat message header. If a key message starts with |kHeartBeatHeader|, |
90 // it's a heart beat message. Otherwise, it's a key request. | 90 // it's a heart beat message. Otherwise, it's a key request. |
91 const char kHeartBeatHeader[] = "HEARTBEAT"; | 91 const char kHeartBeatHeader[] = "HEARTBEAT"; |
92 // CDM file IO test result header. | 92 // CDM file IO test result header. |
93 const char kFileIOTestResultHeader[] = "FILEIOTESTRESULT"; | 93 const char kFileIOTestResultHeader[] = "FILEIOTESTRESULT"; |
94 | 94 |
95 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is | 95 // Copies |input_buffer| into a media::DecoderBuffer. If the |input_buffer| is |
96 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. | 96 // empty, an empty (end-of-stream) media::DecoderBuffer is returned. |
97 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( | 97 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( |
98 const cdm::InputBuffer& input_buffer) { | 98 const cdm::InputBuffer_1& input_buffer) { |
99 if (!input_buffer.data) { | 99 if (!input_buffer.data) { |
100 DCHECK(!input_buffer.data_size); | 100 DCHECK(!input_buffer.data_size); |
101 return media::DecoderBuffer::CreateEOSBuffer(); | 101 return media::DecoderBuffer::CreateEOSBuffer(); |
102 } | 102 } |
103 | 103 |
104 // TODO(xhwang): Get rid of this copy. | 104 // TODO(xhwang): Get rid of this copy. |
105 scoped_refptr<media::DecoderBuffer> output_buffer = | 105 scoped_refptr<media::DecoderBuffer> output_buffer = |
106 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); | 106 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); |
107 | 107 |
108 std::vector<media::SubsampleEntry> subsamples; | 108 std::vector<media::SubsampleEntry> subsamples; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 374 |
375 static void CopyDecryptResults( | 375 static void CopyDecryptResults( |
376 media::Decryptor::Status* status_copy, | 376 media::Decryptor::Status* status_copy, |
377 scoped_refptr<media::DecoderBuffer>* buffer_copy, | 377 scoped_refptr<media::DecoderBuffer>* buffer_copy, |
378 media::Decryptor::Status status, | 378 media::Decryptor::Status status, |
379 const scoped_refptr<media::DecoderBuffer>& buffer) { | 379 const scoped_refptr<media::DecoderBuffer>& buffer) { |
380 *status_copy = status; | 380 *status_copy = status; |
381 *buffer_copy = buffer; | 381 *buffer_copy = buffer; |
382 } | 382 } |
383 | 383 |
384 cdm::Status ClearKeyCdm::Decrypt( | 384 cdm::Status ClearKeyCdm::Decrypt(const cdm::InputBuffer_1& encrypted_buffer, |
385 const cdm::InputBuffer& encrypted_buffer, | 385 cdm::DecryptedBlock* decrypted_block) { |
386 cdm::DecryptedBlock* decrypted_block) { | |
387 DVLOG(1) << "Decrypt()"; | 386 DVLOG(1) << "Decrypt()"; |
388 DCHECK(encrypted_buffer.data); | 387 DCHECK(encrypted_buffer.data); |
389 | 388 |
390 scoped_refptr<media::DecoderBuffer> buffer; | 389 scoped_refptr<media::DecoderBuffer> buffer; |
391 cdm::Status status = DecryptToMediaDecoderBuffer(encrypted_buffer, &buffer); | 390 cdm::Status status = DecryptToMediaDecoderBuffer(encrypted_buffer, &buffer); |
392 | 391 |
393 if (status != cdm::kSuccess) | 392 if (status != cdm::kSuccess) |
394 return status; | 393 return status; |
395 | 394 |
396 DCHECK(buffer->data()); | 395 DCHECK(buffer->data()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 output_timestamp_base_in_microseconds_ = kNoTimestamp; | 480 output_timestamp_base_in_microseconds_ = kNoTimestamp; |
482 total_samples_generated_ = 0; | 481 total_samples_generated_ = 0; |
483 #endif | 482 #endif |
484 break; | 483 break; |
485 default: | 484 default: |
486 NOTREACHED() << "DeinitializeDecoder(): invalid cdm::StreamType"; | 485 NOTREACHED() << "DeinitializeDecoder(): invalid cdm::StreamType"; |
487 } | 486 } |
488 } | 487 } |
489 | 488 |
490 cdm::Status ClearKeyCdm::DecryptAndDecodeFrame( | 489 cdm::Status ClearKeyCdm::DecryptAndDecodeFrame( |
491 const cdm::InputBuffer& encrypted_buffer, | 490 const cdm::InputBuffer_1& encrypted_buffer, |
492 cdm::VideoFrame* decoded_frame) { | 491 cdm::VideoFrame* decoded_frame) { |
493 DVLOG(1) << "DecryptAndDecodeFrame()"; | 492 DVLOG(1) << "DecryptAndDecodeFrame()"; |
494 TRACE_EVENT0("media", "ClearKeyCdm::DecryptAndDecodeFrame"); | 493 TRACE_EVENT0("media", "ClearKeyCdm::DecryptAndDecodeFrame"); |
495 | 494 |
496 scoped_refptr<media::DecoderBuffer> buffer; | 495 scoped_refptr<media::DecoderBuffer> buffer; |
497 cdm::Status status = DecryptToMediaDecoderBuffer(encrypted_buffer, &buffer); | 496 cdm::Status status = DecryptToMediaDecoderBuffer(encrypted_buffer, &buffer); |
498 | 497 |
499 if (status != cdm::kSuccess) | 498 if (status != cdm::kSuccess) |
500 return status; | 499 return status; |
501 | 500 |
502 const uint8_t* data = NULL; | 501 const uint8_t* data = NULL; |
503 int32_t size = 0; | 502 int32_t size = 0; |
504 int64_t timestamp = 0; | 503 int64_t timestamp = 0; |
505 if (!buffer->end_of_stream()) { | 504 if (!buffer->end_of_stream()) { |
506 data = buffer->data(); | 505 data = buffer->data(); |
507 size = buffer->data_size(); | 506 size = buffer->data_size(); |
508 timestamp = encrypted_buffer.timestamp; | 507 timestamp = encrypted_buffer.timestamp; |
509 } | 508 } |
510 | 509 |
511 return video_decoder_->DecodeFrame(data, size, timestamp, decoded_frame); | 510 return video_decoder_->DecodeFrame(data, size, timestamp, decoded_frame); |
512 } | 511 } |
513 | 512 |
514 cdm::Status ClearKeyCdm::DecryptAndDecodeSamples( | 513 cdm::Status ClearKeyCdm::DecryptAndDecodeSamples( |
515 const cdm::InputBuffer& encrypted_buffer, | 514 const cdm::InputBuffer_1& encrypted_buffer, |
516 cdm::AudioFrames* audio_frames) { | 515 cdm::AudioFrames* audio_frames) { |
517 DVLOG(1) << "DecryptAndDecodeSamples()"; | 516 DVLOG(1) << "DecryptAndDecodeSamples()"; |
518 | 517 |
519 // Trigger a crash on purpose for testing purpose. | 518 // Trigger a crash on purpose for testing purpose. |
520 if (key_system_ == kExternalClearKeyCrashKeySystem) | 519 if (key_system_ == kExternalClearKeyCrashKeySystem) |
521 CHECK(false); | 520 CHECK(false); |
522 | 521 |
523 scoped_refptr<media::DecoderBuffer> buffer; | 522 scoped_refptr<media::DecoderBuffer> buffer; |
524 cdm::Status status = DecryptToMediaDecoderBuffer(encrypted_buffer, &buffer); | 523 cdm::Status status = DecryptToMediaDecoderBuffer(encrypted_buffer, &buffer); |
525 | 524 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 | 562 |
564 host_->SetTimer(timer_delay_ms_, &next_heartbeat_message_[0]); | 563 host_->SetTimer(timer_delay_ms_, &next_heartbeat_message_[0]); |
565 | 564 |
566 // Use a smaller timer delay at start-up to facilitate testing. Increase the | 565 // Use a smaller timer delay at start-up to facilitate testing. Increase the |
567 // timer delay up to a limit to avoid message spam. | 566 // timer delay up to a limit to avoid message spam. |
568 if (timer_delay_ms_ < kMaxTimerDelayMs) | 567 if (timer_delay_ms_ < kMaxTimerDelayMs) |
569 timer_delay_ms_ = std::min(2 * timer_delay_ms_, kMaxTimerDelayMs); | 568 timer_delay_ms_ = std::min(2 * timer_delay_ms_, kMaxTimerDelayMs); |
570 } | 569 } |
571 | 570 |
572 cdm::Status ClearKeyCdm::DecryptToMediaDecoderBuffer( | 571 cdm::Status ClearKeyCdm::DecryptToMediaDecoderBuffer( |
573 const cdm::InputBuffer& encrypted_buffer, | 572 const cdm::InputBuffer_1& encrypted_buffer, |
574 scoped_refptr<media::DecoderBuffer>* decrypted_buffer) { | 573 scoped_refptr<media::DecoderBuffer>* decrypted_buffer) { |
575 DCHECK(decrypted_buffer); | 574 DCHECK(decrypted_buffer); |
576 scoped_refptr<media::DecoderBuffer> buffer = | 575 scoped_refptr<media::DecoderBuffer> buffer = |
577 CopyDecoderBufferFrom(encrypted_buffer); | 576 CopyDecoderBufferFrom(encrypted_buffer); |
578 | 577 |
579 if (buffer->end_of_stream()) { | 578 if (buffer->end_of_stream()) { |
580 *decrypted_buffer = buffer; | 579 *decrypted_buffer = buffer; |
581 return cdm::kSuccess; | 580 return cdm::kSuccess; |
582 } | 581 } |
583 | 582 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 host_->OnSessionMessage(last_session_id_.data(), | 790 host_->OnSessionMessage(last_session_id_.data(), |
792 last_session_id_.length(), | 791 last_session_id_.length(), |
793 message.data(), | 792 message.data(), |
794 message.length(), | 793 message.length(), |
795 NULL, | 794 NULL, |
796 0); | 795 0); |
797 file_io_test_runner_.reset(); | 796 file_io_test_runner_.reset(); |
798 } | 797 } |
799 | 798 |
800 } // namespace media | 799 } // namespace media |
OLD | NEW |