]> git.sesse.net Git - vlc/blob - include/vlc_messages.h
Add a timing facility (Refs:#473)
[vlc] / include / vlc_messages.h
1 /*****************************************************************************
2  * messages.h: messages interface
3  * This library provides basic functions for threads to interact with user
4  * interface, such as message output.
5  *****************************************************************************
6  * Copyright (C) 1999, 2000, 2001, 2002 the VideoLAN team
7  * $Id$
8  *
9  * Authors: Vincent Seguin <seguin@via.ecp.fr>
10  *          Samuel Hocevar <sam@zoy.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 #include <stdarg.h>
28
29 int vlc_mutex_lock(  vlc_mutex_t * ) ;
30 int vlc_mutex_unlock(  vlc_mutex_t * ) ;
31
32 /**
33  * \defgroup messages Messages
34  * This library provides basic functions for threads to interact with user
35  * interface, such as message output.
36  *
37  * @{
38  */
39
40
41 /**
42  * Store a single message.
43  */
44 typedef struct
45 {
46     int     i_type;                             /**< message type, see below */
47     int     i_object_id;
48     int     i_object_type;
49     char *  psz_module;
50     char *  psz_msg;                            /**< the message itself */
51     char *  psz_header;                         /**< Additional header */
52
53     mtime_t date;                               /**< Message date */
54 } msg_item_t;
55
56 /* Message types */
57 /** standard messages */
58 #define VLC_MSG_INFO  0
59 /** error messages */
60 #define VLC_MSG_ERR   1
61 /** warning messages */
62 #define VLC_MSG_WARN  2
63 /** debug messages */
64 #define VLC_MSG_DBG   3
65
66 #define MSG_QUEUE_NORMAL 0
67 #define MSG_QUEUE_HTTPD_ACCESS 1
68
69 /**
70  * Store all data requiered by messages interfaces.
71  */
72 struct msg_bank_t
73 {
74     vlc_mutex_t             lock;
75     int                     i_queues;
76     msg_queue_t           **pp_queues;
77 };
78
79 struct msg_queue_t
80 {
81     int                     i_id;
82
83     /** Message queue lock */
84     vlc_mutex_t             lock;
85     vlc_bool_t              b_overflow;
86
87     /* Message queue */
88     msg_item_t              msg[VLC_MSG_QSIZE];           /**< message queue */
89     int i_start;
90     int i_stop;
91
92     /* Subscribers */
93     int i_sub;
94     msg_subscription_t **pp_sub;
95
96     /* Logfile for WinCE */
97 #ifdef UNDER_CE
98     FILE *logfile;
99 #endif
100 };
101
102 /**
103  * Used by interface plugins which subscribe to the message bank.
104  */
105 struct msg_subscription_t
106 {
107     int   i_start;
108     int*  pi_stop;
109
110     msg_item_t*  p_msg;
111     vlc_mutex_t* p_lock;
112 };
113
114 /*****************************************************************************
115  * Prototypes
116  *****************************************************************************/
117 VLC_EXPORT( void, __msg_Generic, ( vlc_object_t *, int, int, const char *, const char *, ... ) ATTRIBUTE_FORMAT( 5, 6 ) );
118 VLC_EXPORT( void, __msg_GenericVa, ( vlc_object_t *, int, int, const char *, const char *, va_list args ) );
119 #define msg_GenericVa(a, b, c, d, e,f) __msg_GenericVa(VLC_OBJECT(a), b, c, d, e,f)
120 VLC_EXPORT( void, __msg_Info,    ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
121 VLC_EXPORT( void, __msg_Err,     ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
122 VLC_EXPORT( void, __msg_Warn,    ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
123 VLC_EXPORT( void, __msg_Dbg,    ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
124
125 #ifdef HAVE_VARIADIC_MACROS
126
127 #   define msg_Info( p_this, psz_format, args... ) \
128       __msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL,VLC_MSG_INFO, MODULE_STRING, \
129                      psz_format, ## args )
130
131 #   define msg_Err( p_this, psz_format, args... ) \
132       __msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL, VLC_MSG_ERR, MODULE_STRING, \
133                      psz_format, ## args )
134
135 #   define msg_Warn( p_this, psz_format, args... ) \
136       __msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL, VLC_MSG_WARN, MODULE_STRING, \
137                      psz_format, ## args )
138
139 #   define msg_Dbg( p_this, psz_format, args... ) \
140       __msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL, VLC_MSG_DBG, MODULE_STRING, \
141                      psz_format, ## args )
142
143 #elif defined(_MSC_VER) /* To avoid warnings and even errors with c++ files */
144
145 inline void msg_Info( void *p_this, const char *psz_format, ... )
146 {
147   va_list ap;
148   va_start( ap, psz_format );
149   __msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL,VLC_MSG_INFO, MODULE_STRING,
150                    psz_format, ap );
151   va_end(ap);
152 }
153 inline void msg_Err( void *p_this, const char *psz_format, ... )
154 {
155   va_list ap;
156   va_start( ap, psz_format );
157   __msg_GenericVa( ( vlc_object_t *)p_this,MSG_QUEUE_NORMAL, VLC_MSG_ERR, MODULE_STRING,
158                    psz_format, ap );
159   va_end(ap);
160 }
161 inline void msg_Warn( void *p_this, const char *psz_format, ... )
162 {
163   va_list ap;
164   va_start( ap, psz_format );
165   __msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL, VLC_MSG_WARN, MODULE_STRING,
166                    psz_format, ap );
167   va_end(ap);
168 }
169 inline void msg_Dbg( void *p_this, const char *psz_format, ... )
170 {
171   va_list ap;
172   va_start( ap, psz_format );
173   __msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL, VLC_MSG_DBG, MODULE_STRING,
174                    psz_format, ap );
175   va_end(ap);
176 }
177
178 #else /* _MSC_VER */
179
180 #   define msg_Info __msg_Info
181 #   define msg_Err __msg_Err
182 #   define msg_Warn __msg_Warn
183 #   define msg_Dbg __msg_Dbg
184
185 #endif /* HAVE_VARIADIC_MACROS */
186
187 #define msg_Create(a) __msg_Create(VLC_OBJECT(a))
188 #define msg_Flush(a) __msg_Flush(VLC_OBJECT(a))
189 #define msg_Destroy(a) __msg_Destroy(VLC_OBJECT(a))
190 void __msg_Create  ( vlc_object_t * );
191 void __msg_Flush   ( vlc_object_t * );
192 void __msg_Destroy ( vlc_object_t * );
193
194 #define msg_Subscribe(a,b) __msg_Subscribe(VLC_OBJECT(a),b)
195 #define msg_Unsubscribe(a,b) __msg_Unsubscribe(VLC_OBJECT(a),b)
196 VLC_EXPORT( msg_subscription_t*, __msg_Subscribe, ( vlc_object_t *, int ) );
197 VLC_EXPORT( void, __msg_Unsubscribe, ( vlc_object_t *, msg_subscription_t * ) );
198
199
200 /**
201  * @}
202  */
203
204 /**
205  * \defgroup statistics Statistics
206  *
207  * @{
208  */
209
210 /****************************
211  * Generic stats stuff
212  ****************************/
213 enum
214 {
215     STATS_LAST,
216     STATS_COUNTER,
217     STATS_MAX,
218     STATS_MIN,
219     STATS_DERIVATIVE,
220     STATS_TIMER
221 };
222
223 struct counter_sample_t
224 {
225     vlc_value_t value;
226     mtime_t     date;
227 };
228
229 struct counter_t
230 {
231     char              * psz_name;
232     int                 i_source_object;
233     int                 i_compute_type;
234     int                 i_type;
235     int                 i_samples;
236     counter_sample_t ** pp_samples;
237
238     mtime_t             update_interval;
239     mtime_t             last_update;
240 };
241
242 struct stats_handler_t
243 {
244     VLC_COMMON_MEMBERS
245
246     int         i_counters;
247     counter_t **pp_counters;
248 };
249
250 VLC_EXPORT( void, stats_HandlerDestroy, (stats_handler_t*) );
251
252 #define stats_Update( a,b,c) __stats_Update( VLC_OBJECT( a ), b, c )
253 VLC_EXPORT( int, __stats_Update, (vlc_object_t*, const char *, vlc_value_t) );
254 #define stats_Create( a,b,c,d ) __stats_Create( VLC_OBJECT(a), b, c, d )
255 VLC_EXPORT( int, __stats_Create, (vlc_object_t*, const char *, int, int) );
256 #define stats_Get( a,b,c,d ) __stats_Create( VLC_OBJECT(a), b, c, d )
257 VLC_EXPORT( int, __stats_Get, (vlc_object_t*, int, const char *, vlc_value_t*) );
258 #define stats_CounterGet( a,b,c) __stats_CounterGet( VLC_OBJECT(a), b, c )
259 VLC_EXPORT( counter_t*, __stats_CounterGet, (vlc_object_t*, int, const char * ) );
260
261 #define stats_GetInteger( a,b,c,d ) __stats_GetInteger( VLC_OBJECT(a), b, c, d )
262 static inline int __stats_GetInteger( vlc_object_t *p_obj, int i_id,
263                                       const char *psz_name, int *value )
264 {
265     vlc_value_t val;
266     int i_ret = __stats_Get( p_obj, i_id, psz_name, &val );
267     *value = val.i_int;
268     return i_ret;
269 }
270
271 #define stats_GetFloat(a,b,c,d ) __stats_GetFloat( VLC_OBJECT(a), b, c, d )
272 static inline int __stats_GetFloat( vlc_object_t *p_obj, int i_id,
273                                     const char *psz_name, float *value )
274 {
275     vlc_value_t val;
276     int i_ret = __stats_Get( p_obj, i_id, psz_name, &val );
277     *value = val.f_float;
278     return i_ret;
279 }
280 #define stats_UpdateInteger( a,b,c ) __stats_UpdateInteger( VLC_OBJECT(a),b,c )
281 static inline int __stats_UpdateInteger( vlc_object_t *p_obj,
282                                          const char *psz_name, int i )
283 {
284     vlc_value_t val;
285     val.i_int = i;
286     return __stats_Update( p_obj, psz_name, val );
287 }
288 #define stats_UpdateFloat( a,b,c ) __stats_UpdateFloat( VLC_OBJECT(a),b,c )
289 static inline int __stats_UpdateFloat( vlc_object_t *p_obj,
290                                        const char *psz_name, float f )
291 {
292     vlc_value_t val;
293     val.f_float = f;
294     return __stats_Update( p_obj, psz_name, val );
295 }
296
297 /******************
298  * Input stats
299  ******************/
300 struct input_stats_t
301 {
302
303     vlc_mutex_t         lock;
304
305     /* Input */
306     int i_read_packets;
307     int i_read_bytes;
308     float f_input_bitrate;
309     float f_average_input_bitrate;
310
311     /* Demux */
312     int i_demux_read_packets;
313     int i_demux_read_bytes;
314     float f_demux_bitrate;
315     float f_average_demux_bitrate;
316
317     /* Decoders */
318     int i_decoded_audio;
319     int i_decoded_video;
320
321     /* Vout */
322     int i_displayed_pictures;
323     int i_lost_pictures;
324
325     /* Sout */
326     int i_sent_packets;
327     int i_sent_bytes;
328     float f_send_bitrate;
329
330     /* Aout */
331     int i_played_abuffers;
332     int i_lost_abuffers;
333 };
334
335 VLC_EXPORT( void, stats_ComputeInputStats, (input_thread_t*, input_stats_t*) );
336 VLC_EXPORT( void, stats_ReinitInputStats, (input_stats_t *) );
337 VLC_EXPORT( void, stats_DumpInputStats, (input_stats_t *) );
338
339 /********************
340  * Global stats
341  *******************/
342 struct global_stats_t
343 {
344     vlc_mutex_t lock;
345
346     float f_input_bitrate;
347     float f_output_bitrate;
348
349     int i_http_clients;
350 };
351
352 #define stats_ComputeGlobalStats( a,b) __stats_ComputeGlobalStats( VLC_OBJECT(a),b)
353 VLC_EXPORT( void, __stats_ComputeGlobalStats, (vlc_object_t*,global_stats_t*));
354
355
356 /*********
357  * Timing
358  ********/
359 #ifdef DEBUG
360 #define stats_TimerStart(a,b) __stats_TimerStart( VLC_OBJECT(a), b )
361 #define stats_TimerStop(a,b) __stats_TimerStop( VLC_OBJECT(a), b )
362 #define stats_TimerDump(a,b) __stats_TimerDump( VLC_OBJECT(a), b )
363 #define stats_TimersDumpAll(a) __stats_TimersDumpAll( VLC_OBJECT(a) )
364 #else
365 #define stats_TimerStart(a,b) {}
366 #define stats_TimerStop(a,b) {}
367 #define stats_TimerDump(a,b) {}
368 #define stats_TimersDumpAll(a) {}
369 #endif
370 VLC_EXPORT( void,__stats_TimerStart, (vlc_object_t*, const char *) );
371 VLC_EXPORT( void,__stats_TimerStop, (vlc_object_t*, const char *) );
372 VLC_EXPORT( void,__stats_TimerDump, (vlc_object_t*, const char *) );
373 VLC_EXPORT( void,__stats_TimersDumpAll, (vlc_object_t*) );