From ce8524cb479f3b3339c6d2b3e0f5a45051145204 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 26 Dec 2015 18:32:27 +0100 Subject: sub: cache subtitle state per track instead of per demuxer stream Since commit 6d9cb893, subtitle state doesn't survive timeline switches (ordered chapters etc.). So there is no point in caching the state per sh_stream anymore (which would be required to deal with multiple segments). Move the cache to struct track. (Whether it's worth caching the subtitle state just for the situation when subtitle tracks get reselected is questionable. But for now, it's nice to have the subtitles immediately show up when reselecting a subtitle.) --- player/loadfile.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'player/loadfile.c') diff --git a/player/loadfile.c b/player/loadfile.c index 8b35209d9f..f1664b2d9d 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -72,17 +72,15 @@ static void uninit_demuxer(struct MPContext *mpctx) mpctx->chapters = NULL; mpctx->num_chapters = 0; - // per-stream cached subtitle state - for (int i = 0; i < mpctx->num_sources; i++) - uninit_stream_sub_decoders(mpctx->sources[i]); - // close demuxers for external tracks for (int n = mpctx->num_tracks - 1; n >= 0; n--) { mpctx->tracks[n]->selected = false; mp_remove_track(mpctx, mpctx->tracks[n]); } - for (int i = 0; i < mpctx->num_tracks; i++) + for (int i = 0; i < mpctx->num_tracks; i++) { + sub_destroy(mpctx->tracks[i]->dec_sub); talloc_free(mpctx->tracks[i]); + } mpctx->num_tracks = 0; mpctx->timeline = NULL; @@ -337,10 +335,15 @@ bool timeline_switch_to_time(struct MPContext *mpctx, double pts) track->user_tid - 1); } - if (track->type == STREAM_SUB && track->stream) { - struct dec_sub *dec = track->stream->sub->dec_sub; - if (dec) - sub_control(dec, SD_CTRL_CLEAR, NULL); + if (track->dec_sub) { + for (int order = 0; order < 2; order++) { + if (mpctx->d_sub[order] == track->dec_sub) { + mpctx->d_sub[order] = NULL; + osd_set_sub(mpctx->osd, OSDTYPE_SUB + order, NULL); + } + } + sub_destroy(track->dec_sub); + track->dec_sub = NULL; } } } @@ -654,6 +657,8 @@ bool mp_remove_track(struct MPContext *mpctx, struct track *track) struct demuxer *d = track->demuxer; + sub_destroy(track->dec_sub); + int index = 0; while (index < mpctx->num_tracks && mpctx->tracks[index] != track) index++; @@ -674,7 +679,6 @@ bool mp_remove_track(struct MPContext *mpctx, struct track *track) break; } } - uninit_stream_sub_decoders(d); free_demuxer_and_stream(d); } -- cgit v1.2.3