mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-24 07:39:45 +00:00
Test version with debug statements. Also moved some common code out to a separate file.
This commit is contained in:
parent
48a36442c6
commit
ce3077c970
4 changed files with 119 additions and 98 deletions
|
@ -53,7 +53,7 @@ add_openmw_dir (mwscript
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwsound
|
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
|
add_openmw_dir (mwworld
|
||||||
|
|
|
@ -60,58 +60,14 @@ extern "C"
|
||||||
#ifdef HAVE_LIBSWRESAMPLE
|
#ifdef HAVE_LIBSWRESAMPLE
|
||||||
#include <libswresample/swresample.h>
|
#include <libswresample/swresample.h>
|
||||||
#else
|
#else
|
||||||
|
/* FIXME: remove this section once libswresample is available on all platforms */
|
||||||
#include <libavresample/avresample.h>
|
#include <libavresample/avresample.h>
|
||||||
#include <libavutil/opt.h>
|
#include <libavutil/opt.h>
|
||||||
/* 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
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,57 +5,15 @@
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
#ifndef HAVE_LIBSWRESAMPLE
|
#ifndef HAVE_LIBSWRESAMPLE
|
||||||
/* FIXME: remove this section once libswresample is available on all platforms */
|
/* FIXME: remove this section once libswresample is available on all platforms */
|
||||||
|
int swr_init(AVAudioResampleContext *avr);
|
||||||
int swr_convert(
|
void swr_free(AVAudioResampleContext **avr);
|
||||||
AVAudioResampleContext *avr,
|
int swr_convert( AVAudioResampleContext *avr, uint8_t** output, int out_samples, const uint8_t** input, int in_samples);
|
||||||
uint8_t** output,
|
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);
|
||||||
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; }
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWSound
|
namespace MWSound
|
||||||
{
|
{
|
||||||
|
@ -398,6 +356,12 @@ void FFmpeg_Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType *
|
||||||
fail(std::string("Couldn't allocate SwrContext"));
|
fail(std::string("Couldn't allocate SwrContext"));
|
||||||
if(swr_init(mSwr) < 0)
|
if(swr_init(mSwr) < 0)
|
||||||
fail(std::string("Couldn't initialize SwrContext"));
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
101
apps/openmw/mwsound/libavwrapper.cpp
Normal file
101
apps/openmw/mwsound/libavwrapper.cpp
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
#ifndef HAVE_LIBSWRESAMPLE
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# include <stdint.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <libavresample/avresample.h>
|
||||||
|
#include <libavutil/opt.h>
|
||||||
|
|
||||||
|
/* 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
|
Loading…
Reference in a new issue