[vlc-devel] [PATCH 20/20] mkv: Reimplemented MkvTree and moved it to `Util.hpp`

Denis Charmet typx at dinauz.org
Mon Mar 7 11:05:17 CET 2016


Hi,

On 2016-03-04 17:04, Filip Roséen wrote:
> +void MkvTree_va( demux_t& demuxer, int i_level, const char* fmt, 
> va_list args)
> +{
> +    static char const * indent = "|    ";
> +    static char const * prefix = "+ ";
> +    static int  const   indent_len = strlen( indent );
> +    static int  const   prefix_len = strlen( prefix );
> +
> +    char   fixed_buffer[256] = {};
> +    size_t const  static_len = sizeof( fixed_buffer );
> +    char *            buffer = fixed_buffer;
> +    size_t         total_len = indent_len * i_level + prefix_len +
> strlen( fmt );
> +
> +    if( total_len >= static_len ) {
> +        buffer = new (std::nothrow) char[total_len] ();
> +
> +        if (buffer == NULL) {
> +            msg_Err (&demuxer, "Unable to allocate memory for format 
> string");
> +            return;
> +        }
> +    }

Since you're cpping everything why not using std::string? :)

> +
> +    char * dst = buffer;
> +
> +    for (int i = 0; i < i_level; ++i, dst += indent_len)
> +        memcpy( dst, indent, indent_len );
> +
> +    strcat( dst, prefix );
> +    strcat( dst, fmt );
> +
> +    msg_GenericVa( &demuxer, VLC_MSG_DBG, buffer, args );
> +
> +    if (buffer != fixed_buffer)
> +        delete [] buffer;
> +}
> +
> +void MkvTree( demux_t & demuxer, int i_level, const char *psz_format, 
> ... )
> +{
> +    va_list args; va_start( args, psz_format );
> +    MkvTree_va( demuxer, i_level, psz_format, args );
> +    va_end( args );
> +}
> diff --git a/modules/demux/mkv/util.hpp b/modules/demux/mkv/util.hpp
> index 8c6cc6a..5867d1d 100644
> --- a/modules/demux/mkv/util.hpp
> +++ b/modules/demux/mkv/util.hpp
> @@ -90,3 +90,7 @@ public:
>  };
> 
>  block_t * packetize_wavpack( mkv_track_t *, uint8_t *, size_t);
> +
> +/* helper functions to print the mkv parse tree */
> +void MkvTree_va( demux_t& demuxer, int i_level, const char* fmt, 
> va_list args);
> +void MkvTree( demux_t & demuxer, int i_level, const char *psz_format, 
> ... );

Regards,
-- 
Denis Charmet - TypX
Le mauvais esprit est un art de vivre


More information about the vlc-devel mailing list