[vlc-devel] [PATCH] Use mkv track flags to define the priority of ES

Denis Charmet typx at dinauz.org
Fri Feb 24 00:07:00 CET 2012


Fix #6199
---
 modules/demux/mkv/matroska_segment.cpp       |   37 ++++++++++++++++++++++---
 modules/demux/mkv/matroska_segment_parse.cpp |    4 ++-
 modules/demux/mkv/mkv.hpp                    |    1 +
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index 528c2b3..b7255ee 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -921,17 +921,42 @@ bool matroska_segment_c::Select( mtime_t i_start_time )
     /* add all es */
     msg_Dbg( &sys.demuxer, "found %d es", (int)tracks.size() );
 
+    bool b_has_default_video = false;
+    bool b_has_default_audio = false;
+    /* check for default */
+    for(size_t i_track = 0; i_track < tracks.size(); i_track++)
+    {
+        mkv_track_t *p_tk = tracks[i_track];
+        es_format_t *p_fmt = &p_tk->fmt;
+        if( p_fmt->i_cat == VIDEO_ES )
+            b_has_default_video |=
+                p_tk->b_enabled && ( p_tk->b_default || p_tk->b_forced );
+        else if( p_fmt->i_cat == AUDIO_ES )
+            b_has_default_audio |=
+                p_tk->b_enabled && ( p_tk->b_default || p_tk->b_forced );
+    }
+
     for( size_t i_track = 0; i_track < tracks.size(); i_track++ )
     {
         mkv_track_t *p_tk = tracks[i_track];
         es_format_t *p_fmt = &p_tk->fmt;
 
-        if( p_fmt->i_cat == UNKNOWN_ES || !p_tk->psz_codec )
+        if( unlikely( p_fmt->i_cat == UNKNOWN_ES || !p_tk->psz_codec ) )
         {
             msg_Warn( &sys.demuxer, "invalid track[%d, n=%d]", (int)i_track, p_tk->i_number );
             p_tk->p_es = NULL;
             continue;
         }
+        else if( unlikely( !b_has_default_video && p_fmt->i_cat == VIDEO_ES ) )
+        {
+            p_tk->b_default = true;
+            b_has_default_video = true;
+        }
+        else if( unlikely( !b_has_default_audio &&  p_fmt->i_cat == AUDIO_ES ) )
+        {
+            p_tk->b_default = true;
+            b_has_default_audio = true;
+        }
 
         if( !strcmp( p_tk->psz_codec, "V_MS/VFW/FOURCC" ) )
         {
@@ -1335,10 +1358,14 @@ bool matroska_segment_c::Select( mtime_t i_start_time )
             msg_Err( &sys.demuxer, "unknown codec id=`%s'", p_tk->psz_codec );
             p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
         }
-        if( p_tk->b_default )
-        {
-            p_tk->fmt.i_priority = 1000;
-        }
+        if( unlikely( !p_tk->b_enabled ) )
+            p_tk->fmt.i_priority = -2;
+        else if( p_tk->b_forced )
+            p_tk->fmt.i_priority = 1;
+        else if( p_tk->b_default )
+            p_tk->fmt.i_priority = 0;
+        else
+            p_tk->fmt.i_priority = -1;
 
         p_tk->p_es = es_out_Add( sys.demuxer.out, &p_tk->fmt );
 
diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp
index 09391da..422fad2 100644
--- a/modules/demux/mkv/matroska_segment_parse.cpp
+++ b/modules/demux/mkv/matroska_segment_parse.cpp
@@ -179,6 +179,7 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
 
     tk->b_default              = true;
     tk->b_enabled              = true;
+    tk->b_forced               = false;
     tk->b_silent               = false;
     tk->i_number               = tracks.size() - 1;
     tk->i_extra_data           = 0;
@@ -254,7 +255,7 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
         {
             KaxTrackFlagEnabled &fenb = *(KaxTrackFlagEnabled*)l;
 
-            // tk->b_enabled = uint32( fenb );
+            tk->b_enabled = uint32( fenb );
             msg_Dbg( &sys.demuxer, "|   |   |   + Track Enabled=%u", uint32( fenb ) );
         }
         else  if( MKV_IS_ID( l, KaxTrackFlagDefault ) )
@@ -267,6 +268,7 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
         else  if( MKV_IS_ID( l, KaxTrackFlagForced ) ) // UNUSED
         {
             KaxTrackFlagForced &ffor = *(KaxTrackFlagForced*)l;
+            tk->b_forced = uint32( ffor );
 
             msg_Dbg( &sys.demuxer, "|   |   |   + Track Forced=%u", uint32( ffor ) );
         }
diff --git a/modules/demux/mkv/mkv.hpp b/modules/demux/mkv/mkv.hpp
index 2687733..1f8c1b4 100644
--- a/modules/demux/mkv/mkv.hpp
+++ b/modules/demux/mkv/mkv.hpp
@@ -180,6 +180,7 @@ struct mkv_track_t
 
     bool         b_default;
     bool         b_enabled;
+    bool         b_forced;
     unsigned int i_number;
 
     unsigned int i_extra_data;
-- 
1.7.8.3




More information about the vlc-devel mailing list