static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)

{

    AVStream *st;

    int len, ret, i;



    av_init_packet(pkt);



    for(;;) {

        /* select current input stream component */

        st = s->cur_st;

        if (st) {

            if (!st->need_parsing || !st->parser) {

                /* no parsing needed: we just output the packet as is */

                /* raw data support */

                *pkt = st->cur_pkt; st->cur_pkt.data= NULL;

                compute_pkt_fields(s, st, NULL, pkt);

                s->cur_st = NULL;

                if ((s->iformat->flags & AVFMT_GENERIC_INDEX) &&

                    (pkt->flags & AV_PKT_FLAG_KEY) && pkt->dts != AV_NOPTS_VALUE) {

                    ff_reduce_index(s, st->index);

                    av_add_index_entry(st, pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME);

                }

                break;

            } else if (st->cur_len > 0 && st->discard < AVDISCARD_ALL) {

                len = av_parser_parse2(st->parser, st->codec, &pkt->data, &pkt->size,

                                       st->cur_ptr, st->cur_len,

                                       st->cur_pkt.pts, st->cur_pkt.dts,

                                       st->cur_pkt.pos);

                st->cur_pkt.pts = AV_NOPTS_VALUE;

                st->cur_pkt.dts = AV_NOPTS_VALUE;

                /* increment read pointer */

                st->cur_ptr += len;

                st->cur_len -= len;



                /* return packet if any */

                if (pkt->size) {

                got_packet:

                    pkt->duration = 0;

                    pkt->stream_index = st->index;

                    pkt->pts = st->parser->pts;

                    pkt->dts = st->parser->dts;

                    pkt->pos = st->parser->pos;

                    if(pkt->data == st->cur_pkt.data && pkt->size == st->cur_pkt.size){

                        s->cur_st = NULL;

                        pkt->destruct= st->cur_pkt.destruct;

                        st->cur_pkt.destruct= NULL;

                        st->cur_pkt.data    = NULL;

                        assert(st->cur_len == 0);

                    }else{

                        pkt->destruct = NULL;

                    }

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



                    if((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY){

                        int64_t pos= (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->pos : st->parser->frame_offset;

                        ff_reduce_index(s, st->index);

                        av_add_index_entry(st, pos, pkt->dts,

                                           0, 0, AVINDEX_KEYFRAME);

                    }



                    break;

                }

            } else {

                /* free packet */

                av_free_packet(&st->cur_pkt);

                s->cur_st = NULL;

            }

        } else {

            AVPacket cur_pkt;

            /* read next packet */

            ret = av_read_packet(s, &cur_pkt);

            if (ret < 0) {

                if (ret == AVERROR(EAGAIN))

                    return ret;

                /* return the last frames, if any */

                for(i = 0; i < s->nb_streams; i++) {

                    st = s->streams[i];

                    if (st->parser && st->need_parsing) {

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

                                        &pkt->data, &pkt->size,

                                        NULL, 0,

                                        AV_NOPTS_VALUE, AV_NOPTS_VALUE,

                                        AV_NOPTS_VALUE);

                        if (pkt->size)

                            goto got_packet;

                    }

                }

                /* no more packets: really terminate parsing */

                return ret;

            }

            st = s->streams[cur_pkt.stream_index];

            st->cur_pkt= cur_pkt;



            if(st->cur_pkt.pts != AV_NOPTS_VALUE &&

               st->cur_pkt.dts != AV_NOPTS_VALUE &&

               st->cur_pkt.pts < st->cur_pkt.dts){

                av_log(s, AV_LOG_WARNING, "Invalid timestamps stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d\n",

                    st->cur_pkt.stream_index,

                    st->cur_pkt.pts,

                    st->cur_pkt.dts,

                    st->cur_pkt.size);

//                av_free_packet(&st->cur_pkt);

//                return -1;

            }



            if(s->debug & FF_FDEBUG_TS)

                av_log(s, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n",

                    st->cur_pkt.stream_index,

                    st->cur_pkt.pts,

                    st->cur_pkt.dts,

                    st->cur_pkt.size,

                    st->cur_pkt.duration,

                    st->cur_pkt.flags);



            s->cur_st = st;

            st->cur_ptr = st->cur_pkt.data;

            st->cur_len = st->cur_pkt.size;

            if (st->need_parsing && !st->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) {

                st->parser = av_parser_init(st->codec->codec_id);

                if (!st->parser) {

                    av_log(s, AV_LOG_WARNING, "parser not found for codec "

                           "%s, packets or times may be invalid.\n",

                           avcodec_get_name(st->codec->codec_id));

                    /* no parser available: just output the raw packets */

                    st->need_parsing = AVSTREAM_PARSE_NONE;

                }else if(st->need_parsing == AVSTREAM_PARSE_HEADERS){

                    st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;

                }else if(st->need_parsing == AVSTREAM_PARSE_FULL_ONCE){

                    st->parser->flags |= PARSER_FLAG_ONCE;

                }

            }

        }

    }

    if(s->debug & FF_FDEBUG_TS)

        av_log(s, AV_LOG_DEBUG, "read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n",

            pkt->stream_index,

            pkt->pts,

            pkt->dts,

            pkt->size,

            pkt->duration,

            pkt->flags);



    return 0;

}

static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)

