audiotrack: avoid cast, use proper type
[vlc.git] / include / vlc_vlm.h
blobcb2ebb8760fa34fda18b460106589fed3db220c7
1 /*****************************************************************************
2 * vlc_vlm.h: VLM core structures
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VLC authors and VideoLAN
6 * Authors: Simon Latapie <garf@videolan.org>
7 * Laurent Aimar <fenrir@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef VLC_VLM_H
25 #define VLC_VLM_H 1
27 #include <vlc_input.h>
29 /**
30 * \defgroup server VLM
31 * \ingroup interface
32 * VLC stream manager
34 * VLM is the server core in vlc that allows streaming of multiple media streams
35 * at the same time. It provides broadcast, schedule and video on demand features
36 * for streaming using several streaming and network protocols.
37 * @{
38 * \file
39 * VLC stream manager interface
42 /** VLM media */
43 typedef struct
45 int64_t id; /*< numeric id for vlm_media_t item */
46 bool b_enabled; /*< vlm_media_t is enabled */
48 char *psz_name; /*< descriptive name of vlm_media_t item */
50 int i_input; /*< number of input options */
51 char **ppsz_input; /*< array of input options */
53 int i_option; /*< number of output options */
54 char **ppsz_option; /*< array of output options */
56 char *psz_output; /*< */
58 struct
60 bool b_loop; /*< this vlc_media_t broadcast item should loop */
61 } broadcast; /*< Broadcast specific information */
63 } vlm_media_t;
65 /** VLM media instance */
66 typedef struct
68 char *psz_name; /*< vlm media instance descriptive name */
70 int64_t i_time; /*< vlm media instance vlm media current time */
71 int64_t i_length; /*< vlm media instance vlm media item length */
72 double d_position; /*< vlm media instance position in stream */
73 bool b_paused; /*< vlm media instance is paused */
74 float f_rate; // normal is 1.0f
75 } vlm_media_instance_t;
77 #if 0
78 typedef struct
81 } vlm_schedule_t
82 #endif
84 /** VLM events
85 * You can catch vlm event by adding a callback on the variable "intf-event"
86 * of the VLM object.
87 * This variable is an address that will hold a vlm_event_t* value.
89 enum vlm_event_type_e
91 /* */
92 VLM_EVENT_MEDIA_ADDED = 0x100,
93 VLM_EVENT_MEDIA_REMOVED,
94 VLM_EVENT_MEDIA_CHANGED,
96 /* */
97 VLM_EVENT_MEDIA_INSTANCE_STARTED = 0x200,
98 VLM_EVENT_MEDIA_INSTANCE_STOPPED,
99 VLM_EVENT_MEDIA_INSTANCE_STATE,
102 typedef enum vlm_state_e
104 VLM_INIT_S = 0,
105 VLM_OPENING_S,
106 VLM_PLAYING_S,
107 VLM_PAUSE_S,
108 VLM_END_S,
109 VLM_ERROR_S,
110 } vlm_state_e;
112 typedef struct
114 int i_type; /* a vlm_event_type_e value */
115 int64_t id; /* Media ID */
116 const char *psz_name; /* Media name */
117 const char *psz_instance_name; /* Instance name or NULL */
118 vlm_state_e input_state; /* Input instance event type */
119 } vlm_event_t;
121 /** VLM control query */
122 enum vlm_query_e
124 /* --- Media control */
125 /* Get all medias */
126 VLM_GET_MEDIAS, /* arg1=vlm_media_t ***, int *pi_media */
127 /* Delete all medias */
128 VLM_CLEAR_MEDIAS, /* no arg */
130 /* Add a new media */
131 VLM_ADD_MEDIA, /* arg1=vlm_media_t* arg2=int64_t *p_id res=can fail */
132 /* Delete an existing media */
133 VLM_DEL_MEDIA, /* arg1=int64_t id */
134 /* Change properties of an existing media (all fields but id) */
135 VLM_CHANGE_MEDIA, /* arg1=vlm_media_t* res=can fail */
136 /* Get 1 media by it's ID */
137 VLM_GET_MEDIA, /* arg1=int64_t id arg2=vlm_media_t ** */
138 /* Get media ID from its name */
139 VLM_GET_MEDIA_ID, /* arg1=const char *psz_name arg2=int64_t* */
141 /* Media instance control */
142 /* Get all media instances */
143 VLM_GET_MEDIA_INSTANCES, /* arg1=int64_t id arg2=vlm_media_instance_t *** arg3=int *pi_instance */
144 /* Delete all media instances */
145 VLM_CLEAR_MEDIA_INSTANCES, /* arg1=int64_t id */
146 /* Control broadcast instance */
147 VLM_START_MEDIA_BROADCAST_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name, int i_input_index res=can fail */
148 /* Stop an instance */
149 VLM_STOP_MEDIA_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name res=can fail */
150 /* Pause an instance */
151 VLM_PAUSE_MEDIA_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name res=can fail */
152 /* Get instance position time (in microsecond) */
153 VLM_GET_MEDIA_INSTANCE_TIME, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t * */
154 /* Set instance position time (in microsecond) */
155 VLM_SET_MEDIA_INSTANCE_TIME, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t */
156 /* Get instance position ([0.0 .. 1.0]) */
157 VLM_GET_MEDIA_INSTANCE_POSITION, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double * */
158 /* Set instance position ([0.0 .. 1.0]) */
159 VLM_SET_MEDIA_INSTANCE_POSITION, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double */
161 /* Schedule control */
162 VLM_CLEAR_SCHEDULES, /* no arg */
163 /* TODO: missing schedule control */
165 /* */
169 /* VLM specific - structures and functions */
171 /* ok, here is the structure of a vlm_message:
172 The parent node is ( name_of_the_command , NULL ), or
173 ( name_of_the_command , message_error ) on error.
174 If a node has children, it should not have a value (=NULL).*/
175 struct vlm_message_t
177 char *psz_name; /*< message name */
178 char *psz_value; /*< message value */
180 int i_child; /*< number of child messages */
181 vlm_message_t **child; /*< array of vlm_message_t */
185 #ifdef __cplusplus
186 extern "C" {
187 #endif
189 VLC_API vlm_t * vlm_New( libvlc_int_t *, const char *path );
190 VLC_API void vlm_Delete( vlm_t * );
191 VLC_API int vlm_ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
192 VLC_API int vlm_Control( vlm_t *p_vlm, int i_query, ... );
194 VLC_API vlm_message_t * vlm_MessageSimpleNew( const char * );
195 VLC_API vlm_message_t * vlm_MessageNew( const char *, const char *, ... ) VLC_FORMAT( 2, 3 );
196 VLC_API vlm_message_t * vlm_MessageAdd( vlm_message_t *, vlm_message_t * );
197 VLC_API void vlm_MessageDelete( vlm_message_t * );
199 /* media helpers */
202 * Initialize a vlm_media_t instance
203 * \param p_media vlm_media_t instance to initialize
205 static inline void vlm_media_Init( vlm_media_t *p_media )
207 memset( p_media, 0, sizeof(vlm_media_t) );
208 p_media->id = 0; // invalid id
209 p_media->psz_name = NULL;
210 TAB_INIT( p_media->i_input, p_media->ppsz_input );
211 TAB_INIT( p_media->i_option, p_media->ppsz_option );
212 p_media->psz_output = NULL;
214 p_media->broadcast.b_loop = false;
218 * Copy a vlm_media_t instance into another vlm_media_t instance
219 * \param p_dst vlm_media_t instance to copy to
220 * \param p_src vlm_media_t instance to copy from
222 static inline void
223 #ifndef __cplusplus
224 vlm_media_Copy( vlm_media_t *restrict p_dst, const vlm_media_t *restrict p_src )
225 #else
226 vlm_media_Copy( vlm_media_t *p_dst, const vlm_media_t *p_src )
227 #endif
229 int i;
231 memset( p_dst, 0, sizeof(vlm_media_t) );
232 p_dst->id = p_src->id;
233 p_dst->b_enabled = p_src->b_enabled;
234 if( p_src->psz_name )
235 p_dst->psz_name = strdup( p_src->psz_name );
237 for( i = 0; i < p_src->i_input; i++ )
238 TAB_APPEND_CAST( (char**), p_dst->i_input, p_dst->ppsz_input, strdup(p_src->ppsz_input[i]) );
239 for( i = 0; i < p_src->i_option; i++ )
240 TAB_APPEND_CAST( (char**), p_dst->i_option, p_dst->ppsz_option, strdup(p_src->ppsz_option[i]) );
242 if( p_src->psz_output )
243 p_dst->psz_output = strdup( p_src->psz_output );
245 p_dst->broadcast.b_loop = p_src->broadcast.b_loop;
249 * Cleanup and release memory associated with this vlm_media_t instance.
250 * You still need to release p_media itself with vlm_media_Delete().
251 * \param p_media vlm_media_t to cleanup
253 static inline void vlm_media_Clean( vlm_media_t *p_media )
255 int i;
256 free( p_media->psz_name );
258 for( i = 0; i < p_media->i_input; i++ )
259 free( p_media->ppsz_input[i]);
260 TAB_CLEAN(p_media->i_input, p_media->ppsz_input );
262 for( i = 0; i < p_media->i_option; i++ )
263 free( p_media->ppsz_option[i]);
264 TAB_CLEAN(p_media->i_option, p_media->ppsz_option );
266 free( p_media->psz_output );
270 * Allocate a new vlm_media_t instance
271 * \return vlm_media_t instance
273 static inline vlm_media_t *vlm_media_New(void)
275 vlm_media_t *p_media = (vlm_media_t *)malloc( sizeof(vlm_media_t) );
276 if( p_media )
277 vlm_media_Init( p_media );
278 return p_media;
282 * Delete a vlm_media_t instance
283 * \param p_media vlm_media_t instance to delete
285 static inline void vlm_media_Delete( vlm_media_t *p_media )
287 vlm_media_Clean( p_media );
288 free( p_media );
292 * Copy a vlm_media_t instance
293 * \param p_src vlm_media_t instance to copy
294 * \return vlm_media_t duplicate of p_src
296 static inline vlm_media_t *vlm_media_Duplicate( vlm_media_t *p_src )
298 vlm_media_t *p_dst = vlm_media_New();
299 if( p_dst )
300 vlm_media_Copy( p_dst, p_src );
301 return p_dst;
304 /* media instance helpers */
306 * Initialize vlm_media_instance_t
307 * \param p_instance vlm_media_instance_t to initialize
309 static inline void vlm_media_instance_Init( vlm_media_instance_t *p_instance )
311 memset( p_instance, 0, sizeof(vlm_media_instance_t) );
312 p_instance->psz_name = NULL;
313 p_instance->i_time = 0;
314 p_instance->i_length = 0;
315 p_instance->d_position = 0.0;
316 p_instance->b_paused = false;
317 p_instance->f_rate = 1.0f;
321 * Cleanup vlm_media_instance_t
322 * \param p_instance vlm_media_instance_t to cleanup
324 static inline void vlm_media_instance_Clean( vlm_media_instance_t *p_instance )
326 free( p_instance->psz_name );
330 * Allocate a new vlm_media_instance_t
331 * \return a new vlm_media_instance_t
333 static inline vlm_media_instance_t *vlm_media_instance_New(void)
335 vlm_media_instance_t *p_instance = (vlm_media_instance_t *) malloc( sizeof(vlm_media_instance_t) );
336 if( p_instance )
337 vlm_media_instance_Init( p_instance );
338 return p_instance;
342 * Delete a vlm_media_instance_t
343 * \param p_instance vlm_media_instance_t to delete
345 static inline void vlm_media_instance_Delete( vlm_media_instance_t *p_instance )
347 vlm_media_instance_Clean( p_instance );
348 free( p_instance );
351 #ifdef __cplusplus
353 #endif
355 /**@}*/
357 #endif