Revision 4ed29207 ffplay.c

View differences:

ffplay.c
110 110
    int seek_req;
111 111
    int seek_flags;
112 112
    int64_t seek_pos;
113
    int64_t seek_rel;
113 114
    AVFormatContext *ic;
114 115
    int dtg_active_format;
115 116

  
......
984 985
}
985 986

  
986 987
/* seek in the stream */
987
static void stream_seek(VideoState *is, int64_t pos, int rel)
988
static void stream_seek(VideoState *is, int64_t pos, int64_t rel)
988 989
{
989 990
    if (!is->seek_req) {
990 991
        is->seek_pos = pos;
991
        is->seek_flags = rel < 0 ? AVSEEK_FLAG_BACKWARD : 0;
992
        is->seek_rel = rel;
992 993
        if (seek_by_bytes)
993 994
            is->seek_flags |= AVSEEK_FLAG_BYTE;
994 995
        is->seek_req = 1;
......
1962 1963
        /* add the stream start time */
1963 1964
        if (ic->start_time != AV_NOPTS_VALUE)
1964 1965
            timestamp += ic->start_time;
1965
        ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
1966
        ret = avformat_seek_file(ic, -1, INT64_MIN, timestamp, INT64_MAX, 0);
1966 1967
        if (ret < 0) {
1967 1968
            fprintf(stderr, "%s: could not seek to position %0.3f\n",
1968 1969
                    is->filename, (double)timestamp / AV_TIME_BASE);
......
2035 2036
        }
2036 2037
#endif
2037 2038
        if (is->seek_req) {
2038
            int stream_index= -1;
2039 2039
            int64_t seek_target= is->seek_pos;
2040
            int64_t seek_min= is->seek_rel > 0 ? seek_target - is->seek_rel + 2: INT64_MIN;
2041
            int64_t seek_max= is->seek_rel < 0 ? seek_target - is->seek_rel - 2: INT64_MAX;
2042
//FIXME the +-2 is due to rounding being not done in the correct direction in generation
2043
//      of the seek_pos/seek_rel variables
2040 2044

  
2041
            if     (is->   video_stream >= 0) stream_index= is->   video_stream;
2042
            else if(is->   audio_stream >= 0) stream_index= is->   audio_stream;
2043
            else if(is->subtitle_stream >= 0) stream_index= is->subtitle_stream;
2044

  
2045
            if(stream_index>=0){
2046
                seek_target= av_rescale_q(seek_target, AV_TIME_BASE_Q, ic->streams[stream_index]->time_base);
2047
            }
2048

  
2049
            ret = av_seek_frame(is->ic, stream_index, seek_target, is->seek_flags);
2045
            ret = avformat_seek_file(is->ic, -1, seek_min, seek_target, seek_max, is->seek_flags);
2050 2046
            if (ret < 0) {
2051 2047
                fprintf(stderr, "%s: error while seeking\n", is->ic->filename);
2052 2048
            }else{
......
2346 2342
                    } else {
2347 2343
                        pos = get_master_clock(cur_stream);
2348 2344
                        pos += incr;
2349
                        stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), incr);
2345
                        stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), (int64_t)(incr * AV_TIME_BASE));
2350 2346
                    }
2351 2347
                }
2352 2348
                break;

Also available in: Unified diff