| Index: media/filters/ffmpeg_audio_decoder.cc
|
| diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc
|
| index 45f8dd4863d6da11db8b4792ee5dba86c4551948..d55e0082407bd9bcbe824de4f40e247ac2c41108 100644
|
| --- a/media/filters/ffmpeg_audio_decoder.cc
|
| +++ b/media/filters/ffmpeg_audio_decoder.cc
|
| @@ -125,6 +125,10 @@ static int GetAudioBuffer(struct AVCodecContext* s, AVFrame* frame, int flags) {
|
| return 0;
|
| }
|
|
|
| +static int TimeDeltaToFrames(base::TimeDelta duration, int sample_rate) {
|
| + return 0.5 + duration.InSecondsF() * sample_rate;
|
| +}
|
| +
|
| FFmpegAudioDecoder::FFmpegAudioDecoder(
|
| const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
|
| : task_runner_(task_runner),
|
| @@ -267,8 +271,8 @@ void FFmpegAudioDecoder::DecodeBuffer(
|
| buffer->timestamp() < base::TimeDelta()) {
|
| // Dropping frames for negative timestamps as outlined in section A.2
|
| // in the Vorbis spec. http://xiph.org/vorbis/doc/Vorbis_I_spec.html
|
| - output_frames_to_drop_ = floor(0.5 + -buffer->timestamp().InSecondsF() *
|
| - config_.samples_per_second());
|
| + output_frames_to_drop_ =
|
| + TimeDeltaToFrames(-buffer->timestamp(), config_.samples_per_second());
|
| } else {
|
| if (last_input_timestamp_ != kNoTimestamp() &&
|
| buffer->timestamp() < last_input_timestamp_) {
|
| @@ -358,10 +362,10 @@ bool FFmpegAudioDecoder::FFmpegDecode(
|
| if (output_timestamp_helper_->base_timestamp() == kNoTimestamp() &&
|
| !buffer->end_of_stream()) {
|
| DCHECK(buffer->timestamp() != kNoTimestamp());
|
| - if (output_frames_to_drop_ > 0) {
|
| - // Currently Vorbis is the only codec that causes us to drop samples.
|
| - // If we have to drop samples it always means the timeline starts at 0.
|
| - DCHECK_EQ(codec_context_->codec_id, AV_CODEC_ID_VORBIS);
|
| + if (output_frames_to_drop_ > 0 &&
|
| + codec_context_->codec_id == AV_CODEC_ID_VORBIS) {
|
| + // If we are dropping samples for Vorbis, it always means the timeline
|
| + // starts at 0.
|
| output_timestamp_helper_->SetBaseTimestamp(base::TimeDelta());
|
| } else {
|
| output_timestamp_helper_->SetBaseTimestamp(buffer->timestamp());
|
| @@ -496,6 +500,12 @@ bool FFmpegAudioDecoder::ConfigureDecoder() {
|
| state_ = kUninitialized;
|
| return false;
|
| }
|
| +
|
| + if (config_.codec_delay() > base::TimeDelta()) {
|
| + output_frames_to_drop_ =
|
| + TimeDeltaToFrames(config_.codec_delay(), config_.samples_per_second());
|
| + }
|
| +
|
| return true;
|
| }
|
|
|
|
|