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 + }