Mercurial > mplayer.hg
changeset 26084:ec5749eb6f5f
Fill sh_sub_t.lang in lavf, mkv and ogg demuxers. Use it for printing subtitle
track language.
author | eugeni |
---|---|
date | Fri, 29 Feb 2008 17:25:39 +0000 |
parents | 19fa7a56ed04 |
children | 681f6ae38b68 |
files | command.c libmpdemux/demux_lavf.c libmpdemux/demux_mkv.c libmpdemux/demux_ogg.c libmpdemux/demuxer.h libmpdemux/matroska.h |
diffstat | 6 files changed, 15 insertions(+), 66 deletions(-) [+] |
line wrap: on
line diff
--- a/command.c Fri Feb 29 17:25:37 2008 +0000 +++ b/command.c Fri Feb 29 17:25:39 2008 +0000 @@ -1296,8 +1296,6 @@ } } -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 @@ } #endif -#ifdef USE_LIBAVFORMAT - if (mpctx->demuxer->type == DEMUXER_TYPE_LAVF && dvdsub_id >= 0) { - char *lang = demux_lavf_sub_lang(mpctx->demuxer, dvdsub_id); + 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 (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; - 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);
--- a/libmpdemux/demux_lavf.c Fri Feb 29 17:25:37 2008 +0000 +++ b/libmpdemux/demux_lavf.c Fri Feb 29 17:25:39 2008 +0000 @@ -431,6 +431,8 @@ 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 @@ } } -/** \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;
--- a/libmpdemux/demux_mkv.c Fri Feb 29 17:25:37 2008 +0000 +++ b/libmpdemux/demux_mkv.c Fri Feb 29 17:25:39 2008 +0000 @@ -2241,6 +2241,8 @@ 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 @@ } } -/** \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",
--- a/libmpdemux/demux_ogg.c Fri Feb 29 17:25:37 2008 +0000 +++ b/libmpdemux/demux_ogg.c Fri Feb 29 17:25:39 2008 +0000 @@ -383,9 +383,13 @@ // 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 @@ 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)
--- a/libmpdemux/demuxer.h Fri Feb 29 17:25:37 2008 +0000 +++ b/libmpdemux/demuxer.h Fri Feb 29 17:25:39 2008 +0000 @@ -385,7 +385,6 @@ /* 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);
--- a/libmpdemux/matroska.h Fri Feb 29 17:25:37 2008 +0000 +++ b/libmpdemux/matroska.h Fri Feb 29 17:25:39 2008 +0000 @@ -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 */