[MPlayer-cvslog] r26116 - in trunk: command.c libmpdemux/demux_lavf.c libmpdemux/demux_mkv.c libmpdemux/demux_ogg.c libmpdemux/demuxer.h libmpdemux/matroska.h

eugeni subversion at mplayerhq.hu
Fri Feb 29 18:25:39 CET 2008


Author: eugeni
Date: Fri Feb 29 18:25:39 2008
New Revision: 26116

Log:
Fill sh_sub_t.lang in lavf, mkv and ogg demuxers. Use it for printing subtitle
track language.


Modified:
   trunk/command.c
   trunk/libmpdemux/demux_lavf.c
   trunk/libmpdemux/demux_mkv.c
   trunk/libmpdemux/demux_ogg.c
   trunk/libmpdemux/demuxer.h
   trunk/libmpdemux/matroska.h

Modified: trunk/command.c
==============================================================================
--- trunk/command.c	(original)
+++ trunk/command.c	Fri Feb 29 18:25:39 2008
@@ -1296,8 +1296,6 @@ static int mp_property_sub_pos(m_option_
     }
 }
 
-char *demux_lavf_sub_lang(demuxer_t *demuxer, int track_num);
-
 /// Selected subtitles (RW)
 static int mp_property_sub(m_option_t * prop, int action, void *arg,
 			   MPContext * mpctx)
@@ -1352,28 +1350,16 @@ static int mp_property_sub(m_option_t * 
 	}
 #endif
 
-#ifdef USE_LIBAVFORMAT
-	if (mpctx->demuxer->type == DEMUXER_TYPE_LAVF && dvdsub_id >= 0) {
-	    char *lang = demux_lavf_sub_lang(mpctx->demuxer, dvdsub_id);
-	    snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
-	    return M_PROPERTY_OK;
-	}
-#endif
-	if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
-	    char lang[40] = MSGTR_Unknown;
-	    demux_mkv_get_sub_lang(mpctx->demuxer, dvdsub_id, lang, 9);
-	    snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
-	    return M_PROPERTY_OK;
-	}
-#ifdef HAVE_OGGVORBIS
-	if (mpctx->demuxer->type == DEMUXER_TYPE_OGG && d_sub && dvdsub_id >= 0) {
-	    const char *lang = demux_ogg_sub_lang(mpctx->demuxer, dvdsub_id);
-	    if (!lang)
-		lang = MSGTR_Unknown;
+	if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
+             || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
+             || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
+             && d_sub && d_sub->sh && dvdsub_id >= 0) {
+            const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
+            if (!lang) lang = MSGTR_Unknown;
 	    snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
 	    return M_PROPERTY_OK;
 	}
-#endif
+
 	if (vo_vobsub && vobsub_id >= 0) {
 	    const char *language = MSGTR_Unknown;
 	    language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);

Modified: trunk/libmpdemux/demux_lavf.c
==============================================================================
--- trunk/libmpdemux/demux_lavf.c	(original)
+++ trunk/libmpdemux/demux_lavf.c	Fri Feb 29 18:25:39 2008
@@ -431,6 +431,8 @@ static void handle_stream(demuxer_t *dem
                 memcpy(sh_sub->extradata, codec->extradata, codec->extradata_size);
                 sh_sub->extradata_len = codec->extradata_size;
             }
+            if (st->language)
+              sh_sub->lang = strdup(st->language);
             if (demuxer->sub->id == -1
                 || (demuxer->sub->id == -2 && (dvdsub_lang && st->language[0] && !strncmp(dvdsub_lang, st->language, 3)))
                 || demuxer->sub->id == priv->sub_streams) {
@@ -791,19 +793,6 @@ redo:
     }
 }
 
