static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {

    AVStream *st = s->streams[pkt->stream_index];

    int i, ret;



    if (!(s->flags & AVFMT_FLAG_AUTO_BSF))

        return 1;



    if (s->oformat->check_bitstream) {

        if (!st->internal->bitstream_checked) {

            if ((ret = s->oformat->check_bitstream(s, pkt)) < 0)

                return ret;

            else if (ret == 1)

                st->internal->bitstream_checked = 1;

        }

    }



#if FF_API_LAVF_MERGE_SD

FF_DISABLE_DEPRECATION_WARNINGS

    if (st->internal->nb_bsfcs) {

        ret = av_packet_split_side_data(pkt);

        if (ret < 0)

            av_log(s, AV_LOG_WARNING, "Failed to split side data before bitstream filter\n");

    }

FF_ENABLE_DEPRECATION_WARNINGS

#endif



    for (i = 0; i < st->internal->nb_bsfcs; i++) {

        AVBSFContext *ctx = st->internal->bsfcs[i];

        if (i > 0) {

            AVBSFContext* prev_ctx = st->internal->bsfcs[i - 1];

            if (prev_ctx->par_out->extradata_size != ctx->par_in->extradata_size) {

                if ((ret = avcodec_parameters_copy(ctx->par_in, prev_ctx->par_out)) < 0)

                    return ret;

            }

        }

        // TODO: when any bitstream filter requires flushing at EOF, we'll need to

        // flush each stream's BSF chain on write_trailer.

        if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) {

            av_log(ctx, AV_LOG_ERROR,

                    "Failed to send packet to filter %s for stream %d\n",

                    ctx->filter->name, pkt->stream_index);

            return ret;

        }

        // TODO: when any automatically-added bitstream filter is generating multiple

        // output packets for a single input one, we'll need to call this in a loop

        // and write each output packet.

        if ((ret = av_bsf_receive_packet(ctx, pkt)) < 0) {

            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)

                return 0;

            av_log(ctx, AV_LOG_ERROR,

                    "Failed to send packet to filter %s for stream %d\n",

                    ctx->filter->name, pkt->stream_index);

            return ret;

        }

        if (i == st->internal->nb_bsfcs - 1) {

            if (ctx->par_out->extradata_size != st->codecpar->extradata_size) {

                if ((ret = avcodec_parameters_copy(st->codecpar, ctx->par_out)) < 0)

                    return ret;

            }

        }

    }

    return 1;

}

