changeset 26269:65ad20416dd7

Support 'default' attribute for audio and subtitle tracks. The first default track is chosen for playback if language-based selection failes. Additionally, for audio tracks, the first one is chosen if there are no default tracks at all.
author eugeni
date Sun, 30 Mar 2008 16:55:46 +0000
parents 2f5886f0d307
children 75a108423c11
files libmpdemux/demux_lavf.c libmpdemux/demux_mkv.c libmpdemux/demuxer.c libmpdemux/demuxer.h libmpdemux/stheader.h mencoder.c mpcommon.c mplayer.c
diffstat 8 files changed, 49 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_lavf.c	Sat Mar 29 15:51:05 2008 +0000
+++ b/libmpdemux/demux_lavf.c	Sun Mar 30 16:55:46 2008 +0000
@@ -337,6 +337,8 @@
             }
             if (st->language)
               sh_audio->lang = strdup(st->language);
+            if (st->disposition & AV_DISPOSITION_DEFAULT)
+              sh_audio->default_track = 1;
             if(mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf, MSGL_V);
             // select the first audio stream
             if (!demuxer->audio->sh) {
@@ -433,6 +435,8 @@
             }
             if (st->language)
               sh_sub->lang = strdup(st->language);
+            if (st->disposition & AV_DISPOSITION_DEFAULT)
+              sh_sub->default_track = 1;
             priv->sub_streams++;
             break;
         }
--- a/libmpdemux/demux_mkv.c	Sat Mar 29 15:51:05 2008 +0000
+++ b/libmpdemux/demux_mkv.c	Sun Mar 30 16:55:46 2008 +0000
@@ -1849,6 +1849,7 @@
 
   if (track->language && (strcmp(track->language, "und") != 0))
     sh_a->lang = strdup(track->language);
+  sh_a->default_track = track->default_track;
   sh_a->ds = demuxer->audio;
   sh_a->wf = malloc (sizeof (WAVEFORMATEX));
   if (track->ms_compat && (track->private_size >= sizeof(WAVEFORMATEX)))
@@ -2217,6 +2218,7 @@
       sh->extradata_len = track->private_size;
       if (track->language && (strcmp(track->language, "und") != 0))
         sh->lang = strdup(track->language);
+      sh->default_track = track->default_track;
     }
   else
     {
--- a/libmpdemux/demuxer.c	Sat Mar 29 15:51:05 2008 +0000
+++ b/libmpdemux/demuxer.c	Sun Mar 30 16:55:46 2008 +0000
@@ -1441,3 +1441,31 @@
     }
     return -1;
 }
+
+int demuxer_default_audio_track(demuxer_t* d)
+{
+    int i;
+    for (i=0; i < MAX_A_STREAMS; ++i) {
+        sh_audio_t* sh = d->a_streams[i];
+        if (sh && sh->default_track)
+            return sh->aid;
+    }
+    for (i=0; i < MAX_A_STREAMS; ++i) {
+        sh_audio_t* sh = d->a_streams[i];
+        if (sh)
+            return sh->aid;
+    }
+    return -1;
+}
+
+int demuxer_default_sub_track(demuxer_t* d)
+{
+    int i;
+    for (i=0; i < MAX_S_STREAMS; ++i) {
+        sh_sub_t* sh = d->s_streams[i];
+        if (sh && sh->default_track)
+            return sh->sid;
+    }
+    return -1;
+}
+
--- a/libmpdemux/demuxer.h	Sat Mar 29 15:51:05 2008 +0000
+++ b/libmpdemux/demuxer.h	Sun Mar 30 16:55:46 2008 +0000
@@ -431,4 +431,10 @@
 int demuxer_audio_track_by_lang(demuxer_t* demuxer, char* lang);
 int demuxer_sub_track_by_lang(demuxer_t* demuxer, char* lang);
 
+// find the default track
+// for subtitles, it is the first track with default attribute
+// for audio, additionally, the first track is selected if no track has default attribute set
+int demuxer_default_audio_track(demuxer_t* d);
+int demuxer_default_sub_track(demuxer_t* d);
+
 #endif /* MPLAYER_DEMUXER_H */
--- a/libmpdemux/stheader.h	Sat Mar 29 15:51:05 2008 +0000
+++ b/libmpdemux/stheader.h	Sun Mar 30 16:55:46 2008 +0000
@@ -51,6 +51,7 @@
   double pts;  // last known pts value in output from decoder
   int pts_bytes; // bytes output by decoder after last known pts
   char* lang; // track language
+  int default_track;
 } sh_audio_t;
 
 typedef struct {
@@ -108,6 +109,7 @@
   ass_track_t* ass_track;  // for SSA/ASS streams (type == 'a')
 #endif
   char* lang; // track language
+  int default_track;
 } sh_sub_t;
 
 // demuxer.c:
--- a/mencoder.c	Sat Mar 29 15:51:05 2008 +0000
+++ b/mencoder.c	Sun Mar 30 16:55:46 2008 +0000
@@ -601,6 +601,9 @@
   if (dvdsub_id < 0 && dvdsub_lang)
     dvdsub_id = demuxer_sub_track_by_lang(demuxer, dvdsub_lang);
 
+  if (dvdsub_id < 0)
+    dvdsub_id = demuxer_default_sub_track(demuxer);
+
   for (i = 0; i < MAX_S_STREAMS; i++) {
     sh_sub_t *sh = demuxer->s_streams[i];
     if (sh && sh->sid == dvdsub_id) {
--- a/mpcommon.c	Sat Mar 29 15:51:05 2008 +0000
+++ b/mpcommon.c	Sun Mar 30 16:55:46 2008 +0000
@@ -195,6 +195,8 @@
 {
     if (audio_id == -1 && audio_lang)
         audio_id = demuxer_audio_track_by_lang(demuxer, audio_lang);
+    if (audio_id == -1)
+        audio_id = demuxer_default_audio_track(demuxer);
     if (audio_id != -1) // -1 (automatic) is the default behaviour of demuxers
         demuxer_switch_audio(demuxer, audio_id);
     if (audio_id == -2) { // some demuxers don't yet know how to switch to no sound
--- a/mplayer.c	Sat Mar 29 15:51:05 2008 +0000
+++ b/mplayer.c	Sun Mar 30 16:55:46 2008 +0000
@@ -3459,6 +3459,8 @@
   int vobsub_index_id = vobsub_get_index_by_id(vo_vobsub, vobsub_id);
   if (dvdsub_id < 0 && dvdsub_lang)
     dvdsub_id = demuxer_sub_track_by_lang(mpctx->demuxer, dvdsub_lang);
+  if (dvdsub_id < 0)
+    dvdsub_id = demuxer_default_sub_track(mpctx->demuxer);
   if (vobsub_index_id >= 0) {
     // if user asks for a vobsub id, use that first.
     mpctx->global_sub_pos = mpctx->global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_index_id;