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

Pawel Golinski git at videolan.org
Mon Aug 1 11:40:47 CEST 2016


vlmc | branch: master | Pawel Golinski <golpaw1 at gmail.com> | Sun Jul 31 17:48:21 2016 +0200| [ca377a2d331fe09ee19b7fca1962f74d7770693f] | committer: Yikai Lu

MLTBackend: Add MLT service info in logHandler

Signed-off-by: Yikai Lu <luyikei.qmltu at gmail.com>

> https://code.videolan.org/videolan/vlmc/commit/ca377a2d331fe09ee19b7fca1962f74d7770693f
---

 src/Backend/MLT/MLTBackend.cpp | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/Backend/MLT/MLTBackend.cpp b/src/Backend/MLT/MLTBackend.cpp
index 3d39930..871c9cd 100644
--- a/src/Backend/MLT/MLTBackend.cpp
+++ b/src/Backend/MLT/MLTBackend.cpp
@@ -26,12 +26,14 @@
 #include <mlt++/MltFactory.h>
 #include <mlt++/MltProperties.h>
 #include <mlt++/MltRepository.h>
+#include <mlt++/MltService.h>
 
 #include <mlt/framework/mlt_log.h>
 
 #include "MLTFilter.h"
 
 #include <mutex>
+#include <sstream>
 
 #include "Tools/VlmcDebug.h"
 #include "vlmc.h"
@@ -101,8 +103,28 @@ 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 )
     {
+        std::string msg_str;
+
+        Mlt::Service service( ( mlt_service )ptr );
+
+        if ( service.is_valid() )
+        {
+            const char *mlt_type = service.get( "mlt_type" );
+            const char *mlt_service = service.get( "mlt_service" );
+            std::ostringstream os;
+
+            if ( mlt_service && mlt_type )
+                os << "[" << mlt_type << " " << mlt_service << "] ";
+            else if ( mlt_type )
+            {
+                os << "[" << mlt_type << " " << ptr << "] ";
+            }
+
+            msg_str = os.str();
+        }
+
         char* buffer = nullptr;
 
         auto lvl = IBackend::None;
@@ -118,7 +140,12 @@ MLTBackend::setLogHandler( IBackend::LogHandler logHandler )
         if ( vasprintf( &buffer, format, vl ) < 0 )
             return;
 
-        staticLogHandler( lvl, buffer );
+        if ( buffer )
+            msg_str += buffer;
+
+        if ( !msg_str.empty() )
+            staticLogHandler( lvl, msg_str.c_str() );
+
         free( buffer );
     } );
 }



More information about the Vlmc-devel mailing list