]> git.sesse.net Git - vlc/blob - include/vlc/libvlc_media.h
9c2d38359fb35e366eb375e84a2b05c59a0095f3
[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     /* Add new meta types HERE */
79 } libvlc_meta_t;
80
81 /** @}*/
82
83 /**
84  * Note the order of libvlc_state_t enum must match exactly the order of
85  * \see mediacontrol_PlayerStatus, \see input_state_e enums,
86  * and VideoLAN.LibVLC.State (at bindings/cil/src/media.cs).
87  *
88  * Expected states by web plugins are:
89  * IDLE/CLOSE=0, OPENING=1, BUFFERING=2, PLAYING=3, PAUSED=4,
90  * STOPPING=5, ENDED=6, ERROR=7
91  */
92 typedef enum libvlc_state_t
93 {
94     libvlc_NothingSpecial=0,
95     libvlc_Opening,
96     libvlc_Buffering,
97     libvlc_Playing,
98     libvlc_Paused,
99     libvlc_Stopped,
100     libvlc_Ended,
101     libvlc_Error
102 } libvlc_state_t;
103
104 enum
105 {
106     libvlc_media_option_trusted = 0x2,
107     libvlc_media_option_unique = 0x100
108 };
109
110 typedef enum libvlc_track_type_t
111 {
112     libvlc_track_unknown   = -1,
113     libvlc_track_audio     = 0,
114     libvlc_track_video     = 1,
115     libvlc_track_text      = 2
116 } libvlc_track_type_t;
117
118 /** defgroup libvlc_media_stats_t LibVLC media statistics
119  * \ingroup libvlc_media
120  * @{
121  */
122 typedef struct libvlc_media_stats_t
123 {
124     /* Input */
125     int         i_read_bytes;
126     float       f_input_bitrate;
127
128     /* Demux */
129     int         i_demux_read_bytes;
130     float       f_demux_bitrate;
131     int         i_demux_corrupted;
132     int         i_demux_discontinuity;
133
134     /* Decoders */
135     int         i_decoded_video;
136     int         i_decoded_audio;
137
138     /* Video Output */
139     int         i_displayed_pictures;
140     int         i_lost_pictures;
141
142     /* Audio output */
143     int         i_played_abuffers;
144     int         i_lost_abuffers;
145
146     /* Stream output */
147     int         i_sent_packets;
148     int         i_sent_bytes;
149     float       f_send_bitrate;
150 } libvlc_media_stats_t;
151 /** @}*/
152
153 typedef struct libvlc_media_track_info_t
154 {
155     /* Codec fourcc */
156     uint32_t    i_codec;
157     int         i_id;
158     libvlc_track_type_t i_type;
159
160     /* Codec specific */
161     int         i_profile;
162     int         i_level;
163
164     union {
165         struct {
166             /* Audio specific */
167             unsigned    i_channels;
168             unsigned    i_rate;
169         } audio;
170         struct {
171             /* Video specific */
172             unsigned    i_height;
173             unsigned    i_width;
174         } video;
175     } u;
176
177 } libvlc_media_track_info_t;
178
179
180 typedef struct libvlc_audio_track_t
181 {
182     unsigned    i_channels;
183     unsigned    i_rate;
184 } libvlc_audio_track_t;
185
186 typedef struct libvlc_video_track_t
187 {
188     unsigned    i_height;
189     unsigned    i_width;
190     unsigned    i_sar_num;
191     unsigned    i_sar_den;
192     unsigned    i_frame_rate_num;
193     unsigned    i_frame_rate_den;
194 } libvlc_video_track_t;
195
196 typedef struct libvlc_subtitle_track_t
197 {
198     char *psz_encoding;
199 } libvlc_subtitle_track_t;
200
201 typedef struct libvlc_media_track_t
202 {
203     /* Codec fourcc */
204     uint32_t    i_codec;
205     uint32_t    i_original_fourcc;
206     int         i_id;
207     libvlc_track_type_t i_type;
208
209     /* Codec specific */
210     int         i_profile;
211     int         i_level;
212
213     union {
214         libvlc_audio_track_t *audio;
215         libvlc_video_track_t *video;
216         libvlc_subtitle_track_t *subtitle;
217     };
218
219     unsigned int i_bitrate;
220     char *psz_language;
221     char *psz_description;
222
223 } libvlc_media_track_t;
224
225
226 /**
227  * Create a media with a certain given media resource location,
228  * for instance a valid URL.
229  *
230  * \note To refer to a local file with this function,
231  * the file://... URI syntax <b>must</b> be used (see IETF RFC3986).
232  * We recommend using libvlc_media_new_path() instead when dealing with
233  * local files.
234  *
235  * \see libvlc_media_release
236  *
237  * \param p_instance the instance
238  * \param psz_mrl the media location
239  * \return the newly created media or NULL on error
240  */
241 LIBVLC_API libvlc_media_t *libvlc_media_new_location(
242                                    libvlc_instance_t *p_instance,
243                                    const char * psz_mrl );
244
245 /**
246  * Create a media for a certain file path.
247  *
248  * \see libvlc_media_release
249  *
250  * \param p_instance the instance
251  * \param path local filesystem path
252  * \return the newly created media or NULL on error
253  */
254 LIBVLC_API libvlc_media_t *libvlc_media_new_path(
255                                    libvlc_instance_t *p_instance,
256                                    const char *path );
257
258 /**
259  * Create a media for an already open file descriptor.
260  * The file descriptor shall be open for reading (or reading and writing).
261  *
262  * Regular file descriptors, pipe read descriptors and character device
263  * descriptors (including TTYs) are supported on all platforms.
264  * Block device descriptors are supported where available.
265  * Directory descriptors are supported on systems that provide fdopendir().
266  * Sockets are supported on all platforms where they are file descriptors,
267  * i.e. all except Windows.
268  *
269  * \note This library will <b>not</b> automatically close the file descriptor
270  * under any circumstance. Nevertheless, a file descriptor can usually only be
271  * rendered once in a media player. To render it a second time, the file
272  * descriptor should probably be rewound to the beginning with lseek().
273  *
274  * \see libvlc_media_release
275  *
276  * \version LibVLC 1.1.5 and later.
277  *
278  * \param p_instance the instance
279  * \param fd open file descriptor
280  * \return the newly created media or NULL on error
281  */
282 LIBVLC_API libvlc_media_t *libvlc_media_new_fd(
283                                    libvlc_instance_t *p_instance,
284                                    int fd );
285
286
287 /**
288  * Create a media as an empty node with a given name.
289  *
290  * \see libvlc_media_release
291  *
292  * \param p_instance the instance
293  * \param psz_name the name of the node
294  * \return the new empty media or NULL on error
295  */
296 LIBVLC_API libvlc_media_t *libvlc_media_new_as_node(
297                                    libvlc_instance_t *p_instance,
298                                    const char * psz_name );
299
300 /**
301  * Add an option to the media.
302  *
303  * This option will be used to determine how the media_player will
304  * read the media. This allows to use VLC's advanced
305  * reading/streaming options on a per-media basis.
306  *
307  * \note The options are listed in 'vlc --long-help' from the command line,
308  * e.g. "-sout-all". Keep in mind that available options and their semantics
309  * vary across LibVLC versions and builds.
310  * \warning Not all options affects libvlc_media_t objects:
311  * Specifically, due to architectural issues most audio and video options,
312  * such as text renderer options, have no effects on an individual media.
313  * These options must be set through libvlc_new() instead.
314  *
315  * \param p_md the media descriptor
316  * \param psz_options the options (as a string)
317  */
318 LIBVLC_API void libvlc_media_add_option(
319                                    libvlc_media_t *p_md,
320                                    const char * psz_options );
321
322 /**
323  * Add an option to the media with configurable flags.
324  *
325  * This option will be used to determine how the media_player will
326  * read the media. This allows to use VLC's advanced
327  * reading/streaming options on a per-media basis.
328  *
329  * The options are detailed in vlc --long-help, for instance
330  * "--sout-all". Note that all options are not usable on medias:
331  * specifically, due to architectural issues, video-related options
332  * such as text renderer options cannot be set on a single media. They
333  * must be set on the whole libvlc instance instead.
334  *
335  * \param p_md the media descriptor
336  * \param psz_options the options (as a string)
337  * \param i_flags the flags for this option
338  */
339 LIBVLC_API void libvlc_media_add_option_flag(
340                                    libvlc_media_t *p_md,
341                                    const char * psz_options,
342                                    unsigned i_flags );
343
344
345 /**
346  * Retain a reference to a media descriptor object (libvlc_media_t). Use
347  * libvlc_media_release() to decrement the reference count of a
348  * media descriptor object.
349  *
350  * \param p_md the media descriptor
351  */
352 LIBVLC_API void libvlc_media_retain( libvlc_media_t *p_md );
353
354 /**
355  * Decrement the reference count of a media descriptor object. If the
356  * reference count is 0, then libvlc_media_release() will release the
357  * media descriptor object. It will send out an libvlc_MediaFreed event
358  * to all listeners. If the media descriptor object has been released it
359  * should not be used again.
360  *
361  * \param p_md the media descriptor
362  */
363 LIBVLC_API void libvlc_media_release( libvlc_media_t *p_md );
364
365
366 /**
367  * Get the media resource locator (mrl) from a media descriptor object
368  *
369  * \param p_md a media descriptor object
370  * \return string with mrl of media descriptor object
371  */
372 LIBVLC_API char *libvlc_media_get_mrl( libvlc_media_t *p_md );
373
374 /**
375  * Duplicate a media descriptor object.
376  *
377  * \param p_md a media descriptor object.
378  */
379 LIBVLC_API libvlc_media_t *libvlc_media_duplicate( libvlc_media_t *p_md );
380
381 /**
382  * Read the meta of the media.
383  *
384  * If the media has not yet been parsed this will return NULL.
385  *
386  * This methods automatically calls libvlc_media_parse_async(), so after calling
387  * it you may receive a libvlc_MediaMetaChanged event. If you prefer a synchronous
388  * version ensure that you call libvlc_media_parse() before get_meta().
389  *
390  * \see libvlc_media_parse
391  * \see libvlc_media_parse_async
392  * \see libvlc_MediaMetaChanged
393  *
394  * \param p_md the media descriptor
395  * \param e_meta the meta to read
396  * \return the media's meta
397  */
398 LIBVLC_API char *libvlc_media_get_meta( libvlc_media_t *p_md,
399                                              libvlc_meta_t e_meta );
400
401 /**
402  * Set the meta of the media (this function will not save the meta, call
403  * libvlc_media_save_meta in order to save the meta)
404  *
405  * \param p_md the media descriptor
406  * \param e_meta the meta to write
407  * \param psz_value the media's meta
408  */
409 LIBVLC_API void libvlc_media_set_meta( libvlc_media_t *p_md,
410                                            libvlc_meta_t e_meta,
411                                            const char *psz_value );
412
413
414 /**
415  * Save the meta previously set
416  *
417  * \param p_md the media desriptor
418  * \return true if the write operation was successful
419  */
420 LIBVLC_API int libvlc_media_save_meta( libvlc_media_t *p_md );
421
422
423 /**
424  * Get current state of media descriptor object. Possible media states
425  * are defined in libvlc_structures.c ( libvlc_NothingSpecial=0,
426  * libvlc_Opening, libvlc_Buffering, libvlc_Playing, libvlc_Paused,
427  * libvlc_Stopped, libvlc_Ended,
428  * libvlc_Error).
429  *
430  * \see libvlc_state_t
431  * \param p_md a media descriptor object
432  * \return state of media descriptor object
433  */
434 LIBVLC_API libvlc_state_t libvlc_media_get_state(
435                                    libvlc_media_t *p_md );
436
437
438 /**
439  * Get the current statistics about the media
440  * \param p_md: media descriptor object
441  * \param p_stats: structure that contain the statistics about the media
442  *                 (this structure must be allocated by the caller)
443  * \return true if the statistics are available, false otherwise
444  *
445  * \libvlc_return_bool
446  */
447 LIBVLC_API int libvlc_media_get_stats( libvlc_media_t *p_md,
448                                            libvlc_media_stats_t *p_stats );
449
450 /* The following method uses libvlc_media_list_t, however, media_list usage is optionnal
451  * and this is here for convenience */
452 #define VLC_FORWARD_DECLARE_OBJECT(a) struct a
453
454 /**
455  * Get subitems of media descriptor object. This will increment
456  * the reference count of supplied media descriptor object. Use
457  * libvlc_media_list_release() to decrement the reference counting.
458  *
459  * \param p_md media descriptor object
460  * \return list of media descriptor subitems or NULL
461  */
462 LIBVLC_API VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t *)
463 libvlc_media_subitems( libvlc_media_t *p_md );
464
465 /**
466  * Get event manager from media descriptor object.
467  * NOTE: this function doesn't increment reference counting.
468  *
469  * \param p_md a media descriptor object
470  * \return event manager object
471  */
472 LIBVLC_API libvlc_event_manager_t *
473     libvlc_media_event_manager( libvlc_media_t *p_md );
474
475 /**
476  * Get duration (in ms) of media descriptor object item.
477  *
478  * \param p_md media descriptor object
479  * \return duration of media item or -1 on error
480  */
481 LIBVLC_API libvlc_time_t
482    libvlc_media_get_duration( libvlc_media_t *p_md );
483
484 /**
485  * Parse a media.
486  *
487  * This fetches (local) meta data and tracks information.
488  * The method is synchronous.
489  *
490  * \see libvlc_media_parse_async
491  * \see libvlc_media_get_meta
492  * \see libvlc_media_get_tracks_info
493  *
494  * \param p_md media descriptor object
495  */
496 LIBVLC_API void
497 libvlc_media_parse( libvlc_media_t *p_md );
498
499 /**
500  * Parse a media.
501  *
502  * This fetches (local) meta data and tracks information.
503  * The method is the asynchronous of libvlc_media_parse().
504  *
505  * To track when this is over you can listen to libvlc_MediaParsedChanged
506  * event. However if the media was already parsed you will not receive this
507  * event.
508  *
509  * \see libvlc_media_parse
510  * \see libvlc_MediaParsedChanged
511  * \see libvlc_media_get_meta
512  * \see libvlc_media_get_tracks_info
513  *
514  * \param p_md media descriptor object
515  */
516 LIBVLC_API void
517 libvlc_media_parse_async( libvlc_media_t *p_md );
518
519 /**
520  * Get Parsed status for media descriptor object.
521  *
522  * \see libvlc_MediaParsedChanged
523  *
524  * \param p_md media descriptor object
525  * \return true if media object has been parsed otherwise it returns false
526  *
527  * \libvlc_return_bool
528  */
529 LIBVLC_API int
530    libvlc_media_is_parsed( libvlc_media_t *p_md );
531
532 /**
533  * Sets media descriptor's user_data. user_data is specialized data
534  * accessed by the host application, VLC.framework uses it as a pointer to
535  * an native object that references a libvlc_media_t pointer
536  *
537  * \param p_md media descriptor object
538  * \param p_new_user_data pointer to user data
539  */
540 LIBVLC_API void
541     libvlc_media_set_user_data( libvlc_media_t *p_md, void *p_new_user_data );
542
543 /**
544  * Get media descriptor's user_data. user_data is specialized data
545  * accessed by the host application, VLC.framework uses it as a pointer to
546  * an native object that references a libvlc_media_t pointer
547  *
548  * \param p_md media descriptor object
549  */
550 LIBVLC_API void *libvlc_media_get_user_data( libvlc_media_t *p_md );
551
552 /**
553  * Get media descriptor's elementary streams description
554  *
555  * Note, you need to call libvlc_media_parse() or play the media at least once
556  * before calling this function.
557  * Not doing this will result in an empty array.
558  *
559  * \deprecated Use libvlc_media_tracks_get instead
560  *
561  * \param p_md media descriptor object
562  * \param tracks address to store an allocated array of Elementary Streams
563  *        descriptions (must be freed by the caller) [OUT]
564  *
565  * \return the number of Elementary Streams
566  */
567 LIBVLC_DEPRECATED LIBVLC_API
568 int libvlc_media_get_tracks_info( libvlc_media_t *p_md,
569                                   libvlc_media_track_info_t **tracks );
570
571 /**
572  * Get media descriptor's elementary streams description
573  *
574  * Note, you need to call libvlc_media_parse() or play the media at least once
575  * before calling this function.
576  * Not doing this will result in an empty array.
577  *
578  * \version LibVLC 2.1.0 and later.
579  *
580  * \param p_md media descriptor object
581  * \param tracks address to store an allocated array of Elementary Streams
582  *        descriptions (must be freed with libvlc_media_tracks_release
583           by the caller) [OUT]
584  *
585  * \return the number of Elementary Streams (zero on error)
586  */
587 LIBVLC_API
588 unsigned libvlc_media_tracks_get( libvlc_media_t *p_md,
589                                   libvlc_media_track_t ***tracks );
590
591
592 /**
593  * Release media descriptor's elementary streams description array
594  *
595  * \version LibVLC 2.1.0 and later.
596  *
597  * \param p_tracks tracks info array to release
598  * \param i_count number of elements in the array
599  */
600 LIBVLC_API
601 void libvlc_media_tracks_release( libvlc_media_track_t **p_tracks,
602                                   unsigned i_count );
603
604 /** @}*/
605
606 # ifdef __cplusplus
607 }
608 # endif
609
610 #endif /* VLC_LIBVLC_MEDIA_H */