MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / init_resampler

Function init_resampler

doc/examples/transcode_aac.c:286–322  ·  view source on GitHub ↗

* Initialize the audio resampler based on the input and output codec settings. * If the input and output sample formats differ, a conversion is required * libswresample takes care of this, but requires initialization. * @param input_codec_context Codec context of the input file * @param output_codec_context Codec context of the output file * @param[out] resample_context Resampl

Source from the content-addressed store, hash-verified

284 * @return Error code (0 if successful)
285 */
286static int init_resampler(AVCodecContext *input_codec_context,
287 AVCodecContext *output_codec_context,
288 SwrContext **resample_context)
289{
290 int error;
291
292 /*
293 * Create a resampler context for the conversion.
294 * Set the conversion parameters.
295 */
296 error = swr_alloc_set_opts2(resample_context,
297 &output_codec_context->ch_layout,
298 output_codec_context->sample_fmt,
299 output_codec_context->sample_rate,
300 &input_codec_context->ch_layout,
301 input_codec_context->sample_fmt,
302 input_codec_context->sample_rate,
303 0, NULL);
304 if (error < 0) {
305 fprintf(stderr, "Could not allocate resample context\n");
306 return error;
307 }
308 /*
309 * Perform a sanity check so that the number of converted samples is
310 * not greater than the number of samples to be converted.
311 * If the sample rates differ, this case has to be handled differently
312 */
313 av_assert0(output_codec_context->sample_rate == input_codec_context->sample_rate);
314
315 /* Open the resampler with the specified parameters. */
316 if ((error = swr_init(*resample_context)) < 0) {
317 fprintf(stderr, "Could not open resample context\n");
318 swr_free(resample_context);
319 return error;
320 }
321 return 0;
322}
323
324/**
325 * Initialize a FIFO buffer for the audio samples to be encoded.

Callers 1

mainFunction · 0.85

Calls 3

swr_alloc_set_opts2Function · 0.85
swr_initFunction · 0.85
swr_freeFunction · 0.85

Tested by

no test coverage detected