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