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

cboesch subversion at mplayerhq.hu
Sat Dec 25 00:02:24 CET 2010


Author: cboesch
Date: Sat Dec 25 00:02:24 2010
New Revision: 32729

Log:
Factorize subtitles loading between mplayer and mencoder.

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

Modified: trunk/mencoder.c
==============================================================================
--- trunk/mencoder.c	Thu Dec 23 19:20:51 2010	(r32728)
+++ trunk/mencoder.c	Sat Dec 25 00:02:24 2010	(r32729)
@@ -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);

Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c	Thu Dec 23 19:20:51 2010	(r32728)
+++ trunk/mplayer.c	Sat Dec 25 00:02:24 2010	(r32729)
@@ -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;
 }

Modified: trunk/sub/subreader.c
==============================================================================
--- trunk/sub/subreader.c	Thu Dec 23 19:20:51 2010	(r32728)
+++ trunk/sub/subreader.c	Sat Dec 25 00:02:24 2010	(r32729)
@@ -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 vo
     }
 }
 
-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, c
     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;

Modified: trunk/sub/subreader.h
==============================================================================
--- trunk/sub/subreader.h	Thu Dec 23 19:20:51 2010	(r32728)
+++ trunk/sub/subreader.h	Sat Dec 25 00:02:24 2010	(r32729)
@@ -94,7 +94,7 @@ void subcp_close (void); /* for demux_og
 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);


More information about the MPlayer-cvslog mailing list