[MPlayer-dev-eng] [PATCH] dvd subtitle and audio selection

Joey Parrish joey at nicewarrior.org
Tue Jul 29 14:02:40 CEST 2003


Hello,

Attached below is a patch I've put into my latest cygwin MPlayer
package.  (released this morning)  It adds runtime selection of dvd
subtitle and audio tracks.  It could probably use a small bit of
cleanup.  For example, I use osd_show_vobsub_changed for dvd subtitle
message instead of a new variable.  Small things like that should
probably be cleaned up.  But otherwise, I'm very happy with it.

Please test and let me know if it's okay to commit.
If not, is it okay to commit after small cleanup?

--Joey
-------------- next part --------------
allow runtime selection of dvd subtitle language (including 'none')
allow runtime selection of dvd audio language

diff -ur main.sofar/input/input.c main.dev/input/input.c
--- main.sofar/input/input.c	2003-07-29 05:34:59.000000000 -0500
+++ main.dev/input/input.c	2003-07-29 05:37:35.000000000 -0500
@@ -77,6 +77,8 @@
   { MP_CMD_SUB_ALIGNMENT, "sub_alignment",0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
   { MP_CMD_SUB_VISIBILITY, "sub_visibility", 0, { {-1,{0}} } },
   { MP_CMD_VOBSUB_LANG, "vobsub_lang", 0, { {-1,{0}} } },
+  { MP_CMD_DVDSUB_LANG, "dvdsub_lang", 0, { {-1,{0}} } },
+  { MP_CMD_DVDAUDIO_LANG, "dvdaudio_lang", 0, { {-1,{0}} } },
   { MP_CMD_GET_PERCENT_POS, "get_percent_pos", 0, { {-1,{0}} } },
   { MP_CMD_GET_TIME_LENGTH, "get_time_length", 0, { {-1,{0}} } },
 #ifdef USE_TV
diff -ur main.sofar/input/input.h main.dev/input/input.h
--- main.sofar/input/input.h	2003-07-29 05:34:59.000000000 -0500
+++ main.dev/input/input.h	2003-07-29 05:37:35.000000000 -0500
@@ -43,6 +43,8 @@
 #define MP_CMD_SUB_ALIGNMENT 39
 #define MP_CMD_TV_LAST_CHANNEL 40
 #define MP_CMD_OSD_SHOW_TEXT 41
+#define MP_CMD_DVDSUB_LANG 42
+#define MP_CMD_DVDAUDIO_LANG 43
 
 #define MP_CMD_GUI_EVENTS       5000
 #define MP_CMD_GUI_LOADFILE     5001
diff -ur main.sofar/libmpdemux/open.c main.dev/libmpdemux/open.c
--- main.sofar/libmpdemux/open.c	2003-07-29 05:34:59.000000000 -0500
+++ main.dev/libmpdemux/open.c	2003-07-29 05:37:35.000000000 -0500
@@ -615,6 +615,25 @@
   return chapter;
 }
 
+int dvd_number_of_channels(stream_t *stream)
+{
+  dvd_priv_t *d;
+  if (!stream) return -1;
+  d = stream->priv;
+  if (!d) return -1;
+  return d->nr_of_channels;
+}
+
+int dvd_lang_from_aid(stream_t *stream, int id)
+{
+  dvd_priv_t *d;
+  if (!stream) return 0;
+  d = stream->priv;
+  if (!d) return 0;
+  if (id >= d->nr_of_channels) return 0;
+  return d->audio_streams[id].language;
+}
+
 int dvd_aid_from_lang(stream_t *stream, unsigned char* lang){
 dvd_priv_t *d=stream->priv;
 int code,i;
@@ -634,6 +653,25 @@
   return -1;
 }
 
+int dvd_number_of_subs(stream_t *stream)
+{
+  dvd_priv_t *d;
+  if (!stream) return -1;
+  d = stream->priv;
+  if (!d) return -1;
+  return d->nr_of_subtitles;
+}
+
+int dvd_lang_from_sid(stream_t *stream, int id)
+{
+  dvd_priv_t *d;
+  if (!stream) return 0;
+  d = stream->priv;
+  if (!d) return 0;
+  if (id >= d->nr_of_subtitles) return 0;
+  return d->subtitles[id].language;
+}
+
 int dvd_sid_from_lang(stream_t *stream, unsigned char* lang){
 dvd_priv_t *d=stream->priv;
 int code,i;
diff -ur main.sofar/libmpdemux/stream.h main.dev/libmpdemux/stream.h
--- main.sofar/libmpdemux/stream.h	2003-07-29 05:34:59.000000000 -0500
+++ main.dev/libmpdemux/stream.h	2003-07-29 05:37:35.000000000 -0500
@@ -310,6 +310,10 @@
   stream_language_t subtitles[32];
 } dvd_priv_t;
 
