libvlc.h 10.4 KB
Newer Older
1
/*****************************************************************************
2
 * libvlc.h: Internal libvlc generic/misc declaration
3
 *****************************************************************************
4
 * Copyright (C) 1999, 2000, 2001, 2002 the VideoLAN team
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
5
 * Copyright © 2006-2007 Rémi Denis-Courmont
Carlo Calabrò's avatar
Carlo Calabrò committed
6
 * $Id$
7
 *
8 9
 * Authors: Vincent Seguin <seguin@via.ecp.fr>
 *
10 11 12 13 14 15 16 17 18 19 20 21
 * 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.
 *
 * 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
Antoine Cellerier's avatar
Antoine Cellerier committed
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24
 *****************************************************************************/

25 26
#ifndef LIBVLC_LIBVLC_H
# define LIBVLC_LIBVLC_H 1
27

28 29
typedef struct variable_t variable_t;

30 31 32 33 34 35 36 37
/* Actions (hot keys) */
typedef struct action
{
    char name[24];
    int  value;
} action_t;
extern const struct action libvlc_actions[];
extern const size_t libvlc_actions_count;
38 39
extern int vlc_InitActions (libvlc_int_t *);
extern void vlc_DeinitActions (libvlc_int_t *);
40

41 42 43 44
/*
 * OS-specific initialization
 */
void system_Init      ( libvlc_int_t *, int *, const char *[] );
45
void system_Configure ( libvlc_int_t *, int, const char *const [] );
46 47
void system_End       ( libvlc_int_t * );

48 49 50 51
/*
 * Threads subsystem
 */

52 53 54
/* This cannot be used as is from plugins: */
void vlc_detach (vlc_thread_t);

55 56
/* Hopefully, no need to export this. There is a new thread API instead. */
void vlc_thread_cancel (vlc_object_t *);
57
int vlc_object_waitpipe (vlc_object_t *obj);
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
58

59 60
void vlc_threads_setup (libvlc_int_t *);

61 62
void vlc_trace (const char *fn, const char *file, unsigned line);
#define vlc_backtrace() vlc_trace(__func__, __FILE__, __LINE__)
63

64
#if defined (LIBVLC_USE_PTHREAD) && !defined (NDEBUG)
65
void vlc_assert_locked (vlc_mutex_t *);
66 67 68 69
#else
# define vlc_assert_locked( m ) (void)m
#endif

70 71 72 73 74
/*
 * CPU capabilities
 */
extern uint32_t cpu_flags;
uint32_t CPUCapabilities( void );
75
bool vlc_CPU_CheckPluginDir (const char *name);
76

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
77 78 79 80
/*
 * Message/logging stuff
 */

81
typedef struct msg_bank_t msg_bank_t;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
82

83 84
msg_bank_t *msg_Create (void);
void msg_Destroy (msg_bank_t *);
85 86 87 88 89 90

/** Internal message stack context */
void msg_StackSet ( int, const char*, ... );
void msg_StackAdd ( const char*, ... );
const char* msg_StackMsg ( void );

91 92 93
/*
 * Unicode stuff
 */
94
char *vlc_fix_readdir (const char *);
95

96 97 98 99 100 101 102 103 104 105 106 107 108 109
/*
 * LibVLC exit event handling
 */
typedef struct vlc_exit
{
    vlc_mutex_t lock;
    void (*handler) (void *);
    void *opaque;
    bool killed;
} vlc_exit_t;

void vlc_ExitInit( vlc_exit_t * );
void vlc_ExitDestroy( vlc_exit_t * );

110 111 112 113
/*
 * LibVLC objects stuff
 */

114 115 116 117 118 119 120 121 122 123 124 125 126 127
/**
 * Creates a VLC object.
 *
 * Note that because the object name pointer must remain valid, potentially
 * even after the destruction of the object (through the message queues), this
 * function CANNOT be exported to plugins as is. In this case, the old
 * vlc_object_create() must be used instead.
 *
 * @param p_this an existing VLC object
 * @param i_size byte size of the object structure
 * @param i_type object type, usually VLC_OBJECT_CUSTOM
 * @param psz_type object type name
 * @return the created object, or NULL.
 */
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
128
extern void *
129
vlc_custom_create (vlc_object_t *p_this, size_t i_size, int i_type,
130 131
                     const char *psz_type);
#define vlc_custom_create(o, s, t, n) \
132
        vlc_custom_create(VLC_OBJECT(o), s, t, n)
133

134 135 136 137 138 139
/**
 * Assign a name to an object for vlc_object_find_name().
 */
