1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-21 06:14:32 +00:00

adds a parameter to the switch_audio command to directly select a track.

Patch by kiriuja mplayer-patches at en-directo net


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@15286 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2005-04-28 14:43:19 +00:00
parent 68f4daf93b
commit be54f4813f
7 changed files with 49 additions and 23 deletions

View File

@ -91,8 +91,9 @@ use_master
mute
Mute/unmute sound output.
switch_audio (MPEG and Matroska only)
Cycle through the available audio tracks.
switch_audio [<value>] (MPEG and Matroska only)
Switch to the audio track with the id <value>. Cycle through the
available tracks if <value> is omitted or negative.
[contrast|gamma|brightness|hue|saturation] <-100 - 100> [<abs>]
Set/adjust video parameters.

View File

@ -82,7 +82,7 @@ static mp_cmd_t mp_cmds[] = {
{ MP_CMD_SUB_LOG, "sub_log", 0, { {-1,{0}} } },
{ MP_CMD_GET_PERCENT_POS, "get_percent_pos", 0, { {-1,{0}} } },
{ MP_CMD_GET_TIME_LENGTH, "get_time_length", 0, { {-1,{0}} } },
{ MP_CMD_SWITCH_AUDIO, "switch_audio", 0, { {-1,{0}} } },
{ MP_CMD_SWITCH_AUDIO, "switch_audio", 0, { { MP_CMD_ARG_INT,{-1} }, {-1,{0}} } },
#ifdef USE_TV
{ MP_CMD_TV_STEP_CHANNEL, "tv_step_channel", 1, { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} }},
{ MP_CMD_TV_STEP_NORM, "tv_step_norm",0, { {-1,{0}} } },

View File

