static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)

{

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

    MPCContext *c = s->priv_data;

    AVPacket pkt1, *pkt = &pkt1;

    int ret;

    int index = av_index_search_timestamp(st, timestamp - DELAY_FRAMES, flags);

    uint32_t lastframe;



    /* if found, seek there */

    if (index >= 0){

        c->curframe = st->index_entries[index].pos;

        return 0;

    }

    /* if timestamp is out of bounds, return error */

    if(timestamp < 0 || timestamp >= c->fcount)

        return -1;

    timestamp -= DELAY_FRAMES;

    /* seek to the furthest known position and read packets until

       we reach desired position */

    lastframe = c->curframe;

    if(c->frames_noted) c->curframe = c->frames_noted - 1;

    while(c->curframe < timestamp){

        ret = av_read_frame(s, pkt);

        if (ret < 0){

            c->curframe = lastframe;

            return ret;

        }

        av_free_packet(pkt);

    }

    return 0;

}

static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)

{

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

    MPCContext *c = s->priv_data;

    AVPacket pkt1, *pkt = &pkt1;

    int ret;

    int index = av_index_search_timestamp(st, timestamp - DELAY_FRAMES, flags);

    uint32_t lastframe;



    

    if (index >= 0){

        c->curframe = st->index_entries[index].pos;

        return 0;

    }

    

    if(timestamp < 0 || timestamp >= c->fcount)

        return -1;

    timestamp -= DELAY_FRAMES;

    



    lastframe = c->curframe;

    if(c->frames_noted) c->curframe = c->frames_noted - 1;

    while(c->curframe < timestamp){

        ret = av_read_frame(s, pkt);

        if (ret < 0){

            c->curframe = lastframe;

            return ret;

        }

        av_free_packet(pkt);

    }

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, int VAR_1, int64_t VAR_2, int VAR_3)

{

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

    MPCContext *c = VAR_0->priv_data;

    AVPacket pkt1, *pkt = &pkt1;

    int VAR_4;

    int VAR_5 = av_index_search_timestamp(st, VAR_2 - DELAY_FRAMES, VAR_3);

    uint32_t lastframe;



    

    if (VAR_5 >= 0){

        c->curframe = st->index_entries[VAR_5].pos;

        return 0;

    }

    

    if(VAR_2 < 0 || VAR_2 >= c->fcount)

        return -1;

    VAR_2 -= DELAY_FRAMES;

    



    lastframe = c->curframe;

    if(c->frames_noted) c->curframe = c->frames_noted - 1;

    while(c->curframe < VAR_2){

        VAR_4 = av_read_frame(VAR_0, pkt);

        if (VAR_4 < 0){

            c->curframe = lastframe;

            return VAR_4;

        }

        av_free_packet(pkt);

    }

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, int VAR_1, int64_t VAR_2, int VAR_3)
{ AVStream *st = VAR_0->streams[VAR_1]; MPCContext *c = VAR_0->priv_data; AVPacket pkt1, *pkt = &pkt1; int VAR_4; int VAR_5 = av_index_search_timestamp(st, VAR_2 - DELAY_FRAMES, VAR_3); uint32_t lastframe; if (VAR_5 >= 0){ c->curframe = st->index_entries[VAR_5].pos; return 0; } if(VAR_2 < 0 || VAR_2 >= c->fcount)
return -1; VAR_2 -= DELAY_FRAMES; lastframe = c->curframe; if(c->frames_noted) c->curframe = c->frames_noted - 1; while(c->curframe < VAR_2){ VAR_4 = av_read_frame(VAR_0, pkt); if (VAR_4 < 0){ c->curframe = lastframe; return VAR_4; } av_free_packet(pkt); } return 0; }