changeset 33577:c111d9e9cfb0

Move init_vo_spudec to mp_common.c and reuse it in mencoder. Fixes bug #1932.
author reimar
date Sun, 19 Jun 2011 16:48:33 +0000
parents c97ec47d1bbb
children 8860c936e5ce
files command.c mencoder.c mp_core.h mpcommon.c mpcommon.h mplayer.c
diffstat 6 files changed, 61 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/command.c	Sun Jun 19 16:28:18 2011 +0000
+++ b/command.c	Sun Jun 19 16:48:33 2011 +0000
@@ -1624,7 +1624,7 @@
             if (d_sub->sh && d_sub->id >= 0) {
                 sh_sub_t *sh = d_sub->sh;
                 if (sh->type == 'v')
-                    init_vo_spudec();
+                    init_vo_spudec(mpctx->stream, mpctx->sh_video, sh);
 #ifdef CONFIG_ASS
                 else if (ass_enabled)
                     ass_track = sh->ass_track;
--- a/mencoder.c	Sun Jun 19 16:28:18 2011 +0000
+++ b/mencoder.c	Sun Jun 19 16:48:33 2011 +0000
@@ -103,7 +103,6 @@
 int vo_doublebuffering=0;
 int vo_directrendering=0;
 int vo_config_count=1;
-int forced_subs_only=0;
 
 //--------------------------
 
@@ -120,7 +119,6 @@
 int vobsub_id=-1;
 char* audio_lang=NULL;
 char* dvdsub_lang=NULL;
-static char* spudec_ifo=NULL;
 
 static char** audio_codec_list=NULL;  // override audio codec
 static char** video_codec_list=NULL;  // override video codec
@@ -809,19 +807,7 @@
 #endif
 }
 else {
-if (spudec_ifo) {
-  unsigned int palette[16], width, height;
-  if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
-    vo_spudec=spudec_new_scaled(palette, sh_video->disp_w, sh_video->disp_h, NULL, 0);
-}
-#ifdef CONFIG_DVDREAD
-if (vo_spudec==NULL) {
-vo_spudec=spudec_new_scaled(stream->type==STREAMTYPE_DVD?((dvd_priv_t *)(stream->priv))->cur_pgc->palette:NULL,
-                           sh_video->disp_w, sh_video->disp_h, NULL, 0);
-}
-#endif
-if (vo_spudec)
-  spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
+init_vo_spudec(stream, sh_video, d_dvdsub ? d_dvdsub->sh : NULL);
 }
 
 ostream = open_output_stream(out_filename, 0);
--- a/mp_core.h	Sun Jun 19 16:28:18 2011 +0000
+++ b/mp_core.h	Sun Jun 19 16:48:33 2011 +0000
@@ -148,12 +148,10 @@
 // These appear in options list
 extern float playback_speed;
 extern int fixed_vo;
-extern int forced_subs_only;
 
 
 void uninit_player(unsigned int mask);
 void reinit_audio_chain(void);
-void init_vo_spudec(void);
 double playing_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio,
 			 const ao_functions_t *audio_out);
 void exit_player(enum exit_reason how);
--- a/mpcommon.c	Sun Jun 19 16:28:18 2011 +0000
+++ b/mpcommon.c	Sun Jun 19 16:48:33 2011 +0000
@@ -21,6 +21,8 @@
 #endif
 #include <stdlib.h>
 #include "stream/stream.h"
+#include "stream/stream_dvd.h"
+#include "stream/stream_dvdnav.h"
 #include "libmpdemux/demuxer.h"
 #include "libmpdemux/stheader.h"
 #include "codec-cfg.h"
@@ -52,6 +54,8 @@
 
 sub_data* subdata = NULL;
 subtitle* vo_sub_last = NULL;
+char *spudec_ifo;
+int forced_subs_only;
 
 const char *mencoder_version = "MEncoder " VERSION;
 const char *mplayer_version  = "MPlayer "  VERSION;
@@ -93,6 +97,55 @@
 #endif /* ARCH_X86 */
 }
 
