]> git.sesse.net Git - vlc/blob - include/vlc/libvlc_media.h
LibVLC structures: cleanup
[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 /*****************************************************************************
39  * media
40  *****************************************************************************/
41 /** \defgroup libvlc_media libvlc_media
42  * \ingroup libvlc
43  * LibVLC Media
44  * @{
45  */
46
47 typedef struct libvlc_media_t libvlc_media_t;
48
49 /* Meta Handling */
50 /** defgroup libvlc_meta libvlc_meta
51  * \ingroup libvlc_media
52  * LibVLC Media Meta
53  * @{
54  */
55
56 typedef enum libvlc_meta_t {
57     libvlc_meta_Title,
58     libvlc_meta_Artist,
59     libvlc_meta_Genre,
60     libvlc_meta_Copyright,
61     libvlc_meta_Album,
62     libvlc_meta_TrackNumber,
63     libvlc_meta_Description,
64     libvlc_meta_Rating,
65     libvlc_meta_Date,
66     libvlc_meta_Setting,
67     libvlc_meta_URL,
68     libvlc_meta_Language,
69     libvlc_meta_NowPlaying,
70     libvlc_meta_Publisher,
71     libvlc_meta_EncodedBy,
72     libvlc_meta_ArtworkURL,
73     libvlc_meta_TrackID,
74     /* Add new meta types HERE */
75 } libvlc_meta_t;
76
77 /** @}*/
78
79 /**
80  * Note the order of libvlc_state_t enum must match exactly the order of
81  * @see mediacontrol_PlayerStatus, @see input_state_e enums,
82  * and VideoLAN.LibVLC.State (at bindings/cil/src/media.cs).
83  *
84  * Expected states by web plugins are:
85  * IDLE/CLOSE=0, OPENING=1, BUFFERING=2, PLAYING=3, PAUSED=4,
86  * STOPPING=5, ENDED=6, ERROR=7
87  */
88 typedef enum libvlc_state_t
89 {
90     libvlc_NothingSpecial=0,
91     libvlc_Opening,
92     libvlc_Buffering,
93     libvlc_Playing,
94     libvlc_Paused,
95     libvlc_Stopped,
96     libvlc_Ended,
97     libvlc_Error
98 } libvlc_state_t;
99
100 enum
101 {
102     libvlc_media_option_trusted = 0x2,
103     libvlc_media_option_unique = 0x100
104 };
105
106 typedef enum libvlc_es_type_t
107 {
108     libvlc_es_unknown   = -1,
109     libvlc_es_audio     = 0,
110     libvlc_es_video     = 1,
111     libvlc_es_text      = 2,
112 } libvlc_es_type_t;
113
114 /** defgroup libvlc_media_stats_t libvlc_media_stats_t
115  * \ingroup libvlc_media
116  * LibVLC Media statistics
117  * @{
118  */
119 typedef struct libvlc_media_stats_t
120 {
121     /* Input */
122     int         i_read_bytes;
123     float       f_input_bitrate;
124
125     /* Demux */
126     int         i_demux_read_bytes;
127     float       f_demux_bitrate;
128     int         i_demux_corrupted;
129     int         i_demux_discontinuity;
130
131     /* Decoders */
132     int         i_decoded_video;
133     int         i_decoded_audio;
134
135     /* Video Output */
136     int         i_displayed_pictures;
137     int         i_lost_pictures;
138
139     /* Audio output */
140     int         i_played_abuffers;
141     int         i_lost_abuffers;
142
143     /* Stream output */
144     int         i_sent_packets;
145     int         i_sent_bytes;
146     float       f_send_bitrate;
147 } libvlc_media_stats_t;
148 /** @}*/
149
150 typedef struct libvlc_media_es_t
151 {
152     /* Codec fourcc */
153     uint32_t    i_codec;
154     int         i_id;
155     libvlc_es_type_t i_type;
156
157     /* Codec specific */
158     int         i_profile;
159     int         i_level;
160
161     /* Audio specific */
162     unsigned    i_channels;
163     unsigned    i_rate;
164
165     /* Video specific */
166     unsigned    i_height;
167     unsigned    i_width;
168
169 } libvlc_media_es_t;
170
171
172 /**
173  * Create a media with a certain given media resource location.
174  *
175  * \param p_instance the instance
176  * \param psz_mrl the MRL to read
177  * \return the newly created media or NULL on error
178  */
179 VLC_PUBLIC_API libvlc_media_t *libvlc_media_new_location(
180                                    libvlc_instance_t *p_instance,
181                                    const char * psz_mrl );
182
183 /**
184  * Create a media with a certain file path.
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  * \param p_instance the instance
198  * \param psz_name the name of the node
199  * \return the new empty media or NULL on error
200  */
201 VLC_PUBLIC_API libvlc_media_t * libvlc_media_new_as_node(
202                                    libvlc_instance_t *p_instance,
203                                    const char * psz_name );
204
205 /**
206  * Add an option to the media.
207  *
208  * This option will be used to determine how the media_player will
209  * read the media. This allows to use VLC's advanced
210  * reading/streaming options on a per-media basis.
211  *
212  * The options are detailed in vlc --long-help, for instance "--sout-all"
213  *
214  * \param p_md the media descriptor
215  * \param ppsz_options the options (as a string)
216  */
217 VLC_PUBLIC_API void libvlc_media_add_option(
218                                    libvlc_media_t * p_md,
219                                    const char * ppsz_options );
220
221 /**
222  * Add an option to the media with configurable flags.
223  *
224  * This option will be used to determine how the media_player will
225  * read the media. This allows to use VLC's advanced
226  * reading/streaming options on a per-media basis.
227  *
228  * The options are detailed in vlc --long-help, for instance "--sout-all"
229  *
230  * \param p_md the media descriptor
231  * \param ppsz_options the options (as a string)
232  * \param i_flags the flags for this option
233  */
234 VLC_PUBLIC_API void libvlc_media_add_option_flag(
235                                    libvlc_media_t * p_md,
236                                    const char * ppsz_options,
237                                    unsigned i_flags );
238
239
240 /**
241  * Retain a reference to a media descriptor object (libvlc_media_t). Use
242  * libvlc_media_release() to decrement the reference count of a
243  * media descriptor object.
244  *
245  * \param p_md the media descriptor
246  */
247 VLC_PUBLIC_API void libvlc_media_retain( libvlc_media_t *p_md );
248
249 /**
250  * Decrement the reference count of a media descriptor object. If the
251  * reference count is 0, then libvlc_media_release() will release the
252  * media descriptor object. It will send out an libvlc_MediaFreed event
253  * to all listeners. If the media descriptor object has been released it
254  * should not be used again.
255  *
256  * \param p_md the media descriptor
257  */
258 VLC_PUBLIC_API void libvlc_media_release( libvlc_media_t *p_md );
259
260
261 /**
262  * Get the media resource locator (mrl) from a media descriptor object
263  *
264  * \param p_md a media descriptor object
265  * \return string with mrl of media descriptor object
266  */
267 VLC_PUBLIC_API char * libvlc_media_get_mrl( libvlc_media_t * p_md );
268
269 /**
270  * Duplicate a media descriptor object.
271  *
272  * \param p_md a media descriptor object.
273  */
274 VLC_PUBLIC_API libvlc_media_t * libvlc_media_duplicate( libvlc_media_t *p_md );
275
276 /**
277  * Read the meta of the media.
278  *
279  * \param p_md the media descriptor
280  * \param e_meta the meta to read
281  * \return the media's meta
282  */
283 VLC_PUBLIC_API char * libvlc_media_get_meta( libvlc_media_t *p_md,
284                                              libvlc_meta_t e_meta );
285
286 /**
287  * Set the meta of the media (this function will not save the meta, call
288  * libvlc_media_save_meta in order to save the meta)
289  *
290  * \param p_md the media descriptor
291  * \param e_meta the meta to write
292  * \param psz_value the media's meta
293  */
294 VLC_PUBLIC_API void libvlc_media_set_meta( libvlc_media_t *p_md,
295                                            libvlc_meta_t e_meta,
296                                            const char *psz_value );
297
298
299 /**
300  * Save the meta previously set
301  *
302  * \param p_md the media desriptor
303  * \return true if the write operation was successfull
304  */
305 VLC_PUBLIC_API int libvlc_media_save_meta( libvlc_media_t *p_md );
306
307
308 /**
309  * Get current state of media descriptor object. Possible media states
310  * are defined in libvlc_structures.c ( libvlc_NothingSpecial=0,
311  * libvlc_Opening, libvlc_Buffering, libvlc_Playing, libvlc_Paused,
312  * libvlc_Stopped, libvlc_Ended,
313  * libvlc_Error).
314  *
315  * @see libvlc_state_t
316  * \param p_meta_desc a media descriptor object
317  * \return state of media descriptor object
318  */
319 VLC_PUBLIC_API libvlc_state_t libvlc_media_get_state(
320                                    libvlc_media_t *p_meta_desc );
321
322
323 /**
324  * get the current statistics about the media
325  * @param p_md: media descriptor object
326  * @param p_stats: structure that contain the statistics about the media
327  *                 (this structure must be allocated by the caller)
328  * @return true if the statistics are available, false otherwise
329  */
330 VLC_PUBLIC_API int libvlc_media_get_stats( libvlc_media_t *p_md,
331                                            libvlc_media_stats_t *p_stats );
332
333 /**
334  * Get subitems of media descriptor object. This will increment
335  * the reference count of supplied media descriptor object. Use
336  * libvlc_media_list_release() to decrement the reference counting.
337  *
338  * \param p_md media descriptor object
339  * \return list of media descriptor subitems or NULL
340  */
341
342 /* This method uses libvlc_media_list_t, however, media_list usage is optionnal
343  * and this is here for convenience */
344 #define VLC_FORWARD_DECLARE_OBJECT(a) struct a
345
346 VLC_PUBLIC_API VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t *)
347 libvlc_media_subitems( libvlc_media_t *p_md );
348
349 /**
350  * Get event manager from media descriptor object.
351  * NOTE: this function doesn't increment reference counting.
352  *
353  * \param p_md a media descriptor object
354  * \return event manager object
355  */
356 VLC_PUBLIC_API libvlc_event_manager_t *
357     libvlc_media_event_manager( libvlc_media_t * p_md );
358
359 /**
360  * Get duration (in ms) of media descriptor object item.
361  *
362  * \param p_md media descriptor object
363  * \return duration of media item or -1 on error
364  */
365 VLC_PUBLIC_API libvlc_time_t
366    libvlc_media_get_duration( libvlc_media_t * p_md );
367
368 /**
369  * Get preparsed status for media descriptor object.
370  *
371  * \param p_md media descriptor object
372  * \return true if media object has been preparsed otherwise it returns false
373  */
374 VLC_PUBLIC_API int
375    libvlc_media_is_preparsed( libvlc_media_t * p_md );
376
377 /**
378  * Sets media descriptor's user_data. user_data is specialized data
379  * accessed by the host application, VLC.framework uses it as a pointer to
380  * an native object that references a libvlc_media_t pointer
381  *
382  * \param p_md media descriptor object
383  * \param p_new_user_data pointer to user data
384  */
385 VLC_PUBLIC_API void
386     libvlc_media_set_user_data( libvlc_media_t * p_md,
387                                            void * p_new_user_data );
388
389 /**
390  * Get media descriptor's user_data. user_data is specialized data
391  * accessed by the host application, VLC.framework uses it as a pointer to
392  * an native object that references a libvlc_media_t pointer
393  *
394  * \param p_md media descriptor object
395  */
396 VLC_PUBLIC_API void *
397     libvlc_media_get_user_data( libvlc_media_t * p_md );
398
399 /**
400  * Get media descriptor's elementary streams description
401  *
402  * Note, you need to play the media _one_ time with --sout="#description"
403  * Not doing this will result in an empty array, and doing it more than once
404  * will duplicate the entries in the array each time.
405  *
406  * \param p_md media descriptor object
407  * \param pp_es address to store an allocated array of Elementary Streams descriptions (must be freed by the caller)
408  *
409  * return the number of Elementary Streams
410  */
411 VLC_PUBLIC_API int
412     libvlc_media_get_es( libvlc_media_t * p_md, libvlc_media_es_t ** pp_es );
413
414 /** @}*/
415
416 # ifdef __cplusplus
417 }
418 # endif
419
420 #endif /* VLC_LIBVLC_MEDIA_H */