[vlc-devel] [RFC, PATCH 3/6] demux/mkv: Cleaned up code to issue debug diagnostics

Filip Roséen filip at videolabs.io
Thu Mar 3 13:30:24 CET 2016


  - helper function to print diagnostics within MetaDataHandlers introduced
  - fixed so that `matroska_segment_c::ParseTracks` is using `MkvTree`
    for diagnostics
---
 modules/demux/mkv/matroska_segment_parse.cpp | 110 ++++++++++++++-------------
 1 file changed, 58 insertions(+), 52 deletions(-)

diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp
index 11874aa..28dc378 100644
--- a/modules/demux/mkv/matroska_segment_parse.cpp
+++ b/modules/demux/mkv/matroska_segment_parse.cpp
@@ -188,6 +188,7 @@ void matroska_segment_c::ParseSeekHead( KaxSeekHead *seekhead )
     }
 }
 
+
 /*****************************************************************************
  * ParseTrackEntry:
  *****************************************************************************/
@@ -231,7 +232,7 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
     tk->i_encoding_scope       = MATROSKA_ENCODING_SCOPE_ALL_FRAMES;
     tk->p_compression_data     = NULL;
 
-    msg_Dbg( &sys.demuxer, "|   |   + Track Entry" );
+    MkvTree( sys.demuxer, 2, "Track Entry" );
 
     struct MetaDataCapture {
       matroska_segment_c * obj;
@@ -257,14 +258,20 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
     {
         MKV_SWITCH_INIT();
 
+        static void debug (MetaDataCapture const& vars, char const * fmt, ...)
+        {
+            va_list args; va_start( args, fmt );
+            MkvTree_va( *vars.p_demuxer, vars.level, fmt, args);
+            va_end( args );
+        }
         E_CASE( KaxTrackNumber, tnum )
         {
             vars.tk->i_number = uint32( tnum );
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Number=%u", uint32( tnum ) );
+            debug( vars, "Track Number=%u", vars.tk->i_number );
         }
         E_CASE( KaxTrackUID, tuid )
         {
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track UID=%u",  uint32( tuid ) );
+            debug( vars, "Track UID=%u", uint32( tuid ) );
         }
         E_CASE( KaxTrackType, ttype )
         {
@@ -296,68 +303,67 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
                     break;
             }
 
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Type=%s", psz_type );
+            debug( vars, "Track Type=%s", psz_type ) ;
         }
         E_CASE( KaxTrackFlagEnabled, fenb ) // UNUSED
         {
             vars.tk->b_enabled = uint32( fenb );
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Enabled=%u", uint32( fenb ) );
+            debug( vars, "Track Enabled=%u", uint32( fenb ) ) ;
         }
         E_CASE( KaxTrackFlagDefault, fdef )
         {
             vars.tk->b_default = uint32( fdef );
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Default=%u", uint32( fdef ) );
+            debug( vars, "Track Default=%u", vars.tk->b_default );
         }
         E_CASE( KaxTrackFlagForced, ffor ) // UNUSED
         {
             vars.tk->b_forced = uint32( ffor );
 
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Forced=%u", uint32( ffor ) );
+            debug( vars, "Track Forced=%u", vars.tk->b_forced );
         }
         E_CASE( KaxTrackFlagLacing, lac ) // UNUSED
         {
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Lacing=%d", uint32( lac ) );
+            debug( vars, "Track Lacing=%d", uint32( lac ) ) ;
         }
         E_CASE( KaxTrackMinCache, cmin ) // UNUSED
         {
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track MinCache=%d", uint32( cmin ) );
+            debug( vars, "Track MinCache=%d", uint32( cmin ) ) ;
         }
         E_CASE( KaxTrackMaxCache, cmax ) // UNUSED
         {
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track MaxCache=%d", uint32( cmax ) );
+            debug( vars, "Track MaxCache=%d", uint32( cmax ) ) ;
         }
         E_CASE( KaxTrackDefaultDuration, defd )
         {
             vars.tk->i_default_duration = uint64(defd);
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Default Duration=%" PRId64, vars.tk->i_default_duration );
+            debug( vars, "Track Default Duration=%" PRId64, vars.tk->i_default_duration );
             vars.tk->i_default_duration /= 1000;
         }
         E_CASE( KaxTrackTimecodeScale, ttcs )
         {
             vars.tk->f_timecodescale = float( ttcs );
             if ( vars.tk->f_timecodescale <= 0 ) vars.tk->f_timecodescale = 1.0;
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track TimeCodeScale=%f", vars.tk->f_timecodescale );
+            debug( vars, "Track TimeCodeScale=%f", vars.tk->f_timecodescale ) ;
         }
         E_CASE( KaxMaxBlockAdditionID, mbl ) // UNUSED
         {
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Max BlockAdditionID=%d", uint32( mbl ) );
+            debug( vars, "Track Max BlockAdditionID=%d", uint32( mbl ) ) ;
         }
         E_CASE( KaxTrackName, tname )
         {
             vars.tk->fmt.psz_description = ToUTF8( UTFstring( tname ) );
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Name=%s", vars.tk->fmt.psz_description );
+            debug( vars, "Track Name=%s", vars.tk->fmt.psz_description ) ;
         }
         E_CASE( KaxTrackLanguage, lang )
         {
             free( vars.tk->fmt.psz_language );
             vars.tk->fmt.psz_language = strdup( std::string( lang ).c_str() );
-            msg_Dbg( vars.p_demuxer,
-                     "|   |   |   + Track Language=`%s'", vars.tk->fmt.psz_language );
+            debug( vars, "Track Language=`%s'", vars.tk->fmt.psz_language );
         }
         E_CASE( KaxCodecID, codecid )
         {
             vars.tk->psz_codec = strdup( std::string( codecid ).c_str() );
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track CodecId=%s", std::string( codecid ).c_str() );
+            debug( vars, "Track CodecId=%s", std::string( codecid ).c_str() ) ;
         }
         E_CASE( KaxCodecPrivate, cpriv )
         {
@@ -367,21 +373,21 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
                 vars.tk->p_extra_data = (uint8_t*)malloc( vars.tk->i_extra_data );
                 memcpy( vars.tk->p_extra_data, cpriv.GetBuffer(), vars.tk->i_extra_data );
             }
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track CodecPrivate size=%" PRId64, cpriv.GetSize() );
+            debug( vars, "Track CodecPrivate size=%" PRId64, cpriv.GetSize() );
         }
         E_CASE( KaxCodecName, cname )
         {
             vars.tk->psz_codec_name = ToUTF8( UTFstring( cname ) );
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Codec Name=%s", vars.tk->psz_codec_name );
+            debug( vars, "Track Codec Name=%s", vars.tk->psz_codec_name ) ;
         }
         //AttachmentLink
         E_CASE( KaxCodecDecodeAll, cdall ) // UNUSED
         {
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Codec Decode All=%u", uint8( cdall ) );
+            debug( vars, "Track Codec Decode All=%u", uint8( cdall ) ) ;
         }
         E_CASE( KaxTrackOverlay, tovr ) // UNUSED
         {
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Overlay=%u", uint32( tovr ) );
+            debug( vars, "Track Overlay=%u", uint32( tovr ) ) ;
         }
 #if LIBMATROSKA_VERSION >= 0x010401
         E_CASE( KaxCodecDelay, codecdelay )
