>From d50c977cf7c082e7ed39ab7a7355d5157c26d52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Thu, 16 Dec 2010 21:24:48 +0100 Subject: [PATCH 1/3] Factorize subtitles loading between mplayer and mencoder. --- mencoder.c | 18 +----------------- mplayer.c | 16 +--------------- sub/subreader.c | 28 +++++++++++++++++++++++++++- sub/subreader.h | 2 +- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/mencoder.c b/mencoder.c index 57afbc2..6efe907 100644 --- a/mencoder.c +++ b/mencoder.c @@ -1019,23 +1019,7 @@ default: { // after reading video params we should load subtitles because // we know fps so now we can adjust subtitles time to ~6 seconds AST // check .sub - if(sub_name && sub_name[0]){ - for (i = 0; sub_name[i] != NULL; ++i) - add_subtitles (sub_name[i], sh_video->fps, 0); - } else - if(sub_auto && filename) { // auto load sub file ... - char **tmp = NULL; - int i = 0; - char *psub = get_path( "sub/" ); - tmp = sub_filenames((psub ? psub : ""), filename); - free(psub); - while (tmp[i]) - { - add_subtitles (tmp[i], sh_video->fps, 0); - free(tmp[i++]); - } - free(tmp); - } + load_subtitles(filename, sh_video->fps, add_subtitles); mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n"); init_best_video_codec(sh_video,video_codec_list,video_fm_list); diff --git a/mplayer.c b/mplayer.c index 83c5771..c0e540e 100644 --- a/mplayer.c +++ b/mplayer.c @@ -3508,21 +3508,7 @@ if(1 || mpctx->sh_video) { // check .sub double fps = mpctx->sh_video ? mpctx->sh_video->fps : 25; current_module="read_subtitles_file"; - if(sub_name){ - for (i = 0; sub_name[i] != NULL; ++i) - add_subtitles (sub_name[i], fps, 0); - } - if(sub_auto) { // auto load sub file ... - char *psub = get_path( "sub/" ); - char **tmp = sub_filenames((psub ? psub : ""), filename); - int i = 0; - free(psub); // release the buffer created by get_path() above - while (tmp[i]) { - add_subtitles (tmp[i], fps, 1); - free(tmp[i++]); - } - free(tmp); - } + load_subtitles(filename, fps, add_subtitles); if (mpctx->set_of_sub_size > 0) mpctx->sub_counts[SUB_SOURCE_SUBS] = mpctx->set_of_sub_size; } diff --git a/sub/subreader.c b/sub/subreader.c index 42d523b..de74823 100644 --- a/sub/subreader.c +++ b/sub/subreader.c @@ -33,6 +33,7 @@ #include "config.h" #include "mp_msg.h" #include "mpcommon.h" +#include "path.h" #include "subreader.h" #include "subassconvert.h" #include "sub.h" @@ -1889,7 +1890,7 @@ static int compare_sub_priority(const void *a, const void *b) } } -char** sub_filenames(const char* path, char *fname) +static char **sub_filenames(const char *path, const char *fname) { char *f_dir, *f_fname, *f_fname_noext, *f_fname_trim, *tmp, *tmp_sub_id; char *tmp_fname_noext, *tmp_fname_trim, *tmp_fname_ext, *tmpresult; @@ -2070,6 +2071,31 @@ char** sub_filenames(const char* path, char *fname) return result2; } +/** + * @brief Load all subtitles matching the subtitle filename + * + * @param fname Path to subtitle filename + * @param fps FPS parameter for the add subtitle function + * @param add_f Add subtitle function to call for each sub + */ +void load_subtitles(const char *fname, int fps, void add_f(char *, float, int)) +{ + int i; + if (sub_name) + for (i = 0; sub_name[i]; i++) + add_f(sub_name[i], fps, 0); + if (sub_auto && fname) { + char *psub = get_path("sub/"); + char **tmp = sub_filenames((psub ? psub : ""), fname); + free(psub); + for (i = 0; tmp[i]; i++) { + add_f(tmp[i], fps, 1); + free(tmp[i]); + } + free(tmp); + } +} + void list_sub_file(sub_data* subd){ int i,j; subtitle *subs = subd->subtitles; diff --git a/sub/subreader.h b/sub/subreader.h index 323b576..dd08a22 100644 --- a/sub/subreader.h +++ b/sub/subreader.h @@ -94,7 +94,7 @@ void subcp_close (void); /* for demux_ogg.c */ const char* guess_buffer_cp(unsigned char* buffer, int buflen, const char *preferred_language, const char *fallback); const char* guess_cp(struct stream *st, const char *preferred_language, const char *fallback); #endif -char ** sub_filenames(const char *path, char *fname); +void load_subtitles(const char *fname, int fps, void add_f(char *, float, int)); void list_sub_file(sub_data* subd); void dump_srt(sub_data* subd, float fps); void dump_mpsub(sub_data* subd, float fps); -- 1.7.3.4