| 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 #include "mojo/public/cpp/system/data_pipe.h" |
| 11 | 12 |
| 12 namespace media { | 13 namespace media { |
| 13 | 14 |
| 14 MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter( | 15 MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter( |
| 15 mojo::DemuxerStreamPtr demuxer_stream, | 16 mojo::DemuxerStreamPtr demuxer_stream, |
| 16 const base::Closure& stream_ready_cb) | 17 const base::Closure& stream_ready_cb) |
| 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), |
| 19 type_(DemuxerStream::UNKNOWN), | 20 type_(DemuxerStream::UNKNOWN), |
| 20 weak_factory_(this) { | 21 weak_factory_(this) { |
| 21 DVLOG(1) << __FUNCTION__; | 22 DVLOG(1) << __FUNCTION__; |
| 22 demuxer_stream_.set_client(this); | 23 demuxer_stream_.set_client(this); |
| 23 } | 24 } |
| 24 | 25 |
| 25 MojoDemuxerStreamAdapter::~MojoDemuxerStreamAdapter() { | 26 MojoDemuxerStreamAdapter::~MojoDemuxerStreamAdapter() { |
| 26 DVLOG(1) << __FUNCTION__; | 27 DVLOG(1) << __FUNCTION__; |
| 27 } | 28 } |
| 28 | 29 |
| 29 void MojoDemuxerStreamAdapter::Read(const DemuxerStream::ReadCB& read_cb) { | 30 void MojoDemuxerStreamAdapter::Read(const DemuxerStream::ReadCB& read_cb) { |
| 30 DVLOG(3) << __FUNCTION__; | 31 DVLOG(3) << __FUNCTION__; |
| 31 // 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. |
| 32 DCHECK(read_cb_.is_null()); | 33 DCHECK(read_cb_.is_null()); |
| 34 |
| 35 DCHECK(stream_pipe_.is_valid()); |
| 33 read_cb_ = read_cb; | 36 read_cb_ = read_cb; |
| 34 demuxer_stream_->Read(base::Bind(&MojoDemuxerStreamAdapter::OnBufferReady, | 37 demuxer_stream_->Read(base::Bind(&MojoDemuxerStreamAdapter::OnBufferReady, |
| 35 weak_factory_.GetWeakPtr())); | 38 weak_factory_.GetWeakPtr())); |
| 36 } | 39 } |
| 37 | 40 |
| 38 AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() { | 41 AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() { |
| 39 DCHECK_EQ(type_, DemuxerStream::AUDIO); | 42 DCHECK_EQ(type_, DemuxerStream::AUDIO); |
| 40 DCHECK(!audio_config_queue_.empty()); | 43 DCHECK(!audio_config_queue_.empty()); |
| 41 return audio_config_queue_.front(); | 44 return audio_config_queue_.front(); |
| 42 } | 45 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 61 | 64 |
| 62 VideoRotation MojoDemuxerStreamAdapter::video_rotation() { | 65 VideoRotation MojoDemuxerStreamAdapter::video_rotation() { |
| 63 NOTIMPLEMENTED(); | 66 NOTIMPLEMENTED(); |
| 64 return VIDEO_ROTATION_0; | 67 return VIDEO_ROTATION_0; |
| 65 } | 68 } |
| 66 | 69 |
| 67 // TODO(xhwang): Pass liveness here. | 70 // TODO(xhwang): Pass liveness here. |
| 68 void MojoDemuxerStreamAdapter::OnStreamReady( | 71 void MojoDemuxerStreamAdapter::OnStreamReady( |
| 69 mojo::ScopedDataPipeConsumerHandle pipe) { | 72 mojo::ScopedDataPipeConsumerHandle pipe) { |
| 70 DVLOG(1) << __FUNCTION__; | 73 DVLOG(1) << __FUNCTION__; |
| 71 // TODO(tim): We don't support pipe streaming yet. | 74 DCHECK(pipe.is_valid()); |
| 72 DCHECK(!pipe.is_valid()); | |
| 73 DCHECK_NE(type_, DemuxerStream::UNKNOWN); | 75 DCHECK_NE(type_, DemuxerStream::UNKNOWN); |
| 76 stream_pipe_ = pipe.Pass(); |
| 74 stream_ready_cb_.Run(); | 77 stream_ready_cb_.Run(); |
| 75 } | 78 } |
| 76 | 79 |
| 77 void MojoDemuxerStreamAdapter::OnAudioDecoderConfigChanged( | 80 void MojoDemuxerStreamAdapter::OnAudioDecoderConfigChanged( |
| 78 mojo::AudioDecoderConfigPtr config) { | 81 mojo::AudioDecoderConfigPtr config) { |
| 79 DCHECK(type_ == DemuxerStream::UNKNOWN || type_ == DemuxerStream::AUDIO) | 82 DCHECK(type_ == DemuxerStream::UNKNOWN || type_ == DemuxerStream::AUDIO) |
| 80 << type_; | 83 << type_; |
| 81 type_ = DemuxerStream::AUDIO; | 84 type_ = DemuxerStream::AUDIO; |
| 82 | 85 |
| 83 audio_config_queue_.push(config.To<AudioDecoderConfig>()); | 86 audio_config_queue_.push(config.To<AudioDecoderConfig>()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 101 read_cb_.Reset(); | 104 read_cb_.Reset(); |
| 102 } | 105 } |
| 103 } | 106 } |
| 104 | 107 |
| 105 void MojoDemuxerStreamAdapter::OnBufferReady( | 108 void MojoDemuxerStreamAdapter::OnBufferReady( |
| 106 mojo::DemuxerStream::Status status, | 109 mojo::DemuxerStream::Status status, |
| 107 mojo::MediaDecoderBufferPtr buffer) { | 110 mojo::MediaDecoderBufferPtr buffer) { |
| 108 DVLOG(3) << __FUNCTION__; | 111 DVLOG(3) << __FUNCTION__; |
| 109 DCHECK(!read_cb_.is_null()); | 112 DCHECK(!read_cb_.is_null()); |
| 110 DCHECK_NE(type_, DemuxerStream::UNKNOWN); | 113 DCHECK_NE(type_, DemuxerStream::UNKNOWN); |
| 114 DCHECK(stream_pipe_.is_valid()); |
| 111 | 115 |
| 112 DemuxerStream::Status media_status( | 116 DemuxerStream::Status media_status( |
| 113 static_cast<DemuxerStream::Status>(status)); | 117 static_cast<DemuxerStream::Status>(status)); |
| 114 scoped_refptr<DecoderBuffer> media_buffer( | 118 scoped_refptr<DecoderBuffer> media_buffer( |
| 115 buffer.To<scoped_refptr<DecoderBuffer>>()); | 119 buffer.To<scoped_refptr<DecoderBuffer>>()); |
| 116 | 120 |
| 117 if (status == mojo::DemuxerStream::STATUS_CONFIG_CHANGED) { | 121 if (status == mojo::DemuxerStream::STATUS_CONFIG_CHANGED) { |
| 118 DCHECK(!media_buffer.get()); | 122 DCHECK(!media_buffer.get()); |
| 119 | 123 |
| 120 // If the configuration queue is empty we need to wait for a config change | 124 // If the configuration queue is empty we need to wait for a config change |
| 121 // event before invoking |read_cb_|. | 125 // event before invoking |read_cb_|. |
| 122 | 126 |
| 123 if (type_ == DemuxerStream::AUDIO) { | 127 if (type_ == DemuxerStream::AUDIO) { |
| 124 audio_config_queue_.pop(); | 128 audio_config_queue_.pop(); |
| 125 if (audio_config_queue_.empty()) | 129 if (audio_config_queue_.empty()) |
| 126 return; | 130 return; |
| 127 } else if (type_ == DemuxerStream::VIDEO) { | 131 } else if (type_ == DemuxerStream::VIDEO) { |
| 128 video_config_queue_.pop(); | 132 video_config_queue_.pop(); |
| 129 if (video_config_queue_.empty()) | 133 if (video_config_queue_.empty()) |
| 130 return; | 134 return; |
| 131 } | 135 } |
| 136 } else if (status == mojo::DemuxerStream::STATUS_OK) { |
| 137 DCHECK_GT(media_buffer->data_size(), 0); |
| 138 |
| 139 // Read the inner data for the DecoderBuffer from our DataPipe. |
| 140 uint32_t num_bytes = media_buffer->data_size(); |
| 141 CHECK_EQ(ReadDataRaw(stream_pipe_.get(), media_buffer->writable_data(), |
| 142 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), |
| 143 MOJO_RESULT_OK); |
| 144 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); |
| 132 } | 145 } |
| 133 | 146 |
| 134 read_cb_.Run(media_status, media_buffer); | 147 read_cb_.Run(media_status, media_buffer); |
| 135 read_cb_.Reset(); | 148 read_cb_.Reset(); |
| 136 } | 149 } |
| 137 | 150 |
| 138 } // namespace media | 151 } // namespace media |
| OLD | NEW |