40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
#include "Resampler.h"
|
|
#include "ffcpp.h"
|
|
#include <stdexcept>
|
|
|
|
extern "C" {
|
|
#include <libavutil/opt.h>
|
|
}
|
|
|
|
namespace ffcpp {
|
|
|
|
Resampler::Resampler(int inChannelLayout, int inSampleRate, AVSampleFormat inSampleFormat, int outChannelLayout,
|
|
int outSampleRate, AVSampleFormat outSampleFormat) {
|
|
_swrContext = swr_alloc();
|
|
if(!_swrContext) {
|
|
throw new std::runtime_error("cannot create resampler");
|
|
}
|
|
|
|
av_opt_set_int(_swrContext, "in_channel_layout", inChannelLayout, 0);
|
|
av_opt_set_int(_swrContext, "in_sample_rate", inSampleRate, 0);
|
|
av_opt_set_sample_fmt(_swrContext, "in_sample_fmt", inSampleFormat, 0);
|
|
|
|
av_opt_set_int(_swrContext, "out_channel_layout", outChannelLayout, 0);
|
|
av_opt_set_int(_swrContext, "out_sample_rate", outSampleRate, 0);
|
|
av_opt_set_sample_fmt(_swrContext, "out_sample_fmt", outSampleFormat, 0);
|
|
|
|
int res = swr_init(_swrContext);
|
|
throwIfError(res, "cannot init resampler");
|
|
}
|
|
|
|
Resampler::~Resampler() {
|
|
if(_swrContext) {
|
|
swr_free(&_swrContext);
|
|
}
|
|
}
|
|
|
|
Frame Resampler::Resample(Frame& inFrame) {
|
|
return Frame();
|
|
}
|
|
}
|