1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-18 12:55:16 +00:00

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

track language.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@26116 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
eugeni 2008-02-29 17:25:39 +00:00
parent 18fea2aa49
commit a2fad60c7f
6 changed files with 15 additions and 66 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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",

View File

@ -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)

View File

@ -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);

View File

@ -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 */