+void init_vo_spudec(struct stream *stream, struct sh_video *sh_video, struct sh_sub *sh_sub)
+{
+    unsigned width, height;
+    spudec_free(vo_spudec);
+    vo_spudec = NULL;
+
+    // we currently can't work without video stream
+    if (!sh_video)
+        return;
+
+    if (spudec_ifo) {
+        unsigned int palette[16];
+        current_module = "spudec_init_vobsub";
+        if (vobsub_parse_ifo(NULL, spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
+            vo_spudec = spudec_new_scaled(palette, width, height, NULL, 0);
+    }
+
+    width  = sh_video->disp_w;
+    height = sh_video->disp_h;
+
+#ifdef CONFIG_DVDREAD
+    if (vo_spudec == NULL && stream->type == STREAMTYPE_DVD) {
+        current_module = "spudec_init_dvdread";
+        vo_spudec      = spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette,
+                                           width, height,
+                                           NULL, 0);
+    }
+#endif
+
+#ifdef CONFIG_DVDNAV
+    if (vo_spudec == NULL && stream->type == STREAMTYPE_DVDNAV) {
+        unsigned int *palette = mp_dvdnav_get_spu_clut(stream);
+        current_module = "spudec_init_dvdnav";
+        vo_spudec      = spudec_new_scaled(palette, width, height, NULL, 0);
+    }
+#endif
+
+    if (vo_spudec == NULL) {
+        current_module = "spudec_init_normal";
+        vo_spudec      = spudec_new_scaled(NULL, width, height,
+                                           sh_sub ? sh_sub->extradata : NULL,
+                                           sh_sub ? sh_sub->extradata_len : 0);
+        spudec_set_font_factor(vo_spudec, font_factor);
+    }
+
+    if (vo_spudec)
+        spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
+}
+
 static int is_text_sub(int type)
 {
     return type == 't' || type == 'm' || type == 'a';
--- a/mpcommon.h	Sun Jun 19 16:28:18 2011 +0000
+++ b/mpcommon.h	Sun Jun 19 16:48:33 2011 +0000
@@ -27,12 +27,16 @@
 
 #define ROUND(x) ((int)((x) < 0 ? (x) - 0.5 : (x) + 0.5))
 
+struct stream;
 struct sh_audio;
 struct sh_video;
+struct sh_sub;
 
 extern double sub_last_pts;
 extern ASS_Track *ass_track;
 extern subtitle *vo_sub_last;
+extern char *spudec_ifo;
+extern int forced_subs_only;
 
 extern int sub_auto;
 extern float sub_delay;
@@ -67,6 +71,7 @@
 extern const m_option_t noconfig_opts[];
 
 void print_version(const char* name);
+void init_vo_spudec(struct stream *stream, struct sh_video *sh_video, struct sh_sub *sh_sub);
 void update_subtitles(struct sh_video *sh_video, double refpts, demux_stream_t *d_dvdsub, int reset);
 void update_teletext(struct sh_video *sh_video, demuxer_t *demuxer, int reset);
 int select_audio(demuxer_t* demuxer, int audio_id, char* audio_lang);
--- a/mplayer.c	Sun Jun 19 16:28:18 2011 +0000
+++ b/mplayer.c	Sun Jun 19 16:48:33 2011 +0000
@@ -252,9 +252,7 @@
 int vobsub_id = -1;
 char *audio_lang;
 char *dvdsub_lang;
-static char *spudec_ifo;
 char *filename;
-int forced_subs_only;
 int file_filter = 1;
 
 // cache2:
@@ -1153,55 +1151,6 @@
     }
 }
 
-void init_vo_spudec(void)
-{
-    unsigned width, height;
-    spudec_free(vo_spudec);
-    vo_spudec = NULL;
-
-    // we currently can't work without video stream
-    if (!mpctx->sh_video)
-        return;
-
-    if (spudec_ifo) {
-        unsigned int palette[16];
-        current_module = "spudec_init_vobsub";
-        if (vobsub_parse_ifo(NULL, spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
-            vo_spudec = spudec_new_scaled(palette, width, height, NULL, 0);
-    }
-
-    width  = mpctx->sh_video->disp_w;
-    height = mpctx->sh_video->disp_h;
-
-#ifdef CONFIG_DVDREAD
-    if (vo_spudec == NULL && mpctx->stream->type == STREAMTYPE_DVD) {
-        current_module = "spudec_init_dvdread";
-        vo_spudec      = spudec_new_scaled(((dvd_priv_t *)(mpctx->stream->priv))->cur_pgc->palette,
-                                           width, height,
-                                           NULL, 0);
-    }
-#endif
-
-#ifdef CONFIG_DVDNAV
-    if (vo_spudec == NULL && mpctx->stream->type == STREAMTYPE_DVDNAV) {
-        unsigned int *palette = mp_dvdnav_get_spu_clut(mpctx->stream);
-        current_module = "spudec_init_dvdnav";
-        vo_spudec      = spudec_new_scaled(palette, width, height, NULL, 0);
-    }
-#endif
-
-    if (vo_spudec == NULL) {
-        sh_sub_t *sh = mpctx->d_sub->sh;
-        current_module = "spudec_init_normal";
-        vo_spudec      = spudec_new_scaled(NULL, width, height, sh->extradata, sh->extradata_len);
-        spudec_set_font_factor(vo_spudec, font_factor);
-    }
-
-    if (vo_spudec != NULL) {
-        mp_property_do("sub_forced_only", M_PROPERTY_SET, &forced_subs_only, mpctx);
-    }
-}
-
 /**
  * @brief Append a formatted string.
  * @param buf buffer to print into
@@ -3604,7 +3553,7 @@
 //================== Read SUBTITLES (DVD & TEXT) ==========================
     if (vo_spudec == NULL &&
         (mpctx->stream->type == STREAMTYPE_DVD || mpctx->stream->type == STREAMTYPE_DVDNAV)) {
-        init_vo_spudec();
+        init_vo_spudec(mpctx->stream, mpctx->sh_video, mpctx->d_sub ? mpctx->d_sub->sh : NULL);
     }
 
     if (1 || mpctx->sh_video) {