[PATCH 2/2] Replace hacky vobsub loading with a new clean one.
Clément Bœsch
ubitux at gmail.com
Mon Jan 10 23:59:37 CET 2011
---
mencoder.c | 1 +
mplayer.c | 27 +--------------------------
sub/sub.h | 1 +
sub/subreader.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
sub/subreader.h | 1 +
5 files changed, 49 insertions(+), 26 deletions(-)
diff --git a/mencoder.c b/mencoder.c
index 6efe907..58c3848 100644
--- a/mencoder.c
+++ b/mencoder.c
@@ -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;
diff --git a/mplayer.c b/mplayer.c
index 4676c47..e689066 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -3134,34 +3134,9 @@ 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)
+ if (load_vob_subtitle(filename, spudec_ifo, &vo_spudec) < 0)
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);
- }
if(vo_vobsub){
initialized_flags|=INITIALIZED_VOBSUB;
vobsub_set_from_lang(vo_vobsub, dvdsub_lang);
diff --git a/sub/sub.h b/sub/sub.h
index 744f8a5..c6021b0 100644
--- a/sub/sub.h
+++ b/sub/sub.h
@@ -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
diff --git a/sub/subreader.c b/sub/subreader.c
index 5542002..96e490c 100644
--- a/sub/subreader.c
+++ b/sub/subreader.c
@@ -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, int fps, void add_f(char *, float, int))
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
+ */
+int load_vob_subtitle(const char *fname, const char * const ifo, void **spu)
+{
+ char *name, *mp_subdir;
+
+ // Load subtitles specified by vobsub option
+ if (vobsub_name) {
+ vo_vobsub = vobsub_open(vobsub_name, ifo, 1, spu);
+ return vo_vobsub ? 0 : -1;
+ }
+
+ // Stop here if automatic detection disabled
+ if (!sub_auto || !fname)
+ return 0;
+
+ // Get only the name of the subtitle file and try to open it
+ name = malloc(strlen(fname) + 1);
+ if (!name)
+ return -1;
+ strcpy_strip_ext(name, fname);
+ vo_vobsub = vobsub_open(name, ifo, 0, spu);
+ if (vo_vobsub) {
+ free(name);
+ return 0;
+ }
+
+ // 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));
+ vo_vobsub = vobsub_open(psub, ifo, 0, spu);
+ free(psub);
+ }
+ free(mp_subdir);
+ free(name);
+ return 0;
+}
+
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 dd08a22..d6ffc54 100644
--- a/sub/subreader.h
+++ b/sub/subreader.h
@@ -95,6 +95,7 @@ const char* guess_buffer_cp(unsigned char* buffer, int buflen, const char *prefe
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));
+int load_vob_subtitle(const char *fname, const char * const spudec_ifo, void **spu);
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.5
--LQksG6bCIzRHxTLp--
More information about the MPlayer-dev-eng
mailing list