]> git.sesse.net Git - vlc/blob - include/vlc/libvlc_media.h
7fc718aa9980e831b3e124950e7f8efe10b1cabb
[vlc] / include / vlc / libvlc_media.h
1 /*****************************************************************************
2  * libvlc_media.h:  libvlc external API
3  *****************************************************************************
4  * Copyright (C) 1998-2009 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Jean-Paul Saman <jpsaman@videolan.org>
9  *          Pierre d'Herbemont <pdherbemont@videolan.org>
10  *
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.
15  *
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.
20  *
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  *****************************************************************************/
25
26 /**
27  * \file
28  * This file defines libvlc_media external API
29  */
30
31 #ifndef VLC_LIBVLC_MEDIA_H
32 #define VLC_LIBVLC_MEDIA_H 1
33
34 # ifdef __cplusplus
35 extern "C" {
36 # endif
37
38 /** \defgroup libvlc_media LibVLC media
39  * \ingroup libvlc
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.
42  * @{
43  */
44
45 typedef struct libvlc_media_t libvlc_media_t;
46
47 /** defgroup libvlc_meta LibVLC meta data
48  * \ingroup libvlc_media
49  * @{
50  */
51
52 /** Meta data types */
53 typedef enum libvlc_meta_t {
54     libvlc_meta_Title,
55     libvlc_meta_Artist,
56     libvlc_meta_Genre,
57     libvlc_meta_Copyright,
58     libvlc_meta_Album,
59     libvlc_meta_TrackNumber,
60     libvlc_meta_Description,
61     libvlc_meta_Rating,
62     libvlc_meta_Date,
63     libvlc_meta_Setting,
64     libvlc_meta_URL,
65     libvlc_meta_Language,
66     libvlc_meta_NowPlaying,
67     libvlc_meta_Publisher,
68     libvlc_meta_EncodedBy,
69     libvlc_meta_ArtworkURL,
70     libvlc_meta_TrackID,
71     libvlc_meta_TrackTotal,
72     libvlc_meta_Director,
73     libvlc_meta_Season,
74     libvlc_meta_Episode,
75     libvlc_meta_ShowName,
76     libvlc_meta_Actors,
77     libvlc_meta_AlbumArtist,
78     libvlc_meta_DiscNumber
79     /* Add new meta types HERE */
80 } libvlc_meta_t;
81
82 /** @}*/
83
84 /**
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).
88  *
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
92  */
93 typedef enum libvlc_state_t
94 {
95     libvlc_NothingSpecial=0,
96     libvlc_Opening,
97     libvlc_Buffering,
98     libvlc_Playing,
99     libvlc_Paused,
100     libvlc_Stopped,
101     libvlc_Ended,
102     libvlc_Error
103 } libvlc_state_t;
104
105 enum
106 {
107     libvlc_media_option_trusted = 0x2,
108     libvlc_media_option_unique = 0x100
109 };
110
111 typedef enum libvlc_track_type_t
112 {
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;
118
119 /** defgroup libvlc_media_stats_t LibVLC media statistics
120  * \ingroup libvlc_media
121  * @{
122  */
123 typedef struct libvlc_media_stats_t
124 {
125     /* Input */
126     int         i_read_bytes;
127     float       f_input_bitrate;
128
129     /* Demux */
130     int         i_demux_read_bytes;
131     float       f_demux_bitrate;
132     int         i_demux_corrupted;
133     int         i_demux_discontinuity;
134
135     /* Decoders */
136     int         i_decoded_video;
137     int         i_decoded_audio;
138
139     /* Video Output */
140     int         i_displayed_pictures;
141     int         i_lost_pictures;
142
143     /* Audio output */
144     int         i_played_abuffers;
145     int         i_lost_abuffers;
146
147     /* Stream output */
148     int         i_sent_packets;
149     int         i_sent_bytes;
150     float       f_send_bitrate;
151 } libvlc_media_stats_t;
152 /** @}*/
153
154 typedef struct libvlc_media_track_info_t
155 {
156     /* Codec fourcc */
157     uint32_t    i_codec;
158     int         i_id;
159     libvlc_track_type_t i_type;
160
161     /* Codec specific */
162     int         i_profile;
163     int         i_level;
164
165     union {
166         struct {
167             /* Audio specific */
168             unsigned    i_channels;
169             unsigned    i_rate;
170         } audio;
171         struct {
172             /* Video specific */
173             unsigned    i_height;
174             unsigned    i_width;
175         } video;
176     } u;
177
178 } libvlc_media_track_info_t;
179
180
181 typedef struct libvlc_audio_track_t
182 {
183     unsigned    i_channels;
184     unsigned    i_rate;
185 } libvlc_audio_track_t;
186
187 typedef struct libvlc_video_track_t
188 {
189     unsigned    i_height;
190     unsigned    i_width;
191     unsigned    i_sar_num;
192     unsigned    i_sar_den;
193     unsigned    i_frame_rate_num;
194     unsigned    i_frame_rate_den;
195 } libvlc_video_track_t;
196
197 typedef struct libvlc_subtitle_track_t
198 {
199     char *psz_encoding;
200 } libvlc_subtitle_track_t;
201
202 typedef struct libvlc_media_track_t
203 {
204     /* Codec fourcc */
205     uint32_t    i_codec;
206     uint32_t    i_original_fourcc;
207     int         i_id;
208     libvlc_track_type_t i_type;
209
210     /* Codec specific */
211     int         i_profile;
212     int         i_level;
213
214     union {
215         libvlc_audio_track_t *audio;
216         libvlc_video_track_t *video;
217         libvlc_subtitle_track_t *subtitle;
218     };
219
220     unsigned int i_bitrate;
221     char *psz_language;
222     char *psz_description;
223
224 } libvlc_media_track_t;
225
226 /**
227  * Parse flags used by libvlc_media_parse_with_options()
228  *
229  * \see libvlc_media_parse_with_options
230  */
231 typedef enum libvlc_media_parse_flag_t
232 {
233     /**
234      * Parse media if it's a local file
235      */
236     libvlc_media_parse_local    = 0x00,
237     /**
238      * Parse media even if it's a network file
239      */
240     libvlc_media_parse_network  = 0x01,
241     /**
242      * Fetch meta and covert art using local resources
243      */
244     libvlc_media_fetch_local    = 0x02,
245     /**
246      * Fetch meta and covert art using network resources
247      */
248     libvlc_media_fetch_network  = 0x04,
249 } libvlc_media_parse_flag_t;
250
251 /**
252  * Create a media with a certain given media resource location,
253  * for instance a valid URL.
254  *
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
258  * local files.
259  *
260  * \see libvlc_media_release
261  *
262  * \param p_instance the instance
263  * \param psz_mrl the media location
264  * \return the newly created media or NULL on error
265  */
266 LIBVLC_API libvlc_media_t *libvlc_media_new_location(
267                                    libvlc_instance_t *p_instance,
268                                    const char * psz_mrl );
269
270 /**
271  * Create a media for a certain file path.
272  *
273  * \see libvlc_media_release
274  *
275  * \param p_instance the instance
276  * \param path local filesystem path
277  * \return the newly created media or NULL on error
278  */
279 LIBVLC_API libvlc_media_t *libvlc_media_new_path(
280                                    libvlc_instance_t *p_instance,
281                                    const char *path );
282
283 /**
284  * Create a media for an already open file descriptor.
285  * The file descriptor shall be open for reading (or reading and writing).
286  *
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.
293  *
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().
298  *
299  * \see libvlc_media_release
300  *
301  * \version LibVLC 1.1.5 and later.
302  *
303  * \param p_instance the instance
304  * \param fd open file descriptor
305  * \return the newly created media or NULL on error
306  */
307 LIBVLC_API libvlc_media_t *libvlc_media_new_fd(
308                                    libvlc_instance_t *p_instance,
309                                    int fd );
310
311
312 /**
313  * Create a media as an empty node with a given name.
314  *
315  * \see libvlc_media_release
316  *
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
320  */
321 LIBVLC_API libvlc_media_t *libvlc_media_new_as_node(
322                                    libvlc_instance_t *p_instance,
323                                    const char * psz_name );
324
325 /**
326  * Add an option to the media.
327  *
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.
331  *
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.
339  *
340  * \param p_md the media descriptor
341  * \param psz_options the options (as a string)
342  */
343 LIBVLC_API void libvlc_media_add_option(
344                                    libvlc_media_t *p_md,
345                                    const char * psz_options );
346
347 /**
348  * Add an option to the media with configurable flags.
349  *
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.
353  *
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.
359  *
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
363  */
364 LIBVLC_API void libvlc_media_add_option_flag(
365                                    libvlc_media_t *p_md,
366                                    const char * psz_options,
367                                    unsigned i_flags );
368
369
370 /**
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.
374  *
375  * \param p_md the media descriptor
376  */
377 LIBVLC_API void libvlc_media_retain( libvlc_media_t *p_md );
378
379 /**
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.
385  *
386  * \param p_md the media descriptor
387  */
388 LIBVLC_API void libvlc_media_release( libvlc_media_t *p_md );
389
390
391 /**
392  * Get the media resource locator (mrl) from a media descriptor object
393  *
394  * \param p_md a media descriptor object
395  * \return string with mrl of media descriptor object
396  */
397 LIBVLC_API char *libvlc_media_get_mrl( libvlc_media_t *p_md );
398
399 /**
400  * Duplicate a media descriptor object.
401  *
402  * \param p_md a media descriptor object.
403  */
404 LIBVLC_API libvlc_media_t *libvlc_media_duplicate( libvlc_media_t *p_md );
405
406 /**
407  * Read the meta of the media.
408  *
409  * If the media has not yet been parsed this will return NULL.
410  *
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().
414  *
415  * \see libvlc_media_parse
416  * \see libvlc_media_parse_async
417  * \see libvlc_MediaMetaChanged
418  *
419  * \param p_md the media descriptor
420  * \param e_meta the meta to read
421  * \return the media's meta
422  */
423 LIBVLC_API char *libvlc_media_get_meta( libvlc_media_t *p_md,
424                                              libvlc_meta_t e_meta );
425
426 /**
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)
429  *
430  * \param p_md the media descriptor
431  * \param e_meta the meta to write
432  * \param psz_value the media's meta
433  */
434 LIBVLC_API void libvlc_media_set_meta( libvlc_media_t *p_md,
435                                            libvlc_meta_t e_meta,
436                                            const char *psz_value );
437
438
439 /**
440  * Save the meta previously set
441  *
442  * \param p_md the media desriptor
443  * \return true if the write operation was successful
444  */
445 LIBVLC_API int libvlc_media_save_meta( libvlc_media_t *p_md );
446
447
448 /**
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,
453  * libvlc_Error).
454  *
455  * \see libvlc_state_t
456  * \param p_md a media descriptor object
457  * \return state of media descriptor object
458  */
459 LIBVLC_API libvlc_state_t libvlc_media_get_state(
460                                    libvlc_media_t *p_md );
461
462
463 /**
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
469  *
470  * \libvlc_return_bool
471  */
472 LIBVLC_API int libvlc_media_get_stats( libvlc_media_t *p_md,
473                                            libvlc_media_stats_t *p_stats );
474
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
478
479 /**
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.
483  *
484  * \param p_md media descriptor object
485  * \return list of media descriptor subitems or NULL
486  */
487 LIBVLC_API VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t *)
488 libvlc_media_subitems( libvlc_media_t *p_md );
489
490 /**
491  * Get event manager from media descriptor object.
492  * NOTE: this function doesn't increment reference counting.
493  *
494  * \param p_md a media descriptor object
495  * \return event manager object
496  */
497 LIBVLC_API libvlc_event_manager_t *
498     libvlc_media_event_manager( libvlc_media_t *p_md );
499
500 /**
501  * Get duration (in ms) of media descriptor object item.
502  *
503  * \param p_md media descriptor object
504  * \return duration of media item or -1 on error
505  */
506 LIBVLC_API libvlc_time_t
507    libvlc_media_get_duration( libvlc_media_t *p_md );
508
509 /**
510  * Parse a media.
511  *
512  * This fetches (local) art, meta data and tracks information.
513  * The method is synchronous.
514  *
515  * \see libvlc_media_parse_async
516  * \see libvlc_media_get_meta
517  * \see libvlc_media_get_tracks_info
518  *
519  * \param p_md media descriptor object
520  */
521 LIBVLC_API void
522 libvlc_media_parse( libvlc_media_t *p_md );
523
524 /**
525  * Parse a media.
526  *
527  * This fetches (local) art, meta data and tracks information.
528  * The method is the asynchronous of libvlc_media_parse().
529  *
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
532  * event.
533  *
534  * \see libvlc_media_parse
535  * \see libvlc_MediaParsedChanged
536  * \see libvlc_media_get_meta
537  * \see libvlc_media_get_tracks_info
538  *
539  * \param p_md media descriptor object
540  */
541 LIBVLC_API void
542 libvlc_media_parse_async( libvlc_media_t *p_md );
543
544 /**
545  * Parse the media asynchronously with options.
546  *
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().
549  *
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
552  * event.
553  *
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
556  * file.
557  *
558  * \see libvlc_MediaParsedChanged
559  * \see libvlc_media_get_meta
560  * \see libvlc_media_tracks_get
561  * \see libvlc_media_parse_flag_t
562  *
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
567  */
568 LIBVLC_API int
569 libvlc_media_parse_with_options( libvlc_media_t *p_md,
570                                  libvlc_media_parse_flag_t parse_flag );
571
572 /**
573  * Get Parsed status for media descriptor object.
574  *
575  * \see libvlc_MediaParsedChanged
576  *
577  * \param p_md media descriptor object
578  * \return true if media object has been parsed otherwise it returns false
579  *
580  * \libvlc_return_bool
581  */
582 LIBVLC_API int
583    libvlc_media_is_parsed( libvlc_media_t *p_md );
584
585 /**
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
589  *
590  * \param p_md media descriptor object
591  * \param p_new_user_data pointer to user data
592  */
593 LIBVLC_API void
594     libvlc_media_set_user_data( libvlc_media_t *p_md, void *p_new_user_data );
595
596 /**
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
600  *
601  * \param p_md media descriptor object
602  */
603 LIBVLC_API void *libvlc_media_get_user_data( libvlc_media_t *p_md );
604
605 /**
606  * Get media descriptor's elementary streams description
607  *
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.
611  *
612  * \deprecated Use libvlc_media_tracks_get instead
613  *
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]
617  *
618  * \return the number of Elementary Streams
619  */
620 LIBVLC_DEPRECATED LIBVLC_API
621 int libvlc_media_get_tracks_info( libvlc_media_t *p_md,
622                                   libvlc_media_track_info_t **tracks );
623
624 /**
625  * Get media descriptor's elementary streams description
626  *
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.
630  *
631  * \version LibVLC 2.1.0 and later.
632  *
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
636           by the caller) [OUT]
637  *
638  * \return the number of Elementary Streams (zero on error)
639  */
640 LIBVLC_API
641 unsigned libvlc_media_tracks_get( libvlc_media_t *p_md,
642                                   libvlc_media_track_t ***tracks );
643
644 /**
645  * Get codec description from media elementary stream
646  *
647  * \version LibVLC 3.0.0 and later.
648  *
649  * \see libvlc_media_track_t
650  *
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
653  *
654  * \return codec description
655  */
656 LIBVLC_API
657 const char *libvlc_media_get_codec_description( libvlc_track_type_t i_type,
658                                                 uint32_t i_codec );
659
660 /**
661  * Release media descriptor's elementary streams description array
662  *
663  * \version LibVLC 2.1.0 and later.
664  *
665  * \param p_tracks tracks info array to release
666  * \param i_count number of elements in the array
667  */
668 LIBVLC_API
669 void libvlc_media_tracks_release( libvlc_media_track_t **p_tracks,
670                                   unsigned i_count );
671
672 /** @}*/
673
674 # ifdef __cplusplus
675 }
676 # endif
677
678 #endif /* VLC_LIBVLC_MEDIA_H */