Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: media/filters/ffmpeg_audio_decoder.cc

Issue 239423005: Wire up codec_delay() to MP3StreamParser and FFmpegAudioDecoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch codec_delay() to frames. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "media/base/audio_buffer.h" 9 #include "media/base/audio_buffer.h"
10 #include "media/base/audio_bus.h" 10 #include "media/base/audio_bus.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 decode_cb.Run(kDecodeError, NULL); 260 decode_cb.Run(kDecodeError, NULL);
261 return; 261 return;
262 } 262 }
263 263
264 if (!buffer->end_of_stream()) { 264 if (!buffer->end_of_stream()) {
265 if (last_input_timestamp_ == kNoTimestamp() && 265 if (last_input_timestamp_ == kNoTimestamp() &&
266 codec_context_->codec_id == AV_CODEC_ID_VORBIS && 266 codec_context_->codec_id == AV_CODEC_ID_VORBIS &&
267 buffer->timestamp() < base::TimeDelta()) { 267 buffer->timestamp() < base::TimeDelta()) {
268 // Dropping frames for negative timestamps as outlined in section A.2 268 // Dropping frames for negative timestamps as outlined in section A.2
269 // in the Vorbis spec. http://xiph.org/vorbis/doc/Vorbis_I_spec.html 269 // in the Vorbis spec. http://xiph.org/vorbis/doc/Vorbis_I_spec.html
270 output_frames_to_drop_ = floor(0.5 + -buffer->timestamp().InSecondsF() * 270 output_frames_to_drop_ = 0.5 + -buffer->timestamp().InSecondsF() *
acolwell GONE FROM CHROMIUM 2014/04/17 21:11:24 Why is this change needed?
DaleCurtis 2014/04/17 21:42:49 It's a cleanup from an earlier patch set. I kept
271 config_.samples_per_second()); 271 config_.samples_per_second();
272 } else { 272 } else {
273 if (last_input_timestamp_ != kNoTimestamp() && 273 if (last_input_timestamp_ != kNoTimestamp() &&
274 buffer->timestamp() < last_input_timestamp_) { 274 buffer->timestamp() < last_input_timestamp_) {
275 const base::TimeDelta diff = 275 const base::TimeDelta diff =
276 buffer->timestamp() - last_input_timestamp_; 276 buffer->timestamp() - last_input_timestamp_;
277 DLOG(WARNING) 277 DLOG(WARNING)
278 << "Input timestamps are not monotonically increasing! " 278 << "Input timestamps are not monotonically increasing! "
279 << " ts " << buffer->timestamp().InMicroseconds() << " us" 279 << " ts " << buffer->timestamp().InMicroseconds() << " us"
280 << " diff " << diff.InMicroseconds() << " us"; 280 << " diff " << diff.InMicroseconds() << " us";
281 } 281 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 } 351 }
352 352
353 // Update packet size and data pointer in case we need to call the decoder 353 // Update packet size and data pointer in case we need to call the decoder
354 // with the remaining bytes from this packet. 354 // with the remaining bytes from this packet.
355 packet.size -= result; 355 packet.size -= result;
356 packet.data += result; 356 packet.data += result;
357 357
358 if (output_timestamp_helper_->base_timestamp() == kNoTimestamp() && 358 if (output_timestamp_helper_->base_timestamp() == kNoTimestamp() &&
359 !buffer->end_of_stream()) { 359 !buffer->end_of_stream()) {
360 DCHECK(buffer->timestamp() != kNoTimestamp()); 360 DCHECK(buffer->timestamp() != kNoTimestamp());
361 if (output_frames_to_drop_ > 0) { 361 if (output_frames_to_drop_ > 0 &&
362 // Currently Vorbis is the only codec that causes us to drop samples. 362 codec_context_->codec_id == AV_CODEC_ID_VORBIS) {
363 // If we have to drop samples it always means the timeline starts at 0. 363 // If we are dropping samples for Vorbis, it always means the timeline
364 DCHECK_EQ(codec_context_->codec_id, AV_CODEC_ID_VORBIS); 364 // starts at 0.
365 output_timestamp_helper_->SetBaseTimestamp(base::TimeDelta()); 365 output_timestamp_helper_->SetBaseTimestamp(base::TimeDelta());
acolwell GONE FROM CHROMIUM 2014/04/17 21:11:24 Can we move this up into DecodeBuffer() next to th
DaleCurtis 2014/04/17 21:42:49 Done.
366 } else { 366 } else {
367 output_timestamp_helper_->SetBaseTimestamp(buffer->timestamp()); 367 output_timestamp_helper_->SetBaseTimestamp(buffer->timestamp());
368 } 368 }
369 } 369 }
370 370
371 scoped_refptr<AudioBuffer> output; 371 scoped_refptr<AudioBuffer> output;
372 int decoded_frames = 0; 372 int decoded_frames = 0;
373 int original_frames = 0; 373 int original_frames = 0;
374 int channels = DetermineChannels(av_frame_.get()); 374 int channels = DetermineChannels(av_frame_.get());
375 if (frame_decoded) { 375 if (frame_decoded) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 if (codec_context_->channels != 489 if (codec_context_->channels !=
490 ChannelLayoutToChannelCount(config_.channel_layout())) { 490 ChannelLayoutToChannelCount(config_.channel_layout())) {
491 DLOG(ERROR) << "Audio configuration specified " 491 DLOG(ERROR) << "Audio configuration specified "
492 << ChannelLayoutToChannelCount(config_.channel_layout()) 492 << ChannelLayoutToChannelCount(config_.channel_layout())
493 << " channels, but FFmpeg thinks the file contains " 493 << " channels, but FFmpeg thinks the file contains "
494 << codec_context_->channels << " channels"; 494 << codec_context_->channels << " channels";
495 ReleaseFFmpegResources(); 495 ReleaseFFmpegResources();
496 state_ = kUninitialized; 496 state_ = kUninitialized;
497 return false; 497 return false;
498 } 498 }
499
500 output_frames_to_drop_ = config_.codec_delay();
499 return true; 501 return true;
500 } 502 }
501 503
502 void FFmpegAudioDecoder::ResetTimestampState() { 504 void FFmpegAudioDecoder::ResetTimestampState() {
503 output_timestamp_helper_->SetBaseTimestamp(kNoTimestamp()); 505 output_timestamp_helper_->SetBaseTimestamp(kNoTimestamp());
504 last_input_timestamp_ = kNoTimestamp(); 506 last_input_timestamp_ = kNoTimestamp();
505 output_frames_to_drop_ = 0; 507 output_frames_to_drop_ = 0;
506 } 508 }
507 509
508 } // namespace media 510 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698