]> git.sesse.net Git - vlc/blob - include/vlc/libvlc_media.h
ffe98ec1523c7f4524e51e17a4288d724aacf333
[vlc] / include / vlc / libvlc_media.h
1 /*****************************************************************************
2  * libvlc.h:  libvlc external API
3  *****************************************************************************
4  * Copyright (C) 1998-2009 the VideoLAN team
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
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 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 General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, 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_es_type_t
104 {
105     libvlc_es_unknown   = -1,
106     libvlc_es_audio     = 0,
107     libvlc_es_video     = 1,
108     libvlc_es_text      = 2,
109 } libvlc_es_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_es_t
147 {
148     /* Codec fourcc */
149     uint32_t    i_codec;
150     int         i_id;
151     libvlc_es_type_t i_type;
152
153     /* Codec specific */
154     int         i_profile;
155     int         i_level;
156
157     /* Audio specific */
158     unsigned    i_channels;
159     unsigned    i_rate;
160
161     /* Video specific */
162     unsigned    i_height;
163     unsigned    i_width;
164
165 } libvlc_media_es_t;
166
167
168 /**
169  * Create a media with a certain given media resource location.
170  *
171  * \see libvlc_media_release
172  *
173  * \param p_instance the instance
174  * \param psz_mrl the MRL to read
175  * \return the newly created media or NULL on error
176  */
177 VLC_PUBLIC_API libvlc_media_t *libvlc_media_new_location(
178                                    libvlc_instance_t *p_instance,
179                                    const char * psz_mrl );
180
181 /**
182  * Create a media with a certain file path.
183  *
184  * \see libvlc_media_release
185  *
186  * \param p_instance the instance
187  * \param path local filesystem path
188  * \return the newly created media or NULL on error
189  */
190 VLC_PUBLIC_API libvlc_media_t *libvlc_media_new_path(
191                                    libvlc_instance_t *p_instance,
192                                    const char *path );
193
194 /**
195  * Create a media as an empty node with a given name.
196  *
197  * \see libvlc_media_release
198  *
199  * \param p_instance the instance
200  * \param psz_name the name of the node
201  * \return the new empty media or NULL on error
202  */
203 VLC_PUBLIC_API libvlc_media_t * libvlc_media_new_as_node(
204                                    libvlc_instance_t *p_instance,
205                                    const char * psz_name );
206
207 /**
208  * Add an option to the media.
209  *
210  * This option will be used to determine how the media_player will
211  * read the media. This allows to use VLC's advanced
212  * reading/streaming options on a per-media basis.
213  *
214  * The options are detailed in vlc --long-help, for instance "--sout-all"
215  *
216  * \param p_md the media descriptor
217  * \param ppsz_options the options (as a string)
218  */
219 VLC_PUBLIC_API void libvlc_media_add_option(
220                                    libvlc_media_t * p_md,
221                                    const char * ppsz_options );
222
223 /**
224  * Add an option to the media with configurable flags.
225  *
226  * This option will be used to determine how the media_player will
227  * read the media. This allows to use VLC's advanced
228  * reading/streaming options on a per-media basis.
229  *
230  * The options are detailed in vlc --long-help, for instance "--sout-all"
231  *
232  * \param p_md the media descriptor
233  * \param ppsz_options the options (as a string)
234  * \param i_flags the flags for this option
235  */
236 VLC_PUBLIC_API void libvlc_media_add_option_flag(
237                                    libvlc_media_t * p_md,
238                                    const char * ppsz_options,
239                                    unsigned i_flags );
240
241
242 /**
243  * Retain a reference to a media descriptor object (libvlc_media_t). Use
244  * libvlc_media_release() to decrement the reference count of a
245  * media descriptor object.
246  *
247  * \param p_md the media descriptor
248  */
249 VLC_PUBLIC_API void libvlc_media_retain( libvlc_media_t *p_md );
250
251 /**
252  * Decrement the reference count of a media descriptor object. If the
253  * reference count is 0, then libvlc_media_release() will release the
254  * media descriptor object. It will send out an libvlc_MediaFreed event
255  * to all listeners. If the media descriptor object has been released it
256  * should not be used again.
257  *
258  * \param p_md the media descriptor
259  */
260 VLC_PUBLIC_API void libvlc_media_release( libvlc_media_t *p_md );
261
262
263 /**
264  * Get the media resource locator (mrl) from a media descriptor object
265  *
266  * \param p_md a media descriptor object
267  * \return string with mrl of media descriptor object
268  */
269 VLC_PUBLIC_API char * libvlc_media_get_mrl( libvlc_media_t * p_md );
270
271 /**
272  * Duplicate a media descriptor object.
273  *
274  * \param p_md a media descriptor object.
275  */
276 VLC_PUBLIC_API libvlc_media_t * libvlc_media_duplicate( libvlc_media_t *p_md );
277
278 /**
279  * Read the meta of the media.
280  *
281  * \param p_md the media descriptor
282  * \param e_meta the meta to read
283  * \return the media's meta
284  */
285 VLC_PUBLIC_API char * libvlc_media_get_meta( libvlc_media_t *p_md,
286                                              libvlc_meta_t e_meta );
287
288 /**
289  * Set the meta of the media (this function will not save the meta, call
290  * libvlc_media_save_meta in order to save the meta)
291  *
292  * \param p_md the media descriptor
293  * \param e_meta the meta to write
294  * \param psz_value the media's meta
295  */
296 VLC_PUBLIC_API void libvlc_media_set_meta( libvlc_media_t *p_md,
297                                            libvlc_meta_t e_meta,
298                                            const char *psz_value );
299
300
301 /**
302  * Save the meta previously set
303  *
304  * \param p_md the media desriptor
305  * \return true if the write operation was successfull
306  */
307 VLC_PUBLIC_API int libvlc_media_save_meta( libvlc_media_t *p_md );
308
309
310 /**
311  * Get current state of media descriptor object. Possible media states
312  * are defined in libvlc_structures.c ( libvlc_NothingSpecial=0,
313  * libvlc_Opening, libvlc_Buffering, libvlc_Playing, libvlc_Paused,
314  * libvlc_Stopped, libvlc_Ended,
315  * libvlc_Error).
316  *
317  * @see libvlc_state_t
318  * \param p_meta_desc a media descriptor object
319  * \return state of media descriptor object
320  */
321 VLC_PUBLIC_API libvlc_state_t libvlc_media_get_state(
322                                    libvlc_media_t *p_meta_desc );
323
324
325 /**
326  * get the current statistics about the media
327  * @param p_md: media descriptor object
328  * @param p_stats: structure that contain the statistics about the media
329  *                 (this structure must be allocated by the caller)
330  * @return true if the statistics are available, false otherwise
331  */
332 VLC_PUBLIC_API int libvlc_media_get_stats( libvlc_media_t *p_md,
333                                            libvlc_media_stats_t *p_stats );
334
335 /**
336  * Get subitems of media descriptor object. This will increment
337  * the reference count of supplied media descriptor object. Use
338  * libvlc_media_list_release() to decrement the reference counting.
339  *
340  * \param p_md media descriptor object
341  * \return list of media descriptor subitems or NULL
342  */
343
344 /* This method uses libvlc_media_list_t, however, media_list usage is optionnal
345  * and this is here for convenience */
346 #define VLC_FORWARD_DECLARE_OBJECT(a) struct a
347
348 VLC_PUBLIC_API VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t *)
349 libvlc_media_subitems( libvlc_media_t *p_md );
350
351 /**
352  * Get event manager from media descriptor object.
353  * NOTE: this function doesn't increment reference counting.
354  *
355  * \param p_md a media descriptor object
356  * \return event manager object
357  */
358 VLC_PUBLIC_API libvlc_event_manager_t *
359     libvlc_media_event_manager( libvlc_media_t * p_md );
360
361 /**
362  * Get duration (in ms) of media descriptor object item.
363  *
364  * \param p_md media descriptor object
365  * \return duration of media item or -1 on error
366  */
367 VLC_PUBLIC_API libvlc_time_t
368    libvlc_media_get_duration( libvlc_media_t * p_md );
369
370 /**
371  * Get preparsed status for media descriptor object.
372  *
373  * \param p_md media descriptor object
374  * \return true if media object has been preparsed otherwise it returns false
375  */
376 VLC_PUBLIC_API int
377    libvlc_media_is_preparsed( libvlc_media_t * p_md );
378
379 /**
380  * Sets media descriptor's user_data. user_data is specialized data
381  * accessed by the host application, VLC.framework uses it as a pointer to
382  * an native object that references a libvlc_media_t pointer
383  *
384  * \param p_md media descriptor object
385  * \param p_new_user_data pointer to user data
386  */
387 VLC_PUBLIC_API void
388     libvlc_media_set_user_data( libvlc_media_t * p_md,
389                                            void * p_new_user_data );
390
391 /**
392  * Get media descriptor's user_data. user_data is specialized data
393  * accessed by the host application, VLC.framework uses it as a pointer to
394  * an native object that references a libvlc_media_t pointer
395  *
396  * \param p_md media descriptor object
397  */
398 VLC_PUBLIC_API void *
399     libvlc_media_get_user_data( libvlc_media_t * p_md );
400
401 /**
402  * Get media descriptor's elementary streams description
403  *
404  * Note, you need to play the media _one_ time with --sout="#description"
405  * Not doing this will result in an empty array, and doing it more than once
406  * will duplicate the entries in the array each time.
407  *
408  * \param p_md media descriptor object
409  * \param pp_es address to store an allocated array of Elementary Streams descriptions (must be freed by the caller)
410  *
411  * return the number of Elementary Streams
412  */
413 VLC_PUBLIC_API int
414     libvlc_media_get_es( libvlc_media_t * p_md, libvlc_media_es_t ** pp_es );
415
416 /** @}*/
417
418 # ifdef __cplusplus
419 }
420 # endif
421
422 #endif /* VLC_LIBVLC_MEDIA_H */