mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 03:52:22 +02:00
player: use symbolic constant for seek precision
Meh.
This commit is contained in:
parent
5c49fe97cb
commit
e35da1ac02
@ -565,7 +565,7 @@ static int mp_property_percent_pos(void *ctx, struct m_property *prop,
|
||||
switch (action) {
|
||||
case M_PROPERTY_SET: {
|
||||
double pos = *(double *)arg;
|
||||
queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, 0, true);
|
||||
queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, MPSEEK_DEFAULT, true);
|
||||
return M_PROPERTY_OK;
|
||||
}
|
||||
case M_PROPERTY_GET: {
|
||||
@ -613,7 +613,7 @@ static int mp_property_time_pos(void *ctx, struct m_property *prop,
|
||||
return M_PROPERTY_UNAVAILABLE;
|
||||
|
||||
if (action == M_PROPERTY_SET) {
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double *)arg, 0, true);
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double *)arg, MPSEEK_DEFAULT, true);
|
||||
return M_PROPERTY_OK;
|
||||
}
|
||||
return property_time(action, arg, get_current_time(mpctx));
|
||||
@ -2029,7 +2029,7 @@ static int mp_property_hwdec(void *ctx, struct m_property *prop,
|
||||
opts->hwdec_api = new;
|
||||
reinit_video_chain(mpctx);
|
||||
if (last_pts != MP_NOPTS_VALUE)
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, last_pts, 1, true);
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, last_pts, MPSEEK_EXACT, true);
|
||||
return M_PROPERTY_OK;
|
||||
}
|
||||
}
|
||||
@ -3108,7 +3108,8 @@ static int mp_property_ab_loop(void *ctx, struct m_property *prop,
|
||||
double now = mpctx->playback_pts;
|
||||
if (now != MP_NOPTS_VALUE && opts->ab_loop[0] != MP_NOPTS_VALUE &&
|
||||
opts->ab_loop[1] != MP_NOPTS_VALUE && now >= opts->ab_loop[1])
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, opts->ab_loop[0], 1, false);
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, opts->ab_loop[0],
|
||||
MPSEEK_EXACT, false);
|
||||
}
|
||||
// Update if visible
|
||||
set_osd_bar_chapters(mpctx, OSD_BAR_SEEK);
|
||||
@ -4186,23 +4187,23 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
||||
case MP_CMD_SEEK: {
|
||||
double v = cmd->args[0].v.d * cmd->scale;
|
||||
int abs = cmd->args[1].v.i & 3;
|
||||
int exact = ((cmd->args[2].v.i | cmd->args[1].v.i) >> 3) & 3;
|
||||
switch (exact) {
|
||||
case 1: exact = -1; break;
|
||||
case 2: exact = 1; break;
|
||||
enum seek_precision precision = MPSEEK_DEFAULT;
|
||||
switch (((cmd->args[2].v.i | cmd->args[1].v.i) >> 3) & 3) {
|
||||
case 1: precision = MPSEEK_KEYFRAME; break;
|
||||
case 2: precision = MPSEEK_EXACT; break;
|
||||
}
|
||||
if (!mpctx->num_sources)
|
||||
return -1;
|
||||
mark_seek(mpctx);
|
||||
if (abs == 2) { // Absolute seek to a timestamp in seconds
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, v, exact, false);
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, v, precision, false);
|
||||
set_osd_function(mpctx,
|
||||
v > get_current_time(mpctx) ? OSD_FFW : OSD_REW);
|
||||
} else if (abs) { /* Absolute seek by percentage */
|
||||
queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, exact, false);
|
||||
queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, precision, false);
|
||||
set_osd_function(mpctx, OSD_FFW); // Direction isn't set correctly
|
||||
} else {
|
||||
queue_seek(mpctx, MPSEEK_RELATIVE, v, exact, false);
|
||||
queue_seek(mpctx, MPSEEK_RELATIVE, v, precision, false);
|
||||
set_osd_function(mpctx, (v > 0) ? OSD_FFW : OSD_REW);
|
||||
}
|
||||
if (bar_osd)
|
||||
@ -4223,7 +4224,7 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
||||
} else if (oldpts != MP_NOPTS_VALUE) {
|
||||
cmdctx->last_seek_pts = get_current_time(mpctx);
|
||||
cmdctx->marked_pts = MP_NOPTS_VALUE;
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, oldpts, 1, false);
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, oldpts, MPSEEK_EXACT, false);
|
||||
set_osd_function(mpctx, OSD_REW);
|
||||
if (bar_osd)
|
||||
mpctx->add_osd_seek_info |= OSD_SEEK_INFO_BAR;
|
||||
@ -4432,7 +4433,7 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
||||
// rounding for the mess of it.
|
||||
a[0] += 0.01 * (a[1] > 0 ? 1 : -1);
|
||||
mark_seek(mpctx);
|
||||
queue_seek(mpctx, MPSEEK_RELATIVE, a[0], 1, false);
|
||||
queue_seek(mpctx, MPSEEK_RELATIVE, a[0], MPSEEK_EXACT, false);
|
||||
set_osd_function(mpctx, (a[0] > 0) ? OSD_FFW : OSD_REW);
|
||||
if (bar_osd)
|
||||
mpctx->add_osd_seek_info |= OSD_SEEK_INFO_BAR;
|
||||
@ -4901,7 +4902,8 @@ static void command_event(struct MPContext *mpctx, int event, void *arg)
|
||||
now >= opts->ab_loop[1])
|
||||
{
|
||||
mark_seek(mpctx);
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, opts->ab_loop[0], 1, false);
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, opts->ab_loop[0],
|
||||
MPSEEK_EXACT, false);
|
||||
}
|
||||
}
|
||||
ctx->prev_pts = now;
|
||||
|
@ -67,6 +67,14 @@ enum seek_type {
|
||||
MPSEEK_FACTOR,
|
||||
};
|
||||
|
||||
enum seek_precision {
|
||||
MPSEEK_DEFAULT = 0,
|
||||
// The following values are numerically sorted by increasing precision
|
||||
MPSEEK_KEYFRAME,
|
||||
MPSEEK_EXACT,
|
||||
MPSEEK_VERY_EXACT,
|
||||
};
|
||||
|
||||
struct track {
|
||||
enum stream_type type;
|
||||
|
||||
@ -293,8 +301,8 @@ typedef struct MPContext {
|
||||
// Used to communicate the parameters of a seek between parts
|
||||
struct seek_params {
|
||||
enum seek_type type;
|
||||
enum seek_precision exact;
|
||||
double amount;
|
||||
int exact; // -1 = disable, 0 = default, 1 = enable
|
||||
bool immediate; // disable seek delay logic
|
||||
} seek;
|
||||
|
||||
@ -437,7 +445,7 @@ void pause_player(struct MPContext *mpctx);
|
||||
void unpause_player(struct MPContext *mpctx);
|
||||
void add_step_frame(struct MPContext *mpctx, int dir);
|
||||
void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount,
|
||||
int exact, bool immediate);
|
||||
enum seek_precision exact, bool immediate);
|
||||
bool mp_seek_chapter(struct MPContext *mpctx, int chapter);
|
||||
double get_time_length(struct MPContext *mpctx);
|
||||
double get_current_time(struct MPContext *mpctx);
|
||||
|
@ -183,7 +183,7 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
|
||||
mpctx->stop_play = KEEP_PLAYING;
|
||||
|
||||
double hr_seek_offset = opts->hr_seek_demuxer_offset;
|
||||
bool hr_seek_very_exact = seek.exact > 1;
|
||||
bool hr_seek_very_exact = seek.exact == MPSEEK_VERY_EXACT;
|
||||
// Always try to compensate for possibly bad demuxers in "special"
|
||||
// situations where we need more robustness from the hr-seek code, even
|
||||
// if the user doesn't use --hr-seek-demuxer-offset.
|
||||
@ -191,9 +191,9 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
|
||||
if (hr_seek_very_exact)
|
||||
hr_seek_offset = MPMAX(hr_seek_offset, 0.5); // arbitrary
|
||||
|
||||
bool hr_seek = opts->correct_pts && seek.exact >= 0;
|
||||
bool hr_seek = opts->correct_pts && seek.exact != MPSEEK_KEYFRAME;
|
||||
hr_seek &= (opts->hr_seek == 0 && seek.type == MPSEEK_ABSOLUTE) ||
|
||||
opts->hr_seek > 0 || seek.exact > 0;
|
||||
opts->hr_seek > 0 || seek.exact >= MPSEEK_EXACT;
|
||||
if (seek.type == MPSEEK_FACTOR || seek.amount < 0 ||
|
||||
(seek.type == MPSEEK_ABSOLUTE && seek.amount < mpctx->last_chapter_pts))
|
||||
mpctx->last_chapter_seek = -2;
|
||||
@ -303,7 +303,7 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
|
||||
|
||||
// This combines consecutive seek requests.
|
||||
void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount,
|
||||
int exact, bool immediate)
|
||||
enum seek_precision exact, bool immediate)
|
||||
{
|
||||
struct seek_params *seek = &mpctx->seek;
|
||||
switch (type) {
|
||||
@ -339,7 +339,7 @@ void execute_queued_seek(struct MPContext *mpctx)
|
||||
{
|
||||
if (mpctx->seek.type) {
|
||||
// Let explicitly imprecise seeks cancel precise seeks:
|
||||
if (mpctx->hrseek_active && mpctx->seek.exact < 0)
|
||||
if (mpctx->hrseek_active && mpctx->seek.exact == MPSEEK_KEYFRAME)
|
||||
mpctx->start_timestamp = -1e9;
|
||||
/* If the user seeks continuously (keeps arrow key down)
|
||||
* try to finish showing a frame from one location before doing
|
||||
@ -505,7 +505,7 @@ bool mp_seek_chapter(struct MPContext *mpctx, int chapter)
|
||||
if (pts == MP_NOPTS_VALUE)
|
||||
return false;
|
||||
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, pts, 0, true);
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, pts, MPSEEK_DEFAULT, true);
|
||||
mpctx->last_chapter_seek = chapter;
|
||||
mpctx->last_chapter_pts = pts;
|
||||
return true;
|
||||
@ -717,14 +717,15 @@ static void handle_backstep(struct MPContext *mpctx)
|
||||
if (mpctx->d_video && current_pts != MP_NOPTS_VALUE) {
|
||||
double seek_pts = find_previous_pts(mpctx, current_pts);
|
||||
if (seek_pts != MP_NOPTS_VALUE) {
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, seek_pts, 2, true);
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, seek_pts, MPSEEK_VERY_EXACT, true);
|
||||
} else {
|
||||
double last = get_last_frame_pts(mpctx);
|
||||
if (last != MP_NOPTS_VALUE && last >= current_pts &&
|
||||
mpctx->backstep_start_seek_ts != mpctx->vo_pts_history_seek_ts)
|
||||
{
|
||||
MP_ERR(mpctx, "Backstep failed.\n");
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, current_pts, 2, true);
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, current_pts,
|
||||
MPSEEK_VERY_EXACT, true);
|
||||
} else if (!mpctx->hrseek_active) {
|
||||
MP_VERBOSE(mpctx, "Start backstep indexing.\n");
|
||||
// Force it to index the video up until current_pts.
|
||||
@ -761,7 +762,7 @@ static void handle_sstep(struct MPContext *mpctx)
|
||||
|
||||
if (opts->step_sec > 0 && !mpctx->paused) {
|
||||
set_osd_function(mpctx, OSD_FFW);
|
||||
queue_seek(mpctx, MPSEEK_RELATIVE, opts->step_sec, 0, true);
|
||||
queue_seek(mpctx, MPSEEK_RELATIVE, opts->step_sec, MPSEEK_DEFAULT, true);
|
||||
}
|
||||
|
||||
if (mpctx->video_status >= STATUS_EOF) {
|
||||
@ -778,7 +779,8 @@ static void handle_loop_file(struct MPContext *mpctx)
|
||||
if (opts->loop_file && mpctx->stop_play == AT_END_OF_FILE) {
|
||||
mpctx->stop_play = KEEP_PLAYING;
|
||||
set_osd_function(mpctx, OSD_FFW);
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, get_start_time(mpctx), 0, true);
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, get_start_time(mpctx),
|
||||
MPSEEK_DEFAULT, true);
|
||||
if (opts->loop_file > 0)
|
||||
opts->loop_file--;
|
||||
}
|
||||
@ -799,7 +801,7 @@ void seek_to_last_frame(struct MPContext *mpctx)
|
||||
mp_seek(mpctx, (struct seek_params){
|
||||
.type = MPSEEK_ABSOLUTE,
|
||||
.amount = end,
|
||||
.exact = 2, // "very exact", no framedrop
|
||||
.exact = MPSEEK_VERY_EXACT,
|
||||
}, false);
|
||||
// Make it exact: stop seek only if last frame was reached.
|
||||
if (mpctx->hrseek_active) {
|
||||
|
@ -348,8 +348,10 @@ void mp_force_video_refresh(struct MPContext *mpctx)
|
||||
return;
|
||||
|
||||
// If not paused, the next frame should come soon enough.
|
||||
if (opts->pause && mpctx->last_vo_pts != MP_NOPTS_VALUE)
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, mpctx->last_vo_pts, 2, true);
|
||||
if (opts->pause && mpctx->last_vo_pts != MP_NOPTS_VALUE) {
|
||||
queue_seek(mpctx, MPSEEK_ABSOLUTE, mpctx->last_vo_pts,
|
||||
MPSEEK_VERY_EXACT, true);
|
||||
}
|
||||
}
|
||||
|
||||
static int check_framedrop(struct MPContext *mpctx)
|
||||
|
Loading…
Reference in New Issue
Block a user