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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 ReleaseFFmpegResources(); | 396 ReleaseFFmpegResources(); |
397 | 397 |
398 // Initialize AVCodecContext structure. | 398 // Initialize AVCodecContext structure. |
399 codec_context_.reset(avcodec_alloc_context3(NULL)); | 399 codec_context_.reset(avcodec_alloc_context3(NULL)); |
400 AudioDecoderConfigToAVCodecContext(config_, codec_context_.get()); | 400 AudioDecoderConfigToAVCodecContext(config_, codec_context_.get()); |
401 | 401 |
402 codec_context_->opaque = this; | 402 codec_context_->opaque = this; |
403 codec_context_->get_buffer2 = GetAudioBuffer; | 403 codec_context_->get_buffer2 = GetAudioBuffer; |
404 codec_context_->refcounted_frames = 1; | 404 codec_context_->refcounted_frames = 1; |
405 | 405 |
| 406 if (config_.codec() == kCodecOpus) |
| 407 codec_context_->request_sample_fmt = AV_SAMPLE_FMT_FLT; |
| 408 |
406 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); | 409 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); |
407 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { | 410 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { |
408 DLOG(ERROR) << "Could not initialize audio decoder: " | 411 DLOG(ERROR) << "Could not initialize audio decoder: " |
409 << codec_context_->codec_id; | 412 << codec_context_->codec_id; |
410 ReleaseFFmpegResources(); | 413 ReleaseFFmpegResources(); |
411 state_ = kUninitialized; | 414 state_ = kUninitialized; |
412 return false; | 415 return false; |
413 } | 416 } |
414 | 417 |
415 // Success! | 418 // Success! |
416 av_frame_.reset(av_frame_alloc()); | 419 av_frame_.reset(av_frame_alloc()); |
417 av_sample_format_ = codec_context_->sample_fmt; | 420 av_sample_format_ = codec_context_->sample_fmt; |
418 | 421 |
419 if (codec_context_->channels != | 422 if (codec_context_->channels != |
420 ChannelLayoutToChannelCount(config_.channel_layout())) { | 423 ChannelLayoutToChannelCount(config_.channel_layout())) { |
421 DLOG(ERROR) << "Audio configuration specified " | 424 DLOG(ERROR) << "Audio configuration specified " |
422 << ChannelLayoutToChannelCount(config_.channel_layout()) | 425 << ChannelLayoutToChannelCount(config_.channel_layout()) |
423 << " channels, but FFmpeg thinks the file contains " | 426 << " channels, but FFmpeg thinks the file contains " |
424 << codec_context_->channels << " channels"; | 427 << codec_context_->channels << " channels"; |
425 ReleaseFFmpegResources(); | 428 ReleaseFFmpegResources(); |
426 state_ = kUninitialized; | 429 state_ = kUninitialized; |
427 return false; | 430 return false; |
428 } | 431 } |
429 | 432 |
430 ResetTimestampState(); | 433 ResetTimestampState(); |
431 return true; | 434 return true; |
432 } | 435 } |
433 | 436 |
434 void FFmpegAudioDecoder::ResetTimestampState() { | 437 void FFmpegAudioDecoder::ResetTimestampState() { |
435 discard_helper_.reset(new AudioDiscardHelper(config_.samples_per_second(), | 438 // Opus codec delay is handled by ffmpeg. |
436 config_.codec_delay())); | 439 const int codec_delay = |
437 discard_helper_->Reset(config_.codec_delay()); | 440 config_.codec() == kCodecOpus ? 0 : config_.codec_delay(); |
| 441 discard_helper_.reset( |
| 442 new AudioDiscardHelper(config_.samples_per_second(), codec_delay, |
| 443 config_.codec() == kCodecVorbis)); |
| 444 discard_helper_->Reset(codec_delay); |
438 } | 445 } |
439 | 446 |
440 } // namespace media | 447 } // namespace media |
OLD | NEW |