]> git.sesse.net Git - vlc/blob - src/control/vlm.c
libvlc : handle VLM input events
[vlc] / src / control / vlm.c
1 /*****************************************************************************
2  * vlm.c: libvlc new API VLM handling functions
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include <vlc/libvlc.h>
25 #include <vlc/libvlc_vlm.h>
26 #include <vlc_es.h>
27 #include <vlc_input.h>
28 #include <vlc_vlm.h>
29
30 #include "libvlc_internal.h"
31
32 #if 0
33 /* local function to be used in libvlc_vlm_show_media only */
34 static char* recurse_answer( char* psz_prefix, vlm_message_t *p_answer ) {
35     char* psz_childprefix;
36     char* psz_response="";
37     char* response_tmp;
38     int i;
39     vlm_message_t *aw_child, **paw_child;
40
41     asprintf( &psz_childprefix, "%s%s.", psz_prefix, p_answer->psz_name );
42
43     if ( p_answer->i_child )
44     {
45         paw_child = p_answer->child;
46         aw_child = *( paw_child );
47         for( i = 0; i < p_answer->i_child; i++ )
48         {
49             asprintf( &response_tmp, "%s%s%s:%s\n",
50                       psz_response, psz_prefix, aw_child->psz_name,
51                       aw_child->psz_value );
52             free( psz_response );
53             psz_response = response_tmp;
54             if ( aw_child->i_child )
55             {
56                 asprintf(&response_tmp, "%s%s", psz_response,
57                          recurse_answer(psz_childprefix, aw_child));
58                 free( psz_response );
59                 psz_response = response_tmp;
60             }
61             paw_child++;
62             aw_child = *( paw_child );
63         }
64     }
65     free( psz_childprefix );
66     return psz_response;
67 }
68
69 char* libvlc_vlm_show_media( libvlc_instance_t *p_instance, char *psz_name,
70                              libvlc_exception_t *p_exception )
71 {
72     char *psz_message;
73     vlm_message_t *answer;
74     char *psz_response;
75
76     CHECK_VLM;
77     asprintf( &psz_message, "show %s", psz_name );
78     asprintf( &psz_response, "", psz_name );
79     vlm_ExecuteCommand( p_instance->libvlc_vlm.p_vlm, psz_message, &answer );
80     if( answer->psz_value )
81     {
82         libvlc_exception_raise( p_exception, "Unable to call show %s: %s",
83                                 psz_name, answer->psz_value );
84     }
85     else
86     {
87         if ( answer->child )
88         {
89             psz_response = recurse_answer( "", answer );
90         }
91     }
92     free( psz_message );
93     return(psz_response );
94 }
95 #else
96
97 char* libvlc_vlm_show_media( libvlc_instance_t *p_instance,
98                              const char *psz_name,
99                              libvlc_exception_t *p_exception )
100 {
101     (void)p_instance;
102     /* FIXME is it needed ? */
103     libvlc_exception_raise( p_exception, "Unable to call show %s", psz_name );
104     return NULL;
105 }
106
107 #endif /* 0 */
108 /* VLM events callback. Transmit to libvlc */
109 static int VlmEvent( vlc_object_t *p_this, const char * name,
110                      vlc_value_t old_val, vlc_value_t newval, void *param )
111 {
112     vlm_event_t *event = (vlm_event_t*)newval.p_address;
113     libvlc_event_manager_t *p_event_manager = (libvlc_event_manager_t *) param;
114     libvlc_event_t libvlc_event;
115
116     VLC_UNUSED( p_this );
117     VLC_UNUSED( name );
118     VLC_UNUSED( old_val );
119
120     libvlc_event.u.vlm_media_event.psz_instance_name = NULL;
121     libvlc_event.u.vlm_media_event.psz_media_name = event->psz_name;
122
123     switch( event->i_type )
124     {
125     case VLM_EVENT_MEDIA_ADDED:
126         libvlc_event.type = libvlc_VlmMediaAdded;
127         break;
128     case VLM_EVENT_MEDIA_REMOVED:
129         libvlc_event.type = libvlc_VlmMediaRemoved;
130         break;
131     case VLM_EVENT_MEDIA_CHANGED:
132         libvlc_event.type = libvlc_VlmMediaChanged;
133         break;
134     case VLM_EVENT_MEDIA_INSTANCE_STARTED:
135         libvlc_event.type = libvlc_VlmMediaInstanceStarted;
136         break;
137     case VLM_EVENT_MEDIA_INSTANCE_STOPPED:
138         libvlc_event.type = libvlc_VlmMediaInstanceStopped;
139         break;
140     case VLM_EVENT_MEDIA_INSTANCE_STATE:
141         libvlc_event.u.vlm_media_event.psz_instance_name =
142             event->psz_instance_name;
143         switch( event->input_state )
144         {
145         case INIT_S:
146             libvlc_event.type = libvlc_VlmMediaInstanceStatusInit;
147             break;
148         case OPENING_S:
149             libvlc_event.type =
150                 libvlc_VlmMediaInstanceStatusOpening;
151             break;
152         case PLAYING_S:
153             libvlc_event.type =
154                 libvlc_VlmMediaInstanceStatusPlaying;
155             break;
156         case PAUSE_S:
157             libvlc_event.type = libvlc_VlmMediaInstanceStatusPause;
158             break;
159         case END_S:
160             libvlc_event.type = libvlc_VlmMediaInstanceStatusEnd;
161             break;
162         case ERROR_S:
163             libvlc_event.type = libvlc_VlmMediaInstanceStatusError;
164             break;
165         default:
166             return 0;
167         }
168         break;
169     default:
170         return 0;
171     }
172     libvlc_event_send( p_event_manager, &libvlc_event );
173     return 0;
174 }
175
176 static void libvlc_vlm_release_internal( libvlc_instance_t *p_instance )
177 {
178     vlm_t *p_vlm = p_instance->libvlc_vlm.p_vlm;
179     if( !p_instance->libvlc_vlm.p_vlm )
180         return;
181     /* We need to remove medias in order to receive events */
182     vlm_Control( p_vlm, VLM_CLEAR_MEDIAS );
183     vlm_Control( p_vlm, VLM_CLEAR_SCHEDULES );
184
185     var_DelCallback( (vlc_object_t *)p_vlm, "intf-event", VlmEvent,
186                      p_instance->libvlc_vlm.p_event_manager );
187     p_instance->libvlc_vlm.pf_release = NULL;
188     libvlc_event_manager_release( p_instance->libvlc_vlm.p_event_manager );
189     p_instance->libvlc_vlm.p_event_manager = NULL;
190     vlm_Delete( p_vlm );
191     p_instance->libvlc_vlm.p_vlm = NULL;
192 }
193
194 static int libvlc_vlm_init( libvlc_instance_t *p_instance,
195                             libvlc_exception_t *p_exception )
196 {
197     if( !p_instance->libvlc_vlm.p_event_manager )
198     {
199         p_instance->libvlc_vlm.p_event_manager =
200             libvlc_event_manager_new( p_instance->libvlc_vlm.p_vlm,
201                                       p_instance, p_exception );
202         libvlc_event_manager_register_event_type(
203             p_instance->libvlc_vlm.p_event_manager,
204             libvlc_VlmMediaAdded, NULL );
205         libvlc_event_manager_register_event_type(
206             p_instance->libvlc_vlm.p_event_manager,
207             libvlc_VlmMediaRemoved, NULL );
208         libvlc_event_manager_register_event_type(
209             p_instance->libvlc_vlm.p_event_manager,
210             libvlc_VlmMediaChanged, NULL );
211         libvlc_event_manager_register_event_type(
212             p_instance->libvlc_vlm.p_event_manager,
213             libvlc_VlmMediaInstanceStarted, NULL );
214         libvlc_event_manager_register_event_type(
215             p_instance->libvlc_vlm.p_event_manager,
216             libvlc_VlmMediaInstanceStopped, NULL );
217         libvlc_event_manager_register_event_type(
218             p_instance->libvlc_vlm.p_event_manager,
219             libvlc_VlmMediaInstanceStatusInit, NULL );
220         libvlc_event_manager_register_event_type(
221             p_instance->libvlc_vlm.p_event_manager,
222             libvlc_VlmMediaInstanceStatusOpening, NULL );
223         libvlc_event_manager_register_event_type(
224             p_instance->libvlc_vlm.p_event_manager,
225             libvlc_VlmMediaInstanceStatusPlaying, NULL );
226         libvlc_event_manager_register_event_type(
227             p_instance->libvlc_vlm.p_event_manager,
228             libvlc_VlmMediaInstanceStatusPause, NULL );
229         libvlc_event_manager_register_event_type(
230             p_instance->libvlc_vlm.p_event_manager,
231             libvlc_VlmMediaInstanceStatusEnd, NULL );
232         libvlc_event_manager_register_event_type(
233             p_instance->libvlc_vlm.p_event_manager,
234             libvlc_VlmMediaInstanceStatusError, NULL );
235     }
236
237     if( !p_instance->libvlc_vlm.p_vlm )
238     {
239         p_instance->libvlc_vlm.p_vlm = vlm_New( p_instance->p_libvlc_int );
240         if( !p_instance->libvlc_vlm.p_vlm )
241         {
242             libvlc_exception_raise( p_exception,
243                                     "Unable to create VLM." );
244             return VLC_EGENERIC;
245         }
246         var_AddCallback( (vlc_object_t *)p_instance->libvlc_vlm.p_vlm,
247                          "intf-event", VlmEvent,
248                          p_instance->libvlc_vlm.p_event_manager );
249         p_instance->libvlc_vlm.pf_release = libvlc_vlm_release_internal;
250     }
251
252     return VLC_SUCCESS;
253 }
254
255 void libvlc_vlm_release( libvlc_instance_t *p_instance,
256                          libvlc_exception_t *p_exception)
257 {
258     libvlc_vlm_release_internal( p_instance );
259 }
260
261 #define VLM_RET(p,ret) do {                                     \
262     if( libvlc_vlm_init( p_instance, p_exception ) ) return ret;\
263     (p) = p_instance->libvlc_vlm.p_vlm;                                    \
264   } while(0)
265 #define VLM(p) VLM_RET(p,)
266
267 static vlm_media_instance_t *
268 libvlc_vlm_get_media_instance( libvlc_instance_t *p_instance,
269                                const char *psz_name, int i_minstance_idx,
270                                libvlc_exception_t *p_exception )
271 {
272     vlm_t *p_vlm;
273     vlm_media_instance_t **pp_minstance;
274     vlm_media_instance_t *p_minstance;
275     int i_minstance;
276     int64_t id;
277
278     VLM_RET(p_vlm, NULL);
279
280     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
281         vlm_Control( p_vlm, VLM_GET_MEDIA_INSTANCES, id, &pp_minstance,
282                      &i_minstance ) )
283     {
284         libvlc_exception_raise( p_exception, "Unable to get %s instances",
285                                 psz_name );
286         return NULL;
287     }
288     p_minstance = NULL;
289     if( i_minstance_idx >= 0 && i_minstance_idx < i_minstance )
290     {
291         p_minstance = pp_minstance[i_minstance_idx];
292         TAB_REMOVE( i_minstance, pp_minstance, p_minstance );
293     }
294     while( i_minstance > 0 )
295         vlm_media_instance_Delete( pp_minstance[--i_minstance] );
296     TAB_CLEAN( i_minstance, pp_minstance );
297     return p_minstance;
298 }
299
300 void libvlc_vlm_add_broadcast( libvlc_instance_t *p_instance,
301                                const char *psz_name,
302                                const char *psz_input,
303                                const char *psz_output, int i_options,
304                                const char * const *ppsz_options,
305                                int b_enabled, int b_loop,
306                                libvlc_exception_t *p_exception )
307 {
308     vlm_t *p_vlm;
309     vlm_media_t m;
310     int n;
311
312     VLM(p_vlm);
313
314     vlm_media_Init( &m );
315     m.psz_name = strdup( psz_name );
316     m.b_enabled = b_enabled;
317     m.b_vod = false;
318     m.broadcast.b_loop = b_loop;
319     if( psz_input )
320         TAB_APPEND( m.i_input, m.ppsz_input, strdup(psz_input) );
321     if( psz_output )
322         m.psz_output = strdup( psz_output );
323     for( n = 0; n < i_options; n++ )
324         TAB_APPEND( m.i_option, m.ppsz_option, strdup(ppsz_options[n]) );
325
326     n = vlm_Control( p_vlm, VLM_ADD_MEDIA, &m, NULL );
327     vlm_media_Clean( &m );
328     if( n )
329         libvlc_exception_raise( p_exception, "Media %s creation failed",
330                                 psz_name );
331 }
332
333 void libvlc_vlm_add_vod( libvlc_instance_t *p_instance, const char *psz_name,
334                          const char *psz_input, int i_options,
335                          const char * const *ppsz_options, int b_enabled,
336                          const char *psz_mux, libvlc_exception_t *p_exception )
337 {
338     vlm_t *p_vlm;
339     vlm_media_t m;
340     int n;
341
342     VLM(p_vlm);
343
344     vlm_media_Init( &m );
345     m.psz_name = strdup( psz_name );
346     m.b_enabled = b_enabled;
347     m.b_vod = true;
348     m.vod.psz_mux = psz_mux ? strdup( psz_mux ) : NULL;
349     if( psz_input )
350         TAB_APPEND( m.i_input, m.ppsz_input, strdup(psz_input) );
351     for( n = 0; n < i_options; n++ )
352         TAB_APPEND( m.i_option, m.ppsz_option, strdup(ppsz_options[n]) );
353
354     n = vlm_Control( p_vlm, VLM_ADD_MEDIA, &m, NULL );
355     vlm_media_Clean( &m );
356     if( n )
357         libvlc_exception_raise( p_exception, "Media %s creation failed",
358                                 psz_name );
359 }
360
361 void libvlc_vlm_del_media( libvlc_instance_t *p_instance, const char *psz_name,
362                            libvlc_exception_t *p_exception )
363 {
364     vlm_t *p_vlm;
365     int64_t id;
366
367     VLM(p_vlm);
368
369     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
370         vlm_Control( p_vlm, VLM_DEL_MEDIA, id ) )
371     {
372         libvlc_exception_raise( p_exception, "Unable to delete %s", psz_name );
373     }
374 }
375
376 #define VLM_CHANGE(psz_error, code ) do {   \
377     vlm_media_t *p_media;   \
378     vlm_t *p_vlm;           \
379     int64_t id;             \
380     VLM(p_vlm);             \
381     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||    \
382         vlm_Control( p_vlm, VLM_GET_MEDIA, id, &p_media ) ) {       \
383         libvlc_exception_raise( p_exception, psz_error, psz_name ); \
384         return;             \
385     }                       \
386     if( !p_media ) goto error;                                      \
387                             \
388     code;                   \
389                             \
390     if( vlm_Control( p_vlm, VLM_CHANGE_MEDIA, p_media ) ) {         \
391         vlm_media_Delete( p_media );                                \
392         goto error;         \
393     }                       \
394     vlm_media_Delete( p_media );                                    \
395     return;                 \
396   error:                    \
397     libvlc_exception_raise( p_exception, psz_error, psz_name );\
398   } while(0)
399
400 void libvlc_vlm_set_enabled( libvlc_instance_t *p_instance,
401                              const char *psz_name, int b_enabled,
402                              libvlc_exception_t *p_exception )
403 {
404 #define VLM_CHANGE_CODE { p_media->b_enabled = b_enabled; }
405     VLM_CHANGE( "Unable to delete %s", VLM_CHANGE_CODE );
406 #undef VLM_CHANGE_CODE
407 }
408
409 void libvlc_vlm_set_loop( libvlc_instance_t *p_instance, const char *psz_name,
410                           int b_loop, libvlc_exception_t *p_exception )
411 {
412 #define VLM_CHANGE_CODE { p_media->broadcast.b_loop = b_loop; }
413     VLM_CHANGE( "Unable to change %s loop property", VLM_CHANGE_CODE );
414 #undef VLM_CHANGE_CODE
415 }
416
417 void libvlc_vlm_set_mux( libvlc_instance_t *p_instance, const char *psz_name,
418                          const char *psz_mux, libvlc_exception_t *p_exception )
419 {
420 #define VLM_CHANGE_CODE { if( p_media->b_vod ) { \
421                             free( p_media->vod.psz_mux ); \
422                             p_media->vod.psz_mux = psz_mux \
423                                  ? strdup( psz_mux ) : NULL; \
424                           } }
425     VLM_CHANGE( "Unable to change %s mux property", VLM_CHANGE_CODE );
426 #undef VLM_CHANGE_CODE
427 }
428
429 void libvlc_vlm_set_output( libvlc_instance_t *p_instance,
430                             const char *psz_name, const char *psz_output,
431                             libvlc_exception_t *p_exception )
432 {
433 #define VLM_CHANGE_CODE { free( p_media->psz_output ); \
434                           p_media->psz_output = strdup( psz_output ); }
435     VLM_CHANGE( "Unable to change %s output property", VLM_CHANGE_CODE );
436 #undef VLM_CHANGE_CODE
437 }
438
439 void libvlc_vlm_set_input( libvlc_instance_t *p_instance,
440                            const char *psz_name, const char *psz_input,
441                            libvlc_exception_t *p_exception )
442 {
443 #define VLM_CHANGE_CODE { while( p_media->i_input > 0 ) \
444                             free( p_media->ppsz_input[--p_media->i_input] );\
445                           TAB_APPEND( p_media->i_input, p_media->ppsz_input, \
446                                       strdup(psz_input) ); }
447     VLM_CHANGE( "Unable to change %s input property", VLM_CHANGE_CODE );
448 #undef VLM_CHANGE_CODE
449 }
450
451 void libvlc_vlm_add_input( libvlc_instance_t *p_instance,
452                            const char *psz_name, const char *psz_input,
453                            libvlc_exception_t *p_exception )
454 {
455 #define VLM_CHANGE_CODE { TAB_APPEND( p_media->i_input, p_media->ppsz_input, \
456                           strdup(psz_input) ); }
457     VLM_CHANGE( "Unable to change %s input property", VLM_CHANGE_CODE );
458 #undef VLM_CHANGE_CODE
459 }
460
461 void libvlc_vlm_change_media( libvlc_instance_t *p_instance,
462                               const char *psz_name, const char *psz_input,
463                               const char *psz_output, int i_options,
464                               const char * const *ppsz_options, int b_enabled,
465                               int b_loop, libvlc_exception_t *p_exception )
466 {
467 #define VLM_CHANGE_CODE { int n;        \
468     p_media->b_enabled = b_enabled;     \
469     p_media->broadcast.b_loop = b_loop; \
470     while( p_media->i_input > 0 )       \
471         free( p_media->ppsz_input[--p_media->i_input] );    \
472     if( psz_input )                     \
473         TAB_APPEND( p_media->i_input, p_media->ppsz_input, strdup(psz_input) ); \
474     free( p_media->psz_output );        \
475     p_media->psz_output = psz_output ? strdup( psz_output ) : NULL; \
476     while( p_media->i_option > 0 )     \
477         free( p_media->ppsz_option[--p_media->i_option] );        \
478     for( n = 0; n < i_options; n++ )    \
479         TAB_APPEND( p_media->i_option, p_media->ppsz_option, \
480                     strdup(ppsz_options[n]) );   \
481   }
482     VLM_CHANGE( "Unable to change %s properties", VLM_CHANGE_CODE );
483 #undef VLM_CHANGE_CODE
484 }
485
486 void libvlc_vlm_play_media( libvlc_instance_t *p_instance,
487                             const char *psz_name,
488                             libvlc_exception_t *p_exception )
489 {
490     vlm_t *p_vlm;
491     int64_t id;
492
493     VLM(p_vlm);
494
495     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
496         vlm_Control( p_vlm, VLM_START_MEDIA_BROADCAST_INSTANCE, id, NULL, 0 ) )
497     {
498         libvlc_exception_raise( p_exception, "Unable to play %s", psz_name );
499     }
500 }
501
502 void libvlc_vlm_stop_media( libvlc_instance_t *p_instance,
503                             const char *psz_name,
504                             libvlc_exception_t *p_exception )
505 {
506     vlm_t *p_vlm;
507     int64_t id;
508
509     VLM(p_vlm);
510
511     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
512         vlm_Control( p_vlm, VLM_STOP_MEDIA_INSTANCE, id, NULL ) )
513     {
514         libvlc_exception_raise( p_exception, "Unable to stop %s", psz_name );
515     }
516 }
517
518 void libvlc_vlm_pause_media( libvlc_instance_t *p_instance,
519                              const char *psz_name,
520                              libvlc_exception_t *p_exception )
521 {
522     vlm_t *p_vlm;
523     int64_t id;
524
525     VLM(p_vlm);
526
527     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
528         vlm_Control( p_vlm, VLM_PAUSE_MEDIA_INSTANCE, id, NULL ) )
529     {
530         libvlc_exception_raise( p_exception, "Unable to pause %s", psz_name );
531     }
532 }
533
534 void libvlc_vlm_seek_media( libvlc_instance_t *p_instance,
535                             const char *psz_name, float f_percentage,
536                             libvlc_exception_t *p_exception )
537 {
538     vlm_t *p_vlm;
539     int64_t id;
540
541     VLM(p_vlm);
542
543     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
544         vlm_Control( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, id, NULL,
545                      f_percentage ) )
546         libvlc_exception_raise( p_exception, "Unable to seek %s to %f",
547                                 psz_name, f_percentage );
548 }
549
550 float libvlc_vlm_get_media_instance_position( libvlc_instance_t *p_instance,
551                                               const char *psz_name,
552                                               int i_instance,
553                                               libvlc_exception_t *p_exception )
554 {
555     vlm_media_instance_t *p_mi;
556     float result = -1.;
557
558     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
559                                           i_instance, p_exception );
560     if( p_mi )
561     {
562         result = p_mi->d_position;
563         vlm_media_instance_Delete( p_mi );
564     }
565     return result;
566 }
567
568 int libvlc_vlm_get_media_instance_time( libvlc_instance_t *p_instance,
569                                         const char *psz_name, int i_instance,
570                                         libvlc_exception_t *p_exception )
571 {
572     vlm_media_instance_t *p_mi;
573     int result = -1;
574
575     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
576                                         i_instance, p_exception );
577     if( p_mi )
578     {
579         result = p_mi->i_time;
580         vlm_media_instance_Delete( p_mi );
581     }
582     return result;
583 }
584
585 int libvlc_vlm_get_media_instance_length( libvlc_instance_t *p_instance,
586                                           const char *psz_name,
587                                           int i_instance,
588                                           libvlc_exception_t *p_exception )
589 {
590     vlm_media_instance_t *p_mi;
591     int result = -1;
592
593     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
594                                           i_instance, p_exception );
595     if( p_mi )
596     {
597         result = p_mi->i_length;
598         vlm_media_instance_Delete( p_mi );
599     }
600     return result;
601 }
602
603 int libvlc_vlm_get_media_instance_rate( libvlc_instance_t *p_instance,
604                                         const char *psz_name, int i_instance,
605                                         libvlc_exception_t *p_exception )
606 {
607     vlm_media_instance_t *p_mi;
608     int result = -1;
609
610     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
611                                           i_instance, p_exception );
612     if( p_mi )
613     {
614         result = p_mi->i_rate;
615         vlm_media_instance_Delete( p_mi );
616     }
617     return result;
618 }
619
620 int libvlc_vlm_get_media_instance_title( libvlc_instance_t *p_instance,
621                                          const char *psz_name, int i_instance,
622                                          libvlc_exception_t *p_exception )
623 {
624     vlm_media_instance_t *p_mi;
625
626     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
627                                           i_instance, p_exception );
628     if( p_mi )
629         vlm_media_instance_Delete( p_mi );
630     return p_mi ? 0 : -1;
631 }
632
633 int libvlc_vlm_get_media_instance_chapter( libvlc_instance_t *p_instance,
634                                            const char *psz_name,
635                                            int i_instance,
636                                            libvlc_exception_t *p_exception )
637 {
638     vlm_media_instance_t *p_mi;
639
640     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
641                                           i_instance, p_exception );
642     if( p_mi )
643         vlm_media_instance_Delete( p_mi );
644     return p_mi ? 0 : -1;
645 }
646
647 int libvlc_vlm_get_media_instance_seekable( libvlc_instance_t *p_instance,
648                                             const char *psz_name,
649                                             int i_instance,
650                                             libvlc_exception_t *p_exception )
651 {
652     vlm_media_instance_t *p_mi;
653
654     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
655                                           i_instance, p_exception );
656     if( p_mi )
657         vlm_media_instance_Delete( p_mi );
658     return p_mi ? 0 : -1;
659 }
660
661 libvlc_event_manager_t * libvlc_vlm_get_event_manager( libvlc_instance_t *p_instance,
662                                                        libvlc_exception_t *p_exception )
663 {
664     vlm_t *p_vlm;
665     VLM_RET( p_vlm, NULL);
666     return p_instance->libvlc_vlm.p_event_manager;
667 }