From 35329593ddd5d75bb323cdc1a29e2b359c9415a5 Mon Sep 17 00:00:00 2001 From: Daniel Morandini Date: Tue, 14 Nov 2023 12:10:29 +0100 Subject: [PATCH] Fix channel layout change --- c_src/decoder.c | 3 +-- test/avx/decoder_test.exs | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/c_src/decoder.c b/c_src/decoder.c index 54190b2..1120941 100644 --- a/c_src/decoder.c +++ b/c_src/decoder.c @@ -68,9 +68,8 @@ int decoder_alloc(Decoder **ctx, DecoderOpts opts) { ictx->codec_ctx = codec_ctx; if (!(ictx->output.ch_layout = malloc(sizeof(AVChannelLayout)))) return AVERROR(ENOMEM); + av_channel_layout_default(ictx->output.ch_layout, opts.output.nb_channels); - av_channel_layout_copy(ictx->output.ch_layout, &codec_ctx->ch_layout); - ictx->output.ch_layout->nb_channels = opts.output.nb_channels; ictx->output.sample_rate = opts.output.sample_rate; // Planar formats are not supported as they require a different procedure to // lay down the plain bits contained in their frames. diff --git a/test/avx/decoder_test.exs b/test/avx/decoder_test.exs index 79d9974..8787529 100644 --- a/test/avx/decoder_test.exs +++ b/test/avx/decoder_test.exs @@ -35,7 +35,8 @@ defmodule AVx.DecoderTest do end test "decodes into a different format" do - {:ok, demuxer} = Demuxer.new_from_file(List.first(@inputs)) + # We use this file for testing as it is stereo, sample rate 97_000, format fltp + {:ok, demuxer} = Demuxer.new_from_file("test/data/packed.aac") [aac] = Demuxer.read_streams(demuxer) packets = Demuxer.consume_packets(demuxer, [aac.stream_index]) @@ -53,7 +54,7 @@ defmodule AVx.DecoderTest do |> Decoder.decode_frames(decoder) |> Enum.count() - assert frame_count == 564 + assert frame_count == 283 end defp assert_frames(packets, decoder, expected_frames, ext) do