vlc_bool_t b_fixed_name; /**< Can the interface change the name ?*/
+ input_stats_t *p_stats; /**< Statistics */
+
vlc_mutex_t lock; /**< Item cannot be changed without this lock */
};
p_i->es = 0;
p_i->i_type = ITEM_TYPE_UNKNOWN;
p_i->b_fixed_name = VLC_TRUE;
+
+ p_i->p_stats = (input_stats_t*) malloc( sizeof( input_stats_t ) );
+ vlc_mutex_init( p_o, &p_i->p_stats->lock );
+
vlc_mutex_init( p_o, &p_i->lock );
}
*****************************************************************************/
#include <stdarg.h>
+
+int vlc_mutex_lock( vlc_mutex_t * ) ;
+int vlc_mutex_unlock( vlc_mutex_t * ) ;
+
/**
* \defgroup messages Messages
* This library provides basic functions for threads to interact with user
VLC_EXPORT( int, __stats_Update, (vlc_object_t*, char *, vlc_value_t) );
#define stats_Create( a,b,c,d ) __stats_Create( VLC_OBJECT(a), b, c, d )
VLC_EXPORT( int, __stats_Create, (vlc_object_t*, char *, int, int) );
+#define stats_Get( a,b,c,d ) __stats_Create( VLC_OBJECT(a), b, c, d )
+VLC_EXPORT( int, __stats_Get, (vlc_object_t*, int, char *, vlc_value_t*) );
+
+#define stats_GetInteger( a,b,c,d ) __stats_GetInteger( VLC_OBJECT(a), b, c, d )
+static inline int __stats_GetInteger( vlc_object_t *p_obj, int i_id,
+ char *psz_name, int *value )
+{
+ vlc_value_t val;
+ int i_ret = __stats_Get( p_obj, i_id, psz_name, &val );
+ *value = val.i_int;
+ return i_ret;
+}
+#define stats_UpdateInteger( a,b,c ) __stats_UpdateInteger( VLC_OBJECT(a),b,c )
static inline int __stats_UpdateInteger( vlc_object_t *p_obj, char *psz_name,
int i )
{
val.i_int = i;
return __stats_Update( p_obj, psz_name, val );
}
-#define stats_UpdateInteger( a,b,c ) __stats_UpdateInteger( VLC_OBJECT(a),b,c )
struct input_stats_t
{
+
+ vlc_mutex_t lock;
+
/* Input */
int i_read_packets;
int i_read_bytes;
int i_displayed_pictures;
int i_lost_pictures;
};
+
+VLC_EXPORT( void, stats_ComputeInputStats, (input_thread_t*, input_stats_t*) );
+VLC_EXPORT( void, stats_ReinitInputStats, (input_stats_t *) );
+VLC_EXPORT( void, stats_DumpInputStats, (input_stats_t *) );
int __var_Destroy (vlc_object_t *, const char *);
int playlist_ItemSetDuration (playlist_item_t *, mtime_t);
void aout_Delete (aout_instance_t *);
+void stats_ComputeInputStats (input_thread_t*, input_stats_t*);
int playlist_Control (playlist_t *, int, ...);
vlc_acl_t * __ACL_Create (vlc_object_t *p_this, vlc_bool_t b_allow);
playlist_item_t * playlist_ItemGetByPos (playlist_t *, int);
int playlist_Delete (playlist_t *, int);
void aout_FiltersPlay (aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_buffer_t ** pp_input_buffer);
int __stats_Update (vlc_object_t*, char *, vlc_value_t);
+int __stats_Get (vlc_object_t*, int, char *, vlc_value_t*);
char* httpd_ClientIP (httpd_client_t *cl, char *psz_ip);
int __intf_UserProgress (vlc_object_t*, const char*, const char*, float);
void httpd_FileDelete (httpd_file_t *);
int aout_Restart (aout_instance_t * p_aout);
void * __vlc_object_create (vlc_object_t *, int);
int __aout_VolumeInfos (vlc_object_t *, audio_volume_t *);
+void stats_DumpInputStats (input_stats_t *);
const iso639_lang_t * GetLang_2T (const char *);
int __intf_Interact (vlc_object_t *,interaction_dialog_t *);
int playlist_NodeAddItem (playlist_t *, playlist_item_t *,int,playlist_item_t *,int , int);
vlc_bool_t vlc_current_charset (char **);
char * __net_Gets (vlc_object_t *p_this, int fd, v_socket_t *);
void aout_DateMove (audio_date_t *, mtime_t);
+void stats_ReinitInputStats (input_stats_t *);
void sout_MuxDelete (sout_mux_t *);
void vout_InitFormat (video_frame_format_t *, uint32_t, int, int, int);
void vout_UnlinkPicture (vout_thread_t *, picture_t *);
void (*__intf_UserHide_inner) (vlc_object_t *, int);
int (*__stats_Create_inner) (vlc_object_t*, char *, int, int);
int (*__stats_Update_inner) (vlc_object_t*, char *, vlc_value_t);
+ int (*__stats_Get_inner) (vlc_object_t*, int, char *, vlc_value_t*);
+ void (*stats_ComputeInputStats_inner) (input_thread_t*, input_stats_t*);
+ void (*stats_DumpInputStats_inner) (input_stats_t *);
+ void (*stats_ReinitInputStats_inner) (input_stats_t *);
};
# if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
# define __intf_UserHide (p_symbols)->__intf_UserHide_inner
# define __stats_Create (p_symbols)->__stats_Create_inner
# define __stats_Update (p_symbols)->__stats_Update_inner
+# define __stats_Get (p_symbols)->__stats_Get_inner
+# define stats_ComputeInputStats (p_symbols)->stats_ComputeInputStats_inner
+# define stats_DumpInputStats (p_symbols)->stats_DumpInputStats_inner
+# define stats_ReinitInputStats (p_symbols)->stats_ReinitInputStats_inner
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
((p_symbols)->__intf_UserHide_inner) = __intf_UserHide; \
((p_symbols)->__stats_Create_inner) = __stats_Create; \
((p_symbols)->__stats_Update_inner) = __stats_Update; \
+ ((p_symbols)->__stats_Get_inner) = __stats_Get; \
+ ((p_symbols)->stats_ComputeInputStats_inner) = stats_ComputeInputStats; \
+ ((p_symbols)->stats_DumpInputStats_inner) = stats_DumpInputStats; \
+ ((p_symbols)->stats_ReinitInputStats_inner) = stats_ReinitInputStats; \
(p_symbols)->net_ConvertIPv4_deprecated = NULL; \
# endif /* __PLUGIN__ */
p_input->input.b_eof = VLC_FALSE;
p_input->input.i_cr_average = 0;
+ stats_ReinitInputStats( p_item->p_stats );
+
/* No slave */
p_input->i_slave = 0;
p_input->slave = NULL;
if( !b_quick )
{
stats_Create( p_input, "read_bytes", VLC_VAR_INTEGER, STATS_COUNTER );
+ stats_Create( p_input, "read_packets", VLC_VAR_INTEGER, STATS_COUNTER );
stats_Create( p_input, "input_bitrate", VLC_VAR_FLOAT,
- STATS_DERIVATIVE );
+ STATS_DERIVATIVE );
psz = var_GetString( p_input, "sout" );
if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) )
{
if( !p_sys->i_list )
{
i_read = p_access->pf_read( p_access, p_read, i_read );
+ stats_UpdateInteger( s->p_parent->p_parent , "read_bytes", i_read );
+ stats_UpdateInteger( s->p_parent->p_parent , "input_bitrate", i_read );
+ stats_UpdateInteger( s->p_parent->p_parent , "read_packets", 1 );
return i_read;
}
}
/* Update read bytes in input */
- stats_UpdateInteger( s->p_parent, "read_bytes", i_read );
-
+ stats_UpdateInteger( s->p_parent->p_parent , "read_bytes", i_read );
+ stats_UpdateInteger( s->p_parent->p_parent , "input_bitrate", i_read );
+ stats_UpdateInteger( s->p_parent->p_parent , "read_packets", 1 );
return i_read;
}
#include <stdio.h> /* required */
#include <vlc/vlc.h>
+#include <vlc_input.h>
/*****************************************************************************
* Local prototypes
{
counter_t *p_counter;
stats_handler_t *p_handler = stats_HandlerGet( p_this );
+ if( !p_handler ) return VLC_ENOMEM;
+
+ vlc_mutex_lock( &p_handler->object_lock );
p_counter = (counter_t*) malloc( sizeof( counter_t ) ) ;
p_handler->i_counters,
p_counter );
+ vlc_mutex_unlock( &p_handler->object_lock );
+
return VLC_SUCCESS;
}
int __stats_Update( vlc_object_t *p_this, char *psz_name, vlc_value_t val )
{
+ int i_ret;
counter_t *p_counter;
/* Get stats handler singleton */
stats_handler_t *p_handler = stats_HandlerGet( p_this );
if( !p_handler ) return VLC_ENOMEM;
+ vlc_mutex_lock( &p_handler->object_lock );
+
/* Look for existing element */
p_counter = stats_GetCounter( p_handler, p_this->i_object_id,
psz_name );
if( !p_counter )
{
+ vlc_mutex_unlock( &p_handler->object_lock );
vlc_object_release( p_handler );
return VLC_ENOOBJ;
}
- return stats_CounterUpdate( p_handler, p_counter, val );
+ i_ret = stats_CounterUpdate( p_handler, p_counter, val );
+ vlc_mutex_unlock( &p_handler->object_lock );
+
+ return i_ret;
+}
+
+int __stats_Get( vlc_object_t *p_this, int i_object_id, char *psz_name, vlc_value_t *val )
+{
+ counter_t *p_counter;
+
+ /* Get stats handler singleton */
+ stats_handler_t *p_handler = stats_HandlerGet( p_this );
+ if( !p_handler ) return VLC_ENOMEM;
+ vlc_mutex_lock( &p_handler->object_lock );
+
+
+ /* Look for existing element */
+ p_counter = stats_GetCounter( p_handler, i_object_id,
+ psz_name );
+ if( !p_counter )
+ {
+ vlc_mutex_unlock( &p_handler->object_lock );
+ vlc_object_release( p_handler );
+ return VLC_ENOOBJ;
+ }
+
+ if( p_counter->i_samples == 0 )
+ {
+ vlc_mutex_unlock( &p_handler->object_lock );
+ return VLC_EGENERIC;
+ }
+
+ /* FIXME: Does not work for all types, maybe */
+ *val = p_counter->pp_samples[0]->value;
+ vlc_object_release( p_handler );
+
+ vlc_mutex_unlock( &p_handler->object_lock );
+ return VLC_SUCCESS;;
}
+void stats_ComputeInputStats( input_thread_t *p_input,
+ input_stats_t *p_stats )
+{
+ vlc_mutex_lock( &p_stats->lock );
+ /* read_packets and read_bytes are common to all streams */
+ stats_GetInteger( p_input, p_input->i_object_id, "read_packets",
+ &p_stats->i_read_packets );
+ stats_GetInteger( p_input, p_input->i_object_id, "read_bytes",
+ &p_stats->i_read_bytes );
+ vlc_mutex_unlock( &p_stats->lock );
+}
+
+void stats_ReinitInputStats( input_stats_t *p_stats )
+{
+ p_stats->i_read_packets = p_stats->i_read_bytes =
+ p_stats->f_last_bitrate = p_stats->f_average_bitrate =
+ p_stats->i_displayed_pictures = p_stats->i_lost_pictures = 0;
+}
+
+void stats_DumpInputStats( input_stats_t *p_stats )
+{
+ vlc_mutex_lock( &p_stats->lock );
+ fprintf( stderr, "Read packets : %i (%i bytes)\n",
+ p_stats->i_read_packets, p_stats->i_read_bytes );
+ vlc_mutex_unlock( &p_stats->lock );
+}
+
+
+/********************************************************************
+ * Following functions are local
+ ********************************************************************/
+
+/**
+ * Update a statistics counter, according to its type
+ * If needed, perform a bit of computation (derivative, mostly)
+ * This function must be entered with stats handler lock
+ * \param p_handler stats handler singleton
+ * \param p_counter the counter to update
+ * \param val the "new" value
+ * \return an error code
+ */
static int stats_CounterUpdate( stats_handler_t *p_handler,
counter_t *p_counter,
vlc_value_t val )
}
-void stats_ComputeInputStats( input_thread_t *p_input,
- input_stats_t *p_stats )
-{
- int i;
- /* read_packets and read_bytes are common to all streams */
- //p_stats->i_read_packets = stats_GetInteger( p_input, "read_packets" );
- // p_stats->i_read_bytes = stats_GetInteger( p_input, "read_bytes" );
-
-}
memset( p_item, 0, sizeof( playlist_item_t ) );
+ vlc_input_item_Init( p_obj, &p_item->input );
+
p_item->input.psz_uri = strdup( psz_uri );
if( psz_name != NULL ) p_item->input.psz_name = strdup( psz_name );
/* If there is an input, check that it doesn't need to die. */
if( p_playlist->p_input )
{
+ stats_ComputeInputStats( p_playlist->p_input,
+ p_playlist->p_input->input.p_item->p_stats );
+
/* This input is dead. Remove it ! */
if( p_playlist->p_input->b_dead )
{