audio_demo/swr_utils.h

30 lines
859 B
C
Raw Permalink Normal View History

2025-02-14 08:58:27 +08:00
#pragma once
extern "C" {
#include <libswresample/swresample.h>
}
class SwrUtil {
public:
struct Param {
int sample_rate;
int channels;
AVSampleFormat format;
} _input, _output;
private:
SwrContext *_swrCtx = nullptr;
public:
SwrUtil() : _swrCtx(swr_alloc()) {}
int init(Param in, Param out) {
_swrCtx = swr_alloc_set_opts(_swrCtx,
av_get_default_channel_layout(out.channels),
out.format,
out.sample_rate,
av_get_default_channel_layout(in.channels),
in.format,
in.sample_rate,
0, nullptr);
return _swrCtx ? 0 : -1;
}
int convert(){}
};