[vlmc-devel] Backend: Add a log handling

Hugo Beauzée-Luyssen git at videolan.org
Fri Feb 28 20:14:02 CET 2014


vlmc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Feb 28 21:03:11 2014 +0200| [15d01e60ec95c1761cd3caad7714d591739be1aa] | committer: Hugo Beauzée-Luyssen

Backend: Add a log handling

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=15d01e60ec95c1761cd3caad7714d591739be1aa
---

 src/Backend/IBackend.h         |   14 ++++++++++++--
 src/Backend/VLC/VLCBackend.cpp |   34 ++++++++++++++++++++++------------
 src/Backend/VLC/VLCBackend.h   |    5 ++++-
 3 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/src/Backend/IBackend.h b/src/Backend/IBackend.h
index bd19695..f0ef534 100644
--- a/src/Backend/IBackend.h
+++ b/src/Backend/IBackend.h
@@ -35,9 +35,19 @@ class IMemorySource;
 class IBackend
 {
     public:
+        enum LogLevel
+        {
+            Debug,
+            Warning,
+            Error,
+            None
+        };
+        typedef void        (*LogHandler)( void* data, LogLevel logLevel, const char* msg);
+
         virtual ~IBackend() {}
-        virtual ISource* createSource( const char* path ) = 0;
-        virtual IMemorySource* createMemorySource() = 0;
+        virtual ISource*        createSource( const char* path ) = 0;
+        virtual IMemorySource*  createMemorySource() = 0;
+        virtual void            setLogHandler( void* data, LogHandler logHandler) = 0;
 };
 
 extern IBackend* getBackend();
diff --git a/src/Backend/VLC/VLCBackend.cpp b/src/Backend/VLC/VLCBackend.cpp
index 5a70da2..ac50e24 100644
--- a/src/Backend/VLC/VLCBackend.cpp
+++ b/src/Backend/VLC/VLCBackend.cpp
@@ -38,6 +38,8 @@ IBackend *Backend::getBackend()
 }
 
 VLCBackend::VLCBackend()
+    : m_logHandler( NULL )
+    , m_logHandlerData( NULL )
 {
     QVector<const char*> argv;
     argv << "--no-skip-frames"
@@ -48,13 +50,8 @@ VLCBackend::VLCBackend()
         // << "--no-overlay",
         << "--no-disable-screensaver";             //No need to disable the screensaver, and save a thread.
 
-    int     debugLevel = VLMC_GET_INT( "private/VlcLogLevel" );
-    if ( debugLevel == VlmcLogger::Debug )
-        argv << "-vv";
-    else if ( debugLevel == VlmcLogger::Verbose )
-        argv << "-v";
     m_vlcInstance = new LibVLCpp::Instance( argv.count(), &argv.front() );
-    m_vlcInstance->setLogHook( this, &logHook );
+    assert( m_vlcInstance != NULL );
 }
 
 ISource*
@@ -69,6 +66,15 @@ VLCBackend::createMemorySource()
     return new VLCMemorySource( this );
 }
 
+void
+VLCBackend::setLogHandler(void *data, IBackend::LogHandler logHandler)
+{
+    m_vlcInstance->unsetLogHook();
+    m_logHandlerData = data;
+    m_logHandler = logHandler;
+    m_vlcInstance->setLogHook( this, &logHook );
+}
+
 LibVLCpp::Instance*
 VLCBackend::vlcInstance()
 {
@@ -76,24 +82,28 @@ VLCBackend::vlcInstance()
 }
 
 void
-VLCBackend::logHook(void *data, int level, const libvlc_log_t *ctx, const char *fmt, va_list args)
+VLCBackend::logHook( void *data, int level, const libvlc_log_t *ctx, const char *fmt, va_list args )
 {
-    Q_UNUSED( data )
     Q_UNUSED( ctx )
 
+    VLCBackend* self = reinterpret_cast<VLCBackend*>( data );
+
+    if ( !self->m_logHandler )
+        return ;
+
     char* msg;
     if (vasprintf( &msg, fmt, args ) < 0 )
         return;
     if ( level <= LIBVLC_NOTICE )
-        vlmcDebug() << "[VLC]" << msg;
+        self->m_logHandler( self->m_logHandlerData, Debug, msg );
     else if ( level == LIBVLC_WARNING )
-        vlmcWarning() << "[VLC]" << msg;
+        self->m_logHandler( self->m_logHandlerData, Warning, msg );
     else if ( level == LIBVLC_ERROR )
-        vlmcCritical() << "[VLC]" << msg;
+        self->m_logHandler( self->m_logHandlerData, Error, msg );
     else
     {
         vlmcCritical() << "Unexpected logging level for VLC log" << level;
-        vlmcCritical() << "[VLC]" << msg;
+        vlmcCritical() << "VLCBackend:" << msg;
     }
     free( msg );
 }
diff --git a/src/Backend/VLC/VLCBackend.h b/src/Backend/VLC/VLCBackend.h
index c42906b..13bc3ec 100644
--- a/src/Backend/VLC/VLCBackend.h
+++ b/src/Backend/VLC/VLCBackend.h
@@ -40,6 +40,7 @@ class VLCBackend : public IBackend, public Singleton<VLCBackend>
         VLCBackend();
         virtual ISource*        createSource( const char* path );
         virtual IMemorySource*  createMemorySource();
+        virtual void            setLogHandler( void* data, LogHandler logHandler );
 
         // Accessible from VLCBackend only:
         LibVLCpp::Instance* vlcInstance();
@@ -50,8 +51,10 @@ class VLCBackend : public IBackend, public Singleton<VLCBackend>
 
     private:
         friend class Singleton<VLCBackend>;
-        LibVLCpp::Instance* m_vlcInstance;
 
+        LibVLCpp::Instance*         m_vlcInstance;
+        LogHandler                  m_logHandler;
+        void*                       m_logHandlerData;
 };
 
 } //VLC



More information about the Vlmc-devel mailing list