OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/cdm_adapter.h" | 5 #include "media/cdm/cdm_adapter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 DCHECK(task_runner_->BelongsToCurrentThread()); | 544 DCHECK(task_runner_->BelongsToCurrentThread()); |
545 | 545 |
546 cdm::InputBuffer input_buffer; | 546 cdm::InputBuffer input_buffer; |
547 std::vector<cdm::SubsampleEntry> subsamples; | 547 std::vector<cdm::SubsampleEntry> subsamples; |
548 std::unique_ptr<DecryptedBlockImpl> decrypted_block(new DecryptedBlockImpl()); | 548 std::unique_ptr<DecryptedBlockImpl> decrypted_block(new DecryptedBlockImpl()); |
549 | 549 |
550 ToCdmInputBuffer(encrypted, &subsamples, &input_buffer); | 550 ToCdmInputBuffer(encrypted, &subsamples, &input_buffer); |
551 cdm::Status status = cdm_->Decrypt(input_buffer, decrypted_block.get()); | 551 cdm::Status status = cdm_->Decrypt(input_buffer, decrypted_block.get()); |
552 | 552 |
553 if (status != cdm::kSuccess) { | 553 if (status != cdm::kSuccess) { |
554 DVLOG(1) << __FUNCTION__ << " failed with cdm::Error " << status; | 554 DVLOG(1) << __func__ << " failed with cdm::Error " << status; |
555 decrypt_cb.Run(ToMediaDecryptorStatus(status), nullptr); | 555 decrypt_cb.Run(ToMediaDecryptorStatus(status), nullptr); |
556 return; | 556 return; |
557 } | 557 } |
558 | 558 |
559 scoped_refptr<DecoderBuffer> decrypted_buffer( | 559 scoped_refptr<DecoderBuffer> decrypted_buffer( |
560 DecoderBuffer::CopyFrom(decrypted_block->DecryptedBuffer()->Data(), | 560 DecoderBuffer::CopyFrom(decrypted_block->DecryptedBuffer()->Data(), |
561 decrypted_block->DecryptedBuffer()->Size())); | 561 decrypted_block->DecryptedBuffer()->Size())); |
562 decrypted_buffer->set_timestamp( | 562 decrypted_buffer->set_timestamp( |
563 base::TimeDelta::FromMicroseconds(decrypted_block->Timestamp())); | 563 base::TimeDelta::FromMicroseconds(decrypted_block->Timestamp())); |
564 decrypt_cb.Run(Decryptor::kSuccess, decrypted_buffer); | 564 decrypt_cb.Run(Decryptor::kSuccess, decrypted_buffer); |
(...skipping 15 matching lines...) Expand all Loading... |
580 ChannelLayoutToChannelCount(config.channel_layout()); | 580 ChannelLayoutToChannelCount(config.channel_layout()); |
581 cdm_decoder_config.bits_per_channel = config.bits_per_channel(); | 581 cdm_decoder_config.bits_per_channel = config.bits_per_channel(); |
582 cdm_decoder_config.samples_per_second = config.samples_per_second(); | 582 cdm_decoder_config.samples_per_second = config.samples_per_second(); |
583 cdm_decoder_config.extra_data = | 583 cdm_decoder_config.extra_data = |
584 const_cast<uint8_t*>(config.extra_data().data()); | 584 const_cast<uint8_t*>(config.extra_data().data()); |
585 cdm_decoder_config.extra_data_size = config.extra_data().size(); | 585 cdm_decoder_config.extra_data_size = config.extra_data().size(); |
586 | 586 |
587 cdm::Status status = cdm_->InitializeAudioDecoder(cdm_decoder_config); | 587 cdm::Status status = cdm_->InitializeAudioDecoder(cdm_decoder_config); |
588 if (status != cdm::kSuccess && status != cdm::kDeferredInitialization) { | 588 if (status != cdm::kSuccess && status != cdm::kDeferredInitialization) { |
589 // DCHECK(status == cdm::kSessionError); http://crbug.com/570486 | 589 // DCHECK(status == cdm::kSessionError); http://crbug.com/570486 |
590 DVLOG(1) << __FUNCTION__ << " failed with cdm::Error " << status; | 590 DVLOG(1) << __func__ << " failed with cdm::Error " << status; |
591 init_cb.Run(false); | 591 init_cb.Run(false); |
592 return; | 592 return; |
593 } | 593 } |
594 | 594 |
595 audio_samples_per_second_ = config.samples_per_second(); | 595 audio_samples_per_second_ = config.samples_per_second(); |
596 audio_channel_layout_ = config.channel_layout(); | 596 audio_channel_layout_ = config.channel_layout(); |
597 | 597 |
598 if (status == cdm::kDeferredInitialization) { | 598 if (status == cdm::kDeferredInitialization) { |
599 DVLOG(1) << "Deferred initialization in " << __FUNCTION__; | 599 DVLOG(1) << "Deferred initialization in " << __func__; |
600 audio_init_cb_ = init_cb; | 600 audio_init_cb_ = init_cb; |
601 return; | 601 return; |
602 } | 602 } |
603 | 603 |
604 init_cb.Run(true); | 604 init_cb.Run(true); |
605 } | 605 } |
606 | 606 |
607 void CdmAdapter::InitializeVideoDecoder(const VideoDecoderConfig& config, | 607 void CdmAdapter::InitializeVideoDecoder(const VideoDecoderConfig& config, |
608 const DecoderInitCB& init_cb) { | 608 const DecoderInitCB& init_cb) { |
609 DCHECK(task_runner_->BelongsToCurrentThread()); | 609 DCHECK(task_runner_->BelongsToCurrentThread()); |
610 DCHECK(video_init_cb_.is_null()); | 610 DCHECK(video_init_cb_.is_null()); |
611 | 611 |
612 cdm::VideoDecoderConfig cdm_decoder_config; | 612 cdm::VideoDecoderConfig cdm_decoder_config; |
613 cdm_decoder_config.codec = ToCdmVideoCodec(config.codec()); | 613 cdm_decoder_config.codec = ToCdmVideoCodec(config.codec()); |
614 cdm_decoder_config.profile = ToCdmVideoCodecProfile(config.profile()); | 614 cdm_decoder_config.profile = ToCdmVideoCodecProfile(config.profile()); |
615 cdm_decoder_config.format = ToCdmVideoFormat(config.format()); | 615 cdm_decoder_config.format = ToCdmVideoFormat(config.format()); |
616 cdm_decoder_config.coded_size.width = config.coded_size().width(); | 616 cdm_decoder_config.coded_size.width = config.coded_size().width(); |
617 cdm_decoder_config.coded_size.height = config.coded_size().height(); | 617 cdm_decoder_config.coded_size.height = config.coded_size().height(); |
618 cdm_decoder_config.extra_data = | 618 cdm_decoder_config.extra_data = |
619 const_cast<uint8_t*>(config.extra_data().data()); | 619 const_cast<uint8_t*>(config.extra_data().data()); |
620 cdm_decoder_config.extra_data_size = config.extra_data().size(); | 620 cdm_decoder_config.extra_data_size = config.extra_data().size(); |
621 | 621 |
622 cdm::Status status = cdm_->InitializeVideoDecoder(cdm_decoder_config); | 622 cdm::Status status = cdm_->InitializeVideoDecoder(cdm_decoder_config); |
623 if (status != cdm::kSuccess && status != cdm::kDeferredInitialization) { | 623 if (status != cdm::kSuccess && status != cdm::kDeferredInitialization) { |
624 // DCHECK(status == cdm::kSessionError); http://crbug.com/570486 | 624 // DCHECK(status == cdm::kSessionError); http://crbug.com/570486 |
625 DVLOG(1) << __FUNCTION__ << " failed with cdm::Error " << status; | 625 DVLOG(1) << __func__ << " failed with cdm::Error " << status; |
626 init_cb.Run(false); | 626 init_cb.Run(false); |
627 return; | 627 return; |
628 } | 628 } |
629 | 629 |
630 natural_size_ = config.natural_size(); | 630 natural_size_ = config.natural_size(); |
631 | 631 |
632 if (status == cdm::kDeferredInitialization) { | 632 if (status == cdm::kDeferredInitialization) { |
633 DVLOG(1) << "Deferred initialization in " << __FUNCTION__; | 633 DVLOG(1) << "Deferred initialization in " << __func__; |
634 video_init_cb_ = init_cb; | 634 video_init_cb_ = init_cb; |
635 return; | 635 return; |
636 } | 636 } |
637 | 637 |
638 init_cb.Run(true); | 638 init_cb.Run(true); |
639 } | 639 } |
640 | 640 |
641 void CdmAdapter::DecryptAndDecodeAudio( | 641 void CdmAdapter::DecryptAndDecodeAudio( |
642 const scoped_refptr<DecoderBuffer>& encrypted, | 642 const scoped_refptr<DecoderBuffer>& encrypted, |
643 const AudioDecodeCB& audio_decode_cb) { | 643 const AudioDecodeCB& audio_decode_cb) { |
644 DCHECK(task_runner_->BelongsToCurrentThread()); | 644 DCHECK(task_runner_->BelongsToCurrentThread()); |
645 | 645 |
646 cdm::InputBuffer input_buffer; | 646 cdm::InputBuffer input_buffer; |
647 std::vector<cdm::SubsampleEntry> subsamples; | 647 std::vector<cdm::SubsampleEntry> subsamples; |
648 std::unique_ptr<AudioFramesImpl> audio_frames(new AudioFramesImpl()); | 648 std::unique_ptr<AudioFramesImpl> audio_frames(new AudioFramesImpl()); |
649 | 649 |
650 ToCdmInputBuffer(encrypted, &subsamples, &input_buffer); | 650 ToCdmInputBuffer(encrypted, &subsamples, &input_buffer); |
651 cdm::Status status = | 651 cdm::Status status = |
652 cdm_->DecryptAndDecodeSamples(input_buffer, audio_frames.get()); | 652 cdm_->DecryptAndDecodeSamples(input_buffer, audio_frames.get()); |
653 | 653 |
654 const Decryptor::AudioFrames empty_frames; | 654 const Decryptor::AudioFrames empty_frames; |
655 if (status != cdm::kSuccess) { | 655 if (status != cdm::kSuccess) { |
656 DVLOG(1) << __FUNCTION__ << " failed with cdm::Error " << status; | 656 DVLOG(1) << __func__ << " failed with cdm::Error " << status; |
657 audio_decode_cb.Run(ToMediaDecryptorStatus(status), empty_frames); | 657 audio_decode_cb.Run(ToMediaDecryptorStatus(status), empty_frames); |
658 return; | 658 return; |
659 } | 659 } |
660 | 660 |
661 Decryptor::AudioFrames audio_frame_list; | 661 Decryptor::AudioFrames audio_frame_list; |
662 DCHECK(audio_frames->FrameBuffer()); | 662 DCHECK(audio_frames->FrameBuffer()); |
663 if (!AudioFramesDataToAudioFrames(std::move(audio_frames), | 663 if (!AudioFramesDataToAudioFrames(std::move(audio_frames), |
664 &audio_frame_list)) { | 664 &audio_frame_list)) { |
665 DVLOG(1) << __FUNCTION__ << " unable to convert Audio Frames"; | 665 DVLOG(1) << __func__ << " unable to convert Audio Frames"; |
666 audio_decode_cb.Run(Decryptor::kError, empty_frames); | 666 audio_decode_cb.Run(Decryptor::kError, empty_frames); |
667 return; | 667 return; |
668 } | 668 } |
669 | 669 |
670 audio_decode_cb.Run(Decryptor::kSuccess, audio_frame_list); | 670 audio_decode_cb.Run(Decryptor::kSuccess, audio_frame_list); |
671 } | 671 } |
672 | 672 |
673 void CdmAdapter::DecryptAndDecodeVideo( | 673 void CdmAdapter::DecryptAndDecodeVideo( |
674 const scoped_refptr<DecoderBuffer>& encrypted, | 674 const scoped_refptr<DecoderBuffer>& encrypted, |
675 const VideoDecodeCB& video_decode_cb) { | 675 const VideoDecodeCB& video_decode_cb) { |
676 DCHECK(task_runner_->BelongsToCurrentThread()); | 676 DCHECK(task_runner_->BelongsToCurrentThread()); |
677 DVLOG(3) << __FUNCTION__ | 677 DVLOG(3) << __func__ << " encrypted: " << encrypted->AsHumanReadableString(); |
678 << " encrypted: " << encrypted->AsHumanReadableString(); | |
679 | 678 |
680 cdm::InputBuffer input_buffer; | 679 cdm::InputBuffer input_buffer; |
681 std::vector<cdm::SubsampleEntry> subsamples; | 680 std::vector<cdm::SubsampleEntry> subsamples; |
682 std::unique_ptr<VideoFrameImpl> video_frame = | 681 std::unique_ptr<VideoFrameImpl> video_frame = |
683 allocator_->CreateCdmVideoFrame(); | 682 allocator_->CreateCdmVideoFrame(); |
684 | 683 |
685 ToCdmInputBuffer(encrypted, &subsamples, &input_buffer); | 684 ToCdmInputBuffer(encrypted, &subsamples, &input_buffer); |
686 cdm::Status status = | 685 cdm::Status status = |
687 cdm_->DecryptAndDecodeFrame(input_buffer, video_frame.get()); | 686 cdm_->DecryptAndDecodeFrame(input_buffer, video_frame.get()); |
688 | 687 |
689 if (status != cdm::kSuccess) { | 688 if (status != cdm::kSuccess) { |
690 DVLOG(1) << __FUNCTION__ << " failed with cdm::Error " << status; | 689 DVLOG(1) << __func__ << " failed with cdm::Error " << status; |
691 video_decode_cb.Run(ToMediaDecryptorStatus(status), nullptr); | 690 video_decode_cb.Run(ToMediaDecryptorStatus(status), nullptr); |
692 return; | 691 return; |
693 } | 692 } |
694 | 693 |
695 scoped_refptr<VideoFrame> decoded_frame = | 694 scoped_refptr<VideoFrame> decoded_frame = |
696 video_frame->TransformToVideoFrame(natural_size_); | 695 video_frame->TransformToVideoFrame(natural_size_); |
697 video_decode_cb.Run(Decryptor::kSuccess, decoded_frame); | 696 video_decode_cb.Run(Decryptor::kSuccess, decoded_frame); |
698 } | 697 } |
699 | 698 |
700 void CdmAdapter::ResetDecoder(StreamType stream_type) { | 699 void CdmAdapter::ResetDecoder(StreamType stream_type) { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 | 873 |
875 // TODO(jrummell): If output protection is available, use it. | 874 // TODO(jrummell): If output protection is available, use it. |
876 NOTIMPLEMENTED(); | 875 NOTIMPLEMENTED(); |
877 cdm_->OnQueryOutputProtectionStatus(cdm::kQueryFailed, 0, 0); | 876 cdm_->OnQueryOutputProtectionStatus(cdm::kQueryFailed, 0, 0); |
878 } | 877 } |
879 | 878 |
880 void CdmAdapter::OnDeferredInitializationDone(cdm::StreamType stream_type, | 879 void CdmAdapter::OnDeferredInitializationDone(cdm::StreamType stream_type, |
881 cdm::Status decoder_status) { | 880 cdm::Status decoder_status) { |
882 DCHECK(task_runner_->BelongsToCurrentThread()); | 881 DCHECK(task_runner_->BelongsToCurrentThread()); |
883 DVLOG_IF(1, decoder_status != cdm::kSuccess) | 882 DVLOG_IF(1, decoder_status != cdm::kSuccess) |
884 << __FUNCTION__ << " failed with cdm::Error " << decoder_status; | 883 << __func__ << " failed with cdm::Error " << decoder_status; |
885 | 884 |
886 switch (stream_type) { | 885 switch (stream_type) { |
887 case cdm::kStreamTypeAudio: | 886 case cdm::kStreamTypeAudio: |
888 base::ResetAndReturn(&audio_init_cb_) | 887 base::ResetAndReturn(&audio_init_cb_) |
889 .Run(decoder_status == cdm::kSuccess); | 888 .Run(decoder_status == cdm::kSuccess); |
890 return; | 889 return; |
891 case cdm::kStreamTypeVideo: | 890 case cdm::kStreamTypeVideo: |
892 base::ResetAndReturn(&video_init_cb_) | 891 base::ResetAndReturn(&video_init_cb_) |
893 .Run(decoder_status == cdm::kSuccess); | 892 .Run(decoder_status == cdm::kSuccess); |
894 return; | 893 return; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 result_frames->push_back(frame); | 959 result_frames->push_back(frame); |
961 | 960 |
962 data += frame_size; | 961 data += frame_size; |
963 bytes_left -= frame_size; | 962 bytes_left -= frame_size; |
964 } while (bytes_left > 0); | 963 } while (bytes_left > 0); |
965 | 964 |
966 return true; | 965 return true; |
967 } | 966 } |
968 | 967 |
969 } // namespace media | 968 } // namespace media |
OLD | NEW |