diff --git a/src/LibVLCpp/VLCInstance.cpp b/src/LibVLCpp/VLCInstance.cpp index 86ccecb34195f39f89313b08866caf22324d5469..5cfb7e2ac2fcd60b90c4a65d14d003532cf8ffe5 100644 --- a/src/LibVLCpp/VLCInstance.cpp +++ b/src/LibVLCpp/VLCInstance.cpp @@ -25,9 +25,12 @@ #include "SettingsManager.h" #include "VlmcLogger.h" +#include "VlmcDebug.h" #include +#include + using namespace LibVLCpp; Instance::Instance( QObject* parent /*= NULL*/ ) : QObject( parent ) @@ -48,6 +51,7 @@ Instance::Instance( QObject* parent /*= NULL*/ ) : QObject( parent ) argv << "-v"; m_internalPtr = libvlc_new( argv.count(), &argv.front() ); + libvlc_log_set( *this, vlcLogHook, this ); Q_ASSERT_X( m_internalPtr != NULL, "LibVLCpp::Instance::Instance()", "Can't launch VLMC without a valid LibVLC instance. Please check your VLC installation" ); } @@ -56,3 +60,25 @@ Instance::~Instance() { libvlc_release( m_internalPtr ); } + +void Instance::vlcLogHook(void *data, int level, const libvlc_log_t *ctx, const char *fmt, va_list args) +{ + Q_UNUSED( data ) + Q_UNUSED( ctx ) + + char* msg; + if (vasprintf( &msg, fmt, args ) < 0 ) + return; + if ( level <= LIBVLC_NOTICE ) + vlmcDebug() << "[VLC]" << msg; + else if ( level == LIBVLC_WARNING ) + vlmcWarning() << "[VLC]" << msg; + else if ( level == LIBVLC_ERROR ) + vlmcCritical() << "[VLC]" << msg; + else + { + vlmcCritical() << "Unexpected logging level for VLC log" << level; + vlmcCritical() << "[VLC]" << msg; + } + free( msg ); +} diff --git a/src/LibVLCpp/VLCInstance.h b/src/LibVLCpp/VLCInstance.h index 8c6afa43a9065d78ff2715f682e4d97247afdb7b..84eae57625e04e44eecc6c4132ffc0b021368f82 100644 --- a/src/LibVLCpp/VLCInstance.h +++ b/src/LibVLCpp/VLCInstance.h @@ -43,9 +43,10 @@ namespace LibVLCpp private: Instance( QObject* parent = NULL ); Instance( int argc, const char** argv ); - ~Instance(); + static void vlcLogHook( void* data, int level, const libvlc_log_t* ctx, const char* fmt, va_list args ); + private: friend class Singleton; };