Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/mojo/services/mojo_demuxer_stream_impl.h" | 5 #include "media/mojo/services/mojo_demuxer_stream_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "media/base/audio_decoder_config.h" | 9 #include "media/base/audio_decoder_config.h" |
| 10 #include "media/base/decoder_buffer.h" | |
| 10 #include "media/base/video_decoder_config.h" | 11 #include "media/base/video_decoder_config.h" |
| 11 #include "media/mojo/interfaces/demuxer_stream.mojom.h" | 12 #include "media/mojo/interfaces/demuxer_stream.mojom.h" |
| 12 #include "media/mojo/services/media_type_converters.h" | 13 #include "media/mojo/services/media_type_converters.h" |
| 13 #include "mojo/public/cpp/bindings/interface_impl.h" | 14 #include "mojo/public/cpp/bindings/interface_impl.h" |
| 14 #include "mojo/public/cpp/system/data_pipe.h" | 15 #include "mojo/public/cpp/system/data_pipe.h" |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 | 18 |
| 18 MojoDemuxerStreamImpl::MojoDemuxerStreamImpl(media::DemuxerStream* stream) | 19 MojoDemuxerStreamImpl::MojoDemuxerStreamImpl(media::DemuxerStream* stream) |
| 19 : stream_(stream), weak_factory_(this) { | 20 : stream_(stream), weak_factory_(this) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 38 // Status obtained via Run() below. | 39 // Status obtained via Run() below. |
| 39 if (stream_->type() == media::DemuxerStream::AUDIO) { | 40 if (stream_->type() == media::DemuxerStream::AUDIO) { |
| 40 client()->OnAudioDecoderConfigChanged( | 41 client()->OnAudioDecoderConfigChanged( |
| 41 mojo::AudioDecoderConfig::From(stream_->audio_decoder_config())); | 42 mojo::AudioDecoderConfig::From(stream_->audio_decoder_config())); |
| 42 } else if (stream_->type() == media::DemuxerStream::VIDEO) { | 43 } else if (stream_->type() == media::DemuxerStream::VIDEO) { |
| 43 client()->OnVideoDecoderConfigChanged( | 44 client()->OnVideoDecoderConfigChanged( |
| 44 mojo::VideoDecoderConfig::From(stream_->video_decoder_config())); | 45 mojo::VideoDecoderConfig::From(stream_->video_decoder_config())); |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 | 48 |
| 48 // TODO(tim): Once using DataPipe, fill via the producer handle and then | 49 // Serialize the data section of the DecoderBuffer into our pipe. |
| 49 // read more to keep the pipe full. | 50 uint32_t num_bytes = buffer->data_size(); |
| 51 CHECK_EQ(WriteDataRaw(stream_pipe_.get(), buffer->data(), &num_bytes, | |
| 52 MOJO_READ_DATA_FLAG_ALL_OR_NONE), | |
| 53 MOJO_RESULT_OK); | |
| 54 CHECK_EQ(num_bytes, static_cast<uint32_t>(buffer->data_size())); | |
| 55 | |
| 56 // TODO(dalecurtis): Once we can write framed data to the DataPipe, fill via | |
| 57 // the producer handle and then read more to keep the pipe full. Waiting for | |
| 58 // space can be accomplished using an AsyncWaiter. | |
| 50 callback.Run(static_cast<mojo::DemuxerStream::Status>(status), | 59 callback.Run(static_cast<mojo::DemuxerStream::Status>(status), |
| 51 mojo::MediaDecoderBuffer::From(buffer)); | 60 mojo::MediaDecoderBuffer::From(buffer)); |
| 52 } | 61 } |
| 53 | 62 |
| 54 void MojoDemuxerStreamImpl::DidConnect() { | 63 void MojoDemuxerStreamImpl::DidConnect() { |
| 55 // This is called when our DemuxerStreamClient has connected itself and is | 64 // This is called when our DemuxerStreamClient has connected itself and is |
| 56 // ready to receive messages. Send an initial config and notify it that | 65 // ready to receive messages. Send an initial config and notify it that |
| 57 // we are now ready for business. | 66 // we are now ready for business. |
| 58 if (stream_->type() == media::DemuxerStream::AUDIO) { | 67 if (stream_->type() == media::DemuxerStream::AUDIO) { |
| 59 client()->OnAudioDecoderConfigChanged( | 68 client()->OnAudioDecoderConfigChanged( |
| 60 mojo::AudioDecoderConfig::From(stream_->audio_decoder_config())); | 69 mojo::AudioDecoderConfig::From(stream_->audio_decoder_config())); |
| 61 } else if (stream_->type() == media::DemuxerStream::VIDEO) { | 70 } else if (stream_->type() == media::DemuxerStream::VIDEO) { |
| 62 client()->OnVideoDecoderConfigChanged( | 71 client()->OnVideoDecoderConfigChanged( |
| 63 mojo::VideoDecoderConfig::From(stream_->video_decoder_config())); | 72 mojo::VideoDecoderConfig::From(stream_->video_decoder_config())); |
| 64 } | 73 } |
| 65 | 74 |
| 66 // TODO(tim): Create a DataPipe, hold the producer handle, and pass the | 75 MojoCreateDataPipeOptions options; |
| 67 // consumer handle here. | 76 options.struct_size = sizeof(MojoCreateDataPipeOptions); |
| 68 client()->OnStreamReady(mojo::ScopedDataPipeConsumerHandle()); | 77 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
| 78 options.element_num_bytes = 1; | |
| 79 | |
| 80 // Allocate DataPipe sizes based on content type to reduce overhead. If this | |
| 81 // is still too burdensome we can adjust for sample rate or resolution. | |
| 82 if (stream_->type() == media::DemuxerStream::AUDIO) { | |
| 83 // Audio doesn't require a lot of room, so use a smaller pipe than video. | |
| 84 options.capacity_num_bytes = 512 * 1024; | |
| 85 } else { | |
| 86 // Video can get quite large; at 4K, VP9 delivers packets which are ~1MB in | |
| 87 // size; so allow for 50% headroom. | |
| 88 options.capacity_num_bytes = 1.5 * (1024 * 1024); | |
|
xhwang
2014/12/06 00:03:44
nit: we have the config; we might be able to do be
DaleCurtis
2014/12/06 00:42:59
I can try and figure out some metric based on reso
xhwang
2014/12/06 01:16:54
Low priority for now. But we may need to have some
| |
| 89 } | |
| 90 | |
|
xhwang
2014/12/06 00:03:44
nit: How about Demuxer::TEXT?
DaleCurtis
2014/12/06 00:42:59
Flipped so only video gets the large pipe.
| |
| 91 mojo::DataPipe data_pipe(options); | |
| 92 stream_pipe_ = data_pipe.producer_handle.Pass(); | |
| 93 client()->OnStreamReady(data_pipe.consumer_handle.Pass()); | |
| 69 } | 94 } |
| 70 | 95 |
| 71 } // namespace media | 96 } // namespace media |
| OLD | NEW |