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