Created
October 18, 2021 03:20
-
-
Save aqjune/3bd0ea19bbc12b4744843c0c070e994c to your computer and use it in GitHub Desktop.
A function that is in seek-preproc.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int ff_seek_frame_binary(AVFormatContext *s, int stream_index, | |
int64_t target_ts, int flags) | |
{ | |
const AVInputFormat *const avif = s->iformat; | |
int64_t pos_min=pos_min, pos_max=pos_max, pos, pos_limit; | |
int64_t ts_min, ts_max, ts; | |
int index; | |
int64_t ret; | |
AVStream *st; | |
FFStream *sti; | |
if (stream_index < 0) | |
return -1; | |
av_log(s, 56, "read_seek: %d %s\n", stream_index, av_ts_make_string((char[32]){0}, target_ts)); | |
ts_max = | |
ts_min = ((int64_t)0x8000000000000000UL); | |
pos_limit = -1; | |
st = s->streams[stream_index]; | |
sti = ffstream(st); | |
if (sti->index_entries) { | |
const AVIndexEntry *e; | |
index = av_index_search_timestamp(st, target_ts, | |
flags | 1); | |
index = ((index) > (0) ? (index) : (0)); | |
e = &sti->index_entries[index]; | |
if (e->timestamp <= target_ts || e->pos == e->min_distance) { | |
pos_min = e->pos; | |
ts_min = e->timestamp; | |
av_log(s, 56, "using cached pos_min=0x%""l" "x"" dts_min=%s\n", | |
pos_min, av_ts_make_string((char[32]){0}, ts_min)); | |
} else { | |
((void)0); | |
} | |
index = av_index_search_timestamp(st, target_ts, | |
flags & ~1); | |
do { if (!(index < sti->nb_index_entries)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n", "index < sti->nb_index_entries", "src/libavformat/seek.c", 325); abort(); } } while (0); | |
if (index >= 0) { | |
e = &sti->index_entries[index]; | |
((void)0); | |
pos_max = e->pos; | |
ts_max = e->timestamp; | |
pos_limit = pos_max - e->min_distance; | |
av_log(s, 56, "using cached pos_max=0x%""l" "x"" pos_limit=0x%""l" "x" | |
" dts_max=%s\n", pos_max, pos_limit, av_ts_make_string((char[32]){0}, ts_max)); | |
} | |
} | |
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) | |
return -1; | |
if ((ret = avio_seek(s->pb, pos, 0)) < 0) | |
return ret; | |
ff_read_frame_flush(s); | |
avpriv_update_cur_dts(s, st, ts); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment