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 (LIBVLC_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_INTERNAL_
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
60extern "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
78typedef 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 */
92LIBVLC_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 */
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 ... the arguments for the format string
106 * \return a nul terminated string in any case
107 */
108const char *libvlc_printerr (const char *fmt, ...);
109
110/**@} */
111
112/**
113 * Create and initialize a libvlc instance.
114 * This functions accept a list of "command line" arguments similar to the
115 * main(). These arguments affect the LibVLC instance default configuration.
116 *
117 * \note
118 * LibVLC may create threads. Therefore, any thread-unsafe process
119 * initialization must be performed before calling libvlc_new(). In particular
120 * and where applicable:
121 * - setlocale() and textdomain(),
122 * - setenv(), unsetenv() and putenv(),
123 * - with the X11 display system, XInitThreads()
124 * (see also libvlc_media_player_set_xwindow()) and
125 * - on Microsoft Windows, SetErrorMode().
126 * - sigprocmask() shall never be invoked; pthread_sigmask() can be used.
127 *
128 * On POSIX systems, the SIGCHLD signal <b>must not</b> be ignored, i.e. the
129 * signal handler must set to SIG_DFL or a function pointer, not SIG_IGN.
130 * Also while LibVLC is active, the wait() function shall not be called, and
131 * any call to waitpid() shall use a strictly positive value for the first
132 * parameter (i.e. the PID). Failure to follow those rules may lead to a
133 * deadlock or a busy loop.
134 * Also on POSIX systems, it is recommended that the SIGPIPE signal be blocked,
135 * even if it is not, in principles, necessary, e.g.:
136 * @code
137 sigset_t set;
138
139 signal(SIGCHLD, SIG_DFL);
140 sigemptyset(&set);
141 sigaddset(&set, SIGPIPE);
142 pthread_sigmask(SIG_BLOCK, &set, NULL);
143 * @endcode
144 *
145 * On Microsoft Windows, setting the default DLL directories to SYSTEM32
146 * exclusively is strongly recommended for security reasons:
147 * @code
148 SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);
149 * @endcode
150 *
151 * \version
152 * Arguments are meant to be passed from the command line to LibVLC, just like
153 * VLC media player does. The list of valid arguments depends on the LibVLC
154 * version, the operating system and platform, and set of available LibVLC
155 * plugins. Invalid or unsupported arguments will cause the function to fail
156 * (i.e. return NULL). Also, some arguments may alter the behaviour or
157 * otherwise interfere with other LibVLC functions.
158 *
159 * \warning
160 * There is absolutely no warranty or promise of forward, backward and
161 * cross-platform compatibility with regards to libvlc_new() arguments.
162 * We recommend that you do not use them, other than when debugging.
163 *
164 * \param argc the number of arguments (should be 0)
165 * \param argv list of arguments (should be NULL)
166 * \return the libvlc instance or NULL in case of error
167 */
169libvlc_new( int argc , const char *const *argv );
170
171/**
172 * Decrement the reference count of a libvlc instance, and destroy it
173 * if it reaches zero.
174 *
175 * \param p_instance the instance to destroy
176 */
178
179/**
180 * Increments the reference count of a libvlc instance.
181 * The initial reference count is 1 after libvlc_new() returns.
182 *
183 * \param p_instance the instance to reference
184 * \return the same object
185 */
187
188/**
189 * Get the ABI version of the libvlc library.
190 *
191 * This is different than the VLC version, which is the version of the whole
192 * VLC package. The value is the same as LIBVLC_ABI_VERSION_INT used when
193 * compiling.
194 *
195 * \return a value with the following mask in hexadecimal
196 * 0xFF000000: major VLC version, similar to VLC major version,
197 * 0x00FF0000: major ABI version, incremented incompatible changes are added,
198 * 0x0000FF00: minor ABI version, incremented when new functions are added
199 * 0x000000FF: micro ABI version, incremented with new release/builds
200 *
201 * \note This the same value as the .so version but cross platform.
202 */
204
205/**
206 * Try to start a user interface for the libvlc instance.
207 *
208 * \param p_instance the instance
209 * \param name interface name, or NULL for default
210 * \return 0 on success, -1 on error.
211 */
213int libvlc_add_intf( libvlc_instance_t *p_instance, const char *name );
214
215/**
216 * Registers a callback for the LibVLC exit event. This is mostly useful if
217 * the VLC playlist and/or at least one interface are started with
218 * libvlc_playlist_play() or libvlc_add_intf() respectively.
219 * Typically, this function will wake up your application main loop (from
220 * another thread).
221 *
222 * \note This function should be called before the playlist or interface are
223 * started. Otherwise, there is a small race condition: the exit event could
224 * be raised before the handler is registered.
225 *
226 * \param p_instance LibVLC instance
227 * \param cb callback to invoke when LibVLC wants to exit,
228 * or NULL to disable the exit handler (as by default)
229 * \param opaque data pointer for the callback
230 */
233 void (*cb) (void *), void *opaque );
234
235/**
236 * Sets the application name. LibVLC passes this as the user agent string
237 * when a protocol requires it.
238 *
239 * \param p_instance LibVLC instance
240 * \param name human-readable application name, e.g. "FooBar player 1.2.3"
241 * \param http HTTP User Agent, e.g. "FooBar/1.2.3 Python/2.6.0"
242 * \version LibVLC 1.1.1 or later
243 */
246 const char *name, const char *http );
247
248/**
249 * Sets some meta-information about the application.
250 * See also libvlc_set_user_agent().
251 *
252 * \param p_instance LibVLC instance
253 * \param id Java-style application identifier, e.g. "com.acme.foobar"
254 * \param version application version numbers, e.g. "1.2.3"
255 * \param icon application icon name, e.g. "foobar"
256 * \version LibVLC 2.1.0 or later.
257 */
259void libvlc_set_app_id( libvlc_instance_t *p_instance, const char *id,
260 const char *version, const char *icon );
261
262/**
263 * Retrieve libvlc version.
264 *
265 * Example: "1.1.0-git The Luggage"
266 *
267 * \return a string containing the libvlc version
268 */
270
271/**
272 * Retrieve libvlc compiler version.
273 *
274 * Example: "gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu6)"
275 *
276 * \return a string containing the libvlc compiler version
277 */
279
280/**
281 * Retrieve libvlc changeset.
282 *
283 * Example: "aa9bce0bc4"
284 *
285 * \return a string containing the libvlc changeset
286 */
288
289/**
290 * Frees an heap allocation returned by a LibVLC function.
291 * If you know you're using the same underlying C run-time as the LibVLC
292 * implementation, then you can call ANSI C free() directly instead.
293 *
294 * \param ptr the pointer
295 */
296LIBVLC_API void libvlc_free( void *ptr );
297
298/** \defgroup libvlc_event LibVLC asynchronous events
299 * LibVLC emits asynchronous events.
300 *
301 * Several LibVLC objects (such @ref libvlc_instance_t as
302 * @ref libvlc_media_player_t) generate events asynchronously. Each of them
303 * provides @ref libvlc_event_manager_t event manager. You can subscribe to
304 * events with libvlc_event_attach() and unsubscribe with
305 * libvlc_event_detach().
306 * @{
307 */
308
309/**
310 * Event manager that belongs to a libvlc object, and from whom events can
311 * be received.
312 */
314
315struct libvlc_event_t;
316
317/**
318 * Type of a LibVLC event.
319 */
321
322/**
323 * Callback function notification
324 * \param p_event the event triggering the callback
325 */
326typedef void ( *libvlc_callback_t )( const struct libvlc_event_t *p_event, void *p_data );
327
328/**
329 * Register for an event notification.
330 *
331 * \param p_event_manager the event manager to which you want to attach to.
332 * Generally it is obtained by vlc_my_object_event_manager() where
333 * my_object is the object you want to listen to.
334 * \param i_event_type the desired event to which we want to listen
335 * \param f_callback the function to call when i_event_type occurs
336 * \param user_data user provided data to carry with the event
337 * \return 0 on success, ENOMEM on error
338 */
340 libvlc_event_type_t i_event_type,
341 libvlc_callback_t f_callback,
342 void *user_data );
343
344/**
345 * Unregister an event notification.
346 *
347 * \param p_event_manager the event manager
348 * \param i_event_type the desired event to which we want to unregister
349 * \param f_callback the function to call when i_event_type occurs
350 * \param p_user_data user provided data to carry with the event
351 */
353 libvlc_event_type_t i_event_type,
354 libvlc_callback_t f_callback,
355 void *p_user_data );
356
357/** @} */
358
359/** \defgroup libvlc_log LibVLC logging
360 * libvlc_log_* functions provide access to the LibVLC messages log.
361 * This is used for logging and debugging.
362 * @{
363 */
364
365/**
366 * Logging messages level.
367 * \note Future LibVLC versions may define new levels.
368 */
370{
371 LIBVLC_DEBUG=0, /**< Debug message */
372 LIBVLC_NOTICE=2, /**< Important informational message */
373 LIBVLC_WARNING=3, /**< Warning (potential error) message */
374 LIBVLC_ERROR=4 /**< Error message */
376
377typedef struct vlc_log_t libvlc_log_t;
378
379/**
380 * Gets log message debug infos.
381 *
382 * This function retrieves self-debug information about a log message:
383 * - the name of the VLC module emitting the message,
384 * - the name of the source code module (i.e. file) and
385 * - the line number within the source code module.
386 *
387 * The returned module name and file name will be NULL if unknown.
388 * The returned line number will similarly be zero if unknown.
389 *
390 * \param ctx message context (as passed to the @ref libvlc_log_cb callback)
391 * \param module module name storage (or NULL) [OUT]
392 * \param file source code file name storage (or NULL) [OUT]
393 * \param line source code file line number storage (or NULL) [OUT]
394 * \warning The returned module name and source code file name, if non-NULL,
395 * are only valid until the logging callback returns.
396 *
397 * \version LibVLC 2.1.0 or later
398 */
400 const char **module, const char **file, unsigned *line);
401
402/**
403 * Gets log message info.
404 *
405 * This function retrieves meta-information about a log message:
406 * - the type name of the VLC object emitting the message,
407 * - the object header if any, and
408 * - a temporaly-unique object identifier.
409 *
410 * This information is mainly meant for <b>manual</b> troubleshooting.
411 *
412 * The returned type name may be "generic" if unknown, but it cannot be NULL.
413 * The returned header will be NULL if unset; in current versions, the header
414 * is used to distinguish for VLM inputs.
415 * The returned object ID will be zero if the message is not associated with
416 * any VLC object.
417 *
418 * \param ctx message context (as passed to the @ref libvlc_log_cb callback)
419 * \param name object name storage (or NULL) [OUT]
420 * \param header object header (or NULL) [OUT]
421 * \param id temporarily-unique object identifier (or 0) [OUT]
422 * \warning The returned module name and source code file name, if non-NULL,
423 * are only valid until the logging callback returns.
424 *
425 * \version LibVLC 2.1.0 or later
426 */
428 const char **name, const char **header, uintptr_t *id);
429
430/**
431 * Callback prototype for LibVLC log message handler.
432 *
433 * \param data data pointer as given to libvlc_log_set()
434 * \param level message level (@ref libvlc_log_level)
435 * \param ctx message context (meta-information about the message)
436 * \param fmt printf() format string (as defined by ISO C11)
437 * \param args variable argument list for the format
438 * \note Log message handlers <b>must</b> be thread-safe.
439 * \warning The message context pointer, the format string parameters and the
440 * variable arguments are only valid until the callback returns.
441 */
442typedef void (*libvlc_log_cb)(void *data, int level, const libvlc_log_t *ctx,
443 const char *fmt, va_list args);
444
445/**
446 * Unsets the logging callback.
447 *
448 * This function deregisters the logging callback for a LibVLC instance.
449 * This is rarely needed as the callback is implicitly unset when the instance
450 * is destroyed.
451 *
452 * \note This function will wait for any pending callbacks invocation to
453 * complete (causing a deadlock if called from within the callback).
454 *
455 * \param p_instance libvlc instance
456 * \version LibVLC 2.1.0 or later
457 */
459
460/**
461 * Sets the logging callback for a LibVLC instance.
462 *
463 * This function is thread-safe: it will wait for any pending callbacks
464 * invocation to complete.
465 *
466 * \param cb callback function pointer
467 * \param data opaque data pointer for the callback function
468 *
469 * \note Some log messages (especially debug) are emitted by LibVLC while
470 * is being initialized. These messages cannot be captured with this interface.
471 *
472 * \warning A deadlock may occur if this function is called from the callback.
473 *
474 * \param p_instance libvlc instance
475 * \version LibVLC 2.1.0 or later
476 */
478 libvlc_log_cb cb, void *data );
479
480
481/**
482 * Sets up logging to a file.
483 * \param p_instance libvlc instance
484 * \param stream FILE pointer opened for writing
485 * (the FILE pointer must remain valid until libvlc_log_unset())
486 * \version LibVLC 2.1.0 or later
487 */
488LIBVLC_API void libvlc_log_set_file( libvlc_instance_t *p_instance, FILE *stream );
489
490/** @} */
491
492/**
493 * Description of a module.
494 */
496{
497 char *psz_name;
500 char *psz_help;
504
505/**
506 * Release a list of module descriptions.
507 *
508 * \param p_list the list to be released
509 */
512
513/**
514 * Returns a list of audio filters that are available.
515 *
516 * \param p_instance libvlc instance
517 *
518 * \return a list of module descriptions. It should be freed with libvlc_module_description_list_release().
519 * In case of an error, NULL is returned.
520 *
521 * \see libvlc_module_description_t
522 * \see libvlc_module_description_list_release
523 */
526
527/**
528 * Returns a list of video filters that are available.
529 *
530 * \param p_instance libvlc instance
531 *
532 * \return a list of module descriptions. It should be freed with libvlc_module_description_list_release().
533 * In case of an error, NULL is returned.
534 *
535 * \see libvlc_module_description_t
536 * \see libvlc_module_description_list_release
537 */
540
541/** @} */
542
543/** \defgroup libvlc_clock LibVLC time
544 * These functions provide access to the LibVLC time/clock.
545 * @{
546 */
547
548/**
549 * Return the current time as defined by LibVLC. The unit is the microsecond.
550 * Time increases monotonically (regardless of time zone changes and RTC
551 * adjustments).
552 * The origin is arbitrary but consistent across the whole system
553 * (e.g. the system uptime, the time since the system was booted).
554 * \note On systems that support it, the POSIX monotonic clock is used.
555 */
557int64_t libvlc_clock(void);
558
559/**
560 * Return the delay (in microseconds) until a certain timestamp.
561 * \param pts timestamp
562 * \return negative if timestamp is in the past,
563 * positive if it is in the future
564 */
565static inline int64_t libvlc_delay(int64_t pts)
566{
567 return pts - libvlc_clock();
568}
569
570/** @} */
571
572# ifdef __cplusplus
573}
574# endif
575
576#endif /** @} */
int64_t libvlc_clock(void)
Return the current time as defined by LibVLC.
static int64_t libvlc_delay(int64_t pts)
Return the delay (in microseconds) until a certain timestamp.
Definition: libvlc.h:565
void libvlc_free(void *ptr)
Frees an heap allocation returned by a LibVLC function.
struct libvlc_module_description_t libvlc_module_description_t
Description of a module.
struct libvlc_instance_t libvlc_instance_t
This structure is opaque.
Definition: libvlc.h:76
const char * libvlc_get_version(void)
Retrieve libvlc version.
const char * libvlc_get_compiler(void)
Retrieve libvlc compiler version.
libvlc_instance_t * libvlc_new(int argc, const char *const *argv)
Create and initialize a libvlc instance.
libvlc_module_description_t * libvlc_video_filter_list_get(libvlc_instance_t *p_instance)
Returns a list of video filters that are available.
void libvlc_release(libvlc_instance_t *p_instance)
Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.
void libvlc_set_user_agent(libvlc_instance_t *p_instance, const char *name, const char *http)
Sets the application name.
const char * libvlc_get_changeset(void)
Retrieve libvlc changeset.
int libvlc_add_intf(libvlc_instance_t *p_instance, const char *name)
Try to start a user interface for the libvlc instance.
int64_t libvlc_time_t
Definition: libvlc.h:78
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_module_description_list_release(libvlc_module_description_t *p_list)
Release a list of module descriptions.
libvlc_module_description_t * libvlc_audio_filter_list_get(libvlc_instance_t *p_instance)
Returns a list of audio filters that are available.
int libvlc_abi_version(void)
Get the ABI version of the libvlc library.
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.
libvlc_instance_t * libvlc_retain(libvlc_instance_t *p_instance)
Increments the reference count of a libvlc instance.
const char * libvlc_errmsg(void)
A human-readable error message for the last LibVLC error in the calling thread.
void libvlc_clearerr(void)
Clears the LibVLC error status for the current thread.
const char * libvlc_printerr(const char *fmt,...)
Sets the LibVLC error status and message for the current thread.
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.
int libvlc_event_type_t
Type of a LibVLC event.
Definition: libvlc.h:320
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:313
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.
void(* libvlc_callback_t)(const struct libvlc_event_t *p_event, void *p_data)
Callback function notification.
Definition: libvlc.h:326
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:442
void libvlc_log_set(libvlc_instance_t *p_instance, libvlc_log_cb cb, void *data)
Sets the logging callback for a LibVLC instance.
void libvlc_log_unset(libvlc_instance_t *p_instance)
Unsets the logging callback.
void libvlc_log_get_context(const libvlc_log_t *ctx, const char **module, const char **file, unsigned *line)
Gets log message debug infos.
void libvlc_log_get_object(const libvlc_log_t *ctx, const char **name, const char **header, uintptr_t *id)
Gets log message info.
void libvlc_log_set_file(libvlc_instance_t *p_instance, FILE *stream)
Sets up logging to a file.
libvlc_log_level
Logging messages level.
Definition: libvlc.h:370
@ LIBVLC_ERROR
Error message.
Definition: libvlc.h:374
@ LIBVLC_WARNING
Warning (potential error) message.
Definition: libvlc.h:373
@ LIBVLC_NOTICE
Important informational message.
Definition: libvlc.h:372
@ LIBVLC_DEBUG
Debug message.
Definition: libvlc.h:371
#define LIBVLC_API
Definition: libvlc.h:42
const char name[16]
Definition: httpd.c:1281
A LibVLC event.
Definition: libvlc_events.h:241
Description of a module.
Definition: libvlc.h:496
char * psz_help_html
Definition: libvlc.h:501
struct libvlc_module_description_t * p_next
Definition: libvlc.h:502
char * psz_name
Definition: libvlc.h:497
char * psz_shortname
Definition: libvlc.h:498
char * psz_help
Definition: libvlc.h:500
char * psz_longname
Definition: libvlc.h:499
Log message.
Definition: vlc_messages.h:57
int line
Source code file line number or -1.
Definition: vlc_messages.h:63
const char * file
Source code file name or NULL.
Definition: vlc_messages.h:62