+int dvd_number_of_channels(stream_t *stream);
+int dvd_number_of_subs(stream_t *stream);
+int dvd_lang_from_aid(stream_t *stream, int id);
+int dvd_lang_from_sid(stream_t *stream, int id);
 int dvd_aid_from_lang(stream_t *stream, unsigned char* lang);
 int dvd_sid_from_lang(stream_t *stream, unsigned char* lang);
 int dvd_chapter_from_cell(dvd_priv_t *dvd,int title,int cell);
diff -ur main.sofar/mplayer.c main.dev/mplayer.c
--- main.sofar/mplayer.c	2003-07-29 05:37:25.000000000 -0500
+++ main.dev/mplayer.c	2003-07-29 05:37:35.000000000 -0500
@@ -749,6 +749,7 @@
 int osd_show_sub_visibility = 0;
 int osd_show_sub_alignment = 0;
 int osd_show_vobsub_changed = 0;
+int osd_show_dvdaudio_changed = 0;
 int osd_show_sub_changed = 0;
 int osd_show_percentage = 0;
 int osd_show_tv_channel = 25;
@@ -1336,6 +1337,7 @@
 if(stream->type==STREAMTYPE_DVD){
   current_module="dvd lang->id";
   if(audio_lang && audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang);
+  else if (audio_id==-1) audio_id=128;
   if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang);
   current_module=NULL;
 }
@@ -1529,7 +1531,7 @@
 demux_info_print(demuxer);
 
 //================== Read SUBTITLES (DVD & TEXT) ==========================
-if(d_dvdsub->id >= 0 && vo_spudec==NULL && sh_video){
+if(vo_spudec==NULL && sh_video && stream->type==STREAMTYPE_DVD){
 
 if (spudec_ifo) {
   unsigned int palette[16], width, height;
@@ -2944,6 +2946,34 @@
 	vo_osd_changed(OSDTYPE_SUBTITLE);
 	break;
     }
+    case MP_CMD_DVDAUDIO_LANG:
+    if (sh_audio && stream->type == STREAMTYPE_DVD)
+    {
+	int new_id = audio_id + 1;
+
+	if (new_id < 128 || new_id >= 128 + dvd_number_of_channels(stream))
+	    new_id = 128;
+
+        if(new_id != audio_id)
+	    osd_show_dvdaudio_changed = 40;
+	d_audio->id = audio_id = new_id;
+	resync_audio_stream(sh_audio);
+    }
+	break;
+    case MP_CMD_DVDSUB_LANG:
+    if (vo_spudec && stream->type == STREAMTYPE_DVD)
+    {
+	int new_id = dvdsub_id + 1;
+	if (dvdsub_id < 0)
+	    new_id = 0;
+	if ((unsigned int) new_id >= dvd_number_of_subs(stream))
+	    new_id = -1;
+        if(new_id != dvdsub_id)
+	    osd_show_vobsub_changed = 40;
+	d_dvdsub->id = dvdsub_id = new_id;
+	spudec_reset(vo_spudec);
+    }
+	break;
     case MP_CMD_VOBSUB_LANG:
     if (vo_vobsub)
     {
@@ -3373,11 +3403,36 @@
 	  snprintf(osd_text_tmp, 63, "Subtitles: %sabled", sub_visibility?"en":"dis");
 	  osd_show_sub_visibility--;
       } else
+      if (osd_show_dvdaudio_changed) {
+	if (sh_audio) {
+	    char lang[3] = "??";
+	    int code = 0;
+	    code = dvd_lang_from_aid(stream, audio_id - 128);
+	    if (code) {
+	       lang[0] = code >> 8;
+	       lang[1] = code;
+	    }
+	    snprintf(osd_text_tmp, 63, "Audio: (%d) %s", audio_id - 128, lang);
+	}
+	osd_show_dvdaudio_changed--;
+      } else
       if (osd_show_vobsub_changed) {
-	  const char *language = "none";
-	  if (vo_vobsub && vobsub_id >= 0)
+	  if (vo_vobsub && vobsub_id >= 0) {
+	      const char *language = "none";
 	      language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
-	  snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
+	      snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", vobsub_id, language ? language : "unknown");
+	  }
+	  if (vo_spudec) {
+	      char lang[5] = "none";
+	      int code = 0;
+	      if (dvdsub_id >= 0) code = dvd_lang_from_sid(stream, dvdsub_id);
+	      if (code) {
+	         lang[0] = code >> 8;
+	         lang[1] = code;
+	         lang[2] = 0;
+	      }
+	      snprintf(osd_text_tmp, 63, "Subtitles: (%d) %s", dvdsub_id, lang);
+	  }
 	  osd_show_vobsub_changed--;
       } else
 #ifdef USE_SUB


More information about the MPlayer-dev-eng mailing list