summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-03 20:55:30 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-03 20:55:30 +0000
commit1f91f484c9e6b8347a13f224d19ae49401e5862f (patch)
treeddc0e38662784a6a0ab42520a635ef5b6a3013fc
parent933a23d23270bba7b6a3a26c2424b299386b548e (diff)
downloadchromium_src-1f91f484c9e6b8347a13f224d19ae49401e5862f.zip
chromium_src-1f91f484c9e6b8347a13f224d19ae49401e5862f.tar.gz
chromium_src-1f91f484c9e6b8347a13f224d19ae49401e5862f.tar.bz2
Fixing misuse of FFmpeg in decoders
AVCodec was not opened properly, leading to crash. Fixed in this patch. Review URL: http://codereview.chromium.org/56203 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13108 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--media/filters/ffmpeg_audio_decoder.cc18
-rw-r--r--media/filters/ffmpeg_video_decoder.cc6
2 files changed, 17 insertions, 7 deletions
diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc
index 54ff1cc..714d0a9 100644
--- a/media/filters/ffmpeg_audio_decoder.cc
+++ b/media/filters/ffmpeg_audio_decoder.cc
@@ -47,17 +47,21 @@ bool FFmpegAudioDecoder::OnInitialize(DemuxerStream* demuxer_stream) {
// 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.
- media_format_.SetAsInteger(MediaFormat::kChannels,
- ffmpeg_demuxer_stream->av_stream()->codec->channels);
+ codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec;
+ media_format_.SetAsInteger(MediaFormat::kChannels, codec_context_->channels);
media_format_.SetAsInteger(MediaFormat::kSampleBits,
- ffmpeg_demuxer_stream->av_stream()->codec->bits_per_raw_sample);
+ codec_context_->bits_per_coded_sample);
media_format_.SetAsInteger(MediaFormat::kSampleRate,
- ffmpeg_demuxer_stream->av_stream()->codec->sample_rate);
+ codec_context_->sample_rate);
media_format_.SetAsString(MediaFormat::kMimeType,
mime_type::kUncompressedAudio);
- // Grab the codec context from ffmpeg demuxer.
- codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec;
+ // 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_ = static_cast<uint8*>(av_malloc(kOutputBufferSize));
@@ -93,6 +97,8 @@ void FFmpegAudioDecoder::OnDecode(Buffer* input) {
DataBuffer* result_buffer = new DataBuffer();
memcpy(result_buffer->GetWritableData(output_buffer_size),
output_buffer_, output_buffer_size);
+ result_buffer->SetTimestamp(input->GetTimestamp());
+ result_buffer->SetDuration(input->GetDuration());
EnqueueResult(result_buffer);
}
}
diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc
index 69111ff..f5d87bc 100644
--- a/media/filters/ffmpeg_video_decoder.cc
+++ b/media/filters/ffmpeg_video_decoder.cc
@@ -43,7 +43,11 @@ bool FFmpegVideoDecoder::OnInitialize(DemuxerStream* demuxer_stream) {
media_format_.SetAsInteger(MediaFormat::kHeight, height_);
codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec;
-
+ AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id);
+ if (!codec || avcodec_open(codec_context_, codec) < 0) {
+ host_->Error(media::PIPELINE_ERROR_DECODE);
+ return false;
+ }
return true;
}