{

    AVStream *st;

    int len, ret, i;



    av_init_packet(pkt);



    for(;;) {

        

        st = s->cur_st;

        if (st) {

            if (!st->need_parsing || !st->parser) {

                

                

                *pkt = st->cur_pkt; st->cur_pkt.data= NULL;

                compute_pkt_fields(s, st, NULL, pkt);

                s->cur_st = NULL;

                if ((s->iformat->flags & AVFMT_GENERIC_INDEX) &&

                    (pkt->flags & AV_PKT_FLAG_KEY) && pkt->dts != AV_NOPTS_VALUE) {

                    ff_reduce_index(s, st->index);

                    av_add_index_entry(st, pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME);

                }

                break;

            } else if (st->cur_len > 0 && st->discard < AVDISCARD_ALL) {

                len = av_parser_parse2(st->parser, st->codec, &pkt->data, &pkt->size,

                                       st->cur_ptr, st->cur_len,

                                       st->cur_pkt.pts, st->cur_pkt.dts,

                                       st->cur_pkt.pos);

                st->cur_pkt.pts = AV_NOPTS_VALUE;

                st->cur_pkt.dts = AV_NOPTS_VALUE;

                

                st->cur_ptr += len;

                st->cur_len -= len;



                

                if (pkt->size) {

                got_packet:

                    pkt->duration = 0;

                    pkt->stream_index = st->index;

                    pkt->pts = st->parser->pts;

                    pkt->dts = st->parser->dts;

                    pkt->pos = st->parser->pos;

                    if(pkt->data == st->cur_pkt.data && pkt->size == st->cur_pkt.size){

                        s->cur_st = NULL;

                        pkt->destruct= st->cur_pkt.destruct;

                        st->cur_pkt.destruct= NULL;

                        st->cur_pkt.data    = NULL;

                        assert(st->cur_len == 0);

                    }else{

                        pkt->destruct = NULL;

                    }

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



                    if((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY){

                        int64_t pos= (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->pos : st->parser->frame_offset;

                        ff_reduce_index(s, st->index);

                        av_add_index_entry(st, pos, pkt->dts,

                                           0, 0, AVINDEX_KEYFRAME);

                    }



                    break;

                }

            } else {

                

                av_free_packet(&st->cur_pkt);

                s->cur_st = NULL;

            }

        } else {

            AVPacket cur_pkt;

            

            ret = av_read_packet(s, &cur_pkt);

            if (ret < 0) {

                if (ret == AVERROR(EAGAIN))

                    return ret;

                

                for(i = 0; i < s->nb_streams; i++) {

                    st = s->streams[i];

                    if (st->parser && st->need_parsing) {

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

                                        &pkt->data, &pkt->size,

                                        NULL, 0,

                                        AV_NOPTS_VALUE, AV_NOPTS_VALUE,

                                        AV_NOPTS_VALUE);

                        if (pkt->size)

                            goto got_packet;

                    }

                }

                

                return ret;

            }

            st = s->streams[cur_pkt.stream_index];

            st->cur_pkt= cur_pkt;



            if(st->cur_pkt.pts != AV_NOPTS_VALUE &&

               st->cur_pkt.dts != AV_NOPTS_VALUE &&

               st->cur_pkt.pts < st->cur_pkt.dts){

                av_log(s, AV_LOG_WARNING, "Invalid timestamps stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d\n",

                    st->cur_pkt.stream_index,

                    st->cur_pkt.pts,

                    st->cur_pkt.dts,

                    st->cur_pkt.size);





            }



            if(s->debug & FF_FDEBUG_TS)

                av_log(s, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n",

                    st->cur_pkt.stream_index,

                    st->cur_pkt.pts,

                    st->cur_pkt.dts,

                    st->cur_pkt.size,

                    st->cur_pkt.duration,

                    st->cur_pkt.flags);



            s->cur_st = st;

            st->cur_ptr = st->cur_pkt.data;

            st->cur_len = st->cur_pkt.size;

            if (st->need_parsing && !st->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) {

                st->parser = av_parser_init(st->codec->codec_id);

                if (!st->parser) {

                    av_log(s, AV_LOG_WARNING, "parser not found for codec "

                           "%s, packets or times may be invalid.\n",

                           avcodec_get_name(st->codec->codec_id));

                    

                    st->need_parsing = AVSTREAM_PARSE_NONE;

                }else if(st->need_parsing == AVSTREAM_PARSE_HEADERS){

                    st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;

                }else if(st->need_parsing == AVSTREAM_PARSE_FULL_ONCE){

                    st->parser->flags |= PARSER_FLAG_ONCE;

                }

            }

        }

    }

    if(s->debug & FF_FDEBUG_TS)

        av_log(s, AV_LOG_DEBUG, "read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n",

            pkt->stream_index,

            pkt->pts,

            pkt->dts,

            pkt->size,

            pkt->duration,

            pkt->flags);



    return 0;

}

                *pkt = st->cur_pkt; st->cur_pkt.data= NULL;
static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    AVStream *st;

    int VAR_2, VAR_3, VAR_4;



    av_init_packet(VAR_1);



    for(;;) {

        

        st = VAR_0->cur_st;

        if (st) {

            if (!st->need_parsing || !st->parser) {

                

                

                *VAR_1 = st->cur_pkt; st->cur_pkt.data= NULL;

                compute_pkt_fields(VAR_0, st, NULL, VAR_1);

                VAR_0->cur_st = NULL;

                if ((VAR_0->iformat->flags & AVFMT_GENERIC_INDEX) &&

                    (VAR_1->flags & AV_PKT_FLAG_KEY) && VAR_1->dts != AV_NOPTS_VALUE) {

                    ff_reduce_index(VAR_0, st->index);

                    av_add_index_entry(st, VAR_1->pos, VAR_1->dts, 0, 0, AVINDEX_KEYFRAME);

                }

                break;

            } else if (st->cur_len > 0 && st->discard < AVDISCARD_ALL) {

                VAR_2 = av_parser_parse2(st->parser, st->codec, &VAR_1->data, &VAR_1->size,

                                       st->cur_ptr, st->cur_len,

                                       st->cur_pkt.pts, st->cur_pkt.dts,

                                       st->cur_pkt.pos);

                st->cur_pkt.pts = AV_NOPTS_VALUE;

                st->cur_pkt.dts = AV_NOPTS_VALUE;

                

                st->cur_ptr += VAR_2;

                st->cur_len -= VAR_2;



                

                if (VAR_1->size) {

                got_packet:

                    VAR_1->duration = 0;

                    VAR_1->stream_index = st->index;

                    VAR_1->pts = st->parser->pts;

                    VAR_1->dts = st->parser->dts;

                    VAR_1->pos = st->parser->pos;

                    if(VAR_1->data == st->cur_pkt.data && VAR_1->size == st->cur_pkt.size){

                        VAR_0->cur_st = NULL;

                        VAR_1->destruct= st->cur_pkt.destruct;

                        st->cur_pkt.destruct= NULL;

                        st->cur_pkt.data    = NULL;

                        assert(st->cur_len == 0);

                    }else{

                        VAR_1->destruct = NULL;

                    }

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



                    if((VAR_0->iformat->flags & AVFMT_GENERIC_INDEX) && VAR_1->flags & AV_PKT_FLAG_KEY){

                        int64_t pos= (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? VAR_1->pos : st->parser->frame_offset;

                        ff_reduce_index(VAR_0, st->index);

                        av_add_index_entry(st, pos, VAR_1->dts,

                                           0, 0, AVINDEX_KEYFRAME);

                    }



                    break;

                }

            } else {

                

                av_free_packet(&st->cur_pkt);

                VAR_0->cur_st = NULL;

            }

        } else {

            AVPacket cur_pkt;

            

            VAR_3 = av_read_packet(VAR_0, &cur_pkt);

            if (VAR_3 < 0) {

                if (VAR_3 == AVERROR(EAGAIN))

                    return VAR_3;

                

                for(VAR_4 = 0; VAR_4 < VAR_0->nb_streams; VAR_4++) {

                    st = VAR_0->streams[VAR_4];

                    if (st->parser && st->need_parsing) {

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

                                        &VAR_1->data, &VAR_1->size,

                                        NULL, 0,

                                        AV_NOPTS_VALUE, AV_NOPTS_VALUE,

                                        AV_NOPTS_VALUE);

                        if (VAR_1->size)

                            goto got_packet;

                    }

                }

                

                return VAR_3;

            }

            st = VAR_0->streams[cur_pkt.stream_index];

            st->cur_pkt= cur_pkt;



            if(st->cur_pkt.pts != AV_NOPTS_VALUE &&

               st->cur_pkt.dts != AV_NOPTS_VALUE &&

               st->cur_pkt.pts < st->cur_pkt.dts){

                av_log(VAR_0, AV_LOG_WARNING, "Invalid timestamps stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d\n",

                    st->cur_pkt.stream_index,

                    st->cur_pkt.pts,

                    st->cur_pkt.dts,

                    st->cur_pkt.size);





            }



            if(VAR_0->debug & FF_FDEBUG_TS)

                av_log(VAR_0, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n",

                    st->cur_pkt.stream_index,

                    st->cur_pkt.pts,

                    st->cur_pkt.dts,

                    st->cur_pkt.size,

                    st->cur_pkt.duration,

                    st->cur_pkt.flags);



            VAR_0->cur_st = st;

            st->cur_ptr = st->cur_pkt.data;

            st->cur_len = st->cur_pkt.size;

            if (st->need_parsing && !st->parser && !(VAR_0->flags & AVFMT_FLAG_NOPARSE)) {

                st->parser = av_parser_init(st->codec->codec_id);

                if (!st->parser) {

                    av_log(VAR_0, AV_LOG_WARNING, "parser not found for codec "

                           "%VAR_0, packets or times may be invalid.\n",

                           avcodec_get_name(st->codec->codec_id));

                    

                    st->need_parsing = AVSTREAM_PARSE_NONE;

                }else if(st->need_parsing == AVSTREAM_PARSE_HEADERS){

                    st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;

                }else if(st->need_parsing == AVSTREAM_PARSE_FULL_ONCE){

                    st->parser->flags |= PARSER_FLAG_ONCE;

                }

            }

        }

    }

    if(VAR_0->debug & FF_FDEBUG_TS)

        av_log(VAR_0, AV_LOG_DEBUG, "FUNC_0 stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n",

            VAR_1->stream_index,

            VAR_1->pts,

            VAR_1->dts,

            VAR_1->size,

            VAR_1->duration,

            VAR_1->flags);



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ AVStream *st; int VAR_2, VAR_3, VAR_4; av_init_packet(VAR_1); for(;;) { st = VAR_0->cur_st; if (st) { if (!st->need_parsing || !st->parser) { *VAR_1 = st->cur_pkt; st->cur_pkt.data= NULL; compute_pkt_fields(VAR_0, st, NULL, VAR_1); VAR_0->cur_st = NULL; if ((VAR_0->iformat->flags & AVFMT_GENERIC_INDEX) &&
(VAR_1->flags & AV_PKT_FLAG_KEY) && VAR_1->dts != AV_NOPTS_VALUE) { ff_reduce_index(VAR_0, st->index); av_add_index_entry(st, VAR_1->pos, VAR_1->dts, 0, 0, AVINDEX_KEYFRAME); } break; } else if (st->cur_len > 0 && st->discard < AVDISCARD_ALL) { VAR_2 = av_parser_parse2(st->parser, st->codec, &VAR_1->data, &VAR_1->size,
st->cur_ptr, st->cur_len,
st->cur_pkt.pts, st->cur_pkt.dts,
st->cur_pkt.pos); st->cur_pkt.pts = AV_NOPTS_VALUE; st->cur_pkt.dts = AV_NOPTS_VALUE; st->cur_ptr += VAR_2; st->cur_len -= VAR_2; if (VAR_1->size) { got_packet:
VAR_1->duration = 0; VAR_1->stream_index = st->index; VAR_1->pts = st->parser->pts; VAR_1->dts = st->parser->dts; VAR_1->pos = st->parser->pos; if(VAR_1->data == st->cur_pkt.data && VAR_1->size == st->cur_pkt.size){ VAR_0->cur_st = NULL; VAR_1->destruct= st->cur_pkt.destruct; st->cur_pkt.destruct= NULL; st->cur_pkt.data    = NULL; assert(st->cur_len == 0); }else{ VAR_1->destruct = NULL; } compute_pkt_fields(VAR_0, st, st->parser, VAR_1); if((VAR_0->iformat->flags & AVFMT_GENERIC_INDEX) && VAR_1->flags & AV_PKT_FLAG_KEY){ int64_t pos= (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? VAR_1->pos : st->parser->frame_offset; ff_reduce_index(VAR_0, st->index); av_add_index_entry(st, pos, VAR_1->dts,
0, 0, AVINDEX_KEYFRAME); } break; } } else { av_free_packet(&st->cur_pkt); VAR_0->cur_st = NULL; } } else { AVPacket cur_pkt; VAR_3 = av_read_packet(VAR_0, &cur_pkt); if (VAR_3 < 0) { if (VAR_3 == AVERROR(EAGAIN))
return VAR_3; for(VAR_4 = 0; VAR_4 < VAR_0->nb_streams; VAR_4++) { st = VAR_0->streams[VAR_4]; if (st->parser && st->need_parsing) { av_parser_parse2(st->parser, st->codec,
&VAR_1->data, &VAR_1->size,
NULL, 0,
AV_NOPTS_VALUE, AV_NOPTS_VALUE,
AV_NOPTS_VALUE); if (VAR_1->size)
goto got_packet; } } return VAR_3; } st = VAR_0->streams[cur_pkt.stream_index]; st->cur_pkt= cur_pkt; if(st->cur_pkt.pts != AV_NOPTS_VALUE &&
st->cur_pkt.dts != AV_NOPTS_VALUE &&
st->cur_pkt.pts < st->cur_pkt.dts){ av_log(VAR_0, AV_LOG_WARNING, "Invalid timestamps stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d\n",
st->cur_pkt.stream_index,
st->cur_pkt.pts,
st->cur_pkt.dts,
st->cur_pkt.size); } if(VAR_0->debug & FF_FDEBUG_TS)
av_log(VAR_0, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n",
st->cur_pkt.stream_index,
st->cur_pkt.pts,
st->cur_pkt.dts,
st->cur_pkt.size,
st->cur_pkt.duration,
st->cur_pkt.flags); VAR_0->cur_st = st; st->cur_ptr = st->cur_pkt.data; st->cur_len = st->cur_pkt.size; if (st->need_parsing && !st->parser && !(VAR_0->flags & AVFMT_FLAG_NOPARSE)) { st->parser = av_parser_init(st->codec->codec_id); if (!st->parser) { av_log(VAR_0, AV_LOG_WARNING, "parser not found for codec "
"%VAR_0, packets or times may be invalid.\n",
avcodec_get_name(st->codec->codec_id)); st->need_parsing = AVSTREAM_PARSE_NONE; }else if(st->need_parsing == AVSTREAM_PARSE_HEADERS){ st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; }else if(st->need_parsing == AVSTREAM_PARSE_FULL_ONCE){ st->parser->flags |= PARSER_FLAG_ONCE; } } } } if(VAR_0->debug & FF_FDEBUG_TS)
av_log(VAR_0, AV_LOG_DEBUG, "FUNC_0 stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n",
VAR_1->stream_index,
VAR_1->pts,
VAR_1->dts,
VAR_1->size,
VAR_1->duration,
VAR_1->flags); return 0; }