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 libvlc_meta_DiscNumber
79 /* Add new meta types HERE */
85 * Note the order of libvlc_state_t enum must match exactly the order of
86 * \see mediacontrol_PlayerStatus, \see input_state_e enums,
87 * and VideoLAN.LibVLC.State (at bindings/cil/src/media.cs).
89 * Expected states by web plugins are:
90 * IDLE/CLOSE=0, OPENING=1, BUFFERING=2, PLAYING=3, PAUSED=4,
91 * STOPPING=5, ENDED=6, ERROR=7
93 typedef enum libvlc_state_t
95 libvlc_NothingSpecial=0,
107 libvlc_media_option_trusted = 0x2,
108 libvlc_media_option_unique = 0x100
111 typedef enum libvlc_track_type_t
113 libvlc_track_unknown = -1,
114 libvlc_track_audio = 0,
115 libvlc_track_video = 1,
116 libvlc_track_text = 2
117 } libvlc_track_type_t;
119 /** defgroup libvlc_media_stats_t LibVLC media statistics
120 * \ingroup libvlc_media
123 typedef struct libvlc_media_stats_t
127 float f_input_bitrate;
130 int i_demux_read_bytes;
131 float f_demux_bitrate;
132 int i_demux_corrupted;
133 int i_demux_discontinuity;
140 int i_displayed_pictures;
144 int i_played_abuffers;
150 float f_send_bitrate;
151 } libvlc_media_stats_t;
154 typedef struct libvlc_media_track_info_t
159 libvlc_track_type_t i_type;
178 } libvlc_media_track_info_t;
181 typedef struct libvlc_audio_track_t
185 } libvlc_audio_track_t;
187 typedef struct libvlc_video_track_t
193 unsigned i_frame_rate_num;
194 unsigned i_frame_rate_den;
195 } libvlc_video_track_t;
197 typedef struct libvlc_subtitle_track_t
200 } libvlc_subtitle_track_t;
202 typedef struct libvlc_media_track_t
206 uint32_t i_original_fourcc;
208 libvlc_track_type_t i_type;
215 libvlc_audio_track_t *audio;
216 libvlc_video_track_t *video;
217 libvlc_subtitle_track_t *subtitle;
220 unsigned int i_bitrate;
222 char *psz_description;
224 } libvlc_media_track_t;
226 /** defgroup libvlc_media_type LibVLC media type
227 * \ingroup libvlc_media
234 * \see libvlc_media_get_type
236 typedef enum libvlc_media_type_t {
237 libvlc_media_type_unknown,
238 libvlc_media_type_file,
239 libvlc_media_type_directory,
240 libvlc_media_type_disc,
241 libvlc_media_type_stream,
242 libvlc_media_type_playlist,
243 } libvlc_media_type_t;
248 * Parse flags used by libvlc_media_parse_with_options()
250 * \see libvlc_media_parse_with_options
252 typedef enum libvlc_media_parse_flag_t
255 * Parse media if it's a local file
257 libvlc_media_parse_local = 0x00,
259 * Parse media even if it's a network file
261 libvlc_media_parse_network = 0x01,
263 * Fetch meta and covert art using local resources
265 libvlc_media_fetch_local = 0x02,
267 * Fetch meta and covert art using network resources
269 libvlc_media_fetch_network = 0x04,
270 } libvlc_media_parse_flag_t;
273 * Create a media with a certain given media resource location,
274 * for instance a valid URL.
276 * \note To refer to a local file with this function,
277 * the file://... URI syntax <b>must</b> be used (see IETF RFC3986).
278 * We recommend using libvlc_media_new_path() instead when dealing with
281 * \see libvlc_media_release
283 * \param p_instance the instance
284 * \param psz_mrl the media location
285 * \return the newly created media or NULL on error
287 LIBVLC_API libvlc_media_t *libvlc_media_new_location(
288 libvlc_instance_t *p_instance,
289 const char * psz_mrl );
292 * Create a media for a certain file path.
294 * \see libvlc_media_release
296 * \param p_instance the instance
297 * \param path local filesystem path
298 * \return the newly created media or NULL on error
300 LIBVLC_API libvlc_media_t *libvlc_media_new_path(
301 libvlc_instance_t *p_instance,
305 * Create a media for an already open file descriptor.
306 * The file descriptor shall be open for reading (or reading and writing).
308 * Regular file descriptors, pipe read descriptors and character device
309 * descriptors (including TTYs) are supported on all platforms.
310 * Block device descriptors are supported where available.
311 * Directory descriptors are supported on systems that provide fdopendir().
312 * Sockets are supported on all platforms where they are file descriptors,
313 * i.e. all except Windows.
315 * \note This library will <b>not</b> automatically close the file descriptor
316 * under any circumstance. Nevertheless, a file descriptor can usually only be
317 * rendered once in a media player. To render it a second time, the file
318 * descriptor should probably be rewound to the beginning with lseek().
320 * \see libvlc_media_release
322 * \version LibVLC 1.1.5 and later.
324 * \param p_instance the instance
325 * \param fd open file descriptor
326 * \return the newly created media or NULL on error
328 LIBVLC_API libvlc_media_t *libvlc_media_new_fd(
329 libvlc_instance_t *p_instance,
334 * Create a media as an empty node with a given name.
336 * \see libvlc_media_release
338 * \param p_instance the instance
339 * \param psz_name the name of the node
340 * \return the new empty media or NULL on error
342 LIBVLC_API libvlc_media_t *libvlc_media_new_as_node(
343 libvlc_instance_t *p_instance,
344 const char * psz_name );
347 * Add an option to the media.
349 * This option will be used to determine how the media_player will
350 * read the media. This allows to use VLC's advanced
351 * reading/streaming options on a per-media basis.
353 * \note The options are listed in 'vlc --long-help' from the command line,
354 * e.g. "-sout-all". Keep in mind that available options and their semantics
355 * vary across LibVLC versions and builds.
356 * \warning Not all options affects libvlc_media_t objects:
357 * Specifically, due to architectural issues most audio and video options,
358 * such as text renderer options, have no effects on an individual media.
359 * These options must be set through libvlc_new() instead.
361 * \param p_md the media descriptor
362 * \param psz_options the options (as a string)
364 LIBVLC_API void libvlc_media_add_option(
365 libvlc_media_t *p_md,
366 const char * psz_options );
369 * Add an option to the media with configurable flags.
371 * This option will be used to determine how the media_player will
372 * read the media. This allows to use VLC's advanced
373 * reading/streaming options on a per-media basis.
375 * The options are detailed in vlc --long-help, for instance
376 * "--sout-all". Note that all options are not usable on medias:
377 * specifically, due to architectural issues, video-related options
378 * such as text renderer options cannot be set on a single media. They
379 * must be set on the whole libvlc instance instead.
381 * \param p_md the media descriptor
382 * \param psz_options the options (as a string)
383 * \param i_flags the flags for this option
385 LIBVLC_API void libvlc_media_add_option_flag(
386 libvlc_media_t *p_md,
387 const char * psz_options,
392 * Retain a reference to a media descriptor object (libvlc_media_t). Use
393 * libvlc_media_release() to decrement the reference count of a
394 * media descriptor object.
396 * \param p_md the media descriptor
398 LIBVLC_API void libvlc_media_retain( libvlc_media_t *p_md );
401 * Decrement the reference count of a media descriptor object. If the
402 * reference count is 0, then libvlc_media_release() will release the
403 * media descriptor object. It will send out an libvlc_MediaFreed event
404 * to all listeners. If the media descriptor object has been released it
405 * should not be used again.
407 * \param p_md the media descriptor
409 LIBVLC_API void libvlc_media_release( libvlc_media_t *p_md );
413 * Get the media resource locator (mrl) from a media descriptor object
415 * \param p_md a media descriptor object
416 * \return string with mrl of media descriptor object
418 LIBVLC_API char *libvlc_media_get_mrl( libvlc_media_t *p_md );
421 * Duplicate a media descriptor object.
423 * \param p_md a media descriptor object.
425 LIBVLC_API libvlc_media_t *libvlc_media_duplicate( libvlc_media_t *p_md );
428 * Read the meta of the media.
430 * If the media has not yet been parsed this will return NULL.
432 * This methods automatically calls libvlc_media_parse_async(), so after calling
433 * it you may receive a libvlc_MediaMetaChanged event. If you prefer a synchronous
434 * version ensure that you call libvlc_media_parse() before get_meta().
436 * \see libvlc_media_parse
437 * \see libvlc_media_parse_async
438 * \see libvlc_MediaMetaChanged
440 * \param p_md the media descriptor
441 * \param e_meta the meta to read
442 * \return the media's meta
444 LIBVLC_API char *libvlc_media_get_meta( libvlc_media_t *p_md,
445 libvlc_meta_t e_meta );
448 * Set the meta of the media (this function will not save the meta, call
449 * libvlc_media_save_meta in order to save the meta)
451 * \param p_md the media descriptor
452 * \param e_meta the meta to write
453 * \param psz_value the media's meta
455 LIBVLC_API void libvlc_media_set_meta( libvlc_media_t *p_md,
456 libvlc_meta_t e_meta,
457 const char *psz_value );
461 * Save the meta previously set
463 * \param p_md the media desriptor
464 * \return true if the write operation was successful
466 LIBVLC_API int libvlc_media_save_meta( libvlc_media_t *p_md );
470 * Get current state of media descriptor object. Possible media states
471 * are defined in libvlc_structures.c ( libvlc_NothingSpecial=0,
472 * libvlc_Opening, libvlc_Buffering, libvlc_Playing, libvlc_Paused,
473 * libvlc_Stopped, libvlc_Ended,
476 * \see libvlc_state_t
477 * \param p_md a media descriptor object
478 * \return state of media descriptor object
480 LIBVLC_API libvlc_state_t libvlc_media_get_state(
481 libvlc_media_t *p_md );
485 * Get the current statistics about the media
486 * \param p_md: media descriptor object
487 * \param p_stats: structure that contain the statistics about the media
488 * (this structure must be allocated by the caller)
489 * \return true if the statistics are available, false otherwise
491 * \libvlc_return_bool
493 LIBVLC_API int libvlc_media_get_stats( libvlc_media_t *p_md,
494 libvlc_media_stats_t *p_stats );
496 /* The following method uses libvlc_media_list_t, however, media_list usage is optionnal
497 * and this is here for convenience */
498 #define VLC_FORWARD_DECLARE_OBJECT(a) struct a
501 * Get subitems of media descriptor object. This will increment
502 * the reference count of supplied media descriptor object. Use
503 * libvlc_media_list_release() to decrement the reference counting.
505 * \param p_md media descriptor object
506 * \return list of media descriptor subitems or NULL
508 LIBVLC_API VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t *)
509 libvlc_media_subitems( libvlc_media_t *p_md );
512 * Get event manager from media descriptor object.
513 * NOTE: this function doesn't increment reference counting.
515 * \param p_md a media descriptor object
516 * \return event manager object
518 LIBVLC_API libvlc_event_manager_t *
519 libvlc_media_event_manager( libvlc_media_t *p_md );
522 * Get duration (in ms) of media descriptor object item.
524 * \param p_md media descriptor object
525 * \return duration of media item or -1 on error
527 LIBVLC_API libvlc_time_t
528 libvlc_media_get_duration( libvlc_media_t *p_md );
533 * This fetches (local) art, meta data and tracks information.
534 * The method is synchronous.
536 * \see libvlc_media_parse_async
537 * \see libvlc_media_get_meta
538 * \see libvlc_media_get_tracks_info
540 * \param p_md media descriptor object
543 libvlc_media_parse( libvlc_media_t *p_md );
548 * This fetches (local) art, meta data and tracks information.
549 * The method is the asynchronous of libvlc_media_parse().
551 * To track when this is over you can listen to libvlc_MediaParsedChanged
552 * event. However if the media was already parsed you will not receive this
555 * \see libvlc_media_parse
556 * \see libvlc_MediaParsedChanged
557 * \see libvlc_media_get_meta
558 * \see libvlc_media_get_tracks_info
560 * \param p_md media descriptor object
563 libvlc_media_parse_async( libvlc_media_t *p_md );
566 * Parse the media asynchronously with options.
568 * This fetches (local or network) art, meta data and/or tracks information.
569 * This method is the extended version of libvlc_media_parse_async().
571 * To track when this is over you can listen to libvlc_MediaParsedChanged
572 * event. However if this functions returns an error, you will not receive this
575 * It uses a flag to specify parse options (see libvlc_media_parse_flag_t). All
576 * these flags can be combined. By default, media is parsed if it's a local
579 * \see libvlc_MediaParsedChanged
580 * \see libvlc_media_get_meta
581 * \see libvlc_media_tracks_get
582 * \see libvlc_media_parse_flag_t
584 * \param p_md media descriptor object
585 * \param parse_flag parse options:
586 * \return -1 in case of error, 0 otherwise
587 * \version LibVLC 3.0.0 or later
590 libvlc_media_parse_with_options( libvlc_media_t *p_md,
591 libvlc_media_parse_flag_t parse_flag );
594 * Get Parsed status for media descriptor object.
596 * \see libvlc_MediaParsedChanged
598 * \param p_md media descriptor object
599 * \return true if media object has been parsed otherwise it returns false
601 * \libvlc_return_bool
604 libvlc_media_is_parsed( libvlc_media_t *p_md );
607 * Sets media descriptor's user_data. user_data is specialized data
608 * accessed by the host application, VLC.framework uses it as a pointer to
609 * an native object that references a libvlc_media_t pointer
611 * \param p_md media descriptor object
612 * \param p_new_user_data pointer to user data
615 libvlc_media_set_user_data( libvlc_media_t *p_md, void *p_new_user_data );
618 * Get media descriptor's user_data. user_data is specialized data
619 * accessed by the host application, VLC.framework uses it as a pointer to
620 * an native object that references a libvlc_media_t pointer
622 * \param p_md media descriptor object
624 LIBVLC_API void *libvlc_media_get_user_data( libvlc_media_t *p_md );
627 * Get media descriptor's elementary streams description
629 * Note, you need to call libvlc_media_parse() or play the media at least once
630 * before calling this function.
631 * Not doing this will result in an empty array.
633 * \deprecated Use libvlc_media_tracks_get instead
635 * \param p_md media descriptor object
636 * \param tracks address to store an allocated array of Elementary Streams
637 * descriptions (must be freed by the caller) [OUT]
639 * \return the number of Elementary Streams
641 LIBVLC_DEPRECATED LIBVLC_API
642 int libvlc_media_get_tracks_info( libvlc_media_t *p_md,
643 libvlc_media_track_info_t **tracks );
646 * Get media descriptor's elementary streams description
648 * Note, you need to call libvlc_media_parse() or play the media at least once
649 * before calling this function.
650 * Not doing this will result in an empty array.
652 * \version LibVLC 2.1.0 and later.
654 * \param p_md media descriptor object
655 * \param tracks address to store an allocated array of Elementary Streams
656 * descriptions (must be freed with libvlc_media_tracks_release
659 * \return the number of Elementary Streams (zero on error)
662 unsigned libvlc_media_tracks_get( libvlc_media_t *p_md,
663 libvlc_media_track_t ***tracks );
666 * Get codec description from media elementary stream
668 * \version LibVLC 3.0.0 and later.
670 * \see libvlc_media_track_t
672 * \param i_type i_type from libvlc_media_track_t
673 * \param i_codec i_codec or i_original_fourcc from libvlc_media_track_t
675 * \return codec description
678 const char *libvlc_media_get_codec_description( libvlc_track_type_t i_type,
682 * Release media descriptor's elementary streams description array
684 * \version LibVLC 2.1.0 and later.
686 * \param p_tracks tracks info array to release
687 * \param i_count number of elements in the array
690 void libvlc_media_tracks_release( libvlc_media_track_t **p_tracks,
694 * Get the media type of the media descriptor object
696 * \version LibVLC 3.0.0 and later.
698 * \see libvlc_media_type_t
700 * \param p_md media descriptor object
705 libvlc_media_type_t libvlc_media_get_type( libvlc_media_t *p_md );
713 #endif /* VLC_LIBVLC_MEDIA_H */