[vlmc-devel] [PATCH] MLTBackend: Add MLT service info in logHandler
yikei lu
luyikei.qmltu at gmail.com
Fri Jul 29 13:37:06 CEST 2016
2016-07-29 20:27 GMT+09:00 Pawel Golinski <golpaw1 at gmail.com>:
> ---
> src/Backend/MLT/MLTBackend.cpp | 31 ++++++++++++++++++++++++++++++-
> 1 file changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/src/Backend/MLT/MLTBackend.cpp b/src/Backend/MLT/MLTBackend.cpp
> index 3d39930..62bfc9a 100644
> --- a/src/Backend/MLT/MLTBackend.cpp
> +++ b/src/Backend/MLT/MLTBackend.cpp
> @@ -28,10 +28,13 @@
> #include <mlt++/MltRepository.h>
>
> #include <mlt/framework/mlt_log.h>
> +#include <mlt/framework/mlt_service.h>
> +#include <mlt/framework/mlt_properties.h>
I'm already including mlt++/MltProperties.h, and you should use mlt++
as much as possible.
>
> #include "MLTFilter.h"
>
> #include <mutex>
> +#include <cstring>
>
> #include "Tools/VlmcDebug.h"
> #include "vlmc.h"
> @@ -101,8 +104,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;
> +
> + if ( properties )
> + {
> + 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 );
> + }
> +
> char* buffer = nullptr;
>
> auto lvl = IBackend::None;
> @@ -118,6 +135,18 @@ MLTBackend::setLogHandler( IBackend::LogHandler logHandler )
> if ( vasprintf( &buffer, format, vl ) < 0 )
> return;
>
> + if ( prefix_buffer )
> + {
> + size_t msg_size = strlen( prefix_buffer ) + strlen( buffer ) + 1;
> + prefix_buffer = ( char* )realloc( prefix_buffer, msg_size * sizeof( char ) );
It's c++, and you are allowed to use std::string :)
> + if ( prefix_buffer != NULL )
> + {
> + strcat( prefix_buffer, buffer );
> + free( buffer );
> + buffer = prefix_buffer;
> + }
> + }
> +
> staticLogHandler( lvl, buffer );
> free( buffer );
> } );
> --
> 2.7.4 (Apple Git-66)
>
> _______________________________________________
> Vlmc-devel mailing list
> Vlmc-devel at videolan.org
> https://mailman.videolan.org/listinfo/vlmc-devel
More information about the Vlmc-devel
mailing list