| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ffmpeg_audio_decoder.h" | 5 #include "media/filters/ffmpeg_audio_decoder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "media/base/audio_decoder_config.h" | 9 #include "media/base/audio_decoder_config.h" |
| 10 #include "media/base/data_buffer.h" | 10 #include "media/base/data_buffer.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 if (status != DemuxerStream::kOk) { | 171 if (status != DemuxerStream::kOk) { |
| 172 DCHECK(!input); | 172 DCHECK(!input); |
| 173 // TODO(acolwell): Add support for reinitializing the decoder when | 173 // TODO(acolwell): Add support for reinitializing the decoder when |
| 174 // |status| == kConfigChanged. For now we just trigger a decode error. | 174 // |status| == kConfigChanged. For now we just trigger a decode error. |
| 175 AudioDecoder::Status decoder_status = | 175 AudioDecoder::Status decoder_status = |
| 176 (status == DemuxerStream::kAborted) ? kAborted : kDecodeError; | 176 (status == DemuxerStream::kAborted) ? kAborted : kDecodeError; |
| 177 base::ResetAndReturn(&read_cb_).Run(decoder_status, NULL); | 177 base::ResetAndReturn(&read_cb_).Run(decoder_status, NULL); |
| 178 return; | 178 return; |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Make sure we are notified if http://crbug.com/49709 returns. | 181 // Make sure we are notified if http://crbug.com/49709 returns. Issue also |
| 182 CHECK(input->GetTimestamp() != kNoTimestamp() || | 182 // occurs with some damaged files. |
| 183 output_timestamp_base_ != kNoTimestamp() || | 183 if (!input->IsEndOfStream() && input->GetTimestamp() == kNoTimestamp() && |
| 184 input->IsEndOfStream()) | 184 output_timestamp_base_ == kNoTimestamp()) { |
| 185 << "First buffers received don't have timestamps!"; | 185 DVLOG(1) << "Received a buffer without timestamps!"; |
| 186 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); |
| 187 return; |
| 188 } |
| 186 | 189 |
| 187 bool is_vorbis = codec_context_->codec_id == CODEC_ID_VORBIS; | 190 bool is_vorbis = codec_context_->codec_id == CODEC_ID_VORBIS; |
| 188 if (!input->IsEndOfStream()) { | 191 if (!input->IsEndOfStream()) { |
| 189 if (last_input_timestamp_ == kNoTimestamp()) { | 192 if (last_input_timestamp_ == kNoTimestamp()) { |
| 190 if (is_vorbis && (input->GetTimestamp() < base::TimeDelta())) { | 193 if (is_vorbis && (input->GetTimestamp() < base::TimeDelta())) { |
| 191 // Dropping frames for negative timestamps as outlined in section A.2 | 194 // Dropping frames for negative timestamps as outlined in section A.2 |
| 192 // in the Vorbis spec. http://xiph.org/vorbis/doc/Vorbis_I_spec.html | 195 // in the Vorbis spec. http://xiph.org/vorbis/doc/Vorbis_I_spec.html |
| 193 int frames_to_drop = floor( | 196 int frames_to_drop = floor( |
| 194 0.5 + -input->GetTimestamp().InSecondsF() * samples_per_second_); | 197 0.5 + -input->GetTimestamp().InSecondsF() * samples_per_second_); |
| 195 output_bytes_to_drop_ = bytes_per_frame_ * frames_to_drop; | 198 output_bytes_to_drop_ = bytes_per_frame_ * frames_to_drop; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 &FFmpegAudioDecoder::DoDecodeBuffer, this, status, buffer)); | 327 &FFmpegAudioDecoder::DoDecodeBuffer, this, status, buffer)); |
| 325 } | 328 } |
| 326 | 329 |
| 327 base::TimeDelta FFmpegAudioDecoder::GetNextOutputTimestamp() const { | 330 base::TimeDelta FFmpegAudioDecoder::GetNextOutputTimestamp() const { |
| 328 DCHECK(output_timestamp_base_ != kNoTimestamp()); | 331 DCHECK(output_timestamp_base_ != kNoTimestamp()); |
| 329 double decoded_us = (total_frames_decoded_ / samples_per_second_) * | 332 double decoded_us = (total_frames_decoded_ / samples_per_second_) * |
| 330 base::Time::kMicrosecondsPerSecond; | 333 base::Time::kMicrosecondsPerSecond; |
| 331 return output_timestamp_base_ + base::TimeDelta::FromMicroseconds(decoded_us); | 334 return output_timestamp_base_ + base::TimeDelta::FromMicroseconds(decoded_us); |
| 332 } | 335 } |
| 333 } // namespace media | 336 } // namespace media |
| OLD | NEW |