OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_audio_decoder.h" | 5 #include "media/mojo/services/mojo_audio_decoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "media/base/audio_buffer.h" | 14 #include "media/base/audio_buffer.h" |
15 #include "media/base/cdm_context.h" | 15 #include "media/base/cdm_context.h" |
16 #include "media/mojo/common/media_type_converters.h" | 16 #include "media/mojo/common/media_type_converters.h" |
17 | 17 |
18 namespace media { | 18 namespace media { |
19 | 19 |
20 MojoAudioDecoder::MojoAudioDecoder( | 20 MojoAudioDecoder::MojoAudioDecoder( |
21 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 21 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
22 interfaces::AudioDecoderPtr remote_decoder) | 22 mojom::AudioDecoderPtr remote_decoder) |
23 : task_runner_(task_runner), | 23 : task_runner_(task_runner), |
24 remote_decoder_info_(remote_decoder.PassInterface()), | 24 remote_decoder_info_(remote_decoder.PassInterface()), |
25 binding_(this), | 25 binding_(this), |
26 has_connection_error_(false), | 26 has_connection_error_(false), |
27 needs_bitstream_conversion_(false) { | 27 needs_bitstream_conversion_(false) { |
28 DVLOG(1) << __FUNCTION__; | 28 DVLOG(1) << __FUNCTION__; |
29 } | 29 } |
30 | 30 |
31 MojoAudioDecoder::~MojoAudioDecoder() { | 31 MojoAudioDecoder::~MojoAudioDecoder() { |
32 DVLOG(1) << __FUNCTION__; | 32 DVLOG(1) << __FUNCTION__; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 remote_decoder_.set_connection_error_handler( | 68 remote_decoder_.set_connection_error_handler( |
69 base::Bind(&MojoAudioDecoder::OnConnectionError, base::Unretained(this))); | 69 base::Bind(&MojoAudioDecoder::OnConnectionError, base::Unretained(this))); |
70 | 70 |
71 init_cb_ = init_cb; | 71 init_cb_ = init_cb; |
72 output_cb_ = output_cb; | 72 output_cb_ = output_cb; |
73 | 73 |
74 // Using base::Unretained(this) is safe because |this| owns |remote_decoder_|, | 74 // Using base::Unretained(this) is safe because |this| owns |remote_decoder_|, |
75 // and the callback won't be dispatched if |remote_decoder_| is destroyed. | 75 // and the callback won't be dispatched if |remote_decoder_| is destroyed. |
76 remote_decoder_->Initialize( | 76 remote_decoder_->Initialize( |
77 binding_.CreateInterfacePtrAndBind(), | 77 binding_.CreateInterfacePtrAndBind(), |
78 interfaces::AudioDecoderConfig::From(config), cdm_id, | 78 mojom::AudioDecoderConfig::From(config), cdm_id, |
79 base::Bind(&MojoAudioDecoder::OnInitialized, base::Unretained(this))); | 79 base::Bind(&MojoAudioDecoder::OnInitialized, base::Unretained(this))); |
80 } | 80 } |
81 | 81 |
82 void MojoAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, | 82 void MojoAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
83 const DecodeCB& decode_cb) { | 83 const DecodeCB& decode_cb) { |
84 DVLOG(3) << __FUNCTION__; | 84 DVLOG(3) << __FUNCTION__; |
85 DCHECK(task_runner_->BelongsToCurrentThread()); | 85 DCHECK(task_runner_->BelongsToCurrentThread()); |
86 | 86 |
87 if (has_connection_error_) { | 87 if (has_connection_error_) { |
88 task_runner_->PostTask(FROM_HERE, | 88 task_runner_->PostTask(FROM_HERE, |
(...skipping 30 matching lines...) Expand all Loading... |
119 base::Bind(&MojoAudioDecoder::OnResetDone, base::Unretained(this))); | 119 base::Bind(&MojoAudioDecoder::OnResetDone, base::Unretained(this))); |
120 } | 120 } |
121 | 121 |
122 bool MojoAudioDecoder::NeedsBitstreamConversion() const { | 122 bool MojoAudioDecoder::NeedsBitstreamConversion() const { |
123 DVLOG(1) << __FUNCTION__; | 123 DVLOG(1) << __FUNCTION__; |
124 DCHECK(task_runner_->BelongsToCurrentThread()); | 124 DCHECK(task_runner_->BelongsToCurrentThread()); |
125 | 125 |
126 return needs_bitstream_conversion_; | 126 return needs_bitstream_conversion_; |
127 } | 127 } |
128 | 128 |
129 void MojoAudioDecoder::OnBufferDecoded(interfaces::AudioBufferPtr buffer) { | 129 void MojoAudioDecoder::OnBufferDecoded(mojom::AudioBufferPtr buffer) { |
130 DVLOG(1) << __FUNCTION__; | 130 DVLOG(1) << __FUNCTION__; |
131 DCHECK(task_runner_->BelongsToCurrentThread()); | 131 DCHECK(task_runner_->BelongsToCurrentThread()); |
132 | 132 |
133 output_cb_.Run(buffer.To<scoped_refptr<AudioBuffer>>()); | 133 output_cb_.Run(buffer.To<scoped_refptr<AudioBuffer>>()); |
134 } | 134 } |
135 | 135 |
136 void MojoAudioDecoder::OnConnectionError() { | 136 void MojoAudioDecoder::OnConnectionError() { |
137 DVLOG(1) << __FUNCTION__; | 137 DVLOG(1) << __FUNCTION__; |
138 DCHECK(task_runner_->BelongsToCurrentThread()); | 138 DCHECK(task_runner_->BelongsToCurrentThread()); |
139 | 139 |
(...skipping 17 matching lines...) Expand all Loading... |
157 | 157 |
158 needs_bitstream_conversion_ = needs_bitstream_conversion; | 158 needs_bitstream_conversion_ = needs_bitstream_conversion; |
159 | 159 |
160 if (success) | 160 if (success) |
161 CreateDataPipe(); | 161 CreateDataPipe(); |
162 | 162 |
163 base::ResetAndReturn(&init_cb_).Run(success); | 163 base::ResetAndReturn(&init_cb_).Run(success); |
164 } | 164 } |
165 | 165 |
166 static media::DecodeStatus ConvertDecodeStatus( | 166 static media::DecodeStatus ConvertDecodeStatus( |
167 interfaces::AudioDecoder::DecodeStatus status) { | 167 mojom::AudioDecoder::DecodeStatus status) { |
168 switch (status) { | 168 switch (status) { |
169 case interfaces::AudioDecoder::DecodeStatus::OK: | 169 case mojom::AudioDecoder::DecodeStatus::OK: |
170 return media::DecodeStatus::OK; | 170 return media::DecodeStatus::OK; |
171 case interfaces::AudioDecoder::DecodeStatus::ABORTED: | 171 case mojom::AudioDecoder::DecodeStatus::ABORTED: |
172 return media::DecodeStatus::ABORTED; | 172 return media::DecodeStatus::ABORTED; |
173 case interfaces::AudioDecoder::DecodeStatus::DECODE_ERROR: | 173 case mojom::AudioDecoder::DecodeStatus::DECODE_ERROR: |
174 return media::DecodeStatus::DECODE_ERROR; | 174 return media::DecodeStatus::DECODE_ERROR; |
175 } | 175 } |
176 NOTREACHED(); | 176 NOTREACHED(); |
177 return media::DecodeStatus::DECODE_ERROR; | 177 return media::DecodeStatus::DECODE_ERROR; |
178 } | 178 } |
179 | 179 |
180 void MojoAudioDecoder::OnDecodeStatus( | 180 void MojoAudioDecoder::OnDecodeStatus( |
181 interfaces::AudioDecoder::DecodeStatus status) { | 181 mojom::AudioDecoder::DecodeStatus status) { |
182 DVLOG(1) << __FUNCTION__ << ": status:" << status; | 182 DVLOG(1) << __FUNCTION__ << ": status:" << status; |
183 DCHECK(task_runner_->BelongsToCurrentThread()); | 183 DCHECK(task_runner_->BelongsToCurrentThread()); |
184 | 184 |
185 DCHECK(!decode_cb_.is_null()); | 185 DCHECK(!decode_cb_.is_null()); |
186 base::ResetAndReturn(&decode_cb_).Run(ConvertDecodeStatus(status)); | 186 base::ResetAndReturn(&decode_cb_).Run(ConvertDecodeStatus(status)); |
187 } | 187 } |
188 | 188 |
189 void MojoAudioDecoder::OnResetDone() { | 189 void MojoAudioDecoder::OnResetDone() { |
190 DVLOG(1) << __FUNCTION__; | 190 DVLOG(1) << __FUNCTION__; |
191 DCHECK(task_runner_->BelongsToCurrentThread()); | 191 DCHECK(task_runner_->BelongsToCurrentThread()); |
(...skipping 15 matching lines...) Expand all Loading... |
207 | 207 |
208 mojo::DataPipe write_pipe(options); | 208 mojo::DataPipe write_pipe(options); |
209 | 209 |
210 // Keep producer end. | 210 // Keep producer end. |
211 producer_handle_ = std::move(write_pipe.producer_handle); | 211 producer_handle_ = std::move(write_pipe.producer_handle); |
212 | 212 |
213 // Pass consumer end to |remote_decoder_|. | 213 // Pass consumer end to |remote_decoder_|. |
214 remote_decoder_->SetDataSource(std::move(write_pipe.consumer_handle)); | 214 remote_decoder_->SetDataSource(std::move(write_pipe.consumer_handle)); |
215 } | 215 } |
216 | 216 |
217 interfaces::DecoderBufferPtr MojoAudioDecoder::TransferDecoderBuffer( | 217 mojom::DecoderBufferPtr MojoAudioDecoder::TransferDecoderBuffer( |
218 const scoped_refptr<DecoderBuffer>& media_buffer) { | 218 const scoped_refptr<DecoderBuffer>& media_buffer) { |
219 interfaces::DecoderBufferPtr buffer = | 219 mojom::DecoderBufferPtr buffer = mojom::DecoderBuffer::From(media_buffer); |
220 interfaces::DecoderBuffer::From(media_buffer); | |
221 if (media_buffer->end_of_stream()) | 220 if (media_buffer->end_of_stream()) |
222 return buffer; | 221 return buffer; |
223 | 222 |
224 // Serialize the data section of the DecoderBuffer into our pipe. | 223 // Serialize the data section of the DecoderBuffer into our pipe. |
225 uint32_t num_bytes = base::checked_cast<uint32_t>(media_buffer->data_size()); | 224 uint32_t num_bytes = base::checked_cast<uint32_t>(media_buffer->data_size()); |
226 DCHECK_GT(num_bytes, 0u); | 225 DCHECK_GT(num_bytes, 0u); |
227 CHECK_EQ(WriteDataRaw(producer_handle_.get(), media_buffer->data(), | 226 CHECK_EQ(WriteDataRaw(producer_handle_.get(), media_buffer->data(), |
228 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), | 227 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), |
229 MOJO_RESULT_OK); | 228 MOJO_RESULT_OK); |
230 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); | 229 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); |
231 return buffer; | 230 return buffer; |
232 } | 231 } |
233 | 232 |
234 } // namespace media | 233 } // namespace media |
OLD | NEW |