VLC  4.0.0-dev
vlc_vlm.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vlc_vlm.h: VLM core structures
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VLC authors and VideoLAN
5  *
6  * Authors: Simon Latapie <garf@videolan.org>
7  * Laurent Aimar <fenrir@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23 
24 #ifndef VLC_VLM_H
25 #define VLC_VLM_H 1
26 
27 #include <vlc_input.h>
28 
29 /**
30  * \defgroup server VLM
31  * \ingroup interface
32  * VLC stream manager
33  *
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
40  */
41 
42 /** VLM media */
43 typedef struct
44 {
45  int64_t id; /*< numeric id for vlm_media_t item */
46  bool b_enabled; /*< vlm_media_t is enabled */
47 
48  char *psz_name; /*< descriptive name of vlm_media_t item */
49 
50  int i_input; /*< number of input options */
51  char **ppsz_input; /*< array of input options */
52 
53  int i_option; /*< number of output options */
54  char **ppsz_option; /*< array of output options */
55 
56  char *psz_output; /*< */
57 
58  bool b_vod; /*< vlm_media_t is of type VOD */
59  struct
60  {
61  bool b_loop; /*< this vlc_media_t broadcast item should loop */
62  } broadcast; /*< Broadcast specific information */
63  struct
64  {
65  char *psz_mux; /*< name of muxer to use */
66  } vod; /*< VOD specific information */
67 
68 } vlm_media_t;
69 
70 /** VLM media instance */
71 typedef struct
72 {
73  char *psz_name; /*< vlm media instance descriptive name */
74 
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
81 
82 #if 0
83 typedef struct
84 {
85 
86 } vlm_schedule_t
87 #endif
88 
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.
93  */
95 {
96  /* */
97  VLM_EVENT_MEDIA_ADDED = 0x100,
101  /* */
105 };
106 
107 typedef enum vlm_state_e
108 {
109  VLM_INIT_S = 0,
116 
117 typedef struct
118 {
119  int i_type; /* a vlm_event_type_e value */
120  int64_t id; /* Media ID */
121  const char *psz_name; /* Media name */
122  const char *psz_instance_name; /* Instance name or NULL */
123  vlm_state_e input_state; /* Input instance event type */
125 
126 /** VLM control query */
127 enum vlm_query_e
128 {
129  /* --- Media control */
130  /* Get all medias */
131  VLM_GET_MEDIAS, /* arg1=vlm_media_t ***, int *pi_media */
132  /* Delete all medias */
133  VLM_CLEAR_MEDIAS, /* no arg */
135  /* Add a new media */
136  VLM_ADD_MEDIA, /* arg1=vlm_media_t* arg2=int64_t *p_id res=can fail */
137  /* Delete an existing media */
138  VLM_DEL_MEDIA, /* arg1=int64_t id */
139  /* Change properties of an existing media (all fields but id and b_vod) */
140  VLM_CHANGE_MEDIA, /* arg1=vlm_media_t* res=can fail */
141  /* Get 1 media by it's ID */
142  VLM_GET_MEDIA, /* arg1=int64_t id arg2=vlm_media_t ** */
143  /* Get media ID from its name */
144  VLM_GET_MEDIA_ID, /* arg1=const char *psz_name arg2=int64_t* */
146  /* Media instance control XXX VOD control are for internal use only */
147  /* Get all media instances */
148  VLM_GET_MEDIA_INSTANCES, /* arg1=int64_t id arg2=vlm_media_instance_t *** arg3=int *pi_instance */
149  /* Delete all media instances */
150  VLM_CLEAR_MEDIA_INSTANCES, /* arg1=int64_t id */
151  /* Control broadcast instance */
152  VLM_START_MEDIA_BROADCAST_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name, int i_input_index res=can fail */
153  /* Control VOD instance */
154  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 */
155  /* Stop an instance */
156  VLM_STOP_MEDIA_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name res=can fail */
157  /* Pause an instance */
158  VLM_PAUSE_MEDIA_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name res=can fail */
159  /* Get instance position time (in microsecond) */
160  VLM_GET_MEDIA_INSTANCE_TIME, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t * */
161  /* Set instance position time (in microsecond) */
162  VLM_SET_MEDIA_INSTANCE_TIME, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t */
163  /* Get instance position ([0.0 .. 1.0]) */
164  VLM_GET_MEDIA_INSTANCE_POSITION, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double * */
165  /* Set instance position ([0.0 .. 1.0]) */
166  VLM_SET_MEDIA_INSTANCE_POSITION, /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double */
168  /* Schedule control */
169  VLM_CLEAR_SCHEDULES, /* no arg */
170  /* TODO: missing schedule control */
171 
172  /* */
173 };
174 
175 
176 /* VLM specific - structures and functions */
177 
178 /* ok, here is the structure of a vlm_message:
179  The parent node is ( name_of_the_command , NULL ), or
180  ( name_of_the_command , message_error ) on error.
181  If a node has children, it should not have a value (=NULL).*/
182 struct vlm_message_t
183 {
184  char *psz_name; /*< message name */
185  char *psz_value; /*< message value */
187  int i_child; /*< number of child messages */
188  vlm_message_t **child; /*< array of vlm_message_t */
189 };
190 
191 
192 #ifdef __cplusplus
193 extern "C" {
194 #endif
195 
196 VLC_API vlm_t * vlm_New( libvlc_int_t *, const char *path );
197 VLC_API void vlm_Delete( vlm_t * );
198 VLC_API int vlm_ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
199 VLC_API int vlm_Control( vlm_t *p_vlm, int i_query, ... );
200 
201 VLC_API vlm_message_t * vlm_MessageSimpleNew( const char * );
202 VLC_API vlm_message_t * vlm_MessageNew( const char *, const char *, ... ) VLC_FORMAT( 2, 3 );
205 
206 /* media helpers */
207 
208 /**
209  * Initialize a vlm_media_t instance
210  * \param p_media vlm_media_t instance to initialize
211  */
212 static inline void vlm_media_Init( vlm_media_t *p_media )
213 {
214  memset( p_media, 0, sizeof(vlm_media_t) );
215  p_media->id = 0; // invalid id
216  p_media->psz_name = NULL;
217  TAB_INIT( p_media->i_input, p_media->ppsz_input );
218  TAB_INIT( p_media->i_option, p_media->ppsz_option );
219  p_media->psz_output = NULL;
220  p_media->b_vod = false;
221 
222  p_media->vod.psz_mux = NULL;
223  p_media->broadcast.b_loop = false;
224 }
225 
226 /**
227  * Copy a vlm_media_t instance into another vlm_media_t instance
228  * \param p_dst vlm_media_t instance to copy to
229  * \param p_src vlm_media_t instance to copy from
230  */
231 static inline void
232 #ifndef __cplusplus
233 vlm_media_Copy( vlm_media_t *restrict p_dst, const vlm_media_t *restrict p_src )
234 #else
235 vlm_media_Copy( vlm_media_t *p_dst, const vlm_media_t *p_src )
236 #endif
237 {
238  int i;
239 
240  memset( p_dst, 0, sizeof(vlm_media_t) );
241  p_dst->id = p_src->id;
242  p_dst->b_enabled = p_src->b_enabled;
243  if( p_src->psz_name )
244  p_dst->psz_name = strdup( p_src->psz_name );
245 
246  for( i = 0; i < p_src->i_input; i++ )
247  TAB_APPEND_CAST( (char**), p_dst->i_input, p_dst->ppsz_input, strdup(p_src->ppsz_input[i]) );
248  for( i = 0; i < p_src->i_option; i++ )
249  TAB_APPEND_CAST( (char**), p_dst->i_option, p_dst->ppsz_option, strdup(p_src->ppsz_option[i]) );
250 
251  if( p_src->psz_output )
252  p_dst->psz_output = strdup( p_src->psz_output );
253 
254  p_dst->b_vod = p_src->b_vod;
255  if( p_src->b_vod )
256  {
257  if( p_src->vod.psz_mux )
258  p_dst->vod.psz_mux = strdup( p_src->vod.psz_mux );
259  }
260  else
261  {
262  p_dst->broadcast.b_loop = p_src->broadcast.b_loop;
263  }
264 }
265 
266 /**
267  * Cleanup and release memory associated with this vlm_media_t instance.
268  * You still need to release p_media itself with vlm_media_Delete().
269  * \param p_media vlm_media_t to cleanup
270  */
271 static inline void vlm_media_Clean( vlm_media_t *p_media )
272 {
273  int i;
274  free( p_media->psz_name );
275 
276  for( i = 0; i < p_media->i_input; i++ )
277  free( p_media->ppsz_input[i]);
278  TAB_CLEAN(p_media->i_input, p_media->ppsz_input );
279 
280  for( i = 0; i < p_media->i_option; i++ )
281  free( p_media->ppsz_option[i]);
282  TAB_CLEAN(p_media->i_option, p_media->ppsz_option );
283 
284  free( p_media->psz_output );
285  if( p_media->b_vod )
286  free( p_media->vod.psz_mux );
287 }
288 
289 /**
290  * Allocate a new vlm_media_t instance
291  * \return vlm_media_t instance
292  */
293 static inline vlm_media_t *vlm_media_New(void)
294 {
295  vlm_media_t *p_media = (vlm_media_t *)malloc( sizeof(vlm_media_t) );
296  if( p_media )
297  vlm_media_Init( p_media );
298  return p_media;
299 }
300 
301 /**
302  * Delete a vlm_media_t instance
303  * \param p_media vlm_media_t instance to delete
304  */
305 static inline void vlm_media_Delete( vlm_media_t *p_media )
306 {
307  vlm_media_Clean( p_media );
308  free( p_media );
309 }
310 
311 /**
312  * Copy a vlm_media_t instance
313  * \param p_src vlm_media_t instance to copy
314  * \return vlm_media_t duplicate of p_src
315  */
316 static inline vlm_media_t *vlm_media_Duplicate( vlm_media_t *p_src )
317 {
318  vlm_media_t *p_dst = vlm_media_New();
319  if( p_dst )
320  vlm_media_Copy( p_dst, p_src );
321  return p_dst;
322 }
323 
324 /* media instance helpers */
325 /**
326  * Initialize vlm_media_instance_t
327  * \param p_instance vlm_media_instance_t to initialize
328  */
329 static inline void vlm_media_instance_Init( vlm_media_instance_t *p_instance )
330 {
331  memset( p_instance, 0, sizeof(vlm_media_instance_t) );
332  p_instance->psz_name = NULL;
333  p_instance->i_time = 0;
334  p_instance->i_length = 0;
335  p_instance->d_position = 0.0;
336  p_instance->b_paused = false;
337  p_instance->f_rate = 1.0f;
338 }
339 
340 /**
341  * Cleanup vlm_media_instance_t
342  * \param p_instance vlm_media_instance_t to cleanup
343  */
344 static inline void vlm_media_instance_Clean( vlm_media_instance_t *p_instance )
345 {
346  free( p_instance->psz_name );
347 }
348 
349 /**
350  * Allocate a new vlm_media_instance_t
351  * \return a new vlm_media_instance_t
352  */
353 static inline vlm_media_instance_t *vlm_media_instance_New(void)
354 {
355  vlm_media_instance_t *p_instance = (vlm_media_instance_t *) malloc( sizeof(vlm_media_instance_t) );
356  if( p_instance )
357  vlm_media_instance_Init( p_instance );
358  return p_instance;
359 }
360 
361 /**
362  * Delete a vlm_media_instance_t
363  * \param p_instance vlm_media_instance_t to delete
364  */
365 static inline void vlm_media_instance_Delete( vlm_media_instance_t *p_instance )
366 {
367  vlm_media_instance_Clean( p_instance );
368  free( p_instance );
369 }
370 
371 #ifdef __cplusplus
372 }
373 #endif
374 
375 /**@}*/
376 
377 #endif
vlm_message_t ** child
Definition: vlc_vlm.h:189
static vlm_media_t * vlm_media_Duplicate(vlm_media_t *p_src)
Copy a vlm_media_t instance.
Definition: vlc_vlm.h:317
int i_child
Definition: vlc_vlm.h:188
Definition: vlc_vlm.h:132
bool b_loop
Definition: vlc_vlm.h:62
Definition: vlc_vlm.h:183
void vlm_MessageDelete(vlm_message_t *)
Definition: missing.c:230
char * strdup(const char *)
Definition: vlc_vlm.h:143
static void vlm_media_instance_Delete(vlm_media_instance_t *p_instance)
Delete a vlm_media_instance_t.
Definition: vlc_vlm.h:366
static void vlm_media_Copy(vlm_media_t *restrict p_dst, const vlm_media_t *restrict p_src)
Copy a vlm_media_t instance into another vlm_media_t instance.
Definition: vlc_vlm.h:234
Definition: vlc_vlm.h:155
bool b_vod
Definition: vlc_vlm.h:59
vlm_message_t * vlm_MessageAdd(vlm_message_t *, vlm_message_t *)
Definition: missing.c:223
static void vlm_media_instance_Clean(vlm_media_instance_t *p_instance)
Cleanup vlm_media_instance_t.
Definition: vlc_vlm.h:345
static void vlm_media_Clean(vlm_media_t *p_media)
Cleanup and release memory associated with this vlm_media_t instance.
Definition: vlc_vlm.h:272
char * psz_name
Definition: vlc_vlm.h:49
#define TAB_CLEAN(count, tab)
Definition: vlc_arrays.h:61
static vlm_media_t * vlm_media_New(void)
Allocate a new vlm_media_t instance.
Definition: vlc_vlm.h:294
Definition: vlc_objects.h:113
Definition: vlc_vlm.h:165
int i_option
Definition: vlc_vlm.h:54
vlm_event_type_e
VLM events You can catch vlm event by adding a callback on the variable "intf-event" of the VLM objec...
Definition: vlc_vlm.h:95
Definition: vlc_vlm.h:141
Definition: vlc_vlm.h:111
vlm_message_t * vlm_MessageNew(const char *, const char *,...)
Definition: missing.c:242
Definition: vlc_vlm.h:105
double d_position
Definition: vlc_vlm.h:78
vlm_message_t * vlm_MessageSimpleNew(const char *)
Definition: missing.c:236
char * psz_name
Definition: vlc_vlm.h:185
struct vlm_media_t::@262 vod
Definition: vlc_vlm.h:118
Definition: vlc_vlm.h:100
int i_input
Definition: vlc_vlm.h:51
Definition: vlc_vlm.h:170
Definition: vlc_vlm.h:115
int64_t id
Definition: vlc_vlm.h:46
int i_type
Definition: httpd.c:1237
char ** ppsz_input
Definition: vlc_vlm.h:52
int vlm_Control(vlm_t *p_vlm, int i_query,...)
Definition: vlm.c:1329
char ** ppsz_option
Definition: vlc_vlm.h:55
Definition: vlc_vlm.h:151
Definition: vlc_vlm.h:145
Definition: vlc_vlm.h:103
Definition: vlc_vlm.h:110
VLM media instance.
Definition: vlc_vlm.h:72
Definition: vlc_vlm.h:134
static void vlm_media_Init(vlm_media_t *p_media)
Initialize a vlm_media_t instance.
Definition: vlc_vlm.h:213
Definition: vlm_internal.h:83
int vlm_ExecuteCommand(vlm_t *, const char *, vlm_message_t **)
Definition: vlm.c:264
#define VLC_API
Definition: fourcc_gen.c:31
#define TAB_APPEND_CAST(cast, count, tab, p)
Definition: vlc_arrays.h:68
Definition: vlc_vlm.h:161
Definition: vlc_vlm.h:99
const char * psz_name
Definition: vlc_codecs.h:313
#define VLC_FORMAT(x, y)
String format function annotation.
Definition: vlc_common.h:141
struct vlm_media_t::@261 broadcast
vlm_query_e
VLM control query.
Definition: vlc_vlm.h:128
Definition: vlc_vlm.h:167
float f_rate
Definition: vlc_vlm.h:80
Definition: vlc_vlm.h:159
char * psz_mux
Definition: vlc_vlm.h:66
char * psz_value
Definition: vlc_vlm.h:186
static vlm_media_instance_t * vlm_media_instance_New(void)
Allocate a new vlm_media_instance_t.
Definition: vlc_vlm.h:354
Definition: vlc_vlm.h:137
char * psz_name
Definition: vlc_vlm.h:74
VLM media.
Definition: vlc_vlm.h:44
Definition: vlc_vlm.h:112
char * psz_output
Definition: vlc_vlm.h:57
vlm_t * vlm_New(libvlc_int_t *, const char *path)
Definition: vlm.c:139
Definition: vlc_vlm.h:149
Definition: vlc_vlm.h:153
Definition: vlc_vlm.h:98
static void vlm_media_instance_Init(vlm_media_instance_t *p_instance)
Initialize vlm_media_instance_t.
Definition: vlc_vlm.h:330
Input thread interface.
bool b_paused
Definition: vlc_vlm.h:79
Definition: vlc_vlm.h:104
int64_t i_length
Definition: vlc_vlm.h:77
int64_t i_time
Definition: vlc_vlm.h:76
static void vlm_media_Delete(vlm_media_t *p_media)
Delete a vlm_media_t instance.
Definition: vlc_vlm.h:306
vlm_state_e
Definition: vlc_vlm.h:108
Definition: vlc_vlm.h:113
Definition: vlc_vlm.h:163
void vlm_Delete(vlm_t *)
Definition: vlm.c:216
bool b_enabled
Definition: vlc_vlm.h:47
Definition: vlc_vlm.h:157
Definition: vlc_vlm.h:114
Definition: vlc_vlm.h:139
#define TAB_INIT(count, tab)
Definition: vlc_arrays.h:55