Commit 1856ddb7 authored by Clément Stenac's avatar Clément Stenac

Add ability to prepend headers to messages (object-specific) and use it for VLM media (Closes:#496)

To use it, put a string in p_object->psz_header, all messages from this object and its parent will have the header prepended
parent b9304629
......@@ -471,6 +471,9 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's object */
char *psz_object_type; \
char *psz_object_name; \
\
/* Messages header */ \
char *psz_header; \
\
/* Thread properties, if any */ \
vlc_bool_t b_thread; \
vlc_thread_t thread_id; \
......
......@@ -415,6 +415,8 @@ struct input_thread_t
*****************************************************************************/
#define input_CreateThread(a,b) __input_CreateThread(VLC_OBJECT(a),b)
VLC_EXPORT( input_thread_t *, __input_CreateThread, ( vlc_object_t *, input_item_t * ) );
#define input_CreateThread2(a,b,c) __input_CreateThread2(VLC_OBJECT(a),b,c)
VLC_EXPORT( input_thread_t *, __input_CreateThread2, ( vlc_object_t *, input_item_t *, char * ) );
#define input_Preparse(a,b) __input_Preparse(VLC_OBJECT(a),b)
VLC_EXPORT( int, __input_Preparse, ( vlc_object_t *, input_item_t * ) );
......
......@@ -47,7 +47,8 @@ typedef struct
int i_object_id;
int i_object_type;
char * psz_module;
char * psz_msg; /**< the message itself */
char * psz_msg; /**< the message itself */
char * psz_header; /**< Additional header */
mtime_t date; /**< Message date */
} msg_item_t;
......
......@@ -21,6 +21,7 @@ char * config_GetHomeDir (void);
int playlist_ItemDelete (playlist_item_t *);
osd_state_t * __osd_StateChange (osd_state_t *, const int);
int vlm_ScheduleSetup (vlm_schedule_t *, const char *, const char *);
input_thread_t * __input_CreateThread2 (vlc_object_t *, input_item_t *, char *);
vlc_acl_t * __ACL_Duplicate (vlc_object_t *p_this, const vlc_acl_t *p_acl);
int osd_Slider (vlc_object_t *, spu_t *, int, int, int, int, short);
int playlist_ServicesDiscoveryRemove (playlist_t *, const char *);
......@@ -883,6 +884,7 @@ struct module_symbols_t
void (*stats_DumpInputStats_inner) (input_stats_t *);
void (*stats_ReinitInputStats_inner) (input_stats_t *);
counter_t* (*__stats_CounterGet_inner) (vlc_object_t*, int, char *);
input_thread_t * (*__input_CreateThread2_inner) (vlc_object_t *, input_item_t *, char *);
};
# if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
......@@ -1310,6 +1312,7 @@ struct module_symbols_t
# define stats_DumpInputStats (p_symbols)->stats_DumpInputStats_inner
# define stats_ReinitInputStats (p_symbols)->stats_ReinitInputStats_inner
# define __stats_CounterGet (p_symbols)->__stats_CounterGet_inner
# define __input_CreateThread2 (p_symbols)->__input_CreateThread2_inner
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
......@@ -1740,6 +1743,7 @@ struct module_symbols_t
((p_symbols)->stats_DumpInputStats_inner) = stats_DumpInputStats; \
((p_symbols)->stats_ReinitInputStats_inner) = stats_ReinitInputStats; \
((p_symbols)->__stats_CounterGet_inner) = __stats_CounterGet; \
((p_symbols)->__input_CreateThread2_inner) = __input_CreateThread2; \
(p_symbols)->net_ConvertIPv4_deprecated = NULL; \
# endif /* __PLUGIN__ */
......
......@@ -46,7 +46,8 @@
static int Run ( input_thread_t *p_input );
static int RunAndClean ( input_thread_t *p_input );
static input_thread_t * Create ( vlc_object_t *, input_item_t *, vlc_bool_t );
static input_thread_t * Create ( vlc_object_t *, input_item_t *, char *,
vlc_bool_t );
static int Init ( input_thread_t *p_input, vlc_bool_t b_quick );
static void Error ( input_thread_t *p_input );
static void End ( input_thread_t *p_input );
......@@ -104,7 +105,7 @@ static vlc_meta_t *InputMetaUser( input_thread_t *p_input );
* TODO complete this list (?)
*****************************************************************************/
static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
vlc_bool_t b_quick )
char *psz_header, vlc_bool_t b_quick )
{
input_thread_t *p_input; /* thread descriptor */
vlc_value_t val;
......@@ -117,6 +118,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
msg_Err( p_parent, "out of memory" );
return NULL;
}
p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
/* Init Common fields */
p_input->b_eof = VLC_FALSE;
......@@ -239,11 +241,19 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
*/
input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
input_item_t *p_item )
{
__input_CreateThread2( p_parent, p_item, NULL );
}
/* Gruik ! */
input_thread_t *__input_CreateThread2( vlc_object_t *p_parent,
input_item_t *p_item,
char *psz_header )
{
input_thread_t *p_input; /* thread descriptor */
p_input = Create( p_parent, p_item, VLC_FALSE );
p_input = Create( p_parent, p_item, psz_header, VLC_FALSE );
/* Now we can attach our new input */
vlc_object_attach( p_input, p_parent );
......@@ -275,7 +285,7 @@ int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
{
input_thread_t *p_input; /* thread descriptor */
p_input = Create( p_parent, p_item, VLC_FALSE );
p_input = Create( p_parent, p_item, NULL, VLC_FALSE );
/* Now we can attach our new input */
vlc_object_attach( p_input, p_parent );
......@@ -311,7 +321,7 @@ int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
input_thread_t *p_input; /* thread descriptor */
/* Allocate descriptor */
p_input = Create( p_parent, p_item, VLC_TRUE );
p_input = Create( p_parent, p_item, NULL, VLC_TRUE );
/* Now we can attach our new input */
vlc_object_attach( p_input, p_parent );
......
......@@ -292,9 +292,12 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
const char *psz_module,
const char *psz_format, va_list _args )
{
int i_header_size; /* Size of the additionnal header */
vlc_object_t *p_obj;
msg_bank_t * p_bank = &p_this->p_libvlc->msg_bank; /* message bank */
msg_queue_t *p_queue = NULL;
char * psz_str = NULL; /* formatted message string */
char * psz_header = NULL;
va_list args;
msg_item_t * p_item = NULL; /* pointer to message */
msg_item_t item; /* message in case of a full queue */
......@@ -326,6 +329,33 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
return;
}
i_header_size = 0;
p_obj = p_this;
while( p_obj != NULL )
{
char *psz_old = NULL;
if( p_obj == NULL ) break;
if( p_obj->psz_header )
{
i_header_size += strlen( p_obj->psz_header ) + 4;
if( psz_header )
{
psz_old = strdup( psz_header );
psz_header = (char*)realloc( psz_header, i_header_size );
snprintf( psz_header, i_header_size , "[%s] %s",
p_obj->psz_header, psz_old );
}
else
{
psz_header = (char *)malloc( i_header_size );
snprintf( psz_header, i_header_size, "[%s]",
p_obj->psz_header );
}
}
if( psz_old ) free( psz_old );
p_obj = p_obj->p_parent;
}
#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
vlc_va_copy( args, _args );
vsnprintf( psz_str, i_size, psz_format, args );
......@@ -386,6 +416,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
p_item->i_object_type = p_this->i_object_type;
p_item->psz_module = strdup( "message" );
p_item->psz_msg = strdup( "message queue overflowed" );
p_item->psz_header = NULL;
PrintMsg( p_this, p_item );
/* We print from a dummy item */
......@@ -407,6 +438,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
p_item->i_object_type = p_this->i_object_type;
p_item->psz_module = strdup( psz_module );
p_item->psz_msg = psz_str;
p_item->psz_header = psz_header;
if( p_queue->i_id == MSG_QUEUE_NORMAL )
PrintMsg( p_this, p_item );
......@@ -546,16 +578,37 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
/* Send the message to stderr */
if( p_this->p_libvlc->b_color )
{
fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
if( p_item->psz_header )
{
fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s %s%s: %s%s" GRAY
"\n",
p_item->i_object_id, p_item->psz_header,
p_item->psz_module, psz_object,
ppsz_type[i_type], ppsz_color[i_type],
p_item->psz_msg );
}
else
{
fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
p_item->i_object_id, p_item->psz_module, psz_object,
ppsz_type[i_type], ppsz_color[i_type],
p_item->psz_msg );
}
}
else
{
fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
if( p_item->psz_header )
{
fprintf( stderr, "[%.8i] %s %s %s%s: %s\n", p_item->i_object_id,
p_item->psz_header, p_item->psz_module,
psz_object, ppsz_type[i_type], p_item->psz_msg );
}
else
{
fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
p_item->psz_module, psz_object, ppsz_type[i_type],
p_item->psz_msg );
}
}
# if defined(WIN32)
......
......@@ -248,6 +248,8 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
p_new->b_attached = VLC_FALSE;
p_new->b_force = VLC_FALSE;
p_new->psz_header = NULL;
p_new->i_vars = 0;
p_new->p_vars = (variable_t *)malloc( 16 * sizeof( variable_t ) );
......
......@@ -1068,6 +1068,7 @@ int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, const char *psz_cmd,
/* Pre-parse the input */
input_thread_t *p_input;
char *psz_output;
char *psz_header;
int i;
vlc_input_item_Clean( &media->item );
......@@ -1092,7 +1093,10 @@ int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, const char *psz_cmd,
strdup( media->option[i] );
}
if( (p_input = input_CreateThread( vlm, &media->item ) ) )
asprintf( &psz_header, _("Media: %s"), media->psz_name );
if( (p_input = input_CreateThread2( vlm, &media->item, psz_header
) ) )
{
while( !p_input->b_eof && !p_input->b_error ) msleep( 100000 );
......@@ -1137,6 +1141,7 @@ int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, const char *psz_id,
{
vlm_media_instance_t *p_instance;
int i;
char *psz_header;
p_instance = vlm_MediaInstanceSearch( vlm, media, psz_id );
......@@ -1194,7 +1199,9 @@ int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, const char *psz_id,
vlc_object_destroy( p_instance->p_input );
}
p_instance->p_input = input_CreateThread( vlm, &p_instance->item );
asprintf( &psz_header, _("Media: %s"), media->psz_name );
p_instance->p_input = input_CreateThread2( vlm, &p_instance->item,
psz_header );
if( !p_instance->p_input )
{
TAB_REMOVE( media->i_instance, media->instance, p_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