summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 18:17:11 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 18:17:11 +0000
commit045e9351159d84a721016c3fc570f9de7d546895 (patch)
treecb10736f06aa7f022d5b8b42cf22ad207ea1a6cd /media
parentabe3ad93b1996ad1b1aff121dbce6be533e579c3 (diff)
downloadchromium_src-045e9351159d84a721016c3fc570f9de7d546895.zip
chromium_src-045e9351159d84a721016c3fc570f9de7d546895.tar.gz
chromium_src-045e9351159d84a721016c3fc570f9de7d546895.tar.bz2
Fixing bug that 8bit PCM stream is gabbled
The CodecContext passed into FFmpegAudioDecoder by the FFmpegDemuxer says the output samples are 16bits. So we tell the audio renderer to create a 16bits audio output stream. But after the decoder is allocated by avcodec_find_codec, the sample bits information in |codec_context_| is changed to 8bit! So we are feeding 16bits output stream with 8bits data. The decoder should knows more about the actual output format. So query the sample bits information after the decoder is allocated. Review URL: http://codereview.chromium.org/125027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18406 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/filters/ffmpeg_audio_decoder.cc18
1 files changed, 10 insertions, 8 deletions
diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc
index 78e764e..0b27519 100644
--- a/media/filters/ffmpeg_audio_decoder.cc
+++ b/media/filters/ffmpeg_audio_decoder.cc
@@ -42,7 +42,16 @@ bool FFmpegAudioDecoder::OnInitialize(DemuxerStream* demuxer_stream) {
DCHECK_GT(av_get_bits_per_sample_format(codec_context_->sample_fmt), 0);
DCHECK_GT(codec_context_->sample_rate, 0);
- // Set the media format.
+ // Grab the codec context from FFmpeg demuxer.
+ AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id);
+ if (!codec || avcodec_open(codec_context_, codec) < 0) {
+ host_->Error(PIPELINE_ERROR_DECODE);
+ return false;
+ }
+
+ // When calling avcodec_find_decoder(), |codec_context_| might be altered by
+ // the decoder to give more accurate values of the output format of the
+ // decoder. So set the media format after a decoder is allocated.
// TODO(hclam): Reuse the information provided by the demuxer for now, we may
// need to wait until the first buffer is decoded to know the correct
// information.
@@ -54,13 +63,6 @@ bool FFmpegAudioDecoder::OnInitialize(DemuxerStream* demuxer_stream) {
media_format_.SetAsString(MediaFormat::kMimeType,
mime_type::kUncompressedAudio);
- // Grab the codec context from FFmpeg demuxer.
- AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id);
- if (!codec || avcodec_open(codec_context_, codec) < 0) {
- host_->Error(PIPELINE_ERROR_DECODE);
- return false;
- }
-
// Prepare the output buffer.
output_buffer_.reset(static_cast<uint8*>(av_malloc(kOutputBufferSize)));
if (!output_buffer_.get()) {