libvlc_media.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * libvlc_media.h:  libvlc external API
00003  *****************************************************************************
00004  * Copyright (C) 1998-2009 VLC authors and VideoLAN
00005  * $Id: 279a29c0b2c2489cbb00889c4236d030099d243f $
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_media external API
00029  */
00030 
00031 #ifndef VLC_LIBVLC_MEDIA_H
00032 #define VLC_LIBVLC_MEDIA_H 1
00033 
00034 # ifdef __cplusplus
00035 extern "C" {
00036 # endif
00037 
00038 /** \defgroup libvlc_media LibVLC media
00039  * \ingroup libvlc
00040  * @ref libvlc_media_t is an abstract representation of a playable media.
00041  * It consists of a media location and various optional meta data.
00042  * @{
00043  */
00044 
00045 typedef struct libvlc_media_t libvlc_media_t;
00046 
00047 /** defgroup libvlc_meta LibVLC meta data
00048  * \ingroup libvlc_media
00049  * @{
00050  */
00051 
00052 /** Meta data types */
00053 typedef enum libvlc_meta_t {
00054     libvlc_meta_Title,
00055     libvlc_meta_Artist,
00056     libvlc_meta_Genre,
00057     libvlc_meta_Copyright,
00058     libvlc_meta_Album,
00059     libvlc_meta_TrackNumber,
00060     libvlc_meta_Description,
00061     libvlc_meta_Rating,
00062     libvlc_meta_Date,
00063     libvlc_meta_Setting,
00064     libvlc_meta_URL,
00065     libvlc_meta_Language,
00066     libvlc_meta_NowPlaying,
00067     libvlc_meta_Publisher,
00068     libvlc_meta_EncodedBy,
00069     libvlc_meta_ArtworkURL,
00070     libvlc_meta_TrackID
00071     /* Add new meta types HERE */
00072 } libvlc_meta_t;
00073 
00074 /** @}*/
00075 
00076 /**
00077  * Note the order of libvlc_state_t enum must match exactly the order of
00078  * \see mediacontrol_PlayerStatus, \see input_state_e enums,
00079  * and VideoLAN.LibVLC.State (at bindings/cil/src/media.cs).
00080  *
00081  * Expected states by web plugins are:
00082  * IDLE/CLOSE=0, OPENING=1, BUFFERING=2, PLAYING=3, PAUSED=4,
00083  * STOPPING=5, ENDED=6, ERROR=7
00084  */
00085 typedef enum libvlc_state_t
00086 {
00087     libvlc_NothingSpecial=0,
00088     libvlc_Opening,
00089     libvlc_Buffering,
00090     libvlc_Playing,
00091     libvlc_Paused,
00092     libvlc_Stopped,
00093     libvlc_Ended,
00094     libvlc_Error
00095 } libvlc_state_t;
00096 
00097 enum
00098 {
00099     libvlc_media_option_trusted = 0x2,
00100     libvlc_media_option_unique = 0x100
00101 };
00102 
00103 typedef enum libvlc_track_type_t
00104 {
00105     libvlc_track_unknown   = -1,
00106     libvlc_track_audio     = 0,
00107     libvlc_track_video     = 1,
00108     libvlc_track_text      = 2
00109 } libvlc_track_type_t;
00110 
00111 /** defgroup libvlc_media_stats_t LibVLC media statistics
00112  * \ingroup libvlc_media
00113  * @{
00114  */
00115 typedef struct libvlc_media_stats_t
00116 {
00117     /* Input */
00118     int         i_read_bytes;
00119     float       f_input_bitrate;
00120 
00121     /* Demux */
00122     int         i_demux_read_bytes;
00123     float       f_demux_bitrate;
00124     int         i_demux_corrupted;
00125     int         i_demux_discontinuity;
00126 
00127     /* Decoders */
00128     int         i_decoded_video;
00129     int         i_decoded_audio;
00130 
00131     /* Video Output */
00132     int         i_displayed_pictures;
00133     int         i_lost_pictures;
00134 
00135     /* Audio output */
00136     int         i_played_abuffers;
00137     int         i_lost_abuffers;
00138 
00139     /* Stream output */
00140     int         i_sent_packets;
00141     int         i_sent_bytes;
00142     float       f_send_bitrate;
00143 } libvlc_media_stats_t;
00144 /** @}*/
00145 
00146 typedef struct libvlc_media_track_info_t
00147 {
00148     /* Codec fourcc */
00149     uint32_t    i_codec;
00150     int         i_id;
00151     libvlc_track_type_t i_type;
00152 
00153     /* Codec specific */
00154     int         i_profile;
00155     int         i_level;
00156 
00157     union {
00158         struct {
00159             /* Audio specific */
00160             unsigned    i_channels;
00161             unsigned    i_rate;
00162         } audio;
00163         struct {
00164             /* Video specific */
00165             unsigned    i_height;
00166             unsigned    i_width;
00167         } video;
00168     } u;
00169 
00170 } libvlc_media_track_info_t;
00171 
00172 
00173 /**
00174  * Create a media with a certain given media resource location,
00175  * for instance a valid URL.
00176  *
00177  * \note To refer to a local file with this function,
00178  * the file://... URI syntax <b>must</b> be used (see IETF RFC3986).
00179  * We recommend using libvlc_media_new_path() instead when dealing with
00180  * local files.
00181  *
00182  * \see libvlc_media_release
00183  *
00184  * \param p_instance the instance
00185  * \param psz_mrl the media location
00186  * \return the newly created media or NULL on error
00187  */
00188 LIBVLC_API libvlc_media_t *libvlc_media_new_location(
00189                                    libvlc_instance_t *p_instance,
00190                                    const char * psz_mrl );
00191 
00192 /**
00193  * Create a media for a certain file path.
00194  *
00195  * \see libvlc_media_release
00196  *
00197  * \param p_instance the instance
00198  * \param path local filesystem path
00199  * \return the newly created media or NULL on error
00200  */
00201 LIBVLC_API libvlc_media_t *libvlc_media_new_path(
00202                                    libvlc_instance_t *p_instance,
00203                                    const char *path );
00204 
00205 /**
00206  * Create a media for an already open file descriptor.
00207  * The file descriptor shall be open for reading (or reading and writing).
00208  *
00209  * Regular file descriptors, pipe read descriptors and character device
00210  * descriptors (including TTYs) are supported on all platforms.
00211  * Block device descriptors are supported where available.
00212  * Directory descriptors are supported on systems that provide fdopendir().
00213  * Sockets are supported on all platforms where they are file descriptors,
00214  * i.e. all except Windows.
00215  *
00216  * \note This library will <b>not</b> automatically close the file descriptor
00217  * under any circumstance. Nevertheless, a file descriptor can usually only be
00218  * rendered once in a media player. To render it a second time, the file
00219  * descriptor should probably be rewound to the beginning with lseek().
00220  *
00221  * \see libvlc_media_release
00222  *
00223  * \version LibVLC 1.1.5 and later.
00224  *
00225  * \param p_instance the instance
00226  * \param fd open file descriptor
00227  * \return the newly created media or NULL on error
00228  */
00229 LIBVLC_API libvlc_media_t *libvlc_media_new_fd(
00230                                    libvlc_instance_t *p_instance,
00231                                    int fd );
00232 
00233 
00234 /**
00235  * Create a media as an empty node with a given name.
00236  *
00237  * \see libvlc_media_release
00238  *
00239  * \param p_instance the instance
00240  * \param psz_name the name of the node
00241  * \return the new empty media or NULL on error
00242  */
00243 LIBVLC_API libvlc_media_t *libvlc_media_new_as_node(
00244                                    libvlc_instance_t *p_instance,
00245                                    const char * psz_name );
00246 
00247 /**
00248  * Add an option to the media.
00249  *
00250  * This option will be used to determine how the media_player will
00251  * read the media. This allows to use VLC's advanced
00252  * reading/streaming options on a per-media basis.
00253  *
00254  * The options are detailed in vlc --long-help, for instance "--sout-all"
00255  *
00256  * \param p_md the media descriptor
00257  * \param ppsz_options the options (as a string)
00258  */
00259 LIBVLC_API void libvlc_media_add_option(
00260                                    libvlc_media_t *p_md,
00261                                    const char * ppsz_options );
00262 
00263 /**
00264  * Add an option to the media with configurable flags.
00265  *
00266  * This option will be used to determine how the media_player will
00267  * read the media. This allows to use VLC's advanced
00268  * reading/streaming options on a per-media basis.
00269  *
00270  * The options are detailed in vlc --long-help, for instance "--sout-all"
00271  *
00272  * \param p_md the media descriptor
00273  * \param ppsz_options the options (as a string)
00274  * \param i_flags the flags for this option
00275  */
00276 LIBVLC_API void libvlc_media_add_option_flag(
00277                                    libvlc_media_t *p_md,
00278                                    const char * ppsz_options,
00279                                    unsigned i_flags );
00280 
00281 
00282 /**
00283  * Retain a reference to a media descriptor object (libvlc_media_t). Use
00284  * libvlc_media_release() to decrement the reference count of a
00285  * media descriptor object.
00286  *
00287  * \param p_md the media descriptor
00288  */
00289 LIBVLC_API void libvlc_media_retain( libvlc_media_t *p_md );
00290 
00291 /**
00292  * Decrement the reference count of a media descriptor object. If the
00293  * reference count is 0, then libvlc_media_release() will release the
00294  * media descriptor object. It will send out an libvlc_MediaFreed event
00295  * to all listeners. If the media descriptor object has been released it
00296  * should not be used again.
00297  *
00298  * \param p_md the media descriptor
00299  */
00300 LIBVLC_API void libvlc_media_release( libvlc_media_t *p_md );
00301 
00302 
00303 /**
00304  * Get the media resource locator (mrl) from a media descriptor object
00305  *
00306  * \param p_md a media descriptor object
00307  * \return string with mrl of media descriptor object
00308  */
00309 LIBVLC_API char *libvlc_media_get_mrl( libvlc_media_t *p_md );
00310 
00311 /**
00312  * Duplicate a media descriptor object.
00313  *
00314  * \param p_md a media descriptor object.
00315  */
00316 LIBVLC_API libvlc_media_t *libvlc_media_duplicate( libvlc_media_t *p_md );
00317 
00318 /**
00319  * Read the meta of the media.
00320  *
00321  * If the media has not yet been parsed this will return NULL.
00322  *
00323  * This methods automatically calls libvlc_media_parse_async(), so after calling
00324  * it you may receive a libvlc_MediaMetaChanged event. If you prefer a synchronous
00325  * version ensure that you call libvlc_media_parse() before get_meta().
00326  *
00327  * \see libvlc_media_parse
00328  * \see libvlc_media_parse_async
00329  * \see libvlc_MediaMetaChanged
00330  *
00331  * \param p_md the media descriptor
00332  * \param e_meta the meta to read
00333  * \return the media's meta
00334  */
00335 LIBVLC_API char *libvlc_media_get_meta( libvlc_media_t *p_md,
00336                                              libvlc_meta_t e_meta );
00337 
00338 /**
00339  * Set the meta of the media (this function will not save the meta, call
00340  * libvlc_media_save_meta in order to save the meta)
00341  *
00342  * \param p_md the media descriptor
00343  * \param e_meta the meta to write
00344  * \param psz_value the media's meta
00345  */
00346 LIBVLC_API void libvlc_media_set_meta( libvlc_media_t *p_md,
00347                                            libvlc_meta_t e_meta,
00348                                            const char *psz_value );
00349 
00350 
00351 /**
00352  * Save the meta previously set
00353  *
00354  * \param p_md the media desriptor
00355  * \return true if the write operation was successful
00356  */
00357 LIBVLC_API int libvlc_media_save_meta( libvlc_media_t *p_md );
00358 
00359 
00360 /**
00361  * Get current state of media descriptor object. Possible media states
00362  * are defined in libvlc_structures.c ( libvlc_NothingSpecial=0,
00363  * libvlc_Opening, libvlc_Buffering, libvlc_Playing, libvlc_Paused,
00364  * libvlc_Stopped, libvlc_Ended,
00365  * libvlc_Error).
00366  *
00367  * \see libvlc_state_t
00368  * \param p_md a media descriptor object
00369  * \return state of media descriptor object
00370  */
00371 LIBVLC_API libvlc_state_t libvlc_media_get_state(
00372                                    libvlc_media_t *p_md );
00373 
00374 
00375 /**
00376  * Get the current statistics about the media
00377  * \param p_md: media descriptor object
00378  * \param p_stats: structure that contain the statistics about the media
00379  *                 (this structure must be allocated by the caller)
00380  * \return true if the statistics are available, false otherwise
00381  *
00382  * \libvlc_return_bool
00383  */
00384 LIBVLC_API int libvlc_media_get_stats( libvlc_media_t *p_md,
00385                                            libvlc_media_stats_t *p_stats );
00386 
00387 /**
00388  * Get subitems of media descriptor object. This will increment
00389  * the reference count of supplied media descriptor object. Use
00390  * libvlc_media_list_release() to decrement the reference counting.
00391  *
00392  * \param p_md media descriptor object
00393  * \return list of media descriptor subitems or NULL
00394  */
00395 
00396 /* This method uses libvlc_media_list_t, however, media_list usage is optionnal
00397  * and this is here for convenience */
00398 #define VLC_FORWARD_DECLARE_OBJECT(a) struct a
00399 
00400 LIBVLC_API VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t *)
00401 libvlc_media_subitems( libvlc_media_t *p_md );
00402 
00403 /**
00404  * Get event manager from media descriptor object.
00405  * NOTE: this function doesn't increment reference counting.
00406  *
00407  * \param p_md a media descriptor object
00408  * \return event manager object
00409  */
00410 LIBVLC_API libvlc_event_manager_t *
00411     libvlc_media_event_manager( libvlc_media_t *p_md );
00412 
00413 /**
00414  * Get duration (in ms) of media descriptor object item.
00415  *
00416  * \param p_md media descriptor object
00417  * \return duration of media item or -1 on error
00418  */
00419 LIBVLC_API libvlc_time_t
00420    libvlc_media_get_duration( libvlc_media_t *p_md );
00421 
00422 /**
00423  * Parse a media.
00424  *
00425  * This fetches (local) meta data and tracks information.
00426  * The method is synchronous.
00427  *
00428  * \see libvlc_media_parse_async
00429  * \see libvlc_media_get_meta
00430  * \see libvlc_media_get_tracks_info
00431  *
00432  * \param p_md media descriptor object
00433  */
00434 LIBVLC_API void
00435 libvlc_media_parse( libvlc_media_t *p_md );
00436 
00437 /**
00438  * Parse a media.
00439  *
00440  * This fetches (local) meta data and tracks information.
00441  * The method is the asynchronous of libvlc_media_parse().
00442  *
00443  * To track when this is over you can listen to libvlc_MediaParsedChanged
00444  * event. However if the media was already parsed you will not receive this
00445  * event.
00446  *
00447  * \see libvlc_media_parse
00448  * \see libvlc_MediaParsedChanged
00449  * \see libvlc_media_get_meta
00450  * \see libvlc_media_get_tracks_info
00451  *
00452  * \param p_md media descriptor object
00453  */
00454 LIBVLC_API void
00455 libvlc_media_parse_async( libvlc_media_t *p_md );
00456 
00457 /**
00458  * Get Parsed status for media descriptor object.
00459  *
00460  * \see libvlc_MediaParsedChanged
00461  *
00462  * \param p_md media descriptor object
00463  * \return true if media object has been parsed otherwise it returns false
00464  *
00465  * \libvlc_return_bool
00466  */
00467 LIBVLC_API int
00468    libvlc_media_is_parsed( libvlc_media_t *p_md );
00469 
00470 /**
00471  * Sets media descriptor's user_data. user_data is specialized data
00472  * accessed by the host application, VLC.framework uses it as a pointer to
00473  * an native object that references a libvlc_media_t pointer
00474  *
00475  * \param p_md media descriptor object
00476  * \param p_new_user_data pointer to user data
00477  */
00478 LIBVLC_API void
00479     libvlc_media_set_user_data( libvlc_media_t *p_md, void *p_new_user_data );
00480 
00481 /**
00482  * Get media descriptor's user_data. user_data is specialized data
00483  * accessed by the host application, VLC.framework uses it as a pointer to
00484  * an native object that references a libvlc_media_t pointer
00485  *
00486  * \param p_md media descriptor object
00487  */
00488 LIBVLC_API void *libvlc_media_get_user_data( libvlc_media_t *p_md );
00489 
00490 /**
00491  * Get media descriptor's elementary streams description
00492  *
00493  * Note, you need to call libvlc_media_parse() or play the media at least once
00494  * before calling this function.
00495  * Not doing this will result in an empty array.
00496  *
00497  * \param p_md media descriptor object
00498  * \param tracks address to store an allocated array of Elementary Streams
00499  * descriptions (must be freed by the caller)
00500  *
00501  * \return the number of Elementary Streams
00502  */
00503 LIBVLC_API
00504 int libvlc_media_get_tracks_info( libvlc_media_t *p_md,
00505                                   libvlc_media_track_info_t **tracks );
00506 
00507 /** @}*/
00508 
00509 # ifdef __cplusplus
00510 }
00511 # endif
00512 
00513 #endif /* VLC_LIBVLC_MEDIA_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines