[vlmc-devel] [PATCH] MLTBackend: Add MLT service info in logHandler

Hugo Beauzée-Luyssen hugo at beauzee.fr
Fri Jul 29 15:05:21 CEST 2016


On 07/29/2016 02:55 PM, yikei lu wrote:
> 2016-07-29 21:38 GMT+09:00 Pawel Golinski <golpaw1 at gmail.com>:
>> ---
>>  src/Backend/MLT/MLTBackend.cpp | 28 ++++++++++++++++++++++++++--
>>  1 file changed, 26 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/Backend/MLT/MLTBackend.cpp b/src/Backend/MLT/MLTBackend.cpp
>> index 3d39930..5f407b0 100644
>> --- a/src/Backend/MLT/MLTBackend.cpp
>> +++ b/src/Backend/MLT/MLTBackend.cpp
>> @@ -28,6 +28,7 @@
>>  #include <mlt++/MltRepository.h>
>>
>>  #include <mlt/framework/mlt_log.h>
>> +#include <mlt/framework/mlt_service.h>
>>
>>  #include "MLTFilter.h"
>>
>> @@ -101,8 +102,22 @@ void
>>  MLTBackend::setLogHandler( IBackend::LogHandler logHandler )
>>  {
>>      staticLogHandler = logHandler;
>> -    mlt_log_set_callback( []( void*, int level, const char* format, va_list vl )
>> +    mlt_log_set_callback( []( void* ptr, int level, const char* format, va_list vl )
>>      {
>> +        char* prefix_buffer = nullptr;
>> +
>> +        mlt_properties properties = ptr ? MLT_SERVICE_PROPERTIES( ( mlt_service )ptr ) : NULL;
>
> Mlt::Properties( ( mlt_service )ptr ) properties?
>
>> +
>> +        if ( properties )
>
> If you use Mlt::Properties, please check it with is_valid.
> Mlt::Properties will never be nullptr.
>
>> +        {
>> +            char *mlt_type = mlt_properties_get( properties, "mlt_type" );
>> +            char *mlt_service = mlt_properties_get( properties, "mlt_service" );
>> +            if ( mlt_service )
>> +                asprintf( &prefix_buffer, "[%s %s] ", mlt_type, mlt_service );
>> +            else
>> +                asprintf( &prefix_buffer, "[%s %p] ", mlt_type, ptr );

Using *printf with a nullptr is undefined, however I think if you apply 
the modification suggested by Yikei your pointer won't be null anymore.

>> +        }
>> +
>>          char* buffer = nullptr;
>>
>>          auto lvl = IBackend::None;
>> @@ -118,7 +133,16 @@ MLTBackend::setLogHandler( IBackend::LogHandler logHandler )
>>          if ( vasprintf( &buffer, format, vl ) < 0 )
>>              return;
>>
>> -        staticLogHandler( lvl, buffer );
>> +        std::string prefix_buffer_str;
>> +        std::string buffer_str;
>> +        if ( prefix_buffer )
>> +            prefix_buffer_str = prefix_buffer;
>> +        if ( buffer )
>> +            buffer_str = buffer;
>> +        std::string msg_str = prefix_buffer_str + buffer_str;
>> +
>> +        staticLogHandler( lvl, msg_str.c_str() );
>> +        free( prefix_buffer );
>
> if you use std::string and not being created by new or malloc ( not
> using heap memory ), you don't have to free/delete.
> Also, You can actually do something like std::string( "something" ) +
> "anything", which means you can do std::string + c string;
>

Provided the C string isn't nullptr, though

> And thanks for your patch :)
>
> Regards,
>
>>          free( buffer );
>>      } );
>>  }
>> --
>> 2.7.4 (Apple Git-66)
>>
>> _______________________________________________
>> Vlmc-devel mailing list
>> Vlmc-devel at videolan.org
>> https://mailman.videolan.org/listinfo/vlmc-devel
> _______________________________________________
> Vlmc-devel mailing list
> Vlmc-devel at videolan.org
> https://mailman.videolan.org/listinfo/vlmc-devel
>



More information about the Vlmc-devel mailing list