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