VLC 4.0.0-dev
Loading...
Searching...
No Matches
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 * Sets the application name. LibVLC passes this as the user agent string
207 * when a protocol requires it.
208 *
209 * \param p_instance LibVLC instance
210 * \param name human-readable application name, e.g. "FooBar player 1.2.3"
211 * \param http HTTP User Agent, e.g. "FooBar/1.2.3 Python/2.6.0"
212 * \version LibVLC 1.1.1 or later
213 */
216 const char *name, const char *http );
217
218/**
219 * Sets some meta-information about the application.
220 * See also libvlc_set_user_agent().
221 *
222 * \param p_instance LibVLC instance
223 * \param id Java-style application identifier, e.g. "com.acme.foobar"
224 * \param version application version numbers, e.g. "1.2.3"
225 * \param icon application icon name, e.g. "foobar"
226 * \version LibVLC 2.1.0 or later.
227 */
229void libvlc_set_app_id( libvlc_instance_t *p_instance, const char *id,
230 const char *version, const char *icon );
231
232/**
233 * Retrieve libvlc version.
234 *
235 * Example: "1.1.0-git The Luggage"
236 *
237 * \return a string containing the libvlc version
238 */
240
241/**
242 * Retrieve libvlc compiler version.
243 *
244 * Example: "gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu6)"
245 *
246 * \return a string containing the libvlc compiler version
247 */
249
250/**
251 * Retrieve libvlc changeset.
252 *
253 * Example: "aa9bce0bc4"
254 *
255 * \return a string containing the libvlc changeset
256 */
258
259/**
260 * Frees an heap allocation returned by a LibVLC function.
261 * If you know you're using the same underlying C run-time as the LibVLC
262 * implementation, then you can call ANSI C free() directly instead.
263 *
264 * \param ptr the pointer
265 */
266LIBVLC_API void libvlc_free( void *ptr );
267
268/** \defgroup libvlc_event LibVLC asynchronous events
269 * LibVLC emits asynchronous events.
270 *
271 * Several LibVLC objects (such @ref libvlc_instance_t as
272 * @ref libvlc_media_player_t) generate events asynchronously. Each of them
273 * provides @ref libvlc_event_manager_t event manager. You can subscribe to
274 * events with libvlc_event_attach() and unsubscribe with
275 * libvlc_event_detach().
276 * @{
277 */
278
279/**
280 * Event manager that belongs to a libvlc object, and from whom events can
281 * be received.
282 */
284
285struct libvlc_event_t;
286
287/**
288 * Type of a LibVLC event.
289 */
291
292/**
293 * Callback function notification
294 * \param p_event the event triggering the callback
295 */
296typedef void ( *libvlc_callback_t )( const struct libvlc_event_t *p_event, void *p_data );
297
298/**
299 * Register for an event notification.
300 *
301 * \param p_event_manager the event manager to which you want to attach to.
302 * Generally it is obtained by vlc_my_object_event_manager() where
303 * my_object is the object you want to listen to.
304 * \param i_event_type the desired event to which we want to listen
305 * \param f_callback the function to call when i_event_type occurs
306 * \param user_data user provided data to carry with the event
307 * \return 0 on success, ENOMEM on error
308 */
310 libvlc_event_type_t i_event_type,
311 libvlc_callback_t f_callback,
312 void *user_data );
313
314/**
315 * Unregister an event notification.
316 *
317 * \param p_event_manager the event manager
318 * \param i_event_type the desired event to which we want to unregister
319 * \param f_callback the function to call when i_event_type occurs
320 * \param p_user_data user provided data to carry with the event
321 */
323 libvlc_event_type_t i_event_type,
324 libvlc_callback_t f_callback,
325 void *p_user_data );
326
327/** @} */
328
329/** \defgroup libvlc_log LibVLC logging
330 * libvlc_log_* functions provide access to the LibVLC messages log.
331 * This is used for logging and debugging.
332 * @{
333 */
334
335/**
336 * Logging messages level.
337 * \note Future LibVLC versions may define new levels.
338 */
340{
341 LIBVLC_DEBUG=0, /**< Debug message */
342 LIBVLC_NOTICE=2, /**< Important informational message */
343 LIBVLC_WARNING=3, /**< Warning (potential error) message */
344 LIBVLC_ERROR=4 /**< Error message */
346
347typedef struct vlc_log_t libvlc_log_t;
348
349/**
350 * Gets log message debug infos.
351 *
352 * This function retrieves self-debug information about a log message:
353 * - the name of the VLC module emitting the message,
354 * - the name of the source code module (i.e. file) and
355 * - the line number within the source code module.
356 *
357 * The returned module name and file name will be NULL if unknown.
358 * The returned line number will similarly be zero if unknown.
359 *
360 * \param ctx message context (as passed to the @ref libvlc_log_cb callback)
361 * \param module module name storage (or NULL) [OUT]
362 * \param file source code file name storage (or NULL) [OUT]
363 * \param line source code file line number storage (or NULL) [OUT]
364 * \warning The returned module name and source code file name, if non-NULL,
365 * are only valid until the logging callback returns.
366 *
367 * \version LibVLC 2.1.0 or later
368 */
370 const char **module, const char **file, unsigned *line);
371
372/**
373 * Gets log message info.
374 *
375 * This function retrieves meta-information about a log message:
376 * - the type name of the VLC object emitting the message,
377 * - the object header if any, and
378 * - a temporaly-unique object identifier.
379 *
380 * This information is mainly meant for <b>manual</b> troubleshooting.
381 *
382 * The returned type name may be "generic" if unknown, but it cannot be NULL.
383 * The returned header will be NULL if unset; in current versions, the header
384 * is used to distinguish for VLM inputs.
385 * The returned object ID will be zero if the message is not associated with
386 * any VLC object.
387 *
388 * \param ctx message context (as passed to the @ref libvlc_log_cb callback)
389 * \param name object name storage (or NULL) [OUT]
390 * \param header object header (or NULL) [OUT]
391 * \param id temporarily-unique object identifier (or 0) [OUT]
392 * \warning The returned module name and source code file name, if non-NULL,
393 * are only valid until the logging callback returns.
394 *
395 * \version LibVLC 2.1.0 or later
396 */
398 const char **name, const char **header, uintptr_t *id);
399
400/**
401 * Callback prototype for LibVLC log message handler.
402 *
403 * \param data data pointer as given to libvlc_log_set()
404 * \param level message level (@ref libvlc_log_level)
405 * \param ctx message context (meta-information about the message)
406 * \param fmt printf() format string (as defined by ISO C11)
407 * \param args variable argument list for the format
408 * \note Log message handlers <b>must</b> be thread-safe.
409 * \warning The message context pointer, the format string parameters and the
410 * variable arguments are only valid until the callback returns.
411 */
412typedef void (*libvlc_log_cb)(void *data, int level, const libvlc_log_t *ctx,
413 const char *fmt, va_list args);
414
415/**
416 * Unsets the logging callback.
417 *
418 * This function deregisters the logging callback for a LibVLC instance.
419 * This is rarely needed as the callback is implicitly unset when the instance
420 * is destroyed.
421 *
422 * \note This function will wait for any pending callbacks invocation to
423 * complete (causing a deadlock if called from within the callback).
424 *
425 * \param p_instance libvlc instance
426 * \version LibVLC 2.1.0 or later
427 */
429
430/**
431 * Sets the logging callback for a LibVLC instance.
432 *
433 * This function is thread-safe: it will wait for any pending callbacks
434 * invocation to complete.
435 *
436 * \param cb callback function pointer
437 * \param data opaque data pointer for the callback function
438 *
439 * \note Some log messages (especially debug) are emitted by LibVLC while
440 * is being initialized. These messages cannot be captured with this interface.
441 *
442 * \warning A deadlock may occur if this function is called from the callback.
443 *
444 * \param p_instance libvlc instance
445 * \version LibVLC 2.1.0 or later
446 */
448 libvlc_log_cb cb, void *data );
449
450
451/**
452 * Sets up logging to a file.
453 * \param p_instance libvlc instance
454 * \param stream FILE pointer opened for writing
455 * (the FILE pointer must remain valid until libvlc_log_unset())
456 * \version LibVLC 2.1.0 or later
457 */
458LIBVLC_API void libvlc_log_set_file( libvlc_instance_t *p_instance, FILE *stream );
459
460/** @} */
461
462/**
463 * Description of a module.
464 */
474
475/**
476 * Release a list of module descriptions.
477 *
478 * \param p_list the list to be released
479 */
482
483/**
484 * Returns a list of audio filters that are available.
485 *
486 * \param p_instance libvlc instance
487 *
488 * \return a list of module descriptions. It should be freed with libvlc_module_description_list_release().
489 * In case of an error, NULL is returned.
490 *
491 * \see libvlc_module_description_t
492 * \see libvlc_module_description_list_release
493 */
496
497/**
498 * Returns a list of video filters that are available.
499 *
500 * \param p_instance libvlc instance
501 *
502 * \return a list of module descriptions. It should be freed with libvlc_module_description_list_release().
503 * In case of an error, NULL is returned.
504 *
505 * \see libvlc_module_description_t
506 * \see libvlc_module_description_list_release
507 */
510
511/** @} */
512
513/** \defgroup libvlc_clock LibVLC time
514 * These functions provide access to the LibVLC time/clock.
515 * @{
516 */
517
518/**
519 * Return the current time as defined by LibVLC. The unit is the microsecond.
520 * Time increases monotonically (regardless of time zone changes and RTC
521 * adjustments).
522 * The origin is arbitrary but consistent across the whole system
523 * (e.g. the system uptime, the time since the system was booted).
524 * \note On systems that support it, the POSIX monotonic clock is used.
525 */
527int64_t libvlc_clock(void);
528
529/**
530 * Return the delay (in microseconds) until a certain timestamp.
531 * \param pts timestamp
532 * \return negative if timestamp is in the past,
533 * positive if it is in the future
534 */
535static inline int64_t libvlc_delay(int64_t pts)
536{
537 return pts - libvlc_clock();
538}
539
540/** @} */
541
542# ifdef __cplusplus
543}
544# endif
545
546#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:535
void libvlc_free(void *ptr)
Frees an heap allocation returned by a LibVLC function.
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.
int64_t libvlc_time_t
Definition libvlc.h:78
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:290
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:283
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:296
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:412
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:340
@ LIBVLC_ERROR
Error message.
Definition libvlc.h:344
@ LIBVLC_WARNING
Warning (potential error) message.
Definition libvlc.h:343
@ LIBVLC_NOTICE
Important informational message.
Definition libvlc.h:342
@ LIBVLC_DEBUG
Debug message.
Definition libvlc.h:341
#define LIBVLC_API
Definition libvlc.h:42
const char name[16]
Definition httpd.c:1298
A LibVLC event.
Definition libvlc_events.h:261
Description of a module.
Definition libvlc.h:466
char * psz_help_html
Definition libvlc.h:471
struct libvlc_module_description_t * p_next
Definition libvlc.h:472
char * psz_name
Definition libvlc.h:467
char * psz_shortname
Definition libvlc.h:468
char * psz_help
Definition libvlc.h:470
char * psz_longname
Definition libvlc.h:469
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