OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/mojo/services/mojo_demuxer_stream_adapter.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" |
| 9 #include "media/base/decoder_buffer.h" |
| 10 #include "media/mojo/services/media_type_converters.h" |
| 11 |
| 12 namespace media { |
| 13 |
| 14 MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter( |
| 15 mojo::DemuxerStreamPtr stream, |
| 16 const base::Closure& stream_ready) : demuxer_stream_(stream.Pass()), |
| 17 stream_ready_callback_(stream_ready), |
| 18 weak_factory_(this) { |
| 19 demuxer_stream_.set_client(this); |
| 20 } |
| 21 |
| 22 MojoDemuxerStreamAdapter::~MojoDemuxerStreamAdapter() { |
| 23 } |
| 24 |
| 25 void MojoDemuxerStreamAdapter::Read(const DemuxerStream::ReadCB& read_cb) { |
| 26 // We shouldn't be holding on to a previous callback if a new Read() came in. |
| 27 DCHECK(on_config_change_cb_.is_null()); |
| 28 demuxer_stream_->Read(base::Bind(&MojoDemuxerStreamAdapter::OnBufferReady, |
| 29 weak_factory_.GetWeakPtr(), |
| 30 read_cb)); |
| 31 } |
| 32 |
| 33 AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() { |
| 34 DCHECK(!config_queue_.empty()); |
| 35 return config_queue_.front(); |
| 36 } |
| 37 |
| 38 VideoDecoderConfig MojoDemuxerStreamAdapter::video_decoder_config() { |
| 39 DCHECK(false); // TODO(tim): Video unsupported. |
| 40 return VideoDecoderConfig(); |
| 41 } |
| 42 |
| 43 media::DemuxerStream::Type MojoDemuxerStreamAdapter::type() { |
| 44 return media::DemuxerStream::AUDIO; |
| 45 } |
| 46 |
| 47 void MojoDemuxerStreamAdapter::EnableBitstreamConverter() { |
| 48 NOTIMPLEMENTED(); |
| 49 } |
| 50 |
| 51 bool MojoDemuxerStreamAdapter::SupportsConfigChanges() { |
| 52 return true; |
| 53 } |
| 54 |
| 55 VideoRotation MojoDemuxerStreamAdapter::video_rotation() { |
| 56 NOTIMPLEMENTED(); |
| 57 return VIDEO_ROTATION_0; |
| 58 } |
| 59 |
| 60 void MojoDemuxerStreamAdapter::OnStreamReady( |
| 61 mojo::ScopedDataPipeConsumerHandle pipe) { |
| 62 // TODO(tim): We don't support pipe streaming yet. |
| 63 DCHECK(!pipe.is_valid()); |
| 64 DCHECK(!config_queue_.empty()); |
| 65 stream_ready_callback_.Run(); |
| 66 } |
| 67 |
| 68 void MojoDemuxerStreamAdapter::OnAudioDecoderConfigChanged( |
| 69 mojo::AudioDecoderConfigPtr config) { |
| 70 config_queue_.push(config.To<media::AudioDecoderConfig>()); |
| 71 |
| 72 if (!on_config_change_cb_.is_null()) |
| 73 base::ResetAndReturn(&on_config_change_cb_).Run(); |
| 74 } |
| 75 |
| 76 void MojoDemuxerStreamAdapter::OnBufferReady( |
| 77 const ReadCB& read_cb, |
| 78 mojo::DemuxerStream::Status status, |
| 79 mojo::MediaDecoderBufferPtr buffer) { |
| 80 DCHECK(on_config_change_cb_.is_null()); |
| 81 DCHECK(!config_queue_.empty()); |
| 82 |
| 83 media::DemuxerStream::Status media_status( |
| 84 static_cast<media::DemuxerStream::Status>(status)); |
| 85 scoped_refptr<media::DecoderBuffer> media_buffer( |
| 86 buffer.To<scoped_refptr<media::DecoderBuffer> >()); |
| 87 |
| 88 if (status == mojo::DemuxerStream::STATUS_CONFIG_CHANGED) { |
| 89 DCHECK_GE(config_queue_.size(), 1U); |
| 90 config_queue_.pop(); |
| 91 |
| 92 // If the |config_queue_| is empty we need to wait for |
| 93 // OnAudioDecoderConfigChanged before invoking |read_cb|. |
| 94 if (config_queue_.empty()) { |
| 95 on_config_change_cb_ = base::Bind(read_cb, media_status, media_buffer); |
| 96 return; |
| 97 } |
| 98 } |
| 99 read_cb.Run(media_status, media_buffer); |
| 100 } |
| 101 |
| 102 } // namespace media |
OLD | NEW |