1 /*****************************************************************************
2 * libvlc.h: libvlc external API
3 *****************************************************************************
4 * Copyright (C) 1998-2009 the VideoLAN team
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
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 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 General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
28 * This file defines libvlc_media external API
31 #ifndef VLC_LIBVLC_MEDIA_H
32 #define VLC_LIBVLC_MEDIA_H 1
38 /** \defgroup libvlc_media LibVLC media
40 * @ref libvlc_media_t is an abstract representation of a playable media.
41 * It consists of a media location and various optional meta data.
45 typedef struct libvlc_media_t libvlc_media_t;
47 /** defgroup libvlc_meta LibVLC meta data
48 * \ingroup libvlc_media
52 /** Meta data types */
53 typedef enum libvlc_meta_t {
57 libvlc_meta_Copyright,
59 libvlc_meta_TrackNumber,
60 libvlc_meta_Description,
66 libvlc_meta_NowPlaying,
67 libvlc_meta_Publisher,
68 libvlc_meta_EncodedBy,
69 libvlc_meta_ArtworkURL,
71 /* Add new meta types HERE */
77 * Note the order of libvlc_state_t enum must match exactly the order of
78 * @see mediacontrol_PlayerStatus, @see input_state_e enums,
79 * and VideoLAN.LibVLC.State (at bindings/cil/src/media.cs).
81 * Expected states by web plugins are:
82 * IDLE/CLOSE=0, OPENING=1, BUFFERING=2, PLAYING=3, PAUSED=4,
83 * STOPPING=5, ENDED=6, ERROR=7
85 typedef enum libvlc_state_t
87 libvlc_NothingSpecial=0,
99 libvlc_media_option_trusted = 0x2,
100 libvlc_media_option_unique = 0x100
103 typedef enum libvlc_track_type_t
105 libvlc_track_unknown = -1,
106 libvlc_track_audio = 0,
107 libvlc_track_video = 1,
108 libvlc_track_text = 2,
109 } libvlc_track_type_t;
111 /** defgroup libvlc_media_stats_t LibVLC media statistics
112 * \ingroup libvlc_media
115 typedef struct libvlc_media_stats_t
119 float f_input_bitrate;
122 int i_demux_read_bytes;
123 float f_demux_bitrate;
124 int i_demux_corrupted;
125 int i_demux_discontinuity;
132 int i_displayed_pictures;
136 int i_played_abuffers;
142 float f_send_bitrate;
143 } libvlc_media_stats_t;
146 typedef struct libvlc_media_track_info_t
151 libvlc_track_type_t i_type;
165 } libvlc_media_track_info_t;
169 * Create a media with a certain given media resource location.
171 * \see libvlc_media_release
173 * \param p_instance the instance
174 * \param psz_mrl the MRL to read
175 * \return the newly created media or NULL on error
177 VLC_PUBLIC_API libvlc_media_t *libvlc_media_new_location(
178 libvlc_instance_t *p_instance,
179 const char * psz_mrl );
182 * Create a media with a certain file path.
184 * \see libvlc_media_release
186 * \param p_instance the instance
187 * \param path local filesystem path
188 * \return the newly created media or NULL on error
190 VLC_PUBLIC_API libvlc_media_t *libvlc_media_new_path(
191 libvlc_instance_t *p_instance,
195 * Create a media as an empty node with a given name.
197 * \see libvlc_media_release
199 * \param p_instance the instance
200 * \param psz_name the name of the node
201 * \return the new empty media or NULL on error
203 VLC_PUBLIC_API libvlc_media_t * libvlc_media_new_as_node(
204 libvlc_instance_t *p_instance,
205 const char * psz_name );
208 * Add an option to the media.
210 * This option will be used to determine how the media_player will
211 * read the media. This allows to use VLC's advanced
212 * reading/streaming options on a per-media basis.
214 * The options are detailed in vlc --long-help, for instance "--sout-all"
216 * \param p_md the media descriptor
217 * \param ppsz_options the options (as a string)
219 VLC_PUBLIC_API void libvlc_media_add_option(
220 libvlc_media_t * p_md,
221 const char * ppsz_options );
224 * Add an option to the media with configurable flags.
226 * This option will be used to determine how the media_player will
227 * read the media. This allows to use VLC's advanced
228 * reading/streaming options on a per-media basis.
230 * The options are detailed in vlc --long-help, for instance "--sout-all"
232 * \param p_md the media descriptor
233 * \param ppsz_options the options (as a string)
234 * \param i_flags the flags for this option
236 VLC_PUBLIC_API void libvlc_media_add_option_flag(
237 libvlc_media_t * p_md,
238 const char * ppsz_options,
243 * Retain a reference to a media descriptor object (libvlc_media_t). Use
244 * libvlc_media_release() to decrement the reference count of a
245 * media descriptor object.
247 * \param p_md the media descriptor
249 VLC_PUBLIC_API void libvlc_media_retain( libvlc_media_t *p_md );
252 * Decrement the reference count of a media descriptor object. If the
253 * reference count is 0, then libvlc_media_release() will release the
254 * media descriptor object. It will send out an libvlc_MediaFreed event
255 * to all listeners. If the media descriptor object has been released it
256 * should not be used again.
258 * \param p_md the media descriptor
260 VLC_PUBLIC_API void libvlc_media_release( libvlc_media_t *p_md );
264 * Get the media resource locator (mrl) from a media descriptor object
266 * \param p_md a media descriptor object
267 * \return string with mrl of media descriptor object
269 VLC_PUBLIC_API char * libvlc_media_get_mrl( libvlc_media_t * p_md );
272 * Duplicate a media descriptor object.
274 * \param p_md a media descriptor object.
276 VLC_PUBLIC_API libvlc_media_t * libvlc_media_duplicate( libvlc_media_t *p_md );
279 * Read the meta of the media.
281 * If the media has not yet been parsed this will return NULL.
283 * This methods automatically calls libvlc_media_parse_async(), so after calling
284 * it you may receive a libvlc_MediaMetaChanged event. If you prefer a synchronous
285 * version ensure that you call libvlc_media_parse() before get_meta().
287 * \see libvlc_media_parse
288 * \see libvlc_media_parse_async
289 * \see libvlc_MediaMetaChanged
291 * \param p_md the media descriptor
292 * \param e_meta the meta to read
293 * \return the media's meta
295 VLC_PUBLIC_API char * libvlc_media_get_meta( libvlc_media_t *p_md,
296 libvlc_meta_t e_meta );
299 * Set the meta of the media (this function will not save the meta, call
300 * libvlc_media_save_meta in order to save the meta)
302 * \param p_md the media descriptor
303 * \param e_meta the meta to write
304 * \param psz_value the media's meta
306 VLC_PUBLIC_API void libvlc_media_set_meta( libvlc_media_t *p_md,
307 libvlc_meta_t e_meta,
308 const char *psz_value );
312 * Save the meta previously set
314 * \param p_md the media desriptor
315 * \return true if the write operation was successfull
317 VLC_PUBLIC_API int libvlc_media_save_meta( libvlc_media_t *p_md );
321 * Get current state of media descriptor object. Possible media states
322 * are defined in libvlc_structures.c ( libvlc_NothingSpecial=0,
323 * libvlc_Opening, libvlc_Buffering, libvlc_Playing, libvlc_Paused,
324 * libvlc_Stopped, libvlc_Ended,
327 * @see libvlc_state_t
328 * \param p_meta_desc a media descriptor object
329 * \return state of media descriptor object
331 VLC_PUBLIC_API libvlc_state_t libvlc_media_get_state(
332 libvlc_media_t *p_meta_desc );
336 * get the current statistics about the media
337 * @param p_md: media descriptor object
338 * @param p_stats: structure that contain the statistics about the media
339 * (this structure must be allocated by the caller)
340 * @return true if the statistics are available, false otherwise
342 VLC_PUBLIC_API int libvlc_media_get_stats( libvlc_media_t *p_md,
343 libvlc_media_stats_t *p_stats );
346 * Get subitems of media descriptor object. This will increment
347 * the reference count of supplied media descriptor object. Use
348 * libvlc_media_list_release() to decrement the reference counting.
350 * \param p_md media descriptor object
351 * \return list of media descriptor subitems or NULL
354 /* This method uses libvlc_media_list_t, however, media_list usage is optionnal
355 * and this is here for convenience */
356 #define VLC_FORWARD_DECLARE_OBJECT(a) struct a
358 VLC_PUBLIC_API VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t *)
359 libvlc_media_subitems( libvlc_media_t *p_md );
362 * Get event manager from media descriptor object.
363 * NOTE: this function doesn't increment reference counting.
365 * \param p_md a media descriptor object
366 * \return event manager object
368 VLC_PUBLIC_API libvlc_event_manager_t *
369 libvlc_media_event_manager( libvlc_media_t * p_md );
372 * Get duration (in ms) of media descriptor object item.
374 * \param p_md media descriptor object
375 * \return duration of media item or -1 on error
377 VLC_PUBLIC_API libvlc_time_t
378 libvlc_media_get_duration( libvlc_media_t * p_md );
383 * This fetches (local) meta data and tracks information.
384 * The method is synchronous.
386 * \see libvlc_media_parse_async
387 * \see libvlc_media_get_meta
388 * \see libvlc_media_get_tracks_info
390 * \param media media descriptor object
393 libvlc_media_parse(libvlc_media_t *media);
398 * This fetches (local) meta data and tracks information.
399 * The method is the asynchronous of libvlc_media_parse_async().
401 * To track when this is over you can listen to libvlc_MediaPreparsedChanged
402 * event. However if the media was already preparsed you will not receive this
405 * \see libvlc_media_parse
406 * \see libvlc_MediaPreparsedChanged
407 * \see libvlc_media_get_meta
408 * \see libvlc_media_get_tracks_info
410 * \param media media descriptor object
413 libvlc_media_parse_async(libvlc_media_t *media);
416 * Get preparsed status for media descriptor object.
418 * \param p_md media descriptor object
419 * \return true if media object has been preparsed otherwise it returns false
422 libvlc_media_is_preparsed( libvlc_media_t * p_md );
425 * Sets media descriptor's user_data. user_data is specialized data
426 * accessed by the host application, VLC.framework uses it as a pointer to
427 * an native object that references a libvlc_media_t pointer
429 * \param p_md media descriptor object
430 * \param p_new_user_data pointer to user data
433 libvlc_media_set_user_data( libvlc_media_t * p_md,
434 void * p_new_user_data );
437 * Get media descriptor's user_data. user_data is specialized data
438 * accessed by the host application, VLC.framework uses it as a pointer to
439 * an native object that references a libvlc_media_t pointer
441 * \param p_md media descriptor object
443 VLC_PUBLIC_API void *
444 libvlc_media_get_user_data( libvlc_media_t * p_md );
447 * Get media descriptor's elementary streams description
449 * Note, you need to play the media _one_ time with --sout="#description"
450 * Not doing this will result in an empty array, and doing it more than once
451 * will duplicate the entries in the array each time. Something like this:
454 * libvlc_media_player_t *player = libvlc_media_player_new_from_media(media);
455 * libvlc_media_add_option_flag(media, "sout=\"#description\"");
456 * libvlc_media_player_play(player);
457 * // ... wait until playing
458 * libvlc_media_player_release(player);
461 * This is very likely to change in next release, and be done at the parsing
464 * \param media media descriptor object
465 * \param tracks address to store an allocated array of Elementary Streams
466 * descriptions (must be freed by the caller)
468 * return the number of Elementary Streams
471 int libvlc_media_get_tracks_info(libvlc_media_t *media,
472 libvlc_media_track_info_t **tracks );
480 #endif /* VLC_LIBVLC_MEDIA_H */