OSD: when switching sub/audio tracks show title of new track

If the played file has per-track titles for audio and subtitles show
those on the OSD when switching tracks. This changes the OSD message
from 'Audio: (2) eng' to 'Audio: (2) eng ("Director's commentary")'.
This commit is contained in:
Uoti Urpala 2011-07-03 20:41:46 +03:00
parent c5364305be
commit 8ff5b2b889
4 changed files with 33 additions and 12 deletions

View File

@ -937,7 +937,8 @@ static int mp_property_audio(m_option_t *prop, int action, void *arg,
int current_id, tmp;
if (!mpctx->demuxer || !mpctx->d_audio)
return M_PROPERTY_UNAVAILABLE;
current_id = mpctx->sh_audio ? mpctx->sh_audio->aid : -2;
struct sh_audio *sh = mpctx->sh_audio;
current_id = sh ? sh->aid : -2;
switch (action) {
case M_PROPERTY_GET:
@ -951,12 +952,18 @@ static int mp_property_audio(m_option_t *prop, int action, void *arg,
if (current_id < 0)
*(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
else {
else if (sh && (sh->lang || sh->title)) {
char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
if (sh->title)
*(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
current_id, lang, sh->title);
else
*(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id,
lang);
} else {
char lang[40];
strncpy(lang, mp_gtext("unknown"), sizeof(lang));
sh_audio_t* sh = mpctx->sh_audio;
if (sh && sh->lang)
av_strlcpy(lang, sh->lang, 40);
if (0);
#ifdef CONFIG_DVDREAD
else if (mpctx->stream->type == STREAMTYPE_DVD) {
int code = dvd_lang_from_aid(mpctx->stream, current_id);
@ -1564,10 +1571,14 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
|| d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
|| d_sub->demuxer->type == DEMUXER_TYPE_OGG)
&& d_sub->sh && opts->sub_id >= 0) {
const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
if (!lang) lang = mp_gtext("unknown");
*(char **) arg = talloc_asprintf(NULL, "(%d) %s",
opts->sub_id, lang);
struct sh_sub *sh = d_sub->sh;
char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
if (sh->title)
*(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
opts->sub_id, lang, sh->title);
else
*(char **)arg = talloc_asprintf(NULL, "(%d) %s",
opts->sub_id, lang);
return M_PROPERTY_OK;
}

View File

@ -362,9 +362,11 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
sh_audio->format = 0x7;
break;
}
if (title && title->value)
if (title && title->value) {
sh_audio->title = talloc_strdup(sh_audio, title->value);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_NAME=%s\n",
priv->audio_streams, title->value);
}
if (lang && lang->value) {
sh_audio->lang = talloc_strdup(sh_audio, lang->value);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_LANG=%s\n",
@ -425,9 +427,11 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
sh_video->aspect = codec->width * codec->sample_aspect_ratio.num
/ (float)(codec->height * codec->sample_aspect_ratio.den);
sh_video->i_bps = codec->bit_rate / 8;
if (title && title->value)
if (title && title->value) {
sh_video->title = talloc_strdup(sh_video, title->value);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VID_%d_NAME=%s\n",
priv->video_streams, title->value);
}
mp_msg(MSGT_DEMUX, MSGL_DBG2, "aspect= %d*%d/(%d*%d)\n",
codec->width, codec->sample_aspect_ratio.num,
codec->height, codec->sample_aspect_ratio.den);
@ -480,9 +484,11 @@ 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 (title && title->value)
if (title && title->value) {
sh_sub->title = talloc_strdup(sh_sub, title->value);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_NAME=%s\n",
priv->sub_streams, title->value);
}
if (lang && lang->value) {
sh_sub->lang = talloc_strdup(sh_sub, lang->value);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n",

View File

@ -1253,6 +1253,7 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track,
}
sh_v = new_sh_video(demuxer, vid);
sh_v->title = talloc_strdup(sh_v, track->name);
sh_v->bih = bih;
sh_v->format = sh_v->bih->biCompression;
if (track->v_frate == 0.0)
@ -1290,6 +1291,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track,
if (track->language && (strcmp(track->language, "und") != 0))
sh_a->lang = talloc_strdup(sh_a, track->language);
sh_a->title = talloc_strdup(sh_a, track->name);
sh_a->default_track = track->default_track;
sh_a->ds = demuxer->audio;
sh_a->wf = malloc(sizeof(*sh_a->wf));
@ -1588,6 +1590,7 @@ static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track,
sh->extradata_len = track->private_size;
if (track->language && (strcmp(track->language, "und") != 0))
sh->lang = talloc_strdup(sh, track->language);
sh->title = talloc_strdup(sh, track->name);
sh->default_track = track->default_track;
} else {
mp_tmsg(MSGT_DEMUX, MSGL_ERR,

View File

@ -47,6 +47,7 @@ struct demuxer;
/* decoder context */ \
void *context; \
char *lang; /* track language */ \
char *title; /* track title */ \
bool default_track; \
typedef struct sh_common {