Commit 15d01e60 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Backend: Add a log handling

parent 24b0958f
......@@ -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();
......
......@@ -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 );
}
......@@ -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
......
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