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