static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, int flags)

{

    MOVStreamContext *sc = st->priv_data;

    int sample, time_sample;

    int i;



    sample = av_index_search_timestamp(st, timestamp, flags);

    av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample);

    if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp)

        sample = 0;

    if (sample < 0) /* not sure what to do */

        return AVERROR_INVALIDDATA;

    sc->current_sample = sample;

    av_log(s, AV_LOG_TRACE, "stream %d, found sample %d\n", st->index, sc->current_sample);

    /* adjust ctts index */

    if (sc->ctts_data) {

        time_sample = 0;

        for (i = 0; i < sc->ctts_count; i++) {

            int next = time_sample + sc->ctts_data[i].count;

            if (next > sc->current_sample) {

                sc->ctts_index = i;

                sc->ctts_sample = sc->current_sample - time_sample;

                break;

            }

            time_sample = next;

        }

    }



    /* adjust stsd index */

    time_sample = 0;

    for (i = 0; i < sc->stsc_count; i++) {

        int next = time_sample + mov_get_stsc_samples(sc, i);

        if (next > sc->current_sample) {

            sc->stsc_index = i;

            sc->stsc_sample = sc->current_sample - time_sample;

            break;

        }

        time_sample = next;

    }



    return sample;

}

static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, int flags)

{

    MOVStreamContext *sc = st->priv_data;

    int sample, time_sample;

    int i;



    sample = av_index_search_timestamp(st, timestamp, flags);

    av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample);

    if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp)

        sample = 0;

    if (sample < 0) 

        return AVERROR_INVALIDDATA;

    sc->current_sample = sample;

    av_log(s, AV_LOG_TRACE, "stream %d, found sample %d\n", st->index, sc->current_sample);

    

    if (sc->ctts_data) {

        time_sample = 0;

        for (i = 0; i < sc->ctts_count; i++) {

            int next = time_sample + sc->ctts_data[i].count;

            if (next > sc->current_sample) {

                sc->ctts_index = i;

                sc->ctts_sample = sc->current_sample - time_sample;

                break;

            }

            time_sample = next;

        }

    }



    

    time_sample = 0;

    for (i = 0; i < sc->stsc_count; i++) {

        int next = time_sample + mov_get_stsc_samples(sc, i);

        if (next > sc->current_sample) {

            sc->stsc_index = i;

            sc->stsc_sample = sc->current_sample - time_sample;

            break;

        }

        time_sample = next;

    }



    return sample;

}

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

{

    MOVStreamContext *sc = VAR_1->priv_data;

    int VAR_4, VAR_5;

    int VAR_6;



    VAR_4 = av_index_search_timestamp(VAR_1, VAR_2, VAR_3);

    av_log(VAR_0, AV_LOG_TRACE, "stream %d, VAR_2 %"PRId64", VAR_4 %d\n", VAR_1->index, VAR_2, VAR_4);

    if (VAR_4 < 0 && VAR_1->nb_index_entries && VAR_2 < VAR_1->index_entries[0].VAR_2)

        VAR_4 = 0;

    if (VAR_4 < 0) 

        return AVERROR_INVALIDDATA;

    sc->current_sample = VAR_4;

    av_log(VAR_0, AV_LOG_TRACE, "stream %d, found VAR_4 %d\n", VAR_1->index, sc->current_sample);

    

    if (sc->ctts_data) {

        VAR_5 = 0;

        for (VAR_6 = 0; VAR_6 < sc->ctts_count; VAR_6++) {

            int next = VAR_5 + sc->ctts_data[VAR_6].count;

            if (next > sc->current_sample) {

                sc->ctts_index = VAR_6;

                sc->ctts_sample = sc->current_sample - VAR_5;

                break;

            }

            VAR_5 = next;

        }

    }



    

    VAR_5 = 0;

    for (VAR_6 = 0; VAR_6 < sc->stsc_count; VAR_6++) {

        int next = VAR_5 + mov_get_stsc_samples(sc, VAR_6);

        if (next > sc->current_sample) {

            sc->stsc_index = VAR_6;

            sc->stsc_sample = sc->current_sample - VAR_5;

            break;

        }

        VAR_5 = next;

    }



    return VAR_4;

}

static int FUNC_0(AVFormatContext *VAR_0, AVStream *VAR_1, int64_t VAR_2, int VAR_3)
{ MOVStreamContext *sc = VAR_1->priv_data; int VAR_4, VAR_5; int VAR_6; VAR_4 = av_index_search_timestamp(VAR_1, VAR_2, VAR_3); av_log(VAR_0, AV_LOG_TRACE, "stream %d, VAR_2 %"PRId64", VAR_4 %d\n", VAR_1->index, VAR_2, VAR_4); if (VAR_4 < 0 && VAR_1->nb_index_entries && VAR_2 < VAR_1->index_entries[0].VAR_2)
VAR_4 = 0; if (VAR_4 < 0)
return AVERROR_INVALIDDATA; sc->current_sample = VAR_4; av_log(VAR_0, AV_LOG_TRACE, "stream %d, found VAR_4 %d\n", VAR_1->index, sc->current_sample); if (sc->ctts_data) { VAR_5 = 0; for (VAR_6 = 0; VAR_6 < sc->ctts_count; VAR_6++) { int next = VAR_5 + sc->ctts_data[VAR_6].count; if (next > sc->current_sample) { sc->ctts_index = VAR_6; sc->ctts_sample = sc->current_sample - VAR_5; break; } VAR_5 = next; } } VAR_5 = 0; for (VAR_6 = 0; VAR_6 < sc->stsc_count; VAR_6++) { int next = VAR_5 + mov_get_stsc_samples(sc, VAR_6); if (next > sc->current_sample) { sc->stsc_index = VAR_6; sc->stsc_sample = sc->current_sample - VAR_5; break; } VAR_5 = next; } return VAR_4; }