summaryrefslogtreecommitdiffstats
path: root/mpvcore
diff options
context:
space:
mode:
authorPhilip Sequeira <phsequei@gmail.com>2013-08-13 21:25:50 -0400
committerwm4 <wm4@nowhere>2013-08-17 21:32:52 +0200
commitb018c7d936879dc2ea1bd49b78157a70f9353430 (patch)
tree53221ab06169baa10c007cb46f1c7ee64cb90f5e /mpvcore
parent8cebec62621cb6e9ed03aab65f5b011393ac588d (diff)
downloadmpv-b018c7d936879dc2ea1bd49b78157a70f9353430.tar.bz2
mpv-b018c7d936879dc2ea1bd49b78157a70f9353430.tar.xz
command: more intuitive chapter seek behavior
If close to chapter start, skipping back goes to previous chapter (no change). If more than <threshold> seconds in, skipping back will now go to the beginning of the current chapter instead. The threshold is set by the new option --chapter-seek-threshold and defaults to 5 seconds. A negative value disables the new functionality.
Diffstat (limited to 'mpvcore')
-rw-r--r--mpvcore/command.c23
-rw-r--r--mpvcore/options.c3
-rw-r--r--mpvcore/options.h1
3 files changed, 26 insertions, 1 deletions
diff --git a/mpvcore/command.c b/mpvcore/command.c
index b04c05c9e6..b7aa9dfe6a 100644
--- a/mpvcore/command.c
+++ b/mpvcore/command.c
@@ -390,9 +390,30 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg,
*(char **) arg = chapter_name;
return M_PROPERTY_OK;
}
+ case M_PROPERTY_SWITCH:
case M_PROPERTY_SET: ;
- int step_all = *(int *)arg - chapter;
+ int step_all;
+ if (action == M_PROPERTY_SWITCH) {
+ struct m_property_switch_arg *sarg = arg;
+ step_all = ROUND(sarg->inc);
+ // Check threshold for relative backward seeks
+ if (mpctx->opts->chapter_seek_threshold >= 0 && step_all < 0) {
+ if (chapter < -1)
+ return M_PROPERTY_UNAVAILABLE;
+ double current_chapter_start =
+ chapter_start_time(mpctx, chapter);
+ // If we are far enough into a chapter, seek back to the
+ // beginning of current chapter instead of previous one
+ if (current_chapter_start >= 0 &&
+ get_current_time(mpctx) - current_chapter_start >
+ mpctx->opts->chapter_seek_threshold)
+ step_all++;
+ }
+ } else // Absolute set
+ step_all = *(int *)arg - chapter;
chapter += step_all;
+ if (chapter < -1)
+ chapter = -1;
if (chapter >= get_chapter_count(mpctx) && step_all > 0) {
mpctx->stop_play = PT_NEXT_ENTRY;
} else {
diff --git a/mpvcore/options.c b/mpvcore/options.c
index e0d138a545..4a3c067404 100644
--- a/mpvcore/options.c
+++ b/mpvcore/options.c
@@ -661,6 +661,8 @@ const m_option_t mp_opts[] = {
OPT_FLAG("ordered-chapters", ordered_chapters, 0),
OPT_INTRANGE("chapter-merge-threshold", chapter_merge_threshold, 0, 0, 10000),
+ OPT_DOUBLE("chapter-seek-threshold", chapter_seek_threshold, 0),
+
// a-v sync stuff:
OPT_FLAG("correct-pts", correct_pts, 0),
OPT_CHOICE("pts-association-mode", user_pts_assoc_mode, 0,
@@ -772,6 +774,7 @@ const struct MPOpts mp_default_opts = {
.loop_times = -1,
.ordered_chapters = 1,
.chapter_merge_threshold = 100,
+ .chapter_seek_threshold = 5.0,
.load_config = 1,
.position_resume = 1,
.stream_cache_min_percent = 20.0,
diff --git a/mpvcore/options.h b/mpvcore/options.h
index ff2b5954ff..9309cc1a85 100644
--- a/mpvcore/options.h
+++ b/mpvcore/options.h
@@ -83,6 +83,7 @@ typedef struct MPOpts {
int loop_times;
int ordered_chapters;
int chapter_merge_threshold;
+ double chapter_seek_threshold;
int quiet;
int load_config;
int use_filedir_conf;