[MPlayer-cvslog] r26301 - in trunk: libmpdemux/demux_lavf.c libmpdemux/demux_mkv.c libmpdemux/demuxer.c libmpdemux/demuxer.h libmpdemux/stheader.h mencoder.c mpcommon.c mplayer.c

eugeni subversion at mplayerhq.hu
Sun Mar 30 18:55:46 CEST 2008


Author: eugeni
Date: Sun Mar 30 18:55:46 2008
New Revision: 26301

Log:
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.


Modified:
   trunk/libmpdemux/demux_lavf.c
   trunk/libmpdemux/demux_mkv.c
   trunk/libmpdemux/demuxer.c
   trunk/libmpdemux/demuxer.h
   trunk/libmpdemux/stheader.h
   trunk/mencoder.c
   trunk/mpcommon.c
   trunk/mplayer.c

Modified: trunk/libmpdemux/demux_lavf.c
==============================================================================
--- trunk/libmpdemux/demux_lavf.c	(original)
+++ trunk/libmpdemux/demux_lavf.c	Sun Mar 30 18:55:46 2008
@@ -337,6 +337,8 @@ static void handle_stream(demuxer_t *dem
             }
             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 @@ static void handle_stream(demuxer_t *dem
             }
             if (st->language)
               sh_sub->lang = strdup(st->language);
+            if (st->disposition & AV_DISPOSITION_DEFAULT)
+              sh_sub->default_track = 1;
             priv->sub_streams++;
             break;
         }

Modified: trunk/libmpdemux/demux_mkv.c
==============================================================================
--- trunk/libmpdemux/demux_mkv.c	(original)
+++ trunk/libmpdemux/demux_mkv.c	Sun Mar 30 18:55:46 2008
@@ -1849,6 +1849,7 @@ demux_mkv_open_audio (demuxer_t *demuxer
 
   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 @@ demux_mkv_open_sub (demuxer_t *demuxer, 
       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
     {

Modified: trunk/libmpdemux/demuxer.c
==============================================================================
--- trunk/libmpdemux/demuxer.c	(original)
+++ trunk/libmpdemux/demuxer.c	Sun Mar 30 18:55:46 2008
@@ -1441,3 +1441,31 @@ int demuxer_sub_track_by_lang(demuxer_t*
     }
     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;
+}
+

Modified: trunk/libmpdemux/demuxer.h
==============================================================================
--- trunk/libmpdemux/demuxer.h	(original)
+++ trunk/libmpdemux/demuxer.h	Sun Mar 30 18:55:46 2008
@@ -431,4 +431,10 @@ int demuxer_angles_count(demuxer_t *demu
 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 */

Modified: trunk/libmpdemux/stheader.h
==============================================================================
--- trunk/libmpdemux/stheader.h	(original)
+++ trunk/libmpdemux/stheader.h	Sun Mar 30 18:55:46 2008
@@ -51,6 +51,7 @@ typedef struct {
   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 @@ typedef struct {
   ass_track_t* ass_track;  // for SSA/ASS streams (type == 'a')
 #endif
   char* lang; // track language
+  int default_track;
 } sh_sub_t;
 
 // demuxer.c:

Modified: trunk/mencoder.c
==============================================================================
--- trunk/mencoder.c	(original)
+++ trunk/mencoder.c	Sun Mar 30 18:55:46 2008
@@ -601,6 +601,9 @@ if(stream->type==STREAMTYPE_DVDNAV){
   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) {

Modified: trunk/mpcommon.c
==============================================================================
--- trunk/mpcommon.c	(original)
+++ trunk/mpcommon.c	Sun Mar 30 18:55:46 2008
@@ -195,6 +195,8 @@ int select_audio(demuxer_t* demuxer, int
 {
     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

Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c	(original)
+++ trunk/mplayer.c	Sun Mar 30 18:55:46 2008
@@ -3459,6 +3459,8 @@ if (mpctx->global_sub_size) {
   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;



More information about the MPlayer-cvslog mailing list