]> git.sesse.net Git - vlc/blob - src/control/libvlc_internal.h
control: Implement and export media_list_view_children_for_item()
[vlc] / src / control / libvlc_internal.h
1 /*****************************************************************************
2  * libvlc_internal.h : Definition of opaque structures for libvlc exported API
3  * Also contains some internal utility functions
4  *****************************************************************************
5  * Copyright (C) 2005 the VideoLAN team
6  * $Id$
7  *
8  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef _LIBVLC_INTERNAL_H
26 #define _LIBVLC_INTERNAL_H 1
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc/vlc.h>
33 #include <vlc/libvlc_structures.h>
34
35 #include <vlc_arrays.h>
36 #include <vlc_input.h>
37
38 # ifdef __cplusplus
39 extern "C" {
40 # endif
41
42 /***************************************************************************
43  * Internal creation and destruction functions
44  ***************************************************************************/
45 VLC_EXPORT (libvlc_int_t *, libvlc_InternalCreate, ( void ) );
46 VLC_EXPORT (int, libvlc_InternalInit, ( libvlc_int_t *, int, const char *ppsz_argv[] ) );
47 VLC_EXPORT (int, libvlc_InternalCleanup, ( libvlc_int_t * ) );
48 VLC_EXPORT (int, libvlc_InternalDestroy, ( libvlc_int_t *, vlc_bool_t ) );
49
50 VLC_EXPORT (int, libvlc_InternalAddIntf, ( libvlc_int_t *, const char *, vlc_bool_t,
51                             vlc_bool_t, int, const char *const * ) );
52
53 VLC_EXPORT (void, libvlc_event_init, ( libvlc_instance_t *, libvlc_exception_t * ) );
54 VLC_EXPORT (void, libvlc_event_fini, ( libvlc_instance_t * ) );
55
56
57 /***************************************************************************
58  * Opaque structures for libvlc API
59  ***************************************************************************/
60
61 typedef int * libvlc_media_list_path_t; /* (Media List Player Internal) */
62
63 typedef enum libvlc_lock_state_t
64 {
65     libvlc_Locked,
66     libvlc_UnLocked
67 } libvlc_lock_state_t;
68
69 struct libvlc_instance_t
70 {
71     libvlc_int_t *p_libvlc_int;
72     vlm_t        *p_vlm;
73     int           b_playlist_locked;
74     unsigned      ref_count;
75     vlc_mutex_t   instance_lock;
76     vlc_mutex_t   event_callback_lock;
77     struct libvlc_callback_entry_list_t *p_callback_list;
78 };
79
80 struct libvlc_tags_storage_t
81 {
82     char ** ppsz_tags;
83     int i_count;
84 };
85
86 struct libvlc_media_descriptor_t
87 {
88     libvlc_event_manager_t * p_event_manager;
89     int                b_preparsed;
90     input_item_t      *p_input_item;
91     int                i_refcount;
92     libvlc_instance_t *p_libvlc_instance;
93     vlc_dictionary_t   tags; /* To be merged with core's meta soon */
94     libvlc_state_t     state;
95     struct libvlc_media_list_t *p_subitems; /* A media descriptor can have
96                                            * Sub item */
97     void *p_user_data; /* Allows for VLC.framework to hook into media descriptor without creating a new VLCMedia object. */
98 };
99
100 struct libvlc_tag_query_t
101 {
102     struct libvlc_instance_t  *p_libvlc_instance; /* Parent instance */
103     int                i_refcount;
104     libvlc_tag_t       tag;
105     char *             psz_tag_key;
106 };
107
108 struct libvlc_media_list_t
109 {
110     libvlc_event_manager_t *    p_event_manager;
111     libvlc_instance_t *         p_libvlc_instance;
112     int                         i_refcount;
113     vlc_mutex_t                 object_lock;
114     libvlc_media_descriptor_t * p_md; /* The media_descriptor from which the
115                                        * mlist comes, if any. */
116     vlc_array_t                items;
117  
118     /* Other way to see that media list */
119     /* Used in flat_media_list.c */
120     libvlc_media_list_t *       p_flat_mlist;
121
122     /* This indicates if this media list is read-only
123      * from a user point of view */
124     vlc_bool_t                  b_read_only;
125 };
126
127 typedef libvlc_media_list_view_t * (*libvlc_media_list_view_constructor_func_t)( libvlc_media_list_t * p_mlist, libvlc_exception_t * p_e ) ;
128 typedef void (*libvlc_media_list_view_release_func_t)( libvlc_media_list_view_t * p_mlv ) ;
129
130 typedef int (*libvlc_media_list_view_count_func_t)( libvlc_media_list_view_t * p_mlv,
131         libvlc_exception_t * ) ;
132
133 typedef libvlc_media_descriptor_t *
134         (*libvlc_media_list_view_item_at_index_func_t)(
135                 libvlc_media_list_view_t * p_mlv,
136                 int index,
137                 libvlc_exception_t * ) ;
138
139 typedef libvlc_media_list_view_t *
140         (*libvlc_media_list_view_children_at_index_func_t)(
141                 libvlc_media_list_view_t * p_mlv,
142                 int index,
143                 libvlc_exception_t * ) ;
144
145 /* A way to see a media list */
146 struct libvlc_media_list_view_t
147 {
148     libvlc_event_manager_t *    p_event_manager;
149     libvlc_instance_t *         p_libvlc_instance;
150     int                         i_refcount;
151     vlc_mutex_t                 object_lock;
152     
153     libvlc_media_list_t *       p_mlist;
154
155     struct libvlc_media_list_view_private_t * p_this_view_data;
156
157     /* Accessors */
158     libvlc_media_list_view_count_func_t              pf_count;
159     libvlc_media_list_view_item_at_index_func_t      pf_item_at_index;
160     libvlc_media_list_view_children_at_index_func_t  pf_children_at_index;
161
162     libvlc_media_list_view_constructor_func_t         pf_constructor;
163     libvlc_media_list_view_release_func_t            pf_release;
164
165     /* Notification callback */
166     void (*pf_ml_item_added)(const libvlc_event_t *, libvlc_media_list_view_t *);
167     void (*pf_ml_item_removed)(const libvlc_event_t *, libvlc_media_list_view_t *);
168 };
169
170 struct libvlc_dynamic_media_list_t
171 {
172     libvlc_instance_t *     p_libvlc_instance;
173     int                     i_refcount;
174     libvlc_media_list_t *   p_media_provider;
175     libvlc_tag_query_t *    p_query;
176     char *                  psz_tag_key;
177     libvlc_tag_t            tag;
178     struct libvlc_media_list_t *  p_mlist;
179     struct libvlc_media_list_t *  p_provider;
180 };
181
182 struct libvlc_media_instance_t
183 {
184     int                i_refcount;
185     vlc_mutex_t        object_lock;
186     int i_input_id;  /* Input object id. We don't use a pointer to
187                         avoid any crash */
188     struct libvlc_instance_t *  p_libvlc_instance; /* Parent instance */
189     libvlc_media_descriptor_t * p_md; /* current media descriptor */
190     libvlc_event_manager_t *    p_event_manager;
191     libvlc_drawable_t           drawable;
192     
193     vlc_bool_t        b_own_its_input_thread;
194 };
195
196 struct libvlc_media_list_player_t
197 {
198     libvlc_event_manager_t *    p_event_manager;
199     libvlc_instance_t *         p_libvlc_instance;
200     int                         i_refcount;
201     vlc_mutex_t                 object_lock;
202     libvlc_media_list_path_t    current_playing_item_path;
203     libvlc_media_descriptor_t * p_current_playing_item;
204     libvlc_media_list_t *       p_mlist;
205     libvlc_media_instance_t *   p_mi;
206 };
207
208 struct libvlc_media_library_t
209 {
210     libvlc_event_manager_t * p_event_manager;
211     libvlc_instance_t *      p_libvlc_instance;
212     int                      i_refcount;
213     libvlc_media_list_t *    p_mlist;
214 };
215
216 struct libvlc_media_discoverer_t
217 {
218     libvlc_event_manager_t * p_event_manager;
219     libvlc_instance_t *      p_libvlc_instance;
220     services_discovery_t *   p_sd;
221     libvlc_media_list_t *    p_mlist;
222     vlc_bool_t               running;
223     vlc_dictionary_t         catname_to_submedialist;
224 };
225
226 /*
227  * Event Handling
228  */
229 /* Example usage
230  *
231  * struct libvlc_cool_object_t
232  * {
233  *        ...
234  *        libvlc_event_manager_t * p_event_manager;
235  *        ...
236  * }
237  *
238  * libvlc_my_cool_object_new()
239  * {
240  *        ...
241  *        p_self->p_event_manager = libvlc_event_manager_init( p_self,
242  *                                                   p_self->p_libvlc_instance, p_e);
243  *        libvlc_event_manager_register_event_type(p_self->p_event_manager,
244  *                libvlc_MyCoolObjectDidSomething, p_e)
245  *        ...
246  * }
247  *
248  * libvlc_my_cool_object_release()
249  * {
250  *         ...
251  *         libvlc_event_manager_release( p_self->p_event_manager );
252  *         ...
253  * }
254  *
255  * libvlc_my_cool_object_do_something()
256  * {
257  *        ...
258  *        libvlc_event_t event;
259  *        event.type = libvlc_MyCoolObjectDidSomething;
260  *        event.u.my_cool_object_did_something.what_it_did = kSomething;
261  *        libvlc_event_send( p_self->p_event_manager, &event );
262  * }
263  * */
264
265 typedef struct libvlc_event_listener_t
266 {
267     libvlc_event_type_t event_type;
268     void *              p_user_data;
269     libvlc_callback_t   pf_callback;
270 } libvlc_event_listener_t;
271
272 typedef struct libvlc_event_listeners_group_t
273 {
274     libvlc_event_type_t event_type;
275     DECL_ARRAY(libvlc_event_listener_t *) listeners;
276 } libvlc_event_listeners_group_t;
277
278 typedef struct libvlc_event_manager_t
279 {
280     void * p_obj;
281     struct libvlc_instance_t * p_libvlc_instance;
282     DECL_ARRAY(libvlc_event_listeners_group_t *) listeners_groups;
283     vlc_mutex_t object_lock;
284     vlc_mutex_t event_sending_lock;
285 } libvlc_event_sender_t;
286
287
288 /***************************************************************************
289  * Other internal functions
290  ***************************************************************************/
291 VLC_EXPORT (input_thread_t *, libvlc_get_input_thread,
292                         ( struct libvlc_media_instance_t *, libvlc_exception_t * ) );
293
294 /* Media instance */
295 VLC_EXPORT (libvlc_media_instance_t *, libvlc_media_instance_new_from_input_thread,
296                         ( struct libvlc_instance_t *, input_thread_t *, libvlc_exception_t * ) );
297
298 VLC_EXPORT (void, libvlc_media_instance_destroy,
299                         ( libvlc_media_instance_t * ) );
300
301 /* Media Descriptor */
302 VLC_EXPORT (libvlc_media_descriptor_t *, libvlc_media_descriptor_new_from_input_item,
303                         ( struct libvlc_instance_t *, input_item_t *, libvlc_exception_t * ) );
304
305 VLC_EXPORT (void, libvlc_media_descriptor_set_state,
306                         ( libvlc_media_descriptor_t *, libvlc_state_t, libvlc_exception_t * ) );
307
308 /* Media List */
309 VLC_EXPORT ( void, _libvlc_media_list_add_media_descriptor,
310                         ( libvlc_media_list_t * p_mlist,
311                           libvlc_media_descriptor_t * p_md,
312                           libvlc_exception_t * p_e ) );
313
314 VLC_EXPORT ( void, _libvlc_media_list_insert_media_descriptor,
315                         ( libvlc_media_list_t * p_mlist,
316                           libvlc_media_descriptor_t * p_md,
317                           int index,
318                           libvlc_exception_t * p_e ) );
319
320 VLC_EXPORT ( void, _libvlc_media_list_remove_index,
321                         ( libvlc_media_list_t * p_mlist,
322                           int index,
323                           libvlc_exception_t * p_e ) );
324
325 /* Media List View */
326 VLC_EXPORT ( libvlc_media_list_view_t *, libvlc_media_list_view_new,
327                           ( libvlc_media_list_t * p_mlist,
328                             libvlc_media_list_view_count_func_t pf_count,
329                             libvlc_media_list_view_item_at_index_func_t pf_item_at_index,
330                             libvlc_media_list_view_children_at_index_func_t pf_children_at_index,
331                             libvlc_media_list_view_constructor_func_t pf_constructor,
332                             libvlc_media_list_view_release_func_t pf_release,
333                             void * this_view_data,
334                             libvlc_exception_t * p_e ) );
335
336 VLC_EXPORT ( void, libvlc_media_list_view_set_ml_notification_callback, (
337                 libvlc_media_list_view_t * p_mlv,
338                 void (*item_added)(const libvlc_event_t *, libvlc_media_list_view_t *),
339                 void (*item_removed)(const libvlc_event_t *, libvlc_media_list_view_t *) ));
340
341 VLC_EXPORT ( void, libvlc_media_list_view_will_delete_item, ( libvlc_media_list_view_t * p_mlv,
342                                                               libvlc_media_descriptor_t * p_item,
343                                                               int index ));
344 VLC_EXPORT ( void, libvlc_media_list_view_item_deleted, ( libvlc_media_list_view_t * p_mlv,
345                                                           libvlc_media_descriptor_t * p_item,
346                                                           int index ));
347 VLC_EXPORT ( void, libvlc_media_list_view_will_add_item, ( libvlc_media_list_view_t * p_mlv,
348                                                            libvlc_media_descriptor_t * p_item,
349                                                            int index ));
350 VLC_EXPORT ( void, libvlc_media_list_view_item_added, ( libvlc_media_list_view_t * p_mlv,
351                                                         libvlc_media_descriptor_t * p_item,
352                                                         int index ));
353
354 /* Events */
355 VLC_EXPORT (libvlc_event_manager_t *, libvlc_event_manager_new, ( void * p_obj, libvlc_instance_t * p_libvlc_inst, libvlc_exception_t *p_e ) );
356
357 VLC_EXPORT (void, libvlc_event_manager_release, ( libvlc_event_manager_t * p_em ) );
358
359 VLC_EXPORT (void, libvlc_event_manager_register_event_type, ( libvlc_event_manager_t * p_em, libvlc_event_type_t event_type, libvlc_exception_t * p_e ) );
360 VLC_EXPORT (void, libvlc_event_detach_lock_state, ( libvlc_event_manager_t *p_event_manager, libvlc_event_type_t event_type, libvlc_callback_t pf_callback,
361                                                     void *p_user_data, libvlc_lock_state_t lockstate, libvlc_exception_t *p_e ) );
362
363 VLC_EXPORT (void, libvlc_event_send, ( libvlc_event_manager_t * p_em, libvlc_event_t * p_event ) );
364
365
366 /* Exception shorcuts */
367
368 #define RAISENULL( psz,a... ) { libvlc_exception_raise( p_e, psz,##a ); \
369                                 return NULL; }
370 #define RAISEVOID( psz,a... ) { libvlc_exception_raise( p_e, psz,##a ); \
371                                 return; }
372 #define RAISEZERO( psz,a... ) { libvlc_exception_raise( p_e, psz,##a ); \
373                                 return 0; }
374
375 # ifdef __cplusplus
376 }
377 # endif
378
379 #endif