| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/numerics/safe_conversions.h" | 12 #include "base/numerics/safe_conversions.h" |
| 13 #include "media/base/decoder_buffer.h" | 13 #include "media/base/decoder_buffer.h" |
| 14 #include "media/mojo/common/media_type_converters.h" | 14 #include "media/mojo/common/media_type_converters.h" |
| 15 #include "media/mojo/common/mojo_decoder_buffer_converter.h" | 15 #include "media/mojo/common/mojo_decoder_buffer_converter.h" |
| 16 #include "mojo/public/cpp/system/data_pipe.h" | 16 #include "mojo/public/cpp/system/data_pipe.h" |
| 17 | 17 |
| 18 namespace media { | 18 namespace media { |
| 19 | 19 |
| 20 MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter( | 20 MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter( |
| 21 mojom::DemuxerStreamPtr demuxer_stream, | 21 mojom::DemuxerStreamPtr demuxer_stream, |
| 22 const base::Closure& stream_ready_cb) | 22 const base::Closure& stream_ready_cb) |
| 23 : demuxer_stream_(std::move(demuxer_stream)), | 23 : demuxer_stream_(std::move(demuxer_stream)), |
| 24 stream_ready_cb_(stream_ready_cb), | 24 stream_ready_cb_(stream_ready_cb), |
| 25 type_(DemuxerStream::UNKNOWN), | 25 type_(UNKNOWN), |
| 26 weak_factory_(this) { | 26 weak_factory_(this) { |
| 27 DVLOG(1) << __FUNCTION__; | 27 DVLOG(1) << __FUNCTION__; |
| 28 demuxer_stream_->Initialize(base::Bind( | 28 demuxer_stream_->Initialize(base::Bind( |
| 29 &MojoDemuxerStreamAdapter::OnStreamReady, weak_factory_.GetWeakPtr())); | 29 &MojoDemuxerStreamAdapter::OnStreamReady, weak_factory_.GetWeakPtr())); |
| 30 } | 30 } |
| 31 | 31 |
| 32 MojoDemuxerStreamAdapter::~MojoDemuxerStreamAdapter() { | 32 MojoDemuxerStreamAdapter::~MojoDemuxerStreamAdapter() { |
| 33 DVLOG(1) << __FUNCTION__; | 33 DVLOG(1) << __FUNCTION__; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void MojoDemuxerStreamAdapter::Read(const DemuxerStream::ReadCB& read_cb) { | 36 void MojoDemuxerStreamAdapter::Read(const ReadCB& read_cb) { |
| 37 DVLOG(3) << __FUNCTION__; | 37 DVLOG(3) << __FUNCTION__; |
| 38 // We shouldn't be holding on to a previous callback if a new Read() came in. | 38 // We shouldn't be holding on to a previous callback if a new Read() came in. |
| 39 DCHECK(read_cb_.is_null()); | 39 DCHECK(read_cb_.is_null()); |
| 40 | 40 |
| 41 read_cb_ = read_cb; | 41 read_cb_ = read_cb; |
| 42 demuxer_stream_->Read(base::Bind(&MojoDemuxerStreamAdapter::OnBufferReady, | 42 demuxer_stream_->Read(base::Bind(&MojoDemuxerStreamAdapter::OnBufferReady, |
| 43 weak_factory_.GetWeakPtr())); | 43 weak_factory_.GetWeakPtr())); |
| 44 } | 44 } |
| 45 | 45 |
| 46 AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() { | 46 AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() { |
| 47 DCHECK_EQ(type_, DemuxerStream::AUDIO); | 47 DCHECK_EQ(type_, AUDIO); |
| 48 return audio_config_; | 48 return audio_config_; |
| 49 } | 49 } |
| 50 | 50 |
| 51 VideoDecoderConfig MojoDemuxerStreamAdapter::video_decoder_config() { | 51 VideoDecoderConfig MojoDemuxerStreamAdapter::video_decoder_config() { |
| 52 DCHECK_EQ(type_, DemuxerStream::VIDEO); | 52 DCHECK_EQ(type_, VIDEO); |
| 53 return video_config_; | 53 return video_config_; |
| 54 } | 54 } |
| 55 | 55 |
| 56 DemuxerStream::Type MojoDemuxerStreamAdapter::type() const { | 56 DemuxerStream::Type MojoDemuxerStreamAdapter::type() const { |
| 57 return type_; | 57 return type_; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void MojoDemuxerStreamAdapter::EnableBitstreamConverter() { | 60 void MojoDemuxerStreamAdapter::EnableBitstreamConverter() { |
| 61 demuxer_stream_->EnableBitstreamConverter(); | 61 demuxer_stream_->EnableBitstreamConverter(); |
| 62 } | 62 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 79 NOTIMPLEMENTED(); | 79 NOTIMPLEMENTED(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void MojoDemuxerStreamAdapter::SetStreamStatusChangeCB( | 82 void MojoDemuxerStreamAdapter::SetStreamStatusChangeCB( |
| 83 const StreamStatusChangeCB& cb) { | 83 const StreamStatusChangeCB& cb) { |
| 84 NOTIMPLEMENTED(); | 84 NOTIMPLEMENTED(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // TODO(xhwang): Pass liveness here. | 87 // TODO(xhwang): Pass liveness here. |
| 88 void MojoDemuxerStreamAdapter::OnStreamReady( | 88 void MojoDemuxerStreamAdapter::OnStreamReady( |
| 89 mojom::DemuxerStream::Type type, | 89 Type type, |
| 90 mojo::ScopedDataPipeConsumerHandle consumer_handle, | 90 mojo::ScopedDataPipeConsumerHandle consumer_handle, |
| 91 mojom::AudioDecoderConfigPtr audio_config, | 91 mojom::AudioDecoderConfigPtr audio_config, |
| 92 mojom::VideoDecoderConfigPtr video_config) { | 92 mojom::VideoDecoderConfigPtr video_config) { |
| 93 DVLOG(1) << __FUNCTION__; | 93 DVLOG(1) << __FUNCTION__; |
| 94 DCHECK_EQ(DemuxerStream::UNKNOWN, type_); | 94 DCHECK_EQ(UNKNOWN, type_); |
| 95 DCHECK(consumer_handle.is_valid()); | 95 DCHECK(consumer_handle.is_valid()); |
| 96 | 96 |
| 97 type_ = static_cast<DemuxerStream::Type>(type); | 97 type_ = type; |
| 98 | 98 |
| 99 mojo_decoder_buffer_reader_.reset( | 99 mojo_decoder_buffer_reader_.reset( |
| 100 new MojoDecoderBufferReader(std::move(consumer_handle))); | 100 new MojoDecoderBufferReader(std::move(consumer_handle))); |
| 101 | 101 |
| 102 UpdateConfig(std::move(audio_config), std::move(video_config)); | 102 UpdateConfig(std::move(audio_config), std::move(video_config)); |
| 103 | 103 |
| 104 stream_ready_cb_.Run(); | 104 stream_ready_cb_.Run(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void MojoDemuxerStreamAdapter::OnBufferReady( | 107 void MojoDemuxerStreamAdapter::OnBufferReady( |
| 108 mojom::DemuxerStream::Status status, | 108 Status status, |
| 109 mojom::DecoderBufferPtr buffer, | 109 mojom::DecoderBufferPtr buffer, |
| 110 mojom::AudioDecoderConfigPtr audio_config, | 110 mojom::AudioDecoderConfigPtr audio_config, |
| 111 mojom::VideoDecoderConfigPtr video_config) { | 111 mojom::VideoDecoderConfigPtr video_config) { |
| 112 DVLOG(3) << __FUNCTION__; | 112 DVLOG(3) << __FUNCTION__; |
| 113 DCHECK(!read_cb_.is_null()); | 113 DCHECK(!read_cb_.is_null()); |
| 114 DCHECK_NE(type_, DemuxerStream::UNKNOWN); | 114 DCHECK_NE(type_, UNKNOWN); |
| 115 | 115 |
| 116 if (status == mojom::DemuxerStream::Status::CONFIG_CHANGED) { | 116 if (status == kConfigChanged) { |
| 117 UpdateConfig(std::move(audio_config), std::move(video_config)); | 117 UpdateConfig(std::move(audio_config), std::move(video_config)); |
| 118 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kConfigChanged, nullptr); | 118 base::ResetAndReturn(&read_cb_).Run(kConfigChanged, nullptr); |
| 119 return; | 119 return; |
| 120 } | 120 } |
| 121 | 121 |
| 122 if (status == mojom::DemuxerStream::Status::ABORTED) { | 122 if (status == kAborted) { |
| 123 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kAborted, nullptr); | 123 base::ResetAndReturn(&read_cb_).Run(kAborted, nullptr); |
| 124 return; | 124 return; |
| 125 } | 125 } |
| 126 | 126 |
| 127 DCHECK_EQ(status, mojom::DemuxerStream::Status::OK); | 127 DCHECK_EQ(status, kOk); |
| 128 | 128 |
| 129 scoped_refptr<DecoderBuffer> media_buffer = | 129 scoped_refptr<DecoderBuffer> media_buffer = |
| 130 mojo_decoder_buffer_reader_->ReadDecoderBuffer(buffer); | 130 mojo_decoder_buffer_reader_->ReadDecoderBuffer(buffer); |
| 131 if (!media_buffer) { | 131 if (!media_buffer) { |
| 132 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kAborted, nullptr); | 132 base::ResetAndReturn(&read_cb_).Run(kAborted, nullptr); |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 | 135 |
| 136 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kOk, media_buffer); | 136 base::ResetAndReturn(&read_cb_).Run(kOk, media_buffer); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void MojoDemuxerStreamAdapter::UpdateConfig( | 139 void MojoDemuxerStreamAdapter::UpdateConfig( |
| 140 mojom::AudioDecoderConfigPtr audio_config, | 140 mojom::AudioDecoderConfigPtr audio_config, |
| 141 mojom::VideoDecoderConfigPtr video_config) { | 141 mojom::VideoDecoderConfigPtr video_config) { |
| 142 DCHECK_NE(type_, DemuxerStream::UNKNOWN); | 142 DCHECK_NE(type_, UNKNOWN); |
| 143 | 143 |
| 144 switch(type_) { | 144 switch(type_) { |
| 145 case DemuxerStream::AUDIO: | 145 case AUDIO: |
| 146 DCHECK(audio_config && !video_config); | 146 DCHECK(audio_config && !video_config); |
| 147 audio_config_ = audio_config.To<AudioDecoderConfig>(); | 147 audio_config_ = audio_config.To<AudioDecoderConfig>(); |
| 148 break; | 148 break; |
| 149 case DemuxerStream::VIDEO: | 149 case VIDEO: |
| 150 DCHECK(video_config && !audio_config); | 150 DCHECK(video_config && !audio_config); |
| 151 video_config_ = video_config.To<VideoDecoderConfig>(); | 151 video_config_ = video_config.To<VideoDecoderConfig>(); |
| 152 break; | 152 break; |
| 153 default: | 153 default: |
| 154 NOTREACHED(); | 154 NOTREACHED(); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 } // namespace media | 158 } // namespace media |
| OLD | NEW |