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