playlist demuxer: remove tabs
[vlc.git] / include / vlc_vlm.h
blob1257b71a449174dfdabea2e52abfa8ac7241d67b
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 bool b_vod; /*< vlm_media_t is of type VOD */
59 struct
61 bool b_loop; /*< this vlc_media_t broadcast item should loop */
62 } broadcast; /*< Broadcast specific information */
63 struct
65 char *psz_mux; /*< name of muxer to use */
66 } vod; /*< VOD specific information */
68 } vlm_media_t;
70 /** VLM media instance */
71 typedef struct
73 char *psz_name; /*< vlm media instance descriptive name */
75 int64_t i_time; /*< vlm media instance vlm media current time */
76 int64_t i_length; /*< vlm media instance vlm media item length */
77 double d_position; /*< vlm media instance position in stream */
78 bool b_paused; /*< vlm media instance is paused */
79 float f_rate; // normal is 1.0f
80 } vlm_media_instance_t;
82 #if 0
83 typedef struct
86 } vlm_schedule_t
87 #endif
89 /** VLM events
90 * You can catch vlm event by adding a callback on the variable "intf-event"
91 * of the VLM object.
92 * This variable is an address that will hold a vlm_event_t* value.
94 enum vlm_event_type_e
96 /* */
97 VLM_EVENT_MEDIA_ADDED = 0x100,
98 VLM_EVENT_MEDIA_REMOVED,
99 VLM_EVENT_MEDIA_CHANGED,
101 /* */
102 VLM_EVENT_MEDIA_INSTANCE_STARTED = 0x200,
103 VLM_EVENT_MEDIA_INSTANCE_STOPPED,
104 VLM_EVENT_MEDIA_INSTANCE_STATE,
107 typedef struct
109 int i_type; /* a vlm_event_type_e value */
110 int64_t id; /* Media ID */
111 const char *psz_name; /* Media name */
112 const char *psz_instance_name; /* Instance name or NULL */
113 input_state_e input_state; /* Input instance event type */
114 } vlm_event_t;
116 /** VLM control query */
117 enum vlm_query_e
119 /* --- Media control */
120 /* Get all medias */
121 VLM_GET_MEDIAS, /* arg1=vlm_media_t ***, int *pi_media */
122 /* Delete all medias */
123 VLM_CLEAR_MEDIAS, /* no arg */
125 /* Add a new media */
126 VLM_ADD_MEDIA, /* arg1=vlm_media_t* arg2=int64_t *p_id res=can fail */
127 /* Delete an existing media */
128 VLM_DEL_MEDIA, /* arg1=int64_t id */
129 /* Change properties of an existing media (all fields but id and b_vod) */
130 VLM_CHANGE_MEDIA, /* arg1=vlm_media_t* res=can fail */
131 /* Get 1 media by it's ID */
132 VLM_GET_MEDIA, /* arg1=int64_t id arg2=vlm_media_t ** */
133 /* Get media ID from its name */
134 VLM_GET_MEDIA_ID, /* arg1=const char *psz_name arg2=int64_t* */
136 /* Media instance control XXX VOD control are for internal use only */
137 /* Get all media instances */
138 VLM_GET_MEDIA_INSTANCES, /* arg1=int64_t id arg2=vlm_media_instance_t *** arg3=int *pi_instance */
139 /* Delete all media instances */
140 VLM_CLEAR_MEDIA_INSTANCES, /* arg1=int64_t id */
141 /* Control broadcast instance */
142 VLM_START_MEDIA_BROADCAST_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name, int i_input_index res=can fail */
143 /* Control VOD instance */
144 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 */
145 /* Stop an instance */
146 VLM_STOP_MEDIA_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name res=can fail */
147 /* Pause an instance */
148 VLM_PAUSE_MEDIA_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name res=can fail */
149 /* Get instance position time (in microsecond) */
150 VLM_GET_MEDIA_INSTANCE_TIME, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t * */
151 /* Set instance position time (in microsecond) */
152 VLM_SET_MEDIA_INSTANCE_TIME, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t */
153 /* Get instance position ([0.0 .. 1.0]) */
154 VLM_GET_MEDIA_INSTANCE_POSITION, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double * */
155 /* Set instance position ([0.0 .. 1.0]) */
156 VLM_SET_MEDIA_INSTANCE_POSITION, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double */
158 /* Schedule control */
159 VLM_CLEAR_SCHEDULES, /* no arg */
160 /* TODO: missing schedule control */
162 /* */
166 /* VLM specific - structures and functions */
168 /* ok, here is the structure of a vlm_message:
169 The parent node is ( name_of_the_command , NULL ), or
170 ( name_of_the_command , message_error ) on error.
171 If a node has children, it should not have a value (=NULL).*/
172 struct vlm_message_t
174 char *psz_name; /*< message name */
175 char *psz_value; /*< message value */
177 int i_child; /*< number of child messages */
178 vlm_message_t **child; /*< array of vlm_message_t */
182 #ifdef __cplusplus
183 extern "C" {
184 #endif
186 VLC_API vlm_t * vlm_New( libvlc_int_t *, const char *path );
187 VLC_API void vlm_Delete( vlm_t * );
188 VLC_API int vlm_ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
189 VLC_API int vlm_Control( vlm_t *p_vlm, int i_query, ... );
191 VLC_API vlm_message_t * vlm_MessageSimpleNew( const char * );
192 VLC_API vlm_message_t * vlm_MessageNew( const char *, const char *, ... ) VLC_FORMAT( 2, 3 );
193 VLC_API vlm_message_t * vlm_MessageAdd( vlm_message_t *, vlm_message_t * );
194 VLC_API void vlm_MessageDelete( vlm_message_t * );
196 /* media helpers */
199 * Initialize a vlm_media_t instance
200 * \param p_media vlm_media_t instance to initialize
202 static inline void vlm_media_Init( vlm_media_t *p_media )
204 memset( p_media, 0, sizeof(vlm_media_t) );
205 p_media->id = 0; // invalid id
206 p_media->psz_name = NULL;
207 TAB_INIT( p_media->i_input, p_media->ppsz_input );
208 TAB_INIT( p_media->i_option, p_media->ppsz_option );
209 p_media->psz_output = NULL;
210 p_media->b_vod = false;
212 p_media->vod.psz_mux = NULL;
213 p_media->broadcast.b_loop = false;
217 * Copy a vlm_media_t instance into another vlm_media_t instance
218 * \param p_dst vlm_media_t instance to copy to
219 * \param p_src vlm_media_t instance to copy from
221 static inline void
222 #ifndef __cplusplus
223 vlm_media_Copy( vlm_media_t *restrict p_dst, const vlm_media_t *restrict p_src )
224 #else
225 vlm_media_Copy( vlm_media_t *p_dst, const vlm_media_t *p_src )
226 #endif
228 int i;
230 memset( p_dst, 0, sizeof(vlm_media_t) );
231 p_dst->id = p_src->id;
232 p_dst->b_enabled = p_src->b_enabled;
233 if( p_src->psz_name )
234 p_dst->psz_name = strdup( p_src->psz_name );
236 for( i = 0; i < p_src->i_input; i++ )
237 TAB_APPEND_CAST( (char**), p_dst->i_input, p_dst->ppsz_input, strdup(p_src->ppsz_input[i]) );
238 for( i = 0; i < p_src->i_option; i++ )
239 TAB_APPEND_CAST( (char**), p_dst->i_option, p_dst->ppsz_option, strdup(p_src->ppsz_option[i]) );
241 if( p_src->psz_output )
242 p_dst->psz_output = strdup( p_src->psz_output );
244 p_dst->b_vod = p_src->b_vod;
245 if( p_src->b_vod )
247 if( p_src->vod.psz_mux )
248 p_dst->vod.psz_mux = strdup( p_src->vod.psz_mux );
250 else
252 p_dst->broadcast.b_loop = p_src->broadcast.b_loop;
257 * Cleanup and release memory associated with this vlm_media_t instance.
258 * You still need to release p_media itself with vlm_media_Delete().
259 * \param p_media vlm_media_t to cleanup
261 static inline void vlm_media_Clean( vlm_media_t *p_media )
263 int i;
264 free( p_media->psz_name );
266 for( i = 0; i < p_media->i_input; i++ )
267 free( p_media->ppsz_input[i]);
268 TAB_CLEAN(p_media->i_input, p_media->ppsz_input );
270 for( i = 0; i < p_media->i_option; i++ )
271 free( p_media->ppsz_option[i]);
272 TAB_CLEAN(p_media->i_option, p_media->ppsz_option );
274 free( p_media->psz_output );
275 if( p_media->b_vod )
276 free( p_media->vod.psz_mux );
280 * Allocate a new vlm_media_t instance
281 * \return vlm_media_t instance
283 static inline vlm_media_t *vlm_media_New(void)
285 vlm_media_t *p_media = (vlm_media_t *)malloc( sizeof(vlm_media_t) );
286 if( p_media )
287 vlm_media_Init( p_media );
288 return p_media;
292 * Delete a vlm_media_t instance
293 * \param p_media vlm_media_t instance to delete
295 static inline void vlm_media_Delete( vlm_media_t *p_media )
297 vlm_media_Clean( p_media );
298 free( p_media );
302 * Copy a vlm_media_t instance
303 * \param p_src vlm_media_t instance to copy
304 * \return vlm_media_t duplicate of p_src
306 static inline vlm_media_t *vlm_media_Duplicate( vlm_media_t *p_src )
308 vlm_media_t *p_dst = vlm_media_New();
309 if( p_dst )
310 vlm_media_Copy( p_dst, p_src );
311 return p_dst;
314 /* media instance helpers */
316 * Initialize vlm_media_instance_t
317 * \param p_instance vlm_media_instance_t to initialize
319 static inline void vlm_media_instance_Init( vlm_media_instance_t *p_instance )
321 memset( p_instance, 0, sizeof(vlm_media_instance_t) );
322 p_instance->psz_name = NULL;
323 p_instance->i_time = 0;
324 p_instance->i_length = 0;
325 p_instance->d_position = 0.0;
326 p_instance->b_paused = false;
327 p_instance->f_rate = 1.0f;
331 * Cleanup vlm_media_instance_t
332 * \param p_instance vlm_media_instance_t to cleanup
334 static inline void vlm_media_instance_Clean( vlm_media_instance_t *p_instance )
336 free( p_instance->psz_name );
340 * Allocate a new vlm_media_instance_t
341 * \return a new vlm_media_instance_t
343 static inline vlm_media_instance_t *vlm_media_instance_New(void)
345 vlm_media_instance_t *p_instance = (vlm_media_instance_t *) malloc( sizeof(vlm_media_instance_t) );
346 if( p_instance )
347 vlm_media_instance_Init( p_instance );
348 return p_instance;
352 * Delete a vlm_media_instance_t
353 * \param p_instance vlm_media_instance_t to delete
355 static inline void vlm_media_instance_Delete( vlm_media_instance_t *p_instance )
357 vlm_media_instance_Clean( p_instance );
358 free( p_instance );
361 #ifdef __cplusplus
363 #endif
365 /**@}*/
367 #endif