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/filters/android/media_codec_audio_decoder.h" | 5 #include "media/filters/android/media_codec_audio_decoder.h" |
6 | 6 |
7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 160 |
161 codec_loop_.reset(new MediaCodecLoop(this, std::move(audio_codec_bridge))); | 161 codec_loop_.reset(new MediaCodecLoop(this, std::move(audio_codec_bridge))); |
162 | 162 |
163 return true; | 163 return true; |
164 } | 164 } |
165 | 165 |
166 void MediaCodecAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, | 166 void MediaCodecAudioDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
167 const DecodeCB& decode_cb) { | 167 const DecodeCB& decode_cb) { |
168 DecodeCB bound_decode_cb = BindToCurrentLoop(decode_cb); | 168 DecodeCB bound_decode_cb = BindToCurrentLoop(decode_cb); |
169 | 169 |
170 if (!buffer->end_of_stream() && buffer->timestamp() == kNoTimestamp()) { | 170 if (!buffer->end_of_stream() && buffer->timestamp() == kNoTimestamp) { |
171 DVLOG(2) << __FUNCTION__ << " " << buffer->AsHumanReadableString() | 171 DVLOG(2) << __FUNCTION__ << " " << buffer->AsHumanReadableString() |
172 << ": no timestamp, skipping this buffer"; | 172 << ": no timestamp, skipping this buffer"; |
173 bound_decode_cb.Run(DecodeStatus::DECODE_ERROR); | 173 bound_decode_cb.Run(DecodeStatus::DECODE_ERROR); |
174 return; | 174 return; |
175 } | 175 } |
176 | 176 |
177 // Note that we transition to STATE_ERROR if |codec_loop_| does. | 177 // Note that we transition to STATE_ERROR if |codec_loop_| does. |
178 if (state_ == STATE_ERROR) { | 178 if (state_ == STATE_ERROR) { |
179 // We get here if an error happens in DequeueOutput() or Reset(). | 179 // We get here if an error happens in DequeueOutput() or Reset(). |
180 DVLOG(2) << __FUNCTION__ << " " << buffer->AsHumanReadableString() | 180 DVLOG(2) << __FUNCTION__ << " " << buffer->AsHumanReadableString() |
(...skipping 24 matching lines...) Expand all Loading... |
205 ClearInputQueue(DecodeStatus::ABORTED); | 205 ClearInputQueue(DecodeStatus::ABORTED); |
206 | 206 |
207 // Flush if we can, otherwise completely recreate and reconfigure the codec. | 207 // Flush if we can, otherwise completely recreate and reconfigure the codec. |
208 bool success = codec_loop_->TryFlush(); | 208 bool success = codec_loop_->TryFlush(); |
209 | 209 |
210 // If the flush failed, then we have to re-create the codec. | 210 // If the flush failed, then we have to re-create the codec. |
211 if (!success) | 211 if (!success) |
212 success = CreateMediaCodecLoop(); | 212 success = CreateMediaCodecLoop(); |
213 | 213 |
214 // Reset AudioTimestampHelper. | 214 // Reset AudioTimestampHelper. |
215 timestamp_helper_->SetBaseTimestamp(kNoTimestamp()); | 215 timestamp_helper_->SetBaseTimestamp(kNoTimestamp); |
216 | 216 |
217 SetState(success ? STATE_READY : STATE_ERROR); | 217 SetState(success ? STATE_READY : STATE_ERROR); |
218 | 218 |
219 task_runner_->PostTask(FROM_HERE, closure); | 219 task_runner_->PostTask(FROM_HERE, closure); |
220 } | 220 } |
221 | 221 |
222 bool MediaCodecAudioDecoder::NeedsBitstreamConversion() const { | 222 bool MediaCodecAudioDecoder::NeedsBitstreamConversion() const { |
223 // An AAC stream needs to be converted as ADTS stream. | 223 // An AAC stream needs to be converted as ADTS stream. |
224 DCHECK_NE(config_.codec(), kUnknownAudioCodec); | 224 DCHECK_NE(config_.codec(), kUnknownAudioCodec); |
225 return config_.codec() == kCodecAAC; | 225 return config_.codec() == kCodecAAC; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 memset(audio_buffer->channel_data()[0], 0, audio_buffer->data_size()); | 427 memset(audio_buffer->channel_data()[0], 0, audio_buffer->data_size()); |
428 SeparatePlanes(interleaved_data, frame_count, bytes_per_frame, | 428 SeparatePlanes(interleaved_data, frame_count, bytes_per_frame, |
429 channel_count_, audio_buffer->channel_data()); | 429 channel_count_, audio_buffer->channel_data()); |
430 } | 430 } |
431 | 431 |
432 // Release MediaCodec output buffer. | 432 // Release MediaCodec output buffer. |
433 media_codec->ReleaseOutputBuffer(out.index, false); | 433 media_codec->ReleaseOutputBuffer(out.index, false); |
434 | 434 |
435 // Calculate and set buffer timestamp. | 435 // Calculate and set buffer timestamp. |
436 | 436 |
437 const bool first_buffer = | 437 const bool first_buffer = timestamp_helper_->base_timestamp() == kNoTimestamp; |
438 timestamp_helper_->base_timestamp() == kNoTimestamp(); | |
439 if (first_buffer) { | 438 if (first_buffer) { |
440 // Clamp the base timestamp to zero. | 439 // Clamp the base timestamp to zero. |
441 timestamp_helper_->SetBaseTimestamp(std::max(base::TimeDelta(), out.pts)); | 440 timestamp_helper_->SetBaseTimestamp(std::max(base::TimeDelta(), out.pts)); |
442 } | 441 } |
443 | 442 |
444 audio_buffer->set_timestamp(timestamp_helper_->GetTimestamp()); | 443 audio_buffer->set_timestamp(timestamp_helper_->GetTimestamp()); |
445 timestamp_helper_->AddFrames(frame_count); | 444 timestamp_helper_->AddFrames(frame_count); |
446 | 445 |
447 // Call the |output_cb_|. | 446 // Call the |output_cb_|. |
448 output_cb_.Run(audio_buffer); | 447 output_cb_.Run(audio_buffer); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 RETURN_STRING(STATE_READY); | 504 RETURN_STRING(STATE_READY); |
506 RETURN_STRING(STATE_ERROR); | 505 RETURN_STRING(STATE_ERROR); |
507 } | 506 } |
508 NOTREACHED() << "Unknown state " << state; | 507 NOTREACHED() << "Unknown state " << state; |
509 return nullptr; | 508 return nullptr; |
510 } | 509 } |
511 | 510 |
512 #undef RETURN_STRING | 511 #undef RETURN_STRING |
513 | 512 |
514 } // namespace media | 513 } // namespace media |
OLD | NEW |