From 8d40b1e8ab2eeefae7a3bc20e176b2be707d3682 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 5 Jul 2014 16:54:49 +0200 Subject: [PATCH] demux: make start time a simple field Simpler, especially for later changes. --- demux/demux.c | 10 ---------- demux/demux.h | 3 +-- demux/demux_lavf.c | 12 +++++++----- player/misc.c | 2 +- player/timeline/tl_mpv_edl.c | 4 ++-- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/demux/demux.c b/demux/demux.c index b13225e642..9884f91845 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -803,16 +803,6 @@ double demuxer_get_time_length(struct demuxer *demuxer) return -1; } -double demuxer_get_start_time(struct demuxer *demuxer) -{ - double time; - if (stream_control(demuxer->stream, STREAM_CTRL_GET_START_TIME, &time) > 0) - return time; - if (demux_control(demuxer, DEMUXER_CTRL_GET_START_TIME, &time) > 0) - return time; - return 0; -} - int demuxer_angles_count(demuxer_t *demuxer) { int ris, angles = -1; diff --git a/demux/demux.h b/demux/demux.h index 3929e23c94..10c4984564 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -53,7 +53,6 @@ enum demuxer_type { enum demux_ctrl { DEMUXER_CTRL_SWITCHED_TRACKS = 1, DEMUXER_CTRL_GET_TIME_LENGTH, - DEMUXER_CTRL_GET_START_TIME, DEMUXER_CTRL_RESYNC, DEMUXER_CTRL_IDENTIFY_PROGRAM, DEMUXER_CTRL_STREAM_CTRL, // stupid workaround for legacy TV code @@ -178,6 +177,7 @@ typedef struct demuxer { char *filename; // same as stream->url enum demuxer_type type; int seekable; // flag + double start_time; /* Set if using absolute seeks for small movements is OK (no pts resets * that would make pts ambigious, preferably supports back/forward flags */ bool accurate_seek; @@ -263,7 +263,6 @@ int demuxer_add_chapter(struct demuxer *demuxer, struct bstr name, uint64_t start, uint64_t end, uint64_t demuxer_id); double demuxer_get_time_length(struct demuxer *demuxer); -double demuxer_get_start_time(struct demuxer *demuxer); /// Get current angle index. int demuxer_get_current_angle(struct demuxer *demuxer); diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 76a7d50471..619f06b32b 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -759,6 +759,13 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check) demuxer->ts_resets_possible = priv->avif->flags & AVFMT_TS_DISCONT; + demuxer->start_time = priv->avfc->start_time == AV_NOPTS_VALUE ? + 0 : (double)priv->avfc->start_time / AV_TIME_BASE; + + double time; + if (stream_control(demuxer->stream, STREAM_CTRL_GET_START_TIME, &time) > 0) + demuxer->start_time = time; + return 0; } @@ -913,11 +920,6 @@ static int demux_lavf_control(demuxer_t *demuxer, int cmd, void *arg) *((double *)arg) = (double)priv->avfc->duration / AV_TIME_BASE; return DEMUXER_CTRL_OK; - case DEMUXER_CTRL_GET_START_TIME: - *((double *)arg) = priv->avfc->start_time == AV_NOPTS_VALUE ? - 0 : (double)priv->avfc->start_time / AV_TIME_BASE; - return DEMUXER_CTRL_OK; - case DEMUXER_CTRL_SWITCHED_TRACKS: { select_tracks(demuxer, 0); diff --git a/player/misc.c b/player/misc.c index 1e22e4e097..abaf5b208a 100644 --- a/player/misc.c +++ b/player/misc.c @@ -116,7 +116,7 @@ double get_start_time(struct MPContext *mpctx) // timestamp it finds as start PTS. if (mpctx->nav_state) return 0; - return demuxer_get_start_time(demuxer); + return demuxer->start_time; } float mp_get_cache_percent(struct MPContext *mpctx) diff --git a/player/timeline/tl_mpv_edl.c b/player/timeline/tl_mpv_edl.c index 78fc8b7cdc..69cd4e97ce 100644 --- a/player/timeline/tl_mpv_edl.c +++ b/player/timeline/tl_mpv_edl.c @@ -203,7 +203,7 @@ static void resolve_timestamps(struct tl_part *part, struct demuxer *demuxer) part->length = length; } if (!part->offset_set) - part->offset = demuxer_get_start_time(demuxer); + part->offset = demuxer->start_time; } static void build_timeline(struct MPContext *mpctx, struct tl_parts *parts) @@ -223,7 +223,7 @@ static void build_timeline(struct MPContext *mpctx, struct tl_parts *parts) double len = source_get_length(source); if (len > 0) { - len += demuxer_get_start_time(source); + len += source->start_time; } else { MP_WARN(mpctx, "EDL: source file '%s' has unknown duration.\n", part->filename);