static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,

                                   uint8_t **data, int *size)

{

    static const int extradata_nal_types_hevc[] = {

        HEVC_NAL_VPS, HEVC_NAL_SPS, HEVC_NAL_PPS,

    };

    static const int extradata_nal_types_h264[] = {

        H264_NAL_SPS, H264_NAL_PPS,

    };



    ExtractExtradataContext *s = ctx->priv_data;



    H2645Packet h2645_pkt = { 0 };

    int extradata_size = 0;

    const int *extradata_nal_types;

    int nb_extradata_nal_types;

    int i, has_sps = 0, has_vps = 0, ret = 0;



    if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) {

        extradata_nal_types    = extradata_nal_types_hevc;

        nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_hevc);

    } else {

        extradata_nal_types    = extradata_nal_types_h264;

        nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_h264);

    }



    ret = ff_h2645_packet_split(&h2645_pkt, pkt->data, pkt->size,

                                ctx, 0, 0, ctx->par_in->codec_id, 1);

    if (ret < 0)

        return ret;



    for (i = 0; i < h2645_pkt.nb_nals; i++) {

        H2645NAL *nal = &h2645_pkt.nals[i];

        if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type)) {

            extradata_size += nal->raw_size + 3;

            if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) {

                if (nal->type == HEVC_NAL_SPS) has_sps = 1;

                if (nal->type == HEVC_NAL_VPS) has_vps = 1;

            } else {

                if (nal->type == H264_NAL_SPS) has_sps = 1;

            }

        }

    }



    if (extradata_size &&

        ((ctx->par_in->codec_id == AV_CODEC_ID_HEVC && has_sps && has_vps) ||

         (ctx->par_in->codec_id == AV_CODEC_ID_H264 && has_sps))) {

        AVBufferRef *filtered_buf;

        uint8_t *extradata, *filtered_data;



        if (s->remove) {

            filtered_buf = av_buffer_alloc(pkt->size + AV_INPUT_BUFFER_PADDING_SIZE);

            if (!filtered_buf) {

                ret = AVERROR(ENOMEM);

                goto fail;

            }

            filtered_data = filtered_buf->data;

        }



        extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);

        if (!extradata) {

            av_buffer_unref(&filtered_buf);

            ret = AVERROR(ENOMEM);

            goto fail;

        }



        *data = extradata;

        *size = extradata_size;



        for (i = 0; i < h2645_pkt.nb_nals; i++) {

            H2645NAL *nal = &h2645_pkt.nals[i];

            if (val_in_array(extradata_nal_types, nb_extradata_nal_types,

                             nal->type)) {

                AV_WB24(extradata, 1); // startcode

                memcpy(extradata + 3, nal->raw_data, nal->raw_size);

                extradata += 3 + nal->raw_size;

            } else if (s->remove) {

                AV_WB24(filtered_data, 1); // startcode

                memcpy(filtered_data + 3, nal->raw_data, nal->raw_size);

                filtered_data += 3 + nal->raw_size;

            }

        }



        if (s->remove) {

            av_buffer_unref(&pkt->buf);

            pkt->buf  = filtered_buf;

            pkt->data = filtered_buf->data;

            pkt->size = filtered_data - filtered_buf->data;

        }

    }



fail:

    ff_h2645_packet_uninit(&h2645_pkt);

    return ret;

}

static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,

                                   uint8_t **data, int *size)

