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/video_decoder_config.h" | |
| 10 #include "media/mojo/interfaces/demuxer_stream.mojom.h" | 11 #include "media/mojo/interfaces/demuxer_stream.mojom.h" |
| 11 #include "media/mojo/services/media_type_converters.h" | 12 #include "media/mojo/services/media_type_converters.h" |
| 12 #include "mojo/public/cpp/bindings/interface_impl.h" | 13 #include "mojo/public/cpp/bindings/interface_impl.h" |
| 13 #include "mojo/public/cpp/system/data_pipe.h" | 14 #include "mojo/public/cpp/system/data_pipe.h" |
| 14 | 15 |
| 15 namespace media { | 16 namespace media { |
| 16 | 17 |
| 17 MojoDemuxerStreamImpl::MojoDemuxerStreamImpl(media::DemuxerStream* stream) | 18 MojoDemuxerStreamImpl::MojoDemuxerStreamImpl(media::DemuxerStream* stream) |
| 18 : stream_(stream), weak_factory_(this) { | 19 : stream_(stream), weak_factory_(this) { |
| 19 } | 20 } |
| 20 | 21 |
| 21 MojoDemuxerStreamImpl::~MojoDemuxerStreamImpl() { | 22 MojoDemuxerStreamImpl::~MojoDemuxerStreamImpl() { |
| 22 } | 23 } |
| 23 | 24 |
| 24 void MojoDemuxerStreamImpl::Read(const mojo::Callback< | 25 void MojoDemuxerStreamImpl::Read(const mojo::Callback< |
| 25 void(mojo::DemuxerStream::Status, mojo::MediaDecoderBufferPtr)>& callback) { | 26 void(mojo::DemuxerStream::Status, mojo::MediaDecoderBufferPtr)>& callback) { |
| 26 stream_->Read(base::Bind(&MojoDemuxerStreamImpl::OnBufferReady, | 27 stream_->Read(base::Bind(&MojoDemuxerStreamImpl::OnBufferReady, |
| 27 weak_factory_.GetWeakPtr(), | 28 weak_factory_.GetWeakPtr(), |
| 28 callback)); | 29 callback)); |
| 29 } | 30 } |
| 30 | 31 |
| 31 void MojoDemuxerStreamImpl::OnBufferReady( | 32 void MojoDemuxerStreamImpl::OnBufferReady( |
| 32 const BufferReadyCB& callback, | 33 const BufferReadyCB& callback, |
| 33 media::DemuxerStream::Status status, | 34 media::DemuxerStream::Status status, |
| 34 const scoped_refptr<media::DecoderBuffer>& buffer) { | 35 const scoped_refptr<media::DecoderBuffer>& buffer) { |
| 35 if (status == media::DemuxerStream::kConfigChanged) { | 36 if (status == media::DemuxerStream::kConfigChanged) { |
| 36 // Send the config change so our client can read it once it parses the | 37 // Send the config change so our client can read it once it parses the |
| 37 // Status obtained via Run() below. | 38 // Status obtained via Run() below. |
| 38 client()->OnAudioDecoderConfigChanged( | 39 if (stream_->type() == media::DemuxerStream::AUDIO) { |
| 39 mojo::AudioDecoderConfig::From(stream_->audio_decoder_config())); | 40 client()->OnAudioDecoderConfigChanged( |
| 41 mojo::AudioDecoderConfig::From(stream_->audio_decoder_config())); | |
| 42 } else if (stream_->type() == media::DemuxerStream::VIDEO) { | |
| 43 client()->OnVideoDecoderConfigChanged( | |
| 44 mojo::VideoDecoderConfig::From(stream_->video_decoder_config())); | |
|
xhwang
2014/10/29 00:22:13
ditto about templatize MojoDemuxerStreamImpl.
| |
| 45 } | |
| 40 } | 46 } |
| 41 | 47 |
| 42 // TODO(tim): Once using DataPipe, fill via the producer handle and then | 48 // TODO(tim): Once using DataPipe, fill via the producer handle and then |
| 43 // read more to keep the pipe full. | 49 // read more to keep the pipe full. |
| 44 callback.Run(static_cast<mojo::DemuxerStream::Status>(status), | 50 callback.Run(static_cast<mojo::DemuxerStream::Status>(status), |
| 45 mojo::MediaDecoderBuffer::From(buffer)); | 51 mojo::MediaDecoderBuffer::From(buffer)); |
| 46 } | 52 } |
| 47 | 53 |
| 48 void MojoDemuxerStreamImpl::OnConnectionEstablished() { | 54 void MojoDemuxerStreamImpl::OnConnectionEstablished() { |
| 49 // This is called when our DemuxerStreamClient has connected itself and is | 55 // This is called when our DemuxerStreamClient has connected itself and is |
| 50 // ready to receive messages. Send an initial config and notify it that | 56 // ready to receive messages. Send an initial config and notify it that |
| 51 // we are now ready for business. | 57 // we are now ready for business. |
| 52 client()->OnAudioDecoderConfigChanged( | 58 if (stream_->type() == media::DemuxerStream::AUDIO) { |
| 53 mojo::AudioDecoderConfig::From(stream_->audio_decoder_config())); | 59 client()->OnAudioDecoderConfigChanged( |
| 60 mojo::AudioDecoderConfig::From(stream_->audio_decoder_config())); | |
| 61 } else if (stream_->type() == media::DemuxerStream::VIDEO) { | |
| 62 client()->OnVideoDecoderConfigChanged( | |
| 63 mojo::VideoDecoderConfig::From(stream_->video_decoder_config())); | |
| 64 } | |
| 54 | 65 |
| 55 // TODO(tim): Create a DataPipe, hold the producer handle, and pass the | 66 // TODO(tim): Create a DataPipe, hold the producer handle, and pass the |
| 56 // consumer handle here. | 67 // consumer handle here. |
| 57 client()->OnStreamReady(mojo::ScopedDataPipeConsumerHandle()); | 68 client()->OnStreamReady(mojo::ScopedDataPipeConsumerHandle()); |
| 58 } | 69 } |
| 59 | 70 |
| 60 } // namespace media | 71 } // namespace media |
| OLD | NEW |