Commit a2faa951 authored by Anton Khirnov's avatar Anton Khirnov

lavf: make some seeking functions private

Specifically av_update_cur_dts(), av_seek_frame_binary() and
av_gen_search().

They are not supposed to be called outside lavf.
parent ec6d7431
...@@ -1282,7 +1282,7 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int ...@@ -1282,7 +1282,7 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int
} }
} }
/* no index or seeking by index failed */ /* no index or seeking by index failed */
if(av_seek_frame_binary(s, stream_index, pts, flags)<0) if (ff_seek_frame_binary(s, stream_index, pts, flags) < 0)
return -1; return -1;
asf_reset_header(s); asf_reset_header(s);
return 0; return 0;
......
...@@ -1388,40 +1388,20 @@ int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags); ...@@ -1388,40 +1388,20 @@ int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
int size, int distance, int flags); int size, int distance, int flags);
/** #if FF_API_SEEK_PUBLIC
* Perform a binary search using av_index_search_timestamp() and attribute_deprecated
* AVInputFormat.read_timestamp().
* This is not supposed to be called directly by a user application,
* but by demuxers.
* @param target_ts target timestamp in the time base of the given stream
* @param stream_index stream number
*/
int av_seek_frame_binary(AVFormatContext *s, int stream_index, int av_seek_frame_binary(AVFormatContext *s, int stream_index,
int64_t target_ts, int flags); int64_t target_ts, int flags);
attribute_deprecated
/**
* Update cur_dts of all streams based on the given timestamp and AVStream.
*
* Stream ref_st unchanged, others set cur_dts in their native time base.
* Only needed for timestamp wrapping or if (dts not set and pts!=dts).
* @param timestamp new dts expressed in time_base of param ref_st
* @param ref_st reference stream giving time_base of param timestamp
*/
void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp); void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
attribute_deprecated
/**
* Perform a binary search using read_timestamp().
* This is not supposed to be called directly by a user application,
* but by demuxers.
* @param target_ts target timestamp in the time base of the given stream
* @param stream_index stream number
*/
int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t av_gen_search(AVFormatContext *s, int stream_index,
int64_t target_ts, int64_t pos_min, int64_t target_ts, int64_t pos_min,
int64_t pos_max, int64_t pos_limit, int64_t pos_max, int64_t pos_limit,
int64_t ts_min, int64_t ts_max, int64_t ts_min, int64_t ts_max,
int flags, int64_t *ts_ret, int flags, int64_t *ts_ret,
int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )); int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
#endif
/** /**
* media file output * media file output
......
...@@ -253,4 +253,37 @@ enum CodecID ff_guess_image2_codec(const char *filename); ...@@ -253,4 +253,37 @@ enum CodecID ff_guess_image2_codec(const char *filename);
*/ */
int64_t ff_iso8601_to_unix_time(const char *datestr); int64_t ff_iso8601_to_unix_time(const char *datestr);
/**
* Perform a binary search using av_index_search_timestamp() and
* AVInputFormat.read_timestamp().
*
* @param target_ts target timestamp in the time base of the given stream
* @param stream_index stream number
*/
int ff_seek_frame_binary(AVFormatContext *s, int stream_index,
int64_t target_ts, int flags);
/**
* Update cur_dts of all streams based on the given timestamp and AVStream.
*
* Stream ref_st unchanged, others set cur_dts in their native time base.
* Only needed for timestamp wrapping or if (dts not set and pts!=dts).
* @param timestamp new dts expressed in time_base of param ref_st
* @param ref_st reference stream giving time_base of param timestamp
*/
void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
/**
* Perform a binary search using read_timestamp().
*
* @param target_ts target timestamp in the time base of the given stream
* @param stream_index stream number
*/
int64_t ff_gen_search(AVFormatContext *s, int stream_index,
int64_t target_ts, int64_t pos_min,
int64_t pos_max, int64_t pos_limit,
int64_t ts_min, int64_t ts_max,
int flags, int64_t *ts_ret,
int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
#endif /* AVFORMAT_INTERNAL_H */ #endif /* AVFORMAT_INTERNAL_H */
...@@ -2002,7 +2002,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, ...@@ -2002,7 +2002,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY); matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY);
matroska->skip_to_timecode = st->index_entries[index].timestamp; matroska->skip_to_timecode = st->index_entries[index].timestamp;
matroska->done = 0; matroska->done = 0;
av_update_cur_dts(s, st, st->index_entries[index].timestamp); ff_update_cur_dts(s, st, st->index_entries[index].timestamp);
return 0; return 0;
} }
......
...@@ -1768,7 +1768,7 @@ static int read_seek2(AVFormatContext *s, ...@@ -1768,7 +1768,7 @@ static int read_seek2(AVFormatContext *s,
ts_adj = target_ts; ts_adj = target_ts;
stream_index_gen_search = stream_index; stream_index_gen_search = stream_index;
} }
pos = av_gen_search(s, stream_index_gen_search, ts_adj, pos = ff_gen_search(s, stream_index_gen_search, ts_adj,
0, INT64_MAX, -1, 0, INT64_MAX, -1,
AV_NOPTS_VALUE, AV_NOPTS_VALUE,
AV_NOPTS_VALUE, AV_NOPTS_VALUE,
...@@ -1816,7 +1816,7 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, in ...@@ -1816,7 +1816,7 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, in
uint8_t buf[TS_PACKET_SIZE]; uint8_t buf[TS_PACKET_SIZE];
int64_t pos; int64_t pos;
if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0) if (ff_seek_frame_binary(s, stream_index, target_ts, flags) < 0)
return -1; return -1;
pos= avio_tell(s->pb); pos= avio_tell(s->pb);
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "libavcodec/bytestream.h" #include "libavcodec/bytestream.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h"
#include "mxf.h" #include "mxf.h"
typedef struct { typedef struct {
...@@ -1020,7 +1021,7 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti ...@@ -1020,7 +1021,7 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti
sample_time = 0; sample_time = 0;
seconds = av_rescale(sample_time, st->time_base.num, st->time_base.den); seconds = av_rescale(sample_time, st->time_base.num, st->time_base.den);
avio_seek(s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET); avio_seek(s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET);
av_update_cur_dts(s, st, sample_time); ff_update_cur_dts(s, st, sample_time);
return 0; return 0;
} }
......
...@@ -874,16 +874,16 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flag ...@@ -874,16 +874,16 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flag
(void **) next_node); (void **) next_node);
av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n", next_node[0]->pos, next_node[1]->pos, av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n", next_node[0]->pos, next_node[1]->pos,
next_node[0]->ts , next_node[1]->ts); next_node[0]->ts , next_node[1]->ts);
pos= av_gen_search(s, -1, dummy.ts, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos, pos = ff_gen_search(s, -1, dummy.ts, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos,
next_node[0]->ts , next_node[1]->ts, AVSEEK_FLAG_BACKWARD, &ts, nut_read_timestamp); next_node[0]->ts , next_node[1]->ts, AVSEEK_FLAG_BACKWARD, &ts, nut_read_timestamp);
if(!(flags & AVSEEK_FLAG_BACKWARD)){ if(!(flags & AVSEEK_FLAG_BACKWARD)){
dummy.pos= pos+16; dummy.pos= pos+16;
next_node[1]= &nopts_sp; next_node[1]= &nopts_sp;
av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp, av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp,
(void **) next_node); (void **) next_node);
pos2= av_gen_search(s, -2, dummy.pos, next_node[0]->pos , next_node[1]->pos, next_node[1]->pos, pos2 = ff_gen_search(s, -2, dummy.pos, next_node[0]->pos , next_node[1]->pos, next_node[1]->pos,
next_node[0]->back_ptr, next_node[1]->back_ptr, flags, &ts, nut_read_timestamp); next_node[0]->back_ptr, next_node[1]->back_ptr, flags, &ts, nut_read_timestamp);
if(pos2>=0) if(pos2>=0)
pos= pos2; pos= pos2;
//FIXME dir but I think it does not matter //FIXME dir but I think it does not matter
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <stdio.h> #include <stdio.h>
#include "oggdec.h" #include "oggdec.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h"
#include "vorbiscomment.h" #include "vorbiscomment.h"
#define MAX_PAGE_SIZE 65307 #define MAX_PAGE_SIZE 65307
...@@ -637,7 +638,7 @@ static int ogg_read_seek(AVFormatContext *s, int stream_index, ...@@ -637,7 +638,7 @@ static int ogg_read_seek(AVFormatContext *s, int stream_index,
&& !(flags & AVSEEK_FLAG_ANY)) && !(flags & AVSEEK_FLAG_ANY))
os->keyframe_seek = 1; os->keyframe_seek = 1;
ret = av_seek_frame_binary(s, stream_index, timestamp, flags); ret = ff_seek_frame_binary(s, stream_index, timestamp, flags);
os = ogg->streams + stream_index; os = ogg->streams + stream_index;
if (ret < 0) if (ret < 0)
os->keyframe_seek = 0; os->keyframe_seek = 0;
......
...@@ -1374,7 +1374,15 @@ void ff_read_frame_flush(AVFormatContext *s) ...@@ -1374,7 +1374,15 @@ void ff_read_frame_flush(AVFormatContext *s)
} }
} }
void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp){ #if FF_API_SEEK_PUBLIC
void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
{
return ff_update_cur_dts(s, ref_st, timestamp);
}
#endif
void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
{
int i; int i;
for(i = 0; i < s->nb_streams; i++) { for(i = 0; i < s->nb_streams; i++) {
...@@ -1494,7 +1502,14 @@ int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, ...@@ -1494,7 +1502,14 @@ int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp,
wanted_timestamp, flags); wanted_timestamp, flags);
} }
#if FF_API_SEEK_PUBLIC
int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){
return ff_seek_frame_binary(s, stream_index, target_ts, flags);
}
#endif
int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags)
{
AVInputFormat *avif= s->iformat; AVInputFormat *avif= s->iformat;
int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit; int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit;
int64_t ts_min, ts_max, ts; int64_t ts_min, ts_max, ts;
...@@ -1541,7 +1556,7 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts ...@@ -1541,7 +1556,7 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts
} }
} }
pos= av_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit, ts_min, ts_max, flags, &ts, avif->read_timestamp); pos= ff_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit, ts_min, ts_max, flags, &ts, avif->read_timestamp);
if(pos<0) if(pos<0)
return -1; return -1;
...@@ -1549,12 +1564,28 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts ...@@ -1549,12 +1564,28 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts
if ((ret = avio_seek(s->pb, pos, SEEK_SET)) < 0) if ((ret = avio_seek(s->pb, pos, SEEK_SET)) < 0)
return ret; return ret;
av_update_cur_dts(s, st, ts); ff_update_cur_dts(s, st, ts);
return 0; return 0;
} }
int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )){ #if FF_API_SEEK_PUBLIC
int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts,
int64_t pos_min, int64_t pos_max, int64_t pos_limit,
int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret,
int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ))
{
return ff_gen_search(s, stream_index, target_ts, pos_min, pos_max,
pos_limit, ts_min, ts_max, flags, ts_ret,
read_timestamp);
}
#endif
int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts,
int64_t pos_min, int64_t pos_max, int64_t pos_limit,
int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret,
int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ))
{
int64_t pos, ts; int64_t pos, ts;
int64_t start_pos, filesize; int64_t start_pos, filesize;
int no_change; int no_change;
...@@ -1708,7 +1739,7 @@ static int seek_frame_generic(AVFormatContext *s, ...@@ -1708,7 +1739,7 @@ static int seek_frame_generic(AVFormatContext *s,
ie= &st->index_entries[st->nb_index_entries-1]; ie= &st->index_entries[st->nb_index_entries-1];
if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0)
return ret; return ret;
av_update_cur_dts(s, st, ie->timestamp); ff_update_cur_dts(s, st, ie->timestamp);
}else{ }else{
if ((ret = avio_seek(s->pb, s->data_offset, SEEK_SET)) < 0) if ((ret = avio_seek(s->pb, s->data_offset, SEEK_SET)) < 0)
return ret; return ret;
...@@ -1739,7 +1770,7 @@ static int seek_frame_generic(AVFormatContext *s, ...@@ -1739,7 +1770,7 @@ static int seek_frame_generic(AVFormatContext *s,
ie = &st->index_entries[index]; ie = &st->index_entries[index];
if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0)
return ret; return ret;
av_update_cur_dts(s, st, ie->timestamp); ff_update_cur_dts(s, st, ie->timestamp);
return 0; return 0;
} }
...@@ -1778,7 +1809,7 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int f ...@@ -1778,7 +1809,7 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int f
if (s->iformat->read_timestamp && !(s->iformat->flags & AVFMT_NOBINSEARCH)) { if (s->iformat->read_timestamp && !(s->iformat->flags & AVFMT_NOBINSEARCH)) {
ff_read_frame_flush(s); ff_read_frame_flush(s);
return av_seek_frame_binary(s, stream_index, timestamp, flags); return ff_seek_frame_binary(s, stream_index, timestamp, flags);
} else if (!(s->iformat->flags & AVFMT_NOGENSEARCH)) { } else if (!(s->iformat->flags & AVFMT_NOGENSEARCH)) {
ff_read_frame_flush(s); ff_read_frame_flush(s);
return seek_frame_generic(s, stream_index, timestamp, flags); return seek_frame_generic(s, stream_index, timestamp, flags);
......
...@@ -104,5 +104,8 @@ ...@@ -104,5 +104,8 @@
#ifndef FF_API_STREAM_COPY #ifndef FF_API_STREAM_COPY
#define FF_API_STREAM_COPY (LIBAVFORMAT_VERSION_MAJOR < 54) #define FF_API_STREAM_COPY (LIBAVFORMAT_VERSION_MAJOR < 54)
#endif #endif
#ifndef FF_API_SEEK_PUBLIC
#define FF_API_SEEK_PUBLIC (LIBAVFORMAT_VERSION_MAJOR < 54)
#endif
#endif /* AVFORMAT_VERSION_H */ #endif /* AVFORMAT_VERSION_H */
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