From ce3077c970bdf01d45985e17cff9d759c88b9aed Mon Sep 17 00:00:00 2001 From: cc9cii Date: Fri, 12 Sep 2014 08:27:25 +1000 Subject: [PATCH] Test version with debug statements. Also moved some common code out to a separate file. --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwrender/videoplayer.cpp | 54 ++----------- apps/openmw/mwsound/ffmpeg_decoder.cpp | 60 +++------------ apps/openmw/mwsound/libavwrapper.cpp | 101 +++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 98 deletions(-) create mode 100644 apps/openmw/mwsound/libavwrapper.cpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index babde8ff2..33433e203 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -53,7 +53,7 @@ add_openmw_dir (mwscript ) add_openmw_dir (mwsound - soundmanagerimp openal_output ffmpeg_decoder sound sound_decoder sound_output loudness + soundmanagerimp openal_output ffmpeg_decoder sound sound_decoder sound_output loudness libavwrapper ) add_openmw_dir (mwworld diff --git a/apps/openmw/mwrender/videoplayer.cpp b/apps/openmw/mwrender/videoplayer.cpp index 21a0cc832..731735c25 100644 --- a/apps/openmw/mwrender/videoplayer.cpp +++ b/apps/openmw/mwrender/videoplayer.cpp @@ -60,58 +60,14 @@ extern "C" #ifdef HAVE_LIBSWRESAMPLE #include #else + /* FIXME: remove this section once libswresample is available on all platforms */ #include #include - /* FIXME: remove this section once libswresample is available on all platforms */ - - int swr_convert( - AVAudioResampleContext *avr, - uint8_t** output, - int out_samples, - const uint8_t** input, - int in_samples) - { - // FIXME: potential performance hit - int out_plane_size = 0; - int in_plane_size = 0; - return avresample_convert(avr, output, out_plane_size, out_samples, - (uint8_t **)input, in_plane_size, in_samples); - } - - AVAudioResampleContext * swr_alloc_set_opts( - AVAudioResampleContext *avr, - int64_t out_ch_layout, - AVSampleFormat out_fmt, - int out_rate, - int64_t in_ch_layout, - AVSampleFormat in_fmt, - int in_rate, - int o, - void* l) - { - avr = avresample_alloc_context(); - if(!avr) - return 0; - - if ((av_opt_set_int(avr, "out_channel_layout", out_ch_layout, 0) < 0) || - (av_opt_set_int(avr, "out_sample_fmt", out_fmt, 0) < 0) || - (av_opt_set_int(avr, "out_sample_rate", out_rate, 0) < 0) || - (av_opt_set_int(avr, "in_channel_layout", in_ch_layout, 0) < 0) || - (av_opt_set_int(avr, "in_sample_fmt", in_fmt, 0) < 0) || - (av_opt_set_int(avr, "in_sample_rate", in_rate, 0) < 0)) - { - return 0; - } - - if(avresample_open(avr) < 0) - return 0; - else - return avr; - } - - void swr_free(AVAudioResampleContext **avr) { avresample_free(avr); } - int swr_init(AVAudioResampleContext *avr) { return 1; } #define SwrContext AVAudioResampleContext + int swr_init(AVAudioResampleContext *avr); + void swr_free(AVAudioResampleContext **avr); + int swr_convert( AVAudioResampleContext *avr, uint8_t** output, int out_samples, const uint8_t** input, int in_samples); + AVAudioResampleContext * swr_alloc_set_opts( AVAudioResampleContext *avr, int64_t out_ch_layout, AVSampleFormat out_fmt, int out_rate, int64_t in_ch_layout, AVSampleFormat in_fmt, int in_rate, int o, void* l); #endif } diff --git a/apps/openmw/mwsound/ffmpeg_decoder.cpp b/apps/openmw/mwsound/ffmpeg_decoder.cpp index a2652ba13..95c4e9c5c 100644 --- a/apps/openmw/mwsound/ffmpeg_decoder.cpp +++ b/apps/openmw/mwsound/ffmpeg_decoder.cpp @@ -5,57 +5,15 @@ #include +extern "C" { #ifndef HAVE_LIBSWRESAMPLE /* FIXME: remove this section once libswresample is available on all platforms */ - -int swr_convert( - AVAudioResampleContext *avr, - uint8_t** output, - int out_samples, - const uint8_t** input, - int in_samples) -{ - // FIXME: potential performance hit - int out_plane_size = 0; - int in_plane_size = 0; - return avresample_convert(avr, output, out_plane_size, out_samples, - (uint8_t **)input, in_plane_size, in_samples); -} - -AVAudioResampleContext * swr_alloc_set_opts( - AVAudioResampleContext *avr, - int64_t out_ch_layout, - AVSampleFormat out_fmt, - int out_rate, - int64_t in_ch_layout, - AVSampleFormat in_fmt, - int in_rate, - int o, - void* l) -{ - avr = avresample_alloc_context(); - if(!avr) - return 0; - - if ((av_opt_set_int(avr, "out_channel_layout", out_ch_layout, 0) < 0) || - (av_opt_set_int(avr, "out_sample_fmt", out_fmt, 0) < 0) || - (av_opt_set_int(avr, "out_sample_rate", out_rate, 0) < 0) || - (av_opt_set_int(avr, "in_channel_layout", in_ch_layout, 0) < 0) || - (av_opt_set_int(avr, "in_sample_fmt", in_fmt, 0) < 0) || - (av_opt_set_int(avr, "in_sample_rate", in_rate, 0) < 0)) - { - return 0; - } - - if(avresample_open(avr) < 0) - return 0; - else - return avr; -} - -void swr_free(AVAudioResampleContext **avr) { avresample_free(avr); } -int swr_init(AVAudioResampleContext *avr) { return 1; } +int swr_init(AVAudioResampleContext *avr); +void swr_free(AVAudioResampleContext **avr); +int swr_convert( AVAudioResampleContext *avr, uint8_t** output, int out_samples, const uint8_t** input, int in_samples); +AVAudioResampleContext * swr_alloc_set_opts( AVAudioResampleContext *avr, int64_t out_ch_layout, AVSampleFormat out_fmt, int out_rate, int64_t in_ch_layout, AVSampleFormat in_fmt, int in_rate, int o, void* l); #endif +} namespace MWSound { @@ -398,6 +356,12 @@ void FFmpeg_Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType * fail(std::string("Couldn't allocate SwrContext")); if(swr_init(mSwr) < 0) fail(std::string("Couldn't initialize SwrContext")); + +// FIXME: debug output +//#if 0 + std::cout << "channel_layout: " + std::to_string((*mStream)->codec->channel_layout) << std::endl; + std::cout << "in_channels: " + std::to_string((*mStream)->codec->channels) << std::endl; +//#endif } } diff --git a/apps/openmw/mwsound/libavwrapper.cpp b/apps/openmw/mwsound/libavwrapper.cpp new file mode 100644 index 000000000..ebf0d7777 --- /dev/null +++ b/apps/openmw/mwsound/libavwrapper.cpp @@ -0,0 +1,101 @@ +#ifndef HAVE_LIBSWRESAMPLE +extern "C" +{ +#ifdef _MSC_VER +# include +#endif + +#include +#include + +/* FIXME: delete this file once libswresample is available on all platforms */ + +int swr_init(AVAudioResampleContext *avr) { return 1; } + +void swr_free(AVAudioResampleContext **avr) { avresample_free(avr); } + +int swr_convert( + AVAudioResampleContext *avr, + uint8_t** output, + int out_samples, + const uint8_t** input, + int in_samples) +{ + // FIXME: potential performance hit + int out_plane_size = 0; + int in_plane_size = 0; + return avresample_convert(avr, output, out_plane_size, out_samples, + (uint8_t **)input, in_plane_size, in_samples); +} + +AVAudioResampleContext * swr_alloc_set_opts( + AVAudioResampleContext *avr, + int64_t out_ch_layout, + AVSampleFormat out_fmt, + int out_rate, + int64_t in_ch_layout, + AVSampleFormat in_fmt, + int in_rate, + int o, + void* l) +{ + avr = avresample_alloc_context(); + if(!avr) + return 0; + + int res; + res = av_opt_set_int(avr, "out_channel_layout", out_ch_layout, 0); + if(res < 0) + { + av_log(avr, AV_LOG_ERROR, "av_opt_set_int: out_ch_layout = %d\n", res); + return 0; + } + res = av_opt_set_int(avr, "out_sample_fmt", out_fmt, 0); + if(res < 0) + { + av_log(avr, AV_LOG_ERROR, "av_opt_set_int: out_fmt = %d\n", res); + return 0; + } + res = av_opt_set_int(avr, "out_sample_rate", out_rate, 0); + if(res < 0) + { + av_log(avr, AV_LOG_ERROR, "av_opt_set_int: out_rate = %d\n", res); + return 0; + } + res = av_opt_set_int(avr, "in_channel_layout", in_ch_layout, 0); + if(res < 0) + { + av_log(avr, AV_LOG_ERROR, "av_opt_set_int: in_ch_layout = %d\n", res); + return 0; + } + res = av_opt_set_int(avr, "in_sample_fmt", in_fmt, 0); + if(res < 0) + { + av_log(avr, AV_LOG_ERROR, "av_opt_set_int: in_fmt = %d\n", res); + return 0; + } + res = av_opt_set_int(avr, "in_sample_rate", in_rate, 0); + if(res < 0) + { + av_log(avr, AV_LOG_ERROR, "av_opt_set_int: in_rate = %d\n", res); + return 0; + } + res = av_opt_set_int(avr, "internal_sample_fmt", AV_SAMPLE_FMT_FLTP, 0); + if(res < 0) + { + av_log(avr, AV_LOG_ERROR, "av_opt_set_int: internal_sample_fmt\n"); + return 0; + } + + + if(avresample_open(avr) < 0) + { + av_log(avr, AV_LOG_ERROR, "Error opening context\n"); + return 0; + } + else + return avr; +} + +} +#endif