vlc_messages.h 7.63 KB
Newer Older
1 2 3 4 5
/*****************************************************************************
 * messages.h: messages interface
 * This library provides basic functions for threads to interact with user
 * interface, such as message output.
 *****************************************************************************
6
 * Copyright (C) 1999, 2000, 2001, 2002 the VideoLAN team
7
 * $Id$
8 9 10 11 12 13 14 15
 *
 * Authors: Vincent Seguin <seguin@via.ecp.fr>
 *          Samuel Hocevar <sam@zoy.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
16
 *
17 18 19 20 21 22 23 24 25 26 27
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

#include <stdarg.h>
Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
28 29 30 31 32 33 34
/**
 * \defgroup messages Messages
 * This library provides basic functions for threads to interact with user
 * interface, such as message output.
 *
 * @{
 */
35

Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
36 37

/**
38
 * Store a single message.
Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
39
 */
40 41
typedef struct
{
Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
42
    int     i_type;                             /**< message type, see below */
43
    int     i_object_id;
44
    int     i_object_type;
45
    char *  psz_module;
Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
46
    char *  psz_msg;                                 /**< the message itself */
47

48
    mtime_t date;                               /**< Message date */
49 50 51
} msg_item_t;

/* Message types */
Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
52
/** standard messages */
53
#define VLC_MSG_INFO  0
Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
54
/** error messages */
55
#define VLC_MSG_ERR   1
Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
56 57 58 59 60
/** warning messages */
#define VLC_MSG_WARN  2
/** debug messages */
#define VLC_MSG_DBG   3

61 62 63
#define MSG_QUEUE_NORMAL 0
#define MSG_QUEUE_HTTPD_ACCESS 1

Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
64
/**
65
 * Store all data requiered by messages interfaces.
Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
66
 */
67
struct msg_bank_t
68
{
69 70 71 72 73 74 75 76 77
    vlc_mutex_t             lock;
    int                     i_queues;
    msg_queue_t           **pp_queues;
};

struct msg_queue_t
{
    int                     i_id;

Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
78
    /** Message queue lock */
79
    vlc_mutex_t             lock;
80
    vlc_bool_t              b_overflow;
81 82

    /* Message queue */
Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
83
    msg_item_t              msg[VLC_MSG_QSIZE];           /**< message queue */
84 85 86 87 88 89
    int i_start;
    int i_stop;

    /* Subscribers */
    int i_sub;
    msg_subscription_t **pp_sub;
90 91 92 93 94

    /* Logfile for WinCE */
#ifdef UNDER_CE
    FILE *logfile;
#endif
95 96
};

Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
97
/**
98
 * Used by interface plugins which subscribe to the message bank.
Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
99
 */
100
struct msg_subscription_t
101 102 103 104 105 106 107 108 109 110 111
{
    int   i_start;
    int*  pi_stop;

    msg_item_t*  p_msg;
    vlc_mutex_t* p_lock;
};

/*****************************************************************************
 * Prototypes
 *****************************************************************************/
