static int channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)

{

    AVFilterContext  *ctx = inlink->dst;

    AVFilterLink *outlink = ctx->outputs[0];

    const ChannelMapContext *s = ctx->priv;

    const int nch_in = av_get_channel_layout_nb_channels(inlink->channel_layout);

    const int nch_out = s->nch;

    int ch;

    uint8_t *source_planes[MAX_CH];



    memcpy(source_planes, buf->extended_data,

           nch_in * sizeof(source_planes[0]));



    if (nch_out > nch_in) {

        if (nch_out > FF_ARRAY_ELEMS(buf->data)) {

            uint8_t **new_extended_data =

                av_mallocz(nch_out * sizeof(*buf->extended_data));

            if (!new_extended_data) {

                avfilter_unref_buffer(buf);

                return AVERROR(ENOMEM);

            }

            if (buf->extended_data == buf->data) {

                buf->extended_data = new_extended_data;

            } else {

                buf->extended_data = new_extended_data;

                av_free(buf->extended_data);

            }

        } else if (buf->extended_data != buf->data) {

            av_free(buf->extended_data);

            buf->extended_data = buf->data;

        }

    }



    for (ch = 0; ch < nch_out; ch++) {

        buf->extended_data[s->map[ch].out_channel_idx] =

            source_planes[s->map[ch].in_channel_idx];

    }



    if (buf->data != buf->extended_data)

        memcpy(buf->data, buf->extended_data,

           FFMIN(FF_ARRAY_ELEMS(buf->data), nch_out) * sizeof(buf->data[0]));



    return ff_filter_samples(outlink, buf);

}

static int channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)

{

    AVFilterContext  *ctx = inlink->dst;

    AVFilterLink *outlink = ctx->outputs[0];

    const ChannelMapContext *s = ctx->priv;

    const int nch_in = av_get_channel_layout_nb_channels(inlink->channel_layout);

    const int nch_out = s->nch;

    int ch;

    uint8_t *source_planes[MAX_CH];



    memcpy(source_planes, buf->extended_data,

           nch_in * sizeof(source_planes[0]));



    if (nch_out > nch_in) {

        if (nch_out > FF_ARRAY_ELEMS(buf->data)) {

            uint8_t **new_extended_data =

                av_mallocz(nch_out * sizeof(*buf->extended_data));

            if (!new_extended_data) {

                avfilter_unref_buffer(buf);

                return AVERROR(ENOMEM);

            }

            if (buf->extended_data == buf->data) {

                buf->extended_data = new_extended_data;

            } else {

                buf->extended_data = new_extended_data;

                av_free(buf->extended_data);

            }

        } else if (buf->extended_data != buf->data) {

            av_free(buf->extended_data);

            buf->extended_data = buf->data;

        }

    }



    for (ch = 0; ch < nch_out; ch++) {

        buf->extended_data[s->map[ch].out_channel_idx] =

            source_planes[s->map[ch].in_channel_idx];

    }



    if (buf->data != buf->extended_data)

        memcpy(buf->data, buf->extended_data,

           FFMIN(FF_ARRAY_ELEMS(buf->data), nch_out) * sizeof(buf->data[0]));



    return ff_filter_samples(outlink, buf);

}

                buf->extended_data = new_extended_data;
static int FUNC_0(AVFilterLink *VAR_0, AVFilterBufferRef *VAR_1)

{

    AVFilterContext  *ctx = VAR_0->dst;

    AVFilterLink *outlink = ctx->outputs[0];

    const ChannelMapContext *VAR_2 = ctx->priv;

    const int VAR_3 = av_get_channel_layout_nb_channels(VAR_0->channel_layout);

    const int VAR_4 = VAR_2->nch;

    int VAR_5;

    uint8_t *source_planes[MAX_CH];



    memcpy(source_planes, VAR_1->extended_data,

           VAR_3 * sizeof(source_planes[0]));



    if (VAR_4 > VAR_3) {

        if (VAR_4 > FF_ARRAY_ELEMS(VAR_1->data)) {

            uint8_t **new_extended_data =

                av_mallocz(VAR_4 * sizeof(*VAR_1->extended_data));

            if (!new_extended_data) {

                avfilter_unref_buffer(VAR_1);

                return AVERROR(ENOMEM);

            }

            if (VAR_1->extended_data == VAR_1->data) {

                VAR_1->extended_data = new_extended_data;

            } else {

                VAR_1->extended_data = new_extended_data;

                av_free(VAR_1->extended_data);

            }

        } else if (VAR_1->extended_data != VAR_1->data) {

            av_free(VAR_1->extended_data);

            VAR_1->extended_data = VAR_1->data;

        }

    }



    for (VAR_5 = 0; VAR_5 < VAR_4; VAR_5++) {

        VAR_1->extended_data[VAR_2->map[VAR_5].out_channel_idx] =

            source_planes[VAR_2->map[VAR_5].in_channel_idx];

    }



    if (VAR_1->data != VAR_1->extended_data)

        memcpy(VAR_1->data, VAR_1->extended_data,

           FFMIN(FF_ARRAY_ELEMS(VAR_1->data), VAR_4) * sizeof(VAR_1->data[0]));



    return ff_filter_samples(outlink, VAR_1);

}

static int FUNC_0(AVFilterLink *VAR_0, AVFilterBufferRef *VAR_1)
{ AVFilterContext  *ctx = VAR_0->dst; AVFilterLink *outlink = ctx->outputs[0]; const ChannelMapContext *VAR_2 = ctx->priv; const int VAR_3 = av_get_channel_layout_nb_channels(VAR_0->channel_layout); const int VAR_4 = VAR_2->nch; int VAR_5; uint8_t *source_planes[MAX_CH]; memcpy(source_planes, VAR_1->extended_data,
VAR_3 * sizeof(source_planes[0])); if (VAR_4 > VAR_3) { if (VAR_4 > FF_ARRAY_ELEMS(VAR_1->data)) { uint8_t **new_extended_data =
av_mallocz(VAR_4 * sizeof(*VAR_1->extended_data)); if (!new_extended_data) { avfilter_unref_buffer(VAR_1); return AVERROR(ENOMEM); } if (VAR_1->extended_data == VAR_1->data) { VAR_1->extended_data = new_extended_data; } else { VAR_1->extended_data = new_extended_data; av_free(VAR_1->extended_data); } } else if (VAR_1->extended_data != VAR_1->data) { av_free(VAR_1->extended_data); VAR_1->extended_data = VAR_1->data; } } for (VAR_5 = 0; VAR_5 < VAR_4; VAR_5++) { VAR_1->extended_data[VAR_2->map[VAR_5].out_channel_idx] =
source_planes[VAR_2->map[VAR_5].in_channel_idx]; } if (VAR_1->data != VAR_1->extended_data)
memcpy(VAR_1->data, VAR_1->extended_data,
FFMIN(FF_ARRAY_ELEMS(VAR_1->data), VAR_4) * sizeof(VAR_1->data[0])); return ff_filter_samples(outlink, VAR_1); }