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 (__OS2__)) && 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
78/** Represents a time value in microseconds */
79typedef int64_t libvlc_time_t;
80
81/** \defgroup libvlc_error LibVLC error handling
82 * @{
83 */
84
85/**
86 * A human-readable error message for the last LibVLC error in the calling
87 * thread. The resulting string is valid until another error occurs (at least
88 * until the next LibVLC call).
89 *
90 * @warning
91 * This will be NULL if there was no error.
92 */
93LIBVLC_API const char *libvlc_errmsg (void);
94
95/**
96 * Clears the LibVLC error status for the current thread. This is optional.
97 * By default, the error status is automatically overridden when a new error
98 * occurs, and destroyed when the thread exits.
99 */
101
102/**
103 * Sets the LibVLC error status and message for the current thread.
104 * Any previous error is overridden.
105 * \param fmt the format string
106 * \param ... the arguments for the format string
107 * \return a nul terminated string in any case
108 */
109const char *libvlc_printerr (const char *fmt, ...);
110
111/**@} */
112
113/**
114 * Create and initialize a libvlc instance.
115 * This functions accept a list of "command line" arguments similar to the
116 * main(). These arguments affect the LibVLC instance default configuration.
117 *
118 * \note
119 * LibVLC may create threads. Therefore, any thread-unsafe process
120 * initialization must be performed before calling libvlc_new(). In particular
121 * and where applicable:
122 * - setlocale() and textdomain(),
123 * - setenv(), unsetenv() and putenv(),
124 * - with the X11 display system, XInitThreads()
125 * (see also libvlc_media_player_set_xwindow()) and
126 * - on Microsoft Windows, SetErrorMode().
127 * - sigprocmask() shall never be invoked; pthread_sigmask() can be used.
128 *
129 * On POSIX systems, the SIGCHLD signal <b>must not</b> be ignored, i.e. the
130 * signal handler must set to SIG_DFL or a function pointer, not SIG_IGN.
131 * Also while LibVLC is active, the wait() function shall not be called, and
132 * any call to waitpid() shall use a strictly positive value for the first
133 * parameter (i.e. the PID). Failure to follow those rules may lead to a
134 * deadlock or a busy loop.
135 * Also on POSIX systems, it is recommended that the SIGPIPE signal be blocked,
136 * even if it is not, in principles, necessary, e.g.:
137 * @code
138 sigset_t set;
139
140 signal(SIGCHLD, SIG_DFL);
141 sigemptyset(&set);
142 sigaddset(&set, SIGPIPE);
143 pthread_sigmask(SIG_BLOCK, &set, NULL);
144 * @endcode
145 *
146 * On Microsoft Windows, setting the default DLL directories to SYSTEM32
147 * exclusively is strongly recommended for security reasons:
148 * @code
149 SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);
150 * @endcode
151 *
152 * \version
153 * Arguments are meant to be passed from the command line to LibVLC, just like
154 * VLC media player does. The list of valid arguments depends on the LibVLC
155 * version, the operating system and platform, and set of available LibVLC
156 * plugins. Invalid or unsupported arguments will cause the function to fail
157 * (i.e. return NULL). Also, some arguments may alter the behaviour or
158 * otherwise interfere with other LibVLC functions.
159 *
160 * \warning
161 * There is absolutely no warranty or promise of forward, backward and
162 * cross-platform compatibility with regards to libvlc_new() arguments.
163 * We recommend that you do not use them, other than when debugging.
164 *
165 * \param argc the number of arguments (should be 0)
166 * \param argv list of arguments (should be NULL)
167 * \return the libvlc instance or NULL in case of error
168 */
170libvlc_new( int argc , const char *const *argv );
171
172/**
173 * Decrement the reference count of a libvlc instance, and destroy it
174 * if it reaches zero.
175 *
176 * \param p_instance the instance to destroy
177 */
179
180/**
181 * Increments the reference count of a libvlc instance.
182 * The initial reference count is 1 after libvlc_new() returns.
183 *
184 * \param p_instance the instance to reference
185 * \return the same object
186 */
188
189/**
190 * Get the ABI version of the libvlc library.
191 *
192 * This is different than the VLC version, which is the version of the whole
193 * VLC package. The value is the same as LIBVLC_ABI_VERSION_INT used when
194 * compiling.
195 *
196 * \return a value with the following mask in hexadecimal
197 * 0xFF000000: major VLC version, similar to VLC major version,
198 * 0x00FF0000: major ABI version, incremented incompatible changes are added,
199 * 0x0000FF00: minor ABI version, incremented when new functions are added
200 * 0x000000FF: micro ABI version, incremented with new release/builds
201 *
202 * \note This the same value as the .so version but cross platform.
203 */
205
206/**
207 * Sets the application name. LibVLC passes this as the user agent string
208 * when a protocol requires it.
209 *
210 * \param p_instance LibVLC instance
211 * \param name human-readable application name, e.g. "FooBar player 1.2.3"
212 * \param http HTTP User Agent, e.g. "FooBar/1.2.3 Python/2.6.0"
213 * \version LibVLC 1.1.1 or later
214 */
217 const char *name, const char *http );
218
219/**
220 * Sets some meta-information about the application.
221 * See also libvlc_set_user_agent().
222 *
223 * \param p_instance LibVLC instance
224 * \param id Java-style application identifier, e.g. "com.acme.foobar"
225 * \param version application version numbers, e.g. "1.2.3"
226 * \param icon application icon name, e.g. "foobar"
227 * \version LibVLC 2.1.0 or later.
228 */
230void libvlc_set_app_id( libvlc_instance_t *p_instance, const char *id,
231 const char *version, const char *icon );
232
233/**
234 * Retrieve libvlc version.
235 *
236 * Example: "1.1.0-git The Luggage"
237 *
238 * \return a string containing the libvlc version
239 */
241
242/**
243 * Retrieve libvlc compiler version.
244 *
245 * Example: "gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu6)"
246 *
247 * \return a string containing the libvlc compiler version
248 */
250
251/**
252 * Retrieve libvlc changeset.
253 *
254 * Example: "aa9bce0bc4"
255 *
256 * \return a string containing the libvlc changeset
257 */
259
260/**
261 * Frees an heap allocation returned by a LibVLC function.
262 * If you know you're using the same underlying C run-time as the LibVLC
263 * implementation, then you can call ANSI C free() directly instead.
264 *
265 * \param ptr the pointer
266 */
267LIBVLC_API void libvlc_free( void *ptr );
268
269/** \defgroup libvlc_log LibVLC logging
270 * libvlc_log_* functions provide access to the LibVLC messages log.
271 * This is used for logging and debugging.
272 * @{
273 */
274
275/**
276 * Logging messages level.
277 * \note Future LibVLC versions may define new levels.
278 */
280{
281 LIBVLC_DEBUG=0, /**< Debug message */
282 LIBVLC_NOTICE=2, /**< Important informational message */
283 LIBVLC_WARNING=3, /**< Warning (potential error) message */
284 LIBVLC_ERROR=4 /**< Error message */
285};
286
287typedef struct vlc_log_t libvlc_log_t;
288
289/**
290 * Gets log message debug infos.
291 *
292 * This function retrieves self-debug information about a log message:
293 * - the name of the VLC module emitting the message,
294 * - the name of the source code module (i.e. file) and
295 * - the line number within the source code module.
296 *
297 * The returned module name and file name will be NULL if unknown.
298 * The returned line number will similarly be zero if unknown.
299 *
300 * \param ctx message context (as passed to the @ref libvlc_log_cb callback)
301 * \param module module name storage (or NULL) [OUT]
302 * \param file source code file name storage (or NULL) [OUT]
303 * \param line source code file line number storage (or NULL) [OUT]
304 * \warning The returned module name and source code file name, if non-NULL,
305 * are only valid until the logging callback returns.
306 *
307 * \version LibVLC 2.1.0 or later
308 */
310 const char **module, const char **file, unsigned *line);
311
312/**
313 * Gets log message info.
314 *
315 * This function retrieves meta-information about a log message:
316 * - the type name of the VLC object emitting the message,
317 * - the object header if any, and
318 * - a temporaly-unique object identifier.
319 *
320 * This information is mainly meant for <b>manual</b> troubleshooting.
321 *
322 * The returned type name may be "generic" if unknown, but it cannot be NULL.
323 * The returned header will be NULL if unset; in current versions, the header
324 * is used to distinguish for VLM inputs.
325 * The returned object ID will be zero if the message is not associated with
326 * any VLC object.
327 *
328 * \param ctx message context (as passed to the @ref libvlc_log_cb callback)
329 * \param name object name storage (or NULL) [OUT]
330 * \param header object header (or NULL) [OUT]
331 * \param id temporarily-unique object identifier (or 0) [OUT]
332 * \warning The returned module name and source code file name, if non-NULL,
333 * are only valid until the logging callback returns.
334 *
335 * \version LibVLC 2.1.0 or later
336 */
338 const char **name, const char **header, uintptr_t *id);
339
340/**
341 * Callback prototype for LibVLC log message handler.
342 *
343 * \param data data pointer as given to libvlc_log_set()
344 * \param level message level (@ref libvlc_log_level)
345 * \param ctx message context (meta-information about the message)
346 * \param fmt printf() format string (as defined by ISO C11)
347 * \param args variable argument list for the format
348 * \note Log message handlers <b>must</b> be thread-safe.
349 * \warning The message context pointer, the format string parameters and the
350 * variable arguments are only valid until the callback returns.
351 */
352typedef void (*libvlc_log_cb)(void *data, int level, const libvlc_log_t *ctx,
353 const char *fmt, va_list args);
354
355/**
356 * Unsets the logging callback.
357 *
358 * This function deregisters the logging callback for a LibVLC instance.
359 * This is rarely needed as the callback is implicitly unset when the instance
360 * is destroyed.
361 *
362 * \note This function will wait for any pending callbacks invocation to
363 * complete (causing a deadlock if called from within the callback).
364 *
365 * \param p_instance libvlc instance
366 * \version LibVLC 2.1.0 or later
367 */
369
370/**
371 * Sets the logging callback for a LibVLC instance.
372 *
373 * This function is thread-safe: it will wait for any pending callbacks
374 * invocation to complete.
375 *
376 * \param cb callback function pointer
377 * \param data opaque data pointer for the callback function
378 *
379 * \note Some log messages (especially debug) are emitted by LibVLC while
380 * is being initialized. These messages cannot be captured with this interface.
381 *
382 * \warning A deadlock may occur if this function is called from the callback.
383 *
384 * \param p_instance libvlc instance
385 * \version LibVLC 2.1.0 or later
386 */
388 libvlc_log_cb cb, void *data );
389
390
391/**
392 * Sets up logging to a file.
393 * \param p_instance libvlc instance
394 * \param stream FILE pointer opened for writing
395 * (the FILE pointer must remain valid until libvlc_log_unset())
396 * \version LibVLC 2.1.0 or later
397 */
398LIBVLC_API void libvlc_log_set_file( libvlc_instance_t *p_instance, FILE *stream );
399
400/** @} */
401
402/**
403 * Description of a module.
404 */
414
415/**
416 * Release a list of module descriptions.
417 *
418 * \param p_list the list to be released
419 */
422
423/**
424 * Returns a list of audio filters that are available.
425 *
426 * \param p_instance libvlc instance
427 *
428 * \return a list of module descriptions. It should be freed with libvlc_module_description_list_release().
429 * In case of an error, NULL is returned.
430 *
431 * \see libvlc_module_description_t
432 * \see libvlc_module_description_list_release
433 */
436
437/**
438 * Returns a list of video filters that are available.
439 *
440 * \param p_instance libvlc instance
441 *
442 * \return a list of module descriptions. It should be freed with libvlc_module_description_list_release().
443 * In case of an error, NULL is returned.
444 *
445 * \see libvlc_module_description_t
446 * \see libvlc_module_description_list_release
447 */
450
451/** @} */
452
453/** \defgroup libvlc_clock LibVLC time
454 * These functions provide access to the LibVLC time/clock.
455 * @{
456 */
457
458/**
459 * Return the current time as defined by LibVLC. The unit is the microsecond.
460 * Time increases monotonically (regardless of time zone changes and RTC
461 * adjustments).
462 * The origin is arbitrary but consistent across the whole system
463 * (e.g. the system uptime, the time since the system was booted).
464 * \note On systems that support it, the POSIX monotonic clock is used.
465 */
468
469/**
470 * Return the delay (in microseconds) until a certain timestamp.
471 * \param pts timestamp
472 * \return negative if timestamp is in the past,
473 * positive if it is in the future
474 */
476{
477 return pts - libvlc_clock();
478}
479
480/** @} */
481
482# ifdef __cplusplus
483}
484# endif
485
486#endif /** @} */
static libvlc_time_t libvlc_delay(libvlc_time_t pts)
Return the delay (in microseconds) until a certain timestamp.
Definition libvlc.h:475
libvlc_time_t libvlc_clock(void)
Return the current time as defined by LibVLC.
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
Represents a time value in microseconds.
Definition libvlc.h:79
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.
struct vlc_log_t libvlc_log_t
Definition libvlc.h:287
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:352
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:280
@ LIBVLC_ERROR
Error message.
Definition libvlc.h:284
@ LIBVLC_WARNING
Warning (potential error) message.
Definition libvlc.h:283
@ LIBVLC_NOTICE
Important informational message.
Definition libvlc.h:282
@ LIBVLC_DEBUG
Debug message.
Definition libvlc.h:281
#define LIBVLC_API
Definition libvlc.h:42
const char name[16]
Definition httpd.c:1298
Description of a module.
Definition libvlc.h:406
char * psz_help_html
Definition libvlc.h:411
struct libvlc_module_description_t * p_next
Definition libvlc.h:412
char * psz_name
Definition libvlc.h:407
char * psz_shortname
Definition libvlc.h:408
char * psz_help
Definition libvlc.h:410
char * psz_longname
Definition libvlc.h:409
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