From 0f30c08701b2da05d56a2d039721788b3aa5bb7b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 14 Sep 2011 09:49:28 +0000 Subject: [PATCH] From Laurens Voerman, "attached is a zipped OpenSceneGraph\src\osgPlugins\ffmpeg\FFmpegDecoderAudio.cpp It solves a wrong sample format being set for audiostreams type S32 and F32, for the enum AVSampleFormat (in include/avutil/samplefmt.h) doesn't match enum SampleFormat (in include/osg/AudioStream) for anything but SAMPLE_FORMAT_U8 and SAMPLE_FORMAT_S16 " and follow up that address versioning issue "I can find the change, avutil version 50.38.0 introduced a new header file: libavutil/samplefmt.h older versions use libavcodec/avcodec.h with the sampleformats without AV_ an intermideate fix with the FF_API_OLD_SAMPLE_FMT is removed from ffmpeg 0.8.3 so I think this is the correct fix: #if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(50,38,0) #define AV_SAMPLE_FMT_NONE SAMPLE_FMT_NONE #define AV_SAMPLE_FMT_U8 SAMPLE_FMT_U8 #define AV_SAMPLE_FMT_S16 SAMPLE_FMT_S16 #define AV_SAMPLE_FMT_S32 SAMPLE_FMT_S32 #define AV_SAMPLE_FMT_FLT SAMPLE_FMT_FLT #define AV_SAMPLE_FMT_DBL SAMPLE_FMT_DBL #define AV_SAMPLE_FMT_NB SAMPLE_FMT_NB #endif " --- src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp | 22 +++++++++++++++++++- src/osgPlugins/ffmpeg/FFmpegHeaders.hpp | 10 +++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp b/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp index f7020fb8f..a4c0e2586 100644 --- a/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp +++ b/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp @@ -72,7 +72,27 @@ void FFmpegDecoderAudio::open(AVStream * const stream) m_frequency = m_context->sample_rate; m_nb_channels = m_context->channels; - m_sample_format = osg::AudioStream::SampleFormat(m_context->sample_fmt); + switch (m_context->sample_fmt) + { + case AV_SAMPLE_FMT_NONE: + throw std::runtime_error("invalid audio format AV_SAMPLE_FMT_NONE"); + case AV_SAMPLE_FMT_U8: + m_sample_format = osg::AudioStream::SAMPLE_FORMAT_U8; + break; + case AV_SAMPLE_FMT_S16: + m_sample_format = osg::AudioStream::SAMPLE_FORMAT_S16; + break; + case AV_SAMPLE_FMT_S32: + m_sample_format = osg::AudioStream::SAMPLE_FORMAT_S32; + break; + case AV_SAMPLE_FMT_FLT: + m_sample_format = osg::AudioStream::SAMPLE_FORMAT_F32; + break; + case AV_SAMPLE_FMT_DBL: + throw std::runtime_error("unhandled audio format AV_SAMPLE_FMT_DBL"); + default: + throw std::runtime_error("unknown audio format"); + } // Check stream sanity if (m_context->codec_id == CODEC_ID_NONE) diff --git a/src/osgPlugins/ffmpeg/FFmpegHeaders.hpp b/src/osgPlugins/ffmpeg/FFmpegHeaders.hpp index 2050ad12e..3cb2a0f67 100644 --- a/src/osgPlugins/ffmpeg/FFmpegHeaders.hpp +++ b/src/osgPlugins/ffmpeg/FFmpegHeaders.hpp @@ -17,6 +17,16 @@ extern "C" #include #endif +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(50,38,0) +#define AV_SAMPLE_FMT_NONE SAMPLE_FMT_NONE +#define AV_SAMPLE_FMT_U8 SAMPLE_FMT_U8 +#define AV_SAMPLE_FMT_S16 SAMPLE_FMT_S16 +#define AV_SAMPLE_FMT_S32 SAMPLE_FMT_S32 +#define AV_SAMPLE_FMT_FLT SAMPLE_FMT_FLT +#define AV_SAMPLE_FMT_DBL SAMPLE_FMT_DBL +#define AV_SAMPLE_FMT_NB SAMPLE_FMT_NB +#endif + }