diff options
Diffstat (limited to 'player/loadfile.c')
-rw-r--r-- | player/loadfile.c | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/player/loadfile.c b/player/loadfile.c index c472cad344..3e8c87f07f 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -96,8 +96,6 @@ static void uninit_demuxer(struct MPContext *mpctx) talloc_free(mpctx->sources); mpctx->sources = NULL; mpctx->num_sources = 0; - - mpctx->video_offset = 0; } static void uninit_stream(struct MPContext *mpctx) @@ -288,14 +286,24 @@ static void enable_demux_thread(struct MPContext *mpctx) } } -static bool timeline_set_part(struct MPContext *mpctx, int i, bool initial) +// Returns whether reinitialization is required (i.e. it switched to a new part) +bool timeline_switch_to_time(struct MPContext *mpctx, double pts) { - struct timeline_part *p = mpctx->timeline + mpctx->timeline_part; - struct timeline_part *n = mpctx->timeline + i; - mpctx->timeline_part = i; - mpctx->video_offset = n->start - n->source_start; - if (n->source == p->source && !initial) + if (!mpctx->timeline) + return false; + + int new_part = mpctx->num_timeline_parts - 1; + for (int i = 0; i < mpctx->num_timeline_parts; i++) { + if (pts < mpctx->timeline[i + 1].start) { + new_part = i; + break; + } + } + + if (mpctx->timeline_part == new_part) return false; + mpctx->timeline_part = new_part; + struct timeline_part *n = mpctx->timeline + mpctx->timeline_part; uninit_audio_chain(mpctx); uninit_video_chain(mpctx); @@ -311,6 +319,7 @@ static bool timeline_set_part(struct MPContext *mpctx, int i, bool initial) } mpctx->demuxer = n->source; + demux_set_ts_offset(mpctx->demuxer, n->start - n->source_start); // While another timeline was active, the selection of active tracks might // have been changed - possibly we need to update this source. @@ -330,7 +339,7 @@ static bool timeline_set_part(struct MPContext *mpctx, int i, bool initial) } } - if (!initial) { + if (mpctx->playback_initialized) { reselect_demux_streams(mpctx); enable_demux_thread(mpctx); } @@ -338,25 +347,6 @@ static bool timeline_set_part(struct MPContext *mpctx, int i, bool initial) return true; } -// Given pts, switch playback to the corresponding part. -// Return offset within that part. -double timeline_set_from_time(struct MPContext *mpctx, double pts, bool *need_reset) -{ - if (pts < 0) - pts = 0; - - int new = mpctx->num_timeline_parts - 1; - for (int i = 0; i < mpctx->num_timeline_parts; i++) { - if (pts < mpctx->timeline[i + 1].start) { - new = i; - break; - } - } - - *need_reset = timeline_set_part(mpctx, new, false); - return pts - mpctx->timeline[new].start + mpctx->timeline[new].source_start; -} - static int find_new_tid(struct MPContext *mpctx, enum stream_type t) { int new_id = 0; @@ -714,6 +704,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 +903,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 +951,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) @@ -1034,9 +1034,7 @@ static void play_current_file(struct MPContext *mpctx) mpctx->max_frames = -1; mpctx->video_speed = mpctx->audio_speed = opts->playback_speed; mpctx->speed_factor_a = mpctx->speed_factor_v = 1.0; - mpctx->display_sync_frameduration = 0.0; mpctx->display_sync_error = 0.0; - mpctx->broken_fps_header = false; mpctx->display_sync_active = false; mpctx->seek = (struct seek_params){ 0 }; @@ -1122,9 +1120,8 @@ reopen_file: load_chapters(mpctx); add_demuxer_tracks(mpctx, mpctx->track_layout); - mpctx->timeline_part = 0; - if (mpctx->timeline) - timeline_set_part(mpctx, mpctx->timeline_part, true); + mpctx->timeline_part = mpctx->num_timeline_parts; + timeline_switch_to_time(mpctx, 0); open_subtitles_from_options(mpctx); open_audiofiles_from_options(mpctx); @@ -1183,6 +1180,8 @@ reopen_file: goto terminate_playback; } + update_playback_speed(mpctx); + reinit_video_chain(mpctx); reinit_audio_chain(mpctx); reinit_subs(mpctx, 0); |