@ -2118,16 +2118,17 @@ demux_mkv_open_sub (demuxer_t *demuxer, mkv_track_t *track)
void demux_mkv_seek (demuxer_t *demuxer, float rel_seek_secs, int flags);
/** \brief Given a matroska track number, find the subtitle number that mplayer would ask for.
/** \brief Given a matroska track number and type, find the id that mplayer would ask for.
* \param d The demuxer for which the subtitle id should be returned.
* \param num The matroska track number we are looking up.
* \param type The track type.
*/
static int demux_mkv_sub_reverse_id(mkv_demuxer_t *d, int num)
static int demux_mkv_reverse_id(mkv_demuxer_t *d, int num, int type)
{
int i, id;
for (i=0, id=0; i < d->num_tracks; i++)
if (d->tracks[i] != NULL && d->tracks[i]->type == MATROSKA_TRACK_SUBTITLE) {
if (d->tracks[i] != NULL && d->tracks[i]->type == type) {
if (d->tracks[i]->tnum == num)
return id;
id++;
@ -2351,7 +2352,7 @@ demux_mkv_open (demuxer_t *demuxer)
{
mp_msg (MSGT_DEMUX, MSGL_INFO,
"[mkv] Will display subtitle track %u\n", track->tnum);
dvdsub_id = demux_mkv_sub_reverse_id(mkv_d, track->tnum);
dvdsub_id = demux_mkv_reverse_id(mkv_d, track->tnum, MATROSKA_TRACK_SUBTITLE);
demuxer->sub->id = track->tnum;
}
else
@ -3344,12 +3345,13 @@ demux_mkv_control (demuxer_t *demuxer, int cmd, void *arg)
if (demuxer->audio && demuxer->audio->sh) {
int i;
demux_stream_t *d_audio = demuxer->audio;
sh_audio_t *sh_audio = d_audio->sh;
int idx = d_audio->id - 1; // track ids are 1 based
int num = mkv_d->num_tracks;
mkv_track_t *otrack = mkv_d->tracks[idx];
for (i = 1; i < num; i++) {
mkv_track_t *track = mkv_d->tracks[(idx+i)%num];
mkv_track_t *track = 0;
if (*((int*)arg) < 0)
for (i = 1; i <= num; i++) {
track = mkv_d->tracks[(idx+i)%num];
if ((track->type == MATROSKA_TRACK_AUDIO) &&
!strcmp(track->codec_id, otrack->codec_id) &&
(track->a_channels == otrack->a_channels) &&
@ -3358,12 +3360,21 @@ demux_mkv_control (demuxer_t *demuxer, int cmd, void *arg)
break;
}
}
if (i < num) {
d_audio->id = (idx+i)%num + 1;
else {
track = demux_mkv_find_track_by_num (mkv_d, *((int*)arg), MATROSKA_TRACK_AUDIO);
if (track == NULL ||
strcmp (track->codec_id, otrack->codec_id) ||
track->a_channels != otrack->a_channels ||
track->a_bps != otrack->a_bps ||
track->a_sfreq != otrack->a_sfreq)
track = otrack;
}
if (track != otrack) {
d_audio->id = track->tnum;
ds_free_packs(d_audio);
}
*((int *)arg)=(int)d_audio->id;
}
*((int*)arg) = demux_mkv_reverse_id (mkv_d, demuxer->audio->id, MATROSKA_TRACK_AUDIO);
return DEMUXER_CTRL_OK;
default:

View File

@ -643,6 +643,8 @@ int demux_mpg_control(demuxer_t *demuxer,int cmd, void *arg){
sh_audio_t *sh_audio = d_audio->sh;
sh_audio_t *sh_a;
int i;
if (*((int*)arg) < 0)
{
for (i = 0; i < mpg_d->num_a_streams; i++) {
if (d_audio->id == mpg_d->a_stream_ids[i]) break;
}
@ -650,13 +652,22 @@ int demux_mpg_control(demuxer_t *demuxer,int cmd, void *arg){
i = (i+1) % mpg_d->num_a_streams;
sh_a = (sh_audio_t*)demuxer->a_streams[mpg_d->a_stream_ids[i]];
} while (sh_a->format != sh_audio->format);
if (d_audio->id != mpg_d->a_stream_ids[i]) {
}
else {
for (i = 0; i < mpg_d->num_a_streams; i++)
if (*((int*)arg) == mpg_d->a_stream_ids[i]) break;
if (i < mpg_d->num_a_streams)
sh_a = (sh_audio_t*)demuxer->a_streams[*((int*)arg)];
if (sh_a->format != sh_audio->format)
i = mpg_d->num_a_streams;
}
if (i < mpg_d->num_a_streams && d_audio->id != mpg_d->a_stream_ids[i]) {
d_audio->id = mpg_d->a_stream_ids[i];
d_audio->sh = sh_a;
ds_free_packs(d_audio);
}
*((int *)arg)=(int)d_audio->id;
}
*((int*)arg) = demuxer->audio->id;
return DEMUXER_CTRL_OK;
default:

View File

@ -1778,8 +1778,9 @@ int demuxer_get_percent_pos(demuxer_t *demuxer){
return ans;
}
int demuxer_switch_audio(demuxer_t *demuxer){
int ans = 0;
int res = demux_control(demuxer, DEMUXER_CTRL_SWITCH_AUDIO, &ans);
return ans;
int demuxer_switch_audio(demuxer_t *demuxer, int index){
int res = demux_control(demuxer, DEMUXER_CTRL_SWITCH_AUDIO, &index);
if (res == DEMUXER_CTRL_NOTIMPL)
index = demuxer->audio->id;
return index;
}

View File

@ -287,6 +287,6 @@ char *demux_ogg_sub_lang(demuxer_t *demuxer, int index);
extern unsigned long demuxer_get_time_length(demuxer_t *demuxer);
extern int demuxer_get_percent_pos(demuxer_t *demuxer);
extern int demuxer_switch_audio(demuxer_t *demuxer);
extern int demuxer_switch_audio(demuxer_t *demuxer, int index);
extern int demuxer_type_by_filename(char* filename);

View File

@ -3494,9 +3494,11 @@ if (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still)
case MP_CMD_GET_PERCENT_POS : {
mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_AnsPercentPos, demuxer_get_percent_pos(demuxer));
} break;
case MP_CMD_SWITCH_AUDIO :
demuxer_switch_audio(demuxer);
break;
case MP_CMD_SWITCH_AUDIO : {
int v = demuxer_switch_audio(demuxer, cmd->args[0].v.i);
if (identify)
mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", v);
} break;
case MP_CMD_RUN : {
#ifndef __MINGW32__
if(!fork()) {