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