-/** \brief Get the language code for a subtitle track.
-
-  Retrieves the language code for a subtitle track.
-
-  \param demuxer The demuxer to work on
-  \param track_num The subtitle track number to get the language from
-*/
-char *demux_lavf_sub_lang(demuxer_t *demuxer, int track_num)
-{
-    lavf_priv_t *priv = demuxer->priv;
-    return priv->avfc->streams[priv->sstreams[track_num]]->language;
-}
-
 static void demux_close_lavf(demuxer_t *demuxer)
 {
     lavf_priv_t* priv = demuxer->priv;

Modified: trunk/libmpdemux/demux_mkv.c
==============================================================================
--- trunk/libmpdemux/demux_mkv.c	(original)
+++ trunk/libmpdemux/demux_mkv.c	Fri Feb 29 18:25:39 2008
@@ -2241,6 +2241,8 @@ demux_mkv_open_sub (demuxer_t *demuxer, 
       memcpy (sh->extradata, track->private_data,
               track->private_size);
       sh->extradata_len = track->private_size;
+      if (track->language && (strcmp(track->language, "und") != 0))
+        sh->lang = strdup(track->language);
     }
   else
     {
@@ -3484,26 +3486,6 @@ demux_mkv_control (demuxer_t *demuxer, i
     }
 }
 
-/** \brief Get the language code for a subtitle track.
-
-  Retrieves the language code for a subtitle track if it is known.
-  If the language code is "und" then do not copy it ("und" = "undefined").
-
-  \param demuxer The demuxer to work on
-  \param track_num The subtitle track number to get the language from
-  \param lang Store the language here
-  \param maxlen The maximum number of characters to copy into lang
-*/
-void
-demux_mkv_get_sub_lang(demuxer_t *demuxer, int track_num, char *lang,
-                       int maxlen)
-{
-  mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
-  mkv_track_t *track = demux_mkv_find_track_by_num (mkv_d, track_num, MATROSKA_TRACK_SUBTITLE);
-  if (track && track->language && strcmp(track->language, "und"))
-    av_strlcpy(lang, track->language, maxlen);
-}
-
 const demuxer_desc_t demuxer_desc_matroska = {
   "Matroska demuxer",
   "mkv",

Modified: trunk/libmpdemux/demux_ogg.c
==============================================================================
--- trunk/libmpdemux/demux_ogg.c	(original)
+++ trunk/libmpdemux/demux_ogg.c	Fri Feb 29 18:25:39 2008
@@ -383,9 +383,13 @@ static void demux_ogg_check_comments(dem
       // copy this language name into the array
       index = demux_ogg_sub_reverse_id(d, id);
       if (index >= 0) {
+	sh_sub_t* sh;
 	// in case of malicious files with more than one lang per track:
 	if (ogg_d->text_langs[index]) free(ogg_d->text_langs[index]);
 	ogg_d->text_langs[index] = strdup(val);
+	sh = d->s_streams[index];
+	if (sh && sh->lang) free(sh->lang);
+	if (sh) sh->lang = strdup(val);
       }
       // check for -slang if subs are uninitialized yet
       if (os->text && d->sub->id < 0 && demux_ogg_check_lang(val, dvdsub_lang))
@@ -645,15 +649,6 @@ static int demux_ogg_sub_reverse_id(demu
   return -1;
 }
 
-/** \brief Lookup the subtitle language by the subtitle number.  Returns NULL on out-of-bounds input.
- *  \param demuxer The demuxer about whose subtitles we are inquiring.
- *  \param index The subtitle number.
- */
-const char *demux_ogg_sub_lang(demuxer_t *demuxer, int index) {
-  ogg_demuxer_t *ogg_d = demuxer->priv;
-  return (index < 0) ? NULL : (index >= ogg_d->n_text) ? NULL : ogg_d->text_langs[index];
-}
-
 static void demux_close_ogg(demuxer_t* demuxer);
 
 static void fixup_vorbis_wf(sh_audio_t *sh, ogg_demuxer_t *od)

Modified: trunk/libmpdemux/demuxer.h
==============================================================================
--- trunk/libmpdemux/demuxer.h	(original)
+++ trunk/libmpdemux/demuxer.h	Fri Feb 29 18:25:39 2008
@@ -385,7 +385,6 @@ int demux_control(demuxer_t *demuxer, in
 /* Found in demux_ogg.c */
 int demux_ogg_num_subs(demuxer_t *demuxer);
 int demux_ogg_sub_id(demuxer_t *demuxer, int index);
-const char *demux_ogg_sub_lang(demuxer_t *demuxer, int index);
 #endif
 
 extern int demuxer_get_current_time(demuxer_t *demuxer);

Modified: trunk/libmpdemux/matroska.h
==============================================================================
--- trunk/libmpdemux/matroska.h	(original)
+++ trunk/libmpdemux/matroska.h	Fri Feb 29 18:25:39 2008
@@ -62,7 +62,5 @@
 #define MKV_S_ASS        "S_ASS" // Deprecated
 
 int demux_mkv_change_subs(demuxer_t *demuxer, int new_num);
-void demux_mkv_get_sub_lang(demuxer_t *demuxer, int track_num, char *lang,
-                            int maxlen);
 
 #endif /* MPLAYER_MATROSKA_H */



More information about the MPlayer-cvslog mailing list