summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--player/core.h2
-rw-r--r--player/loadfile.c41
-rw-r--r--player/playloop.c14
3 files changed, 27 insertions, 30 deletions
diff --git a/player/core.h b/player/core.h
index 2f9d2828ac..c35e3d034b 100644
--- a/player/core.h
+++ b/player/core.h
@@ -430,7 +430,7 @@ void mp_switch_track_n(struct MPContext *mpctx, int order,
void mp_deselect_track(struct MPContext *mpctx, struct track *track);
struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type,
int tid);
-void timeline_set_part(struct MPContext *mpctx, int i, bool initial);
+bool timeline_switch_to_time(struct MPContext *mpctx, double pts);
int timeline_get_for_time(struct MPContext *mpctx, double pts);
void add_demuxer_tracks(struct MPContext *mpctx, struct demuxer *demuxer);
bool mp_remove_track(struct MPContext *mpctx, struct track *track);
diff --git a/player/loadfile.c b/player/loadfile.c
index 879c1747e7..fe8e5021e6 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -286,10 +286,24 @@ static void enable_demux_thread(struct MPContext *mpctx)
}
}
-void 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 *n = mpctx->timeline + i;
- mpctx->timeline_part = i;
+ 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);
@@ -325,24 +339,12 @@ void timeline_set_part(struct MPContext *mpctx, int i, bool initial)
}
}
- if (!initial) {
+ if (mpctx->playback_initialized) {
reselect_demux_streams(mpctx);
enable_demux_thread(mpctx);
}
-}
-
-// Given pts, return the segment number of the corresponding part.
-int timeline_get_for_time(struct MPContext *mpctx, double pts)
-{
- if (pts < 0)
- pts = 0;
- for (int i = 0; i < mpctx->num_timeline_parts; i++) {
- if (pts < mpctx->timeline[i + 1].start)
- return i;
- }
-
- return mpctx->num_timeline_parts - 1;
+ return true;
}
static int find_new_tid(struct MPContext *mpctx, enum stream_type t)
@@ -1118,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);
diff --git a/player/playloop.c b/player/playloop.c
index da21c64d34..5efb048cb2 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -228,15 +228,11 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
hr_seek &= seek.type == MPSEEK_ABSOLUTE; // otherwise, no target PTS known
double demuxer_amount = seek.amount;
- if (mpctx->timeline) {
- int segment = timeline_get_for_time(mpctx, seek.amount);
- if (segment != mpctx->timeline_part) {
- timeline_set_part(mpctx, segment, false);
- reinit_video_chain(mpctx);
- reinit_audio_chain(mpctx);
- reinit_subs(mpctx, 0);
- reinit_subs(mpctx, 1);
- }
+ if (timeline_switch_to_time(mpctx, seek.amount)) {
+ reinit_video_chain(mpctx);
+ reinit_audio_chain(mpctx);
+ reinit_subs(mpctx, 0);
+ reinit_subs(mpctx, 1);
}
int demuxer_style = 0;