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_adapter.h" | 5 #include "media/mojo/services/mojo_demuxer_stream_adapter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "media/base/decoder_buffer.h" | 9 #include "media/base/decoder_buffer.h" |
| 10 #include "media/mojo/services/media_type_converters.h" | 10 #include "media/mojo/services/media_type_converters.h" |
| 11 | 11 |
| 12 namespace media { | 12 namespace media { |
| 13 | 13 |
| 14 MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter( | 14 MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter( |
| 15 mojo::DemuxerStreamPtr demuxer_stream, | 15 mojo::DemuxerStreamPtr demuxer_stream, |
| 16 const base::Closure& stream_ready_cb) | 16 const base::Closure& stream_ready_cb, |
| 17 DemuxerStream::Type type) | |
|
xhwang
2014/10/29 00:22:13
Can we drop this |type| param and populate |type_|
DaleCurtis
2014/10/30 23:16:56
Done.
| |
| 17 : demuxer_stream_(demuxer_stream.Pass()), | 18 : demuxer_stream_(demuxer_stream.Pass()), |
| 18 stream_ready_cb_(stream_ready_cb), | 19 stream_ready_cb_(stream_ready_cb), |
| 20 type_(type), | |
| 19 weak_factory_(this) { | 21 weak_factory_(this) { |
| 20 DVLOG(1) << __FUNCTION__; | 22 DVLOG(1) << __FUNCTION__; |
| 21 demuxer_stream_.set_client(this); | 23 demuxer_stream_.set_client(this); |
| 22 } | 24 } |
| 23 | 25 |
| 24 MojoDemuxerStreamAdapter::~MojoDemuxerStreamAdapter() { | 26 MojoDemuxerStreamAdapter::~MojoDemuxerStreamAdapter() { |
| 25 DVLOG(1) << __FUNCTION__; | 27 DVLOG(1) << __FUNCTION__; |
| 26 } | 28 } |
| 27 | 29 |
| 28 void MojoDemuxerStreamAdapter::Read(const DemuxerStream::ReadCB& read_cb) { | 30 void MojoDemuxerStreamAdapter::Read(const DemuxerStream::ReadCB& read_cb) { |
| 29 DVLOG(3) << __FUNCTION__; | 31 DVLOG(3) << __FUNCTION__; |
| 30 // We shouldn't be holding on to a previous callback if a new Read() came in. | 32 // We shouldn't be holding on to a previous callback if a new Read() came in. |
| 31 DCHECK(read_cb_.is_null()); | 33 DCHECK(read_cb_.is_null()); |
| 32 read_cb_ = read_cb; | 34 read_cb_ = read_cb; |
| 33 demuxer_stream_->Read(base::Bind(&MojoDemuxerStreamAdapter::OnBufferReady, | 35 demuxer_stream_->Read(base::Bind(&MojoDemuxerStreamAdapter::OnBufferReady, |
| 34 weak_factory_.GetWeakPtr())); | 36 weak_factory_.GetWeakPtr())); |
| 35 } | 37 } |
| 36 | 38 |
| 37 AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() { | 39 AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() { |
| 38 DCHECK(!config_queue_.empty()); | 40 DCHECK_EQ(type_, DemuxerStream::AUDIO); |
| 39 return config_queue_.front(); | 41 DCHECK(!audio_config_queue_.empty()); |
| 42 return audio_config_queue_.front(); | |
| 40 } | 43 } |
| 41 | 44 |
| 42 VideoDecoderConfig MojoDemuxerStreamAdapter::video_decoder_config() { | 45 VideoDecoderConfig MojoDemuxerStreamAdapter::video_decoder_config() { |
| 43 NOTREACHED(); | 46 DCHECK_EQ(type_, DemuxerStream::VIDEO); |
| 44 return VideoDecoderConfig(); | 47 DCHECK(!video_config_queue_.empty()); |
| 48 return video_config_queue_.front(); | |
| 45 } | 49 } |
| 46 | 50 |
| 47 media::DemuxerStream::Type MojoDemuxerStreamAdapter::type() { | 51 DemuxerStream::Type MojoDemuxerStreamAdapter::type() { |
| 48 return media::DemuxerStream::AUDIO; | 52 return type_; |
| 49 } | 53 } |
| 50 | 54 |
| 51 void MojoDemuxerStreamAdapter::EnableBitstreamConverter() { | 55 void MojoDemuxerStreamAdapter::EnableBitstreamConverter() { |
| 52 NOTREACHED(); | 56 NOTIMPLEMENTED(); |
| 53 } | 57 } |
| 54 | 58 |
| 55 bool MojoDemuxerStreamAdapter::SupportsConfigChanges() { | 59 bool MojoDemuxerStreamAdapter::SupportsConfigChanges() { |
| 56 return true; | 60 return true; |
| 57 } | 61 } |
| 58 | 62 |
| 59 VideoRotation MojoDemuxerStreamAdapter::video_rotation() { | 63 VideoRotation MojoDemuxerStreamAdapter::video_rotation() { |
| 60 NOTIMPLEMENTED(); | 64 NOTIMPLEMENTED(); |
| 61 return VIDEO_ROTATION_0; | 65 return VIDEO_ROTATION_0; |
| 62 } | 66 } |
| 63 | 67 |
| 64 void MojoDemuxerStreamAdapter::OnStreamReady( | 68 void MojoDemuxerStreamAdapter::OnStreamReady( |
| 65 mojo::ScopedDataPipeConsumerHandle pipe) { | 69 mojo::ScopedDataPipeConsumerHandle pipe) { |
| 66 DVLOG(1) << __FUNCTION__; | 70 DVLOG(1) << __FUNCTION__; |
| 67 // TODO(tim): We don't support pipe streaming yet. | 71 // TODO(tim): We don't support pipe streaming yet. |
| 68 DCHECK(!pipe.is_valid()); | 72 DCHECK(!pipe.is_valid()); |
| 69 DCHECK(!config_queue_.empty()); | 73 if (type_ == DemuxerStream::AUDIO) |
| 74 DCHECK(!audio_config_queue_.empty()); | |
| 75 if (type_ == DemuxerStream::VIDEO) | |
| 76 DCHECK(!video_config_queue_.empty()); | |
|
xhwang
2014/10/29 00:22:13
Some clean up idea for the future. We have both au
DaleCurtis
2014/10/30 23:16:56
Maybe, that's the opposite of what you're suggesti
xhwang
2014/10/31 03:25:57
Yeah, I just felt that'd be something nice. But ho
| |
| 70 stream_ready_cb_.Run(); | 77 stream_ready_cb_.Run(); |
| 71 } | 78 } |
| 72 | 79 |
| 73 void MojoDemuxerStreamAdapter::OnAudioDecoderConfigChanged( | 80 void MojoDemuxerStreamAdapter::OnAudioDecoderConfigChanged( |
| 74 mojo::AudioDecoderConfigPtr config) { | 81 mojo::AudioDecoderConfigPtr config) { |
| 75 config_queue_.push(config.To<media::AudioDecoderConfig>()); | 82 audio_config_queue_.push(config.To<AudioDecoderConfig>()); |
| 76 | 83 |
| 77 if (!read_cb_.is_null()) { | 84 if (!read_cb_.is_null()) { |
| 78 read_cb_.Run(media::DemuxerStream::Status::kConfigChanged, NULL); | 85 read_cb_.Run(DemuxerStream::Status::kConfigChanged, NULL); |
| 79 read_cb_.Reset(); | 86 read_cb_.Reset(); |
| 80 } | 87 } |
| 81 } | 88 } |
| 89 | |
| 90 void MojoDemuxerStreamAdapter::OnVideoDecoderConfigChanged( | |
| 91 mojo::VideoDecoderConfigPtr config) { | |
| 92 video_config_queue_.push(config.To<VideoDecoderConfig>()); | |
| 93 | |
| 94 if (!read_cb_.is_null()) { | |
| 95 read_cb_.Run(DemuxerStream::Status::kConfigChanged, NULL); | |
| 96 read_cb_.Reset(); | |
| 97 } | |
| 98 } | |
| 82 | 99 |
| 83 void MojoDemuxerStreamAdapter::OnBufferReady( | 100 void MojoDemuxerStreamAdapter::OnBufferReady( |
| 84 mojo::DemuxerStream::Status status, | 101 mojo::DemuxerStream::Status status, |
| 85 mojo::MediaDecoderBufferPtr buffer) { | 102 mojo::MediaDecoderBufferPtr buffer) { |
| 86 DVLOG(3) << __FUNCTION__; | 103 DVLOG(3) << __FUNCTION__; |
| 87 DCHECK(!read_cb_.is_null()); | 104 DCHECK(!read_cb_.is_null()); |
| 88 DCHECK(!config_queue_.empty()); | 105 if (type_ == DemuxerStream::AUDIO) |
| 106 DCHECK(!audio_config_queue_.empty()); | |
| 107 if (type_ == DemuxerStream::VIDEO) | |
| 108 DCHECK(!video_config_queue_.empty()); | |
| 89 | 109 |
| 90 media::DemuxerStream::Status media_status( | 110 DemuxerStream::Status media_status( |
| 91 static_cast<media::DemuxerStream::Status>(status)); | 111 static_cast<DemuxerStream::Status>(status)); |
| 92 scoped_refptr<media::DecoderBuffer> media_buffer( | 112 scoped_refptr<DecoderBuffer> media_buffer( |
| 93 buffer.To<scoped_refptr<media::DecoderBuffer> >()); | 113 buffer.To<scoped_refptr<DecoderBuffer> >()); |
| 94 | 114 |
| 95 if (status == mojo::DemuxerStream::STATUS_CONFIG_CHANGED) { | 115 if (status == mojo::DemuxerStream::STATUS_CONFIG_CHANGED) { |
| 96 DCHECK(!media_buffer.get()); | 116 DCHECK(!media_buffer.get()); |
| 97 config_queue_.pop(); | |
| 98 | 117 |
| 99 // If the |config_queue_| is empty we need to wait for | 118 if (type_ == DemuxerStream::AUDIO) { |
| 100 // OnAudioDecoderConfigChanged before invoking |read_cb|. | 119 audio_config_queue_.pop(); |
| 101 if (config_queue_.empty()) | 120 |
| 102 return; | 121 // If the |config_queue_| is empty we need to wait for |
| 122 // OnAudioDecoderConfigChanged before invoking |read_cb|. | |
| 123 if (audio_config_queue_.empty()) | |
| 124 return; | |
| 125 } | |
| 126 if (type_ == DemuxerStream::VIDEO) { | |
| 127 video_config_queue_.pop(); | |
| 128 | |
| 129 // If the |config_queue_| is empty we need to wait for | |
| 130 // OnAudioDecoderConfigChanged before invoking |read_cb|. | |
| 131 if (video_config_queue_.empty()) | |
| 132 return; | |
| 133 } | |
| 103 } | 134 } |
| 104 read_cb_.Run(media_status, media_buffer); | 135 read_cb_.Run(media_status, media_buffer); |
| 105 read_cb_.Reset(); | 136 read_cb_.Reset(); |
| 106 } | 137 } |
| 107 | 138 |
| 108 } // namespace media | 139 } // namespace media |
| OLD | NEW |