| 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/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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 const scoped_refptr<MediaLog>& media_log) | 129 const scoped_refptr<MediaLog>& media_log) |
| 130 : task_runner_(task_runner), | 130 : task_runner_(task_runner), |
| 131 state_(kUninitialized), | 131 state_(kUninitialized), |
| 132 av_sample_format_(0), | 132 av_sample_format_(0), |
| 133 media_log_(media_log) { | 133 media_log_(media_log) { |
| 134 } | 134 } |
| 135 | 135 |
| 136 FFmpegAudioDecoder::~FFmpegAudioDecoder() { | 136 FFmpegAudioDecoder::~FFmpegAudioDecoder() { |
| 137 DCHECK(task_runner_->BelongsToCurrentThread()); | 137 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 138 | 138 |
| 139 if (state_ != kUninitialized) { | 139 if (state_ != kUninitialized) |
| 140 ReleaseFFmpegResources(); | 140 ReleaseFFmpegResources(); |
| 141 ResetTimestampState(); | |
| 142 } | |
| 143 } | 141 } |
| 144 | 142 |
| 145 std::string FFmpegAudioDecoder::GetDisplayName() const { | 143 std::string FFmpegAudioDecoder::GetDisplayName() const { |
| 146 return "FFmpegAudioDecoder"; | 144 return "FFmpegAudioDecoder"; |
| 147 } | 145 } |
| 148 | 146 |
| 149 void FFmpegAudioDecoder::Initialize(const AudioDecoderConfig& config, | 147 void FFmpegAudioDecoder::Initialize(const AudioDecoderConfig& config, |
| 150 const InitCB& init_cb, | 148 const InitCB& init_cb, |
| 151 const OutputCB& output_cb) { | 149 const OutputCB& output_cb) { |
| 152 DCHECK(task_runner_->BelongsToCurrentThread()); | 150 DCHECK(task_runner_->BelongsToCurrentThread()); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { | 362 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { |
| 365 DLOG(ERROR) << "Could not initialize audio decoder: " | 363 DLOG(ERROR) << "Could not initialize audio decoder: " |
| 366 << codec_context_->codec_id; | 364 << codec_context_->codec_id; |
| 367 ReleaseFFmpegResources(); | 365 ReleaseFFmpegResources(); |
| 368 state_ = kUninitialized; | 366 state_ = kUninitialized; |
| 369 return false; | 367 return false; |
| 370 } | 368 } |
| 371 | 369 |
| 372 // Success! | 370 // Success! |
| 373 av_frame_.reset(av_frame_alloc()); | 371 av_frame_.reset(av_frame_alloc()); |
| 374 discard_helper_.reset(new AudioDiscardHelper(config_.samples_per_second(), | |
| 375 config_.codec_delay())); | |
| 376 av_sample_format_ = codec_context_->sample_fmt; | 372 av_sample_format_ = codec_context_->sample_fmt; |
| 377 | 373 |
| 378 if (codec_context_->channels != | 374 if (codec_context_->channels != |
| 379 ChannelLayoutToChannelCount(config_.channel_layout())) { | 375 ChannelLayoutToChannelCount(config_.channel_layout())) { |
| 380 DLOG(ERROR) << "Audio configuration specified " | 376 DLOG(ERROR) << "Audio configuration specified " |
| 381 << ChannelLayoutToChannelCount(config_.channel_layout()) | 377 << ChannelLayoutToChannelCount(config_.channel_layout()) |
| 382 << " channels, but FFmpeg thinks the file contains " | 378 << " channels, but FFmpeg thinks the file contains " |
| 383 << codec_context_->channels << " channels"; | 379 << codec_context_->channels << " channels"; |
| 384 ReleaseFFmpegResources(); | 380 ReleaseFFmpegResources(); |
| 385 state_ = kUninitialized; | 381 state_ = kUninitialized; |
| 386 return false; | 382 return false; |
| 387 } | 383 } |
| 388 | 384 |
| 389 ResetTimestampState(); | 385 ResetTimestampState(); |
| 390 return true; | 386 return true; |
| 391 } | 387 } |
| 392 | 388 |
| 393 void FFmpegAudioDecoder::ResetTimestampState() { | 389 void FFmpegAudioDecoder::ResetTimestampState() { |
| 390 discard_helper_.reset(new AudioDiscardHelper(config_.samples_per_second(), |
| 391 config_.codec_delay())); |
| 394 discard_helper_->Reset(config_.codec_delay()); | 392 discard_helper_->Reset(config_.codec_delay()); |
| 395 } | 393 } |
| 396 | 394 |
| 397 } // namespace media | 395 } // namespace media |
| OLD | NEW |