static int read_seek(AVFormatContext *s, int stream_index,

                     int64_t ts, int flags)

{

    WtvContext *wtv = s->priv_data;

    AVIOContext *pb = wtv->pb;

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

    int64_t ts_relative;

    int i;



    if ((flags & AVSEEK_FLAG_FRAME) || (flags & AVSEEK_FLAG_BYTE))

        return AVERROR(ENOSYS);



    /* timestamp adjustment is required because wtv->pts values are absolute,

     * whereas AVIndexEntry->timestamp values are relative to epoch. */

    ts_relative = ts;

    if (wtv->epoch != AV_NOPTS_VALUE)

        ts_relative -= wtv->epoch;



    i = ff_index_search_timestamp(wtv->index_entries, wtv->nb_index_entries, ts_relative, flags);

    if (i < 0) {

        if (wtv->last_valid_pts == AV_NOPTS_VALUE || ts < wtv->last_valid_pts)

            avio_seek(pb, 0, SEEK_SET);

        else if (st->duration != AV_NOPTS_VALUE && ts_relative > st->duration && wtv->nb_index_entries)

            avio_seek(pb, wtv->index_entries[wtv->nb_index_entries - 1].pos, SEEK_SET);

        if (parse_chunks(s, SEEK_TO_PTS, ts, 0) < 0)

            return AVERROR(ERANGE);

        return 0;

    }

    wtv->pts = wtv->index_entries[i].timestamp;

    if (wtv->epoch != AV_NOPTS_VALUE)

        wtv->pts += wtv->epoch;

    wtv->last_valid_pts = wtv->pts;

    avio_seek(pb, wtv->index_entries[i].pos, SEEK_SET);

    return 0;

}

static int read_seek(AVFormatContext *s, int stream_index,

                     int64_t ts, int flags)

{

    WtvContext *wtv = s->priv_data;

    AVIOContext *pb = wtv->pb;

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

    int64_t ts_relative;

    int i;



    if ((flags & AVSEEK_FLAG_FRAME) || (flags & AVSEEK_FLAG_BYTE))

        return AVERROR(ENOSYS);



    



    ts_relative = ts;

    if (wtv->epoch != AV_NOPTS_VALUE)

        ts_relative -= wtv->epoch;



    i = ff_index_search_timestamp(wtv->index_entries, wtv->nb_index_entries, ts_relative, flags);

    if (i < 0) {

        if (wtv->last_valid_pts == AV_NOPTS_VALUE || ts < wtv->last_valid_pts)

            avio_seek(pb, 0, SEEK_SET);

        else if (st->duration != AV_NOPTS_VALUE && ts_relative > st->duration && wtv->nb_index_entries)

            avio_seek(pb, wtv->index_entries[wtv->nb_index_entries - 1].pos, SEEK_SET);

        if (parse_chunks(s, SEEK_TO_PTS, ts, 0) < 0)

            return AVERROR(ERANGE);

        return 0;

    }

    wtv->pts = wtv->index_entries[i].timestamp;

    if (wtv->epoch != AV_NOPTS_VALUE)

        wtv->pts += wtv->epoch;

    wtv->last_valid_pts = wtv->pts;

    avio_seek(pb, wtv->index_entries[i].pos, SEEK_SET);

    return 0;

}

        if (wtv->last_valid_pts == AV_NOPTS_VALUE || ts < wtv->last_valid_pts)             avio_seek(pb, 0, SEEK_SET);         else if (st->duration != AV_NOPTS_VALUE && ts_relative > st->duration && wtv->nb_index_entries)             avio_seek(pb, wtv->index_entries[wtv->nb_index_entries - 1].pos, SEEK_SET);     avio_seek(pb, wtv->index_entries[i].pos, SEEK_SET);
static int FUNC_0(AVFormatContext *VAR_0, int VAR_1,

                     int64_t VAR_2, int VAR_3)

{

    WtvContext *wtv = VAR_0->priv_data;

    AVIOContext *pb = wtv->pb;

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

    int64_t ts_relative;

    int VAR_4;



    if ((VAR_3 & AVSEEK_FLAG_FRAME) || (VAR_3 & AVSEEK_FLAG_BYTE))

        return AVERROR(ENOSYS);



    



    ts_relative = VAR_2;

    if (wtv->epoch != AV_NOPTS_VALUE)

        ts_relative -= wtv->epoch;



    VAR_4 = ff_index_search_timestamp(wtv->index_entries, wtv->nb_index_entries, ts_relative, VAR_3);

    if (VAR_4 < 0) {

        if (wtv->last_valid_pts == AV_NOPTS_VALUE || VAR_2 < wtv->last_valid_pts)

            avio_seek(pb, 0, SEEK_SET);

        else if (st->duration != AV_NOPTS_VALUE && ts_relative > st->duration && wtv->nb_index_entries)

            avio_seek(pb, wtv->index_entries[wtv->nb_index_entries - 1].pos, SEEK_SET);

        if (parse_chunks(VAR_0, SEEK_TO_PTS, VAR_2, 0) < 0)

            return AVERROR(ERANGE);

        return 0;

    }

    wtv->pts = wtv->index_entries[VAR_4].timestamp;

    if (wtv->epoch != AV_NOPTS_VALUE)

        wtv->pts += wtv->epoch;

    wtv->last_valid_pts = wtv->pts;

    avio_seek(pb, wtv->index_entries[VAR_4].pos, SEEK_SET);

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, int VAR_1,
int64_t VAR_2, int VAR_3)
{ WtvContext *wtv = VAR_0->priv_data; AVIOContext *pb = wtv->pb; AVStream *st = VAR_0->streams[0]; int64_t ts_relative; int VAR_4; if ((VAR_3 & AVSEEK_FLAG_FRAME) || (VAR_3 & AVSEEK_FLAG_BYTE))
return AVERROR(ENOSYS); ts_relative = VAR_2; if (wtv->epoch != AV_NOPTS_VALUE)
ts_relative -= wtv->epoch; VAR_4 = ff_index_search_timestamp(wtv->index_entries, wtv->nb_index_entries, ts_relative, VAR_3); if (VAR_4 < 0) { if (wtv->last_valid_pts == AV_NOPTS_VALUE || VAR_2 < wtv->last_valid_pts)
avio_seek(pb, 0, SEEK_SET); else if (st->duration != AV_NOPTS_VALUE && ts_relative > st->duration && wtv->nb_index_entries)
avio_seek(pb, wtv->index_entries[wtv->nb_index_entries - 1].pos, SEEK_SET); if (parse_chunks(VAR_0, SEEK_TO_PTS, VAR_2, 0) < 0)
return AVERROR(ERANGE); return 0; } wtv->pts = wtv->index_entries[VAR_4].timestamp; if (wtv->epoch != AV_NOPTS_VALUE)
wtv->pts += wtv->epoch; wtv->last_valid_pts = wtv->pts; avio_seek(pb, wtv->index_entries[VAR_4].pos, SEEK_SET); return 0; }