]> git.sesse.net Git - vlc/blob - src/control/vlm.c
2c9dc6274be80221b40a64b82294f7d079cac411
[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 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #include <vlc/libvlc.h>
29 #include <vlc/libvlc_vlm.h>
30 #include <vlc_es.h>
31 #include <vlc_input.h>
32 #include <vlc_vlm.h>
33 #include <assert.h>
34
35 #include "libvlc_internal.h"
36
37 /* VLM events callback. Transmit to libvlc */
38 static int VlmEvent( vlc_object_t *p_this, const char * name,
39                      vlc_value_t old_val, vlc_value_t newval, void *param )
40 {
41     VLC_UNUSED(p_this);
42     VLC_UNUSED(name);
43     VLC_UNUSED(old_val);    
44     vlm_event_t *event = (vlm_event_t*)newval.p_address;
45     libvlc_event_manager_t *p_event_manager = (libvlc_event_manager_t *) param;
46     libvlc_event_t libvlc_event;
47
48     libvlc_event.u.vlm_media_event.psz_instance_name = NULL;
49     libvlc_event.u.vlm_media_event.psz_media_name = event->psz_name;
50
51     switch( event->i_type )
52     {
53     case VLM_EVENT_MEDIA_ADDED:
54         libvlc_event.type = libvlc_VlmMediaAdded;
55         break;
56     case VLM_EVENT_MEDIA_REMOVED:
57         libvlc_event.type = libvlc_VlmMediaRemoved;
58         break;
59     case VLM_EVENT_MEDIA_CHANGED:
60         libvlc_event.type = libvlc_VlmMediaChanged;
61         break;
62     case VLM_EVENT_MEDIA_INSTANCE_STARTED:
63         libvlc_event.type = libvlc_VlmMediaInstanceStarted;
64         break;
65     case VLM_EVENT_MEDIA_INSTANCE_STOPPED:
66         libvlc_event.type = libvlc_VlmMediaInstanceStopped;
67         break;
68     case VLM_EVENT_MEDIA_INSTANCE_STATE:
69         libvlc_event.u.vlm_media_event.psz_instance_name =
70             event->psz_instance_name;
71         switch( event->input_state )
72         {
73         case INIT_S:
74             libvlc_event.type = libvlc_VlmMediaInstanceStatusInit;
75             break;
76         case OPENING_S:
77             libvlc_event.type =
78                 libvlc_VlmMediaInstanceStatusOpening;
79             break;
80         case PLAYING_S:
81             libvlc_event.type =
82                 libvlc_VlmMediaInstanceStatusPlaying;
83             break;
84         case PAUSE_S:
85             libvlc_event.type = libvlc_VlmMediaInstanceStatusPause;
86             break;
87         case END_S:
88             libvlc_event.type = libvlc_VlmMediaInstanceStatusEnd;
89             break;
90         case ERROR_S:
91             libvlc_event.type = libvlc_VlmMediaInstanceStatusError;
92             break;
93         default:
94             return 0;
95         }
96         break;
97     default:
98         return 0;
99     }
100     libvlc_event_send( p_event_manager, &libvlc_event );
101     return 0;
102 }
103
104 static void libvlc_vlm_release_internal( libvlc_instance_t *p_instance )
105 {
106     vlm_t *p_vlm = p_instance->libvlc_vlm.p_vlm;
107     if( !p_instance->libvlc_vlm.p_vlm )
108         return;
109     /* We need to remove medias in order to receive events */
110     vlm_Control( p_vlm, VLM_CLEAR_MEDIAS );
111     vlm_Control( p_vlm, VLM_CLEAR_SCHEDULES );
112
113     var_DelCallback( (vlc_object_t *)p_vlm, "intf-event", VlmEvent,
114                      p_instance->libvlc_vlm.p_event_manager );
115     p_instance->libvlc_vlm.pf_release = NULL;
116     libvlc_event_manager_release( p_instance->libvlc_vlm.p_event_manager );
117     p_instance->libvlc_vlm.p_event_manager = NULL;
118     vlm_Delete( p_vlm );
119     p_instance->libvlc_vlm.p_vlm = NULL;
120 }
121
122 static int libvlc_vlm_init( libvlc_instance_t *p_instance,
123                             libvlc_exception_t *p_exception )
124 {
125     if( !p_instance->libvlc_vlm.p_event_manager )
126     {
127         p_instance->libvlc_vlm.p_event_manager =
128             libvlc_event_manager_new( p_instance->libvlc_vlm.p_vlm,
129                                       p_instance, p_exception );
130         libvlc_event_manager_register_event_type(
131             p_instance->libvlc_vlm.p_event_manager,
132             libvlc_VlmMediaAdded, NULL );
133         libvlc_event_manager_register_event_type(
134             p_instance->libvlc_vlm.p_event_manager,
135             libvlc_VlmMediaRemoved, NULL );
136         libvlc_event_manager_register_event_type(
137             p_instance->libvlc_vlm.p_event_manager,
138             libvlc_VlmMediaChanged, NULL );
139         libvlc_event_manager_register_event_type(
140             p_instance->libvlc_vlm.p_event_manager,
141             libvlc_VlmMediaInstanceStarted, NULL );
142         libvlc_event_manager_register_event_type(
143             p_instance->libvlc_vlm.p_event_manager,
144             libvlc_VlmMediaInstanceStopped, NULL );
145         libvlc_event_manager_register_event_type(
146             p_instance->libvlc_vlm.p_event_manager,
147             libvlc_VlmMediaInstanceStatusInit, NULL );
148         libvlc_event_manager_register_event_type(
149             p_instance->libvlc_vlm.p_event_manager,
150             libvlc_VlmMediaInstanceStatusOpening, NULL );
151         libvlc_event_manager_register_event_type(
152             p_instance->libvlc_vlm.p_event_manager,
153             libvlc_VlmMediaInstanceStatusPlaying, NULL );
154         libvlc_event_manager_register_event_type(
155             p_instance->libvlc_vlm.p_event_manager,
156             libvlc_VlmMediaInstanceStatusPause, NULL );
157         libvlc_event_manager_register_event_type(
158             p_instance->libvlc_vlm.p_event_manager,
159             libvlc_VlmMediaInstanceStatusEnd, NULL );
160         libvlc_event_manager_register_event_type(
161             p_instance->libvlc_vlm.p_event_manager,
162             libvlc_VlmMediaInstanceStatusError, NULL );
163     }
164
165     if( !p_instance->libvlc_vlm.p_vlm )
166     {
167         p_instance->libvlc_vlm.p_vlm = vlm_New( p_instance->p_libvlc_int );
168         if( !p_instance->libvlc_vlm.p_vlm )
169         {
170             libvlc_exception_raise( p_exception );
171             libvlc_printerr( "VLM not supported or out of memory" );
172             return VLC_EGENERIC;
173         }
174         var_AddCallback( (vlc_object_t *)p_instance->libvlc_vlm.p_vlm,
175                          "intf-event", VlmEvent,
176                          p_instance->libvlc_vlm.p_event_manager );
177         p_instance->libvlc_vlm.pf_release = libvlc_vlm_release_internal;
178     }
179
180     return VLC_SUCCESS;
181 }
182
183 void libvlc_vlm_release( libvlc_instance_t *p_instance,
184                          libvlc_exception_t *p_exception)
185 {
186     VLC_UNUSED(p_exception);
187     libvlc_vlm_release_internal( p_instance );
188 }
189
190 #define VLM_RET(p,ret) do {                                     \
191     if( libvlc_vlm_init( p_instance, p_exception ) ) return ret;\
192     (p) = p_instance->libvlc_vlm.p_vlm;                                    \
193   } while(0)
194 #define VLM(p) VLM_RET(p,)
195
196 static vlm_media_instance_t *
197 libvlc_vlm_get_media_instance( libvlc_instance_t *p_instance,
198                                const char *psz_name, int i_minstance_idx,
199                                libvlc_exception_t *p_exception )
200 {
201     vlm_t *p_vlm;
202     vlm_media_instance_t **pp_minstance;
203     vlm_media_instance_t *p_minstance;
204     int i_minstance;
205     int64_t id;
206
207     VLM_RET(p_vlm, NULL);
208
209     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
210         vlm_Control( p_vlm, VLM_GET_MEDIA_INSTANCES, id, &pp_minstance,
211                      &i_minstance ) )
212     {
213         libvlc_exception_raise( p_exception );
214         libvlc_printerr( "%s: media instances not found", psz_name );
215         return NULL;
216     }
217     p_minstance = NULL;
218     if( i_minstance_idx >= 0 && i_minstance_idx < i_minstance )
219     {
220         p_minstance = pp_minstance[i_minstance_idx];
221         TAB_REMOVE( i_minstance, pp_minstance, p_minstance );
222     }
223     while( i_minstance > 0 )
224         vlm_media_instance_Delete( pp_minstance[--i_minstance] );
225     TAB_CLEAN( i_minstance, pp_minstance );
226     return p_minstance;
227 }
228
229 /* local function to be used in libvlc_vlm_show_media only */
230 static char* recurse_answer( vlm_message_t *p_answer, const char* psz_delim,
231                              const int i_list ) {
232     char* psz_childdelim = NULL;
233     char* psz_nametag = NULL;
234     char* psz_response = strdup( "" );
235     int i_success = 0;
236     int i;
237     vlm_message_t *aw_child, **paw_child;
238
239     i_success = asprintf( &psz_childdelim, "%s\t", psz_delim);
240
241     /* starting with the children of root node */
242     if( i_success != -1 && p_answer->i_child )
243     {
244         paw_child = p_answer->child;
245         aw_child = *( paw_child );
246         /* Iterate over children */
247         for( i = 0; i < p_answer->i_child; i++ )
248         {
249             /* Spare comma if it is the last element */
250             char c_comma = ',';
251             if( i == (p_answer->i_child - 1) )
252                 c_comma = ' ';
253
254             /* Append name of child node, if not in a list */
255             if( !i_list )
256             {
257                 i_success = asprintf( &psz_response, "%s\"%s\": ",
258                               psz_response, aw_child->psz_name );
259                 if( i_success == -1 ) break;
260             }
261
262             /* If child node has children, */
263             if( aw_child->i_child )
264             {
265                 /* If the parent node is a list (hence the child node is
266                  * inside a list), create a property of its name as if it
267                  * had a name value node
268                  */
269                 if( i_list )
270                 {
271                     i_success = asprintf( &psz_nametag, "\"name\": \"%s\",%s",
272                                   aw_child->psz_name, psz_childdelim );
273                     if( i_success == -1 ) break;
274                 }
275                 else
276                 {
277                     psz_nametag = strdup( "" );
278                 }
279                 /* If the child is a list itself, format it accordingly and
280                  * recurse through the child's children, telling them that
281                  * they are inside a list.
282                  */
283                 if( strcmp( aw_child->psz_name, "media" ) == 0 ||
284                     strcmp( aw_child->psz_name, "inputs" ) == 0 ||
285                     strcmp( aw_child->psz_name, "options" ) == 0 )
286                 {
287                     i_success = asprintf( &psz_response, "%s[%s%s%s]%c%s",
288                                           psz_response, psz_childdelim,
289                                           recurse_answer( aw_child,
290                                                           psz_childdelim, 1 ),
291                                           psz_delim, c_comma, psz_delim );
292                     if( i_success == -1 ) break;
293                 }
294                 /* Not a list, so format the child as a JSON object and
295                  * recurse through the child's children
296                  */
297                 else
298                 {
299                     i_success = asprintf( &psz_response, "%s{%s%s%s%s}%c%s",
300                                           psz_response, psz_childdelim, psz_nametag,
301                                           recurse_answer( aw_child,
302                                                           psz_childdelim, 0 ),
303                                           psz_delim, c_comma, psz_delim );
304                     if( i_success == -1 ) break;
305                 }
306             }
307             /* Otherwise - when no children are present - the node is a
308              * value node. So print the value string
309              */
310             else
311             {
312                 /* If value is equivalent to NULL, print it as null */
313                 if( aw_child->psz_value == NULL
314                     || strcmp( aw_child->psz_value, "(null)" ) == 0 )
315                 {
316                     i_success = asprintf( &psz_response, "%snull%c%s",
317                                           psz_response, c_comma, psz_delim );
318                     if( i_success == -1 )
319                         break;
320                 }
321                 /* Otherwise print the value in quotation marks */
322                 else
323                 {
324                     i_success = asprintf( &psz_response, "%s\"%s\"%c%s",
325                                           psz_response, aw_child->psz_value,
326                                           c_comma, psz_delim );
327                     if( i_success == -1 ) break;
328                 }
329             }
330             /* getting next child */
331             paw_child++;
332             aw_child = *( paw_child );
333         }
334     }
335     free( psz_nametag );
336     free( psz_childdelim );
337     if( i_success == -1 )
338     {
339         free( psz_response );
340         psz_response = strdup( "" );
341     }
342     return psz_response;
343 }
344
345 const char* libvlc_vlm_show_media( libvlc_instance_t *p_instance,
346                                    const char *psz_name,
347                                    libvlc_exception_t *p_exception )
348 {
349     char *psz_message = NULL;
350     vlm_message_t *answer = NULL;
351     char *psz_response = NULL;
352     const char *psz_fmt = NULL;
353     const char *psz_delimiter = NULL;
354     int i_list;
355     vlm_t *p_vlm = NULL;
356
357     VLM_RET(p_vlm, NULL);
358
359     assert( psz_name );
360
361     if( asprintf( &psz_message, "show %s", psz_name ) == -1 )
362     {
363         libvlc_exception_raise( p_exception );
364         libvlc_printerr( "Not enough memory" );
365         return NULL;
366     }
367
368     vlm_ExecuteCommand( p_vlm, psz_message, &answer );
369     if( answer->psz_value )
370     {
371         libvlc_exception_raise( p_exception );
372         libvlc_printerr( "Unable to call show %s: %s",
373                          psz_name, answer->psz_value );
374     }
375     else if ( answer->child )
376     {   /* in case everything was requested  */
377         if ( strcmp( psz_name, "" ) == 0 )
378         {
379             psz_fmt = "{\n\t%s\n}\n";
380             psz_delimiter = "\n\t";
381             i_list = 0;
382         }
383         else
384         {
385             psz_fmt = "%s\n";
386             psz_delimiter = "\n";
387             i_list = 1;
388         }
389         if( asprintf( &psz_response, psz_fmt,
390                       recurse_answer( answer, psz_delimiter, i_list ) ) == -1 )
391         {
392             libvlc_exception_raise( p_exception );
393             libvlc_printerr( "Out of memory" );
394         }
395     }
396     free( psz_message );
397     return( psz_response );
398 }
399
400
401 void libvlc_vlm_add_broadcast( libvlc_instance_t *p_instance,
402                                const char *psz_name,
403                                const char *psz_input,
404                                const char *psz_output, int i_options,
405                                const char * const *ppsz_options,
406                                int b_enabled, int b_loop,
407                                libvlc_exception_t *p_exception )
408 {
409     vlm_t *p_vlm;
410     vlm_media_t m;
411     int n;
412
413     VLM(p_vlm);
414
415     vlm_media_Init( &m );
416     m.psz_name = strdup( psz_name );
417     m.b_enabled = b_enabled;
418     m.b_vod = false;
419     m.broadcast.b_loop = b_loop;
420     if( psz_input )
421         TAB_APPEND( m.i_input, m.ppsz_input, strdup(psz_input) );
422     if( psz_output )
423         m.psz_output = strdup( psz_output );
424     for( n = 0; n < i_options; n++ )
425         TAB_APPEND( m.i_option, m.ppsz_option, strdup(ppsz_options[n]) );
426
427     n = vlm_Control( p_vlm, VLM_ADD_MEDIA, &m, NULL );
428     vlm_media_Clean( &m );
429     if( n )
430     {
431         libvlc_exception_raise( p_exception );
432         libvlc_printerr( "Media %s creation failed", psz_name );
433     }
434 }
435
436 void libvlc_vlm_add_vod( libvlc_instance_t *p_instance, const char *psz_name,
437                          const char *psz_input, int i_options,
438                          const char * const *ppsz_options, int b_enabled,
439                          const char *psz_mux, libvlc_exception_t *p_exception )
440 {
441     vlm_t *p_vlm;
442     vlm_media_t m;
443     int n;
444
445     VLM(p_vlm);
446
447     vlm_media_Init( &m );
448     m.psz_name = strdup( psz_name );
449     m.b_enabled = b_enabled;
450     m.b_vod = true;
451     m.vod.psz_mux = psz_mux ? strdup( psz_mux ) : NULL;
452     if( psz_input )
453         TAB_APPEND( m.i_input, m.ppsz_input, strdup(psz_input) );
454     for( n = 0; n < i_options; n++ )
455         TAB_APPEND( m.i_option, m.ppsz_option, strdup(ppsz_options[n]) );
456
457     n = vlm_Control( p_vlm, VLM_ADD_MEDIA, &m, NULL );
458     vlm_media_Clean( &m );
459     if( n )
460     {
461         libvlc_exception_raise( p_exception );
462         libvlc_printerr( "Media %s creation failed", psz_name );
463     }
464 }
465
466 void libvlc_vlm_del_media( libvlc_instance_t *p_instance, const char *psz_name,
467                            libvlc_exception_t *p_exception )
468 {
469     vlm_t *p_vlm;
470     int64_t id;
471
472     VLM(p_vlm);
473
474     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
475         vlm_Control( p_vlm, VLM_DEL_MEDIA, id ) )
476     {
477         libvlc_exception_raise( p_exception );
478         libvlc_printerr( "Unable to delete %s", psz_name );
479     }
480 }
481
482 #define VLM_CHANGE(psz_error, code ) do {   \
483     vlm_media_t *p_media;   \
484     vlm_t *p_vlm;           \
485     int64_t id;             \
486     VLM(p_vlm);             \
487     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||    \
488         vlm_Control( p_vlm, VLM_GET_MEDIA, id, &p_media ) ) {       \
489         libvlc_exception_raise( p_exception );                      \
490         libvlc_printerr( psz_error, psz_name );                     \
491         return;             \
492     }                       \
493     if( !p_media ) goto error;                                      \
494                             \
495     code;                   \
496                             \
497     if( vlm_Control( p_vlm, VLM_CHANGE_MEDIA, p_media ) ) {         \
498         vlm_media_Delete( p_media );                                \
499         goto error;         \
500     }                       \
501     vlm_media_Delete( p_media );                                    \
502     return;                 \
503   error:                    \
504     libvlc_exception_raise( p_exception );                          \
505     libvlc_printerr( psz_error, psz_name );                         \
506   } while(0)
507
508 void libvlc_vlm_set_enabled( libvlc_instance_t *p_instance,
509                              const char *psz_name, int b_enabled,
510                              libvlc_exception_t *p_exception )
511 {
512 #define VLM_CHANGE_CODE { p_media->b_enabled = b_enabled; }
513     VLM_CHANGE( "Unable to delete %s", VLM_CHANGE_CODE );
514 #undef VLM_CHANGE_CODE
515 }
516
517 void libvlc_vlm_set_loop( libvlc_instance_t *p_instance, const char *psz_name,
518                           int b_loop, libvlc_exception_t *p_exception )
519 {
520 #define VLM_CHANGE_CODE { p_media->broadcast.b_loop = b_loop; }
521     VLM_CHANGE( "Unable to change %s loop property", VLM_CHANGE_CODE );
522 #undef VLM_CHANGE_CODE
523 }
524
525 void libvlc_vlm_set_mux( libvlc_instance_t *p_instance, const char *psz_name,
526                          const char *psz_mux, libvlc_exception_t *p_exception )
527 {
528 #define VLM_CHANGE_CODE { if( p_media->b_vod ) { \
529                             free( p_media->vod.psz_mux ); \
530                             p_media->vod.psz_mux = psz_mux \
531                                  ? strdup( psz_mux ) : NULL; \
532                           } }
533     VLM_CHANGE( "Unable to change %s mux property", VLM_CHANGE_CODE );
534 #undef VLM_CHANGE_CODE
535 }
536
537 void libvlc_vlm_set_output( libvlc_instance_t *p_instance,
538                             const char *psz_name, const char *psz_output,
539                             libvlc_exception_t *p_exception )
540 {
541 #define VLM_CHANGE_CODE { free( p_media->psz_output ); \
542                           p_media->psz_output = strdup( psz_output ); }
543     VLM_CHANGE( "Unable to change %s output property", VLM_CHANGE_CODE );
544 #undef VLM_CHANGE_CODE
545 }
546
547 void libvlc_vlm_set_input( libvlc_instance_t *p_instance,
548                            const char *psz_name, const char *psz_input,
549                            libvlc_exception_t *p_exception )
550 {
551 #define VLM_CHANGE_CODE { while( p_media->i_input > 0 ) \
552                             free( p_media->ppsz_input[--p_media->i_input] );\
553                           TAB_APPEND( p_media->i_input, p_media->ppsz_input, \
554                                       strdup(psz_input) ); }
555     VLM_CHANGE( "Unable to change %s input property", VLM_CHANGE_CODE );
556 #undef VLM_CHANGE_CODE
557 }
558
559 void libvlc_vlm_add_input( libvlc_instance_t *p_instance,
560                            const char *psz_name, const char *psz_input,
561                            libvlc_exception_t *p_exception )
562 {
563 #define VLM_CHANGE_CODE { TAB_APPEND( p_media->i_input, p_media->ppsz_input, \
564                           strdup(psz_input) ); }
565     VLM_CHANGE( "Unable to change %s input property", VLM_CHANGE_CODE );
566 #undef VLM_CHANGE_CODE
567 }
568
569 void libvlc_vlm_change_media( libvlc_instance_t *p_instance,
570                               const char *psz_name, const char *psz_input,
571                               const char *psz_output, int i_options,
572                               const char * const *ppsz_options, int b_enabled,
573                               int b_loop, libvlc_exception_t *p_exception )
574 {
575 #define VLM_CHANGE_CODE { int n;        \
576     p_media->b_enabled = b_enabled;     \
577     p_media->broadcast.b_loop = b_loop; \
578     while( p_media->i_input > 0 )       \
579         free( p_media->ppsz_input[--p_media->i_input] );    \
580     if( psz_input )                     \
581         TAB_APPEND( p_media->i_input, p_media->ppsz_input, strdup(psz_input) ); \
582     free( p_media->psz_output );        \
583     p_media->psz_output = psz_output ? strdup( psz_output ) : NULL; \
584     while( p_media->i_option > 0 )     \
585         free( p_media->ppsz_option[--p_media->i_option] );        \
586     for( n = 0; n < i_options; n++ )    \
587         TAB_APPEND( p_media->i_option, p_media->ppsz_option, \
588                     strdup(ppsz_options[n]) );   \
589   }
590     VLM_CHANGE( "Unable to change %s properties", VLM_CHANGE_CODE );
591 #undef VLM_CHANGE_CODE
592 }
593
594 void libvlc_vlm_play_media( libvlc_instance_t *p_instance,
595                             const char *psz_name,
596                             libvlc_exception_t *p_exception )
597 {
598     vlm_t *p_vlm;
599     int64_t id;
600
601     VLM(p_vlm);
602
603     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
604         vlm_Control( p_vlm, VLM_START_MEDIA_BROADCAST_INSTANCE, id, NULL, 0 ) )
605     {
606         libvlc_exception_raise( p_exception );
607         libvlc_printerr( "Unable to play %s", psz_name );
608     }
609 }
610
611 void libvlc_vlm_stop_media( libvlc_instance_t *p_instance,
612                             const char *psz_name,
613                             libvlc_exception_t *p_exception )
614 {
615     vlm_t *p_vlm;
616     int64_t id;
617
618     VLM(p_vlm);
619
620     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
621         vlm_Control( p_vlm, VLM_STOP_MEDIA_INSTANCE, id, NULL ) )
622     {
623         libvlc_exception_raise( p_exception );
624         libvlc_printerr( "Unable to stop %s", psz_name );
625     }
626 }
627
628 void libvlc_vlm_pause_media( libvlc_instance_t *p_instance,
629                              const char *psz_name,
630                              libvlc_exception_t *p_exception )
631 {
632     vlm_t *p_vlm;
633     int64_t id;
634
635     VLM(p_vlm);
636
637     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
638         vlm_Control( p_vlm, VLM_PAUSE_MEDIA_INSTANCE, id, NULL ) )
639     {
640         libvlc_exception_raise( p_exception );
641         libvlc_printerr( "Unable to pause %s", psz_name );
642     }
643 }
644
645 void libvlc_vlm_seek_media( libvlc_instance_t *p_instance,
646                             const char *psz_name, float f_percentage,
647                             libvlc_exception_t *p_exception )
648 {
649     vlm_t *p_vlm;
650     int64_t id;
651
652     VLM(p_vlm);
653
654     if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
655         vlm_Control( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, id, NULL,
656                      f_percentage ) )
657     {
658         libvlc_exception_raise( p_exception );
659         libvlc_printerr( "Unable to seek %s to %f%%", psz_name, f_percentage );
660     }
661 }
662
663 float libvlc_vlm_get_media_instance_position( libvlc_instance_t *p_instance,
664                                               const char *psz_name,
665                                               int i_instance,
666                                               libvlc_exception_t *p_exception )
667 {
668     vlm_media_instance_t *p_mi;
669     float result = -1.;
670
671     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
672                                           i_instance, p_exception );
673     if( p_mi )
674     {
675         result = p_mi->d_position;
676         vlm_media_instance_Delete( p_mi );
677     }
678     return result;
679 }
680
681 int libvlc_vlm_get_media_instance_time( libvlc_instance_t *p_instance,
682                                         const char *psz_name, int i_instance,
683                                         libvlc_exception_t *p_exception )
684 {
685     vlm_media_instance_t *p_mi;
686     int result = -1;
687
688     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
689                                         i_instance, p_exception );
690     if( p_mi )
691     {
692         result = p_mi->i_time;
693         vlm_media_instance_Delete( p_mi );
694     }
695     return result;
696 }
697
698 int libvlc_vlm_get_media_instance_length( libvlc_instance_t *p_instance,
699                                           const char *psz_name,
700                                           int i_instance,
701                                           libvlc_exception_t *p_exception )
702 {
703     vlm_media_instance_t *p_mi;
704     int result = -1;
705
706     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
707                                           i_instance, p_exception );
708     if( p_mi )
709     {
710         result = p_mi->i_length;
711         vlm_media_instance_Delete( p_mi );
712     }
713     return result;
714 }
715
716 int libvlc_vlm_get_media_instance_rate( libvlc_instance_t *p_instance,
717                                         const char *psz_name, int i_instance,
718                                         libvlc_exception_t *p_exception )
719 {
720     vlm_media_instance_t *p_mi;
721     int result = -1;
722
723     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
724                                           i_instance, p_exception );
725     if( p_mi )
726     {
727         result = p_mi->i_rate;
728         vlm_media_instance_Delete( p_mi );
729     }
730     return result;
731 }
732
733 int libvlc_vlm_get_media_instance_title( libvlc_instance_t *p_instance,
734                                          const char *psz_name, int i_instance,
735                                          libvlc_exception_t *p_exception )
736 {
737     vlm_media_instance_t *p_mi;
738
739     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
740                                           i_instance, p_exception );
741     if( p_mi )
742         vlm_media_instance_Delete( p_mi );
743     return p_mi ? 0 : -1;
744 }
745
746 int libvlc_vlm_get_media_instance_chapter( libvlc_instance_t *p_instance,
747                                            const char *psz_name,
748                                            int i_instance,
749                                            libvlc_exception_t *p_exception )
750 {
751     vlm_media_instance_t *p_mi;
752
753     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
754                                           i_instance, p_exception );
755     if( p_mi )
756         vlm_media_instance_Delete( p_mi );
757     return p_mi ? 0 : -1;
758 }
759
760 int libvlc_vlm_get_media_instance_seekable( libvlc_instance_t *p_instance,
761                                             const char *psz_name,
762                                             int i_instance,
763                                             libvlc_exception_t *p_exception )
764 {
765     vlm_media_instance_t *p_mi;
766
767     p_mi = libvlc_vlm_get_media_instance( p_instance, psz_name,
768                                           i_instance, p_exception );
769     if( p_mi )
770         vlm_media_instance_Delete( p_mi );
771     return p_mi ? 0 : -1;
772 }
773
774 libvlc_event_manager_t * libvlc_vlm_get_event_manager( libvlc_instance_t *p_instance,
775                                                        libvlc_exception_t *p_exception )
776 {
777     vlm_t *p_vlm;
778     VLM_RET( p_vlm, NULL);
779     return p_instance->libvlc_vlm.p_event_manager;
780 }