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" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 mojom::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>& media_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, |
89 base::Bind(decode_cb, DecodeStatus::DECODE_ERROR)); | 89 base::Bind(decode_cb, DecodeStatus::DECODE_ERROR)); |
90 return; | 90 return; |
91 } | 91 } |
92 | 92 |
93 mojom::DecoderBufferPtr buffer = TransferDecoderBuffer(media_buffer); | |
94 if (!buffer) { | |
95 task_runner_->PostTask(FROM_HERE, | |
96 base::Bind(decode_cb, DecodeStatus::DECODE_ERROR)); | |
97 return; | |
98 } | |
99 | |
93 DCHECK(decode_cb_.is_null()); | 100 DCHECK(decode_cb_.is_null()); |
94 decode_cb_ = decode_cb; | 101 decode_cb_ = decode_cb; |
95 | 102 |
96 remote_decoder_->Decode( | 103 remote_decoder_->Decode( |
97 TransferDecoderBuffer(buffer), | 104 std::move(buffer), |
98 base::Bind(&MojoAudioDecoder::OnDecodeStatus, base::Unretained(this))); | 105 base::Bind(&MojoAudioDecoder::OnDecodeStatus, base::Unretained(this))); |
99 } | 106 } |
100 | 107 |
101 void MojoAudioDecoder::Reset(const base::Closure& closure) { | 108 void MojoAudioDecoder::Reset(const base::Closure& closure) { |
102 DVLOG(2) << __FUNCTION__; | 109 DVLOG(2) << __FUNCTION__; |
103 DCHECK(task_runner_->BelongsToCurrentThread()); | 110 DCHECK(task_runner_->BelongsToCurrentThread()); |
104 | 111 |
105 if (has_connection_error_) { | 112 if (has_connection_error_) { |
106 if (!decode_cb_.is_null()) { | 113 if (!decode_cb_.is_null()) { |
107 task_runner_->PostTask(FROM_HERE, | 114 task_runner_->PostTask(FROM_HERE, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 | 223 |
217 mojom::DecoderBufferPtr MojoAudioDecoder::TransferDecoderBuffer( | 224 mojom::DecoderBufferPtr MojoAudioDecoder::TransferDecoderBuffer( |
218 const scoped_refptr<DecoderBuffer>& media_buffer) { | 225 const scoped_refptr<DecoderBuffer>& media_buffer) { |
219 mojom::DecoderBufferPtr buffer = mojom::DecoderBuffer::From(media_buffer); | 226 mojom::DecoderBufferPtr buffer = mojom::DecoderBuffer::From(media_buffer); |
220 if (media_buffer->end_of_stream()) | 227 if (media_buffer->end_of_stream()) |
221 return buffer; | 228 return buffer; |
222 | 229 |
223 // Serialize the data section of the DecoderBuffer into our pipe. | 230 // Serialize the data section of the DecoderBuffer into our pipe. |
224 uint32_t num_bytes = base::checked_cast<uint32_t>(media_buffer->data_size()); | 231 uint32_t num_bytes = base::checked_cast<uint32_t>(media_buffer->data_size()); |
225 DCHECK_GT(num_bytes, 0u); | 232 DCHECK_GT(num_bytes, 0u); |
226 CHECK_EQ(WriteDataRaw(producer_handle_.get(), media_buffer->data(), | 233 MojoResult result = |
227 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), | 234 WriteDataRaw(producer_handle_.get(), media_buffer->data(), &num_bytes, |
228 MOJO_RESULT_OK); | 235 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE); |
229 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); | 236 if (result != MOJO_RESULT_OK || num_bytes != media_buffer->data_size()) |
237 return nullptr; | |
xhwang
2016/05/19 18:59:59
Can you put a DVLOG(1) here?
Tima Vaisburd
2016/05/19 22:00:57
Done.
| |
238 | |
230 return buffer; | 239 return buffer; |
231 } | 240 } |
232 | 241 |
233 } // namespace media | 242 } // namespace media |
OLD | NEW |