From 639e672bd153e06cfc01ced6c2a48b45870e8f31 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 23 Nov 2013 21:37:15 +0100 Subject: player: rearrange how subtitle context and stream headers are used Use sh_stream over sh_sub. Use dec_sub (and mpctx->d_sub) instead of the stream header. This aligns the subtitle code with the recent audio and video refactoring. sh_sub still has the decoder context, though. This is because we want to avoid reinit when switching segments with ordered chapters. (Reinit is fast, except for creating the ASS_Renderer, which in turn triggers fontconfig.) Not sure how much this matters, though, because the initial segment switch will lazily initialize the decoder anyway. --- sub/dec_sub.c | 26 ++++++++++++++------------ sub/dec_sub.h | 6 +++--- 2 files changed, 17 insertions(+), 15 deletions(-) (limited to 'sub') diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 1a6cc6b0aa..cb76acc248 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -162,15 +162,16 @@ static int sub_init_decoder(struct dec_sub *sub, struct sd *sd) return 0; } -void sub_init_from_sh(struct dec_sub *sub, struct sh_sub *sh) +void sub_init_from_sh(struct dec_sub *sub, struct sh_stream *sh) { assert(!sub->num_sd); + assert(sh && sh->sub); - if (sh->extradata && !sub->init_sd.extradata) - sub_set_extradata(sub, sh->extradata, sh->extradata_len); + if (sh->sub->extradata && !sub->init_sd.extradata) + sub_set_extradata(sub, sh->sub->extradata, sh->sub->extradata_len); struct sd init_sd = sub->init_sd; - init_sd.codec = sh->gsh->codec; - init_sd.ass_track = sh->track; + init_sd.codec = sh->codec; + init_sd.ass_track = sh->sub->track; while (sub->num_sd < MAX_NUM_SD) { struct sd *sd = talloc(NULL, struct sd); @@ -199,7 +200,7 @@ void sub_init_from_sh(struct dec_sub *sub, struct sh_sub *sh) sub_uninit(sub); mp_msg(MSGT_OSD, MSGL_ERR, "Could not find subtitle decoder for format '%s'.\n", - sh->gsh->codec ? sh->gsh->codec : ""); + sh->codec ? sh->codec : ""); } static struct demux_packet *get_decoded_packet(struct sd *sd) @@ -362,11 +363,12 @@ static void add_packet(struct packet_list *subs, struct demux_packet *pkt) // Read all packets from the demuxer and decode/add them. Returns false if // there are circumstances which makes this not possible. -bool sub_read_all_packets(struct dec_sub *sub, struct sh_sub *sh) +bool sub_read_all_packets(struct dec_sub *sub, struct sh_stream *sh) { + assert(sh && sh->sub); struct MPOpts *opts = sub->opts; - if (!sub_accept_packets_in_advance(sub) || sh->track || sub->num_sd < 1) + if (!sub_accept_packets_in_advance(sub) || sh->sub->track || sub->num_sd < 1) return false; struct packet_list *subs = talloc_zero(NULL, struct packet_list); @@ -385,7 +387,7 @@ bool sub_read_all_packets(struct dec_sub *sub, struct sh_sub *sh) preprocess = 1; for (;;) { - struct demux_packet *pkt = demux_read_packet(sh->gsh); + struct demux_packet *pkt = demux_read_packet(sh); if (!pkt) break; if (preprocess) { @@ -403,7 +405,7 @@ bool sub_read_all_packets(struct dec_sub *sub, struct sh_sub *sh) } } - if (opts->sub_cp && !sh->is_utf8) + if (opts->sub_cp && !sh->sub->is_utf8) sub->charset = guess_sub_cp(subs, opts->sub_cp); if (sub->charset && sub->charset[0] && !mp_charset_is_utf8(sub->charset)) @@ -412,7 +414,7 @@ bool sub_read_all_packets(struct dec_sub *sub, struct sh_sub *sh) double sub_speed = 1.0; // 23.976 FPS is used as default timebase for frame based formats - if (sub->video_fps && sh->frame_based) + if (sub->video_fps && sh->sub->frame_based) sub_speed *= sub->video_fps / 23.976; if (opts->sub_fps && sub->video_fps) @@ -426,7 +428,7 @@ bool sub_read_all_packets(struct dec_sub *sub, struct sh_sub *sh) if (!opts->suboverlap_enabled) fix_overlaps_and_gaps(subs); - if (sh->gsh->codec && strcmp(sh->gsh->codec, "microdvd") == 0) { + if (sh->codec && strcmp(sh->codec, "microdvd") == 0) { // The last subtitle event in MicroDVD subs can have duration unset, // which means show the subtitle until end of video. // See FFmpeg FATE MicroDVD_capability_tester.sub diff --git a/sub/dec_sub.h b/sub/dec_sub.h index b269326cac..9ff2b366bd 100644 --- a/sub/dec_sub.h +++ b/sub/dec_sub.h @@ -6,7 +6,7 @@ #include "sub/sub.h" -struct sh_sub; +struct sh_stream; struct ass_track; struct MPOpts; struct demux_packet; @@ -29,11 +29,11 @@ void sub_set_video_fps(struct dec_sub *sub, double fps); void sub_set_extradata(struct dec_sub *sub, void *data, int data_len); void sub_set_ass_renderer(struct dec_sub *sub, struct ass_library *ass_library, struct ass_renderer *ass_renderer); -void sub_init_from_sh(struct dec_sub *sub, struct sh_sub *sh); +void sub_init_from_sh(struct dec_sub *sub, struct sh_stream *sh); bool sub_is_initialized(struct dec_sub *sub); -bool sub_read_all_packets(struct dec_sub *sub, struct sh_sub *sh); +bool sub_read_all_packets(struct dec_sub *sub, struct sh_stream *sh); bool sub_accept_packets_in_advance(struct dec_sub *sub); void sub_decode(struct dec_sub *sub, struct demux_packet *packet); void sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, double pts, -- cgit v1.2.3