00001 /***************************************************************************** 00002 * libvlc.h: libvlc external API 00003 ***************************************************************************** 00004 * Copyright (C) 1998-2009 VLC authors and VideoLAN 00005 * $Id: 65056b4613ea7bfc2aa9af56ff26dff5d8aeae1b $ 00006 * 00007 * Authors: Clément Stenac <zorglub@videolan.org> 00008 * Jean-Paul Saman <jpsaman@videolan.org> 00009 * Pierre d'Herbemont <pdherbemont@videolan.org> 00010 * 00011 * This program is free software; you can redistribute it and/or modify it 00012 * under the terms of the GNU Lesser General Public License as published by 00013 * the Free Software Foundation; either version 2.1 of the License, or 00014 * (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public License 00022 * along with this program; if not, write to the Free Software Foundation, 00023 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 00024 *****************************************************************************/ 00025 00026 /** 00027 * \file 00028 * This file defines libvlc external API 00029 */ 00030 00031 /** 00032 * \defgroup libvlc LibVLC 00033 * LibVLC is the external programming interface of the VLC media player. 00034 * It is used to embed VLC into other applications or frameworks. 00035 * @{ 00036 */ 00037 00038 #ifndef VLC_LIBVLC_H 00039 #define VLC_LIBVLC_H 1 00040 00041 #if defined (WIN32) && defined (DLL_EXPORT) 00042 # define LIBVLC_API __declspec(dllexport) 00043 #elif defined (__GNUC__) && (__GNUC__ >= 4) 00044 # define LIBVLC_API __attribute__((visibility("default"))) 00045 #else 00046 # define LIBVLC_API 00047 #endif 00048 00049 #ifdef __LIBVLC__ 00050 /* Avoid unhelpful warnings from libvlc with our deprecated APIs */ 00051 # define LIBVLC_DEPRECATED 00052 #elif defined(__GNUC__) && \ 00053 (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) 00054 # define LIBVLC_DEPRECATED __attribute__((deprecated)) 00055 #else 00056 # define LIBVLC_DEPRECATED 00057 #endif 00058 00059 #include <stdio.h> 00060 #include <stdarg.h> 00061 00062 # ifdef __cplusplus 00063 extern "C" { 00064 # endif 00065 00066 #include <vlc/libvlc_structures.h> 00067 00068 /** \defgroup libvlc_core LibVLC core 00069 * \ingroup libvlc 00070 * Before it can do anything useful, LibVLC must be initialized. 00071 * You can create one (or more) instance(s) of LibVLC in a given process, 00072 * with libvlc_new() and destroy them with libvlc_release(). 00073 * 00074 * \version Unless otherwise stated, these functions are available 00075 * from LibVLC versions numbered 1.1.0 or more. 00076 * Earlier versions (0.9.x and 1.0.x) are <b>not</b> compatible. 00077 * @{ 00078 */ 00079 00080 /** \defgroup libvlc_error LibVLC error handling 00081 * @{ 00082 */ 00083 00084 /** 00085 * A human-readable error message for the last LibVLC error in the calling 00086 * thread. The resulting string is valid until another error occurs (at least 00087 * until the next LibVLC call). 00088 * 00089 * @warning 00090 * This will be NULL if there was no error. 00091 */ 00092 LIBVLC_API const char *libvlc_errmsg (void); 00093 00094 /** 00095 * Clears the LibVLC error status for the current thread. This is optional. 00096 * By default, the error status is automatically overridden when a new error 00097 * occurs, and destroyed when the thread exits. 00098 */ 00099 LIBVLC_API void libvlc_clearerr (void); 00100 00101 /** 00102 * Sets the LibVLC error status and message for the current thread. 00103 * Any previous error is overridden. 00104 * \return a nul terminated string in any case 00105 */ 00106 LIBVLC_API const char *libvlc_vprinterr (const char *fmt, va_list ap); 00107 00108 /** 00109 * Sets the LibVLC error status and message for the current thread. 00110 * Any previous error is overridden. 00111 * \return a nul terminated string in any case 00112 */ 00113 LIBVLC_API const char *libvlc_printerr (const char *fmt, ...); 00114 00115 /**@} */ 00116 00117 /** 00118 * Create and initialize a libvlc instance. 00119 * This functions accept a list of "command line" arguments similar to the 00120 * main(). These arguments affect the LibVLC instance default configuration. 00121 * 00122 * \version 00123 * Arguments are meant to be passed from the command line to LibVLC, just like 00124 * VLC media player does. The list of valid arguments depends on the LibVLC 00125 * version, the operating system and platform, and set of available LibVLC 00126 * plugins. Invalid or unsupported arguments will cause the function to fail 00127 * (i.e. return NULL). Also, some arguments may alter the behaviour or 00128 * otherwise interfere with other LibVLC functions. 00129 * 00130 * \warning 00131 * There is absolutely no warranty or promise of forward, backward and 00132 * cross-platform compatibility with regards to libvlc_new() arguments. 00133 * We recommend that you do not use them, other than when debugging. 00134 * 00135 * \param argc the number of arguments (should be 0) 00136 * \param argv list of arguments (should be NULL) 00137 * \return the libvlc instance or NULL in case of error 00138 */ 00139 LIBVLC_API libvlc_instance_t * 00140 libvlc_new( int argc , const char *const *argv ); 00141 00142 /** 00143 * Decrement the reference count of a libvlc instance, and destroy it 00144 * if it reaches zero. 00145 * 00146 * \param p_instance the instance to destroy 00147 */ 00148 LIBVLC_API void libvlc_release( libvlc_instance_t *p_instance ); 00149 00150 /** 00151 * Increments the reference count of a libvlc instance. 00152 * The initial reference count is 1 after libvlc_new() returns. 00153 * 00154 * \param p_instance the instance to reference 00155 */ 00156 LIBVLC_API void libvlc_retain( libvlc_instance_t *p_instance ); 00157 00158 /** 00159 * Try to start a user interface for the libvlc instance. 00160 * 00161 * \param p_instance the instance 00162 * \param name interface name, or NULL for default 00163 * \return 0 on success, -1 on error. 00164 */ 00165 LIBVLC_API 00166 int libvlc_add_intf( libvlc_instance_t *p_instance, const char *name ); 00167 00168 /** 00169 * Registers a callback for the LibVLC exit event. This is mostly useful if 00170 * you have started at least one interface with libvlc_add_intf(). 00171 * Typically, this function will wake up your application main loop (from 00172 * another thread). 00173 * 00174 * \param p_instance LibVLC instance 00175 * \param cb callback to invoke when LibVLC wants to exit 00176 * \param opaque data pointer for the callback 00177 * \warning This function and libvlc_wait() cannot be used at the same time. 00178 * Use either or none of them but not both. 00179 */ 00180 LIBVLC_API 00181 void libvlc_set_exit_handler( libvlc_instance_t *p_instance, 00182 void (*cb) (void *), void *opaque ); 00183 00184 /** 00185 * Waits until an interface causes the instance to exit. 00186 * You should start at least one interface first, using libvlc_add_intf(). 00187 * 00188 * \param p_instance the instance 00189 */ 00190 LIBVLC_API 00191 void libvlc_wait( libvlc_instance_t *p_instance ); 00192 00193 /** 00194 * Sets the application name. LibVLC passes this as the user agent string 00195 * when a protocol requires it. 00196 * 00197 * \param p_instance LibVLC instance 00198 * \param name human-readable application name, e.g. "FooBar player 1.2.3" 00199 * \param http HTTP User Agent, e.g. "FooBar/1.2.3 Python/2.6.0" 00200 * \version LibVLC 1.1.1 or later 00201 */ 00202 LIBVLC_API 00203 void libvlc_set_user_agent( libvlc_instance_t *p_instance, 00204 const char *name, const char *http ); 00205 00206 /** 00207 * Retrieve libvlc version. 00208 * 00209 * Example: "1.1.0-git The Luggage" 00210 * 00211 * \return a string containing the libvlc version 00212 */ 00213 LIBVLC_API const char * libvlc_get_version(void); 00214 00215 /** 00216 * Retrieve libvlc compiler version. 00217 * 00218 * Example: "gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu6)" 00219 * 00220 * \return a string containing the libvlc compiler version 00221 */ 00222 LIBVLC_API const char * libvlc_get_compiler(void); 00223 00224 /** 00225 * Retrieve libvlc changeset. 00226 * 00227 * Example: "aa9bce0bc4" 00228 * 00229 * \return a string containing the libvlc changeset 00230 */ 00231 LIBVLC_API const char * libvlc_get_changeset(void); 00232 00233 /** 00234 * Frees an heap allocation returned by a LibVLC function. 00235 * If you know you're using the same underlying C run-time as the LibVLC 00236 * implementation, then you can call ANSI C free() directly instead. 00237 * 00238 * \param ptr the pointer 00239 */ 00240 LIBVLC_API void libvlc_free( void *ptr ); 00241 00242 /** \defgroup libvlc_event LibVLC asynchronous events 00243 * LibVLC emits asynchronous events. 00244 * 00245 * Several LibVLC objects (such @ref libvlc_instance_t as 00246 * @ref libvlc_media_player_t) generate events asynchronously. Each of them 00247 * provides @ref libvlc_event_manager_t event manager. You can subscribe to 00248 * events with libvlc_event_attach() and unsubscribe with 00249 * libvlc_event_detach(). 00250 * @{ 00251 */ 00252 00253 /** 00254 * Event manager that belongs to a libvlc object, and from whom events can 00255 * be received. 00256 */ 00257 typedef struct libvlc_event_manager_t libvlc_event_manager_t; 00258 00259 struct libvlc_event_t; 00260 00261 /** 00262 * Type of a LibVLC event. 00263 */ 00264 typedef int libvlc_event_type_t; 00265 00266 /** 00267 * Callback function notification 00268 * \param p_event the event triggering the callback 00269 */ 00270 typedef void ( *libvlc_callback_t )( const struct libvlc_event_t *, void * ); 00271 00272 /** 00273 * Register for an event notification. 00274 * 00275 * \param p_event_manager the event manager to which you want to attach to. 00276 * Generally it is obtained by vlc_my_object_event_manager() where 00277 * my_object is the object you want to listen to. 00278 * \param i_event_type the desired event to which we want to listen 00279 * \param f_callback the function to call when i_event_type occurs 00280 * \param user_data user provided data to carry with the event 00281 * \return 0 on success, ENOMEM on error 00282 */ 00283 LIBVLC_API int libvlc_event_attach( libvlc_event_manager_t *p_event_manager, 00284 libvlc_event_type_t i_event_type, 00285 libvlc_callback_t f_callback, 00286 void *user_data ); 00287 00288 /** 00289 * Unregister an event notification. 00290 * 00291 * \param p_event_manager the event manager 00292 * \param i_event_type the desired event to which we want to unregister 00293 * \param f_callback the function to call when i_event_type occurs 00294 * \param p_user_data user provided data to carry with the event 00295 */ 00296 LIBVLC_API void libvlc_event_detach( libvlc_event_manager_t *p_event_manager, 00297 libvlc_event_type_t i_event_type, 00298 libvlc_callback_t f_callback, 00299 void *p_user_data ); 00300 00301 /** 00302 * Get an event's type name. 00303 * 00304 * \param event_type the desired event 00305 */ 00306 LIBVLC_API const char * libvlc_event_type_name( libvlc_event_type_t event_type ); 00307 00308 /** @} */ 00309 00310 /** \defgroup libvlc_log LibVLC logging 00311 * libvlc_log_* functions provide access to the LibVLC messages log. 00312 * This is used for logging and debugging. 00313 * @{ 00314 */ 00315 00316 /** 00317 * Logging messages level. 00318 * \note Future LibVLC versions may define new levels. 00319 */ 00320 enum libvlc_log_level 00321 { 00322 LIBVLC_DEBUG=0 /**< Debug message */, 00323 LIBVLC_NOTICE=2 /**< Important informational message */, 00324 LIBVLC_WARNING=3 /**< Warning (potential error) message */, 00325 LIBVLC_ERROR=4 /**< Error message */, 00326 }; 00327 00328 /** 00329 * Callback prototype for LibVLC log message handler. 00330 * \param data data pointer as given to libvlc_log_subscribe() 00331 * \param level message level (@ref enum libvlc_log_level) 00332 * \param fmt printf() format string (as defined by ISO C11) 00333 * \param args variable argument list for the format 00334 * \note Log message handlers <b>must</b> be thread-safe. 00335 */ 00336 typedef void (*libvlc_log_cb)(void *data, int level, const char *fmt, 00337 va_list args); 00338 00339 /** 00340 * Data structure for a LibVLC logging callbacks. 00341 * \note This structure contains exactly 4 pointers and will never change. 00342 * Nevertheless, it should not be accessed directly outside of LibVLC. 00343 * (In fact, doing so would fail the thread memory model.) 00344 */ 00345 typedef struct libvlc_log_subscriber 00346 { 00347 struct libvlc_log_subscriber *prev, *next; 00348 libvlc_log_cb func; 00349 void *opaque; 00350 } libvlc_log_subscriber_t; 00351 00352 /** 00353 * Registers a logging callback to LibVLC. 00354 * This function is thread-safe. 00355 * 00356 * \param sub uninitialized subscriber structure 00357 * \param cb callback function pointer 00358 * \param data opaque data pointer for the callback function 00359 * 00360 * \note Some log messages (especially debug) are emitted by LibVLC while 00361 * initializing, before any LibVLC instance even exists. 00362 * Thus this function does not require a LibVLC instance parameter. 00363 * 00364 * \warning As a consequence of not depending on a LibVLC instance, 00365 * all logging callbacks are shared by all LibVLC instances within the 00366 * process / address space. This also enables log messages to be emitted 00367 * by LibVLC components that are not specific to any given LibVLC instance. 00368 * 00369 * \warning Do not call this function from within a logging callback. 00370 * It would trigger a dead lock. 00371 */ 00372 LIBVLC_API void libvlc_log_subscribe( libvlc_log_subscriber_t *sub, 00373 libvlc_log_cb cb, void *data ); 00374 00375 00376 /** 00377 * Registers a logging callback to a file. 00378 * @param stream FILE pointer opened for writing 00379 * (the FILE pointer must remain valid until libvlc_log_unsubscribe()) 00380 */ 00381 LIBVLC_API void libvlc_log_subscribe_file( libvlc_log_subscriber_t *sub, 00382 FILE *stream ); 00383 00384 /** 00385 * Deregisters a logging callback from LibVLC. 00386 * This function is thread-safe. 00387 * 00388 * \note After (and only after) libvlc_log_unsubscribe() has returned, 00389 * LibVLC warrants that there are no more pending calls of the subscription 00390 * callback function. 00391 * 00392 * \warning Do not call this function from within a logging callback. 00393 * It would trigger a dead lock. 00394 * 00395 * \param sub initialized subscriber structure 00396 */ 00397 LIBVLC_API void libvlc_log_unsubscribe( libvlc_log_subscriber_t *sub ); 00398 00399 /** 00400 * Always returns minus one. 00401 * This function is only provided for backward compatibility. 00402 * 00403 * \param p_instance ignored 00404 * \return always -1 00405 */ 00406 LIBVLC_DEPRECATED 00407 LIBVLC_API unsigned libvlc_get_log_verbosity( const libvlc_instance_t *p_instance ); 00408 00409 /** 00410 * This function does nothing. 00411 * It is only provided for backward compatibility. 00412 * 00413 * \param p_instance ignored 00414 * \param level ignored 00415 */ 00416 LIBVLC_DEPRECATED 00417 LIBVLC_API void libvlc_set_log_verbosity( libvlc_instance_t *p_instance, unsigned level ); 00418 00419 /** 00420 * This function does nothing useful. 00421 * It is only provided for backward compatibility. 00422 * 00423 * \param p_instance libvlc instance 00424 * \return an unique pointer or NULL on error 00425 */ 00426 LIBVLC_DEPRECATED 00427 LIBVLC_API libvlc_log_t *libvlc_log_open( libvlc_instance_t *p_instance ); 00428 00429 /** 00430 * Frees memory allocated by libvlc_log_open(). 00431 * 00432 * \param p_log libvlc log instance or NULL 00433 */ 00434 LIBVLC_DEPRECATED 00435 LIBVLC_API void libvlc_log_close( libvlc_log_t *p_log ); 00436 00437 /** 00438 * Always returns zero. 00439 * This function is only provided for backward compatibility. 00440 * 00441 * \param p_log ignored 00442 * \return always zero 00443 */ 00444 LIBVLC_DEPRECATED 00445 LIBVLC_API unsigned libvlc_log_count( const libvlc_log_t *p_log ); 00446 00447 /** 00448 * This function does nothing. 00449 * It is only provided for backward compatibility. 00450 * 00451 * \param p_log ignored 00452 */ 00453 LIBVLC_DEPRECATED 00454 LIBVLC_API void libvlc_log_clear( libvlc_log_t *p_log ); 00455 00456 /** 00457 * This function does nothing useful. 00458 * It is only provided for backward compatibility. 00459 * 00460 * \param p_log ignored 00461 * \return an unique pointer or NULL on error or if the parameter was NULL 00462 */ 00463 LIBVLC_DEPRECATED 00464 LIBVLC_API libvlc_log_iterator_t *libvlc_log_get_iterator( const libvlc_log_t *p_log ); 00465 00466 /** 00467 * Frees memory allocated by libvlc_log_get_iterator(). 00468 * 00469 * \param p_iter libvlc log iterator or NULL 00470 */ 00471 LIBVLC_DEPRECATED 00472 LIBVLC_API void libvlc_log_iterator_free( libvlc_log_iterator_t *p_iter ); 00473 00474 /** 00475 * Always returns zero. 00476 * This function is only provided for backward compatibility. 00477 * 00478 * \param p_iter ignored 00479 * \return always zero 00480 */ 00481 LIBVLC_DEPRECATED 00482 LIBVLC_API int libvlc_log_iterator_has_next( const libvlc_log_iterator_t *p_iter ); 00483 00484 /** 00485 * Always returns NULL. 00486 * This function is only provided for backward compatibility. 00487 * 00488 * \param p_iter libvlc log iterator or NULL 00489 * \param p_buffer ignored 00490 * \return always NULL 00491 */ 00492 LIBVLC_DEPRECATED 00493 LIBVLC_API libvlc_log_message_t *libvlc_log_iterator_next( libvlc_log_iterator_t *p_iter, 00494 libvlc_log_message_t *p_buffer ); 00495 00496 /** @} */ 00497 00498 /** 00499 * Description of a module. 00500 */ 00501 typedef struct libvlc_module_description_t 00502 { 00503 char *psz_name; 00504 char *psz_shortname; 00505 char *psz_longname; 00506 char *psz_help; 00507 struct libvlc_module_description_t *p_next; 00508 } libvlc_module_description_t; 00509 00510 /** 00511 * Release a list of module descriptions. 00512 * 00513 * \param p_list the list to be released 00514 */ 00515 LIBVLC_API 00516 void libvlc_module_description_list_release( libvlc_module_description_t *p_list ); 00517 00518 /** 00519 * Returns a list of audio filters that are available. 00520 * 00521 * \param p_instance libvlc instance 00522 * 00523 * \return a list of module descriptions. It should be freed with libvlc_module_description_list_release(). 00524 * In case of an error, NULL is returned. 00525 * 00526 * \see libvlc_module_description_t 00527 * \see libvlc_module_description_list_release 00528 */ 00529 LIBVLC_API 00530 libvlc_module_description_t *libvlc_audio_filter_list_get( libvlc_instance_t *p_instance ); 00531 00532 /** 00533 * Returns a list of video filters that are available. 00534 * 00535 * \param p_instance libvlc instance 00536 * 00537 * \return a list of module descriptions. It should be freed with libvlc_module_description_list_release(). 00538 * In case of an error, NULL is returned. 00539 * 00540 * \see libvlc_module_description_t 00541 * \see libvlc_module_description_list_release 00542 */ 00543 LIBVLC_API 00544 libvlc_module_description_t *libvlc_video_filter_list_get( libvlc_instance_t *p_instance ); 00545 00546 /** @} */ 00547 00548 /** \defgroup libvlc_clock LibVLC time 00549 * These functions provide access to the LibVLC time/clock. 00550 * @{ 00551 */ 00552 00553 /** 00554 * Return the current time as defined by LibVLC. The unit is the microsecond. 00555 * Time increases monotonically (regardless of time zone changes and RTC 00556 * adjustements). 00557 * The origin is arbitrary but consistent across the whole system 00558 * (e.g. the system uptim, the time since the system was booted). 00559 * \note On systems that support it, the POSIX monotonic clock is used. 00560 */ 00561 LIBVLC_API 00562 int64_t libvlc_clock(void); 00563 00564 /** 00565 * Return the delay (in microseconds) until a certain timestamp. 00566 * \param pts timestamp 00567 * \return negative if timestamp is in the past, 00568 * positive if it is in the future 00569 */ 00570 static inline int64_t libvlc_delay(int64_t pts) 00571 { 00572 return pts - libvlc_clock(); 00573 } 00574 00575 /** @} */ 00576 00577 # ifdef __cplusplus 00578 } 00579 # endif 00580 00581 #endif /* <vlc/libvlc.h> */
1.7.1