aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Leo Izen <leo.izen@gmail.com>2017-12-03 20:26:42 -0500
committerGravatar Leo Izen <leo.izen@gmail.com>2017-12-03 21:57:34 -0500
commita6ca1677941b817cce401eb4d75f9c049b789b55 (patch)
treea7859885e247f693508df5eae12a7fcf1d50fe84
parente92d1b72a79c53369fdfd03b2d1499aa410324db (diff)
player: add get_play_start_pts
Added a get_play_start_pts function to coincide with the already-existing get_play_end_pts. This prevents code duplication and also serves to make it so code that probes the start time (such as get_current_pos_ratio) will work correctly with chapters. Included is a bug fix for misc.c/rel_time_to_abs that makes it work correctly with chapters when --rebase-start-time=no is set.
-rw-r--r--player/core.h1
-rw-r--r--player/loadfile.c19
-rw-r--r--player/misc.c52
-rw-r--r--player/playloop.c2
4 files changed, 60 insertions, 14 deletions
diff --git a/player/core.h b/player/core.h
index c3ceefd17d..80d7ad88f4 100644
--- a/player/core.h
+++ b/player/core.h
@@ -542,6 +542,7 @@ void issue_refresh_seek(struct MPContext *mpctx, enum seek_precision min_prec);
// misc.c
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t);
double get_play_end_pts(struct MPContext *mpctx);
+double get_play_start_pts(struct MPContext *mpctx);
void merge_playlist_files(struct playlist *pl);
float mp_get_cache_percent(struct MPContext *mpctx);
bool mp_get_cache_idle(struct MPContext *mpctx);
diff --git a/player/loadfile.c b/player/loadfile.c
index b5c7cae6cb..46f5d4e4f3 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -1330,17 +1330,16 @@ reopen_file:
goto terminate_playback;
}
- double startpos = rel_time_to_abs(mpctx, opts->play_start);
- if (startpos == MP_NOPTS_VALUE && opts->chapterrange[0] > 0) {
- double start = chapter_start_time(mpctx, opts->chapterrange[0] - 1);
- if (start != MP_NOPTS_VALUE)
- startpos = start;
- }
- if (startpos != MP_NOPTS_VALUE) {
- if (!opts->rebase_start_time) {
- startpos += mpctx->demuxer->start_time;
+ double play_start_pts = get_play_start_pts(mpctx);
+ if (play_start_pts != MP_NOPTS_VALUE) {
+ /*
+ * get_play_start_pts returns rebased values, but
+ * we want an un rebased value to feed to seeker.
+ */
+ if (!opts->rebase_start_time){
+ play_start_pts += mpctx->demuxer->start_time;
}
- queue_seek(mpctx, MPSEEK_ABSOLUTE, startpos, MPSEEK_DEFAULT, 0);
+ queue_seek(mpctx, MPSEEK_ABSOLUTE, play_start_pts, MPSEEK_DEFAULT, 0);
execute_queued_seek(mpctx);
}
diff --git a/player/misc.c b/player/misc.c
index 87e6521b14..9ca1ea9750 100644
--- a/player/misc.c
+++ b/player/misc.c
@@ -48,6 +48,8 @@
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t)
{
double length = get_time_length(mpctx);
+ // declaration up here because of C grammar quirk
+ double chapter_start_pts;
switch (t.type) {
case REL_TIME_ABSOLUTE:
return t.pos;
@@ -64,8 +66,20 @@ double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t)
return length * (t.pos / 100.0);
break;
case REL_TIME_CHAPTER:
- if (chapter_start_time(mpctx, t.pos) != MP_NOPTS_VALUE)
- return chapter_start_time(mpctx, t.pos);
+ chapter_start_pts = chapter_start_time(mpctx, t.pos);
+ if (chapter_start_pts != MP_NOPTS_VALUE){
+ /*
+ * rel_time_to_abs always returns rebased timetamps,
+ * even with --rebase-start-time=no. (See the above two
+ * cases.) chapter_start_time values are not rebased without
+ * --rebase-start-time=yes, so we need to rebase them
+ * here to be consistent with the rest of rel_time_to_abs.
+ */
+ if (mpctx->demuxer && !mpctx->opts->rebase_start_time){
+ chapter_start_pts -= mpctx->demuxer->start_time;
+ }
+ return chapter_start_pts;
+ }
break;
}
return MP_NOPTS_VALUE;
@@ -78,7 +92,7 @@ double get_play_end_pts(struct MPContext *mpctx)
if (opts->play_end.type) {
end = rel_time_to_abs(mpctx, opts->play_end);
} else if (opts->play_length.type) {
- double start = rel_time_to_abs(mpctx, opts->play_start);
+ double start = get_play_start_pts(mpctx);
if (start == MP_NOPTS_VALUE)
start = 0;
double length = rel_time_to_abs(mpctx, opts->play_length);
@@ -99,6 +113,38 @@ double get_play_end_pts(struct MPContext *mpctx)
return end;
}
+/**
+ * Get the rebased PTS for which playback should start.
+ * The order of priority is as follows:
+ * 1. --start, if set.
+ * 2. The start chapter, if set.
+ * 3. MP_NOPTS_VALUE.
+ * If unspecified, return MP_NOPTS_VALUE.
+ * Does not return zero unless the start time is explicitly set to zero.
+ */
+double get_play_start_pts(struct MPContext *mpctx)
+{
+ struct MPOpts *opts = mpctx->opts;
+ double play_start_pts = rel_time_to_abs(mpctx, opts->play_start);
+ if (play_start_pts == MP_NOPTS_VALUE && opts->chapterrange[0] > 0) {
+ double chapter_start_pts = chapter_start_time(mpctx, opts->chapterrange[0] - 1);
+ if (chapter_start_pts != MP_NOPTS_VALUE) {
+ /*
+ * get_play_start_pts always returns rebased timetamps,
+ * even with --rebase-start-time=no. chapter_start_time
+ * values are not rebased without --rebase-start-time=yes,
+ * so we need to rebase them here to be consistent with
+ * the rest of get_play_start_pts.
+ */
+ if (mpctx->demuxer && !mpctx->opts->rebase_start_time){
+ chapter_start_pts -= mpctx->demuxer->start_time;
+ }
+ play_start_pts = chapter_start_pts;
+ }
+ }
+ return play_start_pts;
+}
+
double get_track_seek_offset(struct MPContext *mpctx, struct track *track)
{
struct MPOpts *opts = mpctx->opts;
diff --git a/player/playloop.c b/player/playloop.c
index c53dd0fed0..2d1db03867 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -482,7 +482,7 @@ double get_current_pos_ratio(struct MPContext *mpctx, bool use_range)
double start = 0;
double len = get_time_length(mpctx);
if (use_range) {
- double startpos = rel_time_to_abs(mpctx, mpctx->opts->play_start);
+ double startpos = get_play_start_pts(mpctx);
double endpos = get_play_end_pts(mpctx);
if (endpos == MP_NOPTS_VALUE || endpos > MPMAX(0, len))
endpos = MPMAX(0, len);