[vlc-devel] [PATCH] access: vnc: use thread specific var to redirect logging
Francois Cartegnie
fcvlcdev at free.fr
Sat Mar 23 15:19:25 CET 2013
---
modules/access/vnc.c | 44 +++++++++++++++++++++++++++++++++++++++++---
1 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/modules/access/vnc.c b/modules/access/vnc.c
index 30f3e17..24a5942 100644
--- a/modules/access/vnc.c
+++ b/modules/access/vnc.c
@@ -118,6 +118,8 @@ struct demux_sys_t
es_out_id_t *es;
};
+static vlc_threadvar_t log_object_var; /* logger local data */
+
static void *DemuxThread( void *p_data );
/*****************************************************************************
@@ -262,6 +264,35 @@ static rfbCredential* getCredentialHandler( rfbClient *p_client, int i_credentia
return credential;
}
+inline void logThroughLibVLC( const char *psz_format, va_list args, int i_error )
+{
+ vlc_object_t *p_obj = (vlc_object_t * ) vlc_threadvar_get( log_object_var );
+ char *psz_text;
+ int i_ret = vasprintf( &psz_text, psz_format, args );
+ if ( unlikely( i_ret == -1 ) ) return;
+ if ( i_error )
+ msg_Err( p_obj, "%s", psz_text );
+ else
+ msg_Dbg( p_obj, "%s", psz_text );
+ free( psz_text );
+}
+
+static void errLogHandler( const char *psz_format, ... )
+{
+ va_list args;
+ va_start( args, psz_format );
+ logThroughLibVLC( psz_format, args, true );
+ va_end( args );
+}
+
+static void logHandler( const char *psz_format, ... )
+{
+ va_list args;
+ va_start( args, psz_format );
+ logThroughLibVLC( psz_format, args, false );
+ va_end( args );
+}
+
/*****************************************************************************
* Control:
*****************************************************************************/
@@ -330,6 +361,9 @@ static void *DemuxThread( void *p_data )
mtime_t i_next_frame_date = mdate() + p_sys->i_frame_interval;
int i_status;
+ if ( rfbEnableClientLogging )
+ vlc_threadvar_set( log_object_var, p_demux );
+
for(;;)
{
p_sys->i_cancel_state = vlc_savecancel();
@@ -403,9 +437,7 @@ static int Open( vlc_object_t *p_this )
return VLC_EGENERIC;
}
-#ifdef NDEBUG
- rfbEnableClientLogging = FALSE;
-#endif
+ rfbEnableClientLogging = !vlc_threadvar_create( &log_object_var, NULL );
p_sys->p_client = rfbGetClient( p_chroma_desc->pixel_bits / 3, // bitsPerSample
3, // samplesPerPixel
@@ -465,6 +497,12 @@ static int Open( vlc_object_t *p_this )
p_sys->i_starttime = mdate();
+ if ( rfbEnableClientLogging )
+ {
+ rfbClientLog = logHandler;
+ rfbClientErr = errLogHandler;
+ }
+
if ( vlc_clone( &p_sys->thread, DemuxThread, p_demux, VLC_THREAD_PRIORITY_INPUT ) != VLC_SUCCESS )
{
msg_Err( p_demux, "can't spawn thread" );
--
1.7.9
More information about the vlc-devel
mailing list