static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index)

{

    AVPacket out_pkt = { 0 }, flush_pkt = { 0 };

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

    uint8_t *data = pkt ? pkt->data : NULL;

    int size      = pkt ? pkt->size : 0;

    int ret = 0, got_output = 0;



    if (!pkt) {

        av_init_packet(&flush_pkt);

        pkt        = &flush_pkt;

        got_output = 1;

    } else if (!size && st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {

        // preserve 0-size sync packets

        compute_pkt_fields(s, st, st->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE);

    }



    while (size > 0 || (pkt == &flush_pkt && got_output)) {

        int len;

        int64_t next_pts = pkt->pts;

        int64_t next_dts = pkt->dts;



        av_init_packet(&out_pkt);

        len = av_parser_parse2(st->parser, st->codec,

                               &out_pkt.data, &out_pkt.size, data, size,

                               pkt->pts, pkt->dts, pkt->pos);



        pkt->pts = pkt->dts = AV_NOPTS_VALUE;

        pkt->pos = -1;

        /* increment read pointer */

        data += len;

        size -= len;



        got_output = !!out_pkt.size;



        if (!out_pkt.size)

            continue;



        if (pkt->side_data) {

            out_pkt.side_data       = pkt->side_data;

            out_pkt.side_data_elems = pkt->side_data_elems;

            pkt->side_data          = NULL;

            pkt->side_data_elems    = 0;

        }



        /* set the duration */

        out_pkt.duration = (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0;

        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {

            if (st->codec->sample_rate > 0) {

                out_pkt.duration =

                    av_rescale_q_rnd(st->parser->duration,

                                     (AVRational) { 1, st->codec->sample_rate },

                                     st->time_base,

                                     AV_ROUND_DOWN);

            }

        }



        out_pkt.stream_index = st->index;

        out_pkt.pts          = st->parser->pts;

        out_pkt.dts          = st->parser->dts;

        out_pkt.pos          = st->parser->pos;



        if (st->need_parsing == AVSTREAM_PARSE_FULL_RAW)

            out_pkt.pos = st->parser->frame_offset;



        if (st->parser->key_frame == 1 ||

            (st->parser->key_frame == -1 &&

             st->parser->pict_type == AV_PICTURE_TYPE_I))

            out_pkt.flags |= AV_PKT_FLAG_KEY;



        if (st->parser->key_frame == -1 && st->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY))

            out_pkt.flags |= AV_PKT_FLAG_KEY;



        compute_pkt_fields(s, st, st->parser, &out_pkt, next_dts, next_pts);



        if ((ret = add_to_pktbuf(&s->internal->parse_queue, &out_pkt,

                                 &s->internal->parse_queue_end,

                                 1))) {

            av_packet_unref(&out_pkt);

            goto fail;

        }

    }



    /* end of the stream => close and free the parser */

    if (pkt == &flush_pkt) {

        av_parser_close(st->parser);

        st->parser = NULL;

    }



fail:

    av_packet_unref(pkt);

    return ret;

}

static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index)

