[MPlayer-dev-eng] [PATCH] simplify/correct subtitle selection

Reimar Doeffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sun Jun 17 10:56:02 CEST 2007


Hello,
I have not properly tested attached patch, so feel free to flame me ;-)
But I think something like this makes sense because
1) current code does not work right with demuxers that detect streams
only during playback (e.g. vobs), see also
no_subs_displayed_past_sid0.VOB in incoming.
2) The change would make sure behaviour is more consistent with the ID_
messages
3) The resulting code is simpler.

There is at least one bug remaining somewhere: with the
no_subs_displayed_past_sid0.VOB sample using 'j' to switch channels
always results in no output. I do not know for sure where the problem
lies yet, though the demuxer seems to demux the correct stream...

Greetings,
Reimar Doeffinger
-------------- next part --------------
Index: command.c
===================================================================
--- command.c	(revision 23569)
+++ command.c	(working copy)
@@ -1242,25 +1242,19 @@
     } else if (source == SUB_SOURCE_DEMUX) {
 	dvdsub_id =
 	    mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
-	if (d_sub) {
-	    if (mpctx->stream->type != STREAMTYPE_DVD
-		&& mpctx->stream->type != STREAMTYPE_DVDNAV) {
-		int i = 0;
-		d_sub->sh = NULL;
-		for (d_sub->id = 0; d_sub->id < MAX_S_STREAMS; d_sub->id++) {
-		    if (mpctx->demuxer->s_streams[d_sub->id]) {
-			if (i == dvdsub_id) {
-			    d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
-			    break;
-			}
-			i++;
-		    }
+	if (d_sub && dvdsub_id < MAX_S_STREAMS) {
+	    int i = 0;
+	    // default: assume 1:1 mapping of sid and stream id
+	    d_sub->id = dvdsub_id;
+	    d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
+	    for (i = 0; i < MAX_S_STREAMS; i++) {
+		sh_sub_t *sh = mpctx->demuxer->s_streams[i];
+		if (sh && sh->sid == dvdsub_id) {
+		    d_sub->id = i;
+		    d_sub->sh = sh;
+		    break;
 		}
 	    }
-	    else if (vo_spudec)
-		d_sub->id = dvdsub_id;
-	    if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA)
-		d_sub->id = demux_mkv_change_subs(mpctx->demuxer, dvdsub_id);
 	    if (d_sub->sh && d_sub->id >= 0) {
 		sh_sub_t *sh = d_sub->sh;
 		if (sh->type == 'v')
Index: libmpdemux/demux_mkv.c
===================================================================
--- libmpdemux/demux_mkv.c	(revision 23566)
+++ libmpdemux/demux_mkv.c	(working copy)
@@ -3596,48 +3596,6 @@
     }
 }
 
-/** \brief Change the current subtitle track and return its ID.
-
-  Changes the current subtitle track. If the new subtitle track is a
-  VobSub track then the SPU decoder will be re-initialized.
-
-  \param demuxer The demuxer whose subtitle track will be changed.
-  \param new_num The number of the new subtitle track. The number must be
-  between 0 and demux_mkv_num_subs - 1.
-
-  \returns The Matroska track number of the newly selected track.
-*/
-int
-demux_mkv_change_subs (demuxer_t *demuxer, int new_num)
-{
-  mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
-  mkv_track_t *track;
-  int i, num;
-
-  num = 0;
-  track = NULL;
-  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++;
-      if (num == (new_num + 1))
-        {
-          track = mkv_d->tracks[i];
-          break;
-        }
-    }
-  if (track == NULL)
-    return -1;
-
-  if (demuxer->sub->sh == NULL)
-    demuxer->sub->sh = malloc(sizeof(sh_sub_t));
-  if (demuxer->sub->sh != NULL)
-    memcpy(demuxer->sub->sh, &track->sh_sub, sizeof(sh_sub_t));
-
-  return track->tnum;
-}
-
 /** \brief Get the language code for a subtitle track.
 
   Retrieves the language code for a subtitle track if it is known.


More information about the MPlayer-dev-eng mailing list