From 11071563347d5d68ccf3ef52ef61de643939fee2 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Fri, 12 Sep 2014 21:18:54 +1000 Subject: [PATCH] Workaround incorrectly reported channel_layout --- apps/openmw/mwrender/videoplayer.cpp | 26 +++++++++++++-------- apps/openmw/mwsound/ffmpeg_decoder.cpp | 31 ++++++++++++++------------ 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/apps/openmw/mwrender/videoplayer.cpp b/apps/openmw/mwrender/videoplayer.cpp index 731735c25c..5ab504f481 100644 --- a/apps/openmw/mwrender/videoplayer.cpp +++ b/apps/openmw/mwrender/videoplayer.cpp @@ -488,6 +488,8 @@ public: fail(std::string("Unsupported sample format: ")+ av_get_sample_fmt_name(mAVStream->codec->sample_fmt)); + int64_t ch_layout = mAVStream->codec->channel_layout; + if(mAVStream->codec->channel_layout == AV_CH_LAYOUT_MONO) *chans = MWSound::ChannelConfig_Mono; else if(mAVStream->codec->channel_layout == AV_CH_LAYOUT_STEREO) @@ -502,9 +504,15 @@ public: { /* Unknown channel layout. Try to guess. */ if(mAVStream->codec->channels == 1) + { *chans = MWSound::ChannelConfig_Mono; + ch_layout = AV_CH_LAYOUT_MONO; + } else if(mAVStream->codec->channels == 2) + { *chans = MWSound::ChannelConfig_Stereo; + ch_layout = AV_CH_LAYOUT_STEREO; + } else { std::stringstream sstr("Unsupported raw channel count: "); @@ -531,15 +539,15 @@ public: if(mOutputSampleFormat != AV_SAMPLE_FMT_NONE) { - mSwr = swr_alloc_set_opts(mSwr, // SwrContext - mAVStream->codec->channel_layout, // output ch layout - mOutputSampleFormat, // output sample format - mAVStream->codec->sample_rate, // output sample rate - mAVStream->codec->channel_layout, // input ch layout - mAVStream->codec->sample_fmt, // input sample format - mAVStream->codec->sample_rate, // input sample rate - 0, // logging level offset - NULL); // log context + mSwr = swr_alloc_set_opts(mSwr, // SwrContext + ch_layout, // output ch layout + mOutputSampleFormat, // output sample format + mAVStream->codec->sample_rate, // output sample rate + ch_layout, // input ch layout + mAVStream->codec->sample_fmt, // input sample format + mAVStream->codec->sample_rate, // input sample rate + 0, // logging level offset + NULL); // log context if(!mSwr) fail(std::string("Couldn't allocate SwrContext")); if(swr_init(mSwr) < 0) diff --git a/apps/openmw/mwsound/ffmpeg_decoder.cpp b/apps/openmw/mwsound/ffmpeg_decoder.cpp index 5fca4b5b40..7b6e125763 100644 --- a/apps/openmw/mwsound/ffmpeg_decoder.cpp +++ b/apps/openmw/mwsound/ffmpeg_decoder.cpp @@ -300,6 +300,8 @@ void FFmpeg_Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType * fail(std::string("Unsupported sample format: ")+ av_get_sample_fmt_name((*mStream)->codec->sample_fmt)); + int64_t ch_layout = (*mStream)->codec->channel_layout; + if((*mStream)->codec->channel_layout == AV_CH_LAYOUT_MONO) *chans = ChannelConfig_Mono; else if((*mStream)->codec->channel_layout == AV_CH_LAYOUT_STEREO) @@ -314,9 +316,15 @@ void FFmpeg_Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType * { /* Unknown channel layout. Try to guess. */ if((*mStream)->codec->channels == 1) + { *chans = ChannelConfig_Mono; + ch_layout = AV_CH_LAYOUT_MONO; + } else if((*mStream)->codec->channels == 2) + { *chans = ChannelConfig_Stereo; + ch_layout = AV_CH_LAYOUT_STEREO; + } else { std::stringstream sstr("Unsupported raw channel count: "); @@ -343,20 +351,15 @@ void FFmpeg_Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType * if(mOutputSampleFormat != AV_SAMPLE_FMT_NONE) { -// FIXME: debug output -//#if 0 - printf("channel_layout: %d\n",(int)(*mStream)->codec->channel_layout); - printf("in_channels: %d\n",(*mStream)->codec->channels); -//#endif - mSwr = swr_alloc_set_opts(mSwr, // SwrContext - (*mStream)->codec->channel_layout, // output ch layout - mOutputSampleFormat, // output sample format - (*mStream)->codec->sample_rate, // output sample rate - (*mStream)->codec->channel_layout, // input ch layout - (*mStream)->codec->sample_fmt, // input sample format - (*mStream)->codec->sample_rate, // input sample rate - 0, // logging level offset - NULL); // log context + mSwr = swr_alloc_set_opts(mSwr, // SwrContext + ch_layout, // output ch layout + mOutputSampleFormat, // output sample format + (*mStream)->codec->sample_rate, // output sample rate + ch_layout, // input ch layout + (*mStream)->codec->sample_fmt, // input sample format + (*mStream)->codec->sample_rate, // input sample rate + 0, // logging level offset + NULL); // log context if(!mSwr) fail(std::string("Couldn't allocate SwrContext")); if(swr_init(mSwr) < 0)