{

    AVPacket out_pkt = { 0 }, flush_pkt = { 0 };

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

    uint8_t *data = pkt ? pkt->data : NULL;

    int size      = pkt ? pkt->size : 0;

    int ret = 0, got_output = 0;



    if (!pkt) {

        av_init_packet(&flush_pkt);

        pkt        = &flush_pkt;

        got_output = 1;

    } else if (!size && st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {

        

        compute_pkt_fields(s, st, st->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE);

    }



    while (size > 0 || (pkt == &flush_pkt && got_output)) {

        int len;

        int64_t next_pts = pkt->pts;

        int64_t next_dts = pkt->dts;



        av_init_packet(&out_pkt);

        len = av_parser_parse2(st->parser, st->codec,

                               &out_pkt.data, &out_pkt.size, data, size,

                               pkt->pts, pkt->dts, pkt->pos);



        pkt->pts = pkt->dts = AV_NOPTS_VALUE;

        pkt->pos = -1;

        

        data += len;

        size -= len;



        got_output = !!out_pkt.size;



        if (!out_pkt.size)

            continue;



        if (pkt->side_data) {

            out_pkt.side_data       = pkt->side_data;

            out_pkt.side_data_elems = pkt->side_data_elems;

            pkt->side_data          = NULL;

            pkt->side_data_elems    = 0;

        }



        

        out_pkt.duration = (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0;

        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {

            if (st->codec->sample_rate > 0) {

                out_pkt.duration =

                    av_rescale_q_rnd(st->parser->duration,

                                     (AVRational) { 1, st->codec->sample_rate },

                                     st->time_base,

                                     AV_ROUND_DOWN);

            }

        }



        out_pkt.stream_index = st->index;

        out_pkt.pts          = st->parser->pts;

        out_pkt.dts          = st->parser->dts;

        out_pkt.pos          = st->parser->pos;



        if (st->need_parsing == AVSTREAM_PARSE_FULL_RAW)

            out_pkt.pos = st->parser->frame_offset;



        if (st->parser->key_frame == 1 ||

            (st->parser->key_frame == -1 &&

             st->parser->pict_type == AV_PICTURE_TYPE_I))

            out_pkt.flags |= AV_PKT_FLAG_KEY;



        if (st->parser->key_frame == -1 && st->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY))

            out_pkt.flags |= AV_PKT_FLAG_KEY;



        compute_pkt_fields(s, st, st->parser, &out_pkt, next_dts, next_pts);



        if ((ret = add_to_pktbuf(&s->internal->parse_queue, &out_pkt,

                                 &s->internal->parse_queue_end,

                                 1))) {

            av_packet_unref(&out_pkt);

            goto fail;

        }

    }



    

    if (pkt == &flush_pkt) {

        av_parser_close(st->parser);

        st->parser = NULL;

    }



fail:

    av_packet_unref(pkt);

    return ret;

}

        if ((ret = add_to_pktbuf(&s->internal->parse_queue, &out_pkt,                                  &s->internal->parse_queue_end,                                  1))) {             av_packet_unref(&out_pkt);
static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1, int VAR_2)

{

    AVPacket out_pkt = { 0 }, flush_pkt = { 0 };

    AVStream *st = VAR_0->streams[VAR_2];

    uint8_t *data = VAR_1 ? VAR_1->data : NULL;

    int VAR_3      = VAR_1 ? VAR_1->VAR_3 : 0;

    int VAR_4 = 0, VAR_5 = 0;



    if (!VAR_1) {

        av_init_packet(&flush_pkt);

        VAR_1        = &flush_pkt;

        VAR_5 = 1;

    } else if (!VAR_3 && st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {

        

        compute_pkt_fields(VAR_0, st, st->parser, VAR_1, AV_NOPTS_VALUE, AV_NOPTS_VALUE);

    }



    while (VAR_3 > 0 || (VAR_1 == &flush_pkt && VAR_5)) {

        int VAR_6;

        int64_t next_pts = VAR_1->pts;

        int64_t next_dts = VAR_1->dts;



        av_init_packet(&out_pkt);

        VAR_6 = av_parser_parse2(st->parser, st->codec,

                               &out_pkt.data, &out_pkt.VAR_3, data, VAR_3,

                               VAR_1->pts, VAR_1->dts, VAR_1->pos);



        VAR_1->pts = VAR_1->dts = AV_NOPTS_VALUE;

        VAR_1->pos = -1;

        

        data += VAR_6;

        VAR_3 -= VAR_6;



        VAR_5 = !!out_pkt.VAR_3;



        if (!out_pkt.VAR_3)

            continue;



        if (VAR_1->side_data) {

            out_pkt.side_data       = VAR_1->side_data;

            out_pkt.side_data_elems = VAR_1->side_data_elems;

            VAR_1->side_data          = NULL;

            VAR_1->side_data_elems    = 0;

        }



        

        out_pkt.duration = (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? VAR_1->duration : 0;

        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {

            if (st->codec->sample_rate > 0) {

                out_pkt.duration =

                    av_rescale_q_rnd(st->parser->duration,

                                     (AVRational) { 1, st->codec->sample_rate },

                                     st->time_base,

                                     AV_ROUND_DOWN);

            }

        }



        out_pkt.VAR_2 = st->index;

        out_pkt.pts          = st->parser->pts;

        out_pkt.dts          = st->parser->dts;

        out_pkt.pos          = st->parser->pos;



        if (st->need_parsing == AVSTREAM_PARSE_FULL_RAW)

            out_pkt.pos = st->parser->frame_offset;



        if (st->parser->key_frame == 1 ||

            (st->parser->key_frame == -1 &&

             st->parser->pict_type == AV_PICTURE_TYPE_I))

            out_pkt.flags |= AV_PKT_FLAG_KEY;



        if (st->parser->key_frame == -1 && st->parser->pict_type ==AV_PICTURE_TYPE_NONE && (VAR_1->flags&AV_PKT_FLAG_KEY))

            out_pkt.flags |= AV_PKT_FLAG_KEY;



        compute_pkt_fields(VAR_0, st, st->parser, &out_pkt, next_dts, next_pts);



        if ((VAR_4 = add_to_pktbuf(&VAR_0->internal->parse_queue, &out_pkt,

                                 &VAR_0->internal->parse_queue_end,

                                 1))) {

            av_packet_unref(&out_pkt);

            goto fail;

        }

    }



    

    if (VAR_1 == &flush_pkt) {

        av_parser_close(st->parser);

        st->parser = NULL;

    }



fail:

    av_packet_unref(VAR_1);

    return VAR_4;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1, int VAR_2)
{ AVPacket out_pkt = { 0 }, flush_pkt = { 0 }; AVStream *st = VAR_0->streams[VAR_2]; uint8_t *data = VAR_1 ? VAR_1->data : NULL; int VAR_3      = VAR_1 ? VAR_1->VAR_3 : 0; int VAR_4 = 0, VAR_5 = 0; if (!VAR_1) { av_init_packet(&flush_pkt); VAR_1        = &flush_pkt; VAR_5 = 1; } else if (!VAR_3 && st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { compute_pkt_fields(VAR_0, st, st->parser, VAR_1, AV_NOPTS_VALUE, AV_NOPTS_VALUE); } while (VAR_3 > 0 || (VAR_1 == &flush_pkt && VAR_5)) { int VAR_6; int64_t next_pts = VAR_1->pts; int64_t next_dts = VAR_1->dts; av_init_packet(&out_pkt); VAR_6 = av_parser_parse2(st->parser, st->codec,
&out_pkt.data, &out_pkt.VAR_3, data, VAR_3,
VAR_1->pts, VAR_1->dts, VAR_1->pos); VAR_1->pts = VAR_1->dts = AV_NOPTS_VALUE; VAR_1->pos = -1; data += VAR_6; VAR_3 -= VAR_6; VAR_5 = !!out_pkt.VAR_3; if (!out_pkt.VAR_3)
continue; if (VAR_1->side_data) { out_pkt.side_data       = VAR_1->side_data; out_pkt.side_data_elems = VAR_1->side_data_elems; VAR_1->side_data          = NULL; VAR_1->side_data_elems    = 0; } out_pkt.duration = (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? VAR_1->duration : 0; if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { if (st->codec->sample_rate > 0) { out_pkt.duration =
av_rescale_q_rnd(st->parser->duration,
(AVRational) { 1, st->codec->sample_rate }, st->time_base,
AV_ROUND_DOWN); } } out_pkt.VAR_2 = st->index; out_pkt.pts          = st->parser->pts; out_pkt.dts          = st->parser->dts; out_pkt.pos          = st->parser->pos; if (st->need_parsing == AVSTREAM_PARSE_FULL_RAW)
out_pkt.pos = st->parser->frame_offset; if (st->parser->key_frame == 1 ||
(st->parser->key_frame == -1 &&
st->parser->pict_type == AV_PICTURE_TYPE_I))
out_pkt.flags |= AV_PKT_FLAG_KEY; if (st->parser->key_frame == -1 && st->parser->pict_type ==AV_PICTURE_TYPE_NONE && (VAR_1->flags&AV_PKT_FLAG_KEY))
out_pkt.flags |= AV_PKT_FLAG_KEY; compute_pkt_fields(VAR_0, st, st->parser, &out_pkt, next_dts, next_pts); if ((VAR_4 = add_to_pktbuf(&VAR_0->internal->parse_queue, &out_pkt,
&VAR_0->internal->parse_queue_end,
1))) { av_packet_unref(&out_pkt); goto fail; } } if (VAR_1 == &flush_pkt) { av_parser_close(st->parser); st->parser = NULL; } fail:
av_packet_unref(VAR_1); return VAR_4; }