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
"
This commit is contained in:
Robert Osfield
2011-09-14 09:49:28 +00:00
parent c1af863f78
commit 0f30c08701
2 changed files with 31 additions and 1 deletions

View File

@@ -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)