From 43c3a07f5812bfe32b1d65cced7f4d07213e1c72 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sat, 16 Jan 2010 17:38:58 +0200 Subject: subtitles: avoid running subreader.c parser when using libass When loading external subtitle files, the code always tried parsing the file with subreader.c sub_read_file() first, even if libass was then used to parse and render the file (the results of the first parsing would be ignored in that case). This could cause problems like unnecessary error messages. Change the code to try libass parsing first if enabled, and skip subreader.c parsing if that succeeds. --- mplayer.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index 2668bd07f0..90317dcbc1 100644 --- a/mplayer.c +++ b/mplayer.c @@ -1049,39 +1049,42 @@ static int playtree_add_playlist(struct MPContext *mpctx, play_tree_t* entry) void add_subtitles(struct MPContext *mpctx, char *filename, float fps, int noerr) { struct MPOpts *opts = &mpctx->opts; - sub_data *subd; -#ifdef CONFIG_ASS - ASS_Track *asst = 0; -#endif + sub_data *subd = NULL; + struct ass_track *asst = NULL; if (filename == NULL || mpctx->set_of_sub_size >= MAX_SUBTITLE_FILES) { return; } - subd = sub_read_file(filename, fps); #ifdef CONFIG_ASS - if (opts->ass_enabled) + if (opts->ass_enabled) { #ifdef CONFIG_ICONV asst = ass_read_file(ass_library, filename, sub_cp); #else asst = ass_read_file(ass_library, filename, 0); #endif - if (opts->ass_enabled && subd && !asst) - asst = ass_read_subdata(ass_library, subd, fps); - - if (!asst && !subd) -#else - if(!subd) + if (!asst) { + subd = sub_read_file(filename, fps); + if (subd) { + asst = ass_read_subdata(ass_library, subd, fps); + if (asst) { + sub_free(subd); + subd = NULL; + } + } + } + } else #endif - mp_tmsg(MSGT_CPLAYER, noerr ? MSGL_WARN : MSGL_ERR, "Cannot load subtitles: %s\n", - filename_recode(filename)); + subd = sub_read_file(filename, fps); + + + if (!asst && !subd) { + mp_tmsg(MSGT_CPLAYER, noerr ? MSGL_WARN : MSGL_ERR, + "Cannot load subtitles: %s\n", filename_recode(filename)); + return; + } -#ifdef CONFIG_ASS - if (!asst && !subd) return; mpctx->set_of_ass_tracks[mpctx->set_of_sub_size] = asst; -#else - if (!subd) return; -#endif mpctx->set_of_subtitles[mpctx->set_of_sub_size] = subd; mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", mpctx->set_of_sub_size); mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", -- cgit v1.2.3