]> git.sesse.net Git - vlc/blob - include/vlc/libvlc_media.h
lib: expose new meta data attributes
[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     /* Add new meta types HERE */
78 } libvlc_meta_t;
79
80 /** @}*/
81
82 /**
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).
86  *
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
90  */
91 typedef enum libvlc_state_t
92 {
93     libvlc_NothingSpecial=0,
94     libvlc_Opening,
95     libvlc_Buffering,
96     libvlc_Playing,
97     libvlc_Paused,
98     libvlc_Stopped,
99     libvlc_Ended,
100     libvlc_Error
101 } libvlc_state_t;
102
103 enum
104 {
105     libvlc_media_option_trusted = 0x2,
106     libvlc_media_option_unique = 0x100
107 };
108
109 typedef enum libvlc_track_type_t
110 {
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;
116
117 /** defgroup libvlc_media_stats_t LibVLC media statistics
118  * \ingroup libvlc_media
119  * @{
120  */
121 typedef struct libvlc_media_stats_t
122 {
123     /* Input */
124     int         i_read_bytes;
125     float       f_input_bitrate;
126
127     /* Demux */
128     int         i_demux_read_bytes;
129     float       f_demux_bitrate;
130     int         i_demux_corrupted;
131     int         i_demux_discontinuity;
132
133     /* Decoders */
134     int         i_decoded_video;
135     int         i_decoded_audio;
136
137     /* Video Output */
138     int         i_displayed_pictures;
139     int         i_lost_pictures;
140
141     /* Audio output */
142     int         i_played_abuffers;
143     int         i_lost_abuffers;
144
145     /* Stream output */
146     int         i_sent_packets;
147     int         i_sent_bytes;
148     float       f_send_bitrate;
149 } libvlc_media_stats_t;
150 /** @}*/
151
152 typedef struct libvlc_media_track_info_t
153 {
154     /* Codec fourcc */
155     uint32_t    i_codec;
156     int         i_id;
157     libvlc_track_type_t i_type;
158
159     /* Codec specific */
160     int         i_profile;
161     int         i_level;
162
163     union {
164         struct {
165             /* Audio specific */
166             unsigned    i_channels;
167             unsigned    i_rate;
168         } audio;
169         struct {
170             /* Video specific */
171             unsigned    i_height;
172             unsigned    i_width;
173         } video;
174     } u;
175
176 } libvlc_media_track_info_t;
177
178
179 typedef struct libvlc_audio_track_t
180 {
181     unsigned    i_channels;
182     unsigned    i_rate;
183 } libvlc_audio_track_t;
184
185 typedef struct libvlc_video_track_t
186 {
187     unsigned    i_height;
188     unsigned    i_width;
189     unsigned    i_sar_num;
190     unsigned    i_sar_den;
191     unsigned    i_frame_rate_num;
192     unsigned    i_frame_rate_den;
193 } libvlc_video_track_t;
194
195 typedef struct libvlc_subtitle_track_t
196 {
197     char *psz_encoding;
198 } libvlc_subtitle_track_t;
199
200 typedef struct libvlc_media_track_t
201 {
202     /* Codec fourcc */
203     uint32_t    i_codec;
204     uint32_t    i_original_fourcc;
205     int         i_id;
206     libvlc_track_type_t i_type;
207
208     /* Codec specific */
209     int         i_profile;
210     int         i_level;
211
212     union {
213         libvlc_audio_track_t *audio;
214         libvlc_video_track_t *video;
215         libvlc_subtitle_track_t *subtitle;
216     };
217
218     unsigned int i_bitrate;
219     char *psz_language;
220     char *psz_description;
221
222 } libvlc_media_track_t;
223
224
225 /**
226  * Create a media with a certain given media resource location,
227  * for instance a valid URL.
228  *
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
232  * local files.
233  *
234  * \see libvlc_media_release
235  *
236  * \param p_instance the instance
237  * \param psz_mrl the media location
238  * \return the newly created media or NULL on error
239  */
240 LIBVLC_API libvlc_media_t *libvlc_media_new_location(
241                                    libvlc_instance_t *p_instance,
242                                    const char * psz_mrl );
243
244 /**
245  * Create a media for a certain file path.
246  *
247  * \see libvlc_media_release
248  *
249  * \param p_instance the instance
250  * \param path local filesystem path
251  * \return the newly created media or NULL on error
252  */
253 LIBVLC_API libvlc_media_t *libvlc_media_new_path(
254                                    libvlc_instance_t *p_instance,
255                                    const char *path );
256
257 /**
258  * Create a media for an already open file descriptor.
259  * The file descriptor shall be open for reading (or reading and writing).
260  *
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.
267  *
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().
272  *
273  * \see libvlc_media_release
274  *
275  * \version LibVLC 1.1.5 and later.
276  *
277  * \param p_instance the instance
278  * \param fd open file descriptor
279  * \return the newly created media or NULL on error
280  */
281 LIBVLC_API libvlc_media_t *libvlc_media_new_fd(
282                                    libvlc_instance_t *p_instance,
283                                    int fd );
284
285
286 /**
287  * Create a media as an empty node with a given name.
288  *
289  * \see libvlc_media_release
290  *
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
294  */
295 LIBVLC_API libvlc_media_t *libvlc_media_new_as_node(
296                                    libvlc_instance_t *p_instance,
297                                    const char * psz_name );
298
299 /**
300  * Add an option to the media.
301  *
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.
305  *
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.
313  *
314  * \param p_md the media descriptor
315  * \param psz_options the options (as a string)
316  */
317 LIBVLC_API void libvlc_media_add_option(
318                                    libvlc_media_t *p_md,
319                                    const char * psz_options );
320
321 /**
322  * Add an option to the media with configurable flags.
323  *
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.
327  *
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.
333  *
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
337  */
338 LIBVLC_API void libvlc_media_add_option_flag(
339                                    libvlc_media_t *p_md,
340                                    const char * psz_options,
341                                    unsigned i_flags );
342
343
344 /**
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.
348  *
349  * \param p_md the media descriptor
350  */
351 LIBVLC_API void libvlc_media_retain( libvlc_media_t *p_md );
352
353 /**
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.
359  *
360  * \param p_md the media descriptor
361  */
362 LIBVLC_API void libvlc_media_release( libvlc_media_t *p_md );
363
364
365 /**
366  * Get the media resource locator (mrl) from a media descriptor object
367  *
368  * \param p_md a media descriptor object
369  * \return string with mrl of media descriptor object
370  */
371 LIBVLC_API char *libvlc_media_get_mrl( libvlc_media_t *p_md );
372
373 /**
374  * Duplicate a media descriptor object.
375  *
376  * \param p_md a media descriptor object.
377  */
378 LIBVLC_API libvlc_media_t *libvlc_media_duplicate( libvlc_media_t *p_md );
379
380 /**
381  * Read the meta of the media.
382  *
383  * If the media has not yet been parsed this will return NULL.
384  *
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().
388  *
389  * \see libvlc_media_parse
390  * \see libvlc_media_parse_async
391  * \see libvlc_MediaMetaChanged
392  *
393  * \param p_md the media descriptor
394  * \param e_meta the meta to read
395  * \return the media's meta
396  */
397 LIBVLC_API char *libvlc_media_get_meta( libvlc_media_t *p_md,
398                                              libvlc_meta_t e_meta );
399
400 /**
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)
403  *
404  * \param p_md the media descriptor
405  * \param e_meta the meta to write
406  * \param psz_value the media's meta
407  */
408 LIBVLC_API void libvlc_media_set_meta( libvlc_media_t *p_md,
409                                            libvlc_meta_t e_meta,
410                                            const char *psz_value );
411
412
413 /**
414  * Save the meta previously set
415  *
416  * \param p_md the media desriptor
417  * \return true if the write operation was successful
418  */
419 LIBVLC_API int libvlc_media_save_meta( libvlc_media_t *p_md );
420
421
422 /**
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,
427  * libvlc_Error).
428  *
429  * \see libvlc_state_t
430  * \param p_md a media descriptor object
431  * \return state of media descriptor object
432  */
433 LIBVLC_API libvlc_state_t libvlc_media_get_state(
434                                    libvlc_media_t *p_md );
435
436
437 /**
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
443  *
444  * \libvlc_return_bool
445  */
446 LIBVLC_API int libvlc_media_get_stats( libvlc_media_t *p_md,
447                                            libvlc_media_stats_t *p_stats );
448
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
452
453 /**
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.
457  *
458  * \param p_md media descriptor object
459  * \return list of media descriptor subitems or NULL
460  */
461 LIBVLC_API VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t *)
462 libvlc_media_subitems( libvlc_media_t *p_md );
463
464 /**
465  * Get event manager from media descriptor object.
466  * NOTE: this function doesn't increment reference counting.
467  *
468  * \param p_md a media descriptor object
469  * \return event manager object
470  */
471 LIBVLC_API libvlc_event_manager_t *
472     libvlc_media_event_manager( libvlc_media_t *p_md );
473
474 /**
475  * Get duration (in ms) of media descriptor object item.
476  *
477  * \param p_md media descriptor object
478  * \return duration of media item or -1 on error
479  */
480 LIBVLC_API libvlc_time_t
481    libvlc_media_get_duration( libvlc_media_t *p_md );
482
483 /**
484  * Parse a media.
485  *
486  * This fetches (local) meta data and tracks information.
487  * The method is synchronous.
488  *
489  * \see libvlc_media_parse_async
490  * \see libvlc_media_get_meta
491  * \see libvlc_media_get_tracks_info
492  *
493  * \param p_md media descriptor object
494  */
495 LIBVLC_API void
496 libvlc_media_parse( libvlc_media_t *p_md );
497
498 /**
499  * Parse a media.
500  *
501  * This fetches (local) meta data and tracks information.
502  * The method is the asynchronous of libvlc_media_parse().
503  *
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
506  * event.
507  *
508  * \see libvlc_media_parse
509  * \see libvlc_MediaParsedChanged
510  * \see libvlc_media_get_meta
511  * \see libvlc_media_get_tracks_info
512  *
513  * \param p_md media descriptor object
514  */
515 LIBVLC_API void
516 libvlc_media_parse_async( libvlc_media_t *p_md );
517
518 /**
519  * Get Parsed status for media descriptor object.
520  *
521  * \see libvlc_MediaParsedChanged
522  *
523  * \param p_md media descriptor object
524  * \return true if media object has been parsed otherwise it returns false
525  *
526  * \libvlc_return_bool
527  */
528 LIBVLC_API int
529    libvlc_media_is_parsed( libvlc_media_t *p_md );
530
531 /**
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
535  *
536  * \param p_md media descriptor object
537  * \param p_new_user_data pointer to user data
538  */
539 LIBVLC_API void
540     libvlc_media_set_user_data( libvlc_media_t *p_md, void *p_new_user_data );
541
542 /**
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
546  *
547  * \param p_md media descriptor object
548  */
549 LIBVLC_API void *libvlc_media_get_user_data( libvlc_media_t *p_md );
550
551 /**
552  * Get media descriptor's elementary streams description
553  *
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.
557  *
558  * \deprecated Use libvlc_media_tracks_get instead
559  *
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]
563  *
564  * \return the number of Elementary Streams
565  */
566 LIBVLC_DEPRECATED LIBVLC_API
567 int libvlc_media_get_tracks_info( libvlc_media_t *p_md,
568                                   libvlc_media_track_info_t **tracks );
569
570 /**
571  * Get media descriptor's elementary streams description
572  *
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.
576  *
577  * \version LibVLC 2.1.0 and later.
578  *
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
582           by the caller) [OUT]
583  *
584  * \return the number of Elementary Streams (zero on error)
585  */
586 LIBVLC_API
587 unsigned libvlc_media_tracks_get( libvlc_media_t *p_md,
588                                   libvlc_media_track_t ***tracks );
589
590
591 /**
592  * Release media descriptor's elementary streams description array
593  *
594  * \version LibVLC 2.1.0 and later.
595  *
596  * \param p_tracks tracks info array to release
597  * \param i_count number of elements in the array
598  */
599 LIBVLC_API
600 void libvlc_media_tracks_release( libvlc_media_track_t **p_tracks,
601                                   unsigned i_count );
602
603 /** @}*/
604
605 # ifdef __cplusplus
606 }
607 # endif
608
609 #endif /* VLC_LIBVLC_MEDIA_H */