audiotrack: avoid cast, use proper type
[vlc.git] / include / vlc / libvlc.h
blob1c2550fe3be1d81c156f6054049262f0d8618bb9
1 /*****************************************************************************
2 * libvlc.h: libvlc external API
3 *****************************************************************************
4 * Copyright (C) 1998-2009 VLC authors and VideoLAN
6 * Authors: Clément Stenac <zorglub@videolan.org>
7 * Jean-Paul Saman <jpsaman@videolan.org>
8 * Pierre d'Herbemont <pdherbemont@videolan.org>
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.
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.
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 *****************************************************************************/
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
34 #ifndef VLC_LIBVLC_H
35 #define VLC_LIBVLC_H 1
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
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
55 #include <stdio.h>
56 #include <stdarg.h>
57 #include <stdint.h>
59 # ifdef __cplusplus
60 extern "C" {
61 # endif
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().
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 * @{
75 /** This structure is opaque. It represents a libvlc instance */
76 typedef struct libvlc_instance_t libvlc_instance_t;
78 typedef int64_t libvlc_time_t;
80 /** \defgroup libvlc_error LibVLC error handling
81 * @{
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).
89 * @warning
90 * This will be NULL if there was no error.
92 LIBVLC_API const char *libvlc_errmsg (void);
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.
99 LIBVLC_API void libvlc_clearerr (void);
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
108 LIBVLC_API const char *libvlc_vprinterr (const char *fmt, va_list ap);
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
117 LIBVLC_API const char *libvlc_printerr (const char *fmt, ...);
119 /**@} */
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.
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.
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;
148 signal(SIGCHLD, SIG_DFL);
149 sigemptyset(&set);
150 sigaddset(&set, SIGPIPE);
151 pthread_sigmask(SIG_BLOCK, &set, NULL);
152 * @endcode
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
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.
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.
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
177 LIBVLC_API libvlc_instance_t *
178 libvlc_new( int argc , const char *const *argv );
181 * Decrement the reference count of a libvlc instance, and destroy it
182 * if it reaches zero.
184 * \param p_instance the instance to destroy
186 LIBVLC_API void libvlc_release( libvlc_instance_t *p_instance );
189 * Increments the reference count of a libvlc instance.
190 * The initial reference count is 1 after libvlc_new() returns.
192 * \param p_instance the instance to reference
194 LIBVLC_API void libvlc_retain( libvlc_instance_t *p_instance );
197 * Try to start a user interface for the libvlc instance.
199 * \param p_instance the instance
200 * \param name interface name, or NULL for default
201 * \return 0 on success, -1 on error.
203 LIBVLC_API
204 int libvlc_add_intf( libvlc_instance_t *p_instance, const char *name );
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).
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.
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
222 LIBVLC_API
223 void libvlc_set_exit_handler( libvlc_instance_t *p_instance,
224 void (*cb) (void *), void *opaque );
227 * Sets the application name. LibVLC passes this as the user agent string
228 * when a protocol requires it.
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
235 LIBVLC_API
236 void libvlc_set_user_agent( libvlc_instance_t *p_instance,
237 const char *name, const char *http );
240 * Sets some meta-information about the application.
241 * See also libvlc_set_user_agent().
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.
249 LIBVLC_API
250 void libvlc_set_app_id( libvlc_instance_t *p_instance, const char *id,
251 const char *version, const char *icon );
254 * Retrieve libvlc version.
256 * Example: "1.1.0-git The Luggage"
258 * \return a string containing the libvlc version
260 LIBVLC_API const char * libvlc_get_version(void);
263 * Retrieve libvlc compiler version.
265 * Example: "gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu6)"
267 * \return a string containing the libvlc compiler version
269 LIBVLC_API const char * libvlc_get_compiler(void);
272 * Retrieve libvlc changeset.
274 * Example: "aa9bce0bc4"
276 * \return a string containing the libvlc changeset
278 LIBVLC_API const char * libvlc_get_changeset(void);
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.
285 * \param ptr the pointer
287 LIBVLC_API void libvlc_free( void *ptr );
289 /** \defgroup libvlc_event LibVLC asynchronous events
290 * LibVLC emits asynchronous events.
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 * @{
301 * Event manager that belongs to a libvlc object, and from whom events can
302 * be received.
304 typedef struct libvlc_event_manager_t libvlc_event_manager_t;
306 struct libvlc_event_t;
309 * Type of a LibVLC event.
311 typedef int libvlc_event_type_t;
314 * Callback function notification
315 * \param p_event the event triggering the callback
317 typedef void ( *libvlc_callback_t )( const struct libvlc_event_t *p_event, void *p_data );
320 * Register for an event notification.
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
330 LIBVLC_API int libvlc_event_attach( libvlc_event_manager_t *p_event_manager,
331 libvlc_event_type_t i_event_type,
332 libvlc_callback_t f_callback,
333 void *user_data );
336 * Unregister an event notification.
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
343 LIBVLC_API void libvlc_event_detach( libvlc_event_manager_t *p_event_manager,
344 libvlc_event_type_t i_event_type,
345 libvlc_callback_t f_callback,
346 void *p_user_data );
348 /** @} */
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 * @{
357 * Logging messages level.
358 * \note Future LibVLC versions may define new levels.
360 enum libvlc_log_level
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 */
368 typedef struct vlc_log_t libvlc_log_t;
371 * Gets log message debug infos.
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.
378 * The returned module name and file name will be NULL if unknown.
379 * The returned line number will similarly be zero if unknown.
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.
388 * \version LibVLC 2.1.0 or later
390 LIBVLC_API void libvlc_log_get_context(const libvlc_log_t *ctx,
391 const char **module, const char **file, unsigned *line);
394 * Gets log message info.
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.
401 * This information is mainly meant for <b>manual</b> troubleshooting.
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.
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.
416 * \version LibVLC 2.1.0 or later
418 LIBVLC_API void libvlc_log_get_object(const libvlc_log_t *ctx,
419 const char **name, const char **header, uintptr_t *id);
422 * Callback prototype for LibVLC log message handler.
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.
433 typedef void (*libvlc_log_cb)(void *data, int level, const libvlc_log_t *ctx,
434 const char *fmt, va_list args);
437 * Unsets the logging callback.
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.
443 * \note This function will wait for any pending callbacks invocation to
444 * complete (causing a deadlock if called from within the callback).
446 * \param p_instance libvlc instance
447 * \version LibVLC 2.1.0 or later
449 LIBVLC_API void libvlc_log_unset( libvlc_instance_t *p_instance );
452 * Sets the logging callback for a LibVLC instance.
454 * This function is thread-safe: it will wait for any pending callbacks
455 * invocation to complete.
457 * \param cb callback function pointer
458 * \param data opaque data pointer for the callback function
460 * \note Some log messages (especially debug) are emitted by LibVLC while
461 * is being initialized. These messages cannot be captured with this interface.
463 * \warning A deadlock may occur if this function is called from the callback.
465 * \param p_instance libvlc instance
466 * \version LibVLC 2.1.0 or later
468 LIBVLC_API void libvlc_log_set( libvlc_instance_t *p_instance,
469 libvlc_log_cb cb, void *data );
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
479 LIBVLC_API void libvlc_log_set_file( libvlc_instance_t *p_instance, FILE *stream );
481 /** @} */
484 * Description of a module.
486 typedef struct libvlc_module_description_t
488 char *psz_name;
489 char *psz_shortname;
490 char *psz_longname;
491 char *psz_help;
492 struct libvlc_module_description_t *p_next;
493 } libvlc_module_description_t;
496 * Release a list of module descriptions.
498 * \param p_list the list to be released
500 LIBVLC_API
501 void libvlc_module_description_list_release( libvlc_module_description_t *p_list );
504 * Returns a list of audio filters that are available.
506 * \param p_instance libvlc instance
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.
511 * \see libvlc_module_description_t
512 * \see libvlc_module_description_list_release
514 LIBVLC_API
515 libvlc_module_description_t *libvlc_audio_filter_list_get( libvlc_instance_t *p_instance );
518 * Returns a list of video filters that are available.
520 * \param p_instance libvlc instance
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.
525 * \see libvlc_module_description_t
526 * \see libvlc_module_description_list_release
528 LIBVLC_API
529 libvlc_module_description_t *libvlc_video_filter_list_get( libvlc_instance_t *p_instance );
531 /** @} */
533 /** \defgroup libvlc_clock LibVLC time
534 * These functions provide access to the LibVLC time/clock.
535 * @{
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.
546 LIBVLC_API
547 int64_t libvlc_clock(void);
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
555 static inline int64_t libvlc_delay(int64_t pts)
557 return pts - libvlc_clock();
560 /** @} */
562 # ifdef __cplusplus
564 # endif
566 #endif /** @} */