]> git.sesse.net Git - vlc/blob - include/vlc/libvlc_media.h
libvlc: add libvlc_media_get_type
[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 /** defgroup libvlc_media_type LibVLC media type
227  * \ingroup libvlc_media
228  * @{
229  */
230
231 /**
232  * Media type
233  *
234  * \see libvlc_media_get_type
235  */
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;
244
245 /** @}*/
246
247 /**
248  * Parse flags used by libvlc_media_parse_with_options()
249  *
250  * \see libvlc_media_parse_with_options
251  */
252 typedef enum libvlc_media_parse_flag_t
253 {
254     /**
255      * Parse media if it's a local file
256      */
257     libvlc_media_parse_local    = 0x00,
258     /**
259      * Parse media even if it's a network file
260      */
261     libvlc_media_parse_network  = 0x01,
262     /**
263      * Fetch meta and covert art using local resources
264      */
265     libvlc_media_fetch_local    = 0x02,
266     /**
267      * Fetch meta and covert art using network resources
268      */
269     libvlc_media_fetch_network  = 0x04,
270 } libvlc_media_parse_flag_t;
271
272 /**
273  * Create a media with a certain given media resource location,
274  * for instance a valid URL.
275  *
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
279  * local files.
280  *
281  * \see libvlc_media_release
282  *
283  * \param p_instance the instance
284  * \param psz_mrl the media location
285  * \return the newly created media or NULL on error
286  */
287 LIBVLC_API libvlc_media_t *libvlc_media_new_location(
288                                    libvlc_instance_t *p_instance,
289                                    const char * psz_mrl );
290
291 /**
292  * Create a media for a certain file path.
293  *
294  * \see libvlc_media_release
295  *
296  * \param p_instance the instance
297  * \param path local filesystem path
298  * \return the newly created media or NULL on error
299  */
300 LIBVLC_API libvlc_media_t *libvlc_media_new_path(
301                                    libvlc_instance_t *p_instance,
302                                    const char *path );
303
304 /**
305  * Create a media for an already open file descriptor.
306  * The file descriptor shall be open for reading (or reading and writing).
307  *
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.
314  *
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().
319  *
320  * \see libvlc_media_release
321  *
322  * \version LibVLC 1.1.5 and later.
323  *
324  * \param p_instance the instance
325  * \param fd open file descriptor
326  * \return the newly created media or NULL on error
327  */
328 LIBVLC_API libvlc_media_t *libvlc_media_new_fd(
329                                    libvlc_instance_t *p_instance,
330                                    int fd );
331
332
333 /**
334  * Create a media as an empty node with a given name.
335  *
336  * \see libvlc_media_release
337  *
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
341  */
342 LIBVLC_API libvlc_media_t *libvlc_media_new_as_node(
343                                    libvlc_instance_t *p_instance,
344                                    const char * psz_name );
345
346 /**
347  * Add an option to the media.
348  *
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.
352  *
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.
360  *
361  * \param p_md the media descriptor
362  * \param psz_options the options (as a string)
363  */
364 LIBVLC_API void libvlc_media_add_option(
365                                    libvlc_media_t *p_md,
366                                    const char * psz_options );
367
368 /**
369  * Add an option to the media with configurable flags.
370  *
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.
374  *
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.
380  *
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
384  */
385 LIBVLC_API void libvlc_media_add_option_flag(
386                                    libvlc_media_t *p_md,
387                                    const char * psz_options,
388                                    unsigned i_flags );
389
390
391 /**
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.
395  *
396  * \param p_md the media descriptor
397  */
398 LIBVLC_API void libvlc_media_retain( libvlc_media_t *p_md );
399
400 /**
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.
406  *
407  * \param p_md the media descriptor
408  */
409 LIBVLC_API void libvlc_media_release( libvlc_media_t *p_md );
410
411
412 /**
413  * Get the media resource locator (mrl) from a media descriptor object
414  *
415  * \param p_md a media descriptor object
416  * \return string with mrl of media descriptor object
417  */
418 LIBVLC_API char *libvlc_media_get_mrl( libvlc_media_t *p_md );
419
420 /**
421  * Duplicate a media descriptor object.
422  *
423  * \param p_md a media descriptor object.
424  */
425 LIBVLC_API libvlc_media_t *libvlc_media_duplicate( libvlc_media_t *p_md );
426
427 /**
428  * Read the meta of the media.
429  *
430  * If the media has not yet been parsed this will return NULL.
431  *
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().
435  *
436  * \see libvlc_media_parse
437  * \see libvlc_media_parse_async
438  * \see libvlc_MediaMetaChanged
439  *
440  * \param p_md the media descriptor
441  * \param e_meta the meta to read
442  * \return the media's meta
443  */
444 LIBVLC_API char *libvlc_media_get_meta( libvlc_media_t *p_md,
445                                              libvlc_meta_t e_meta );
446
447 /**
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)
450  *
451  * \param p_md the media descriptor
452  * \param e_meta the meta to write
453  * \param psz_value the media's meta
454  */
455 LIBVLC_API void libvlc_media_set_meta( libvlc_media_t *p_md,
456                                            libvlc_meta_t e_meta,
457                                            const char *psz_value );
458
459
460 /**
461  * Save the meta previously set
462  *
463  * \param p_md the media desriptor
464  * \return true if the write operation was successful
465  */
466 LIBVLC_API int libvlc_media_save_meta( libvlc_media_t *p_md );
467
468
469 /**
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,
474  * libvlc_Error).
475  *
476  * \see libvlc_state_t
477  * \param p_md a media descriptor object
478  * \return state of media descriptor object
479  */
480 LIBVLC_API libvlc_state_t libvlc_media_get_state(
481                                    libvlc_media_t *p_md );
482
483
484 /**
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
490  *
491  * \libvlc_return_bool
492  */
493 LIBVLC_API int libvlc_media_get_stats( libvlc_media_t *p_md,
494                                            libvlc_media_stats_t *p_stats );
495
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
499
500 /**
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.
504  *
505  * \param p_md media descriptor object
506  * \return list of media descriptor subitems or NULL
507  */
508 LIBVLC_API VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t *)
509 libvlc_media_subitems( libvlc_media_t *p_md );
510
511 /**
512  * Get event manager from media descriptor object.
513  * NOTE: this function doesn't increment reference counting.
514  *
515  * \param p_md a media descriptor object
516  * \return event manager object
517  */
518 LIBVLC_API libvlc_event_manager_t *
519     libvlc_media_event_manager( libvlc_media_t *p_md );
520
521 /**
522  * Get duration (in ms) of media descriptor object item.
523  *
524  * \param p_md media descriptor object
525  * \return duration of media item or -1 on error
526  */
527 LIBVLC_API libvlc_time_t
528    libvlc_media_get_duration( libvlc_media_t *p_md );
529
530 /**
531  * Parse a media.
532  *
533  * This fetches (local) art, meta data and tracks information.
534  * The method is synchronous.
535  *
536  * \see libvlc_media_parse_async
537  * \see libvlc_media_get_meta
538  * \see libvlc_media_get_tracks_info
539  *
540  * \param p_md media descriptor object
541  */
542 LIBVLC_API void
543 libvlc_media_parse( libvlc_media_t *p_md );
544
545 /**
546  * Parse a media.
547  *
548  * This fetches (local) art, meta data and tracks information.
549  * The method is the asynchronous of libvlc_media_parse().
550  *
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
553  * event.
554  *
555  * \see libvlc_media_parse
556  * \see libvlc_MediaParsedChanged
557  * \see libvlc_media_get_meta
558  * \see libvlc_media_get_tracks_info
559  *
560  * \param p_md media descriptor object
561  */
562 LIBVLC_API void
563 libvlc_media_parse_async( libvlc_media_t *p_md );
564
565 /**
566  * Parse the media asynchronously with options.
567  *
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().
570  *
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
573  * event.
574  *
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
577  * file.
578  *
579  * \see libvlc_MediaParsedChanged
580  * \see libvlc_media_get_meta
581  * \see libvlc_media_tracks_get
582  * \see libvlc_media_parse_flag_t
583  *
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
588  */
589 LIBVLC_API int
590 libvlc_media_parse_with_options( libvlc_media_t *p_md,
591                                  libvlc_media_parse_flag_t parse_flag );
592
593 /**
594  * Get Parsed status for media descriptor object.
595  *
596  * \see libvlc_MediaParsedChanged
597  *
598  * \param p_md media descriptor object
599  * \return true if media object has been parsed otherwise it returns false
600  *
601  * \libvlc_return_bool
602  */
603 LIBVLC_API int
604    libvlc_media_is_parsed( libvlc_media_t *p_md );
605
606 /**
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
610  *
611  * \param p_md media descriptor object
612  * \param p_new_user_data pointer to user data
613  */
614 LIBVLC_API void
615     libvlc_media_set_user_data( libvlc_media_t *p_md, void *p_new_user_data );
616
617 /**
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
621  *
622  * \param p_md media descriptor object
623  */
624 LIBVLC_API void *libvlc_media_get_user_data( libvlc_media_t *p_md );
625
626 /**
627  * Get media descriptor's elementary streams description
628  *
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.
632  *
633  * \deprecated Use libvlc_media_tracks_get instead
634  *
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]
638  *
639  * \return the number of Elementary Streams
640  */
641 LIBVLC_DEPRECATED LIBVLC_API
642 int libvlc_media_get_tracks_info( libvlc_media_t *p_md,
643                                   libvlc_media_track_info_t **tracks );
644
645 /**
646  * Get media descriptor's elementary streams description
647  *
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.
651  *
652  * \version LibVLC 2.1.0 and later.
653  *
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
657           by the caller) [OUT]
658  *
659  * \return the number of Elementary Streams (zero on error)
660  */
661 LIBVLC_API
662 unsigned libvlc_media_tracks_get( libvlc_media_t *p_md,
663                                   libvlc_media_track_t ***tracks );
664
665 /**
666  * Get codec description from media elementary stream
667  *
668  * \version LibVLC 3.0.0 and later.
669  *
670  * \see libvlc_media_track_t
671  *
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
674  *
675  * \return codec description
676  */
677 LIBVLC_API
678 const char *libvlc_media_get_codec_description( libvlc_track_type_t i_type,
679                                                 uint32_t i_codec );
680
681 /**
682  * Release media descriptor's elementary streams description array
683  *
684  * \version LibVLC 2.1.0 and later.
685  *
686  * \param p_tracks tracks info array to release
687  * \param i_count number of elements in the array
688  */
689 LIBVLC_API
690 void libvlc_media_tracks_release( libvlc_media_track_t **p_tracks,
691                                   unsigned i_count );
692
693 /**
694  * Get the media type of the media descriptor object
695  *
696  * \version LibVLC 3.0.0 and later.
697  *
698  * \see libvlc_media_type_t
699  *
700  * \param p_md media descriptor object
701  *
702  * \return media type
703  */
704 LIBVLC_API
705 libvlc_media_type_t libvlc_media_get_type( libvlc_media_t *p_md );
706
707 /** @}*/
708
709 # ifdef __cplusplus
710 }
711 # endif
712
713 #endif /* VLC_LIBVLC_MEDIA_H */