Contrib: fix libvorbis CVEs: 2008-1419, 2008-1420, 2008-1423.
[vlc.git] / include / vlc_vlm.h
blob9bbb4a57cd45b0302b49b0ebd11b288c520249af
1 /*****************************************************************************
2 * vlc_vlm.h: VLM core structures
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 the VideoLAN team
5 * $Id$
7 * Authors: Simon Latapie <garf@videolan.org>
8 * Laurent Aimar <fenrir@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #if !defined( __LIBVLC__ )
26 #error You are not libvlc or one of its plugins. You cannot include this file
27 #endif
29 #ifndef _VLC_VLM_H
30 #define _VLC_VLM_H 1
32 #include <vlc_input.h>
34 /* VLM media */
35 typedef struct
37 int64_t id;
38 bool b_enabled;
40 /* */
41 char *psz_name;
43 /* */
44 int i_input;
45 char **ppsz_input;
47 int i_option;
48 char **ppsz_option;
50 char *psz_output;
52 /* */
53 bool b_vod;
54 struct
56 bool b_loop;
57 } broadcast;
58 struct
60 char *psz_mux;
61 } vod;
63 } vlm_media_t;
65 /* VLM media instance */
66 typedef struct
68 char *psz_name;
70 int64_t i_time;
71 int64_t i_length;
72 double d_position;
73 bool b_paused;
74 int i_rate; // normal is INPUT_RATE_DEFAULT
75 } vlm_media_instance_t;
77 #if 0
78 typedef struct
81 } vlm_schedule_t
82 #endif
84 /* VLM control query */
85 enum vlm_query_e
87 /* --- Media control */
88 /* Get all medias */
89 VLM_GET_MEDIAS, /* arg1=vlm_media_t ***, int *pi_media */
90 /* Delete all medias */
91 VLM_CLEAR_MEDIAS, /* no arg */
93 /* Add a new media */
94 VLM_ADD_MEDIA, /* arg1=vlm_media_t* arg2=int64_t *p_id res=can fail */
95 /* Delete an existing media */
96 VLM_DEL_MEDIA, /* arg1=int64_t id */
97 /* Change properties of an existing media (all fields but id and b_vod) */
98 VLM_CHANGE_MEDIA, /* arg1=vlm_media_t* res=can fail */
99 /* Get 1 media by it's ID */
100 VLM_GET_MEDIA, /* arg1=int64_t id arg2=vlm_media_t ** */
101 /* Get media ID from its name */
102 VLM_GET_MEDIA_ID, /* arg1=const char *psz_name arg2=int64_t* */
104 /* Media instance control XXX VOD control are for internal use only */
105 /* Get all media instances */
106 VLM_GET_MEDIA_INSTANCES, /* arg1=int64_t id arg2=vlm_media_instance_t *** arg3=int *pi_instance */
107 /* Delete all media instances */
108 VLM_CLEAR_MEDIA_INSTANCES, /* arg1=int64_t id */
109 /* Control broadcast instance */
110 VLM_START_MEDIA_BROADCAST_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name, int i_input_index res=can fail */
111 /* Control VOD instance */
112 VLM_START_MEDIA_VOD_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name, int i_input_index char *psz_vod_output res=can fail */
113 /* Stop an instance */
114 VLM_STOP_MEDIA_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name res=can fail */
115 /* Pause an instance */
116 VLM_PAUSE_MEDIA_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name res=can fail */
117 /* Get instance position time (in microsecond) */
118 VLM_GET_MEDIA_INSTANCE_TIME, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t * */
119 /* Set instance position time (in microsecond) */
120 VLM_SET_MEDIA_INSTANCE_TIME, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t */
121 /* Get instance position ([0.0 .. 1.0]) */
122 VLM_GET_MEDIA_INSTANCE_POSITION, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double * */
123 /* Set instance position ([0.0 .. 1.0]) */
124 VLM_SET_MEDIA_INSTANCE_POSITION, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double */
126 /* Schedule control */
127 VLM_CLEAR_SCHEDULES, /* no arg */
128 /* TODO: missing schedule control */
130 /* */
134 /* VLM specific - structures and functions */
136 /* ok, here is the structure of a vlm_message:
137 The parent node is ( name_of_the_command , NULL ), or
138 ( name_of_the_command , message_error ) on error.
139 If a node has children, it should not have a value (=NULL).*/
140 struct vlm_message_t
142 char *psz_name;
143 char *psz_value;
145 int i_child;
146 vlm_message_t **child;
150 #ifdef __cpluplus
151 extern "C" {
152 #endif
154 #define vlm_New( a ) __vlm_New( VLC_OBJECT(a) )
155 VLC_EXPORT( vlm_t *, __vlm_New, ( vlc_object_t * ) );
156 VLC_EXPORT( void, vlm_Delete, ( vlm_t * ) );
157 VLC_EXPORT( int, vlm_ExecuteCommand, ( vlm_t *, const char *, vlm_message_t ** ) );
158 VLC_EXPORT( int, vlm_Control, ( vlm_t *p_vlm, int i_query, ... ) );
160 VLC_EXPORT( vlm_message_t *, vlm_MessageNew, ( const char *, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
161 VLC_EXPORT( vlm_message_t *, vlm_MessageAdd, ( vlm_message_t *, vlm_message_t * ) );
162 VLC_EXPORT( void, vlm_MessageDelete, ( vlm_message_t * ) );
164 /* media helpers */
165 static inline void vlm_media_Init( vlm_media_t *p_media )
167 memset( p_media, 0, sizeof(vlm_media_t) );
168 p_media->id = 0; // invalid id
169 p_media->psz_name = NULL;
170 TAB_INIT( p_media->i_input, p_media->ppsz_input );
171 TAB_INIT( p_media->i_option, p_media->ppsz_option );
172 p_media->psz_output = NULL;
173 p_media->b_vod = false;
175 p_media->vod.psz_mux = NULL;
176 p_media->broadcast.b_loop = false;
179 static inline void vlm_media_Copy( vlm_media_t *p_dst, vlm_media_t *p_src )
181 int i;
183 memset( p_dst, 0, sizeof(vlm_media_t) );
184 p_dst->id = p_src->id;
185 p_dst->b_enabled = p_src->b_enabled;
186 if( p_src->psz_name )
187 p_dst->psz_name = strdup( p_src->psz_name );
189 for( i = 0; i < p_src->i_input; i++ )
190 TAB_APPEND_CPP( char, p_dst->i_input, p_dst->ppsz_input, strdup(p_src->ppsz_input[i]) );
191 for( i = 0; i < p_src->i_option; i++ )
192 TAB_APPEND_CPP( char, p_dst->i_option, p_dst->ppsz_option, strdup(p_src->ppsz_option[i]) );
194 if( p_src->psz_output )
195 p_dst->psz_output = strdup( p_src->psz_output );
197 p_dst->b_vod = p_src->b_vod;
198 if( p_src->b_vod )
200 if( p_src->vod.psz_mux )
201 p_dst->vod.psz_mux = strdup( p_src->vod.psz_mux );
203 else
205 p_dst->broadcast.b_loop = p_src->broadcast.b_loop;
208 static inline void vlm_media_Clean( vlm_media_t *p_media )
210 int i;
211 free( p_media->psz_name );
213 for( i = 0; i < p_media->i_input; i++ )
214 free( p_media->ppsz_input[i]) ;
215 TAB_CLEAN(p_media->i_input, p_media->ppsz_input );
217 for( i = 0; i < p_media->i_option; i++ )
218 free( p_media->ppsz_option[i]) ;
219 TAB_CLEAN(p_media->i_option, p_media->ppsz_option );
221 free( p_media->psz_output );
222 if( p_media->b_vod )
223 free( p_media->vod.psz_mux );
225 static inline vlm_media_t *vlm_media_New(void)
227 vlm_media_t *p_media = (vlm_media_t *)malloc( sizeof(vlm_media_t) );
228 if( p_media )
229 vlm_media_Init( p_media );
230 return p_media;
232 static inline void vlm_media_Delete( vlm_media_t *p_media )
234 vlm_media_Clean( p_media );
235 free( p_media );
237 static inline vlm_media_t *vlm_media_Duplicate( vlm_media_t *p_src )
239 vlm_media_t *p_dst = vlm_media_New();
240 if( p_dst )
241 vlm_media_Copy( p_dst, p_src );
242 return p_dst;
245 /* media instance helpers */
246 static inline void vlm_media_instance_Init( vlm_media_instance_t *p_instance )
248 memset( p_instance, 0, sizeof(vlm_media_instance_t) );
249 p_instance->psz_name = NULL;
250 p_instance->i_time = 0;
251 p_instance->i_length = 0;
252 p_instance->d_position = 0.0;
253 p_instance->b_paused = false;
254 p_instance->i_rate = INPUT_RATE_DEFAULT;
256 static inline void vlm_media_instance_Clean( vlm_media_instance_t *p_instance )
258 free( p_instance->psz_name );
260 static inline vlm_media_instance_t *vlm_media_instance_New(void)
262 vlm_media_instance_t *p_instance = (vlm_media_instance_t *) malloc( sizeof(vlm_media_instance_t) );
263 if( p_instance )
264 vlm_media_instance_Init( p_instance );
265 return p_instance;
267 static inline void vlm_media_instance_Delete( vlm_media_instance_t *p_instance )
269 vlm_media_instance_Clean( p_instance );
270 free( p_instance );
273 #ifdef __cpluplus
275 #endif
277 #endif