From 045caf10864895d0a46cab0a694e722531da8bb0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 23 Jan 2015 17:15:20 +0000 Subject: [PATCH] From Javier Taibo, "I have found a "bug" in the new audio decoding code (actually I think the bug is in ffmpeg, but anyway it should be wise to protect the OSG plug-in about it). I am attaching a security check in FFmpegDecoderAudio.cpp. If anybody is curious about the problem, it happens sometimes when decoding an AAC audio stream. It eventually includes a PCE block inside the AAC audio frame and then ffmpeg audio decoding function signals a "new_frame" with 1024 samples, but a null pointer instead of the audio data. It can be easily detected because in these cases number of channels is 0. Maybe this is the intended behaviour for ffmpeg, but I find it quite weird. " " It seems that libav does not have a channels attribute in AVFrame structure. This new version should do." git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14676 16af8721-9629-0410-8352-f15c8da7e697 --- src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp b/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp index c4839483e..65631512f 100644 --- a/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp +++ b/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp @@ -47,7 +47,11 @@ static int decode_audio(AVCodecContext *avctx, int16_t *samples, ret = avcodec_decode_audio4(avctx, frame, &got_frame, &avpkt); +#ifdef USE_AVRESAMPLE // libav's AVFrame structure does not contain a 'channels' field if (ret >= 0 && got_frame) { +#else + if (ret >= 0 && got_frame && av_frame_get_channels(frame)>0) { +#endif int ch, plane_size; int planar = av_sample_fmt_is_planar(avctx->sample_fmt);