From 07f474425ecd00173df0410d6d9f9cb0bb5d6f0f Mon Sep 17 00:00:00 2001 From: Daniel Morandini Date: Thu, 2 Nov 2023 10:33:17 +0100 Subject: [PATCH] Preserve output ch layout --- c_src/decoder.c | 7 +++---- c_src/decoder.h | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/c_src/decoder.c b/c_src/decoder.c index 0b341aa..bcd48f8 100644 --- a/c_src/decoder.c +++ b/c_src/decoder.c @@ -27,11 +27,10 @@ int alloc_resampler(Decoder *ctx, FormatOpts output_opts) { output_layout = malloc(sizeof(AVChannelLayout)); av_channel_layout_copy(output_layout, &ctx->codec_ctx->ch_layout); + output_layout->nb_channels = output_opts.channels; - // TODO - // free(output_layout); + ctx->output_ch_layout = output_layout; - output_layout->nb_channels = output_opts.channels; output_opts.sample_format = av_get_packed_sample_fmt(output_opts.sample_format); @@ -89,7 +88,7 @@ int decoder_read_frame(Decoder *ctx, AVFrame *frame) { AVFrame *resampled_frame; resampled_frame = av_frame_alloc(); resampled_frame->nb_samples = frame->nb_samples; - resampled_frame->ch_layout = frame->ch_layout; + resampled_frame->ch_layout = *ctx->output_ch_layout; resampled_frame->sample_rate = frame->sample_rate; resampled_frame->format = ctx->output_fmt->sample_format; diff --git a/c_src/decoder.h b/c_src/decoder.h index 62b3d28..107574a 100644 --- a/c_src/decoder.h +++ b/c_src/decoder.h @@ -14,6 +14,7 @@ typedef struct { SwrContext *resampler_ctx; FormatOpts *output_fmt; + AVChannelLayout *output_ch_layout; } Decoder; typedef struct {