]> git.sesse.net Git - vlc/blob - include/vlc_vlm.h
Fix potential memleak.
[vlc] / include / vlc_vlm.h
1 /*****************************************************************************
2  * vlc_vlm.h: VLM core structures
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Simon Latapie <garf@videolan.org>
8  *          Laurent Aimar <fenrir@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifndef _VLC_VLM_H
26 #define _VLC_VLM_H 1
27
28 #include <vlc_input.h>
29
30 /* VLM media */
31 typedef struct
32 {
33     int64_t     id;
34     bool  b_enabled;
35
36     /* */
37     char *psz_name;
38
39     /* */
40     int  i_input;
41     char **ppsz_input;
42
43     int  i_option;
44     char **ppsz_option;
45
46     char *psz_output;
47
48     /* */
49     bool b_vod;
50     struct
51     {
52         bool b_loop;
53     } broadcast;
54     struct
55     {
56         char *psz_mux;
57     } vod;
58
59 } vlm_media_t;
60
61 /* VLM media instance */
62 typedef struct
63 {
64     char *psz_name;
65
66     int64_t     i_time;
67     int64_t     i_length;
68     double      d_position;
69     bool  b_paused;
70     int         i_rate;     // normal is INPUT_RATE_DEFAULT
71 } vlm_media_instance_t;
72
73 #if 0
74 typedef struct
75 {
76
77 } vlm_schedule_t
78 #endif
79
80 /* VLM control query */
81 enum vlm_query_e
82 {
83     /* --- Media control */
84     /* Get all medias */
85     VLM_GET_MEDIAS,                     /* arg1=vlm_media_t ***, int *pi_media      */
86     /* Delete all medias */
87     VLM_CLEAR_MEDIAS,                   /* no arg */
88
89     /* Add a new media */
90     VLM_ADD_MEDIA,                      /* arg1=vlm_media_t* arg2=int64_t *p_id         res=can fail */
91     /* Delete an existing media */
92     VLM_DEL_MEDIA,                      /* arg1=int64_t id */
93     /* Change properties of an existing media (all fields but id and b_vod) */
94     VLM_CHANGE_MEDIA,                   /* arg1=vlm_media_t*                            res=can fail */
95     /* Get 1 media by it's ID */
96     VLM_GET_MEDIA,                      /* arg1=int64_t id arg2=vlm_media_t **  */
97     /* Get media ID from its name */
98     VLM_GET_MEDIA_ID,                   /* arg1=const char *psz_name arg2=int64_t*  */
99
100     /* Media instance control XXX VOD control are for internal use only */
101     /* Get all media instances */
102     VLM_GET_MEDIA_INSTANCES,            /* arg1=int64_t id arg2=vlm_media_instance_t *** arg3=int *pi_instance */
103     /* Delete all media instances */
104     VLM_CLEAR_MEDIA_INSTANCES,          /* arg1=int64_t id */
105     /* Control broadcast instance */
106     VLM_START_MEDIA_BROADCAST_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name, int i_input_index  res=can fail */
107     /* Control VOD instance */
108     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 */
109     /* Stop an instance */
110     VLM_STOP_MEDIA_INSTANCE,            /* arg1=int64_t id, arg2=const char *psz_instance_name      res=can fail */
111     /* Pause an instance */
112     VLM_PAUSE_MEDIA_INSTANCE,           /* arg1=int64_t id, arg2=const char *psz_instance_name      res=can fail */
113     /* Get instance position time (in microsecond) */
114     VLM_GET_MEDIA_INSTANCE_TIME,        /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t *   */
115     /* Set instance position time (in microsecond) */
116     VLM_SET_MEDIA_INSTANCE_TIME,        /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t     */
117     /* Get instance position ([0.0 .. 1.0]) */
118     VLM_GET_MEDIA_INSTANCE_POSITION,    /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double *   */
119     /* Set instance position ([0.0 .. 1.0]) */
120     VLM_SET_MEDIA_INSTANCE_POSITION,    /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double     */
121
122     /* Schedule control */
123     VLM_CLEAR_SCHEDULES,                /* no arg */
124     /* TODO: missing schedule control */
125
126     /* */
127 };
128
129
130 /* VLM specific - structures and functions */
131
132 /* ok, here is the structure of a vlm_message:
133    The parent node is ( name_of_the_command , NULL ), or
134    ( name_of_the_command , message_error ) on error.
135    If a node has children, it should not have a value (=NULL).*/
136 struct vlm_message_t
137 {
138     char *psz_name;
139     char *psz_value;
140
141     int           i_child;
142     vlm_message_t **child;
143 };
144
145
146 #ifdef __cpluplus
147 extern "C" {
148 #endif
149
150 #define vlm_New( a ) __vlm_New( VLC_OBJECT(a) )
151 VLC_EXPORT( vlm_t *, __vlm_New, ( vlc_object_t * ) );
152 VLC_EXPORT( void,      vlm_Delete, ( vlm_t * ) );
153 VLC_EXPORT( int,       vlm_ExecuteCommand, ( vlm_t *, const char *, vlm_message_t ** ) );
154 VLC_EXPORT( int,       vlm_Control, ( vlm_t *p_vlm, int i_query, ... ) );
155
156 VLC_EXPORT( vlm_message_t *, vlm_MessageNew, ( const char *, const char *, ... ) LIBVLC_FORMAT( 2, 3 ) );
157 VLC_EXPORT( vlm_message_t *, vlm_MessageAdd, ( vlm_message_t *, vlm_message_t * ) );
158 VLC_EXPORT( void,            vlm_MessageDelete, ( vlm_message_t * ) );
159
160 /* media helpers */
161 static inline void vlm_media_Init( vlm_media_t *p_media )
162 {
163     memset( p_media, 0, sizeof(vlm_media_t) );
164     p_media->id = 0;    // invalid id
165     p_media->psz_name = NULL;
166     TAB_INIT( p_media->i_input, p_media->ppsz_input );
167     TAB_INIT( p_media->i_option, p_media->ppsz_option );
168     p_media->psz_output = NULL;
169     p_media->b_vod = false;
170
171     p_media->vod.psz_mux = NULL;
172     p_media->broadcast.b_loop = false;
173 }
174
175 static inline void vlm_media_Copy( vlm_media_t *p_dst, vlm_media_t *p_src )
176 {
177     int i;
178
179     memset( p_dst, 0, sizeof(vlm_media_t) );
180     p_dst->id = p_src->id;
181     p_dst->b_enabled = p_src->b_enabled;
182     if( p_src->psz_name )
183         p_dst->psz_name = strdup( p_src->psz_name );
184
185     for( i = 0; i < p_src->i_input; i++ )
186         TAB_APPEND_CPP( char, p_dst->i_input, p_dst->ppsz_input, strdup(p_src->ppsz_input[i]) );
187     for( i = 0; i < p_src->i_option; i++ )
188         TAB_APPEND_CPP( char, p_dst->i_option, p_dst->ppsz_option, strdup(p_src->ppsz_option[i]) );
189
190     if( p_src->psz_output )
191         p_dst->psz_output = strdup( p_src->psz_output );
192
193     p_dst->b_vod = p_src->b_vod;
194     if( p_src->b_vod )
195     {
196         if( p_src->vod.psz_mux )
197             p_dst->vod.psz_mux = strdup( p_src->vod.psz_mux );
198     }
199     else
200     {
201         p_dst->broadcast.b_loop = p_src->broadcast.b_loop;
202     }
203 }
204 static inline void vlm_media_Clean( vlm_media_t *p_media )
205 {
206     int i;
207     free( p_media->psz_name );
208
209     for( i = 0; i < p_media->i_input; i++ )
210         free( p_media->ppsz_input[i]) ;
211     TAB_CLEAN(p_media->i_input, p_media->ppsz_input );
212
213     for( i = 0; i < p_media->i_option; i++ )
214         free( p_media->ppsz_option[i]) ;
215     TAB_CLEAN(p_media->i_option, p_media->ppsz_option );
216
217     free( p_media->psz_output );
218     if( p_media->b_vod )
219         free( p_media->vod.psz_mux );
220 }
221 static inline vlm_media_t *vlm_media_New(void)
222 {
223     vlm_media_t *p_media = (vlm_media_t *)malloc( sizeof(vlm_media_t) );
224     if( p_media )
225         vlm_media_Init( p_media );
226     return p_media;
227 }
228 static inline void vlm_media_Delete( vlm_media_t *p_media )
229 {
230     vlm_media_Clean( p_media );
231     free( p_media );
232 }
233 static inline vlm_media_t *vlm_media_Duplicate( vlm_media_t *p_src )
234 {
235     vlm_media_t *p_dst = vlm_media_New();
236     if( p_dst )
237         vlm_media_Copy( p_dst, p_src );
238     return p_dst;
239 }
240
241 /* media instance helpers */
242 static inline void vlm_media_instance_Init( vlm_media_instance_t *p_instance )
243 {
244     memset( p_instance, 0, sizeof(vlm_media_instance_t) );
245     p_instance->psz_name = NULL;
246     p_instance->i_time = 0;
247     p_instance->i_length = 0;
248     p_instance->d_position = 0.0;
249     p_instance->b_paused = false;
250     p_instance->i_rate = INPUT_RATE_DEFAULT;
251 }
252 static inline void vlm_media_instance_Clean( vlm_media_instance_t *p_instance )
253 {
254     free( p_instance->psz_name );
255 }
256 static inline vlm_media_instance_t *vlm_media_instance_New(void)
257 {
258     vlm_media_instance_t *p_instance = (vlm_media_instance_t *) malloc( sizeof(vlm_media_instance_t) );
259     if( p_instance )
260         vlm_media_instance_Init( p_instance );
261     return p_instance;
262 }
263 static inline void vlm_media_instance_Delete( vlm_media_instance_t *p_instance )
264 {
265     vlm_media_instance_Clean( p_instance );
266     free( p_instance );
267 }
268
269 #ifdef __cpluplus
270 }
271 #endif
272
273 #endif