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;
227 * Parse flags used by libvlc_media_parse_with_options()
229 * \see libvlc_media_parse_with_options
231 typedef enum libvlc_media_parse_flag_t
234 * Parse media if it's a local file
236 libvlc_media_parse_local = 0x00,
238 * Parse media even if it's a network file
240 libvlc_media_parse_network = 0x01,
242 * Fetch meta and covert art using local resources
244 libvlc_media_fetch_local = 0x02,
246 * Fetch meta and covert art using network resources
248 libvlc_media_fetch_network = 0x04,
249 } libvlc_media_parse_flag_t;
252 * Create a media with a certain given media resource location,
253 * for instance a valid URL.
255 * \note To refer to a local file with this function,
256 * the file://... URI syntax <b>must</b> be used (see IETF RFC3986).
257 * We recommend using libvlc_media_new_path() instead when dealing with
260 * \see libvlc_media_release
262 * \param p_instance the instance
263 * \param psz_mrl the media location
264 * \return the newly created media or NULL on error
266 LIBVLC_API libvlc_media_t *libvlc_media_new_location(
267 libvlc_instance_t *p_instance,
268 const char * psz_mrl );
271 * Create a media for a certain file path.
273 * \see libvlc_media_release
275 * \param p_instance the instance
276 * \param path local filesystem path
277 * \return the newly created media or NULL on error
279 LIBVLC_API libvlc_media_t *libvlc_media_new_path(
280 libvlc_instance_t *p_instance,
284 * Create a media for an already open file descriptor.
285 * The file descriptor shall be open for reading (or reading and writing).
287 * Regular file descriptors, pipe read descriptors and character device
288 * descriptors (including TTYs) are supported on all platforms.
289 * Block device descriptors are supported where available.
290 * Directory descriptors are supported on systems that provide fdopendir().
291 * Sockets are supported on all platforms where they are file descriptors,
292 * i.e. all except Windows.
294 * \note This library will <b>not</b> automatically close the file descriptor
295 * under any circumstance. Nevertheless, a file descriptor can usually only be
296 * rendered once in a media player. To render it a second time, the file
297 * descriptor should probably be rewound to the beginning with lseek().
299 * \see libvlc_media_release
301 * \version LibVLC 1.1.5 and later.
303 * \param p_instance the instance
304 * \param fd open file descriptor
305 * \return the newly created media or NULL on error
307 LIBVLC_API libvlc_media_t *libvlc_media_new_fd(
308 libvlc_instance_t *p_instance,
313 * Create a media as an empty node with a given name.
315 * \see libvlc_media_release
317 * \param p_instance the instance
318 * \param psz_name the name of the node
319 * \return the new empty media or NULL on error
321 LIBVLC_API libvlc_media_t *libvlc_media_new_as_node(
322 libvlc_instance_t *p_instance,
323 const char * psz_name );
326 * Add an option to the media.
328 * This option will be used to determine how the media_player will
329 * read the media. This allows to use VLC's advanced
330 * reading/streaming options on a per-media basis.
332 * \note The options are listed in 'vlc --long-help' from the command line,
333 * e.g. "-sout-all". Keep in mind that available options and their semantics
334 * vary across LibVLC versions and builds.
335 * \warning Not all options affects libvlc_media_t objects:
336 * Specifically, due to architectural issues most audio and video options,
337 * such as text renderer options, have no effects on an individual media.
338 * These options must be set through libvlc_new() instead.
340 * \param p_md the media descriptor
341 * \param psz_options the options (as a string)
343 LIBVLC_API void libvlc_media_add_option(
344 libvlc_media_t *p_md,
345 const char * psz_options );
348 * Add an option to the media with configurable flags.
350 * This option will be used to determine how the media_player will
351 * read the media. This allows to use VLC's advanced
352 * reading/streaming options on a per-media basis.
354 * The options are detailed in vlc --long-help, for instance
355 * "--sout-all". Note that all options are not usable on medias:
356 * specifically, due to architectural issues, video-related options
357 * such as text renderer options cannot be set on a single media. They
358 * must be set on the whole libvlc instance instead.
360 * \param p_md the media descriptor
361 * \param psz_options the options (as a string)
362 * \param i_flags the flags for this option
364 LIBVLC_API void libvlc_media_add_option_flag(
365 libvlc_media_t *p_md,
366 const char * psz_options,
371 * Retain a reference to a media descriptor object (libvlc_media_t). Use
372 * libvlc_media_release() to decrement the reference count of a
373 * media descriptor object.
375 * \param p_md the media descriptor
377 LIBVLC_API void libvlc_media_retain( libvlc_media_t *p_md );
380 * Decrement the reference count of a media descriptor object. If the
381 * reference count is 0, then libvlc_media_release() will release the
382 * media descriptor object. It will send out an libvlc_MediaFreed event
383 * to all listeners. If the media descriptor object has been released it
384 * should not be used again.
386 * \param p_md the media descriptor
388 LIBVLC_API void libvlc_media_release( libvlc_media_t *p_md );
392 * Get the media resource locator (mrl) from a media descriptor object
394 * \param p_md a media descriptor object
395 * \return string with mrl of media descriptor object
397 LIBVLC_API char *libvlc_media_get_mrl( libvlc_media_t *p_md );
400 * Duplicate a media descriptor object.
402 * \param p_md a media descriptor object.
404 LIBVLC_API libvlc_media_t *libvlc_media_duplicate( libvlc_media_t *p_md );
407 * Read the meta of the media.
409 * If the media has not yet been parsed this will return NULL.
411 * This methods automatically calls libvlc_media_parse_async(), so after calling
412 * it you may receive a libvlc_MediaMetaChanged event. If you prefer a synchronous
413 * version ensure that you call libvlc_media_parse() before get_meta().
415 * \see libvlc_media_parse
416 * \see libvlc_media_parse_async
417 * \see libvlc_MediaMetaChanged
419 * \param p_md the media descriptor
420 * \param e_meta the meta to read
421 * \return the media's meta
423 LIBVLC_API char *libvlc_media_get_meta( libvlc_media_t *p_md,
424 libvlc_meta_t e_meta );
427 * Set the meta of the media (this function will not save the meta, call
428 * libvlc_media_save_meta in order to save the meta)
430 * \param p_md the media descriptor
431 * \param e_meta the meta to write
432 * \param psz_value the media's meta
434 LIBVLC_API void libvlc_media_set_meta( libvlc_media_t *p_md,
435 libvlc_meta_t e_meta,
436 const char *psz_value );
440 * Save the meta previously set
442 * \param p_md the media desriptor
443 * \return true if the write operation was successful
445 LIBVLC_API int libvlc_media_save_meta( libvlc_media_t *p_md );
449 * Get current state of media descriptor object. Possible media states
450 * are defined in libvlc_structures.c ( libvlc_NothingSpecial=0,
451 * libvlc_Opening, libvlc_Buffering, libvlc_Playing, libvlc_Paused,
452 * libvlc_Stopped, libvlc_Ended,
455 * \see libvlc_state_t
456 * \param p_md a media descriptor object
457 * \return state of media descriptor object
459 LIBVLC_API libvlc_state_t libvlc_media_get_state(
460 libvlc_media_t *p_md );
464 * Get the current statistics about the media
465 * \param p_md: media descriptor object
466 * \param p_stats: structure that contain the statistics about the media
467 * (this structure must be allocated by the caller)
468 * \return true if the statistics are available, false otherwise
470 * \libvlc_return_bool
472 LIBVLC_API int libvlc_media_get_stats( libvlc_media_t *p_md,
473 libvlc_media_stats_t *p_stats );
475 /* The following method uses libvlc_media_list_t, however, media_list usage is optionnal
476 * and this is here for convenience */
477 #define VLC_FORWARD_DECLARE_OBJECT(a) struct a
480 * Get subitems of media descriptor object. This will increment
481 * the reference count of supplied media descriptor object. Use
482 * libvlc_media_list_release() to decrement the reference counting.
484 * \param p_md media descriptor object
485 * \return list of media descriptor subitems or NULL
487 LIBVLC_API VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t *)
488 libvlc_media_subitems( libvlc_media_t *p_md );
491 * Get event manager from media descriptor object.
492 * NOTE: this function doesn't increment reference counting.
494 * \param p_md a media descriptor object
495 * \return event manager object
497 LIBVLC_API libvlc_event_manager_t *
498 libvlc_media_event_manager( libvlc_media_t *p_md );
501 * Get duration (in ms) of media descriptor object item.
503 * \param p_md media descriptor object
504 * \return duration of media item or -1 on error
506 LIBVLC_API libvlc_time_t
507 libvlc_media_get_duration( libvlc_media_t *p_md );
512 * This fetches (local) art, meta data and tracks information.
513 * The method is synchronous.
515 * \see libvlc_media_parse_async
516 * \see libvlc_media_get_meta
517 * \see libvlc_media_get_tracks_info
519 * \param p_md media descriptor object
522 libvlc_media_parse( libvlc_media_t *p_md );
527 * This fetches (local) art, meta data and tracks information.
528 * The method is the asynchronous of libvlc_media_parse().
530 * To track when this is over you can listen to libvlc_MediaParsedChanged
531 * event. However if the media was already parsed you will not receive this
534 * \see libvlc_media_parse
535 * \see libvlc_MediaParsedChanged
536 * \see libvlc_media_get_meta
537 * \see libvlc_media_get_tracks_info
539 * \param p_md media descriptor object
542 libvlc_media_parse_async( libvlc_media_t *p_md );
545 * Parse the media asynchronously with options.
547 * This fetches (local or network) art, meta data and/or tracks information.
548 * This method is the extended version of libvlc_media_parse_async().
550 * To track when this is over you can listen to libvlc_MediaParsedChanged
551 * event. However if this functions returns an error, you will not receive this
554 * It uses a flag to specify parse options (see libvlc_media_parse_flag_t). All
555 * these flags can be combined. By default, media is parsed if it's a local
558 * \see libvlc_MediaParsedChanged
559 * \see libvlc_media_get_meta
560 * \see libvlc_media_tracks_get
561 * \see libvlc_media_parse_flag_t
563 * \param p_md media descriptor object
564 * \param parse_flag parse options:
565 * \return -1 in case of error, 0 otherwise
566 * \version LibVLC 3.0.0 or later
569 libvlc_media_parse_with_options( libvlc_media_t *p_md,
570 libvlc_media_parse_flag_t parse_flag );
573 * Get Parsed status for media descriptor object.
575 * \see libvlc_MediaParsedChanged
577 * \param p_md media descriptor object
578 * \return true if media object has been parsed otherwise it returns false
580 * \libvlc_return_bool
583 libvlc_media_is_parsed( libvlc_media_t *p_md );
586 * Sets media descriptor's user_data. user_data is specialized data
587 * accessed by the host application, VLC.framework uses it as a pointer to
588 * an native object that references a libvlc_media_t pointer
590 * \param p_md media descriptor object
591 * \param p_new_user_data pointer to user data
594 libvlc_media_set_user_data( libvlc_media_t *p_md, void *p_new_user_data );
597 * Get media descriptor's user_data. user_data is specialized data
598 * accessed by the host application, VLC.framework uses it as a pointer to
599 * an native object that references a libvlc_media_t pointer
601 * \param p_md media descriptor object
603 LIBVLC_API void *libvlc_media_get_user_data( libvlc_media_t *p_md );
606 * Get media descriptor's elementary streams description
608 * Note, you need to call libvlc_media_parse() or play the media at least once
609 * before calling this function.
610 * Not doing this will result in an empty array.
612 * \deprecated Use libvlc_media_tracks_get instead
614 * \param p_md media descriptor object
615 * \param tracks address to store an allocated array of Elementary Streams
616 * descriptions (must be freed by the caller) [OUT]
618 * \return the number of Elementary Streams
620 LIBVLC_DEPRECATED LIBVLC_API
621 int libvlc_media_get_tracks_info( libvlc_media_t *p_md,
622 libvlc_media_track_info_t **tracks );
625 * Get media descriptor's elementary streams description
627 * Note, you need to call libvlc_media_parse() or play the media at least once
628 * before calling this function.
629 * Not doing this will result in an empty array.
631 * \version LibVLC 2.1.0 and later.
633 * \param p_md media descriptor object
634 * \param tracks address to store an allocated array of Elementary Streams
635 * descriptions (must be freed with libvlc_media_tracks_release
638 * \return the number of Elementary Streams (zero on error)
641 unsigned libvlc_media_tracks_get( libvlc_media_t *p_md,
642 libvlc_media_track_t ***tracks );
645 * Get codec description from media elementary stream
647 * \version LibVLC 3.0.0 and later.
649 * \see libvlc_media_track_t
651 * \param i_type i_type from libvlc_media_track_t
652 * \param i_codec i_codec or i_original_fourcc from libvlc_media_track_t
654 * \return codec description
657 const char *libvlc_media_get_codec_description( libvlc_track_type_t i_type,
661 * Release media descriptor's elementary streams description array
663 * \version LibVLC 2.1.0 and later.
665 * \param p_tracks tracks info array to release
666 * \param i_count number of elements in the array
669 void libvlc_media_tracks_release( libvlc_media_track_t **p_tracks,
678 #endif /* VLC_LIBVLC_MEDIA_H */