]> git.sesse.net Git - vlc/blob - include/vlc_vlm.h
5795b529ed7e4eb01b4062dd8e46784ce4e7c1e1
[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 #include <vlc_input.h>
33
34 /* VLM media */
35 typedef struct
36 {
37     int64_t     id;
38     vlc_bool_t  b_enabled;
39
40     /* */
41     char *psz_name;
42
43     /* */
44     int  i_input;
45     char **ppsz_input;
46
47     int  i_option;
48     char **ppsz_option;
49
50     char *psz_output;
51
52     /* */
53     vlc_bool_t b_vod;
54     struct
55     {
56         vlc_bool_t b_loop;
57     } broadcast;
58     struct
59     {
60         char *psz_mux;
61     } vod;
62
63 } vlm_media_t;
64
65 /* VLM media instance */
66 typedef struct
67 {
68     char *psz_name;
69
70     int64_t     i_time;
71     int64_t     i_length;
72     double      d_position;
73     vlc_bool_t  b_paused;
74     int         i_rate;     // normal is INPUT_RATE_DEFAULT
75 } vlm_media_instance_t;
76
77 #if 0
78 typedef struct
79 {
80
81 } vlm_schedule_t
82 #endif
83
84 /* VLM control query */
85 enum vlm_query_e
86 {
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 */
92
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*  */
103
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     */
125
126     /* Schedule control */
127     VLM_CLEAR_SCHEDULES,                /* no arg */
128     /* TODO: missing schedule control */
129
130     /* */
131 };
132
133
134 /* VLM specific - structures and functions */
135
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
141 {
142     char *psz_name;
143     char *psz_value;
144
145     int           i_child;
146     vlm_message_t **child;
147 };
148
149
150 #ifdef __cpluplus
151 extern "C" {
152 #endif
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 = (vlm_media_t *)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 = (vlm_media_instance_t *) 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