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

Unified Diff: media/filters/ffmpeg_audio_decoder.cc

Issue 7867051: Introduce AudioDecoderConfig to migrate away from GetAVStream(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: forgot files Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: media/filters/ffmpeg_audio_decoder.cc
diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc
index bbac958043379519f3c6642a691e20dbd9d47c60..f3869fef205bb13fc2f6cfed670e06c8e1ae2c56 100644
--- a/media/filters/ffmpeg_audio_decoder.cc
+++ b/media/filters/ffmpeg_audio_decoder.cc
@@ -56,7 +56,15 @@ FFmpegAudioDecoder::FFmpegAudioDecoder(MessageLoop* message_loop)
pending_reads_(0) {
}
-FFmpegAudioDecoder::~FFmpegAudioDecoder() {}
+FFmpegAudioDecoder::~FFmpegAudioDecoder() {
+ // 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) {
message_loop_->PostTask(
@@ -102,32 +110,32 @@ void FFmpegAudioDecoder::DoInitialize(
scoped_ptr<FilterCallback> c(callback);
demuxer_stream_ = stream;
- AVStream* av_stream = demuxer_stream_->GetAVStream();
- CHECK(av_stream);
-
+ AudioDecoderConfig* config = stream->audio_decoder_config();
Ami GONE FROM CHROMIUM 2011/09/12 20:54:21 Hopefully this can be a const& or at least a const
scherkus (not reviewing) 2011/09/19 21:19:45 Done.
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) {
+ // Sanity checking.
Ami GONE FROM CHROMIUM 2011/09/12 20:54:21 Shouldn't this be happening earlier (ideally durin
scherkus (not reviewing) 2011/09/19 21:19:45 I'm torn.. on one hand you could argue that said l
+ if (config->codec() == kUnknownAudioCodec ||
+ config->channel_layout() == CHANNEL_LAYOUT_UNSUPPORTED ||
+ config->bits_per_channel() <= 0 ||
+ config->bits_per_channel() > Limits::kMaxBitsPerSample ||
+ config->sample_rate() <= 0 ||
+ config->sample_rate() > Limits::kMaxSampleRate) {
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();
+ // XXX: format error?
host()->SetError(PIPELINE_ERROR_DECODE);
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: "
@@ -139,11 +147,9 @@ void FFmpegAudioDecoder::DoInitialize(
}
// 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();
}

Powered by Google App Engine
This is Rietveld 408576698