]> git.sesse.net Git - vlc/commitdiff
Misc stats work (Refs:#473)
authorClément Stenac <zorglub@videolan.org>
Wed, 11 Jan 2006 20:00:58 +0000 (20:00 +0000)
committerClément Stenac <zorglub@videolan.org>
Wed, 11 Jan 2006 20:00:58 +0000 (20:00 +0000)
include/vlc_input.h
include/vlc_messages.h
include/vlc_symbols.h
src/input/input.c
src/input/stream.c
src/misc/stats.c
src/playlist/item.c
src/playlist/playlist.c

index 069657d7fe972928416deae4e128454a1da089fd..adca4ff6aea29ff7e96e5168f460e870cdc1085c 100644 (file)
@@ -64,6 +64,8 @@ struct input_item_t
 
     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 */
 };
 
@@ -91,6 +93,10 @@ static inline void vlc_input_item_Init( vlc_object_t *p_o, input_item_t *p_i )
     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 );
 }
 
index c8f5f5bf84176db2ba94e974e3c7bb03340395d9..4027fa510e6d88c7d05b98ded52b0560cc0aecf9 100644 (file)
  *****************************************************************************/
 
 #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
@@ -239,7 +243,20 @@ struct stats_handler_t
 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 )
 {
@@ -247,11 +264,13 @@ static inline int __stats_UpdateInteger( vlc_object_t *p_obj, char *psz_name,
     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;
@@ -265,3 +284,7 @@ struct input_stats_t
     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 *) );
index b5e7df4dbd7a562076d82bc1e11105c3bf46a311..97f7c433cf26a7130051b0ea7e061d7a02d007f6 100644 (file)
@@ -29,6 +29,7 @@ void vlm_MediaDelete (vlm_t *, vlm_media_t *, const char *);
 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);
@@ -120,6 +121,7 @@ void vout_SynchroDecode (vout_synchro_t *);
 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 *);
@@ -241,6 +243,7 @@ int osd_ConfigLoader (vlc_object_t *, const char *, osd_menu_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);
@@ -251,6 +254,7 @@ int playlist_LockControl (playlist_t *, 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 *);
@@ -873,6 +877,10 @@ struct module_symbols_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
@@ -1295,6 +1303,10 @@ struct module_symbols_t
 #  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.
@@ -1720,6 +1732,10 @@ struct module_symbols_t
     ((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__ */
index 0d10aa7883f04500658c7c6a7fd19ae9535c6856..c34104dbe8a2fb27ced523dfdaf3637a11f6aa0a 100644 (file)
@@ -150,6 +150,8 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     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;
@@ -673,8 +675,9 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
     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 ) )
         {
index 456322116315fe3cc2c0069b73d4c766b4d493d8..c3bec91be25c6cdf8236539f401ed791be84dad0 100644 (file)
@@ -1569,6 +1569,9 @@ static int AReadStream( stream_t *s, void *p_read, int i_read )
     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;
     }
 
@@ -1597,8 +1600,9 @@ static int AReadStream( stream_t *s, void *p_read, int 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;
 }
 
index 433f7a6d6b126a95fdbcc17b94499e55394e6460..d88ef18e1cf58799785dc94e97de1e0e5bf7541b 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdio.h>                                               /* required */
 
 #include <vlc/vlc.h>
+#include <vlc_input.h>
 
 /*****************************************************************************
  * Local prototypes
@@ -48,6 +49,9 @@ int __stats_Create( vlc_object_t *p_this, char *psz_name, int i_type,
 {
     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 ) ) ;
 
@@ -63,6 +67,8 @@ int __stats_Create( vlc_object_t *p_this, char *psz_name, int i_type,
                  p_handler->i_counters,
                  p_counter );
 
+    vlc_mutex_unlock( &p_handler->object_lock );
+
     return VLC_SUCCESS;
 }
 
@@ -70,24 +76,106 @@ int __stats_Create( vlc_object_t *p_this, char *psz_name, int i_type,
 
 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 )
@@ -244,12 +332,3 @@ static stats_handler_t* stats_HandlerCreate( vlc_object_t *p_this )
 }
 
 
-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" );
-
-}
index b5c6603c758cd2c11dc2d401d4351d344027cca5..c339a2b5140ddb330ce288cbe6433db2f11af173 100644 (file)
@@ -63,6 +63,8 @@ playlist_item_t * playlist_ItemNewWithType( vlc_object_t *p_obj,
 
     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 );
index eb901a1c425ad2218c955344caf357a073bf49bd..00567988abc5d150343e080397ed1682278c0f41 100644 (file)
@@ -618,6 +618,9 @@ static void RunThread ( playlist_t *p_playlist )
         /* 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 )
             {