{

    static const int extradata_nal_types_hevc[] = {

        HEVC_NAL_VPS, HEVC_NAL_SPS, HEVC_NAL_PPS,

    };

    static const int extradata_nal_types_h264[] = {

        H264_NAL_SPS, H264_NAL_PPS,

    };



    ExtractExtradataContext *s = ctx->priv_data;



    H2645Packet h2645_pkt = { 0 };

    int extradata_size = 0;

    const int *extradata_nal_types;

    int nb_extradata_nal_types;

    int i, has_sps = 0, has_vps = 0, ret = 0;



    if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) {

        extradata_nal_types    = extradata_nal_types_hevc;

        nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_hevc);

    } else {

        extradata_nal_types    = extradata_nal_types_h264;

        nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_h264);

    }



    ret = ff_h2645_packet_split(&h2645_pkt, pkt->data, pkt->size,

                                ctx, 0, 0, ctx->par_in->codec_id, 1);

    if (ret < 0)

        return ret;



    for (i = 0; i < h2645_pkt.nb_nals; i++) {

        H2645NAL *nal = &h2645_pkt.nals[i];

        if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type)) {

            extradata_size += nal->raw_size + 3;

            if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) {

                if (nal->type == HEVC_NAL_SPS) has_sps = 1;

                if (nal->type == HEVC_NAL_VPS) has_vps = 1;

            } else {

                if (nal->type == H264_NAL_SPS) has_sps = 1;

            }

        }

    }



    if (extradata_size &&

        ((ctx->par_in->codec_id == AV_CODEC_ID_HEVC && has_sps && has_vps) ||

         (ctx->par_in->codec_id == AV_CODEC_ID_H264 && has_sps))) {

        AVBufferRef *filtered_buf;

        uint8_t *extradata, *filtered_data;



        if (s->remove) {

            filtered_buf = av_buffer_alloc(pkt->size + AV_INPUT_BUFFER_PADDING_SIZE);

            if (!filtered_buf) {

                ret = AVERROR(ENOMEM);

                goto fail;

            }

            filtered_data = filtered_buf->data;

        }



        extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);

        if (!extradata) {

            av_buffer_unref(&filtered_buf);

            ret = AVERROR(ENOMEM);

            goto fail;

        }



        *data = extradata;

        *size = extradata_size;



        for (i = 0; i < h2645_pkt.nb_nals; i++) {

            H2645NAL *nal = &h2645_pkt.nals[i];

            if (val_in_array(extradata_nal_types, nb_extradata_nal_types,

                             nal->type)) {

                AV_WB24(extradata, 1); 

                memcpy(extradata + 3, nal->raw_data, nal->raw_size);

                extradata += 3 + nal->raw_size;

            } else if (s->remove) {

                AV_WB24(filtered_data, 1); 

                memcpy(filtered_data + 3, nal->raw_data, nal->raw_size);

                filtered_data += 3 + nal->raw_size;

            }

        }



        if (s->remove) {

            av_buffer_unref(&pkt->buf);

            pkt->buf  = filtered_buf;

            pkt->data = filtered_buf->data;

            pkt->size = filtered_data - filtered_buf->data;

        }

    }



fail:

    ff_h2645_packet_uninit(&h2645_pkt);

    return ret;

}

        return ret;
static int FUNC_0(AVBSFContext *VAR_0, AVPacket *VAR_1,

                                   uint8_t **VAR_2, int *VAR_3)

{

    static const int VAR_4[] = {

        HEVC_NAL_VPS, HEVC_NAL_SPS, HEVC_NAL_PPS,

    };

    static const int VAR_5[] = {

        H264_NAL_SPS, H264_NAL_PPS,

    };



    ExtractExtradataContext *s = VAR_0->priv_data;



    H2645Packet h2645_pkt = { 0 };

    int VAR_6 = 0;

    const int *VAR_7;

    int VAR_8;

    int VAR_9, VAR_10 = 0, VAR_11 = 0, VAR_12 = 0;



    if (VAR_0->par_in->codec_id == AV_CODEC_ID_HEVC) {

        VAR_7    = VAR_4;

        VAR_8 = FF_ARRAY_ELEMS(VAR_4);

    } else {

        VAR_7    = VAR_5;

        VAR_8 = FF_ARRAY_ELEMS(VAR_5);

    }



    VAR_12 = ff_h2645_packet_split(&h2645_pkt, VAR_1->VAR_2, VAR_1->VAR_3,

                                VAR_0, 0, 0, VAR_0->par_in->codec_id, 1);

    if (VAR_12 < 0)

        return VAR_12;



    for (VAR_9 = 0; VAR_9 < h2645_pkt.nb_nals; VAR_9++) {

        H2645NAL *nal = &h2645_pkt.nals[VAR_9];

        if (val_in_array(VAR_7, VAR_8, nal->type)) {

            VAR_6 += nal->raw_size + 3;

            if (VAR_0->par_in->codec_id == AV_CODEC_ID_HEVC) {

                if (nal->type == HEVC_NAL_SPS) VAR_10 = 1;

                if (nal->type == HEVC_NAL_VPS) VAR_11 = 1;

            } else {

                if (nal->type == H264_NAL_SPS) VAR_10 = 1;

            }

        }

    }



    if (VAR_6 &&

        ((VAR_0->par_in->codec_id == AV_CODEC_ID_HEVC && VAR_10 && VAR_11) ||

         (VAR_0->par_in->codec_id == AV_CODEC_ID_H264 && VAR_10))) {

        AVBufferRef *filtered_buf;

        uint8_t *extradata, *filtered_data;



        if (s->remove) {

            filtered_buf = av_buffer_alloc(VAR_1->VAR_3 + AV_INPUT_BUFFER_PADDING_SIZE);

            if (!filtered_buf) {

                VAR_12 = AVERROR(ENOMEM);

                goto fail;

            }

            filtered_data = filtered_buf->VAR_2;

        }



        extradata = av_malloc(VAR_6 + AV_INPUT_BUFFER_PADDING_SIZE);

        if (!extradata) {

            av_buffer_unref(&filtered_buf);

            VAR_12 = AVERROR(ENOMEM);

            goto fail;

        }



        *VAR_2 = extradata;

        *VAR_3 = VAR_6;



        for (VAR_9 = 0; VAR_9 < h2645_pkt.nb_nals; VAR_9++) {

            H2645NAL *nal = &h2645_pkt.nals[VAR_9];

            if (val_in_array(VAR_7, VAR_8,

                             nal->type)) {

                AV_WB24(extradata, 1); 

                memcpy(extradata + 3, nal->raw_data, nal->raw_size);

                extradata += 3 + nal->raw_size;

            } else if (s->remove) {

                AV_WB24(filtered_data, 1); 

                memcpy(filtered_data + 3, nal->raw_data, nal->raw_size);

                filtered_data += 3 + nal->raw_size;

            }

        }



        if (s->remove) {

            av_buffer_unref(&VAR_1->buf);

            VAR_1->buf  = filtered_buf;

            VAR_1->VAR_2 = filtered_buf->VAR_2;

            VAR_1->VAR_3 = filtered_data - filtered_buf->VAR_2;

        }

    }



fail:

    ff_h2645_packet_uninit(&h2645_pkt);

    return VAR_12;

}