static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {

    AVStream *st = s->streams[pkt->stream_index];

    int i, ret;



    if (!(s->flags & AVFMT_FLAG_AUTO_BSF))

        return 1;



    if (s->oformat->check_bitstream) {

        if (!st->internal->bitstream_checked) {

            if ((ret = s->oformat->check_bitstream(s, pkt)) < 0)

                return ret;

            else if (ret == 1)

                st->internal->bitstream_checked = 1;

        }

    }



#if FF_API_LAVF_MERGE_SD

FF_DISABLE_DEPRECATION_WARNINGS

    if (st->internal->nb_bsfcs) {

        ret = av_packet_split_side_data(pkt);

        if (ret < 0)

            av_log(s, AV_LOG_WARNING, "Failed to split side data before bitstream filter\n");

    }

FF_ENABLE_DEPRECATION_WARNINGS

#endif



    for (i = 0; i < st->internal->nb_bsfcs; i++) {

        AVBSFContext *ctx = st->internal->bsfcs[i];

        if (i > 0) {

            AVBSFContext* prev_ctx = st->internal->bsfcs[i - 1];

            if (prev_ctx->par_out->extradata_size != ctx->par_in->extradata_size) {

                if ((ret = avcodec_parameters_copy(ctx->par_in, prev_ctx->par_out)) < 0)

                    return ret;

            }

        }

        

        

        if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) {

            av_log(ctx, AV_LOG_ERROR,

                    "Failed to send packet to filter %s for stream %d\n",

                    ctx->filter->name, pkt->stream_index);

            return ret;

        }

        

        

        

        if ((ret = av_bsf_receive_packet(ctx, pkt)) < 0) {

            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)

                return 0;

            av_log(ctx, AV_LOG_ERROR,

                    "Failed to send packet to filter %s for stream %d\n",

                    ctx->filter->name, pkt->stream_index);

            return ret;

        }

        if (i == st->internal->nb_bsfcs - 1) {

            if (ctx->par_out->extradata_size != st->codecpar->extradata_size) {

                if ((ret = avcodec_parameters_copy(st->codecpar, ctx->par_out)) < 0)

                    return ret;

            }

        }

    }

    return 1;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1) {

    AVStream *st = VAR_0->streams[VAR_1->stream_index];

    int VAR_2, VAR_3;



    if (!(VAR_0->flags & AVFMT_FLAG_AUTO_BSF))

        return 1;



    if (VAR_0->oformat->check_bitstream) {

        if (!st->internal->bitstream_checked) {

            if ((VAR_3 = VAR_0->oformat->check_bitstream(VAR_0, VAR_1)) < 0)

                return VAR_3;

            else if (VAR_3 == 1)

                st->internal->bitstream_checked = 1;

        }

    }



#if FF_API_LAVF_MERGE_SD

FF_DISABLE_DEPRECATION_WARNINGS

    if (st->internal->nb_bsfcs) {

        VAR_3 = av_packet_split_side_data(VAR_1);

        if (VAR_3 < 0)

            av_log(VAR_0, AV_LOG_WARNING, "Failed to split side data before bitstream filter\n");

    }

FF_ENABLE_DEPRECATION_WARNINGS

#endif



    for (VAR_2 = 0; VAR_2 < st->internal->nb_bsfcs; VAR_2++) {

        AVBSFContext *ctx = st->internal->bsfcs[VAR_2];

        if (VAR_2 > 0) {

            AVBSFContext* prev_ctx = st->internal->bsfcs[VAR_2 - 1];

            if (prev_ctx->par_out->extradata_size != ctx->par_in->extradata_size) {

                if ((VAR_3 = avcodec_parameters_copy(ctx->par_in, prev_ctx->par_out)) < 0)

                    return VAR_3;

            }

        }

        

        

        if ((VAR_3 = av_bsf_send_packet(ctx, VAR_1)) < 0) {

            av_log(ctx, AV_LOG_ERROR,

                    "Failed to send packet to filter %VAR_0 for stream %d\n",

                    ctx->filter->name, VAR_1->stream_index);

            return VAR_3;

        }

        

        

        

        if ((VAR_3 = av_bsf_receive_packet(ctx, VAR_1)) < 0) {

            if (VAR_3 == AVERROR(EAGAIN) || VAR_3 == AVERROR_EOF)

                return 0;

            av_log(ctx, AV_LOG_ERROR,

                    "Failed to send packet to filter %VAR_0 for stream %d\n",

                    ctx->filter->name, VAR_1->stream_index);

            return VAR_3;

        }

        if (VAR_2 == st->internal->nb_bsfcs - 1) {

            if (ctx->par_out->extradata_size != st->codecpar->extradata_size) {

                if ((VAR_3 = avcodec_parameters_copy(st->codecpar, ctx->par_out)) < 0)

                    return VAR_3;

            }

        }

    }

    return 1;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1) { AVStream *st = VAR_0->streams[VAR_1->stream_index]; int VAR_2, VAR_3; if (!(VAR_0->flags & AVFMT_FLAG_AUTO_BSF))
return 1; if (VAR_0->oformat->check_bitstream) { if (!st->internal->bitstream_checked) { if ((VAR_3 = VAR_0->oformat->check_bitstream(VAR_0, VAR_1)) < 0)
return VAR_3; else if (VAR_3 == 1)
st->internal->bitstream_checked = 1; } } #if FF_API_LAVF_MERGE_SD
FF_DISABLE_DEPRECATION_WARNINGS
if (st->internal->nb_bsfcs) { VAR_3 = av_packet_split_side_data(VAR_1); if (VAR_3 < 0)
av_log(VAR_0, AV_LOG_WARNING, "Failed to split side data before bitstream filter\n"); } FF_ENABLE_DEPRECATION_WARNINGS
#endif
for (VAR_2 = 0; VAR_2 < st->internal->nb_bsfcs; VAR_2++) { AVBSFContext *ctx = st->internal->bsfcs[VAR_2]; if (VAR_2 > 0) { AVBSFContext* prev_ctx = st->internal->bsfcs[VAR_2 - 1]; if (prev_ctx->par_out->extradata_size != ctx->par_in->extradata_size) { if ((VAR_3 = avcodec_parameters_copy(ctx->par_in, prev_ctx->par_out)) < 0)
return VAR_3; } } if ((VAR_3 = av_bsf_send_packet(ctx, VAR_1)) < 0) { av_log(ctx, AV_LOG_ERROR,
"Failed to send packet to filter %VAR_0 for stream %d\n",
ctx->filter->name, VAR_1->stream_index); return VAR_3; } if ((VAR_3 = av_bsf_receive_packet(ctx, VAR_1)) < 0) { if (VAR_3 == AVERROR(EAGAIN) || VAR_3 == AVERROR_EOF)
return 0; av_log(ctx, AV_LOG_ERROR,
"Failed to send packet to filter %VAR_0 for stream %d\n",
ctx->filter->name, VAR_1->stream_index); return VAR_3; } if (VAR_2 == st->internal->nb_bsfcs - 1) { if (ctx->par_out->extradata_size != st->codecpar->extradata_size) { if ((VAR_3 = avcodec_parameters_copy(st->codecpar, ctx->par_out)) < 0)
return VAR_3; } } } return 1; }