]> git.sesse.net Git - vlc/blob - include/vlc_messages.h
Misc stats work (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., 59 Temple Place - Suite 330, Boston, MA  02111, 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
52     mtime_t date;                               /**< Message date */
53 } msg_item_t;
54
55 /* Message types */
56 /** standard messages */
57 #define VLC_MSG_INFO  0
58 /** error messages */
59 #define VLC_MSG_ERR   1
60 /** warning messages */
61 #define VLC_MSG_WARN  2
62 /** debug messages */
63 #define VLC_MSG_DBG   3
64
65 #define MSG_QUEUE_NORMAL 0
66 #define MSG_QUEUE_HTTPD_ACCESS 1
67
68 /**
69  * Store all data requiered by messages interfaces.
70  */
71 struct msg_bank_t
72 {
73     vlc_mutex_t             lock;
74     int                     i_queues;
75     msg_queue_t           **pp_queues;
76 };
77
78 struct msg_queue_t
79 {
80     int                     i_id;
81
82     /** Message queue lock */
83     vlc_mutex_t             lock;
84     vlc_bool_t              b_overflow;
85
86     /* Message queue */
87     msg_item_t              msg[VLC_MSG_QSIZE];           /**< message queue */
88     int i_start;
89     int i_stop;
90
91     /* Subscribers */
92     int i_sub;
93     msg_subscription_t **pp_sub;
94
95     /* Logfile for WinCE */
96 #ifdef UNDER_CE
97     FILE *logfile;
98 #endif
99 };
100
101 /**
102  * Used by interface plugins which subscribe to the message bank.
103  */
104 struct msg_subscription_t
105 {
106     int   i_start;
107     int*  pi_stop;
108
109     msg_item_t*  p_msg;
110     vlc_mutex_t* p_lock;
111 };
112
113 /*****************************************************************************
114  * Prototypes
115  *****************************************************************************/
116 VLC_EXPORT( void, __msg_Generic, ( vlc_object_t *, int, int, const char *, const char *, ... ) ATTRIBUTE_FORMAT( 5, 6 ) );
117 VLC_EXPORT( void, __msg_GenericVa, ( vlc_object_t *, int, int, const char *, const char *, va_list args ) );
118 #define msg_GenericVa(a, b, c, d, e,f) __msg_GenericVa(VLC_OBJECT(a), b, c, d, e,f)
119 VLC_EXPORT( void, __msg_Info,    ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
120 VLC_EXPORT( void, __msg_Err,     ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
121 VLC_EXPORT( void, __msg_Warn,    ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
122 VLC_EXPORT( void, __msg_Dbg,    ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
123
124 #ifdef HAVE_VARIADIC_MACROS
125
126 #   define msg_Info( p_this, psz_format, args... ) \
127       __msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL,VLC_MSG_INFO, MODULE_STRING, \
128                      psz_format, ## args )
129
130 #   define msg_Err( p_this, psz_format, args... ) \
131       __msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL, VLC_MSG_ERR, MODULE_STRING, \
132                      psz_format, ## args )
133
134 #   define msg_Warn( p_this, psz_format, args... ) \
135       __msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL, VLC_MSG_WARN, MODULE_STRING, \
136                      psz_format, ## args )
137
138 #   define msg_Dbg( p_this, psz_format, args... ) \
139       __msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL, VLC_MSG_DBG, MODULE_STRING, \
140                      psz_format, ## args )
141
142 #elif defined(_MSC_VER) /* To avoid warnings and even errors with c++ files */
143
144 inline void msg_Info( void *p_this, const char *psz_format, ... )
145 {
146   va_list ap;
147   va_start( ap, psz_format );
148   __msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL,VLC_MSG_INFO, MODULE_STRING,
149                    psz_format, ap );
150   va_end(ap);
151 }
152 inline void msg_Err( void *p_this, const char *psz_format, ... )
153 {
154   va_list ap;
155   va_start( ap, psz_format );
156   __msg_GenericVa( ( vlc_object_t *)p_this,MSG_QUEUE_NORMAL, VLC_MSG_ERR, MODULE_STRING,
157                    psz_format, ap );
158   va_end(ap);
159 }
160 inline void msg_Warn( void *p_this, const char *psz_format, ... )
161 {
162   va_list ap;
163   va_start( ap, psz_format );
164   __msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL, VLC_MSG_WARN, MODULE_STRING,
165                    psz_format, ap );
166   va_end(ap);
167 }
168 inline void msg_Dbg( void *p_this, const char *psz_format, ... )
169 {
170   va_list ap;
171   va_start( ap, psz_format );
172   __msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL, VLC_MSG_DBG, MODULE_STRING,
173                    psz_format, ap );
174   va_end(ap);
175 }
176
177 #else /* _MSC_VER */
178
179 #   define msg_Info __msg_Info
180 #   define msg_Err __msg_Err
181 #   define msg_Warn __msg_Warn
182 #   define msg_Dbg __msg_Dbg
183
184 #endif /* HAVE_VARIADIC_MACROS */
185
186 #define msg_Create(a) __msg_Create(VLC_OBJECT(a))
187 #define msg_Flush(a) __msg_Flush(VLC_OBJECT(a))
188 #define msg_Destroy(a) __msg_Destroy(VLC_OBJECT(a))
189 void __msg_Create  ( vlc_object_t * );
190 void __msg_Flush   ( vlc_object_t * );
191 void __msg_Destroy ( vlc_object_t * );
192
193 #define msg_Subscribe(a,b) __msg_Subscribe(VLC_OBJECT(a),b)
194 #define msg_Unsubscribe(a,b) __msg_Unsubscribe(VLC_OBJECT(a),b)
195 VLC_EXPORT( msg_subscription_t*, __msg_Subscribe, ( vlc_object_t *, int ) );
196 VLC_EXPORT( void, __msg_Unsubscribe, ( vlc_object_t *, msg_subscription_t * ) );
197
198
199 /**
200  * @}
201  */
202
203 /**
204  * \defgroup statistics Statistics
205  *
206  * @{
207  */
208
209 enum
210 {
211     STATS_LAST,
212     STATS_COUNTER,
213     STATS_MAX,
214     STATS_MIN,
215     STATS_DERIVATIVE
216 };
217
218 struct counter_sample_t
219 {
220     vlc_value_t value;
221     mtime_t     date;
222 };
223
224 struct counter_t
225 {
226     char              * psz_name;
227     int                 i_source_object;
228     int                 i_compute_type;
229     int                 i_type;
230     int                 i_samples;
231     counter_sample_t ** pp_samples;
232 };
233
234 struct stats_handler_t
235 {
236     VLC_COMMON_MEMBERS
237
238     int         i_counters;
239     counter_t **pp_counters;
240 };
241
242 #define stats_Update( a,b,c) __stats_Update( VLC_OBJECT( a ), b, c )
243 VLC_EXPORT( int, __stats_Update, (vlc_object_t*, char *, vlc_value_t) );
244 #define stats_Create( a,b,c,d ) __stats_Create( VLC_OBJECT(a), b, c, d )
245 VLC_EXPORT( int, __stats_Create, (vlc_object_t*, char *, int, int) );
246 #define stats_Get( a,b,c,d ) __stats_Create( VLC_OBJECT(a), b, c, d )
247 VLC_EXPORT( int, __stats_Get, (vlc_object_t*, int, char *, vlc_value_t*) );
248
249 #define stats_GetInteger( a,b,c,d ) __stats_GetInteger( VLC_OBJECT(a), b, c, d )
250 static inline int __stats_GetInteger( vlc_object_t *p_obj, int i_id,
251                                       char *psz_name, int *value )
252 {
253     vlc_value_t val;
254     int i_ret = __stats_Get( p_obj, i_id, psz_name, &val );
255     *value = val.i_int;
256     return i_ret;
257 }
258
259 #define stats_UpdateInteger( a,b,c ) __stats_UpdateInteger( VLC_OBJECT(a),b,c )
260 static inline int __stats_UpdateInteger( vlc_object_t *p_obj, char *psz_name,
261                                          int i )
262 {
263     vlc_value_t val;
264     val.i_int = i;
265     return __stats_Update( p_obj, psz_name, val );
266 }
267
268
269 struct input_stats_t
270 {
271
272     vlc_mutex_t         lock;
273
274     /* Input */
275     int i_read_packets;
276     int i_read_bytes;
277
278     float f_last_bitrate;
279     float f_average_bitrate;
280
281     /* Decoders */
282
283     /* Vout */
284     int i_displayed_pictures;
285     int i_lost_pictures;
286 };
287
288 VLC_EXPORT( void, stats_ComputeInputStats, (input_thread_t*, input_stats_t*) );
289 VLC_EXPORT( void, stats_ReinitInputStats, (input_stats_t *) );
290 VLC_EXPORT( void, stats_DumpInputStats, (input_stats_t *) );