Commit 709389e3 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

VLCInstance: Hook to VLC's logs to aggregate them in vlmc's logfile

parent b525645f
......@@ -25,9 +25,12 @@
#include "SettingsManager.h"
#include "VlmcLogger.h"
#include "VlmcDebug.h"
#include <QVector>
#include <cstdio>
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 );
}
......@@ -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<Instance>;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment