Mercurial > mplayer.hg
changeset 20156:42b46a42f83b
added OSD audio switching visualization
author | ptt |
---|---|
date | Wed, 11 Oct 2006 17:25:46 +0000 |
parents | c903e0d80f02 |
children | eec5cccc1734 |
files | help/help_mp-en.h libmpdemux/demux_mkv.c libmpdemux/matroska.h mplayer.c stream/stream_dvd.c stream/stream_dvd.h |
diffstat | 6 files changed, 120 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/help/help_mp-en.h Wed Oct 11 15:57:51 2006 +0000 +++ b/help/help_mp-en.h Wed Oct 11 17:25:46 2006 +0000 @@ -207,6 +207,7 @@ #define MSGTR_OSDenabled "enabled" #define MSGTR_OSDdisabled "disabled" +#define MSGTR_OSDAudio "Audio: %s" #define MSGTR_OSDChannel "Channel: %s" #define MSGTR_OSDSubDelay "Sub delay: %d ms" #define MSGTR_OSDSpeed "Speed: x %6.2f"
--- a/libmpdemux/demux_mkv.c Wed Oct 11 15:57:51 2006 +0000 +++ b/libmpdemux/demux_mkv.c Wed Oct 11 17:25:46 2006 +0000 @@ -3954,6 +3954,40 @@ } } +/** \brief Get the language code for an audio track. + + Retrieves the language code for an audio 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 n'th audio track 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_audio_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; + int i, num; + + num = 0; + for (i = 0; i < mkv_d->num_tracks; i++) + { + track = mkv_d->tracks[i]; + if (track->type == MATROSKA_TRACK_AUDIO) + num++; + if (num == (track_num + 1)) + { + if ((track->language != NULL) && + strcmp(track->language, "und")) + strlcpy(lang, track->language, maxlen); + return; + } + } +} + demuxer_desc_t demuxer_desc_matroska = { "Matroska demuxer",
--- a/libmpdemux/matroska.h Wed Oct 11 15:57:51 2006 +0000 +++ b/libmpdemux/matroska.h Wed Oct 11 17:25:46 2006 +0000 @@ -63,6 +63,8 @@ int demux_mkv_num_subs(demuxer_t *demuxer); int demux_mkv_change_subs(demuxer_t *demuxer, int new_num); +void demux_mkv_get_audio_lang(demuxer_t *demuxer, int track_num, char *lang, + int maxlen); void demux_mkv_get_sub_lang(demuxer_t *demuxer, int track_num, char *lang, int maxlen);
--- a/mplayer.c Wed Oct 11 15:57:51 2006 +0000 +++ b/mplayer.c Wed Oct 11 17:25:46 2006 +0000 @@ -193,6 +193,10 @@ #include "libmpcodecs/vd.h" //**************************************************************************// + +static void reinit_audio_chain(void); + +//**************************************************************************// //**************************************************************************// // Common FIFO functions, and keyboard/event FIFO code @@ -1781,6 +1785,68 @@ return m_property_int_ro(prop,action,arg,sh_audio->channels); } +/// Selected audio id (RW) +static int mp_property_audio(m_option_t* prop,int action,void* arg) { + int current_id = -1; + + if(!sh_audio) return M_PROPERTY_UNAVAILABLE; + + switch(action) { + case M_PROPERTY_GET: + if(!arg) return 0; + *(int*)arg = audio_id; + return 1; + case M_PROPERTY_PRINT: + if(!arg) return 0; + *(char**)arg = malloc(64); + (*(char**)arg)[63] = 0; + + if (demuxer->type == DEMUXER_TYPE_MATROSKA && audio_id >= 0) { + char lang[40] = MSGTR_Unknown; + demux_mkv_get_audio_lang(demuxer, audio_id, lang, 9); + lang[39] = 0; + snprintf(*(char**)arg, 63, "(%d) %s", audio_id, lang); + return 1; + } +#ifdef USE_DVDREAD + if (audio_id >= 0) { + char lang[3] = "\0\0\0"; + int code = 0; + code = dvd_lang_from_aid(stream, audio_id); + if (code) { + lang[0] = code >> 8; + lang[1] = code; + } + snprintf(*(char**)arg, 63, "(%d) %s", audio_id, code ? lang : MSGTR_Unknown); + return 1; + } +#endif + snprintf(*(char**)arg, 63, MSGTR_Disabled); + return 1; + + case M_PROPERTY_STEP_UP: + current_id = demuxer->audio->id; + audio_id = demuxer_switch_audio(demuxer, -1); + if(audio_id > -1 && demuxer->audio->id != current_id) { + sh_audio_t *sh2; + uninit_player(INITED_AO | INITED_ACODEC); + sh2 = demuxer->a_streams[demuxer->audio->id]; + if(sh2) { + sh2->ds = demuxer->audio; + sh_audio = sh2; + reinit_audio_chain(); + } + } + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id); + + break; + default: + return M_PROPERTY_NOT_IMPLEMENTED; + } + + return 1; +} + ///@} /// \defgroup VideoProperties Video properties @@ -2352,6 +2418,8 @@ 0, 0, 0, NULL }, { "channels", mp_property_channels, CONF_TYPE_INT, 0, 0, 0, NULL }, + { "switch_audio", mp_property_audio, CONF_TYPE_INT, + -1, -1, 0, NULL }, // Video { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG, @@ -2471,6 +2539,7 @@ { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume }, { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus }, { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus }, + { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio }, // video { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL }, { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan }, @@ -5107,21 +5176,6 @@ pos = playing_audio_pts(sh_audio, d_audio, audio_out); mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos); } break; - case MP_CMD_SWITCH_AUDIO : { - int current_id = demuxer->audio->id; - int v = demuxer_switch_audio(demuxer, cmd->args[0].v.i); - if(v > -1 && demuxer->audio->id != current_id) { - sh_audio_t *sh2; - uninit_player(INITED_AO | INITED_ACODEC); - sh2 = demuxer->a_streams[demuxer->audio->id]; - if(sh2) { - sh2->ds = demuxer->audio; - sh_audio = sh2; - reinit_audio_chain(); - } - } - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", v); - } break; case MP_CMD_RUN : { #ifndef __MINGW32__ if(!fork()) {
--- a/stream/stream_dvd.c Wed Oct 11 15:57:51 2006 +0000 +++ b/stream/stream_dvd.c Wed Oct 11 17:25:46 2006 +0000 @@ -140,6 +140,19 @@ return chapter; } +int dvd_lang_from_aid(stream_t *stream, int id) { + dvd_priv_t *d; + if (!stream) return 0; + d = stream->priv; + if (!d) return 0; + int i; + for(i=0;i<d->nr_of_channels;i++) { + if(d->audio_streams[i].id==id) + return d->audio_streams[i].language; + } + return 0; +} + int dvd_aid_from_lang(stream_t *stream, unsigned char* lang) { dvd_priv_t *d=stream->priv; int code,i;
--- a/stream/stream_dvd.h Wed Oct 11 15:57:51 2006 +0000 +++ b/stream/stream_dvd.h Wed Oct 11 17:25:46 2006 +0000 @@ -45,6 +45,7 @@ } dvd_priv_t; int dvd_number_of_subs(stream_t *stream); +int dvd_lang_from_aid(stream_t *stream, int id); int dvd_lang_from_sid(stream_t *stream, int id); int dvd_aid_from_lang(stream_t *stream, unsigned char* lang); int dvd_sid_from_lang(stream_t *stream, unsigned char* lang);