| Index: media/mojo/services/mojo_decryptor.cc
|
| diff --git a/media/mojo/services/mojo_decryptor.cc b/media/mojo/services/mojo_decryptor.cc
|
| index 74af5cf7772c8e0c9f813517f92cf91c0c43f03f..cc1b250b8a3652cbb4e13398ea7fc0355fe7c133 100644
|
| --- a/media/mojo/services/mojo_decryptor.cc
|
| +++ b/media/mojo/services/mojo_decryptor.cc
|
| @@ -17,7 +17,9 @@
|
| namespace media {
|
|
|
| MojoDecryptor::MojoDecryptor(interfaces::DecryptorPtr remote_decryptor)
|
| - : remote_decryptor_(std::move(remote_decryptor)), weak_factory_(this) {}
|
| + : remote_decryptor_(std::move(remote_decryptor)), weak_factory_(this) {
|
| + CreateDataPipes();
|
| +}
|
|
|
| MojoDecryptor::~MojoDecryptor() {}
|
|
|
| @@ -38,26 +40,30 @@ void MojoDecryptor::RegisterNewKeyCB(StreamType stream_type,
|
| void MojoDecryptor::Decrypt(StreamType stream_type,
|
| const scoped_refptr<DecoderBuffer>& encrypted,
|
| const DecryptCB& decrypt_cb) {
|
| + DVLOG(3) << __FUNCTION__;
|
| remote_decryptor_->Decrypt(
|
| static_cast<interfaces::DemuxerStream::Type>(stream_type),
|
| - interfaces::DecoderBuffer::From(encrypted),
|
| + TransferDecoderBuffer(encrypted),
|
| base::Bind(&MojoDecryptor::OnBufferDecrypted, weak_factory_.GetWeakPtr(),
|
| decrypt_cb));
|
| }
|
|
|
| void MojoDecryptor::CancelDecrypt(StreamType stream_type) {
|
| + DVLOG(1) << __FUNCTION__;
|
| remote_decryptor_->CancelDecrypt(
|
| static_cast<interfaces::DemuxerStream::Type>(stream_type));
|
| }
|
|
|
| void MojoDecryptor::InitializeAudioDecoder(const AudioDecoderConfig& config,
|
| const DecoderInitCB& init_cb) {
|
| + DVLOG(1) << __FUNCTION__;
|
| remote_decryptor_->InitializeAudioDecoder(
|
| interfaces::AudioDecoderConfig::From(config), init_cb);
|
| }
|
|
|
| void MojoDecryptor::InitializeVideoDecoder(const VideoDecoderConfig& config,
|
| const DecoderInitCB& init_cb) {
|
| + DVLOG(1) << __FUNCTION__;
|
| remote_decryptor_->InitializeVideoDecoder(
|
| interfaces::VideoDecoderConfig::From(config), init_cb);
|
| }
|
| @@ -65,8 +71,9 @@ void MojoDecryptor::InitializeVideoDecoder(const VideoDecoderConfig& config,
|
| void MojoDecryptor::DecryptAndDecodeAudio(
|
| const scoped_refptr<DecoderBuffer>& encrypted,
|
| const AudioDecodeCB& audio_decode_cb) {
|
| + DVLOG(3) << __FUNCTION__;
|
| remote_decryptor_->DecryptAndDecodeAudio(
|
| - interfaces::DecoderBuffer::From(encrypted),
|
| + TransferDecoderBuffer(encrypted),
|
| base::Bind(&MojoDecryptor::OnAudioDecoded, weak_factory_.GetWeakPtr(),
|
| audio_decode_cb));
|
| }
|
| @@ -74,23 +81,27 @@ void MojoDecryptor::DecryptAndDecodeAudio(
|
| void MojoDecryptor::DecryptAndDecodeVideo(
|
| const scoped_refptr<DecoderBuffer>& encrypted,
|
| const VideoDecodeCB& video_decode_cb) {
|
| + DVLOG(3) << __FUNCTION__;
|
| remote_decryptor_->DecryptAndDecodeVideo(
|
| - interfaces::DecoderBuffer::From(encrypted),
|
| + TransferDecoderBuffer(encrypted),
|
| base::Bind(&MojoDecryptor::OnVideoDecoded, weak_factory_.GetWeakPtr(),
|
| video_decode_cb));
|
| }
|
|
|
| void MojoDecryptor::ResetDecoder(StreamType stream_type) {
|
| + DVLOG(1) << __FUNCTION__;
|
| remote_decryptor_->ResetDecoder(
|
| static_cast<interfaces::DemuxerStream::Type>(stream_type));
|
| }
|
|
|
| void MojoDecryptor::DeinitializeDecoder(StreamType stream_type) {
|
| + DVLOG(1) << __FUNCTION__;
|
| remote_decryptor_->DeinitializeDecoder(
|
| static_cast<interfaces::DemuxerStream::Type>(stream_type));
|
| }
|
|
|
| void MojoDecryptor::OnKeyAdded() {
|
| + DVLOG(1) << __FUNCTION__;
|
| if (!new_audio_key_cb_.is_null())
|
| new_audio_key_cb_.Run();
|
|
|
| @@ -101,14 +112,23 @@ void MojoDecryptor::OnKeyAdded() {
|
| void MojoDecryptor::OnBufferDecrypted(const DecryptCB& decrypt_cb,
|
| interfaces::Decryptor::Status status,
|
| interfaces::DecoderBufferPtr buffer) {
|
| + DVLOG(status != interfaces::Decryptor::STATUS_SUCCESS ? 1 : 3)
|
| + << __FUNCTION__ << "(" << status << ")";
|
| + if (buffer.is_null()) {
|
| + decrypt_cb.Run(static_cast<Decryptor::Status>(status), nullptr);
|
| + return;
|
| + }
|
| +
|
| decrypt_cb.Run(static_cast<Decryptor::Status>(status),
|
| - std::move(buffer.To<scoped_refptr<DecoderBuffer>>()));
|
| + ReadDecoderBuffer(std::move(buffer)));
|
| }
|
|
|
| void MojoDecryptor::OnAudioDecoded(
|
| const AudioDecodeCB& audio_decode_cb,
|
| interfaces::Decryptor::Status status,
|
| mojo::Array<interfaces::AudioBufferPtr> audio_buffers) {
|
| + DVLOG(status != interfaces::Decryptor::STATUS_SUCCESS ? 1 : 3)
|
| + << __FUNCTION__ << "(" << status << ")";
|
| Decryptor::AudioFrames audio_frames;
|
| for (size_t i = 0; i < audio_buffers.size(); ++i)
|
| audio_frames.push_back(audio_buffers[i].To<scoped_refptr<AudioBuffer>>());
|
| @@ -119,8 +139,72 @@ void MojoDecryptor::OnAudioDecoded(
|
| void MojoDecryptor::OnVideoDecoded(const VideoDecodeCB& video_decode_cb,
|
| interfaces::Decryptor::Status status,
|
| interfaces::VideoFramePtr video_frame) {
|
| - video_decode_cb.Run(static_cast<Decryptor::Status>(status),
|
| - std::move(video_frame.To<scoped_refptr<VideoFrame>>()));
|
| + DVLOG(status != interfaces::Decryptor::STATUS_SUCCESS ? 1 : 3)
|
| + << __FUNCTION__ << "(" << status << ")";
|
| + if (video_frame.is_null()) {
|
| + video_decode_cb.Run(static_cast<Decryptor::Status>(status), nullptr);
|
| + return;
|
| + }
|
| +
|
| + scoped_refptr<VideoFrame> frame(video_frame.To<scoped_refptr<VideoFrame>>());
|
| + video_decode_cb.Run(static_cast<Decryptor::Status>(status), frame);
|
| +}
|
| +
|
| +void MojoDecryptor::CreateDataPipes() {
|
| + // Allocate DataPipe size based on video content. Video can get quite large;
|
| + // at 4K, VP9 delivers packets which are ~1MB in size; so allow for 50%
|
| + // headroom.
|
| + MojoCreateDataPipeOptions options;
|
| + options.struct_size = sizeof(MojoCreateDataPipeOptions);
|
| + options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
|
| + options.element_num_bytes = 1;
|
| + options.capacity_num_bytes = 1.5 * (1024 * 1024);
|
| +
|
| + // Create 2 pipes, one for each direction.
|
| + mojo::DataPipe write_pipe(options);
|
| + mojo::DataPipe read_pipe(options);
|
| +
|
| + // Keep one end of each pipe.
|
| + producer_handle_ = std::move(write_pipe.producer_handle);
|
| + consumer_handle_ = std::move(read_pipe.consumer_handle);
|
| +
|
| + // Pass the other end of each pipe to |remote_decryptor_|.
|
| + remote_decryptor_->Initialize(std::move(write_pipe.consumer_handle),
|
| + std::move(read_pipe.producer_handle));
|
| +}
|
| +
|
| +interfaces::DecoderBufferPtr MojoDecryptor::TransferDecoderBuffer(
|
| + const scoped_refptr<DecoderBuffer>& encrypted) {
|
| + interfaces::DecoderBufferPtr buffer =
|
| + interfaces::DecoderBuffer::From(encrypted);
|
| + if (encrypted->end_of_stream())
|
| + return buffer;
|
| +
|
| + // Serialize the data section of the DecoderBuffer into our pipe.
|
| + uint32_t num_bytes = encrypted->data_size();
|
| + DCHECK_GT(num_bytes, 0u);
|
| + CHECK_EQ(WriteDataRaw(producer_handle_.get(), encrypted->data(), &num_bytes,
|
| + MOJO_READ_DATA_FLAG_ALL_OR_NONE),
|
| + MOJO_RESULT_OK);
|
| + CHECK_EQ(num_bytes, static_cast<uint32_t>(encrypted->data_size()));
|
| + return buffer;
|
| +}
|
| +
|
| +scoped_refptr<DecoderBuffer> MojoDecryptor::ReadDecoderBuffer(
|
| + interfaces::DecoderBufferPtr buffer) {
|
| + scoped_refptr<DecoderBuffer> media_buffer(
|
| + buffer.To<scoped_refptr<DecoderBuffer>>());
|
| + if (media_buffer->end_of_stream())
|
| + return media_buffer;
|
| +
|
| + // Read the inner data for the DecoderBuffer from our DataPipe.
|
| + uint32_t num_bytes = media_buffer->data_size();
|
| + DCHECK_GT(num_bytes, 0u);
|
| + CHECK_EQ(ReadDataRaw(consumer_handle_.get(), media_buffer->writable_data(),
|
| + &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE),
|
| + MOJO_RESULT_OK);
|
| + CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size()));
|
| + return media_buffer;
|
| }
|
|
|
| } // namespace media
|
|
|