| Index: media/mojo/services/mojo_demuxer_stream_impl.cc
|
| diff --git a/media/mojo/services/mojo_demuxer_stream_impl.cc b/media/mojo/services/mojo_demuxer_stream_impl.cc
|
| index 82cad845008f40c83db8ba87a9c251d9a1b76643..3f5d992cd79fe8473ada17208e646fff5cecd2d6 100644
|
| --- a/media/mojo/services/mojo_demuxer_stream_impl.cc
|
| +++ b/media/mojo/services/mojo_demuxer_stream_impl.cc
|
| @@ -23,39 +23,86 @@ MojoDemuxerStreamImpl::MojoDemuxerStreamImpl(media::DemuxerStream* stream)
|
| MojoDemuxerStreamImpl::~MojoDemuxerStreamImpl() {
|
| }
|
|
|
| -void MojoDemuxerStreamImpl::Read(const mojo::Callback<
|
| - void(mojo::DemuxerStream::Status, mojo::MediaDecoderBufferPtr)>& callback) {
|
| +// This is called when our DemuxerStreamClient has connected itself and is
|
| +// ready to receive messages. Send an initial config and notify it that
|
| +// we are now ready for business.
|
| +void MojoDemuxerStreamImpl::Initialize(const InitializeCallback& callback) {
|
| + DVLOG(2) << __FUNCTION__;
|
| + MojoCreateDataPipeOptions options;
|
| + options.struct_size = sizeof(MojoCreateDataPipeOptions);
|
| + options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
|
| + options.element_num_bytes = 1;
|
| +
|
| + // Allocate DataPipe sizes based on content type to reduce overhead. If this
|
| + // is still too burdensome we can adjust for sample rate or resolution.
|
| + if (stream_->type() == media::DemuxerStream::VIDEO) {
|
| + // Video can get quite large; at 4K, VP9 delivers packets which are ~1MB in
|
| + // size; so allow for 50% headroom.
|
| + options.capacity_num_bytes = 1.5 * (1024 * 1024);
|
| + } else {
|
| + // Other types don't require a lot of room, so use a smaller pipe.
|
| + options.capacity_num_bytes = 512 * 1024;
|
| + }
|
| +
|
| + mojo::DataPipe data_pipe(options);
|
| + stream_pipe_ = data_pipe.producer_handle.Pass();
|
| +
|
| + // Prepare the initial config.
|
| + mojo::AudioDecoderConfigPtr audio_config;
|
| + mojo::VideoDecoderConfigPtr video_config;
|
| + if (stream_->type() == media::DemuxerStream::AUDIO) {
|
| + audio_config =
|
| + mojo::AudioDecoderConfig::From(stream_->audio_decoder_config());
|
| + } else if (stream_->type() == media::DemuxerStream::VIDEO) {
|
| + video_config =
|
| + mojo::VideoDecoderConfig::From(stream_->video_decoder_config());
|
| + } else {
|
| + NOTREACHED() << "Unsupported stream type: " << stream_->type();
|
| + return;
|
| + }
|
| +
|
| + callback.Run(static_cast<mojo::DemuxerStream::Type>(stream_->type()),
|
| + data_pipe.consumer_handle.Pass(), audio_config.Pass(),
|
| + video_config.Pass());
|
| +}
|
| +
|
| +void MojoDemuxerStreamImpl::Read(const ReadCallback& callback) {
|
| stream_->Read(base::Bind(&MojoDemuxerStreamImpl::OnBufferReady,
|
| - weak_factory_.GetWeakPtr(),
|
| - callback));
|
| + weak_factory_.GetWeakPtr(), callback));
|
| }
|
|
|
| void MojoDemuxerStreamImpl::OnBufferReady(
|
| - const BufferReadyCB& callback,
|
| + const ReadCallback& callback,
|
| media::DemuxerStream::Status status,
|
| const scoped_refptr<media::DecoderBuffer>& buffer) {
|
| + mojo::AudioDecoderConfigPtr audio_config;
|
| + mojo::VideoDecoderConfigPtr video_config;
|
| +
|
| if (status == media::DemuxerStream::kConfigChanged) {
|
| + DVLOG(2) << __FUNCTION__ << ": ConfigChange!";
|
| // Send the config change so our client can read it once it parses the
|
| // Status obtained via Run() below.
|
| if (stream_->type() == media::DemuxerStream::AUDIO) {
|
| - observer_->OnAudioDecoderConfigChanged(
|
| - mojo::AudioDecoderConfig::From(stream_->audio_decoder_config()));
|
| + audio_config =
|
| + mojo::AudioDecoderConfig::From(stream_->audio_decoder_config());
|
| } else if (stream_->type() == media::DemuxerStream::VIDEO) {
|
| - observer_->OnVideoDecoderConfigChanged(
|
| - mojo::VideoDecoderConfig::From(stream_->video_decoder_config()));
|
| + video_config =
|
| + mojo::VideoDecoderConfig::From(stream_->video_decoder_config());
|
| } else {
|
| NOTREACHED() << "Unsupported config change encountered for type: "
|
| << stream_->type();
|
| }
|
|
|
| callback.Run(mojo::DemuxerStream::STATUS_CONFIG_CHANGED,
|
| - mojo::MediaDecoderBufferPtr());
|
| + mojo::MediaDecoderBufferPtr(), audio_config.Pass(),
|
| + video_config.Pass());
|
| return;
|
| }
|
|
|
| if (status == media::DemuxerStream::kAborted) {
|
| callback.Run(mojo::DemuxerStream::STATUS_ABORTED,
|
| - mojo::MediaDecoderBufferPtr());
|
| + mojo::MediaDecoderBufferPtr(), audio_config.Pass(),
|
| + video_config.Pass());
|
| return;
|
| }
|
|
|
| @@ -74,45 +121,8 @@ void MojoDemuxerStreamImpl::OnBufferReady(
|
| // the producer handle and then read more to keep the pipe full. Waiting for
|
| // space can be accomplished using an AsyncWaiter.
|
| callback.Run(static_cast<mojo::DemuxerStream::Status>(status),
|
| - mojo::MediaDecoderBuffer::From(buffer));
|
| -}
|
| -
|
| -void MojoDemuxerStreamImpl::Initialize(
|
| - mojo::DemuxerStreamObserverPtr observer,
|
| - const mojo::Callback<void(mojo::ScopedDataPipeConsumerHandle)>& callback) {
|
| - DCHECK(observer);
|
| - observer_ = observer.Pass();
|
| -
|
| - // This is called when our DemuxerStreamClient has connected itself and is
|
| - // ready to receive messages. Send an initial config and notify it that
|
| - // we are now ready for business.
|
| - if (stream_->type() == media::DemuxerStream::AUDIO) {
|
| - observer_->OnAudioDecoderConfigChanged(
|
| - mojo::AudioDecoderConfig::From(stream_->audio_decoder_config()));
|
| - } else if (stream_->type() == media::DemuxerStream::VIDEO) {
|
| - observer_->OnVideoDecoderConfigChanged(
|
| - mojo::VideoDecoderConfig::From(stream_->video_decoder_config()));
|
| - }
|
| -
|
| - MojoCreateDataPipeOptions options;
|
| - options.struct_size = sizeof(MojoCreateDataPipeOptions);
|
| - options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
|
| - options.element_num_bytes = 1;
|
| -
|
| - // Allocate DataPipe sizes based on content type to reduce overhead. If this
|
| - // is still too burdensome we can adjust for sample rate or resolution.
|
| - if (stream_->type() == media::DemuxerStream::VIDEO) {
|
| - // Video can get quite large; at 4K, VP9 delivers packets which are ~1MB in
|
| - // size; so allow for 50% headroom.
|
| - options.capacity_num_bytes = 1.5 * (1024 * 1024);
|
| - } else {
|
| - // Other types don't require a lot of room, so use a smaller pipe.
|
| - options.capacity_num_bytes = 512 * 1024;
|
| - }
|
| -
|
| - mojo::DataPipe data_pipe(options);
|
| - stream_pipe_ = data_pipe.producer_handle.Pass();
|
| - callback.Run(data_pipe.consumer_handle.Pass());
|
| + mojo::MediaDecoderBuffer::From(buffer), audio_config.Pass(),
|
| + video_config.Pass());
|
| }
|
|
|
| } // namespace media
|
|
|