Index: media/filters/ffmpeg_audio_decoder.cc |
diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc |
index cb3f846078329514071f4791569be5aa59b7b128..2cbcb4509b474eca69c7cf59fcd5f8768241fc1d 100644 |
--- a/media/filters/ffmpeg_audio_decoder.cc |
+++ b/media/filters/ffmpeg_audio_decoder.cc |
@@ -8,7 +8,6 @@ |
#include "media/base/data_buffer.h" |
#include "media/base/demuxer.h" |
#include "media/base/filter_host.h" |
-#include "media/base/limits.h" |
#include "media/ffmpeg/ffmpeg_common.h" |
namespace media { |
@@ -58,6 +57,14 @@ FFmpegAudioDecoder::FFmpegAudioDecoder(MessageLoop* message_loop) |
FFmpegAudioDecoder::~FFmpegAudioDecoder() { |
av_free(decoded_audio_); |
+ |
+ // XXX: should we require Stop() to be called? this might end up getting |
+ // called on a random thread due to refcounting. |
+ if (codec_context_) { |
+ av_free(codec_context_->extradata); |
+ avcodec_close(codec_context_); |
+ av_free(codec_context_); |
+ } |
} |
void FFmpegAudioDecoder::Flush(FilterCallback* callback) { |
@@ -105,48 +112,39 @@ void FFmpegAudioDecoder::DoInitialize( |
scoped_ptr<FilterCallback> c(callback); |
demuxer_stream_ = stream; |
- AVStream* av_stream = demuxer_stream_->GetAVStream(); |
- CHECK(av_stream); |
- |
+ const AudioDecoderConfig& config = stream->audio_decoder_config(); |
stats_callback_.reset(stats_callback); |
- // Grab the AVStream's codec context and make sure we have sensible values. |
- codec_context_ = av_stream->codec; |
- int bps = av_get_bits_per_sample_fmt(codec_context_->sample_fmt); |
- if (codec_context_->channels <= 0 || |
- codec_context_->channels > Limits::kMaxChannels || |
- (codec_context_->channel_layout == 0 && codec_context_->channels > 2) || |
- bps <= 0 || bps > Limits::kMaxBitsPerSample || |
- codec_context_->sample_rate <= 0 || |
- codec_context_->sample_rate > Limits::kMaxSampleRate) { |
+ if (!config.IsValidConfig()) { |
Ami GONE FROM CHROMIUM
2011/09/20 20:34:50
This is better, but my point was that it would be
scherkus (not reviewing)
2011/09/21 18:19:16
You're right in that the correct place for this ch
|
DLOG(ERROR) << "Invalid audio stream -" |
- << " channels: " << codec_context_->channels |
- << " channel layout:" << codec_context_->channel_layout |
- << " bps: " << bps |
- << " sample rate: " << codec_context_->sample_rate; |
+ << " codec: " << config.codec() |
+ << " channel layout: " << config.channel_layout() |
+ << " bits per channel: " << config.bits_per_channel() |
+ << " sample rate: " << config.sample_rate(); |
- host()->SetError(PIPELINE_ERROR_DECODE); |
+ host()->SetError(DECODER_ERROR_NOT_SUPPORTED); |
callback->Run(); |
return; |
} |
- // Serialize calls to avcodec_open(). |
+ // Initialize AVCodecContext structure. |
+ codec_context_ = avcodec_alloc_context(); |
+ AudioDecoderConfigToAVCodecContext(config, codec_context_); |
+ |
AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); |
if (!codec || avcodec_open(codec_context_, codec) < 0) { |
DLOG(ERROR) << "Could not initialize audio decoder: " |
<< codec_context_->codec_id; |
- host()->SetError(PIPELINE_ERROR_DECODE); |
+ host()->SetError(DECODER_ERROR_NOT_SUPPORTED); |
callback->Run(); |
return; |
} |
// Success! |
- bits_per_channel_ = av_get_bits_per_sample_fmt(codec_context_->sample_fmt); |
- channel_layout_ = |
- ChannelLayoutToChromeChannelLayout(codec_context_->channel_layout, |
- codec_context_->channels); |
- sample_rate_ = codec_context_->sample_rate; |
+ bits_per_channel_ = config.bits_per_channel(); |
+ channel_layout_ = config.channel_layout(); |
+ sample_rate_ = config.sample_rate(); |
callback->Run(); |
} |