extern int vlc_object_set_name(vlc_object_t *, const char *);
#define vlc_object_set_name(o, n) vlc_object_set_name(VLC_OBJECT(o), n)

140 141 142
/*
 * To be cleaned-up module stuff:
 */
143
extern char *psz_vlcpath;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
144

145
module_t *module_find_by_shortcut (const char *psz_shortcut);
146

147 148 149
/**
 * Private LibVLC data for each object.
 */
150 151 152
typedef struct vlc_object_internals vlc_object_internals_t;

struct vlc_object_internals
153
{
154
    int             i_object_type; /* Object type, deprecated */
155
    char           *psz_name; /* given name */
156

157
    /* Object variables */
158
    void           *var_root;
159
    vlc_mutex_t     var_lock;
160
    vlc_cond_t      var_wait;
161 162

    /* Thread properties, if any */
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
163
    vlc_thread_t    thread_id;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
164
    bool            b_thread;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
165

166 167 168
    /* Objects thread synchronization */
    int             pipes[2];

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
169
    /* Objects management */
170
    vlc_spinlock_t   ref_spin;
171 172
    unsigned         i_refcount;
    vlc_destructor_t pf_destructor;
173

174
    /* Objects tree structure */
175 176 177 178
    vlc_object_internals_t *next;  /* next sibling */
    vlc_object_internals_t *prev;  /* previous sibling */
    vlc_object_internals_t *first; /* first child */
};
179

180 181 182 183 184
#define ZOOM_SECTION N_("Zoom")
#define ZOOM_QUARTER_KEY_TEXT N_("1:4 Quarter")
#define ZOOM_HALF_KEY_TEXT N_("1:2 Half")
#define ZOOM_ORIGINAL_KEY_TEXT N_("1:1 Original")
#define ZOOM_DOUBLE_KEY_TEXT N_("2:1 Double")
185

186
#define vlc_internals( obj ) (((vlc_object_internals_t*)(VLC_OBJECT(obj)))-1)
187
#define vlc_externals( priv ) ((vlc_object_t *)((priv) + 1))
188

189 190
typedef struct sap_handler_t sap_handler_t;

191 192 193 194 195
/**
 * Private LibVLC instance data.
 */
typedef struct libvlc_priv_t
{
196 197
    libvlc_int_t       public_data;

198
    int                i_last_input_id ; ///< Last id of input item
199
    bool               playlist_active;
200

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
201
    /* Messages */
202
    msg_bank_t        *msg_bank;    ///< The message bank
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
203
    int                i_verbose;   ///< info messages
Rémi Duraffort's avatar
Rémi Duraffort committed
204
    bool               b_color;     ///< color messages?
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
205 206

    /* Timer stats */
Rémi Duraffort's avatar
Rémi Duraffort committed
207
    bool               b_stats;     ///< Whether to collect stats
208 209 210
    vlc_mutex_t        timer_lock;  ///< Lock to protect timers
    counter_t        **pp_timers;   ///< Array of all timers
    int                i_timers;    ///< Number of timers
211

212
    /* Singleton objects */
213
    module_t          *p_memcpy_module;  ///< Fast memcpy plugin used
214 215
    playlist_t        *p_playlist; //< the playlist singleton
    vlm_t             *p_vlm;  ///< the VLM singleton (or NULL)
216
    vlc_object_t      *p_dialog_provider; ///< dialog provider
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
217
    httpd_t           *p_httpd; ///< HTTP daemon (src/network/httpd.c)
218 219 220
#ifdef ENABLE_SOUT
    sap_handler_t     *p_sap; ///< SAP SDP advertiser
#endif
221 222 223 224 225

    /* Interfaces */
    struct intf_thread_t *p_intf; ///< Interfaces linked-list

    /* Objects tree */
226
    vlc_mutex_t        structure_lock;
227 228 229

    /* Exit callback */
    vlc_exit_t       exit;
230 231 232 233
} libvlc_priv_t;

static inline libvlc_priv_t *libvlc_priv (libvlc_int_t *libvlc)
{
234
    return (libvlc_priv_t *)libvlc;
235 236
}

237
void playlist_ServicesDiscoveryKillAll( playlist_t *p_playlist );
238
void intf_DestroyAll( libvlc_int_t * );
239

240
#define libvlc_stats( o ) (libvlc_priv((VLC_OBJECT(o))->p_libvlc)->b_stats)
241 242 243 244

/**
 * LibVLC "main module" configuration settings array.
 */
245
extern module_config_t libvlc_config[];
246 247
extern const size_t libvlc_config_count;

