changeset 15285:39eb8a327ea9

adds a parameter to the switch_audio command to directly select a track. Patch by kiriuja mplayer-patches at en-directo net
author reimar
date Thu, 28 Apr 2005 14:43:19 +0000
parents 5e5497faee72
children 1e8305fffa79
files DOCS/tech/slave.txt input/input.c libmpdemux/demux_mkv.c libmpdemux/demux_mpg.c libmpdemux/demuxer.c libmpdemux/demuxer.h mplayer.c
diffstat 7 files changed, 49 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/tech/slave.txt	Wed Apr 27 21:59:38 2005 +0000
+++ b/DOCS/tech/slave.txt	Thu Apr 28 14:43:19 2005 +0000
@@ -91,8 +91,9 @@
 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.
--- a/input/input.c	Wed Apr 27 21:59:38 2005 +0000
+++ b/input/input.c	Thu Apr 28 14:43:19 2005 +0000
@@ -82,7 +82,7 @@
   { 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}} }  },
--- a/libmpdemux/demux_mkv.c	Wed Apr 27 21:59:38 2005 +0000
+++ b/libmpdemux/demux_mkv.c	Thu Apr 28 14:43:19 2005 +0000
@@ -2118,16 +2118,17 @@
 
 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 @@
           {
             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 @@
       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 @@
             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:
--- a/libmpdemux/demux_mpg.c	Wed Apr 27 21:59:38 2005 +0000
+++ b/libmpdemux/demux_mpg.c	Thu Apr 28 14:43:19 2005 +0000
@@ -643,6 +643,8 @@
               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 @@
                 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:
--- a/libmpdemux/demuxer.c	Wed Apr 27 21:59:38 2005 +0000
+++ b/libmpdemux/demuxer.c	Thu Apr 28 14:43:19 2005 +0000
@@ -1778,8 +1778,9 @@
     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;
 }
--- a/libmpdemux/demuxer.h	Wed Apr 27 21:59:38 2005 +0000
+++ b/libmpdemux/demuxer.h	Thu Apr 28 14:43:19 2005 +0000
@@ -287,6 +287,6 @@
 
 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);
--- a/mplayer.c	Wed Apr 27 21:59:38 2005 +0000
+++ b/mplayer.c	Thu Apr 28 14:43:19 2005 +0000
@@ -3494,9 +3494,11 @@
     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()) {