Commit 3ba1438d authored by Michael Niedermayer's avatar Michael Niedermayer

use native timebase for seeking

direction flag for seeking

Originally committed as revision 3577 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent ac8b03c0
......@@ -2777,7 +2777,7 @@ static void opt_input_file(const char *filename)
/* if seeking requested, we execute it */
if (start_time != 0) {
ret = av_seek_frame(ic, -1, timestamp);
ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
if (ret < 0) {
fprintf(stderr, "%s: could not seek to position %0.3f\n",
filename, (double)timestamp / AV_TIME_BASE);
......
......@@ -92,6 +92,7 @@ typedef struct VideoState {
int paused;
int last_paused;
int seek_req;
int seek_flags;
int64_t seek_pos;
AVFormatContext *ic;
int dtg_active_format;
......@@ -589,10 +590,11 @@ static double get_master_clock(VideoState *is)
}
/* seek in the stream */
static void stream_seek(VideoState *is, int64_t pos)
static void stream_seek(VideoState *is, int64_t pos, int rel)
{
is->seek_pos = pos;
is->seek_req = 1;
is->seek_flags = rel < 0 ? AVSEEK_FLAG_BACKWARD : 0;
}
/* pause or resume the video */
......@@ -1335,7 +1337,7 @@ static int decode_thread(void *arg)
/* add the stream start time */
if (ic->start_time != AV_NOPTS_VALUE)
timestamp += ic->start_time;
ret = av_seek_frame(ic, -1, timestamp);
ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);
if (ret < 0) {
fprintf(stderr, "%s: could not seek to position %0.3f\n",
is->filename, (double)timestamp / AV_TIME_BASE);
......@@ -1412,7 +1414,7 @@ static int decode_thread(void *arg)
#endif
if (is->seek_req) {
/* XXX: must lock decoder threads */
ret = av_seek_frame(is->ic, -1, is->seek_pos);
ret = av_seek_frame(is->ic, -1, is->seek_pos, is->seek_flags);
if (ret < 0) {
fprintf(stderr, "%s: error while seeking\n", is->ic->filename);
}else{
......@@ -1682,7 +1684,7 @@ void event_loop(void)
if (cur_stream) {
pos = get_master_clock(cur_stream);
pos += incr;
stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE));
stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), incr);
}
break;
default:
......@@ -1704,7 +1706,7 @@ void event_loop(void)
ss = (ns%60);
fprintf(stderr, "Seek to %2.0f%% (%2d:%02d:%02d) of total duration (%2d:%02d:%02d) \n", frac*100,
hh, mm, ss, thh, tmm, tss);
stream_seek(cur_stream, (int64_t)(cur_stream->ic->start_time+frac*cur_stream->ic->duration));
stream_seek(cur_stream, (int64_t)(cur_stream->ic->start_time+frac*cur_stream->ic->duration), 0);
}
break;
case SDL_VIDEORESIZE:
......
......@@ -757,14 +757,14 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos,
return pts;
}
static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts)
static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
{
ASFContext *asf = s->priv_data;
if (asf->packet_size <= 0)
return -1;
if(av_seek_frame_binary(s, stream_index, pts)<0)
if(av_seek_frame_binary(s, stream_index, pts, flags)<0)
return -1;
asf_reset_header(s);
......
......@@ -5,7 +5,7 @@
extern "C" {
#endif
#define LIBAVFORMAT_BUILD 4618
#define LIBAVFORMAT_BUILD 4619
#define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVFORMAT_VERSION FFMPEG_VERSION
......@@ -165,10 +165,15 @@ typedef struct AVInputFormat {
/* close the stream. The AVFormatContext and AVStreams are not
freed by this function */
int (*read_close)(struct AVFormatContext *);
/* seek at or before a given timestamp (given in AV_TIME_BASE
units) relative to the frames in stream component stream_index */
/**
* seek to a given timestamp relative to the frames in
* stream component stream_index
* @param stream_index must not be -1
* @param flags selects which direction should be preferred if no exact
* match is available
*/
int (*read_seek)(struct AVFormatContext *,
int stream_index, int64_t timestamp);
int stream_index, int64_t timestamp, int flags);
/**
* gets the next timestamp in AV_TIME_BASE units.
*/
......@@ -553,7 +558,7 @@ AVFormatContext *av_alloc_format_context(void);
int av_find_stream_info(AVFormatContext *ic);
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
int av_read_frame(AVFormatContext *s, AVPacket *pkt);
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp);
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
int av_read_play(AVFormatContext *s);
int av_read_pause(AVFormatContext *s);
void av_close_input_file(AVFormatContext *s);
......@@ -561,11 +566,14 @@ AVStream *av_new_stream(AVFormatContext *s, int id);
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
int pts_num, int pts_den);
#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
#define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
int av_find_default_stream_index(AVFormatContext *s);
int av_index_search_timestamp(AVStream *st, int timestamp);
int av_index_search_timestamp(AVStream *st, int timestamp, int flags);
int av_add_index_entry(AVStream *st,
int64_t pos, int64_t timestamp, int distance, int flags);
int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts);
int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
/* media file output */
int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
......
......@@ -1331,12 +1331,12 @@ static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index,
return timestamp;
}
static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts){
static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){
MpegTSContext *ts = s->priv_data;
uint8_t buf[TS_PACKET_SIZE];
int64_t pos;
if(av_seek_frame_binary(s, stream_index, target_ts) < 0)
if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0)
return -1;
pos= url_ftell(&s->pb);
......
......@@ -1373,11 +1373,11 @@ av_log(s, AV_LOG_DEBUG, "syncing from %lld\n", nut->packet_start[2]+1);
return AV_NOPTS_VALUE;
}
static int nut_read_seek(AVFormatContext *s, int stream_index, int64_t target_ts){
static int nut_read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){
// NUTContext *nut = s->priv_data;
int64_t pos;
if(av_seek_frame_binary(s, stream_index, target_ts) < 0)
if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0)
return -1;
pos= url_ftell(&s->pb);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment