From 8d4a179c144cb3e36762b2c3cef55d1d3bb9f951 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 26 Dec 2015 18:34:18 +0100 Subject: sub: always recreate ASS_Renderer on subtitle decoder reinit This includes the case of switching ordered chapter boundaries. It will now be recreated on each timeline part switch. This shouldn't be much of a problem with modern libass. (Older libass versions use fontconfig for memory fonts, and will be very slow to reinitialize memory fonts.) --- player/core.h | 10 ------ player/loadfile.c | 1 - player/main.c | 3 -- player/sub.c | 99 +------------------------------------------------------ 4 files changed, 1 insertion(+), 112 deletions(-) (limited to 'player') diff --git a/player/core.h b/player/core.h index 1d68019c1a..6228732bd9 100644 --- a/player/core.h +++ b/player/core.h @@ -365,15 +365,6 @@ typedef struct MPContext { int last_chapter_seek; double last_chapter_pts; - /* Subtitle renderer. This is separate, because we want to keep fonts - * loaded across ordered chapters, instead of reloading and rescanning - * them on each transition. (Both of these objects contain this state.) - */ - pthread_mutex_t ass_lock; - struct ass_renderer *ass_renderer; - struct ass_library *ass_library; - struct mp_log *ass_log; - int last_dvb_step; bool paused; @@ -525,7 +516,6 @@ void uninit_sub(struct MPContext *mpctx, int order); void uninit_sub_all(struct MPContext *mpctx); void update_osd_msg(struct MPContext *mpctx); void update_subtitles(struct MPContext *mpctx); -void uninit_sub_renderer(struct MPContext *mpctx); // video.c void reset_video_state(struct MPContext *mpctx); diff --git a/player/loadfile.c b/player/loadfile.c index f1664b2d9d..d98f8f942a 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1254,7 +1254,6 @@ terminate_playback: uninit_audio_chain(mpctx); uninit_video_chain(mpctx); uninit_sub_all(mpctx); - uninit_sub_renderer(mpctx); uninit_demuxer(mpctx); uninit_stream(mpctx); if (!opts->gapless_audio && !mpctx->encode_lavc_ctx) diff --git a/player/main.c b/player/main.c index ce438636c3..b0a577238d 100644 --- a/player/main.c +++ b/player/main.c @@ -222,7 +222,6 @@ void mp_destroy(struct MPContext *mpctx) pthread_detach(pthread_self()); mp_msg_uninit(mpctx->global); - pthread_mutex_destroy(&mpctx->ass_lock); talloc_free(mpctx); } @@ -330,8 +329,6 @@ struct MPContext *mp_create(void) .playback_abort = mp_cancel_new(mpctx), }; - pthread_mutex_init(&mpctx->ass_lock, NULL); - mpctx->global = talloc_zero(mpctx, struct mpv_global); // Nothing must call mp_msg*() and related before this diff --git a/player/sub.c b/player/sub.c index 25af9e5c15..9c69df39ab 100644 --- a/player/sub.c +++ b/player/sub.c @@ -30,7 +30,6 @@ #include "common/global.h" #include "stream/stream.h" -#include "sub/ass_mp.h" #include "sub/dec_sub.h" #include "demux/demux.h" #include "video/mp_image.h" @@ -39,98 +38,6 @@ #include "core.h" -#if HAVE_LIBASS - -static const char *const font_mimetypes[] = { - "application/x-truetype-font", - "application/vnd.ms-opentype", - "application/x-font-ttf", - "application/x-font", // probably incorrect - NULL -}; - -static const char *const font_exts[] = {".ttf", ".ttc", ".otf", NULL}; - -static bool attachment_is_font(struct mp_log *log, struct demux_attachment *att) -{ - if (!att->name || !att->type || !att->data || !att->data_size) - return false; - for (int n = 0; font_mimetypes[n]; n++) { - if (strcmp(font_mimetypes[n], att->type) == 0) - return true; - } - // fallback: match against file extension - char *ext = strlen(att->name) > 4 ? att->name + strlen(att->name) - 4 : ""; - for (int n = 0; font_exts[n]; n++) { - if (strcasecmp(ext, font_exts[n]) == 0) { - mp_warn(log, "Loading font attachment '%s' with MIME type %s. " - "Assuming this is a broken Matroska file, which was " - "muxed without setting a correct font MIME type.\n", - att->name, att->type); - return true; - } - } - return false; -} - -static void add_subtitle_fonts_from_sources(struct MPContext *mpctx) -{ - if (mpctx->opts->ass_enabled) { - for (int j = 0; j < mpctx->num_sources; j++) { - struct demuxer *d = mpctx->sources[j]; - for (int i = 0; i < d->num_attachments; i++) { - struct demux_attachment *att = d->attachments + i; - if (mpctx->opts->use_embedded_fonts && - attachment_is_font(mpctx->log, att)) - { - ass_add_font(mpctx->ass_library, att->name, att->data, - att->data_size); - } - } - } - } -} - -static void init_sub_renderer(struct MPContext *mpctx) -{ - struct MPOpts *opts = mpctx->opts; - - if (mpctx->ass_renderer) - return; - - if (!mpctx->ass_log) - mpctx->ass_log = mp_log_new(mpctx, mpctx->global->log, "!libass"); - - mpctx->ass_library = mp_ass_init(mpctx->global, mpctx->ass_log); - - add_subtitle_fonts_from_sources(mpctx); - - if (opts->ass_style_override) - ass_set_style_overrides(mpctx->ass_library, opts->ass_force_style_list); - - mpctx->ass_renderer = ass_renderer_init(mpctx->ass_library); - - mp_ass_configure_fonts(mpctx->ass_renderer, opts->sub_text_style, - mpctx->global, mpctx->ass_log); -} - -void uninit_sub_renderer(struct MPContext *mpctx) -{ - if (mpctx->ass_renderer) - ass_renderer_done(mpctx->ass_renderer); - mpctx->ass_renderer = NULL; - if (mpctx->ass_library) - ass_library_done(mpctx->ass_library); - mpctx->ass_library = NULL; -} - -#else /* HAVE_LIBASS */ - -static void init_sub_renderer(struct MPContext *mpctx) {} -void uninit_sub_renderer(struct MPContext *mpctx) {} - -#endif - static void reset_subtitles(struct MPContext *mpctx, int order) { if (mpctx->d_sub[order]) @@ -248,12 +155,8 @@ static void reinit_subdec(struct MPContext *mpctx, struct track *track) mpctx->d_video ? mpctx->d_video->header->video : NULL; float fps = sh_video ? sh_video->fps : 25; - init_sub_renderer(mpctx); - sub_set_video_fps(dec_sub, fps); - sub_set_ass_renderer(dec_sub, mpctx->ass_library, mpctx->ass_renderer, - &mpctx->ass_lock); - sub_init_from_sh(dec_sub, track->stream); + sub_init(dec_sub, track->demuxer, track->stream); // Don't do this if the file has video/audio streams. Don't do it even // if it has only sub streams, because reading packets will change the -- cgit v1.2.3