248 249 250
/*
 * Variables stuff
 */
251
void var_OptionParse (vlc_object_t *, const char *, bool trusted);
252

253 254 255 256

/*
 * Stats stuff
 */
257 258 259 260 261
int stats_Update (vlc_object_t*, counter_t *, vlc_value_t, vlc_value_t *);
counter_t * stats_CounterCreate (vlc_object_t*, int, int);
#define stats_CounterCreate(a,b,c) stats_CounterCreate( VLC_OBJECT(a), b, c )
int stats_Get (vlc_object_t*, counter_t *, vlc_value_t*);
#define stats_Get(a,b,c) stats_Get( VLC_OBJECT(a), b, c)
262 263 264

void stats_CounterClean (counter_t * );

265 266
static inline int stats_GetInteger( vlc_object_t *p_obj, counter_t *p_counter,
                                    int *value )
267 268 269 270
{
    int i_ret;
    vlc_value_t val; val.i_int = 0;
    if( !p_counter ) return VLC_EGENERIC;
271
    i_ret = stats_Get( p_obj, p_counter, &val );
272 273 274
    *value = val.i_int;
    return i_ret;
}
275
#define stats_GetInteger(a,b,c) stats_GetInteger( VLC_OBJECT(a), b, c )
276

277
static inline int stats_GetFloat( vlc_object_t *p_obj, counter_t *p_counter,
278 279 280 281 282
                                    float *value )
{
    int i_ret;
    vlc_value_t val; val.f_float = 0.0;
    if( !p_counter ) return VLC_EGENERIC;
283
    i_ret = stats_Get( p_obj, p_counter, &val );
284 285 286
    *value = val.f_float;
    return i_ret;
}
287 288 289
#define stats_GetFloat(a,b,c) stats_GetFloat( VLC_OBJECT(a), b, c )

static inline int stats_UpdateInteger( vlc_object_t *p_obj,counter_t *p_co,
290 291 292 293 294 295 296
                                         int i, int *pi_new )
{
    int i_ret;
    vlc_value_t val;
    vlc_value_t new_val; new_val.i_int = 0;
    if( !p_co ) return VLC_EGENERIC;
    val.i_int = i;
297
    i_ret = stats_Update( p_obj, p_co, val, &new_val );
298 299 300 301
    if( pi_new )
        *pi_new = new_val.i_int;
    return i_ret;
}
302 303 304
#define stats_UpdateInteger(a,b,c,d) stats_UpdateInteger( VLC_OBJECT(a),b,c,d )

static inline int stats_UpdateFloat( vlc_object_t *p_obj, counter_t *p_co,
305 306 307 308 309 310 311
                                       float f, float *pf_new )
{
    vlc_value_t val;
    int i_ret;
    vlc_value_t new_val;new_val.f_float = 0.0;
    if( !p_co ) return VLC_EGENERIC;
    val.f_float = f;
312
    i_ret =  stats_Update( p_obj, p_co, val, &new_val );
313 314 315 316
    if( pf_new )
        *pf_new = new_val.f_float;
    return i_ret;
}
317
#define stats_UpdateFloat(a,b,c,d) stats_UpdateFloat( VLC_OBJECT(a),b,c,d )
318 319 320 321 322

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 *) );

323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
/*
 * Replacement functions
 */
# ifndef HAVE_DIRENT_H
typedef void DIR;
#  ifndef FILENAME_MAX
#      define FILENAME_MAX (260)
#  endif
struct dirent
{
    long            d_ino;          /* Always zero. */
    unsigned short  d_reclen;       /* Always zero. */
    unsigned short  d_namlen;       /* Length of name in d_name. */
    char            d_name[FILENAME_MAX]; /* File name. */
};
#  define opendir vlc_opendir
#  define readdir vlc_readdir
#  define closedir vlc_closedir
#  define rewinddir vlc_rewindir
void *vlc_opendir (const char *);
void *vlc_readdir (void *);
int   vlc_closedir(void *);
void  vlc_rewinddir(void *);
# endif

348 349 350
#if defined (WIN32)
#   include <dirent.h>
void *vlc_wopendir (const wchar_t *);
351
/* void *vlc_wclosedir (void *); in vlc's exported symbols */
352 353 354 355 356 357 358 359
struct _wdirent *vlc_wreaddir (void *);
void vlc_rewinddir (void *);
#   define _wopendir vlc_wopendir
#   define _wreaddir vlc_wreaddir
#   define _wclosedir vlc_wclosedir
#   define rewinddir vlc_rewinddir
#endif

360
#endif