int av_read_frame(AVFormatContext *s, AVPacket *pkt)

{

    const int genpts = s->flags & AVFMT_FLAG_GENPTS;

    int eof = 0;



    if (!genpts)

        return s->internal->packet_buffer

               ? read_from_packet_buffer(&s->internal->packet_buffer,

                                         &s->internal->packet_buffer_end, pkt)

               : read_frame_internal(s, pkt);



    for (;;) {

        int ret;

        AVPacketList *pktl = s->internal->packet_buffer;



        if (pktl) {

            AVPacket *next_pkt = &pktl->pkt;



            if (next_pkt->dts != AV_NOPTS_VALUE) {

                int wrap_bits = s->streams[next_pkt->stream_index]->pts_wrap_bits;

                while (pktl && next_pkt->pts == AV_NOPTS_VALUE) {

                    if (pktl->pkt.stream_index == next_pkt->stream_index &&

                        (av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2LL << (wrap_bits - 1)) < 0) &&

                         av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2LL << (wrap_bits - 1))) {

                        // not B-frame

                        next_pkt->pts = pktl->pkt.dts;

                    }

                    pktl = pktl->next;

                }

                pktl = s->internal->packet_buffer;

            }



            /* read packet from packet buffer, if there is data */

            if (!(next_pkt->pts == AV_NOPTS_VALUE &&

                  next_pkt->dts != AV_NOPTS_VALUE && !eof))

                return read_from_packet_buffer(&s->internal->packet_buffer,

                                               &s->internal->packet_buffer_end, pkt);

        }



        ret = read_frame_internal(s, pkt);

        if (ret < 0) {

            if (pktl && ret != AVERROR(EAGAIN)) {

                eof = 1;

                continue;

            } else

                return ret;

        }



        if (av_dup_packet(add_to_pktbuf(&s->internal->packet_buffer, pkt,

                                        &s->internal->packet_buffer_end)) < 0)

            return AVERROR(ENOMEM);

    }

}

int av_read_frame(AVFormatContext *s, AVPacket *pkt)

{

    const int genpts = s->flags & AVFMT_FLAG_GENPTS;

    int eof = 0;



    if (!genpts)

        return s->internal->packet_buffer

               ? read_from_packet_buffer(&s->internal->packet_buffer,

                                         &s->internal->packet_buffer_end, pkt)

               : read_frame_internal(s, pkt);



    for (;;) {

        int ret;

        AVPacketList *pktl = s->internal->packet_buffer;



        if (pktl) {

            AVPacket *next_pkt = &pktl->pkt;



            if (next_pkt->dts != AV_NOPTS_VALUE) {

                int wrap_bits = s->streams[next_pkt->stream_index]->pts_wrap_bits;

                while (pktl && next_pkt->pts == AV_NOPTS_VALUE) {

                    if (pktl->pkt.stream_index == next_pkt->stream_index &&

                        (av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2LL << (wrap_bits - 1)) < 0) &&

                         av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2LL << (wrap_bits - 1))) {

                        

                        next_pkt->pts = pktl->pkt.dts;

                    }

                    pktl = pktl->next;

                }

                pktl = s->internal->packet_buffer;

            }



            

            if (!(next_pkt->pts == AV_NOPTS_VALUE &&

                  next_pkt->dts != AV_NOPTS_VALUE && !eof))

                return read_from_packet_buffer(&s->internal->packet_buffer,

                                               &s->internal->packet_buffer_end, pkt);

        }



        ret = read_frame_internal(s, pkt);

        if (ret < 0) {

            if (pktl && ret != AVERROR(EAGAIN)) {

                eof = 1;

                continue;

            } else

                return ret;

        }



        if (av_dup_packet(add_to_pktbuf(&s->internal->packet_buffer, pkt,

                                        &s->internal->packet_buffer_end)) < 0)

            return AVERROR(ENOMEM);

    }

}

