]> git.sesse.net Git - vlc/blob - src/libvlc.h
Remove vlc_threads_(init|end), fix thread-safety on Win32
[vlc] / src / libvlc.h
1 /*****************************************************************************
2  * libvlc.h: Internal libvlc generic/misc declaration
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001, 2002 the VideoLAN team
5  * Copyright © 2006-2007 Rémi Denis-Courmont
6  * $Id$
7  *
8  * Authors: Vincent Seguin <seguin@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef LIBVLC_LIBVLC_H
26 # define LIBVLC_LIBVLC_H 1
27
28 typedef struct variable_t variable_t;
29
30 extern const char vlc_usage[];
31
32 /* Hotkey stuff */
33 extern const struct hotkey libvlc_hotkeys[];
34 extern const size_t libvlc_hotkeys_size;
35 extern int vlc_key_to_action (vlc_object_t *, const char *,
36                               vlc_value_t, vlc_value_t, void *);
37
38 /*
39  * OS-specific initialization
40  */
41 void system_Init      ( libvlc_int_t *, int *, const char *[] );
42 void system_Configure ( libvlc_int_t *, int *, const char *[] );
43 void system_End       ( libvlc_int_t * );
44
45 /*
46  * Threads subsystem
47  */
48
49 /* Hopefully, no need to export this. There is a new thread API instead. */
50 void vlc_thread_cancel (vlc_object_t *);
51 int vlc_object_waitpipe (vlc_object_t *obj);
52
53 void vlc_trace (const char *fn, const char *file, unsigned line);
54 #define vlc_backtrace() vlc_trace(__func__, __FILE__, __LINE__)
55
56 #if defined (LIBVLC_USE_PTHREAD) && !defined (NDEBUG)
57 # define vlc_assert_locked( m ) \
58          assert (pthread_mutex_lock (m) == EDEADLK)
59 #else
60 # define vlc_assert_locked( m ) (void)m
61 #endif
62
63 /*
64  * CPU capabilities
65  */
66 extern uint32_t cpu_flags;
67 uint32_t CPUCapabilities( void );
68
69 /*
70  * Message/logging stuff
71  */
72
73 typedef struct msg_queue_t
74 {
75     /** Message queue lock */
76     vlc_mutex_t             lock;
77     bool              b_overflow;
78
79     /* Message queue */
80     msg_item_t              msg[VLC_MSG_QSIZE];           /**< message queue */
81     int i_start;
82     int i_stop;
83
84     /* Subscribers */
85     int i_sub;
86     msg_subscription_t **pp_sub;
87
88     /* Logfile for WinCE */
89 #ifdef UNDER_CE
90     FILE *logfile;
91 #endif
92 } msg_queue_t;
93
94 /**
95  * Store all data required by messages interfaces.
96  */
97 typedef struct msg_bank_t
98 {
99     vlc_mutex_t             lock;
100     msg_queue_t             queue;
101 } msg_bank_t;
102
103 void msg_Create  (libvlc_int_t *);
104 void msg_Flush   (libvlc_int_t *);
105 void msg_Destroy (libvlc_int_t *);
106
107 /** Internal message stack context */
108 void msg_StackSet ( int, const char*, ... );
109 void msg_StackAdd ( const char*, ... );
110 const char* msg_StackMsg ( void );
111 void msg_StackDestroy (void *);
112
113 /*
114  * Unicode stuff
115  */
116 char *vlc_fix_readdir (const char *);
117
118 /*
119  * LibVLC objects stuff
120  */
121
122 /**
123  * Creates a VLC object.
124  *
125  * Note that because the object name pointer must remain valid, potentially
126  * even after the destruction of the object (through the message queues), this
127  * function CANNOT be exported to plugins as is. In this case, the old
128  * vlc_object_create() must be used instead.
129  *
130  * @param p_this an existing VLC object
131  * @param i_size byte size of the object structure
132  * @param i_type object type, usually VLC_OBJECT_CUSTOM
133  * @param psz_type object type name
134  * @return the created object, or NULL.
135  */
136 extern void *
137 __vlc_custom_create (vlc_object_t *p_this, size_t i_size, int i_type,
138                      const char *psz_type);
139 #define vlc_custom_create(o, s, t, n) \
140         __vlc_custom_create(VLC_OBJECT(o), s, t, n)
141
142
143 /**
144  * The module bank
145  */
146 extern module_bank_t *p_module_bank;
147
148 extern char *psz_vlcpath;
149
150 #ifdef LIBVLC_USE_PTHREAD
151 # include <semaphore.h> /* TODO: get rid of vlc_thread_ready and this */
152 #endif
153
154 /**
155  * Private LibVLC data for each object.
156  */
157 typedef struct vlc_object_internals_t
158 {
159     /* Object variables */
160     variable_t *    p_vars;
161     vlc_mutex_t     var_lock;
162     int             i_vars;
163
164     /* Thread properties, if any */
165     vlc_thread_t    thread_id;
166     bool            b_thread;
167 #ifdef LIBVLC_USE_PTHREAD
168     sem_t           thread_ready;
169 #elif defined (WIN32)
170     HANDLE          thread_ready;
171 #endif
172
173     /* Objects thread synchronization */
174     vlc_mutex_t     lock;
175     vlc_cond_t      wait;
176     int             pipes[2];
177     vlc_spinlock_t  spin;
178
179     /* Objects management */
180     vlc_spinlock_t   ref_spin;
181     unsigned         i_refcount;
182     vlc_destructor_t pf_destructor;
183
184     /* Objects tree structure */
185     vlc_object_t    *prev, *next;
186     vlc_object_t   **pp_children;
187     int              i_children;
188 } vlc_object_internals_t;
189
190 #define ZOOM_SECTION N_("Zoom")
191 #define ZOOM_QUARTER_KEY_TEXT N_("1:4 Quarter")
192 #define ZOOM_HALF_KEY_TEXT N_("1:2 Half")
193 #define ZOOM_ORIGINAL_KEY_TEXT N_("1:1 Original")
194 #define ZOOM_DOUBLE_KEY_TEXT N_("2:1 Double")
195
196 #define vlc_internals( obj ) (((vlc_object_internals_t*)(VLC_OBJECT(obj)))-1)
197
198 typedef struct sap_handler_t sap_handler_t;
199
200 /**
201  * Private LibVLC instance data.
202  */
203 typedef struct libvlc_priv_t
204 {
205     libvlc_int_t       public_data;
206
207     /* Configuration */
208     vlc_mutex_t        config_lock; ///< config file lock
209     char *             psz_configfile;   ///< location of config file
210
211     int                i_last_input_id ; ///< Last id of input item
212
213     /* Messages */
214     msg_bank_t         msg_bank;    ///< The message bank
215     int                i_verbose;   ///< info messages
216     bool               b_color;     ///< color messages?
217     vlc_dictionary_t   msg_enabled_objects; ///< Enabled objects
218     bool               msg_all_objects_enabled; ///< Should we print all objects?
219
220     /* Timer stats */
221     vlc_mutex_t        timer_lock;  ///< Lock to protect timers
222     counter_t        **pp_timers;   ///< Array of all timers
223     int                i_timers;    ///< Number of timers
224     bool               b_stats;     ///< Whether to collect stats
225
226     void              *p_stats_computer;  ///< Input thread computing stats
227                                           /// (needs cleanup)
228
229     /* Singleton objects */
230     module_t          *p_memcpy_module;  ///< Fast memcpy plugin used
231     playlist_t        *p_playlist; //< the playlist singleton
232     vlm_t             *p_vlm;  ///< the VLM singleton (or NULL)
233     interaction_t     *p_interaction;    ///< interface interaction object
234     httpd_t           *p_httpd; ///< HTTP daemon (src/network/httpd.c)
235 #ifdef ENABLE_SOUT
236     sap_handler_t     *p_sap; ///< SAP SDP advertiser
237 #endif
238     vlc_mutex_t        structure_lock;
239 } libvlc_priv_t;
240
241 static inline libvlc_priv_t *libvlc_priv (libvlc_int_t *libvlc)
242 {
243     return (libvlc_priv_t *)libvlc;
244 }
245
246 void playlist_ServicesDiscoveryKillAll( playlist_t *p_playlist );
247
248 #define libvlc_stats( o ) (libvlc_priv((VLC_OBJECT(o))->p_libvlc)->b_stats)
249
250 /**
251  * LibVLC "main module" configuration settings array.
252  */
253 extern module_config_t libvlc_config[];
254 extern const size_t libvlc_config_count;
255
256 /*
257  * Variables stuff
258  */
259 void var_OptionParse (vlc_object_t *, const char *, bool trusted);
260
261 /*
262  * Replacement functions
263  */
264 # ifndef HAVE_DIRENT_H
265 typedef void DIR;
266 #  ifndef FILENAME_MAX
267 #      define FILENAME_MAX (260)
268 #  endif
269 struct dirent
270 {
271     long            d_ino;          /* Always zero. */
272     unsigned short  d_reclen;       /* Always zero. */
273     unsigned short  d_namlen;       /* Length of name in d_name. */
274     char            d_name[FILENAME_MAX]; /* File name. */
275 };
276 #  define opendir vlc_opendir
277 #  define readdir vlc_readdir
278 #  define closedir vlc_closedir
279 #  define rewinddir vlc_rewindir
280 void *vlc_opendir (const char *);
281 void *vlc_readdir (void *);
282 int   vlc_closedir(void *);
283 void  vlc_rewinddir(void *);
284 # endif
285
286 #if defined (WIN32)
287 #   include <dirent.h>
288 void *vlc_wopendir (const wchar_t *);
289 /* void *vlc_wclosedir (void *); in vlc's exported symbols */
290 struct _wdirent *vlc_wreaddir (void *);
291 void vlc_rewinddir (void *);
292 #   define _wopendir vlc_wopendir
293 #   define _wreaddir vlc_wreaddir
294 #   define _wclosedir vlc_wclosedir
295 #   define rewinddir vlc_rewinddir
296 #endif
297
298 #endif