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 $
7 * Authors: Clément Stenac <zorglub@videolan.org>
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.
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.
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 *****************************************************************************/
24 #include "libvlc_internal.h"
25 #include <vlc/libvlc.h>
27 #include <vlc_input.h>
30 static void InitVLM( libvlc_instance_t *p_instance )
33 if( p_instance->p_vlm ) return;
34 p_instance->p_vlm = vlm_New( p_instance->p_libvlc_int );
36 p_instance->p_vlm = NULL;
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)
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; } }
52 #define GET_MEDIA { p_media = vlm_MediaSearch( p_instance->p_vlm, psz_name );\
55 libvlc_exception_raise( p_exception, \
56 "Media %s does not exist", \
57 psz_name ); return; } }
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 )
68 p_media = vlm_MediaNew( p_instance->p_vlm, psz_name, BROADCAST_TYPE );
71 libvlc_exception_raise( p_exception, "Media %s creation failed",
75 libvlc_vlm_change_media( p_instance, psz_name, psz_input, psz_output,
76 i_options, ppsz_options, b_enabled, b_loop,
81 void libvlc_vlm_del_media( libvlc_instance_t *p_instance, char *psz_name,
82 libvlc_exception_t *p_exception )
85 vlm_message_t *answer;
88 asprintf( &psz_message, "del %s", psz_name );
89 vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
90 if( answer->psz_value )
92 libvlc_exception_raise( p_exception, "Unable to delete %s",
99 void libvlc_vlm_set_enabled( libvlc_instance_t *p_instance, char *psz_name,
100 int b_enabled, libvlc_exception_t *p_exception )
102 vlm_media_t *p_media;
106 if( b_enabled != 0 ) b_enabled = 1;
107 p_media->b_enabled = b_enabled;
111 void libvlc_vlm_set_loop( libvlc_instance_t *p_instance, char *psz_name,
112 int b_loop, libvlc_exception_t *p_exception )
114 vlm_media_t *p_media;
118 if( b_loop != 0 ) b_loop = 1;
119 p_media->b_loop = b_loop;
123 void libvlc_vlm_set_output( libvlc_instance_t *p_instance, char *psz_name,
124 char *psz_output, libvlc_exception_t *p_exception )
126 vlm_media_t *p_media;
132 vlc_mutex_lock( &p_instance->p_vlm->lock );
133 i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "output", psz_output );
136 libvlc_exception_raise( p_exception, "Unable to set output" );
137 vlc_mutex_unlock( &p_instance->p_vlm->lock );
140 vlc_mutex_unlock( &p_instance->p_vlm->lock );
144 void libvlc_vlm_set_input( libvlc_instance_t *p_instance, char *psz_name,
145 char *psz_input, libvlc_exception_t *p_exception )
147 vlm_media_t *p_media;
151 vlc_mutex_lock( &p_instance->p_vlm->lock );
154 i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "inputdel", "all" );
157 libvlc_exception_raise( p_exception, "Unable to change input" );
158 vlc_mutex_unlock( &p_instance->p_vlm->lock );
161 i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "input", psz_input );
164 libvlc_exception_raise( p_exception, "Unable to change input" );
165 vlc_mutex_unlock( &p_instance->p_vlm->lock );
168 vlc_mutex_unlock( &p_instance->p_vlm->lock );
172 void libvlc_vlm_add_input( libvlc_instance_t *p_instance, char *psz_name,
173 char *psz_input, libvlc_exception_t *p_exception )
175 vlm_media_t *p_media;
179 vlc_mutex_lock( &p_instance->p_vlm->lock );
182 i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "input", psz_input );
185 libvlc_exception_raise( p_exception, "Unable to change input" );
186 vlc_mutex_unlock( &p_instance->p_vlm->lock );
190 vlc_mutex_unlock( &p_instance->p_vlm->lock );
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 )
200 vlm_media_t *p_media;
204 vlc_mutex_lock( &p_instance->p_vlm->lock );
206 if( b_enabled != 0 ) b_enabled = 1;
207 if( b_loop != 0 ) b_loop = 1;
209 i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "output", psz_output );
212 libvlc_exception_raise( p_exception, "Unable to set output" );
213 vlc_mutex_unlock( &p_instance->p_vlm->lock );
216 p_media->b_enabled = b_enabled;
217 p_media->b_loop = b_loop;
219 i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "output", psz_output );
222 libvlc_exception_raise( p_exception, "Unable to set output" );
223 vlc_mutex_unlock( &p_instance->p_vlm->lock );
226 i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "inputdel", "all" );
229 libvlc_exception_raise( p_exception, "Unable to change input" );
230 vlc_mutex_unlock( &p_instance->p_vlm->lock );
233 i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "input", psz_input );
236 libvlc_exception_raise( p_exception, "Unable to change input" );
237 vlc_mutex_unlock( &p_instance->p_vlm->lock );
241 vlc_mutex_unlock( &p_instance->p_vlm->lock );
245 void libvlc_vlm_play_media( libvlc_instance_t *p_instance, char *psz_name,
246 libvlc_exception_t *p_exception )
250 vlm_message_t *answer;
253 asprintf( &psz_message, "control %s play", psz_name );
254 vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
255 if( answer->psz_value )
257 libvlc_exception_raise( p_exception, "Unable to play %s",
264 void libvlc_vlm_stop_media( libvlc_instance_t *p_instance, char *psz_name,
265 libvlc_exception_t *p_exception )
269 vlm_message_t *answer;
272 asprintf( &psz_message, "control %s stop", psz_name );
273 vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
274 if( answer->psz_value )
276 libvlc_exception_raise( p_exception, "Unable to stop %s",
283 void libvlc_vlm_pause_media( libvlc_instance_t *p_instance, char *psz_name,
284 libvlc_exception_t *p_exception )
288 vlm_message_t *answer;
291 asprintf( &psz_message, "control %s pause", psz_name );
292 vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
293 if( answer->psz_value )
295 libvlc_exception_raise( p_exception, "Unable to pause %s",
302 void libvlc_vlm_seek_media( libvlc_instance_t *p_instance, char *psz_name,
303 float f_percentage, libvlc_exception_t *p_exception )
307 vlm_message_t *answer;
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 )
314 libvlc_exception_raise( p_exception, "Unable to seek %s to %f",
315 psz_name, f_percentage );
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 ) \
327 vlm_media_instance_t *p_media_instance; \
329 vlm_media_t *p_media; \
330 p_media = vlm_MediaSearch( p_instance->p_vlm, psz_name ); \
331 if ( p_media == NULL ) \
333 libvlc_exception_raise( p_exception, "Unable to find media %s", \
338 if ( i_instance < p_media->i_instance ) \
340 p_media_instance = p_media->instance[ i_instance ]; \
341 return var_Get ## getType( p_media_instance->p_input, #attr );\
345 libvlc_exception_raise( p_exception, "Media index %i out of range",\
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 ) \
357 vlm_message_t *answer; \
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);
371 #undef LIBVLC_VLM_GET_MEDIA_ATTRIBUTE
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="";
379 vlm_message_t *aw_child, **paw_child;
381 asprintf( &psz_childprefix, "%s%s.", psz_prefix, p_answer->psz_name );
383 if ( p_answer->i_child )
385 paw_child = p_answer->child;
386 aw_child = *( paw_child );
387 for( i = 0; i < p_answer->i_child; i++ )
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 )
396 asprintf(&response_tmp, "%s%s", psz_response,
397 recurse_answer(psz_childprefix, aw_child));
398 free( psz_response );
399 psz_response = response_tmp;
402 aw_child = *( paw_child );
405 free( psz_childprefix );
409 char* libvlc_vlm_show_media( libvlc_instance_t *p_instance, char *psz_name,
410 libvlc_exception_t *p_exception )
413 vlm_message_t *answer;
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 )
423 libvlc_exception_raise( p_exception, "Unable to call show %s: %s",
424 psz_name, answer->psz_value );
430 psz_response = recurse_answer( "", answer );
434 return(psz_response );
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 )
445 libvlc_exception_raise( p_exception, "Media %s creation failed", psz_name );
448 void libvlc_vlm_del_media( libvlc_instance_t *p_instance, char *psz_name,
449 libvlc_exception_t *p_exception )
451 libvlc_exception_raise( p_exception, "Unable to delete %s", psz_name );
454 void libvlc_vlm_set_enabled( libvlc_instance_t *p_instance, char *psz_name,
455 int b_enabled, libvlc_exception_t *p_exception )
457 libvlc_exception_raise( p_exception, "Unable to enable %s", psz_name );
460 void libvlc_vlm_set_loop( libvlc_instance_t *p_instance, char *psz_name,
461 int b_loop, libvlc_exception_t *p_exception )
463 libvlc_exception_raise( p_exception, "Unable change %s loop property", psz_name );
466 void libvlc_vlm_set_output( libvlc_instance_t *p_instance, char *psz_name,
467 char *psz_output, libvlc_exception_t *p_exception )
469 libvlc_exception_raise( p_exception, "Unable change %s output property", psz_name );
472 void libvlc_vlm_set_input( libvlc_instance_t *p_instance, char *psz_name,
473 char *psz_input, libvlc_exception_t *p_exception )
475 libvlc_exception_raise( p_exception, "Unable change %s input property", psz_name );
478 void libvlc_vlm_add_input( libvlc_instance_t *p_instance, char *psz_name,
479 char *psz_input, libvlc_exception_t *p_exception )
481 libvlc_exception_raise( p_exception, "Unable change %s input property", psz_name );
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 )
490 libvlc_exception_raise( p_exception, "Unable change %s properties", psz_name );
493 void libvlc_vlm_play_media( libvlc_instance_t *p_instance, char *psz_name,
494 libvlc_exception_t *p_exception )
497 libvlc_exception_raise( p_exception, "Unable to play %s", psz_name );
500 void libvlc_vlm_stop_media( libvlc_instance_t *p_instance, char *psz_name,
501 libvlc_exception_t *p_exception )
504 libvlc_exception_raise( p_exception, "Unable to stop %s", psz_name );
507 void libvlc_vlm_pause_media( libvlc_instance_t *p_instance, char *psz_name,
508 libvlc_exception_t *p_exception )
511 libvlc_exception_raise( p_exception, "Unable to pause %s", psz_name );
514 void libvlc_vlm_seek_media( libvlc_instance_t *p_instance, char *psz_name,
515 float f_percentage, libvlc_exception_t *p_exception )
518 libvlc_exception_raise( p_exception, "Unable to seek %s to %f", psz_name, f_percentage );
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 ) \
525 libvlc_exception_raise( p_exception, "Unable to get %s "#attr "attribute" ); \
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);
537 #undef LIBVLC_VLM_GET_MEDIA_ATTRIBUTE
539 char* libvlc_vlm_show_media( libvlc_instance_t *p_instance, char *psz_name,
540 libvlc_exception_t *p_exception )
542 libvlc_exception_raise( p_exception, "Unable to call show %s", psz_name );