20#include <libavutil/frame.h>
21#include <libavutil/mathematics.h>
22#include <libavutil/opt.h>
27#include <libswresample/swresample.h>
48 JAMI_ERROR(
"[{}] Unable to allocate resampler context", fmt::ptr(
this));
49 throw std::bad_alloc();
57 JAMI_ERROR(
"[{}] Failed to set input channel layout {}: {}",
61 throw std::runtime_error(
"Failed to set input channel layout");
66 JAMI_ERROR(
"[{}] Failed to set input sample rate {}: {}",
70 throw std::runtime_error(
"Failed to set input sample rate");
75 JAMI_ERROR(
"[{}] Failed to set input sample format {}: {}",
79 throw std::runtime_error(
"Failed to set input sample format");
87 JAMI_ERROR(
"[{}] Failed to set output channel layout {}: {}",
91 throw std::runtime_error(
"Failed to set output channel layout");
96 JAMI_ERROR(
"[{}] Failed to set output sample rate {}: {}",
100 throw std::runtime_error(
"Failed to set output sample rate");
105 JAMI_ERROR(
"[{}] Failed to set output sample format {}: {}",
109 throw std::runtime_error(
"Failed to set output sample format");
126 if (
out->ch_layout.nb_channels == 2) {
157 throw std::runtime_error(
"Failed to set mixing matrix");
163 std::swap(swrCtx_,
swrCtx);
165 JAMI_DEBUG(
"[{}] Succesfully (re)initialized resampler context from {} to {}",
172 JAMI_ERROR(
"[{}] Runtime error: Failed to initialize resampler context: {}",
175 throw std::runtime_error(
"Failed to initialize resampler context");
191 if (initCount_ > 1) {
193 JAMI_ERROR(
"[{}] Loop detected in audio resampler when resampling from {} to {}",
197 throw std::runtime_error(
"Infinite loop detected in audio resampler");
216 JAMI_WARNING(
"[{}] Adding {} samples of silence at beginning of first frame to reach {} samples",
222 JAMI_ERROR(
"[{}] Failed to clone output frame for resizing", fmt::ptr(
this));
233 JAMI_ERROR(
"[{}] Failed to allocate new output frame buffer: {}",
243 output->ch_layout.nb_channels,
246 JAMI_ERROR(
"[{}] Failed to set silence on new output frame: {}",
258 output->ch_layout.nb_channels,
261 JAMI_ERROR(
"[{}] Failed to copy data to new output frame: {}",
267 JAMI_DEBUG(
"[{}] Resampled first frame. Resized from {} to {} samples",
283std::unique_ptr<AudioFrame>
287 &&
in->pointer()->ch_layout.nb_channels == (
int) format.
nb_channels
289 return std::move(
in);
291 auto output = std::make_unique<AudioFrame>(format);
297std::shared_ptr<AudioFrame>
304 if (
inPtr ==
nullptr) {
310 return std::move(
in);
313 auto output = std::make_shared<AudioFrame>(format);
int resample(const AVFrame *input, AVFrame *output)
Resample a frame.
#define JAMI_ERROR(formatstr,...)
#define JAMI_DEBUG(formatstr,...)
#define JAMI_WARNING(formatstr,...)
AudioFormat getFormat(const AVFrame *frame)
std::string getError(int err)
static constexpr std::string_view toString(AuthDecodingState state)
void emitSignal(Args... args)
void av_frame_free(AVFrame **frame)