static int av_seek_frame_generic(AVFormatContext *s,

                                 int stream_index, int64_t timestamp, int flags)

{

    int index;

    AVStream *st;

    AVIndexEntry *ie;



    st = s->streams[stream_index];



    index = av_index_search_timestamp(st, timestamp, flags);



    if(index < 0 || index==st->nb_index_entries-1){

        int i;

        AVPacket pkt;



        if(st->nb_index_entries){

            assert(st->index_entries);

            ie= &st->index_entries[st->nb_index_entries-1];

            url_fseek(s->pb, ie->pos, SEEK_SET);

            av_update_cur_dts(s, st, ie->timestamp);

        }else

            url_fseek(s->pb, 0, SEEK_SET);



        for(i=0;; i++) {

            int ret = av_read_frame(s, &pkt);

            if(ret<0)

                break;

            av_free_packet(&pkt);

            if(stream_index == pkt.stream_index){

                if((pkt.flags & PKT_FLAG_KEY) && pkt.dts > timestamp)

                    break;

            }

        }

        index = av_index_search_timestamp(st, timestamp, flags);

    }

    if (index < 0)

        return -1;



    av_read_frame_flush(s);

    if (s->iformat->read_seek){

        if(s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0)

            return 0;

    }

    ie = &st->index_entries[index];

    url_fseek(s->pb, ie->pos, SEEK_SET);



    av_update_cur_dts(s, st, ie->timestamp);



    return 0;

}

static int av_seek_frame_generic(AVFormatContext *s,

                                 int stream_index, int64_t timestamp, int flags)

{

    int index;

    AVStream *st;

    AVIndexEntry *ie;



    st = s->streams[stream_index];



    index = av_index_search_timestamp(st, timestamp, flags);



    if(index < 0 || index==st->nb_index_entries-1){

        int i;

        AVPacket pkt;



        if(st->nb_index_entries){

            assert(st->index_entries);

            ie= &st->index_entries[st->nb_index_entries-1];

            url_fseek(s->pb, ie->pos, SEEK_SET);

            av_update_cur_dts(s, st, ie->timestamp);

        }else

            url_fseek(s->pb, 0, SEEK_SET);



        for(i=0;; i++) {

            int ret = av_read_frame(s, &pkt);

            if(ret<0)

                break;

            av_free_packet(&pkt);

            if(stream_index == pkt.stream_index){

                if((pkt.flags & PKT_FLAG_KEY) && pkt.dts > timestamp)

                    break;

            }

        }

        index = av_index_search_timestamp(st, timestamp, flags);

    }

    if (index < 0)

        return -1;



    av_read_frame_flush(s);

    if (s->iformat->read_seek){

        if(s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0)

            return 0;

    }

    ie = &st->index_entries[index];

    url_fseek(s->pb, ie->pos, SEEK_SET);



    av_update_cur_dts(s, st, ie->timestamp);



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0,

                                 int VAR_1, int64_t VAR_2, int VAR_3)

{

    int VAR_4;

    AVStream *st;

    AVIndexEntry *ie;



    st = VAR_0->streams[VAR_1];



    VAR_4 = av_index_search_timestamp(st, VAR_2, VAR_3);



    if(VAR_4 < 0 || VAR_4==st->nb_index_entries-1){

        int VAR_5;

        AVPacket pkt;



        if(st->nb_index_entries){

            assert(st->index_entries);

            ie= &st->index_entries[st->nb_index_entries-1];

            url_fseek(VAR_0->pb, ie->pos, SEEK_SET);

            av_update_cur_dts(VAR_0, st, ie->VAR_2);

        }else

            url_fseek(VAR_0->pb, 0, SEEK_SET);



        for(VAR_5=0;; VAR_5++) {

            int VAR_6 = av_read_frame(VAR_0, &pkt);

            if(VAR_6<0)

                break;

            av_free_packet(&pkt);

            if(VAR_1 == pkt.VAR_1){

                if((pkt.VAR_3 & PKT_FLAG_KEY) && pkt.dts > VAR_2)

                    break;

            }

        }

        VAR_4 = av_index_search_timestamp(st, VAR_2, VAR_3);

    }

    if (VAR_4 < 0)

        return -1;



    av_read_frame_flush(VAR_0);

    if (VAR_0->iformat->read_seek){

        if(VAR_0->iformat->read_seek(VAR_0, VAR_1, VAR_2, VAR_3) >= 0)

            return 0;

    }

    ie = &st->index_entries[VAR_4];

    url_fseek(VAR_0->pb, ie->pos, SEEK_SET);



    av_update_cur_dts(VAR_0, st, ie->VAR_2);



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0,
int VAR_1, int64_t VAR_2, int VAR_3)
{ int VAR_4; AVStream *st; AVIndexEntry *ie; st = VAR_0->streams[VAR_1]; VAR_4 = av_index_search_timestamp(st, VAR_2, VAR_3); if(VAR_4 < 0 || VAR_4==st->nb_index_entries-1){ int VAR_5; AVPacket pkt; if(st->nb_index_entries){ assert(st->index_entries); ie= &st->index_entries[st->nb_index_entries-1]; url_fseek(VAR_0->pb, ie->pos, SEEK_SET); av_update_cur_dts(VAR_0, st, ie->VAR_2); }else url_fseek(VAR_0->pb, 0, SEEK_SET); for(VAR_5=0;; VAR_5++) { int VAR_6 = av_read_frame(VAR_0, &pkt); if(VAR_6<0)
break; av_free_packet(&pkt); if(VAR_1 == pkt.VAR_1){ if((pkt.VAR_3 & PKT_FLAG_KEY) && pkt.dts > VAR_2)
break; } } VAR_4 = av_index_search_timestamp(st, VAR_2, VAR_3); } if (VAR_4 < 0)
return -1; av_read_frame_flush(VAR_0); if (VAR_0->iformat->read_seek){ if(VAR_0->iformat->read_seek(VAR_0, VAR_1, VAR_2, VAR_3) >= 0)
return 0; } ie = &st->index_entries[VAR_4]; url_fseek(VAR_0->pb, ie->pos, SEEK_SET); av_update_cur_dts(VAR_0, st, ie->VAR_2); return 0; }