diff --git a/command.c b/command.c index 0157f971b3..ba23b7e005 100644 --- a/command.c +++ b/command.c @@ -1296,8 +1296,6 @@ static int mp_property_sub_pos(m_option_t * prop, int action, void *arg, } } -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 * prop, int action, void *arg, } #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); diff --git a/libmpdemux/demux_lavf.c b/libmpdemux/demux_lavf.c index c7eeae7fbb..5ab20a06e8 100644 --- a/libmpdemux/demux_lavf.c +++ b/libmpdemux/demux_lavf.c @@ -431,6 +431,8 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) { 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; diff --git a/libmpdemux/demux_mkv.c b/libmpdemux/demux_mkv.c index c0ac842eca..2a124ba902 100644 --- a/libmpdemux/demux_mkv.c +++ b/libmpdemux/demux_mkv.c @@ -2241,6 +2241,8 @@ demux_mkv_open_sub (demuxer_t *demuxer, mkv_track_t *track, int sid) 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, int cmd, void *arg) } } -/** \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", diff --git a/libmpdemux/demux_ogg.c b/libmpdemux/demux_ogg.c index 44816cf3bc..4b906c3da9 100644 --- a/libmpdemux/demux_ogg.c +++ b/libmpdemux/demux_ogg.c @@ -383,9 +383,13 @@ static void demux_ogg_check_comments(demuxer_t *d, ogg_stream_t *os, int id, vor // 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(demuxer_t *demuxer, int id) { 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) diff --git a/libmpdemux/demuxer.h b/libmpdemux/demuxer.h index 5a314e474a..e9cbc3984e 100644 --- a/libmpdemux/demuxer.h +++ b/libmpdemux/demuxer.h @@ -385,7 +385,6 @@ int demux_control(demuxer_t *demuxer, int cmd, void *arg); /* 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); diff --git a/libmpdemux/matroska.h b/libmpdemux/matroska.h index bbdc9d8424..ef610aab49 100644 --- a/libmpdemux/matroska.h +++ b/libmpdemux/matroska.h @@ -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 */