112 113
VLC_EXPORT( void, __msg_Generic, ( vlc_object_t *, int, int, const char *, const char *, ... ) ATTRIBUTE_FORMAT( 5, 6 ) );
VLC_EXPORT( void, __msg_GenericVa, ( vlc_object_t *, int, int, const char *, const char *, va_list args ) );
Clément Stenac's avatar
Clément Stenac committed
114
#define msg_GenericVa(a, b, c, d, e,f) __msg_GenericVa(VLC_OBJECT(a), b, c, d, e,f)
Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
115 116 117 118
VLC_EXPORT( void, __msg_Info,    ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
VLC_EXPORT( void, __msg_Err,     ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
VLC_EXPORT( void, __msg_Warn,    ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
VLC_EXPORT( void, __msg_Dbg,    ( vlc_object_t *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
119 120 121 122

#ifdef HAVE_VARIADIC_MACROS

#   define msg_Info( p_this, psz_format, args... ) \
123
      __msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL,VLC_MSG_INFO, MODULE_STRING, \
124 125 126
                     psz_format, ## args )

#   define msg_Err( p_this, psz_format, args... ) \
127
      __msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL, VLC_MSG_ERR, MODULE_STRING, \
128 129 130
                     psz_format, ## args )

#   define msg_Warn( p_this, psz_format, args... ) \
131
      __msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL, VLC_MSG_WARN, MODULE_STRING, \
132 133 134
                     psz_format, ## args )

#   define msg_Dbg( p_this, psz_format, args... ) \
135
      __msg_Generic( VLC_OBJECT(p_this), MSG_QUEUE_NORMAL, VLC_MSG_DBG, MODULE_STRING, \
136 137
                     psz_format, ## args )

138 139 140 141 142 143
#elif defined(_MSC_VER) /* To avoid warnings and even errors with c++ files */

inline void msg_Info( void *p_this, const char *psz_format, ... )
{
  va_list ap;
  va_start( ap, psz_format );
144
  __msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL,VLC_MSG_INFO, MODULE_STRING,
145 146 147 148 149 150 151
                   psz_format, ap );
  va_end(ap);
}
inline void msg_Err( void *p_this, const char *psz_format, ... )
{
  va_list ap;
  va_start( ap, psz_format );
152
  __msg_GenericVa( ( vlc_object_t *)p_this,MSG_QUEUE_NORMAL, VLC_MSG_ERR, MODULE_STRING,
153 154 155 156 157 158 159
                   psz_format, ap );
  va_end(ap);
}
inline void msg_Warn( void *p_this, const char *psz_format, ... )
{
  va_list ap;
  va_start( ap, psz_format );
160
  __msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL, VLC_MSG_WARN, MODULE_STRING,
161 162 163 164 165 166 167
                   psz_format, ap );
  va_end(ap);
}
inline void msg_Dbg( void *p_this, const char *psz_format, ... )
{
  va_list ap;
  va_start( ap, psz_format );
168
  __msg_GenericVa( ( vlc_object_t *)p_this, MSG_QUEUE_NORMAL, VLC_MSG_DBG, MODULE_STRING,
169 170 171 172 173
                   psz_format, ap );
  va_end(ap);
}

#else /* _MSC_VER */
174 175 176 177 178 179 180 181

#   define msg_Info __msg_Info
#   define msg_Err __msg_Err
#   define msg_Warn __msg_Warn
#   define msg_Dbg __msg_Dbg

#endif /* HAVE_VARIADIC_MACROS */

182 183 184
#define msg_Create(a) __msg_Create(VLC_OBJECT(a))
#define msg_Flush(a) __msg_Flush(VLC_OBJECT(a))
#define msg_Destroy(a) __msg_Destroy(VLC_OBJECT(a))
185
void __msg_Create  ( vlc_object_t * );
186
void __msg_Flush   ( vlc_object_t * );
187 188
void __msg_Destroy ( vlc_object_t * );

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 193
VLC_EXPORT( void, __msg_Unsubscribe, ( vlc_object_t *, msg_subscription_t * ) );

Sigmund Augdal Helberg's avatar
all:  
Sigmund Augdal Helberg committed
194 195 196 197

/**
 * @}
 */
198 199 200 201 202 203 204 205 206 207 208 209 210

/**
 * \defgroup statistics Statistics
 *
 * @{
 */

enum
{
    STATS_LAST,
    STATS_COUNTER,
    STATS_MAX,
    STATS_MIN,
211
    STATS_DERIVATIVE
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
};

struct counter_sample_t
{
    vlc_value_t value;
    mtime_t     date;
};

struct counter_t
{
    char              * psz_name;
    int                 i_source_object;
    int                 i_compute_type;
    int                 i_type;
    int                 i_samples;
    counter_sample_t ** pp_samples;
};

struct stats_handler_t
{
    VLC_COMMON_MEMBERS

    int         i_counters;
    counter_t **pp_counters;
};

#define stats_Update( a,b,c) __stats_Update( VLC_OBJECT( a ), b, c )
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) );

static inline int __stats_UpdateInteger( vlc_object_t *p_obj, char *psz_name,
                                         int i )
{
    vlc_value_t val;
    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 )
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267


struct input_stats_t
{
    /* Input */
    int i_read_packets;
    int i_read_bytes;

    float f_last_bitrate;
    float f_average_bitrate;

    /* Decoders */

    /* Vout */
    int i_displayed_pictures;
    int i_lost_pictures;
}