summaryrefslogtreecommitdiffstats
path: root/player/sub.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-12-26 18:32:27 +0100
committerwm4 <wm4@nowhere>2015-12-26 18:32:27 +0100
commitce8524cb479f3b3339c6d2b3e0f5a45051145204 (patch)
treef82095783f5762c3229f6d7b71a029b794bf1efa /player/sub.c
parent504286b00689ad2c436bdd230b5a63cd66ba8cd6 (diff)
downloadmpv-ce8524cb479f3b3339c6d2b3e0f5a45051145204.tar.bz2
mpv-ce8524cb479f3b3339c6d2b3e0f5a45051145204.tar.xz
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.)
Diffstat (limited to 'player/sub.c')
-rw-r--r--player/sub.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/player/sub.c b/player/sub.c
index df84e910af..25af9e5c15 100644
--- a/player/sub.c
+++ b/player/sub.c
@@ -144,22 +144,11 @@ void reset_subtitle_state(struct MPContext *mpctx)
reset_subtitles(mpctx, 1);
}
-void uninit_stream_sub_decoders(struct demuxer *demuxer)
-{
- for (int i = 0; i < demux_get_num_stream(demuxer); i++) {
- struct sh_stream *sh = demux_get_stream(demuxer, i);
- if (sh->sub) {
- sub_destroy(sh->sub->dec_sub);
- sh->sub->dec_sub = NULL;
- }
- }
-}
-
void uninit_sub(struct MPContext *mpctx, int order)
{
if (mpctx->d_sub[order]) {
reset_subtitles(mpctx, order);
- mpctx->d_sub[order] = NULL; // Note: not free'd.
+ mpctx->d_sub[order] = NULL; // not destroyed
osd_set_sub(mpctx->osd, OSDTYPE_SUB + order, NULL);
reselect_demux_streams(mpctx);
}
@@ -211,8 +200,6 @@ static void update_subtitle(struct MPContext *mpctx, int order)
struct sh_stream *sh_stream = track->stream;
bool interleaved = is_interleaved(mpctx, track);
- assert(sh_stream->sub->dec_sub == dec_sub);
-
while (1) {
if (interleaved && !demux_has_packet(sh_stream))
break;
@@ -248,11 +235,12 @@ void update_subtitles(struct MPContext *mpctx)
update_subtitle(mpctx, 1);
}
-static void reinit_subdec(struct MPContext *mpctx, struct track *track,
- struct dec_sub *dec_sub)
+static void reinit_subdec(struct MPContext *mpctx, struct track *track)
{
struct MPOpts *opts = mpctx->opts;
+ struct dec_sub *dec_sub = track->dec_sub;
+
if (sub_is_initialized(dec_sub))
return;
@@ -288,13 +276,11 @@ void reinit_subs(struct MPContext *mpctx, int order)
if (!sh)
return;
- // The decoder is cached in the stream header in order to make ordered
- // chapters work better.
- if (!sh->sub->dec_sub)
- sh->sub->dec_sub = sub_create(mpctx->global);
- mpctx->d_sub[order] = sh->sub->dec_sub;
+ if (!track->dec_sub)
+ track->dec_sub = sub_create(mpctx->global);
+ mpctx->d_sub[order] = track->dec_sub;
- reinit_subdec(mpctx, track, sh->sub->dec_sub);
- osd_set_sub(mpctx->osd, OSDTYPE_SUB + order, sh->sub->dec_sub);
- sub_control(sh->sub->dec_sub, SD_CTRL_SET_TOP, &(bool){!!order});
+ reinit_subdec(mpctx, track);
+ osd_set_sub(mpctx->osd, OSDTYPE_SUB + order, track->dec_sub);
+ sub_control(track->dec_sub, SD_CTRL_SET_TOP, &(bool){!!order});
}