summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-11-16 22:47:17 +0100
committerwm4 <wm4@nowhere>2015-11-16 22:47:17 +0100
commit70df1608d6f74f3eba9a5e593822984194f63951 (patch)
treee6f332aa72d8fd8020d4ba9a214a4826ed6e711f /player
parente24e0ccd6828ff8a50fb290bed45a0f6d81eb00b (diff)
downloadmpv-70df1608d6f74f3eba9a5e593822984194f63951.tar.bz2
mpv-70df1608d6f74f3eba9a5e593822984194f63951.tar.xz
player: handle rebasing start time differently
Most of this is explained in the DOCS additions. This gives us slightly more sanity, because there is less interaction between the various parts. The goal is getting rid of the video_offset entirely. The simplification extends to the user API. In particular, we don't need to fix missing parts in the API, such as the lack for a seek command that seeks relatively to the start time. All these things are now transparent. (If someone really wants to know the real timestamps/start time, new properties would have to be added.)
Diffstat (limited to 'player')
-rw-r--r--player/command.c10
-rw-r--r--player/core.h1
-rw-r--r--player/loadfile.c12
-rw-r--r--player/misc.c19
-rw-r--r--player/osd.c3
-rw-r--r--player/playloop.c22
6 files changed, 30 insertions, 37 deletions
diff --git a/player/command.c b/player/command.c
index eadcc27296..2e29f994de 100644
--- a/player/command.c
+++ b/player/command.c
@@ -658,11 +658,8 @@ static int mp_property_percent_pos(void *ctx, struct m_property *prop,
static int mp_property_time_start(void *ctx, struct m_property *prop,
int action, void *arg)
{
- MPContext *mpctx = ctx;
- double start = get_start_time(mpctx);
- if (start < 0)
- return M_PROPERTY_UNAVAILABLE;
- return property_time(action, arg, start);
+ // minor backwards-compat.
+ return property_time(action, arg, 0);
}
/// Current position in seconds (RW)
@@ -723,8 +720,7 @@ static int mp_property_playback_time(void *ctx, struct m_property *prop,
return M_PROPERTY_UNAVAILABLE;
if (action == M_PROPERTY_SET) {
- double target = get_start_time(mpctx) + *(double *)arg;
- queue_seek(mpctx, MPSEEK_ABSOLUTE, target, MPSEEK_DEFAULT, true);
+ queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double *)arg, MPSEEK_DEFAULT, true);
return M_PROPERTY_OK;
}
return property_time(action, arg, get_playback_time(mpctx));
diff --git a/player/core.h b/player/core.h
index abe1316b41..9f47e2ad4e 100644
--- a/player/core.h
+++ b/player/core.h
@@ -454,7 +454,6 @@ void mp_print_version(struct mp_log *log, int always);
void wakeup_playloop(void *ctx);
// misc.c
-double get_start_time(struct MPContext *mpctx);
double get_main_demux_pts(struct MPContext *mpctx);
double get_track_video_offset(struct MPContext *mpctx, struct track *track);
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t);
diff --git a/player/loadfile.c b/player/loadfile.c
index 3007ef4f8e..be54b4c9c0 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -714,6 +714,9 @@ struct track *mp_add_external_file(struct MPContext *mpctx, char *filename,
if (!demuxer)
goto err_out;
+ if (filter != STREAM_SUB && opts->rebase_start_time)
+ demux_set_ts_offset(demuxer, -demuxer->start_time);
+
struct track *first = NULL;
for (int n = 0; n < demuxer->num_streams; n++) {
struct sh_stream *sh = demuxer->streams[n];
@@ -910,6 +913,10 @@ static void load_chapters(struct MPContext *mpctx)
talloc_free(mpctx->chapters);
mpctx->num_chapters = src->num_chapters;
mpctx->chapters = demux_copy_chapter_data(src->chapters, src->num_chapters);
+ if (mpctx->opts->rebase_start_time) {
+ for (int n = 0; n < mpctx->num_chapters; n++)
+ mpctx->chapters[n].pts -= src->start_time;
+ }
}
if (free_src)
free_demuxer_and_stream(src);
@@ -954,8 +961,11 @@ static void open_demux_thread(void *pctx)
args->err = MPV_ERROR_LOADING_FAILED;
}
}
- if (args->demux)
+ if (args->demux) {
args->tl = timeline_load(global, args->log, args->demux);
+ if (global->opts->rebase_start_time)
+ demux_set_ts_offset(args->demux, -args->demux->start_time);
+ }
}
static void open_demux_reentrant(struct MPContext *mpctx)
diff --git a/player/misc.c b/player/misc.c
index 1e67adbe32..0a3479590d 100644
--- a/player/misc.c
+++ b/player/misc.c
@@ -56,21 +56,20 @@ double get_relative_time(struct MPContext *mpctx)
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t)
{
double length = get_time_length(mpctx);
- double start = get_start_time(mpctx);
switch (t.type) {
case REL_TIME_ABSOLUTE:
return t.pos;
case REL_TIME_RELATIVE:
if (t.pos >= 0) {
- return start + t.pos;
+ return t.pos;
} else {
if (length >= 0)
- return MPMAX(start + length + t.pos, 0.0);
+ return MPMAX(length + t.pos, 0.0);
}
break;
case REL_TIME_PERCENT:
if (length >= 0)
- return start + length * (t.pos / 100.0);
+ return length * (t.pos / 100.0);
break;
case REL_TIME_CHAPTER:
if (chapter_start_time(mpctx, t.pos) != MP_NOPTS_VALUE)
@@ -87,12 +86,11 @@ 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 startpts = get_start_time(mpctx);
double start = rel_time_to_abs(mpctx, opts->play_start);
if (start == MP_NOPTS_VALUE)
- start = startpts;
+ start = 0;
double length = rel_time_to_abs(mpctx, opts->play_length);
- if (start != MP_NOPTS_VALUE && length != MP_NOPTS_VALUE)
+ if (length != MP_NOPTS_VALUE)
end = start + length;
}
if (opts->chapterrange[1] > 0) {
@@ -117,18 +115,11 @@ double get_main_demux_pts(struct MPContext *mpctx)
return main_new_pos;
}
-double get_start_time(struct MPContext *mpctx)
-{
- return mpctx->demuxer ? mpctx->demuxer->start_time : 0;
-}
-
// Get the offset from the given track to the video.
double get_track_video_offset(struct MPContext *mpctx, struct track *track)
{
if (track && track->under_timeline)
return mpctx->video_offset;
- if (track && track->is_external)
- return get_start_time(mpctx);
return 0;
}
diff --git a/player/osd.c b/player/osd.c
index cb49131cc1..ce3ba103cd 100644
--- a/player/osd.c
+++ b/player/osd.c
@@ -363,8 +363,7 @@ void set_osd_bar_chapters(struct MPContext *mpctx, int type)
} else {
int num = get_chapter_count(mpctx);
for (int n = 0; n < num; n++) {
- double time = chapter_start_time(mpctx, n) -
- get_start_time(mpctx);
+ double time = chapter_start_time(mpctx, n);
if (time >= 0) {
float pos = time / len;
MP_TARRAY_APPEND(mpctx, mpctx->osd_progbar.stops,
diff --git a/player/playloop.c b/player/playloop.c
index 643f290c48..6fa7b62292 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -205,7 +205,7 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
case MPSEEK_FACTOR: ;
double len = get_time_length(mpctx);
if (len >= 0)
- target_time = seek.amount * len + get_start_time(mpctx);
+ target_time = seek.amount * len;
break;
}
@@ -405,15 +405,14 @@ double get_playback_time(struct MPContext *mpctx)
double cur = get_current_time(mpctx);
if (cur == MP_NOPTS_VALUE)
return cur;
- double start = get_start_time(mpctx);
// During seeking, the time corresponds to the last seek time - apply some
// cosmetics to it.
if (mpctx->playback_pts == MP_NOPTS_VALUE) {
double length = get_time_length(mpctx);
if (length >= 0)
- cur = MPCLAMP(cur, start, start + length);
+ cur = MPCLAMP(cur, 0, length);
}
- return cur >= start ? cur - start : cur;
+ return cur;
}
// Return playback position in 0.0-1.0 ratio, or -1 if unknown.
@@ -423,15 +422,15 @@ double get_current_pos_ratio(struct MPContext *mpctx, bool use_range)
if (!demuxer)
return -1;
double ans = -1;
- double start = get_start_time(mpctx);
+ double start = 0;
double len = get_time_length(mpctx);
if (use_range) {
double startpos = rel_time_to_abs(mpctx, mpctx->opts->play_start);
double endpos = get_play_end_pts(mpctx);
- if (endpos == MP_NOPTS_VALUE || endpos > start + MPMAX(0, len))
- endpos = start + MPMAX(0, len);
- if (startpos == MP_NOPTS_VALUE || startpos < start)
- startpos = start;
+ if (endpos == MP_NOPTS_VALUE || endpos > MPMAX(0, len))
+ endpos = MPMAX(0, len);
+ if (startpos == MP_NOPTS_VALUE || startpos < 0)
+ startpos = 0;
if (endpos < startpos)
endpos = startpos;
start = startpos;
@@ -506,7 +505,7 @@ char *chapter_name(struct MPContext *mpctx, int chapter)
double chapter_start_time(struct MPContext *mpctx, int chapter)
{
if (chapter == -1)
- return get_start_time(mpctx);
+ return 0;
if (chapter >= 0 && chapter < mpctx->num_chapters)
return mpctx->chapters[chapter].pts;
return MP_NOPTS_VALUE;
@@ -785,8 +784,7 @@ 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),
- MPSEEK_DEFAULT, true);
+ queue_seek(mpctx, MPSEEK_ABSOLUTE, 0, MPSEEK_DEFAULT, true);
if (opts->loop_file > 0)
opts->loop_file--;
}