[MPlayer-dev-eng] [PATCH] SImplified and generalized embedded subtitle switching

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat Nov 18 23:42:51 CET 2006


Hello,
please consider this patch. It makes subtitle switching work for
non-vobsub mov-subtitles, too. For vobsub switching the initialization
code should be separated from mplayer.c main into an extra function.
Testing very welcome.
I intend to apply soon if no objections.

Greetings,
Reimar Döffinger
-------------- next part --------------
diff --git a/libmpdemux/demux_mkv.c b/libmpdemux/demux_mkv.c
index 81d00f8..df60be5 100644
--- a/libmpdemux/demux_mkv.c
+++ b/libmpdemux/demux_mkv.c
@@ -3864,26 +3864,6 @@ demux_mkv_control (demuxer_t *demuxer, i
     }
 }
 
-/** \brief Return the number of subtitle tracks in the file.
-
-  \param demuxer The demuxer for which the number of subtitle tracks
-  should be returned.
-*/
-int
-demux_mkv_num_subs (demuxer_t *demuxer)
-{
-  mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
-  int i, num;
-
-  num = 0;
-  for (i = 0; i < mkv_d->num_tracks; i++)
-    if ((mkv_d->tracks[i]->type == MATROSKA_TRACK_SUBTITLE) &&
-        (mkv_d->tracks[i]->subtitle_type != MATROSKA_SUBTYPE_UNKNOWN))
-      num++;
-
-  return num;
-}
-
 /** \brief Change the current subtitle track and return its ID.
 
   Changes the current subtitle track. If the new subtitle track is a
diff --git a/libmpdemux/demux_ogg.c b/libmpdemux/demux_ogg.c
index c9d511a..9419319 100644
--- a/libmpdemux/demux_ogg.c
+++ b/libmpdemux/demux_ogg.c
@@ -718,16 +718,6 @@ extern void print_video_header(BITMAPINF
 /* defined in demux_mov.c */
 extern unsigned int store_ughvlc(unsigned char *s, unsigned int v);
 
-/** \brief Return the number of subtitle tracks in the file.
-
-  \param demuxer The demuxer for which the number of subtitle tracks
-  should be returned.
-*/
-int demux_ogg_num_subs(demuxer_t *demuxer) {
-  ogg_demuxer_t *ogg_d = (ogg_demuxer_t *)demuxer->priv;
-  return ogg_d->n_text;
-}
-
 /** \brief Change the current subtitle stream and return its ID.
 
   \param demuxer The demuxer whose subtitle stream will be changed.
diff --git a/libmpdemux/matroska.h b/libmpdemux/matroska.h
index c0c342a..3656076 100644
--- a/libmpdemux/matroska.h
+++ b/libmpdemux/matroska.h
@@ -61,7 +61,6 @@
 #define MKV_S_SSA        "S_SSA" // Deprecated
 #define MKV_S_ASS        "S_ASS" // Deprecated
 
-int demux_mkv_num_subs(demuxer_t *demuxer);
 int demux_mkv_change_subs(demuxer_t *demuxer, int new_num);
 void demux_mkv_get_audio_lang(demuxer_t *demuxer, int track_num, char *lang,
                             int maxlen);
diff --git a/mplayer.c b/mplayer.c
index 6386190..6a805fb 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -2224,6 +2224,10 @@ static int mp_property_sub(m_option_t* p
             return M_PROPERTY_OK;
         }
 #endif
+        if (dvdsub_id >= 0) {
+            snprintf(*(char**)arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
+            return M_PROPERTY_OK;
+        }
         snprintf(*(char**)arg, 63, MSGTR_Disabled);
         return M_PROPERTY_OK;
 
@@ -2294,6 +2298,16 @@ static int mp_property_sub(m_option_t* p
                 spudec_reset(vo_spudec);
             }
 #endif
+            if (stream->type != STREAMTYPE_DVD) {
+              int i = 0;
+              for (d_dvdsub->id = 0; d_dvdsub->id < MAX_S_STREAMS; d_dvdsub->id++) {
+                if (demuxer->s_streams[d_dvdsub->id]) {
+                  if (i == dvdsub_id) break;
+                  i++;
+                }
+              }
+              d_dvdsub->sh = demuxer->s_streams[d_dvdsub->id];
+            }
 #ifdef HAVE_OGGVORBIS
             if (demuxer->type == DEMUXER_TYPE_OGG)
                 d_dvdsub->id = demux_ogg_sub_id(demuxer, dvdsub_id);
@@ -4016,18 +4030,14 @@ if(!demuxer)
 }
 inited_flags|=INITED_DEMUXER;
 
-if (demuxer->type==DEMUXER_TYPE_MATROSKA) {
+if (stream->type != STREAMTYPE_DVD) {
+  int i;
   // setup global sub numbering
   global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
-  global_sub_size += demux_mkv_num_subs(demuxer);
+  for (i = 0; i < MAX_S_STREAMS; i++)
+    if (demuxer->s_streams[i])
+      global_sub_size++;
 }
-#ifdef HAVE_OGGVORBIS
-if (demuxer->type==DEMUXER_TYPE_OGG) {
-  // setup global sub numbering
-  global_sub_indices[SUB_SOURCE_DEMUX] = global_sub_size; // the global # of the first demux-specific sub.
-  global_sub_size += demux_ogg_num_subs(demuxer);
-}
-#endif
 
 current_module="demux_open2";
 


More information about the MPlayer-dev-eng mailing list