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