int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    const int VAR_2 = VAR_0->flags & AVFMT_FLAG_GENPTS;

    int VAR_3 = 0;



    if (!VAR_2)

        return VAR_0->internal->packet_buffer

               ? read_from_packet_buffer(&VAR_0->internal->packet_buffer,

                                         &VAR_0->internal->packet_buffer_end, VAR_1)

               : read_frame_internal(VAR_0, VAR_1);



    for (;;) {

        int VAR_4;

        AVPacketList *pktl = VAR_0->internal->packet_buffer;



        if (pktl) {

            AVPacket *next_pkt = &pktl->VAR_1;



            if (next_pkt->dts != AV_NOPTS_VALUE) {

                int VAR_5 = VAR_0->streams[next_pkt->stream_index]->pts_wrap_bits;

                while (pktl && next_pkt->pts == AV_NOPTS_VALUE) {

                    if (pktl->VAR_1.stream_index == next_pkt->stream_index &&

                        (av_compare_mod(next_pkt->dts, pktl->VAR_1.dts, 2LL << (VAR_5 - 1)) < 0) &&

                         av_compare_mod(pktl->VAR_1.pts, pktl->VAR_1.dts, 2LL << (VAR_5 - 1))) {

                        

                        next_pkt->pts = pktl->VAR_1.dts;

                    }

                    pktl = pktl->next;

                }

                pktl = VAR_0->internal->packet_buffer;

            }



            

            if (!(next_pkt->pts == AV_NOPTS_VALUE &&

                  next_pkt->dts != AV_NOPTS_VALUE && !VAR_3))

                return read_from_packet_buffer(&VAR_0->internal->packet_buffer,

                                               &VAR_0->internal->packet_buffer_end, VAR_1);

        }



        VAR_4 = read_frame_internal(VAR_0, VAR_1);

        if (VAR_4 < 0) {

            if (pktl && VAR_4 != AVERROR(EAGAIN)) {

                VAR_3 = 1;

                continue;

            } else

                return VAR_4;

        }



        if (av_dup_packet(add_to_pktbuf(&VAR_0->internal->packet_buffer, VAR_1,

                                        &VAR_0->internal->packet_buffer_end)) < 0)

            return AVERROR(ENOMEM);

    }

}

int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ const int VAR_2 = VAR_0->flags & AVFMT_FLAG_GENPTS; int VAR_3 = 0; if (!VAR_2)
return VAR_0->internal->packet_buffer
? read_from_packet_buffer(&VAR_0->internal->packet_buffer,
&VAR_0->internal->packet_buffer_end, VAR_1)
: read_frame_internal(VAR_0, VAR_1); for (;;) { int VAR_4; AVPacketList *pktl = VAR_0->internal->packet_buffer; if (pktl) { AVPacket *next_pkt = &pktl->VAR_1; if (next_pkt->dts != AV_NOPTS_VALUE) { int VAR_5 = VAR_0->streams[next_pkt->stream_index]->pts_wrap_bits; while (pktl && next_pkt->pts == AV_NOPTS_VALUE) { if (pktl->VAR_1.stream_index == next_pkt->stream_index &&
(av_compare_mod(next_pkt->dts, pktl->VAR_1.dts, 2LL << (VAR_5 - 1)) < 0) &&
av_compare_mod(pktl->VAR_1.pts, pktl->VAR_1.dts, 2LL << (VAR_5 - 1))) { next_pkt->pts = pktl->VAR_1.dts; } pktl = pktl->next; } pktl = VAR_0->internal->packet_buffer; } if (!(next_pkt->pts == AV_NOPTS_VALUE &&
next_pkt->dts != AV_NOPTS_VALUE && !VAR_3))
return read_from_packet_buffer(&VAR_0->internal->packet_buffer,
&VAR_0->internal->packet_buffer_end, VAR_1); } VAR_4 = read_frame_internal(VAR_0, VAR_1); if (VAR_4 < 0) { if (pktl && VAR_4 != AVERROR(EAGAIN)) { VAR_3 = 1; continue; } else return VAR_4; } if (av_dup_packet(add_to_pktbuf(&VAR_0->internal->packet_buffer, VAR_1,
&VAR_0->internal->packet_buffer_end)) < 0)
return AVERROR(ENOMEM); } }