| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 interfaces::AudioDecoderConfig::From(config), cdm_id, | 78 interfaces::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, base::Bind(decode_cb, kDecodeError)); | 88 task_runner_->PostTask(FROM_HERE, |
| 89 base::Bind(decode_cb, DecodeStatus::DECODE_ERROR)); |
| 89 return; | 90 return; |
| 90 } | 91 } |
| 91 | 92 |
| 92 DCHECK(decode_cb_.is_null()); | 93 DCHECK(decode_cb_.is_null()); |
| 93 decode_cb_ = decode_cb; | 94 decode_cb_ = decode_cb; |
| 94 | 95 |
| 95 remote_decoder_->Decode( | 96 remote_decoder_->Decode( |
| 96 TransferDecoderBuffer(buffer), | 97 TransferDecoderBuffer(buffer), |
| 97 base::Bind(&MojoAudioDecoder::OnDecodeStatus, base::Unretained(this))); | 98 base::Bind(&MojoAudioDecoder::OnDecodeStatus, base::Unretained(this))); |
| 98 } | 99 } |
| 99 | 100 |
| 100 void MojoAudioDecoder::Reset(const base::Closure& closure) { | 101 void MojoAudioDecoder::Reset(const base::Closure& closure) { |
| 101 DVLOG(2) << __FUNCTION__; | 102 DVLOG(2) << __FUNCTION__; |
| 102 DCHECK(task_runner_->BelongsToCurrentThread()); | 103 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 103 | 104 |
| 104 if (has_connection_error_) { | 105 if (has_connection_error_) { |
| 105 if (!decode_cb_.is_null()) { | 106 if (!decode_cb_.is_null()) { |
| 106 task_runner_->PostTask( | 107 task_runner_->PostTask(FROM_HERE, |
| 107 FROM_HERE, | 108 base::Bind(base::ResetAndReturn(&decode_cb_), |
| 108 base::Bind(base::ResetAndReturn(&decode_cb_), kDecodeError)); | 109 DecodeStatus::DECODE_ERROR)); |
| 109 } | 110 } |
| 110 | 111 |
| 111 task_runner_->PostTask(FROM_HERE, closure); | 112 task_runner_->PostTask(FROM_HERE, closure); |
| 112 return; | 113 return; |
| 113 } | 114 } |
| 114 | 115 |
| 115 DCHECK(reset_cb_.is_null()); | 116 DCHECK(reset_cb_.is_null()); |
| 116 reset_cb_ = closure; | 117 reset_cb_ = closure; |
| 117 remote_decoder_->Reset( | 118 remote_decoder_->Reset( |
| 118 base::Bind(&MojoAudioDecoder::OnResetDone, base::Unretained(this))); | 119 base::Bind(&MojoAudioDecoder::OnResetDone, base::Unretained(this))); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 137 DCHECK(task_runner_->BelongsToCurrentThread()); | 138 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 138 | 139 |
| 139 has_connection_error_ = true; | 140 has_connection_error_ = true; |
| 140 | 141 |
| 141 if (!init_cb_.is_null()) { | 142 if (!init_cb_.is_null()) { |
| 142 base::ResetAndReturn(&init_cb_).Run(false); | 143 base::ResetAndReturn(&init_cb_).Run(false); |
| 143 return; | 144 return; |
| 144 } | 145 } |
| 145 | 146 |
| 146 if (!decode_cb_.is_null()) | 147 if (!decode_cb_.is_null()) |
| 147 base::ResetAndReturn(&decode_cb_).Run(kDecodeError); | 148 base::ResetAndReturn(&decode_cb_).Run(DecodeStatus::DECODE_ERROR); |
| 148 if (!reset_cb_.is_null()) | 149 if (!reset_cb_.is_null()) |
| 149 base::ResetAndReturn(&reset_cb_).Run(); | 150 base::ResetAndReturn(&reset_cb_).Run(); |
| 150 } | 151 } |
| 151 | 152 |
| 152 void MojoAudioDecoder::OnInitialized(bool status, | 153 void MojoAudioDecoder::OnInitialized(bool status, |
| 153 bool needs_bitstream_conversion) { | 154 bool needs_bitstream_conversion) { |
| 154 DVLOG(1) << __FUNCTION__ << ": status:" << status; | 155 DVLOG(1) << __FUNCTION__ << ": status:" << status; |
| 155 DCHECK(task_runner_->BelongsToCurrentThread()); | 156 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 156 | 157 |
| 157 needs_bitstream_conversion_ = needs_bitstream_conversion; | 158 needs_bitstream_conversion_ = needs_bitstream_conversion; |
| 158 | 159 |
| 159 if (status) | 160 if (status) |
| 160 CreateDataPipe(); | 161 CreateDataPipe(); |
| 161 | 162 |
| 162 task_runner_->PostTask(FROM_HERE, base::Bind(init_cb_, status)); | 163 task_runner_->PostTask(FROM_HERE, base::Bind(init_cb_, status)); |
| 163 } | 164 } |
| 164 | 165 |
| 165 static media::AudioDecoder::Status ConvertDecodeStatus( | 166 static media::DecodeStatus ConvertDecodeStatus( |
| 166 interfaces::AudioDecoder::DecodeStatus status) { | 167 interfaces::AudioDecoder::DecodeStatus status) { |
| 167 switch (status) { | 168 switch (status) { |
| 168 case interfaces::AudioDecoder::DecodeStatus::OK: | 169 case interfaces::AudioDecoder::DecodeStatus::OK: |
| 169 return media::AudioDecoder::kOk; | 170 return media::DecodeStatus::OK; |
| 170 case interfaces::AudioDecoder::DecodeStatus::ABORTED: | 171 case interfaces::AudioDecoder::DecodeStatus::ABORTED: |
| 171 return media::AudioDecoder::kAborted; | 172 return media::DecodeStatus::ABORTED; |
| 172 case interfaces::AudioDecoder::DecodeStatus::DECODE_ERROR: | 173 case interfaces::AudioDecoder::DecodeStatus::DECODE_ERROR: |
| 173 return media::AudioDecoder::kDecodeError; | 174 return media::DecodeStatus::DECODE_ERROR; |
| 174 } | 175 } |
| 175 NOTREACHED(); | 176 NOTREACHED(); |
| 176 return media::AudioDecoder::kDecodeError; | 177 return media::DecodeStatus::DECODE_ERROR; |
| 177 } | 178 } |
| 178 | 179 |
| 179 void MojoAudioDecoder::OnDecodeStatus( | 180 void MojoAudioDecoder::OnDecodeStatus( |
| 180 interfaces::AudioDecoder::DecodeStatus status) { | 181 interfaces::AudioDecoder::DecodeStatus status) { |
| 181 DVLOG(1) << __FUNCTION__ << ": status:" << status; | 182 DVLOG(1) << __FUNCTION__ << ": status:" << status; |
| 182 DCHECK(task_runner_->BelongsToCurrentThread()); | 183 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 183 | 184 |
| 184 DCHECK(!decode_cb_.is_null()); | 185 DCHECK(!decode_cb_.is_null()); |
| 185 base::ResetAndReturn(&decode_cb_).Run(ConvertDecodeStatus(status)); | 186 base::ResetAndReturn(&decode_cb_).Run(ConvertDecodeStatus(status)); |
| 186 } | 187 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 uint32_t num_bytes = base::checked_cast<uint32_t>(media_buffer->data_size()); | 225 uint32_t num_bytes = base::checked_cast<uint32_t>(media_buffer->data_size()); |
| 225 DCHECK_GT(num_bytes, 0u); | 226 DCHECK_GT(num_bytes, 0u); |
| 226 CHECK_EQ(WriteDataRaw(producer_handle_.get(), media_buffer->data(), | 227 CHECK_EQ(WriteDataRaw(producer_handle_.get(), media_buffer->data(), |
| 227 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), | 228 &num_bytes, MOJO_READ_DATA_FLAG_ALL_OR_NONE), |
| 228 MOJO_RESULT_OK); | 229 MOJO_RESULT_OK); |
| 229 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); | 230 CHECK_EQ(num_bytes, static_cast<uint32_t>(media_buffer->data_size())); |
| 230 return buffer; | 231 return buffer; |
| 231 } | 232 } |
| 232 | 233 |
| 233 } // namespace media | 234 } // namespace media |
| OLD | NEW |