Commit 8876f61947 for ffmpeg

commit 8876f61947bf922e6e30c1c2df83fd7f55759b9a
Author: romainhedouin <romain.hedouin@epitech.eu>
Date:   Fri Nov 6 18:27:13 2026 +0100

    avcodec/aacenc: Use the right element type when restoring coefficients

    When the rate loop encodes a frame again, it first restores the
    coefficients of every element. The number of channels to restore came
    from the type of the last element, not from the element being
    restored. For layouts that do not end in a channel pair (4.0, 5.1, 6.1,
    7.1), the second channel of each pair was not restored.

    Noticed during a review sweep of ffmpeg using an LLM.

    Signed-off-by: romainhedouin <romain.hedouin@epitech.eu>

diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 5b1e3eff0f..50a1460e61 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -1650,7 +1650,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
                 if (is_mode || ms_mode || tns_mode || pred_mode) {
                     for (i = 0; i < s->chan_map[0]; i++) {
                         // Must restore coeffs
-                        chans = tag == TYPE_CPE ? 2 : 1;
+                        chans = s->chan_map[i + 1] == TYPE_CPE ? 2 : 1;
                         cpe = &s->cpe[i];
                         for (ch = 0; ch < chans; ch++)
                             memcpy(cpe->ch[ch].coeffs, cpe->ch[ch].pcoeffs, sizeof(cpe->ch[ch].coeffs));