@@ -393,12 +399,12 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
         E_CASE( KaxSeekPreRoll, spr )
         {
             vars.tk->i_seek_preroll = uint64_t(spr) / 1000;
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Seek Preroll =%" PRIu64, vars.tk->i_seek_preroll );
+            debug( vars, "Track Seek Preroll =%" PRIu64, vars.tk->i_seek_preroll );
         }
 #endif
         E_CASE( KaxContentEncodings, cencs )
         {
-            MkvTree( *vars.p_demuxer, 3, "Content Encodings" );
+            debug( vars, "Content Encodings" );
 
             if ( cencs.ListSize () > 1 )
             {
@@ -412,7 +418,7 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
         }
         E_CASE( KaxContentEncoding, cenc )
         {
-            MkvTree( *vars.p_demuxer, 4, "Content Encoding" );
+            debug( vars, "Content Encoding" );
 
             vars.level += 1;
             dispatcher.iterate( cenc.begin(), cenc.end(), Payload( vars ) );
@@ -420,20 +426,20 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
         }
         E_CASE( KaxContentEncodingOrder, encord )
         {
-            MkvTree( *vars.p_demuxer, 4, "Order: %i", uint32( encord ) );
+            debug( vars, "Order: %i", uint32( encord ) );
         }
         E_CASE( KaxContentEncodingScope, encscope )
         {
             vars.tk->i_encoding_scope = uint32( encscope );
-            MkvTree( *vars.p_demuxer, 4, "Scope: %i", uint32( encscope ) );
+            debug( vars, "Scope: %i", uint32( encscope ) );
         }
         E_CASE( KaxContentEncodingType, enctype )
         {
-            MkvTree( *vars.p_demuxer, 4, "Type: %i", uint32( enctype ) );
+            debug( vars, "Type: %i", uint32( enctype ) );
         }
         E_CASE( KaxContentCompression, compr )
         {
-            MkvTree( *vars.p_demuxer, 5, "Content Compression" );
+            debug( vars, "Content Compression" );
             //Default compression type is 0 (Zlib)
             vars.tk->i_compression_type = MATROSKA_COMPRESSION_ZLIB;
 
@@ -443,7 +449,7 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
         }
         E_CASE( KaxContentCompAlgo, compalg )
         {
-            MkvTree( *vars.p_demuxer, 6, "Compression Algorithm: %i", uint32(compalg) );
+            debug( vars, "Compression Algorithm: %i", uint32( compalg ) );
             vars.tk->i_compression_type = uint32( compalg );
             if ( ( vars.tk->i_compression_type != MATROSKA_COMPRESSION_ZLIB ) &&
                  ( vars.tk->i_compression_type != MATROSKA_COMPRESSION_HEADER ) )
@@ -458,11 +464,11 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
         }
         E_CASE( KaxTrackVideo, tkv )
         {
+            debug( vars, "Track Video");
+
             mkv_track_t *tk = vars.tk;
 
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Video" );
             tk->f_fps = 0.0;
-
             tk->fmt.video.i_frame_rate_base = (unsigned int)tk->i_default_duration;
             tk->fmt.video.i_frame_rate = 1000000;
 
@@ -500,72 +506,72 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
         }
         E_CASE( KaxVideoFlagInterlaced, fint ) // UNUSED
         {
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + Track Video Interlaced=%u", uint8( fint ) );
+            debug( vars, "Track Video Interlaced=%u", uint8( fint ) ) ;
         }
         E_CASE( KaxVideoStereoMode, stereo ) // UNUSED
         {
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + Track Video Stereo Mode=%u", uint8( stereo ) );
+            debug( vars, "Track Video Stereo Mode=%u", uint8( stereo ) ) ;
         }
         E_CASE( KaxVideoPixelWidth, vwidth )
         {
             vars.tk->fmt.video.i_width += uint16( vwidth );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + width=%d", uint16( vwidth ) );
+            debug( vars, "width=%d", uint16( vwidth ) ) ;
         }
         E_CASE( KaxVideoPixelHeight, vheight )
         {
             vars.tk->fmt.video.i_height += uint16( vheight );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + height=%d", uint16( vheight ) );
+            debug( vars, "height=%d", uint16( vheight ) ) ;
         }
         E_CASE( KaxVideoDisplayWidth, vwidth )
         {
             vars.track_video_info.i_display_width = uint16( vwidth );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + display width=%d", uint16( vwidth ) );
+            debug( vars, "display width=%d", uint16( vwidth ) ) ;
         }
         E_CASE( KaxVideoDisplayHeight, vheight )
         {
             vars.track_video_info.i_display_height = uint16( vheight );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + display height=%d", uint16( vheight ) );
+            debug( vars, "display height=%d", uint16( vheight ) ) ;
         }
         E_CASE( KaxVideoPixelCropBottom, cropval )
         {
             vars.track_video_info.i_crop_bottom = uint16( cropval );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + crop pixel bottom=%d", uint16( cropval ) );
+            debug( vars, "crop pixel bottom=%d", uint16( cropval ) ) ;
         }
         E_CASE( KaxVideoPixelCropTop, cropval )
         {
             vars.track_video_info.i_crop_top = uint16( cropval );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + crop pixel top=%d", uint16( cropval ) );
+            debug( vars, "crop pixel top=%d", uint16( cropval ) ) ;
         }
         E_CASE( KaxVideoPixelCropRight, cropval )
         {
             vars.track_video_info.i_crop_right = uint16( cropval );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + crop pixel right=%d", uint16( cropval ) );
+            debug( vars, "crop pixel right=%d", uint16( cropval ) ) ;
         }
         E_CASE( KaxVideoPixelCropLeft, cropval )
         {
             vars.track_video_info.i_crop_left = uint16( cropval );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + crop pixel left=%d", uint16( cropval ) );
+            debug( vars, "crop pixel left=%d", uint16( cropval ) ) ;
         }
         E_CASE( KaxVideoDisplayUnit, vdmode )
         {
             vars.track_video_info.i_display_unit = uint8( vdmode );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + Track Video Display Unit=%s",
-                     vars.track_video_info.i_display_unit == 0 ? "pixels" : ( vars.track_video_info.i_display_unit == 1 ? "centimeters": "inches" ) );
+            debug( vars, "Track Video Display Unit=%s",
+                vars.track_video_info.i_display_unit == 0 ? "pixels" : ( vars.track_video_info.i_display_unit == 1 ? "centimeters": "inches" ) );
         }
         E_CASE( KaxVideoAspectRatio, ratio ) // UNUSED
         {
-            msg_Dbg( vars.p_demuxer, "   |   |   |   + Track Video Aspect Ratio Type=%u", uint8( ratio ) );
+            debug( vars, "Track Video Aspect Ratio Type=%u", uint8( ratio ) ) ;
         }
         E_CASE( KaxVideoFrameRate, vfps )
         {
             vars.tk->f_fps = __MAX( float( vfps ), 1 );
-            msg_Dbg( vars.p_demuxer, "   |   |   |   + fps=%f", float( vfps ) );
+            debug( vars, "fps=%f", float( vfps ) ) ;
         }
         E_CASE( KaxTrackAudio, tka ) {
             vars.tk->fmt.audio.i_channels = 1;
             vars.tk->fmt.audio.i_rate = 8000;
 
-            msg_Dbg( vars.p_demuxer, "|   |   |   + Track Audio" );
+            debug( vars, "Track Audio");
 
             vars.level += 1;
             dispatcher.iterate( tka.begin(), tka.end(), Payload( vars ));
@@ -574,28 +580,28 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
         E_CASE( KaxAudioSamplingFreq, afreq )
         {
             vars.tk->i_original_rate = vars.tk->fmt.audio.i_rate = (int)float( afreq );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + afreq=%d", vars.tk->fmt.audio.i_rate );
+            debug( vars, "afreq=%d", vars.tk->fmt.audio.i_rate ) ;
         }
         E_CASE( KaxAudioOutputSamplingFreq, afreq )
         {
             vars.tk->fmt.audio.i_rate = (int)float( afreq );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + aoutfreq=%d", vars.tk->fmt.audio.i_rate );
+            debug( vars, "aoutfreq=%d", vars.tk->fmt.audio.i_rate ) ;
         }
         E_CASE( KaxAudioChannels, achan )
         {
             vars.tk->fmt.audio.i_channels = uint8( achan );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + achan=%u", uint8( achan ) );
+            debug( vars, "achan=%u", uint8( achan ) ) ;
         }
         E_CASE( KaxAudioBitDepth, abits )
         {
             vars.tk->fmt.audio.i_bitspersample = uint8( abits );
-            msg_Dbg( vars.p_demuxer, "|   |   |   |   + abits=%u", uint8( abits ) );
+            debug( vars, "abits=%u", uint8( abits ) ) ;
         }
         E_CASE ( EbmlVoid, ) {
           VLC_UNUSED( vars );
         }
         E_CASE_DEFAULT(element) {
-            MkvTree( *vars.p_demuxer, vars.level, "Unknown (%s)", typeid(element).name() );
+            debug( vars, "Unknown (%s)", typeid(element).name() );
         }
     };
 
@@ -672,7 +678,7 @@ void matroska_segment_c::ParseTracks( KaxTracks *tracks )
             VLC_UNUSED( vars );
         }
         E_CASE_DEFAULT(element) {
-            msg_Dbg( vars.p_demuxer, "|   |   + Unknown (%s)", typeid(element).name() );
+            MkvTree( *vars.p_demuxer, 2, "Unknown (%s)", typeid(element).name() );
         }
     };
 
-- 
2.7.2



More information about the vlc-devel mailing list