]> git.sesse.net Git - vlc/blob - src/control/vlm.c
Disable control vlm.
[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: playlist.c 14265 2006-02-12 17:31:39Z zorglub $
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 "libvlc_internal.h"
25 #include <vlc/libvlc.h>
26 #include <vlc_es.h>
27 #include <vlc_input.h>
28
29 #if 0
30 static void InitVLM( libvlc_instance_t *p_instance )
31 {
32 #ifdef ENABLE_VLM
33     if( p_instance->p_vlm ) return;
34     p_instance->p_vlm = vlm_New( p_instance->p_libvlc_int );
35 #else
36     p_instance->p_vlm = NULL;
37 #endif
38 }
39
40 /* XXX this code has to be rewritten, disable it for now */
41 #define vlm_MediaNew( a, b, c) (NULL)
42 #define vlm_MediaDelete(a,b,c)
43 #define vlm_MediaSetup(a,b,c,d) (-1)
44 #define vlm_MediaControl(a,b,c,d,e) (-1)
45 #define vlm_MediaSearch(a,b) (NULL)
46
47 #define CHECK_VLM { if( !p_instance->p_vlm ) InitVLM( p_instance ); \
48                     if( !p_instance->p_vlm ) {\
49                   libvlc_exception_raise( p_exception, \
50                   "Unable to create VLM. It might be disabled." ); return; } }
51
52 #define GET_MEDIA { p_media = vlm_MediaSearch( p_instance->p_vlm, psz_name );\
53                    if( !p_media ) \
54                    { \
55                         libvlc_exception_raise( p_exception, \
56                                                 "Media %s does not exist", \
57                                                 psz_name ); return; } }
58
59 void libvlc_vlm_add_broadcast( libvlc_instance_t *p_instance, char *psz_name,
60                                char *psz_input, char *psz_output,
61                                int i_options, char **ppsz_options,
62                                int b_enabled, int b_loop,
63                                libvlc_exception_t *p_exception )
64 {
65     vlm_media_t *p_media;
66     CHECK_VLM;
67
68     p_media = vlm_MediaNew( p_instance->p_vlm, psz_name, BROADCAST_TYPE );
69     if( !p_media )
70     {
71         libvlc_exception_raise( p_exception, "Media %s creation failed",
72                                 psz_name );
73         return;
74     }
75     libvlc_vlm_change_media( p_instance, psz_name, psz_input, psz_output,
76                              i_options, ppsz_options, b_enabled, b_loop,
77                              p_exception );
78
79 }
80
81 void libvlc_vlm_del_media( libvlc_instance_t *p_instance, char *psz_name,
82                            libvlc_exception_t *p_exception )
83 {
84     char *psz_message;
85     vlm_message_t *answer;
86     CHECK_VLM;
87 #ifdef ENABLE_VLM
88     asprintf( &psz_message, "del %s", psz_name );
89     vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
90     if( answer->psz_value )
91     {
92         libvlc_exception_raise( p_exception, "Unable to delete %s",
93                                 psz_name );
94     }
95     free( psz_message);
96 #endif
97 }
98
99 void libvlc_vlm_set_enabled( libvlc_instance_t *p_instance, char *psz_name,
100                              int b_enabled, libvlc_exception_t *p_exception )
101 {
102     vlm_media_t *p_media;
103     CHECK_VLM;
104 #ifdef ENABLE_VLM
105     GET_MEDIA;
106     if( b_enabled != 0 ) b_enabled = 1;
107     p_media->b_enabled = b_enabled;
108 #endif
109 }
110
111 void libvlc_vlm_set_loop( libvlc_instance_t *p_instance, char *psz_name,
112                           int b_loop, libvlc_exception_t *p_exception )
113 {
114     vlm_media_t *p_media;
115     CHECK_VLM;
116 #ifdef ENABLE_VLM
117     GET_MEDIA;
118     if( b_loop != 0 ) b_loop = 1;
119     p_media->b_loop = b_loop;
120 #endif
121 }
122
123 void libvlc_vlm_set_output( libvlc_instance_t *p_instance, char *psz_name,
124                             char *psz_output,  libvlc_exception_t *p_exception )
125 {
126     vlm_media_t *p_media;
127     int i_ret;
128     CHECK_VLM;
129 #ifdef ENABLE_VLM
130     GET_MEDIA;
131
132     vlc_mutex_lock( &p_instance->p_vlm->lock );
133     i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "output", psz_output );
134     if( i_ret )
135     {
136         libvlc_exception_raise( p_exception, "Unable to set output" );
137         vlc_mutex_unlock( &p_instance->p_vlm->lock );
138         return;
139     }
140     vlc_mutex_unlock( &p_instance->p_vlm->lock );
141 #endif
142 }
143
144 void libvlc_vlm_set_input( libvlc_instance_t *p_instance, char *psz_name,
145                            char *psz_input,  libvlc_exception_t *p_exception )
146 {
147     vlm_media_t *p_media;
148     int i_ret;
149     CHECK_VLM;
150 #ifdef ENABLE_VLM
151     vlc_mutex_lock( &p_instance->p_vlm->lock );
152     GET_MEDIA;
153
154     i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "inputdel", "all" );
155     if( i_ret )
156     {
157         libvlc_exception_raise( p_exception, "Unable to change input" );
158         vlc_mutex_unlock( &p_instance->p_vlm->lock );
159         return;
160     }
161     i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "input", psz_input );
162     if( i_ret )
163     {
164         libvlc_exception_raise( p_exception, "Unable to change input" );
165         vlc_mutex_unlock( &p_instance->p_vlm->lock );
166         return;
167     }
168     vlc_mutex_unlock( &p_instance->p_vlm->lock );
169 #endif
170 }
171
172 void libvlc_vlm_add_input( libvlc_instance_t *p_instance, char *psz_name,
173                            char *psz_input,  libvlc_exception_t *p_exception )
174 {
175     vlm_media_t *p_media;
176     int i_ret;
177     CHECK_VLM;
178 #ifdef ENABLE_VLM
179     vlc_mutex_lock( &p_instance->p_vlm->lock );
180     GET_MEDIA;
181
182     i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "input", psz_input );
183     if( i_ret )
184     {
185         libvlc_exception_raise( p_exception, "Unable to change input" );
186         vlc_mutex_unlock( &p_instance->p_vlm->lock );
187         return;
188     }
189
190     vlc_mutex_unlock( &p_instance->p_vlm->lock );
191 #endif
192 }
193
194
195 void libvlc_vlm_change_media( libvlc_instance_t *p_instance, char *psz_name,
196                               char *psz_input, char *psz_output, int i_options,
197                               char **ppsz_options, int b_enabled, int b_loop,
198                               libvlc_exception_t *p_exception )
199 {
200     vlm_media_t *p_media;
201     int i_ret;
202     CHECK_VLM;
203 #ifdef ENABLE_VLM
204     vlc_mutex_lock( &p_instance->p_vlm->lock );
205     GET_MEDIA;
206     if( b_enabled != 0 ) b_enabled = 1;
207     if( b_loop != 0 ) b_loop = 1;
208
209     i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "output", psz_output );
210     if( i_ret )
211     {
212         libvlc_exception_raise( p_exception, "Unable to set output" );
213         vlc_mutex_unlock( &p_instance->p_vlm->lock );
214         return;
215     }
216     p_media->b_enabled = b_enabled;
217     p_media->b_loop = b_loop;
218
219     i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "output", psz_output );
220     if( i_ret )
221     {
222         libvlc_exception_raise( p_exception, "Unable to set output" );
223         vlc_mutex_unlock( &p_instance->p_vlm->lock );
224         return;
225     }
226     i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "inputdel", "all" );
227     if( i_ret )
228     {
229         libvlc_exception_raise( p_exception, "Unable to change input" );
230         vlc_mutex_unlock( &p_instance->p_vlm->lock );
231         return;
232     }
233     i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "input", psz_input );
234     if( i_ret )
235     {
236         libvlc_exception_raise( p_exception, "Unable to change input" );
237         vlc_mutex_unlock( &p_instance->p_vlm->lock );
238         return;
239     }
240
241     vlc_mutex_unlock( &p_instance->p_vlm->lock );
242 #endif
243 }
244
245 void libvlc_vlm_play_media( libvlc_instance_t *p_instance, char *psz_name,
246                             libvlc_exception_t *p_exception )
247     
248 {
249     char *psz_message;
250     vlm_message_t *answer;
251     CHECK_VLM;
252 #ifdef ENABLE_VLM
253     asprintf( &psz_message, "control %s play", psz_name );
254     vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
255     if( answer->psz_value )
256     {
257         libvlc_exception_raise( p_exception, "Unable to play %s",
258                                 psz_name );
259     }
260     free( psz_message);
261 #endif
262 }
263
264 void libvlc_vlm_stop_media( libvlc_instance_t *p_instance, char *psz_name,
265                             libvlc_exception_t *p_exception )
266     
267 {
268     char *psz_message;
269     vlm_message_t *answer;
270     CHECK_VLM;
271 #ifdef ENABLE_VLM
272     asprintf( &psz_message, "control %s stop", psz_name );
273     vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
274     if( answer->psz_value )
275     {
276         libvlc_exception_raise( p_exception, "Unable to stop %s",
277                                 psz_name );
278     }
279     free( psz_message);
280 #endif
281 }
282
283 void libvlc_vlm_pause_media( libvlc_instance_t *p_instance, char *psz_name,
284                             libvlc_exception_t *p_exception )
285     
286 {
287     char *psz_message;
288     vlm_message_t *answer;
289     CHECK_VLM;
290 #ifdef ENABLE_VLM
291     asprintf( &psz_message, "control %s pause", psz_name );
292     vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
293     if( answer->psz_value )
294     {
295         libvlc_exception_raise( p_exception, "Unable to pause %s",
296                                 psz_name );
297     }
298     free( psz_message );
299 #endif
300 }
301
302 void libvlc_vlm_seek_media( libvlc_instance_t *p_instance, char *psz_name,
303                             float f_percentage, libvlc_exception_t *p_exception )
304     
305 {
306     char *psz_message;
307     vlm_message_t *answer;
308     CHECK_VLM;
309 #ifdef ENABLE_VLM
310     asprintf( &psz_message, "control %s seek %f", psz_name, f_percentage );
311     vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
312     if( answer->psz_value )
313     {
314         libvlc_exception_raise( p_exception, "Unable to seek %s to %f",
315                                 psz_name, f_percentage );
316     }
317     free( psz_message );
318 #endif
319 }
320
321 #ifdef ENABLE_VLM && 0
322 #define LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( attr, returnType, getType, default)\
323 returnType libvlc_vlm_get_media_## attr( libvlc_instance_t *p_instance, \
324                         char *psz_name, int i_instance, \
325                         libvlc_exception_t *p_exception ) \
326 { \
327     vlm_media_instance_t *p_media_instance; \
328     CHECK_VLM; \
329     vlm_media_t *p_media; \
330     p_media = vlm_MediaSearch( p_instance->p_vlm, psz_name ); \
331     if ( p_media == NULL ) \
332     { \
333         libvlc_exception_raise( p_exception, "Unable to find media %s", \
334                                 psz_name); \
335     } \
336     else \
337     { \
338         if ( i_instance < p_media->i_instance ) \
339         { \
340             p_media_instance = p_media->instance[ i_instance ]; \
341             return var_Get ## getType( p_media_instance->p_input, #attr );\
342         } \
343         else \
344         { \
345             libvlc_exception_raise( p_exception, "Media index %i out of range",\
346                                     i_instance); \
347         } \
348     } \
349     return default; \
350 }
351 #else
352 #define LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( attr, returnType, getType, default)\
353 returnType libvlc_vlm_get_media_## attr( libvlc_instance_t *p_instance, \
354                         char *psz_name, int i_instance, libvlc_exception_t *p_exception ) \
355 { \
356     char *psz_message; \
357     vlm_message_t *answer; \
358     CHECK_VLM; \
359     return default; \
360 }
361 #endif
362
363 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( position, float, Float, -1);
364 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( time, int, Integer, -1);
365 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( length, int, Integer, -1);
366 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( rate, int, Integer, -1);
367 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( title, int, Integer, 0);
368 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( chapter, int, Integer, 0);
369 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( seekable, int, Bool, 0);
370
371 #undef LIBVLC_VLM_GET_MEDIA_ATTRIBUTE
372
373 /* local function to be used in libvlc_vlm_show_media only */
374 static char* recurse_answer( char* psz_prefix, vlm_message_t *p_answer ) {
375     char* psz_childprefix;
376     char* psz_response="";
377     char* response_tmp;
378     int i;
379     vlm_message_t *aw_child, **paw_child;
380
381     asprintf( &psz_childprefix, "%s%s.", psz_prefix, p_answer->psz_name );
382
383     if ( p_answer->i_child )
384     {
385         paw_child = p_answer->child;
386         aw_child = *( paw_child );
387         for( i = 0; i < p_answer->i_child; i++ )
388         {
389             asprintf( &response_tmp, "%s%s%s:%s\n",
390                       psz_response, psz_prefix, aw_child->psz_name,
391                       aw_child->psz_value );
392             free( psz_response );
393             psz_response = response_tmp;
394             if ( aw_child->i_child )
395             {
396                 asprintf(&response_tmp, "%s%s", psz_response,
397                          recurse_answer(psz_childprefix, aw_child));
398                 free( psz_response );
399                 psz_response = response_tmp;
400             }
401             paw_child++;
402             aw_child = *( paw_child );
403         }
404     }
405     free( psz_childprefix );
406     return psz_response;
407 }
408
409 char* libvlc_vlm_show_media( libvlc_instance_t *p_instance, char *psz_name,
410                              libvlc_exception_t *p_exception )
411 {
412     char *psz_message;
413     vlm_message_t *answer;
414     char *psz_response;
415
416     CHECK_VLM;
417 #ifdef ENABLE_VLM
418     asprintf( &psz_message, "show %s", psz_name );
419     asprintf( &psz_response, "", psz_name );
420     vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
421     if( answer->psz_value )
422     {
423         libvlc_exception_raise( p_exception, "Unable to call show %s: %s",
424                                 psz_name, answer->psz_value );
425     }
426     else
427     {
428         if ( answer->child )
429         {
430             psz_response = recurse_answer( "", answer );
431         }
432     }
433     free( psz_message );
434     return(psz_response );
435 #endif
436     return NULL;
437 }
438 #else
439 void libvlc_vlm_add_broadcast( libvlc_instance_t *p_instance, char *psz_name,
440                                char *psz_input, char *psz_output,
441                                int i_options, char **ppsz_options,
442                                int b_enabled, int b_loop,
443                                libvlc_exception_t *p_exception )
444 {
445     libvlc_exception_raise( p_exception, "Media %s creation failed", psz_name );
446 }
447
448 void libvlc_vlm_del_media( libvlc_instance_t *p_instance, char *psz_name,
449                            libvlc_exception_t *p_exception )
450 {
451     libvlc_exception_raise( p_exception, "Unable to delete %s", psz_name );
452 }
453
454 void libvlc_vlm_set_enabled( libvlc_instance_t *p_instance, char *psz_name,
455                              int b_enabled, libvlc_exception_t *p_exception )
456 {
457     libvlc_exception_raise( p_exception, "Unable to enable %s", psz_name );
458 }
459
460 void libvlc_vlm_set_loop( libvlc_instance_t *p_instance, char *psz_name,
461                           int b_loop, libvlc_exception_t *p_exception )
462 {
463     libvlc_exception_raise( p_exception, "Unable change %s loop property", psz_name );
464 }
465
466 void libvlc_vlm_set_output( libvlc_instance_t *p_instance, char *psz_name,
467                             char *psz_output,  libvlc_exception_t *p_exception )
468 {
469     libvlc_exception_raise( p_exception, "Unable change %s output property", psz_name );
470 }
471
472 void libvlc_vlm_set_input( libvlc_instance_t *p_instance, char *psz_name,
473                            char *psz_input,  libvlc_exception_t *p_exception )
474 {
475     libvlc_exception_raise( p_exception, "Unable change %s input property", psz_name );
476 }
477
478 void libvlc_vlm_add_input( libvlc_instance_t *p_instance, char *psz_name,
479                            char *psz_input,  libvlc_exception_t *p_exception )
480 {
481     libvlc_exception_raise( p_exception, "Unable change %s input property", psz_name );
482 }
483
484
485 void libvlc_vlm_change_media( libvlc_instance_t *p_instance, char *psz_name,
486                               char *psz_input, char *psz_output, int i_options,
487                               char **ppsz_options, int b_enabled, int b_loop,
488                               libvlc_exception_t *p_exception )
489 {
490     libvlc_exception_raise( p_exception, "Unable change %s properties", psz_name );
491 }
492
493 void libvlc_vlm_play_media( libvlc_instance_t *p_instance, char *psz_name,
494                             libvlc_exception_t *p_exception )
495     
496 {
497     libvlc_exception_raise( p_exception, "Unable to play %s", psz_name );
498 }
499
500 void libvlc_vlm_stop_media( libvlc_instance_t *p_instance, char *psz_name,
501                             libvlc_exception_t *p_exception )
502     
503 {
504     libvlc_exception_raise( p_exception, "Unable to stop %s", psz_name );
505 }
506
507 void libvlc_vlm_pause_media( libvlc_instance_t *p_instance, char *psz_name,
508                             libvlc_exception_t *p_exception )
509     
510 {
511     libvlc_exception_raise( p_exception, "Unable to pause %s", psz_name );
512 }
513
514 void libvlc_vlm_seek_media( libvlc_instance_t *p_instance, char *psz_name,
515                             float f_percentage, libvlc_exception_t *p_exception )
516     
517 {
518     libvlc_exception_raise( p_exception, "Unable to seek %s to %f", psz_name, f_percentage );
519 }
520
521 #define LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( attr, returnType, getType, ret)\
522 returnType libvlc_vlm_get_media_## attr( libvlc_instance_t *p_instance, \
523                         char *psz_name, int i_instance, libvlc_exception_t *p_exception ) \
524 { \
525     libvlc_exception_raise( p_exception, "Unable to get %s "#attr "attribute" ); \
526     return ret; \
527 }
528
529 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( position, float, Float, -1);
530 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( time, int, Integer, -1);
531 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( length, int, Integer, -1);
532 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( rate, int, Integer, -1);
533 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( title, int, Integer, 0);
534 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( chapter, int, Integer, 0);
535 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( seekable, int, Bool, 0);
536
537 #undef LIBVLC_VLM_GET_MEDIA_ATTRIBUTE
538
539 char* libvlc_vlm_show_media( libvlc_instance_t *p_instance, char *psz_name,
540                              libvlc_exception_t *p_exception )
541 {
542     libvlc_exception_raise( p_exception, "Unable to call show %s", psz_name );
543     return NULL;
544 }
545 #endif