1 /*****************************************************************************
2 * libvlc_media.h: libvlc external API
3 *****************************************************************************
4 * Copyright (C) 1998-2009 VLC authors and VideoLAN
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 *****************************************************************************/
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 libvlc_meta_TrackTotal,
77 libvlc_meta_AlbumArtist
78 /* Add new meta types HERE */
84 * Note the order of libvlc_state_t enum must match exactly the order of
85 * \see mediacontrol_PlayerStatus, \see input_state_e enums,
86 * and VideoLAN.LibVLC.State (at bindings/cil/src/media.cs).
88 * Expected states by web plugins are:
89 * IDLE/CLOSE=0, OPENING=1, BUFFERING=2, PLAYING=3, PAUSED=4,
90 * STOPPING=5, ENDED=6, ERROR=7
92 typedef enum libvlc_state_t
94 libvlc_NothingSpecial=0,
106 libvlc_media_option_trusted = 0x2,
107 libvlc_media_option_unique = 0x100
110 typedef enum libvlc_track_type_t
112 libvlc_track_unknown = -1,
113 libvlc_track_audio = 0,
114 libvlc_track_video = 1,
115 libvlc_track_text = 2
116 } libvlc_track_type_t;
118 /** defgroup libvlc_media_stats_t LibVLC media statistics
119 * \ingroup libvlc_media
122 typedef struct libvlc_media_stats_t
126 float f_input_bitrate;
129 int i_demux_read_bytes;
130 float f_demux_bitrate;
131 int i_demux_corrupted;
132 int i_demux_discontinuity;
139 int i_displayed_pictures;
143 int i_played_abuffers;
149 float f_send_bitrate;
150 } libvlc_media_stats_t;
153 typedef struct libvlc_media_track_info_t
158 libvlc_track_type_t i_type;
177 } libvlc_media_track_info_t;
180 typedef struct libvlc_audio_track_t
184 } libvlc_audio_track_t;
186 typedef struct libvlc_video_track_t
192 unsigned i_frame_rate_num;
193 unsigned i_frame_rate_den;
194 } libvlc_video_track_t;
196 typedef struct libvlc_subtitle_track_t
199 } libvlc_subtitle_track_t;
201 typedef struct libvlc_media_track_t
205 uint32_t i_original_fourcc;
207 libvlc_track_type_t i_type;
214 libvlc_audio_track_t *audio;
215 libvlc_video_track_t *video;
216 libvlc_subtitle_track_t *subtitle;
219 unsigned int i_bitrate;
221 char *psz_description;
223 } libvlc_media_track_t;
227 * Create a media with a certain given media resource location,
228 * for instance a valid URL.
230 * \note To refer to a local file with this function,
231 * the file://... URI syntax <b>must</b> be used (see IETF RFC3986).
232 * We recommend using libvlc_media_new_path() instead when dealing with
235 * \see libvlc_media_release
237 * \param p_instance the instance
238 * \param psz_mrl the media location
239 * \return the newly created media or NULL on error
241 LIBVLC_API libvlc_media_t *libvlc_media_new_location(
242 libvlc_instance_t *p_instance,
243 const char * psz_mrl );
246 * Create a media for a certain file path.
248 * \see libvlc_media_release
250 * \param p_instance the instance
251 * \param path local filesystem path
252 * \return the newly created media or NULL on error
254 LIBVLC_API libvlc_media_t *libvlc_media_new_path(
255 libvlc_instance_t *p_instance,
259 * Create a media for an already open file descriptor.
260 * The file descriptor shall be open for reading (or reading and writing).
262 * Regular file descriptors, pipe read descriptors and character device
263 * descriptors (including TTYs) are supported on all platforms.
264 * Block device descriptors are supported where available.
265 * Directory descriptors are supported on systems that provide fdopendir().
266 * Sockets are supported on all platforms where they are file descriptors,
267 * i.e. all except Windows.
269 * \note This library will <b>not</b> automatically close the file descriptor
270 * under any circumstance. Nevertheless, a file descriptor can usually only be
271 * rendered once in a media player. To render it a second time, the file
272 * descriptor should probably be rewound to the beginning with lseek().
274 * \see libvlc_media_release
276 * \version LibVLC 1.1.5 and later.
278 * \param p_instance the instance
279 * \param fd open file descriptor
280 * \return the newly created media or NULL on error
282 LIBVLC_API libvlc_media_t *libvlc_media_new_fd(
283 libvlc_instance_t *p_instance,
288 * Create a media as an empty node with a given name.
290 * \see libvlc_media_release
292 * \param p_instance the instance
293 * \param psz_name the name of the node
294 * \return the new empty media or NULL on error
296 LIBVLC_API libvlc_media_t *libvlc_media_new_as_node(
297 libvlc_instance_t *p_instance,
298 const char * psz_name );
301 * Add an option to the media.
303 * This option will be used to determine how the media_player will
304 * read the media. This allows to use VLC's advanced
305 * reading/streaming options on a per-media basis.
307 * \note The options are listed in 'vlc --long-help' from the command line,
308 * e.g. "-sout-all". Keep in mind that available options and their semantics
309 * vary across LibVLC versions and builds.
310 * \warning Not all options affects libvlc_media_t objects:
311 * Specifically, due to architectural issues most audio and video options,
312 * such as text renderer options, have no effects on an individual media.
313 * These options must be set through libvlc_new() instead.
315 * \param p_md the media descriptor
316 * \param psz_options the options (as a string)
318 LIBVLC_API void libvlc_media_add_option(
319 libvlc_media_t *p_md,
320 const char * psz_options );
323 * Add an option to the media with configurable flags.
325 * This option will be used to determine how the media_player will
326 * read the media. This allows to use VLC's advanced
327 * reading/streaming options on a per-media basis.
329 * The options are detailed in vlc --long-help, for instance
330 * "--sout-all". Note that all options are not usable on medias:
331 * specifically, due to architectural issues, video-related options
332 * such as text renderer options cannot be set on a single media. They
333 * must be set on the whole libvlc instance instead.
335 * \param p_md the media descriptor
336 * \param psz_options the options (as a string)
337 * \param i_flags the flags for this option
339 LIBVLC_API void libvlc_media_add_option_flag(
340 libvlc_media_t *p_md,
341 const char * psz_options,
346 * Retain a reference to a media descriptor object (libvlc_media_t). Use
347 * libvlc_media_release() to decrement the reference count of a
348 * media descriptor object.
350 * \param p_md the media descriptor
352 LIBVLC_API void libvlc_media_retain( libvlc_media_t *p_md );
355 * Decrement the reference count of a media descriptor object. If the
356 * reference count is 0, then libvlc_media_release() will release the
357 * media descriptor object. It will send out an libvlc_MediaFreed event
358 * to all listeners. If the media descriptor object has been released it
359 * should not be used again.
361 * \param p_md the media descriptor
363 LIBVLC_API void libvlc_media_release( libvlc_media_t *p_md );
367 * Get the media resource locator (mrl) from a media descriptor object
369 * \param p_md a media descriptor object
370 * \return string with mrl of media descriptor object
372 LIBVLC_API char *libvlc_media_get_mrl( libvlc_media_t *p_md );
375 * Duplicate a media descriptor object.
377 * \param p_md a media descriptor object.
379 LIBVLC_API libvlc_media_t *libvlc_media_duplicate( libvlc_media_t *p_md );
382 * Read the meta of the media.
384 * If the media has not yet been parsed this will return NULL.
386 * This methods automatically calls libvlc_media_parse_async(), so after calling
387 * it you may receive a libvlc_MediaMetaChanged event. If you prefer a synchronous
388 * version ensure that you call libvlc_media_parse() before get_meta().
390 * \see libvlc_media_parse
391 * \see libvlc_media_parse_async
392 * \see libvlc_MediaMetaChanged
394 * \param p_md the media descriptor
395 * \param e_meta the meta to read
396 * \return the media's meta
398 LIBVLC_API char *libvlc_media_get_meta( libvlc_media_t *p_md,
399 libvlc_meta_t e_meta );
402 * Set the meta of the media (this function will not save the meta, call
403 * libvlc_media_save_meta in order to save the meta)
405 * \param p_md the media descriptor
406 * \param e_meta the meta to write
407 * \param psz_value the media's meta
409 LIBVLC_API void libvlc_media_set_meta( libvlc_media_t *p_md,
410 libvlc_meta_t e_meta,
411 const char *psz_value );
415 * Save the meta previously set
417 * \param p_md the media desriptor
418 * \return true if the write operation was successful
420 LIBVLC_API int libvlc_media_save_meta( libvlc_media_t *p_md );
424 * Get current state of media descriptor object. Possible media states
425 * are defined in libvlc_structures.c ( libvlc_NothingSpecial=0,
426 * libvlc_Opening, libvlc_Buffering, libvlc_Playing, libvlc_Paused,
427 * libvlc_Stopped, libvlc_Ended,
430 * \see libvlc_state_t
431 * \param p_md a media descriptor object
432 * \return state of media descriptor object
434 LIBVLC_API libvlc_state_t libvlc_media_get_state(
435 libvlc_media_t *p_md );
439 * Get the current statistics about the media
440 * \param p_md: media descriptor object
441 * \param p_stats: structure that contain the statistics about the media
442 * (this structure must be allocated by the caller)
443 * \return true if the statistics are available, false otherwise
445 * \libvlc_return_bool
447 LIBVLC_API int libvlc_media_get_stats( libvlc_media_t *p_md,
448 libvlc_media_stats_t *p_stats );
450 /* The following method uses libvlc_media_list_t, however, media_list usage is optionnal
451 * and this is here for convenience */
452 #define VLC_FORWARD_DECLARE_OBJECT(a) struct a
455 * Get subitems of media descriptor object. This will increment
456 * the reference count of supplied media descriptor object. Use
457 * libvlc_media_list_release() to decrement the reference counting.
459 * \param p_md media descriptor object
460 * \return list of media descriptor subitems or NULL
462 LIBVLC_API VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t *)
463 libvlc_media_subitems( libvlc_media_t *p_md );
466 * Get event manager from media descriptor object.
467 * NOTE: this function doesn't increment reference counting.
469 * \param p_md a media descriptor object
470 * \return event manager object
472 LIBVLC_API libvlc_event_manager_t *
473 libvlc_media_event_manager( libvlc_media_t *p_md );
476 * Get duration (in ms) of media descriptor object item.
478 * \param p_md media descriptor object
479 * \return duration of media item or -1 on error
481 LIBVLC_API libvlc_time_t
482 libvlc_media_get_duration( libvlc_media_t *p_md );
487 * This fetches (local) meta data and tracks information.
488 * The method is synchronous.
490 * \see libvlc_media_parse_async
491 * \see libvlc_media_get_meta
492 * \see libvlc_media_get_tracks_info
494 * \param p_md media descriptor object
497 libvlc_media_parse( libvlc_media_t *p_md );
502 * This fetches (local) meta data and tracks information.
503 * The method is the asynchronous of libvlc_media_parse().
505 * To track when this is over you can listen to libvlc_MediaParsedChanged
506 * event. However if the media was already parsed you will not receive this
509 * \see libvlc_media_parse
510 * \see libvlc_MediaParsedChanged
511 * \see libvlc_media_get_meta
512 * \see libvlc_media_get_tracks_info
514 * \param p_md media descriptor object
517 libvlc_media_parse_async( libvlc_media_t *p_md );
520 * Get Parsed status for media descriptor object.
522 * \see libvlc_MediaParsedChanged
524 * \param p_md media descriptor object
525 * \return true if media object has been parsed otherwise it returns false
527 * \libvlc_return_bool
530 libvlc_media_is_parsed( libvlc_media_t *p_md );
533 * Sets media descriptor's user_data. user_data is specialized data
534 * accessed by the host application, VLC.framework uses it as a pointer to
535 * an native object that references a libvlc_media_t pointer
537 * \param p_md media descriptor object
538 * \param p_new_user_data pointer to user data
541 libvlc_media_set_user_data( libvlc_media_t *p_md, void *p_new_user_data );
544 * Get media descriptor's user_data. user_data is specialized data
545 * accessed by the host application, VLC.framework uses it as a pointer to
546 * an native object that references a libvlc_media_t pointer
548 * \param p_md media descriptor object
550 LIBVLC_API void *libvlc_media_get_user_data( libvlc_media_t *p_md );
553 * Get media descriptor's elementary streams description
555 * Note, you need to call libvlc_media_parse() or play the media at least once
556 * before calling this function.
557 * Not doing this will result in an empty array.
559 * \deprecated Use libvlc_media_tracks_get instead
561 * \param p_md media descriptor object
562 * \param tracks address to store an allocated array of Elementary Streams
563 * descriptions (must be freed by the caller) [OUT]
565 * \return the number of Elementary Streams
567 LIBVLC_DEPRECATED LIBVLC_API
568 int libvlc_media_get_tracks_info( libvlc_media_t *p_md,
569 libvlc_media_track_info_t **tracks );
572 * Get media descriptor's elementary streams description
574 * Note, you need to call libvlc_media_parse() or play the media at least once
575 * before calling this function.
576 * Not doing this will result in an empty array.
578 * \version LibVLC 2.1.0 and later.
580 * \param p_md media descriptor object
581 * \param tracks address to store an allocated array of Elementary Streams
582 * descriptions (must be freed with libvlc_media_tracks_release
585 * \return the number of Elementary Streams (zero on error)
588 unsigned libvlc_media_tracks_get( libvlc_media_t *p_md,
589 libvlc_media_track_t ***tracks );
593 * Release media descriptor's elementary streams description array
595 * \version LibVLC 2.1.0 and later.
597 * \param p_tracks tracks info array to release
598 * \param i_count number of elements in the array
601 void libvlc_media_tracks_release( libvlc_media_track_t **p_tracks,
610 #endif /* VLC_LIBVLC_MEDIA_H */