diff --git a/demux/demux.c b/demux/demux.c index 2ebed5a3e7..35e7059426 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -721,7 +721,7 @@ static bool read_packet(struct demux_internal *in) if (refresh_seek) { MP_VERBOSE(in, "refresh seek to %f\n", seek_pts); - demux->desc->seek(demux, seek_pts, SEEK_BACKWARD | SEEK_HR); + demux->desc->seek(demux, seek_pts, SEEK_HR); } bool eof = true; @@ -1608,8 +1608,8 @@ static struct demux_packet *find_seek_target(struct demux_stream *ds, if (range_pts == MP_NOPTS_VALUE) continue; - double diff = pts - range_pts; - if (flags & SEEK_BACKWARD) + double diff = range_pts - pts; + if (flags & SEEK_FORWARD) diff = -diff; if (target_diff != MP_NOPTS_VALUE) { if (diff <= 0) { @@ -1671,8 +1671,7 @@ static bool try_seek_cache(struct demux_internal *in, double pts, int flags) // (We assume the find_seek_target() will return the // same target for the video stream.) pts = target_pts; - flags &= SEEK_FORWARD; - flags |= SEEK_BACKWARD; + flags &= ~SEEK_FORWARD; } } break; @@ -1713,9 +1712,6 @@ int demux_seek(demuxer_t *demuxer, double seek_pts, int flags) if (seek_pts == MP_NOPTS_VALUE) return 0; - if (!(flags & SEEK_FORWARD)) - flags |= SEEK_BACKWARD; - pthread_mutex_lock(&in->lock); MP_VERBOSE(in, "queuing seek to %f%s\n", seek_pts, @@ -1949,7 +1945,7 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg) // new packets if we seek there and also last_ts is the hightest // DTS or PTS, while ts_min should be as accurate as possible, as // we would have to trigger a real seek if it's off and we seeked - // there with SEEK_BACKWARD) + // there) r->ts_max = MP_PTS_MAX(r->ts_max, ds->last_ts); r->ts_min = MP_PTS_MAX(r->ts_min, ds->back_pts); if (ds->queue_head) { diff --git a/demux/demux.h b/demux/demux.h index 9c9824658b..64b9f9f561 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -47,7 +47,7 @@ struct demux_ctrl_reader_state { double ts_start; // approx. timestamp for the earliest packet buffered double ts_min; // timestamp of the earliest packet in backward cache // that can be seeked to (i.e. all streams have such - // a packet for which SEEK_BACKWARD can be executed) + // a packet for which normal seeks can be executed) double ts_max; // timestamp of latest packet in forward cache that can be // seeked to }; @@ -60,7 +60,7 @@ struct demux_ctrl_stream_ctrl { #define SEEK_FACTOR (1 << 1) // argument is in range [0,1] #define SEEK_FORWARD (1 << 2) // prefer later time if not exact -#define SEEK_BACKWARD (1 << 3) // prefer earlier time if not exact + // (if unset, prefer earlier time) #define SEEK_HR (1 << 5) // hr-seek (this is a weak hint only) // Strictness of the demuxer open format check. diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 53bf62016a..c11f7739e1 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -1014,7 +1014,7 @@ static void demux_seek_lavf(demuxer_t *demuxer, double seek_pts, int flags) int avsflags = 0; int64_t seek_pts_av = 0; - if (flags & SEEK_BACKWARD) + if (!(flags & SEEK_FORWARD)) avsflags = AVSEEK_FLAG_BACKWARD; if (flags & SEEK_FACTOR) { @@ -1031,7 +1031,7 @@ static void demux_seek_lavf(demuxer_t *demuxer, double seek_pts, int flags) seek_pts_av = seek_pts * priv->avfc->duration; } } else { - if (flags & SEEK_BACKWARD) + if (!(flags & SEEK_FORWARD)) seek_pts -= priv->seek_delay; seek_pts_av = seek_pts * AV_TIME_BASE; } diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index c95de36f00..753d783063 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -2893,8 +2893,6 @@ static int create_index_until(struct demuxer *demuxer, int64_t timecode) return 0; } -#define FLAG_BACKWARD 1 -#define FLAG_SUBPREROLL 2 static struct mkv_index *seek_with_cues(struct demuxer *demuxer, int seek_id, int64_t target_timecode, int flags) { @@ -2905,8 +2903,8 @@ static struct mkv_index *seek_with_cues(struct demuxer *demuxer, int seek_id, for (size_t i = 0; i < mkv_d->num_indexes; i++) { if (seek_id < 0 || mkv_d->indexes[i].tnum == seek_id) { int64_t diff = - target_timecode - mkv_d->indexes[i].timecode * mkv_d->tc_scale; - if (flags & FLAG_BACKWARD) + mkv_d->indexes[i].timecode * mkv_d->tc_scale - target_timecode; + if (flags & SEEK_FORWARD) diff = -diff; if (min_diff != INT64_MIN) { if (diff <= 0) { @@ -2922,7 +2920,7 @@ static struct mkv_index *seek_with_cues(struct demuxer *demuxer, int seek_id, if (index) { /* We've found an entry. */ uint64_t seek_pos = index->filepos; - if (flags & FLAG_SUBPREROLL) { + if (flags & SEEK_HR) { // Find the cluster with the highest filepos, that has a timestamp // still lower than min_tc. double secs = mkv_d->opts->subtitle_preroll_secs; @@ -2987,14 +2985,12 @@ static void demux_mkv_seek(demuxer_t *demuxer, double seek_pts, int flags) } } - int cueflags = (flags & SEEK_BACKWARD) ? FLAG_BACKWARD : 0; - mkv_d->subtitle_preroll = NUM_SUB_PREROLL_PACKETS; int preroll_opt = mkv_d->opts->subtitle_preroll; - if (((flags & SEEK_HR) || preroll_opt == 1 || - (preroll_opt == 2 && mkv_d->index_has_durations)) - && st_active[STREAM_SUB] && st_active[STREAM_VIDEO]) - cueflags |= FLAG_SUBPREROLL; + if (preroll_opt == 1 || (preroll_opt == 2 && mkv_d->index_has_durations)) + flags |= SEEK_HR; + if (!st_active[STREAM_SUB]) + flags &= ~SEEK_HR; // Adjust the target a little bit to catch cases where the target position // specifies a keyframe with high, but not perfect, precision. @@ -3008,9 +3004,9 @@ static void demux_mkv_seek(demuxer_t *demuxer, double seek_pts, int flags) if (create_index_until(demuxer, target_timecode) >= 0) { int seek_id = st_active[STREAM_VIDEO] ? v_tnum : a_tnum; - index = seek_with_cues(demuxer, seek_id, target_timecode, cueflags); + index = seek_with_cues(demuxer, seek_id, target_timecode, flags); if (!index) - index = seek_with_cues(demuxer, -1, target_timecode, cueflags); + index = seek_with_cues(demuxer, -1, target_timecode, flags); } if (!index) diff --git a/demux/demux_timeline.c b/demux/demux_timeline.c index d7a5c36d70..6b375261f4 100644 --- a/demux/demux_timeline.c +++ b/demux/demux_timeline.c @@ -179,8 +179,8 @@ static void switch_segment(struct demuxer *demuxer, struct segment *new, { struct priv *p = demuxer->priv; - if (!(flags & (SEEK_FORWARD | SEEK_BACKWARD))) - flags |= SEEK_BACKWARD | SEEK_HR; + if (!(flags & SEEK_FORWARD)) + flags |= SEEK_HR; MP_VERBOSE(demuxer, "switch to segment %d\n", new->index); @@ -209,7 +209,7 @@ static void d_seek(struct demuxer *demuxer, double seek_pts, int flags) double pts = seek_pts * ((flags & SEEK_FACTOR) ? p->duration : 1); - flags &= SEEK_FORWARD | SEEK_BACKWARD | SEEK_HR; + flags &= SEEK_FORWARD | SEEK_HR; struct segment *new = p->segments[p->num_segments - 1]; for (int n = 0; n < p->num_segments; n++) { diff --git a/player/playloop.c b/player/playloop.c index 3dc185dd55..0c44042ab1 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -277,14 +277,13 @@ static void mp_seek(MPContext *mpctx, struct seek_params seek) hr_seek_very_exact = true; break; case MPSEEK_RELATIVE: - demux_flags = seek.amount > 0 ? SEEK_FORWARD : SEEK_BACKWARD; + demux_flags = seek.amount > 0 ? SEEK_FORWARD : 0; seek_pts = current_time + seek.amount; break; case MPSEEK_FACTOR: ; double len = get_time_length(mpctx); if (len >= 0) seek_pts = seek.amount * len; - demux_flags = SEEK_BACKWARD; break; default: abort(); } @@ -323,7 +322,7 @@ static void mp_seek(MPContext *mpctx, struct seek_params seek) hr_seek_offset = MPMAX(hr_seek_offset, -offset); } demux_pts -= hr_seek_offset; - demux_flags = (demux_flags | SEEK_HR | SEEK_BACKWARD) & ~SEEK_FORWARD; + demux_flags = (demux_flags | SEEK_HR) & ~SEEK_FORWARD; } demux_seek(mpctx->demuxer, demux_pts, demux_flags);