]> git.sesse.net Git - vlc/blob - src/control/vlm.c
More VLM API stuff
[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
27 #include <vlc/vlc.h>
28 #include <vlc_input.h>
29 #include <vlc_vlm.h>
30
31 void InitVLM( libvlc_instance_t *p_instance )
32 {
33     if( p_instance->p_vlm ) return;
34     p_instance->p_vlm = vlm_New( p_instance->p_vlc );
35 }
36
37 #define CHECK_VLM { if( !p_instance->p_vlm ) InitVLM( p_instance ); \
38                     if( !p_instance->p_vlm ) {\
39                       libvlc_exception_raise( p_exception, \
40                                          "Unable to create VLM" ); return; } }
41
42 #define GET_MEDIA { p_media = vlm_MediaSearch( p_instance->p_vlm, psz_name );\
43                    if( !p_media ) \
44                    { \
45                         libvlc_exception_raise( p_exception, \
46                                                 "Media %s does not exist", \
47                                                 psz_name ); return; } }
48
49 void libvlc_vlm_add_broadcast( libvlc_instance_t *p_instance, char *psz_name,
50                                char *psz_input, char *psz_output,
51                                int i_options, char **ppsz_options,
52                                int b_enabled, int b_loop,
53                                libvlc_exception_t *p_exception )
54 {
55     vlm_media_t *p_media;
56     CHECK_VLM;
57
58     p_media = vlm_MediaNew( p_instance->p_vlm, psz_name, BROADCAST_TYPE );
59     if( !p_media )
60     {
61         libvlc_exception_raise( p_exception, "Media %s creation failed",
62                                 psz_name );
63         return;
64     }
65     libvlc_vlm_change_media( p_instance, psz_name, psz_input, psz_output,
66                              i_options, ppsz_options, b_enabled, b_loop,
67                              p_exception );
68
69 }
70
71 void libvlc_vlm_del_media( libvlc_instance_t *p_instance, char *psz_name,
72                            libvlc_exception_t *p_exception )
73 {
74     char *psz_message;
75     vlm_message_t *answer;
76     CHECK_VLM;
77     asprintf( &psz_message, "del %s", psz_name );
78     vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
79     if( answer->psz_value )
80     {
81         libvlc_exception_raise( p_exception, "Unable to delete %s",
82                                 psz_name );
83     }
84     free( psz_message);
85 }
86
87 void libvlc_vlm_set_enabled( libvlc_instance_t *p_instance, char *psz_name,
88                              int b_enabled, libvlc_exception_t *p_exception )
89 {
90     vlm_media_t *p_media;
91     CHECK_VLM;
92     GET_MEDIA;
93     if( b_enabled != 0 ) b_enabled = 1;
94     p_media->b_enabled = b_enabled;
95 }
96
97 void libvlc_vlm_set_loop( libvlc_instance_t *p_instance, char *psz_name,
98                           int b_loop, libvlc_exception_t *p_exception )
99 {
100     vlm_media_t *p_media;
101     CHECK_VLM;
102     GET_MEDIA;
103     if( b_loop != 0 ) b_loop = 1;
104     p_media->b_loop = b_loop;
105 }
106
107 void libvlc_vlm_set_output( libvlc_instance_t *p_instance, char *psz_name,
108                             char *psz_output,  libvlc_exception_t *p_exception )
109 {
110     vlm_media_t *p_media;
111     int i_ret;
112     CHECK_VLM;
113     GET_MEDIA;
114
115     vlc_mutex_lock( &p_instance->p_vlm->lock );
116     i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "output", psz_output );
117     if( i_ret )
118     { libvlc_exception_raise( p_exception, "Unable to set output" ); return;}
119     vlc_mutex_unlock( &p_instance->p_vlm->lock );
120 }
121
122 void libvlc_vlm_set_input( libvlc_instance_t *p_instance, char *psz_name,
123                            char *psz_input,  libvlc_exception_t *p_exception )
124 {
125     vlm_media_t *p_media;
126     int i_ret;
127     CHECK_VLM;
128     GET_MEDIA;
129
130     vlc_mutex_lock( &p_instance->p_vlm->lock );
131
132     vlm_MediaSetup( p_instance->p_vlm, p_media, "inputdel", "all" );
133     if( i_ret )
134     { libvlc_exception_raise( p_exception, "Unable to change input" ); return;}
135     vlm_MediaSetup( p_instance->p_vlm, p_media, "input", psz_input );
136     if( i_ret )
137     { libvlc_exception_raise( p_exception, "Unable to change input" ); return;}
138
139     vlc_mutex_unlock( &p_instance->p_vlm->lock );
140 }
141
142 void libvlc_vlm_add_input( libvlc_instance_t *p_instance, char *psz_name,
143                            char *psz_input,  libvlc_exception_t *p_exception )
144 {
145     vlm_media_t *p_media;
146     int i_ret;
147     CHECK_VLM;
148     GET_MEDIA;
149
150     vlc_mutex_lock( &p_instance->p_vlm->lock );
151
152     vlm_MediaSetup( p_instance->p_vlm, p_media, "input", psz_input );
153     if( i_ret )
154     { libvlc_exception_raise( p_exception, "Unable to change input" ); return;}
155
156     vlc_mutex_unlock( &p_instance->p_vlm->lock );
157 }
158
159
160
161
162 void libvlc_vlm_change_media( libvlc_instance_t *p_instance, char *psz_name,
163                               char *psz_input, char *psz_output, int i_options,
164                               char **ppsz_options, int b_enabled, int b_loop,
165                               libvlc_exception_t *p_exception )
166 {
167     vlm_media_t *p_media;
168     int i_ret;
169     CHECK_VLM;
170     GET_MEDIA;
171     if( b_enabled != 0 ) b_enabled = 1;
172     if( b_loop != 0 ) b_loop = 1;
173
174     vlc_mutex_lock( &p_instance->p_vlm->lock );
175     i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "output", psz_output );
176     if( i_ret ) libvlc_exception_raise( p_exception, "Unable to set output" );
177     p_media->b_enabled = b_enabled;
178     p_media->b_loop = b_loop;
179
180     i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "output", psz_output );
181     if( i_ret )
182     { libvlc_exception_raise( p_exception, "Unable to set output" ); return;}
183     vlm_MediaSetup( p_instance->p_vlm, p_media, "inputdel", "all" );
184     if( i_ret )
185     { libvlc_exception_raise( p_exception, "Unable to change input" ); return;}
186     vlm_MediaSetup( p_instance->p_vlm, p_media, "input", psz_input );
187     if( i_ret )
188     { libvlc_exception_raise( p_exception, "Unable to change input" ); return;}
189
190     vlc_mutex_unlock( &p_instance->p_vlm->lock );
191 }