[MPlayer-cvslog] r32811 - in trunk: mencoder.c mplayer.c sub/sub.h sub/subreader.c sub/subreader.h

cboesch subversion at mplayerhq.hu
Sun Jan 23 14:04:15 CET 2011


Author: cboesch
Date: Sun Jan 23 14:04:15 2011
New Revision: 32811

Log:
Replace hacky vobsub loading with a new clean one.

Modified:
   trunk/mencoder.c
   trunk/mplayer.c
   trunk/sub/sub.h
   trunk/sub/subreader.c
   trunk/sub/subreader.h

Modified: trunk/mencoder.c
==============================================================================
--- trunk/mencoder.c	Fri Jan 21 16:33:12 2011	(r32810)
+++ trunk/mencoder.c	Sun Jan 23 14:04:15 2011	(r32811)
@@ -182,6 +182,7 @@ char **sub_name=NULL;
 float sub_delay=0;
 float sub_fps=0;
 int   sub_auto = 0;
+char *vobsub_name = NULL;
 int   subcc_enabled=0;
 int   suboverlap_enabled = 1;
 

Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c	Fri Jan 21 16:33:12 2011	(r32810)
+++ trunk/mplayer.c	Sun Jan 23 14:04:15 2011	(r32811)
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <assert.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/types.h>
@@ -1079,6 +1080,22 @@ void add_subtitles(char *filename, float
 	    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 @@ while (player_idle_mode && !filename) {
 //==================== 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);

Modified: trunk/sub/sub.h
==============================================================================
--- trunk/sub/sub.h	Fri Jan 21 16:33:12 2011	(r32810)
+++ trunk/sub/sub.h	Sun Jan 23 14:04:15 2011	(r32811)
@@ -86,6 +86,7 @@ extern mp_osd_obj_t *vo_osd_list;
 
 extern void* vo_spudec;
 extern void* vo_vobsub;
+extern char *vobsub_name;
 
 #define OSD_PLAY 0x01
 #define OSD_PAUSE 0x02

Modified: trunk/sub/subreader.c
==============================================================================
--- trunk/sub/subreader.c	Fri Jan 21 16:33:12 2011	(r32810)
+++ trunk/sub/subreader.c	Sun Jan 23 14:04:15 2011	(r32811)
@@ -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 @@ void load_subtitles(const char *fname, i
     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;

Modified: trunk/sub/subreader.h
==============================================================================
--- trunk/sub/subreader.h	Fri Jan 21 16:33:12 2011	(r32810)
+++ trunk/sub/subreader.h	Sun Jan 23 14:04:15 2011	(r32811)
@@ -83,6 +83,8 @@ extern char *fribidi_charset;
 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_buffer_cp(unsigned cha
 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);


More information about the MPlayer-cvslog mailing list