Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1023)

Unified Diff: media/mojo/services/mojo_decryptor_service.cc

Issue 1538063003: Use data pipe to pass DecoderBuffer contents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/mojo/services/mojo_decryptor_service.cc
diff --git a/media/mojo/services/mojo_decryptor_service.cc b/media/mojo/services/mojo_decryptor_service.cc
index 774684a044ed4d38c72619c4f9a6d4ddc2a133a2..53bff0f19c83e9f2b33019c786956e1169b562a3 100644
--- a/media/mojo/services/mojo_decryptor_service.cc
+++ b/media/mojo/services/mojo_decryptor_service.cc
@@ -11,6 +11,7 @@
#include "media/base/decryptor.h"
#include "media/base/media_keys.h"
#include "media/base/video_decoder_config.h"
+#include "media/base/video_frame.h"
#include "media/mojo/interfaces/demuxer_stream.mojom.h"
#include "media/mojo/services/media_type_converters.h"
@@ -29,17 +30,29 @@ MojoDecryptorService::MojoDecryptorService(
MojoDecryptorService::~MojoDecryptorService() {}
+void MojoDecryptorService::Initialize(
+ mojo::ScopedDataPipeConsumerHandle receive_pipe,
+ mojo::ScopedDataPipeProducerHandle transmit_pipe) {
+ write_pipe_ = transmit_pipe.Pass();
+ read_pipe_ = receive_pipe.Pass();
+}
+
void MojoDecryptorService::Decrypt(interfaces::DemuxerStream::Type stream_type,
interfaces::DecoderBufferPtr encrypted,
const DecryptCallback& callback) {
+ DVLOG(1) << __FUNCTION__;
+
+ scoped_refptr<DecoderBuffer> buffer(
+ encrypted.To<scoped_refptr<DecoderBuffer>>());
+ ReadDataFromDataPipe(buffer);
decryptor_->Decrypt(
- static_cast<media::Decryptor::StreamType>(stream_type),
- encrypted.To<scoped_refptr<DecoderBuffer>>(),
+ static_cast<media::Decryptor::StreamType>(stream_type), buffer,
base::Bind(&MojoDecryptorService::OnDecryptDone, weak_this_, callback));
}
void MojoDecryptorService::CancelDecrypt(
interfaces::DemuxerStream::Type stream_type) {
+ DVLOG(1) << __FUNCTION__;
decryptor_->CancelDecrypt(
static_cast<media::Decryptor::StreamType>(stream_type));
}
@@ -47,6 +60,7 @@ void MojoDecryptorService::CancelDecrypt(
void MojoDecryptorService::InitializeAudioDecoder(
interfaces::AudioDecoderConfigPtr config,
const InitializeAudioDecoderCallback& callback) {
+ DVLOG(1) << __FUNCTION__;
decryptor_->InitializeAudioDecoder(
config.To<AudioDecoderConfig>(),
base::Bind(&MojoDecryptorService::OnAudioDecoderInitialized, weak_this_,
@@ -56,6 +70,7 @@ void MojoDecryptorService::InitializeAudioDecoder(
void MojoDecryptorService::InitializeVideoDecoder(
interfaces::VideoDecoderConfigPtr config,
const InitializeVideoDecoderCallback& callback) {
+ DVLOG(1) << __FUNCTION__;
decryptor_->InitializeVideoDecoder(
config.To<VideoDecoderConfig>(),
base::Bind(&MojoDecryptorService::OnVideoDecoderInitialized, weak_this_,
@@ -65,27 +80,37 @@ void MojoDecryptorService::InitializeVideoDecoder(
void MojoDecryptorService::DecryptAndDecodeAudio(
interfaces::DecoderBufferPtr encrypted,
const DecryptAndDecodeAudioCallback& callback) {
+ DVLOG(1) << __FUNCTION__;
xhwang 2015/12/19 18:16:31 ditto about log level.
jrummell 2015/12/21 23:20:55 Done.
+ scoped_refptr<DecoderBuffer> buffer(
+ encrypted.To<scoped_refptr<DecoderBuffer>>());
+ ReadDataFromDataPipe(buffer);
decryptor_->DecryptAndDecodeAudio(
- encrypted.To<scoped_refptr<DecoderBuffer>>(),
+ buffer,
base::Bind(&MojoDecryptorService::OnAudioDecoded, weak_this_, callback));
}
void MojoDecryptorService::DecryptAndDecodeVideo(
interfaces::DecoderBufferPtr encrypted,
const DecryptAndDecodeVideoCallback& callback) {
+ DVLOG(1) << __FUNCTION__;
+ scoped_refptr<DecoderBuffer> buffer(
+ encrypted.To<scoped_refptr<DecoderBuffer>>());
+ ReadDataFromDataPipe(buffer);
decryptor_->DecryptAndDecodeVideo(
- encrypted.To<scoped_refptr<DecoderBuffer>>(),
+ buffer,
base::Bind(&MojoDecryptorService::OnVideoDecoded, weak_this_, callback));
}
void MojoDecryptorService::ResetDecoder(
interfaces::DemuxerStream::Type stream_type) {
+ DVLOG(1) << __FUNCTION__;
decryptor_->ResetDecoder(
static_cast<media::Decryptor::StreamType>(stream_type));
}
void MojoDecryptorService::DeinitializeDecoder(
interfaces::DemuxerStream::Type stream_type) {
+ DVLOG(1) << __FUNCTION__;
decryptor_->DeinitializeDecoder(
static_cast<media::Decryptor::StreamType>(stream_type));
}
@@ -95,6 +120,14 @@ void MojoDecryptorService::OnDecryptDone(
media::Decryptor::Status status,
const scoped_refptr<DecoderBuffer>& buffer) {
DVLOG(1) << __FUNCTION__ << "(" << status << ")";
+ if (!buffer) {
+ DCHECK_NE(status, media::Decryptor::kSuccess);
+ callback.Run(static_cast<Decryptor::Status>(status), nullptr);
+ return;
+ }
+
+ DVLOG(3) << " buffer: " << buffer->AsHumanReadableString();
+ WriteDataIntoDataPipe(buffer);
callback.Run(static_cast<Decryptor::Status>(status),
interfaces::DecoderBuffer::From(buffer));
}
@@ -131,9 +164,41 @@ void MojoDecryptorService::OnVideoDecoded(
media::Decryptor::Status status,
const scoped_refptr<VideoFrame>& frame) {
DVLOG(1) << __FUNCTION__ << "(" << status << ")";
+ if (!frame) {
+ DCHECK_NE(status, media::Decryptor::kSuccess);
+ callback.Run(static_cast<Decryptor::Status>(status), nullptr);
+ return;
+ }
+ DVLOG(3) << " video_frame: " << frame->AsHumanReadableString();
callback.Run(static_cast<Decryptor::Status>(status),
interfaces::VideoFrame::From(frame).Pass());
}
+void MojoDecryptorService::WriteDataIntoDataPipe(
+ const scoped_refptr<DecoderBuffer>& buffer) {
+ if (!buffer->end_of_stream()) {
xhwang 2015/12/19 18:16:31 ditto
jrummell 2015/12/21 23:20:55 Done.
+ // Serialize the data section of the DecoderBuffer into our pipe.
+ uint32_t num_bytes = buffer->data_size();
+ DCHECK_GT(num_bytes, 0u);
+ CHECK_EQ(WriteDataRaw(write_pipe_.get(), buffer->data(), &num_bytes,
+ MOJO_READ_DATA_FLAG_ALL_OR_NONE),
+ MOJO_RESULT_OK);
+ CHECK_EQ(num_bytes, static_cast<uint32_t>(buffer->data_size()));
+ }
+}
+
+void MojoDecryptorService::ReadDataFromDataPipe(
+ const scoped_refptr<DecoderBuffer>& buffer) {
+ if (!buffer->end_of_stream()) {
+ // Read the inner data for the DecoderBuffer from our DataPipe.
+ uint32_t num_bytes = buffer->data_size();
+ DCHECK_GT(num_bytes, 0u);
+ CHECK_EQ(ReadDataRaw(read_pipe_.get(), buffer->writable_data(), &num_bytes,
+ MOJO_READ_DATA_FLAG_ALL_OR_NONE),
+ MOJO_RESULT_OK);
+ CHECK_EQ(num_bytes, static_cast<uint32_t>(buffer->data_size()));
+ }
+}
+
} // namespace media
« media/mojo/services/mojo_decryptor.cc ('K') | « media/mojo/services/mojo_decryptor_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698