VLC  4.0.0-dev
libvlc.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * libvlc.h: libvlc external API
3  *****************************************************************************
4  * Copyright (C) 1998-2009 VLC authors and VideoLAN
5  *
6  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
7  * Jean-Paul Saman <jpsaman@videolan.org>
8  * Pierre d'Herbemont <pdherbemont@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 
25 /**
26  * \defgroup libvlc LibVLC
27  * LibVLC is the external programming interface of the VLC media player.
28  * It is used to embed VLC into other applications or frameworks.
29  * @{
30  * \file
31  * LibVLC core external API
32  */
33 
34 #ifndef VLC_LIBVLC_H
35 #define VLC_LIBVLC_H 1
36 
37 #if defined (_WIN32) && defined (DLL_EXPORT)
38 # define LIBVLC_API __declspec(dllexport)
39 #elif defined (__GNUC__) && (__GNUC__ >= 4)
40 # define LIBVLC_API __attribute__((visibility("default")))
41 #else
42 # define LIBVLC_API
43 #endif
44 
45 #ifdef __LIBVLC__
46 /* Avoid unhelpful warnings from libvlc with our deprecated APIs */
47 # define LIBVLC_DEPRECATED
48 #elif defined(__GNUC__) && \
49  (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
50 # define LIBVLC_DEPRECATED __attribute__((deprecated))
51 #else
52 # define LIBVLC_DEPRECATED
53 #endif
54 
55 #include <stdio.h>
56 #include <stdarg.h>
57 #include <stdint.h>
58 
59 # ifdef __cplusplus
60 extern "C" {
61 # endif
62 
63 /** \defgroup libvlc_core LibVLC core
64  * \ingroup libvlc
65  * Before it can do anything useful, LibVLC must be initialized.
66  * You can create one (or more) instance(s) of LibVLC in a given process,
67  * with libvlc_new() and destroy them with libvlc_release().
68  *
69  * \version Unless otherwise stated, these functions are available
70  * from LibVLC versions numbered 1.1.0 or more.
71  * Earlier versions (0.9.x and 1.0.x) are <b>not</b> compatible.
72  * @{
73  */
74 
75 /** This structure is opaque. It represents a libvlc instance */
77 
78 typedef int64_t libvlc_time_t;
79 
80 /** \defgroup libvlc_error LibVLC error handling
81  * @{
82  */
83 
84 /**
85  * A human-readable error message for the last LibVLC error in the calling
86  * thread. The resulting string is valid until another error occurs (at least
87  * until the next LibVLC call).
88  *
89  * @warning
90  * This will be NULL if there was no error.
91  */
92 LIBVLC_API const char *libvlc_errmsg (void);
93 
94 /**
95  * Clears the LibVLC error status for the current thread. This is optional.
96  * By default, the error status is automatically overridden when a new error
97  * occurs, and destroyed when the thread exits.
98  */
99 LIBVLC_API void libvlc_clearerr (void);
100 
101 /**
102  * Sets the LibVLC error status and message for the current thread.
103  * Any previous error is overridden.
104  * \param fmt the format string
105  * \param ap the arguments
106  * \return a nul terminated string in any case
107  */
108 LIBVLC_API const char *libvlc_vprinterr (const char *fmt, va_list ap);
109 
110 /**
111  * Sets the LibVLC error status and message for the current thread.
112  * Any previous error is overridden.
113  * \param fmt the format string
114  * \param args the arguments
115  * \return a nul terminated string in any case
116  */
117 LIBVLC_API const char *libvlc_printerr (const char *fmt, ...);
118 
119 /**@} */
120 
121 /**
122  * Create and initialize a libvlc instance.
123  * This functions accept a list of "command line" arguments similar to the
124  * main(). These arguments affect the LibVLC instance default configuration.
125  *
126  * \note
127  * LibVLC may create threads. Therefore, any thread-unsafe process
128  * initialization must be performed before calling libvlc_new(). In particular
129  * and where applicable:
130  * - setlocale() and textdomain(),
131  * - setenv(), unsetenv() and putenv(),
132  * - with the X11 display system, XInitThreads()
133  * (see also libvlc_media_player_set_xwindow()) and
134  * - on Microsoft Windows, SetErrorMode().
135  * - sigprocmask() shall never be invoked; pthread_sigmask() can be used.
136  *
137  * On POSIX systems, the SIGCHLD signal <b>must not</b> be ignored, i.e. the
138  * signal handler must set to SIG_DFL or a function pointer, not SIG_IGN.
139  * Also while LibVLC is active, the wait() function shall not be called, and
140  * any call to waitpid() shall use a strictly positive value for the first
141  * parameter (i.e. the PID). Failure to follow those rules may lead to a
142  * deadlock or a busy loop.
143  * Also on POSIX systems, it is recommended that the SIGPIPE signal be blocked,
144  * even if it is not, in principles, necessary, e.g.:
145  * @code
146  sigset_t set;
147 
148  signal(SIGCHLD, SIG_DFL);
149  sigemptyset(&set);
150  sigaddset(&set, SIGPIPE);
151  pthread_sigmask(SIG_BLOCK, &set, NULL);
152  * @endcode
153  *
154  * On Microsoft Windows, setting the default DLL directories to SYSTEM32
155  * exclusively is strongly recommended for security reasons:
156  * @code
157  SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);
158  * @endcode
159  *
160  * \version
161  * Arguments are meant to be passed from the command line to LibVLC, just like
162  * VLC media player does. The list of valid arguments depends on the LibVLC
163  * version, the operating system and platform, and set of available LibVLC
164  * plugins. Invalid or unsupported arguments will cause the function to fail
165  * (i.e. return NULL). Also, some arguments may alter the behaviour or
166  * otherwise interfere with other LibVLC functions.
167  *
168  * \warning
169  * There is absolutely no warranty or promise of forward, backward and
170  * cross-platform compatibility with regards to libvlc_new() arguments.
171  * We recommend that you do not use them, other than when debugging.
172  *
173  * \param argc the number of arguments (should be 0)
174  * \param argv list of arguments (should be NULL)
175  * \return the libvlc instance or NULL in case of error
176  */
178 libvlc_new( int argc , const char *const *argv );
179 
180 /**
181  * Decrement the reference count of a libvlc instance, and destroy it
182  * if it reaches zero.
183  *
184  * \param p_instance the instance to destroy
185  */
186 LIBVLC_API void libvlc_release( libvlc_instance_t *p_instance );
187 
188 /**
189  * Increments the reference count of a libvlc instance.
190  * The initial reference count is 1 after libvlc_new() returns.
191  *
192  * \param p_instance the instance to reference
193  */
194 LIBVLC_API void libvlc_retain( libvlc_instance_t *p_instance );
195 
196 /**
197  * Try to start a user interface for the libvlc instance.
198  *
199  * \param p_instance the instance
200  * \param name interface name, or NULL for default
201  * \return 0 on success, -1 on error.
202  */
204 int libvlc_add_intf( libvlc_instance_t *p_instance, const char *name );
205 
206 /**
207  * Registers a callback for the LibVLC exit event. This is mostly useful if
208  * the VLC playlist and/or at least one interface are started with
209  * libvlc_playlist_play() or libvlc_add_intf() respectively.
210  * Typically, this function will wake up your application main loop (from
211  * another thread).
212  *
213  * \note This function should be called before the playlist or interface are
214  * started. Otherwise, there is a small race condition: the exit event could
215  * be raised before the handler is registered.
216  *
217  * \param p_instance LibVLC instance
218  * \param cb callback to invoke when LibVLC wants to exit,
219  * or NULL to disable the exit handler (as by default)
220  * \param opaque data pointer for the callback
221  */
224  void (*cb) (void *), void *opaque );
225 
226 /**
227  * Sets the application name. LibVLC passes this as the user agent string
228  * when a protocol requires it.
229  *
230  * \param p_instance LibVLC instance
231  * \param name human-readable application name, e.g. "FooBar player 1.2.3"
232  * \param http HTTP User Agent, e.g. "FooBar/1.2.3 Python/2.6.0"
233  * \version LibVLC 1.1.1 or later
234  */
236 void libvlc_set_user_agent( libvlc_instance_t *p_instance,
237  const char *name, const char *http );
238 
239 /**
240  * Sets some meta-information about the application.
241  * See also libvlc_set_user_agent().
242  *
243  * \param p_instance LibVLC instance
244  * \param id Java-style application identifier, e.g. "com.acme.foobar"
245  * \param version application version numbers, e.g. "1.2.3"
246  * \param icon application icon name, e.g. "foobar"
247  * \version LibVLC 2.1.0 or later.
248  */
250 void libvlc_set_app_id( libvlc_instance_t *p_instance, const char *id,
251  const char *version, const char *icon );
252 
253 /**
254  * Retrieve libvlc version.
255  *
256  * Example: "1.1.0-git The Luggage"
257  *
258  * \return a string containing the libvlc version
259  */
260 LIBVLC_API const char * libvlc_get_version(void);
261 
262 /**
263  * Retrieve libvlc compiler version.
264  *
265  * Example: "gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu6)"
266  *
267  * \return a string containing the libvlc compiler version
268  */
269 LIBVLC_API const char * libvlc_get_compiler(void);
270 
271 /**
272  * Retrieve libvlc changeset.
273  *
274  * Example: "aa9bce0bc4"
275  *
276  * \return a string containing the libvlc changeset
277  */
278 LIBVLC_API const char * libvlc_get_changeset(void);
279 
280 /**
281  * Frees an heap allocation returned by a LibVLC function.
282  * If you know you're using the same underlying C run-time as the LibVLC
283  * implementation, then you can call ANSI C free() directly instead.
284  *
285  * \param ptr the pointer
286  */
287 LIBVLC_API void libvlc_free( void *ptr );
288 
289 /** \defgroup libvlc_event LibVLC asynchronous events
290  * LibVLC emits asynchronous events.
291  *
292  * Several LibVLC objects (such @ref libvlc_instance_t as
293  * @ref libvlc_media_player_t) generate events asynchronously. Each of them
294  * provides @ref libvlc_event_manager_t event manager. You can subscribe to
295  * events with libvlc_event_attach() and unsubscribe with
296  * libvlc_event_detach().
297  * @{
298  */
299 
300 /**
301  * Event manager that belongs to a libvlc object, and from whom events can
302  * be received.
303  */
305 
307 
308 /**
309  * Type of a LibVLC event.
310  */
311 typedef int libvlc_event_type_t;
312 
313 /**
314  * Callback function notification
315  * \param p_event the event triggering the callback
316  */
317 typedef void ( *libvlc_callback_t )( const struct libvlc_event_t *p_event, void *p_data );
318 
319 /**
320  * Register for an event notification.
321  *
322  * \param p_event_manager the event manager to which you want to attach to.
323  * Generally it is obtained by vlc_my_object_event_manager() where
324  * my_object is the object you want to listen to.
325  * \param i_event_type the desired event to which we want to listen
326  * \param f_callback the function to call when i_event_type occurs
327  * \param user_data user provided data to carry with the event
328  * \return 0 on success, ENOMEM on error
329  */
331  libvlc_event_type_t i_event_type,
332  libvlc_callback_t f_callback,
333  void *user_data );
334 
335 /**
336  * Unregister an event notification.
337  *
338  * \param p_event_manager the event manager
339  * \param i_event_type the desired event to which we want to unregister
340  * \param f_callback the function to call when i_event_type occurs
341  * \param p_user_data user provided data to carry with the event
342  */
344  libvlc_event_type_t i_event_type,
345  libvlc_callback_t f_callback,
346  void *p_user_data );
347 
348 /** @} */
349 
350 /** \defgroup libvlc_log LibVLC logging
351  * libvlc_log_* functions provide access to the LibVLC messages log.
352  * This is used for logging and debugging.
353  * @{
354  */
355 
356 /**
357  * Logging messages level.
358  * \note Future LibVLC versions may define new levels.
359  */
361 {
362  LIBVLC_DEBUG=0, /**< Debug message */
363  LIBVLC_NOTICE=2, /**< Important informational message */
364  LIBVLC_WARNING=3, /**< Warning (potential error) message */
365  LIBVLC_ERROR=4 /**< Error message */
366 };
367 
368 typedef struct vlc_log_t libvlc_log_t;
369 
370 /**
371  * Gets log message debug infos.
372  *
373  * This function retrieves self-debug information about a log message:
374  * - the name of the VLC module emitting the message,
375  * - the name of the source code module (i.e. file) and
376  * - the line number within the source code module.
377  *
378  * The returned module name and file name will be NULL if unknown.
379  * The returned line number will similarly be zero if unknown.
380  *
381  * \param ctx message context (as passed to the @ref libvlc_log_cb callback)
382  * \param module module name storage (or NULL) [OUT]
383  * \param file source code file name storage (or NULL) [OUT]
384  * \param line source code file line number storage (or NULL) [OUT]
385  * \warning The returned module name and source code file name, if non-NULL,
386  * are only valid until the logging callback returns.
387  *
388  * \version LibVLC 2.1.0 or later
389  */
391  const char **module, const char **file, unsigned *line);
392 
393 /**
394  * Gets log message info.
395  *
396  * This function retrieves meta-information about a log message:
397  * - the type name of the VLC object emitting the message,
398  * - the object header if any, and
399  * - a temporaly-unique object identifier.
400  *
401  * This information is mainly meant for <b>manual</b> troubleshooting.
402  *
403  * The returned type name may be "generic" if unknown, but it cannot be NULL.
404  * The returned header will be NULL if unset; in current versions, the header
405  * is used to distinguish for VLM inputs.
406  * The returned object ID will be zero if the message is not associated with
407  * any VLC object.
408  *
409  * \param ctx message context (as passed to the @ref libvlc_log_cb callback)
410  * \param name object name storage (or NULL) [OUT]
411  * \param header object header (or NULL) [OUT]
412  * \param line source code file line number storage (or NULL) [OUT]
413  * \warning The returned module name and source code file name, if non-NULL,
414  * are only valid until the logging callback returns.
415  *
416  * \version LibVLC 2.1.0 or later
417  */
419  const char **name, const char **header, uintptr_t *id);
420 
421 /**
422  * Callback prototype for LibVLC log message handler.
423  *
424  * \param data data pointer as given to libvlc_log_set()
425  * \param level message level (@ref libvlc_log_level)
426  * \param ctx message context (meta-information about the message)
427  * \param fmt printf() format string (as defined by ISO C11)
428  * \param args variable argument list for the format
429  * \note Log message handlers <b>must</b> be thread-safe.
430  * \warning The message context pointer, the format string parameters and the
431  * variable arguments are only valid until the callback returns.
432  */
433 typedef void (*libvlc_log_cb)(void *data, int level, const libvlc_log_t *ctx,
434  const char *fmt, va_list args);
435 
436 /**
437  * Unsets the logging callback.
438  *
439  * This function deregisters the logging callback for a LibVLC instance.
440  * This is rarely needed as the callback is implicitly unset when the instance
441  * is destroyed.
442  *
443  * \note This function will wait for any pending callbacks invocation to
444  * complete (causing a deadlock if called from within the callback).
445  *
446  * \param p_instance libvlc instance
447  * \version LibVLC 2.1.0 or later
448  */
449 LIBVLC_API void libvlc_log_unset( libvlc_instance_t *p_instance );
450 
451 /**
452  * Sets the logging callback for a LibVLC instance.
453  *
454  * This function is thread-safe: it will wait for any pending callbacks
455  * invocation to complete.
456  *
457  * \param cb callback function pointer
458  * \param data opaque data pointer for the callback function
459  *
460  * \note Some log messages (especially debug) are emitted by LibVLC while
461  * is being initialized. These messages cannot be captured with this interface.
462  *
463  * \warning A deadlock may occur if this function is called from the callback.
464  *
465  * \param p_instance libvlc instance
466  * \version LibVLC 2.1.0 or later
467  */
469  libvlc_log_cb cb, void *data );
470 
471 
472 /**
473  * Sets up logging to a file.
474  * \param p_instance libvlc instance
475  * \param stream FILE pointer opened for writing
476  * (the FILE pointer must remain valid until libvlc_log_unset())
477  * \version LibVLC 2.1.0 or later
478  */
479 LIBVLC_API void libvlc_log_set_file( libvlc_instance_t *p_instance, FILE *stream );
480 
481 /** @} */
482 
483 /**
484  * Description of a module.
485  */
487 {
488  char *psz_name;
491  char *psz_help;
494 
495 /**
496  * Release a list of module descriptions.
497  *
498  * \param p_list the list to be released
499  */
502 
503 /**
504  * Returns a list of audio filters that are available.
505  *
506  * \param p_instance libvlc instance
507  *
508  * \return a list of module descriptions. It should be freed with libvlc_module_description_list_release().
509  * In case of an error, NULL is returned.
510  *
511  * \see libvlc_module_description_t
512  * \see libvlc_module_description_list_release
513  */
516 
517 /**
518  * Returns a list of video filters that are available.
519  *
520  * \param p_instance libvlc instance
521  *
522  * \return a list of module descriptions. It should be freed with libvlc_module_description_list_release().
523  * In case of an error, NULL is returned.
524  *
525  * \see libvlc_module_description_t
526  * \see libvlc_module_description_list_release
527  */
530 
531 /** @} */
532 
533 /** \defgroup libvlc_clock LibVLC time
534  * These functions provide access to the LibVLC time/clock.
535  * @{
536  */
537 
538 /**
539  * Return the current time as defined by LibVLC. The unit is the microsecond.
540  * Time increases monotonically (regardless of time zone changes and RTC
541  * adjustements).
542  * The origin is arbitrary but consistent across the whole system
543  * (e.g. the system uptim, the time since the system was booted).
544  * \note On systems that support it, the POSIX monotonic clock is used.
545  */
547 int64_t libvlc_clock(void);
548 
549 /**
550  * Return the delay (in microseconds) until a certain timestamp.
551  * \param pts timestamp
552  * \return negative if timestamp is in the past,
553  * positive if it is in the future
554  */
555 static inline int64_t libvlc_delay(int64_t pts)
556 {
557  return pts - libvlc_clock();
558 }
559 
560 /** @} */
561 
562 # ifdef __cplusplus
563 }
564 # endif
565 
566 #endif /** @} */
void libvlc_set_user_agent(libvlc_instance_t *p_instance, const char *name, const char *http)
Sets the application name.
const char * libvlc_get_version(void)
Retrieve libvlc version.
const char * libvlc_errmsg(void)
A human-readable error message for the last LibVLC error in the calling thread.
void(* libvlc_callback_t)(const struct libvlc_event_t *p_event, void *p_data)
Callback function notification.
Definition: libvlc.h:317
void libvlc_release(libvlc_instance_t *p_instance)
Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.
const char * libvlc_get_compiler(void)
Retrieve libvlc compiler version.
void libvlc_log_set_file(libvlc_instance_t *p_instance, FILE *stream)
Sets up logging to a file.
struct libvlc_event_manager_t libvlc_event_manager_t
Event manager that belongs to a libvlc object, and from whom events can be received.
Definition: libvlc.h:304
libvlc_module_description_t * libvlc_video_filter_list_get(libvlc_instance_t *p_instance)
Returns a list of video filters that are available.
char * psz_shortname
Definition: libvlc.h:489
#define LIBVLC_API
Definition: libvlc.h:42
Description of a module.
Definition: libvlc.h:486
int libvlc_event_attach(libvlc_event_manager_t *p_event_manager, libvlc_event_type_t i_event_type, libvlc_callback_t f_callback, void *user_data)
Register for an event notification.
const char * libvlc_get_changeset(void)
Retrieve libvlc changeset.
void libvlc_set_app_id(libvlc_instance_t *p_instance, const char *id, const char *version, const char *icon)
Sets some meta-information about the application.
void libvlc_module_description_list_release(libvlc_module_description_t *p_list)
Release a list of module descriptions.
struct libvlc_module_description_t libvlc_module_description_t
Description of a module.
static int64_t libvlc_delay(int64_t pts)
Return the delay (in microseconds) until a certain timestamp.
Definition: libvlc.h:555
void(* libvlc_log_cb)(void *data, int level, const libvlc_log_t *ctx, const char *fmt, va_list args)
Callback prototype for LibVLC log message handler.
Definition: libvlc.h:433
char * psz_name
Definition: libvlc.h:488
int line
Source code file line number or -1.
Definition: vlc_messages.h:63
void libvlc_log_unset(libvlc_instance_t *p_instance)
Unsets the logging callback.
libvlc_log_level
Logging messages level.
Definition: libvlc.h:360
const char name[16]
Definition: httpd.c:1269
void libvlc_set_exit_handler(libvlc_instance_t *p_instance, void(*cb)(void *), void *opaque)
Registers a callback for the LibVLC exit event.
void libvlc_free(void *ptr)
Frees an heap allocation returned by a LibVLC function.
libvlc_module_description_t * libvlc_audio_filter_list_get(libvlc_instance_t *p_instance)
Returns a list of audio filters that are available.
libvlc_instance_t * libvlc_new(int argc, const char *const *argv)
Create and initialize a libvlc instance.
const char * file
Source code file name or NULL.
Definition: vlc_messages.h:62
void libvlc_event_detach(libvlc_event_manager_t *p_event_manager, libvlc_event_type_t i_event_type, libvlc_callback_t f_callback, void *p_user_data)
Unregister an event notification.
struct libvlc_module_description_t * p_next
Definition: libvlc.h:492
const char * libvlc_vprinterr(const char *fmt, va_list ap)
Sets the LibVLC error status and message for the current thread.
struct libvlc_instance_t libvlc_instance_t
This structure is opaque.
Definition: libvlc.h:76
A LibVLC event.
Definition: libvlc_events.h:209
void libvlc_log_get_object(const libvlc_log_t *ctx, const char **name, const char **header, uintptr_t *id)
Gets log message info.
Debug message.
Definition: libvlc.h:362
char * psz_longname
Definition: libvlc.h:490
int64_t libvlc_time_t
Definition: libvlc.h:78
void libvlc_clearerr(void)
Clears the LibVLC error status for the current thread.
Warning (potential error) message.
Definition: libvlc.h:364
int64_t libvlc_clock(void)
Return the current time as defined by LibVLC.
Log message.
Definition: vlc_messages.h:56
char * psz_help
Definition: libvlc.h:491
void libvlc_log_get_context(const libvlc_log_t *ctx, const char **module, const char **file, unsigned *line)
Gets log message debug infos.
Error message.
Definition: libvlc.h:365
int libvlc_add_intf(libvlc_instance_t *p_instance, const char *name)
Try to start a user interface for the libvlc instance.
void libvlc_retain(libvlc_instance_t *p_instance)
Increments the reference count of a libvlc instance.
int libvlc_event_type_t
Type of a LibVLC event.
Definition: libvlc.h:306
Important informational message.
Definition: libvlc.h:363
void libvlc_log_set(libvlc_instance_t *p_instance, libvlc_log_cb cb, void *data)
Sets the logging callback for a LibVLC instance.
const char * libvlc_printerr(const char *fmt,...)
Sets the LibVLC error status and message for the current thread.