# HG changeset patch # User cboesch # Date 1295787855 0 # Node ID 732cd2afae101fdb19b99321274c694abb669bf7 # Parent 5310794ef052e7840cebeeefb3986f809e7289f5 Replace hacky vobsub loading with a new clean one. diff -r 5310794ef052 -r 732cd2afae10 mencoder.c --- a/mencoder.c Fri Jan 21 15:33:12 2011 +0000 +++ b/mencoder.c Sun Jan 23 13:04:15 2011 +0000 @@ -182,6 +182,7 @@ float sub_delay=0; float sub_fps=0; int sub_auto = 0; +char *vobsub_name = NULL; int subcc_enabled=0; int suboverlap_enabled = 1; diff -r 5310794ef052 -r 732cd2afae10 mplayer.c --- a/mplayer.c Fri Jan 21 15:33:12 2011 +0000 +++ b/mplayer.c Sun Jan 23 13:04:15 2011 +0000 @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -1079,6 +1080,22 @@ filename_recode(filename)); } +static int add_vob_subtitle(const char *vobname, const char * const ifo, int force, void *spu) +{ + if (!vobname) + return 0; + + assert(!vo_vobsub); + + vo_vobsub = vobsub_open(vobname, ifo, force, spu); + + if (!vo_vobsub && force) + mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, + filename_recode(vobname)); + + return !!vo_vobsub; +} + // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken. void update_set_of_subtitles(void) // subdata was changed, set_of_sub... have to be updated. @@ -3134,34 +3151,7 @@ //==================== Open VOB-Sub ============================ current_module="vobsub"; - if (vobsub_name){ - vo_vobsub=vobsub_open(vobsub_name,spudec_ifo,1,&vo_spudec); - if(vo_vobsub==NULL) - mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub, - filename_recode(vobsub_name)); - } else if (sub_auto && filename){ - /* try to autodetect vobsub from movie filename ::atmos */ - char *buf = strdup(filename), *psub; - char *pdot = strrchr(buf, '.'); - char *pslash = strrchr(buf, '/'); -#if defined(__MINGW32__) || defined(__CYGWIN__) - if (!pslash) pslash = strrchr(buf, '\\'); -#endif - if (pdot && (!pslash || pdot > pslash)) - *pdot = '\0'; - vo_vobsub=vobsub_open(buf,spudec_ifo,0,&vo_spudec); - /* try from ~/.mplayer/sub */ - if(!vo_vobsub && (psub = get_path( "sub/" ))) { - const char *bname = mp_basename(buf); - int l; - l = strlen(psub) + strlen(bname) + 1; - psub = realloc(psub,l); - strcat(psub,bname); - vo_vobsub=vobsub_open(psub,spudec_ifo,0,&vo_spudec); - free(psub); - } - free(buf); - } + load_vob_subtitle(filename, spudec_ifo, &vo_spudec, add_vob_subtitle); if(vo_vobsub){ initialized_flags|=INITIALIZED_VOBSUB; vobsub_set_from_lang(vo_vobsub, dvdsub_lang); diff -r 5310794ef052 -r 732cd2afae10 sub/sub.h --- a/sub/sub.h Fri Jan 21 15:33:12 2011 +0000 +++ b/sub/sub.h Sun Jan 23 13:04:15 2011 +0000 @@ -86,6 +86,7 @@ extern void* vo_spudec; extern void* vo_vobsub; +extern char *vobsub_name; #define OSD_PLAY 0x01 #define OSD_PAUSE 0x02 diff -r 5310794ef052 -r 732cd2afae10 sub/subreader.c --- a/sub/subreader.c Fri Jan 21 15:33:12 2011 +0000 +++ b/sub/subreader.c Sun Jan 23 13:04:15 2011 +0000 @@ -37,6 +37,7 @@ #include "subreader.h" #include "subassconvert.h" #include "sub.h" +#include "vobsub.h" #include "stream/stream.h" #include "libavutil/common.h" #include "libavutil/avstring.h" @@ -2100,6 +2101,50 @@ free(slist.subs); } +/** + * @brief Load VOB subtitle matching the subtitle filename. + * + * @param fname Path to subtitle filename. + * @param ifo Path to .ifo file. + * @spu SPU decoder instance. + * @add_f Function called when adding a vobsub. + */ +void load_vob_subtitle(const char *fname, const char * const ifo, void **spu, + open_vob_func add_f) +{ + char *name, *mp_subdir; + + // Load subtitles specified by vobsub option + if (vobsub_name) { + add_f(vobsub_name, ifo, 1, spu); + return; + } + + // Stop here if automatic detection disabled + if (!sub_auto || !fname) + return; + + // Get only the name of the subtitle file and try to open it + name = malloc(strlen(fname) + 1); + if (!name) + return; + strcpy_strip_ext(name, fname); + if (add_f(name, ifo, 0, spu)) { + free(name); + return; + } + + // If still no VOB found, try loading it from ~/.mplayer/sub + mp_subdir = get_path("sub/"); + if (mp_subdir) { + char *psub = mp_path_join(mp_subdir, mp_basename(name)); + add_f(psub, ifo, 0, spu); + free(psub); + } + free(mp_subdir); + free(name); +} + void list_sub_file(sub_data* subd){ int i,j; subtitle *subs = subd->subtitles; diff -r 5310794ef052 -r 732cd2afae10 sub/subreader.h --- a/sub/subreader.h Fri Jan 21 15:33:12 2011 +0000 +++ b/sub/subreader.h Sun Jan 23 13:04:15 2011 +0000 @@ -83,6 +83,8 @@ extern int flip_hebrew; extern int fribidi_flip_commas; +typedef int (*open_vob_func)(const char *, const char * const, int, void *); + sub_data* sub_read_file (char *filename, float pts); subtitle* subcp_recode (subtitle *sub); // enca_fd is the file enca uses to determine the codepage. @@ -95,6 +97,7 @@ const char* guess_cp(struct stream *st, const char *preferred_language, const char *fallback); #endif void load_subtitles(const char *fname, int fps, void add_f(char *, float, int)); +void load_vob_subtitle(const char *fname, const char * const spudec_ifo, void **spu, open_vob_func add_f); void list_sub_file(sub_data* subd); void dump_srt(sub_data* subd, float fps); void dump_mpsub(sub_data* subd, float fps);