0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

player: make timeline switching slightly nicer

But not much.
This commit is contained in:
wm4 2015-11-18 20:58:07 +01:00
parent 74c862c68e
commit 76fcef618b
3 changed files with 27 additions and 30 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;