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 /* Add new meta types HERE */
83 * Note the order of libvlc_state_t enum must match exactly the order of
84 * \see mediacontrol_PlayerStatus, \see input_state_e enums,
85 * and VideoLAN.LibVLC.State (at bindings/cil/src/media.cs).
87 * Expected states by web plugins are:
88 * IDLE/CLOSE=0, OPENING=1, BUFFERING=2, PLAYING=3, PAUSED=4,
89 * STOPPING=5, ENDED=6, ERROR=7
91 typedef enum libvlc_state_t
93 libvlc_NothingSpecial=0,
105 libvlc_media_option_trusted = 0x2,
106 libvlc_media_option_unique = 0x100
109 typedef enum libvlc_track_type_t
111 libvlc_track_unknown = -1,
112 libvlc_track_audio = 0,
113 libvlc_track_video = 1,
114 libvlc_track_text = 2
115 } libvlc_track_type_t;
117 /** defgroup libvlc_media_stats_t LibVLC media statistics
118 * \ingroup libvlc_media
121 typedef struct libvlc_media_stats_t
125 float f_input_bitrate;
128 int i_demux_read_bytes;
129 float f_demux_bitrate;
130 int i_demux_corrupted;
131 int i_demux_discontinuity;
138 int i_displayed_pictures;
142 int i_played_abuffers;
148 float f_send_bitrate;
149 } libvlc_media_stats_t;
152 typedef struct libvlc_media_track_info_t
157 libvlc_track_type_t i_type;
176 } libvlc_media_track_info_t;
179 typedef struct libvlc_audio_track_t
183 } libvlc_audio_track_t;
185 typedef struct libvlc_video_track_t
191 unsigned i_frame_rate_num;
192 unsigned i_frame_rate_den;
193 } libvlc_video_track_t;
195 typedef struct libvlc_subtitle_track_t
198 } libvlc_subtitle_track_t;
200 typedef struct libvlc_media_track_t
204 uint32_t i_original_fourcc;
206 libvlc_track_type_t i_type;
213 libvlc_audio_track_t *audio;
214 libvlc_video_track_t *video;
215 libvlc_subtitle_track_t *subtitle;
218 unsigned int i_bitrate;
220 char *psz_description;
222 } libvlc_media_track_t;
226 * Create a media with a certain given media resource location,
227 * for instance a valid URL.
229 * \note To refer to a local file with this function,
230 * the file://... URI syntax <b>must</b> be used (see IETF RFC3986).
231 * We recommend using libvlc_media_new_path() instead when dealing with
234 * \see libvlc_media_release
236 * \param p_instance the instance
237 * \param psz_mrl the media location
238 * \return the newly created media or NULL on error
240 LIBVLC_API libvlc_media_t *libvlc_media_new_location(
241 libvlc_instance_t *p_instance,
242 const char * psz_mrl );
245 * Create a media for a certain file path.
247 * \see libvlc_media_release
249 * \param p_instance the instance
250 * \param path local filesystem path
251 * \return the newly created media or NULL on error
253 LIBVLC_API libvlc_media_t *libvlc_media_new_path(
254 libvlc_instance_t *p_instance,
258 * Create a media for an already open file descriptor.
259 * The file descriptor shall be open for reading (or reading and writing).
261 * Regular file descriptors, pipe read descriptors and character device
262 * descriptors (including TTYs) are supported on all platforms.
263 * Block device descriptors are supported where available.
264 * Directory descriptors are supported on systems that provide fdopendir().
265 * Sockets are supported on all platforms where they are file descriptors,
266 * i.e. all except Windows.
268 * \note This library will <b>not</b> automatically close the file descriptor
269 * under any circumstance. Nevertheless, a file descriptor can usually only be
270 * rendered once in a media player. To render it a second time, the file
271 * descriptor should probably be rewound to the beginning with lseek().
273 * \see libvlc_media_release
275 * \version LibVLC 1.1.5 and later.
277 * \param p_instance the instance
278 * \param fd open file descriptor
279 * \return the newly created media or NULL on error
281 LIBVLC_API libvlc_media_t *libvlc_media_new_fd(
282 libvlc_instance_t *p_instance,
287 * Create a media as an empty node with a given name.
289 * \see libvlc_media_release
291 * \param p_instance the instance
292 * \param psz_name the name of the node
293 * \return the new empty media or NULL on error
295 LIBVLC_API libvlc_media_t *libvlc_media_new_as_node(
296 libvlc_instance_t *p_instance,
297 const char * psz_name );
300 * Add an option to the media.
302 * This option will be used to determine how the media_player will
303 * read the media. This allows to use VLC's advanced
304 * reading/streaming options on a per-media basis.
306 * \note The options are listed in 'vlc --long-help' from the command line,
307 * e.g. "-sout-all". Keep in mind that available options and their semantics
308 * vary across LibVLC versions and builds.
309 * \warning Not all options affects libvlc_media_t objects:
310 * Specifically, due to architectural issues most audio and video options,
311 * such as text renderer options, have no effects on an individual media.
312 * These options must be set through libvlc_new() instead.
314 * \param p_md the media descriptor
315 * \param psz_options the options (as a string)
317 LIBVLC_API void libvlc_media_add_option(
318 libvlc_media_t *p_md,
319 const char * psz_options );
322 * Add an option to the media with configurable flags.
324 * This option will be used to determine how the media_player will
325 * read the media. This allows to use VLC's advanced
326 * reading/streaming options on a per-media basis.
328 * The options are detailed in vlc --long-help, for instance
329 * "--sout-all". Note that all options are not usable on medias:
330 * specifically, due to architectural issues, video-related options
331 * such as text renderer options cannot be set on a single media. They
332 * must be set on the whole libvlc instance instead.
334 * \param p_md the media descriptor
335 * \param psz_options the options (as a string)
336 * \param i_flags the flags for this option
338 LIBVLC_API void libvlc_media_add_option_flag(
339 libvlc_media_t *p_md,
340 const char * psz_options,
345 * Retain a reference to a media descriptor object (libvlc_media_t). Use
346 * libvlc_media_release() to decrement the reference count of a
347 * media descriptor object.
349 * \param p_md the media descriptor
351 LIBVLC_API void libvlc_media_retain( libvlc_media_t *p_md );
354 * Decrement the reference count of a media descriptor object. If the
355 * reference count is 0, then libvlc_media_release() will release the
356 * media descriptor object. It will send out an libvlc_MediaFreed event
357 * to all listeners. If the media descriptor object has been released it
358 * should not be used again.
360 * \param p_md the media descriptor
362 LIBVLC_API void libvlc_media_release( libvlc_media_t *p_md );
366 * Get the media resource locator (mrl) from a media descriptor object
368 * \param p_md a media descriptor object
369 * \return string with mrl of media descriptor object
371 LIBVLC_API char *libvlc_media_get_mrl( libvlc_media_t *p_md );
374 * Duplicate a media descriptor object.
376 * \param p_md a media descriptor object.
378 LIBVLC_API libvlc_media_t *libvlc_media_duplicate( libvlc_media_t *p_md );
381 * Read the meta of the media.
383 * If the media has not yet been parsed this will return NULL.
385 * This methods automatically calls libvlc_media_parse_async(), so after calling
386 * it you may receive a libvlc_MediaMetaChanged event. If you prefer a synchronous
387 * version ensure that you call libvlc_media_parse() before get_meta().
389 * \see libvlc_media_parse
390 * \see libvlc_media_parse_async
391 * \see libvlc_MediaMetaChanged
393 * \param p_md the media descriptor
394 * \param e_meta the meta to read
395 * \return the media's meta
397 LIBVLC_API char *libvlc_media_get_meta( libvlc_media_t *p_md,
398 libvlc_meta_t e_meta );
401 * Set the meta of the media (this function will not save the meta, call
402 * libvlc_media_save_meta in order to save the meta)
404 * \param p_md the media descriptor
405 * \param e_meta the meta to write
406 * \param psz_value the media's meta
408 LIBVLC_API void libvlc_media_set_meta( libvlc_media_t *p_md,
409 libvlc_meta_t e_meta,
410 const char *psz_value );
414 * Save the meta previously set
416 * \param p_md the media desriptor
417 * \return true if the write operation was successful
419 LIBVLC_API int libvlc_media_save_meta( libvlc_media_t *p_md );
423 * Get current state of media descriptor object. Possible media states
424 * are defined in libvlc_structures.c ( libvlc_NothingSpecial=0,
425 * libvlc_Opening, libvlc_Buffering, libvlc_Playing, libvlc_Paused,
426 * libvlc_Stopped, libvlc_Ended,
429 * \see libvlc_state_t
430 * \param p_md a media descriptor object
431 * \return state of media descriptor object
433 LIBVLC_API libvlc_state_t libvlc_media_get_state(
434 libvlc_media_t *p_md );
438 * Get the current statistics about the media
439 * \param p_md: media descriptor object
440 * \param p_stats: structure that contain the statistics about the media
441 * (this structure must be allocated by the caller)
442 * \return true if the statistics are available, false otherwise
444 * \libvlc_return_bool
446 LIBVLC_API int libvlc_media_get_stats( libvlc_media_t *p_md,
447 libvlc_media_stats_t *p_stats );
449 /* The following method uses libvlc_media_list_t, however, media_list usage is optionnal
450 * and this is here for convenience */
451 #define VLC_FORWARD_DECLARE_OBJECT(a) struct a
454 * Get subitems of media descriptor object. This will increment
455 * the reference count of supplied media descriptor object. Use
456 * libvlc_media_list_release() to decrement the reference counting.
458 * \param p_md media descriptor object
459 * \return list of media descriptor subitems or NULL
461 LIBVLC_API VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t *)
462 libvlc_media_subitems( libvlc_media_t *p_md );
465 * Get event manager from media descriptor object.
466 * NOTE: this function doesn't increment reference counting.
468 * \param p_md a media descriptor object
469 * \return event manager object
471 LIBVLC_API libvlc_event_manager_t *
472 libvlc_media_event_manager( libvlc_media_t *p_md );
475 * Get duration (in ms) of media descriptor object item.
477 * \param p_md media descriptor object
478 * \return duration of media item or -1 on error
480 LIBVLC_API libvlc_time_t
481 libvlc_media_get_duration( libvlc_media_t *p_md );
486 * This fetches (local) meta data and tracks information.
487 * The method is synchronous.
489 * \see libvlc_media_parse_async
490 * \see libvlc_media_get_meta
491 * \see libvlc_media_get_tracks_info
493 * \param p_md media descriptor object
496 libvlc_media_parse( libvlc_media_t *p_md );
501 * This fetches (local) meta data and tracks information.
502 * The method is the asynchronous of libvlc_media_parse().
504 * To track when this is over you can listen to libvlc_MediaParsedChanged
505 * event. However if the media was already parsed you will not receive this
508 * \see libvlc_media_parse
509 * \see libvlc_MediaParsedChanged
510 * \see libvlc_media_get_meta
511 * \see libvlc_media_get_tracks_info
513 * \param p_md media descriptor object
516 libvlc_media_parse_async( libvlc_media_t *p_md );
519 * Get Parsed status for media descriptor object.
521 * \see libvlc_MediaParsedChanged
523 * \param p_md media descriptor object
524 * \return true if media object has been parsed otherwise it returns false
526 * \libvlc_return_bool
529 libvlc_media_is_parsed( libvlc_media_t *p_md );
532 * Sets media descriptor's user_data. user_data is specialized data
533 * accessed by the host application, VLC.framework uses it as a pointer to
534 * an native object that references a libvlc_media_t pointer
536 * \param p_md media descriptor object
537 * \param p_new_user_data pointer to user data
540 libvlc_media_set_user_data( libvlc_media_t *p_md, void *p_new_user_data );
543 * Get media descriptor's user_data. user_data is specialized data
544 * accessed by the host application, VLC.framework uses it as a pointer to
545 * an native object that references a libvlc_media_t pointer
547 * \param p_md media descriptor object
549 LIBVLC_API void *libvlc_media_get_user_data( libvlc_media_t *p_md );
552 * Get media descriptor's elementary streams description
554 * Note, you need to call libvlc_media_parse() or play the media at least once
555 * before calling this function.
556 * Not doing this will result in an empty array.
558 * \deprecated Use libvlc_media_tracks_get instead
560 * \param p_md media descriptor object
561 * \param tracks address to store an allocated array of Elementary Streams
562 * descriptions (must be freed by the caller) [OUT]
564 * \return the number of Elementary Streams
566 LIBVLC_DEPRECATED LIBVLC_API
567 int libvlc_media_get_tracks_info( libvlc_media_t *p_md,
568 libvlc_media_track_info_t **tracks );
571 * Get media descriptor's elementary streams description
573 * Note, you need to call libvlc_media_parse() or play the media at least once
574 * before calling this function.
575 * Not doing this will result in an empty array.
577 * \version LibVLC 2.1.0 and later.
579 * \param p_md media descriptor object
580 * \param tracks address to store an allocated array of Elementary Streams
581 * descriptions (must be freed with libvlc_media_tracks_release
584 * \return the number of Elementary Streams (zero on error)
587 unsigned libvlc_media_tracks_get( libvlc_media_t *p_md,
588 libvlc_media_track_t ***tracks );
592 * Release media descriptor's elementary streams description array
594 * \version LibVLC 2.1.0 and later.
596 * \param p_tracks tracks info array to release
597 * \param i_count number of elements in the array
600 void libvlc_media_tracks_release( libvlc_media_track_t **p_tracks,
609 #endif /* VLC_LIBVLC_MEDIA_H */