Set up the FFmpeg resampler if needed.
241{
242 if (!ctx || !ctx->codec_context) {
243 return false;
244 }
245
246 AVChannelLayout out_ch_layout;
247 av_channel_layout_copy(&out_ch_layout, &ctx->codec_context->ch_layout);
248
250
252 ? AV_SAMPLE_FMT_DBLP
253 : AV_SAMPLE_FMT_DBL;
254
255 int ret = swr_alloc_set_opts2(&ctx->swr_context,
256 &out_ch_layout, out_sample_fmt, out_sample_rate,
257 &ctx->codec_context->ch_layout, ctx->codec_context->sample_fmt,
258 ctx->codec_context->sample_rate,
259 0, nullptr);
260
261 av_channel_layout_uninit(&out_ch_layout);
262
263 if (ret < 0 || !ctx->swr_context) {
264 set_error(
"Failed to allocate resampler");
265 return false;
266 }
267
268 if (swr_init(ctx->swr_context) < 0) {
269 set_error(
"Failed to initialize resampler");
270 return false;
271 }
272
273 return true;
274}
uint32_t m_target_sample_rate
Target sample rate for resampling (0 = use source rate).
void set_error(const std::string &error) const
Set the last error message.
AudioReadOptions m_audio_options
Audio-specific read options.