static int FUNC_0(AVBSFContext *VAR_0, AVPacket *VAR_1,
uint8_t **VAR_2, int *VAR_3)
{ static const int VAR_4[] = { HEVC_NAL_VPS, HEVC_NAL_SPS, HEVC_NAL_PPS,
}; static const int VAR_5[] = { H264_NAL_SPS, H264_NAL_PPS,
}; ExtractExtradataContext *s = VAR_0->priv_data; H2645Packet h2645_pkt = { 0 }; int VAR_6 = 0; const int *VAR_7; int VAR_8; int VAR_9, VAR_10 = 0, VAR_11 = 0, VAR_12 = 0; if (VAR_0->par_in->codec_id == AV_CODEC_ID_HEVC) { VAR_7    = VAR_4; VAR_8 = FF_ARRAY_ELEMS(VAR_4); } else { VAR_7    = VAR_5; VAR_8 = FF_ARRAY_ELEMS(VAR_5); } VAR_12 = ff_h2645_packet_split(&h2645_pkt, VAR_1->VAR_2, VAR_1->VAR_3,
VAR_0, 0, 0, VAR_0->par_in->codec_id, 1); if (VAR_12 < 0)
return VAR_12; for (VAR_9 = 0; VAR_9 < h2645_pkt.nb_nals; VAR_9++) { H2645NAL *nal = &h2645_pkt.nals[VAR_9]; if (val_in_array(VAR_7, VAR_8, nal->type)) { VAR_6 += nal->raw_size + 3; if (VAR_0->par_in->codec_id == AV_CODEC_ID_HEVC) { if (nal->type == HEVC_NAL_SPS) VAR_10 = 1; if (nal->type == HEVC_NAL_VPS) VAR_11 = 1; } else { if (nal->type == H264_NAL_SPS) VAR_10 = 1; } } } if (VAR_6 &&
((VAR_0->par_in->codec_id == AV_CODEC_ID_HEVC && VAR_10 && VAR_11) ||
(VAR_0->par_in->codec_id == AV_CODEC_ID_H264 && VAR_10))) { AVBufferRef *filtered_buf; uint8_t *extradata, *filtered_data; if (s->remove) { filtered_buf = av_buffer_alloc(VAR_1->VAR_3 + AV_INPUT_BUFFER_PADDING_SIZE); if (!filtered_buf) { VAR_12 = AVERROR(ENOMEM); goto fail; } filtered_data = filtered_buf->VAR_2; } extradata = av_malloc(VAR_6 + AV_INPUT_BUFFER_PADDING_SIZE); if (!extradata) { av_buffer_unref(&filtered_buf); VAR_12 = AVERROR(ENOMEM); goto fail; } *VAR_2 = extradata; *VAR_3 = VAR_6; for (VAR_9 = 0; VAR_9 < h2645_pkt.nb_nals; VAR_9++) { H2645NAL *nal = &h2645_pkt.nals[VAR_9]; if (val_in_array(VAR_7, VAR_8,
nal->type)) { AV_WB24(extradata, 1); memcpy(extradata + 3, nal->raw_data, nal->raw_size); extradata += 3 + nal->raw_size; } else if (s->remove) { AV_WB24(filtered_data, 1); memcpy(filtered_data + 3, nal->raw_data, nal->raw_size); filtered_data += 3 + nal->raw_size; } } if (s->remove) { av_buffer_unref(&VAR_1->buf); VAR_1->buf  = filtered_buf; VAR_1->VAR_2 = filtered_buf->VAR_2; VAR_1->VAR_3 = filtered_data - filtered_buf->VAR_2; } } fail:
ff_h2645_packet_uninit(&h2645_pkt); return VAR_12; }