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  struct
59  {
60  bool b_loop; /*< this vlc_media_t broadcast item should loop */
61  } broadcast; /*< Broadcast specific information */
62 
63 } vlm_media_t;
64 
65 /** VLM media instance */
66 typedef struct
67 {
68  char *psz_name; /*< vlm media instance descriptive name */
69 
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
76 
77 #if 0
78 typedef struct
79 {
80 
81 } vlm_schedule_t
82 #endif
83 
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.
88  */
90 {
91  /* */
92  VLM_EVENT_MEDIA_ADDED = 0x100,
95 
96  /* */
100 };
101 
102 typedef enum vlm_state_e
103 {
104  VLM_INIT_S = 0,
111 
112 typedef struct
113 {
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 */
120 
121 /** VLM control query */
122 enum vlm_query_e
123 {
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 */
129 
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* */
140 
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 */
160 
161  /* Schedule control */
162  VLM_CLEAR_SCHEDULES, /* no arg */
163  /* TODO: missing schedule control */
164 
165  /* */
166 };
167 
168 
169 /* VLM specific - structures and functions */
170 
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
176 {
177  char *psz_name; /*< message name */
178  char *psz_value; /*< message value */
179 
180  int i_child; /*< number of child messages */
181  vlm_message_t **child; /*< array of vlm_message_t */
182 };
183 
184 
185 #ifdef __cplusplus
186 extern "C" {
187 #endif
188 
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, ... );
193 
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 );
198 
199 /* media helpers */
200 
201 /**
202  * Initialize a vlm_media_t instance
203  * \param p_media vlm_media_t instance to initialize
204  */
205 static inline void vlm_media_Init( vlm_media_t *p_media )
206 {
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;
213 
214  p_media->broadcast.b_loop = false;
215 }
216 
217 /**
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
221  */
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
228 {
229  int i;
230 
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 );
236 
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]) );
241 
242  if( p_src->psz_output )
243  p_dst->psz_output = strdup( p_src->psz_output );
244 
245  p_dst->broadcast.b_loop = p_src->broadcast.b_loop;
246 }
247 
248 /**
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
252  */
253 static inline void vlm_media_Clean( vlm_media_t *p_media )
254 {
255  int i;
256  free( p_media->psz_name );
257 
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 );
261 
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 );
265 
266  free( p_media->psz_output );
267 }
268 
269 /**
270  * Allocate a new vlm_media_t instance
271  * \return vlm_media_t instance
272  */
273 static inline vlm_media_t *vlm_media_New(void)
274 {
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;
279 }
280 
281 /**
282  * Delete a vlm_media_t instance
283  * \param p_media vlm_media_t instance to delete
284  */
285 static inline void vlm_media_Delete( vlm_media_t *p_media )
286 {
287  vlm_media_Clean( p_media );
288  free( p_media );
289 }
290 
291 /**
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
295  */
296 static inline vlm_media_t *vlm_media_Duplicate( vlm_media_t *p_src )
297 {
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;
302 }
303 
304 /* media instance helpers */
305 /**
306  * Initialize vlm_media_instance_t
307  * \param p_instance vlm_media_instance_t to initialize
308  */
309 static inline void vlm_media_instance_Init( vlm_media_instance_t *p_instance )
310 {
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;
318 }
319 
320 /**
321  * Cleanup vlm_media_instance_t
322  * \param p_instance vlm_media_instance_t to cleanup
323  */
324 static inline void vlm_media_instance_Clean( vlm_media_instance_t *p_instance )
325 {
326  free( p_instance->psz_name );
327 }
328 
329 /**
330  * Allocate a new vlm_media_instance_t
331  * \return a new vlm_media_instance_t
332  */
333 static inline vlm_media_instance_t *vlm_media_instance_New(void)
334 {
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;
339 }
340 
341 /**
342  * Delete a vlm_media_instance_t
343  * \param p_instance vlm_media_instance_t to delete
344  */
345 static inline void vlm_media_instance_Delete( vlm_media_instance_t *p_instance )
346 {
347  vlm_media_instance_Clean( p_instance );
348  free( p_instance );
349 }
350 
351 #ifdef __cplusplus
352 }
353 #endif
354 
355 /**@}*/
356 
357 #endif
vlm_media_New
static vlm_media_t * vlm_media_New(void)
Allocate a new vlm_media_t instance.
Definition: vlc_vlm.h:274
VLM_EVENT_MEDIA_INSTANCE_STATE
@ VLM_EVENT_MEDIA_INSTANCE_STATE
Definition: vlc_vlm.h:100
VLC_API
#define VLC_API
Definition: fourcc_gen.c:31
TAB_CLEAN
#define TAB_CLEAN(count, tab)
Definition: vlc_arrays.h:61
vlm_event_t
Definition: vlc_vlm.h:113
VLM_EVENT_MEDIA_ADDED
@ VLM_EVENT_MEDIA_ADDED
Definition: vlc_vlm.h:93
VLM_CLEAR_MEDIAS
@ VLM_CLEAR_MEDIAS
Definition: vlc_vlm.h:129
vlm_event_t::id
int64_t id
Definition: vlc_vlm.h:116
psz_name
const char * psz_name
Definition: text_style.c:53
vlm_media_instance_t::d_position
double d_position
Definition: vlc_vlm.h:73
vlm_media_instance_t::f_rate
float f_rate
Definition: vlc_vlm.h:75
libvlc_int_t
Definition: vlc_objects.h:114
vlc_common.h
vlm_media_instance_t::psz_name
char * psz_name
Definition: vlc_vlm.h:69
vlm_MessageNew
VLC_EXPORT vlm_message_t * vlm_MessageNew(const char *, const char *,...)
Definition: missing.c:222
vlm_media_Copy
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:225
vlm_media_t::ppsz_option
char ** ppsz_option
Definition: vlc_vlm.h:55
vlm_Delete
VLC_EXPORT void vlm_Delete(vlm_t *)
Definition: vlm.c:183
VLM_ERROR_S
@ VLM_ERROR_S
Definition: vlc_vlm.h:110
vlm_media_t::psz_name
char * psz_name
Definition: vlc_vlm.h:49
vlm_event_t::psz_name
const char * psz_name
Definition: vlc_vlm.h:117
vlm_media_t::b_enabled
bool b_enabled
Definition: vlc_vlm.h:47
VLM_EVENT_MEDIA_CHANGED
@ VLM_EVENT_MEDIA_CHANGED
Definition: vlc_vlm.h:95
VLM_EVENT_MEDIA_INSTANCE_STARTED
@ VLM_EVENT_MEDIA_INSTANCE_STARTED
Definition: vlc_vlm.h:98
vlm_media_t::i_input
int i_input
Definition: vlc_vlm.h:51
vlm_message_t::i_child
int i_child
Definition: vlc_vlm.h:181
VLM_PAUSE_S
@ VLM_PAUSE_S
Definition: vlc_vlm.h:108
vlm_ExecuteCommand
VLC_EXPORT int vlm_ExecuteCommand(vlm_t *, const char *, vlm_message_t **)
Definition: vlm.c:224
vlm_media_Delete
static void vlm_media_Delete(vlm_media_t *p_media)
Delete a vlm_media_t instance.
Definition: vlc_vlm.h:286
vlm_media_t::psz_output
char * psz_output
Definition: vlc_vlm.h:57
VLM_START_MEDIA_BROADCAST_INSTANCE
@ VLM_START_MEDIA_BROADCAST_INSTANCE
Definition: vlc_vlm.h:148
vlm_media_instance_t::i_time
int64_t i_time
Definition: vlc_vlm.h:71
vlm_message_t::psz_name
char * psz_name
Definition: vlc_vlm.h:178
VLM_OPENING_S
@ VLM_OPENING_S
Definition: vlc_vlm.h:106
vlm_media_t::broadcast
struct vlm_media_t::@276 broadcast
vlc_input.h
vlm_New
VLC_EXPORT vlm_t * vlm_New(libvlc_int_t *, const char *path)
Definition: vlm.c:109
vlm_MessageSimpleNew
VLC_EXPORT vlm_message_t * vlm_MessageSimpleNew(const char *)
Definition: missing.c:216
vlm_media_instance_t::i_length
int64_t i_length
Definition: vlc_vlm.h:72
VLM_STOP_MEDIA_INSTANCE
@ VLM_STOP_MEDIA_INSTANCE
Definition: vlc_vlm.h:150
VLM_GET_MEDIAS
@ VLM_GET_MEDIAS
Definition: vlc_vlm.h:127
VLM_GET_MEDIA
@ VLM_GET_MEDIA
Definition: vlc_vlm.h:138
VLM_PAUSE_MEDIA_INSTANCE
@ VLM_PAUSE_MEDIA_INSTANCE
Definition: vlc_vlm.h:152
vlm_event_t::input_state
vlm_state_e input_state
Definition: vlc_vlm.h:119
i_type
int i_type
Definition: httpd.c:1269
vlm_media_t
VLM media.
Definition: vlc_vlm.h:44
VLM_ADD_MEDIA
@ VLM_ADD_MEDIA
Definition: vlc_vlm.h:132
vlm_t
Definition: vlm_internal.h:77
VLM_CLEAR_MEDIA_INSTANCES
@ VLM_CLEAR_MEDIA_INSTANCES
Definition: vlc_vlm.h:146
vlm_media_Clean
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:254
VLM_SET_MEDIA_INSTANCE_POSITION
@ VLM_SET_MEDIA_INSTANCE_POSITION
Definition: vlc_vlm.h:160
VLM_CHANGE_MEDIA
@ VLM_CHANGE_MEDIA
Definition: vlc_vlm.h:136
vlm_media_instance_Init
static void vlm_media_instance_Init(vlm_media_instance_t *p_instance)
Initialize vlm_media_instance_t.
Definition: vlc_vlm.h:310
vlm_state_e
vlm_state_e
Definition: vlc_vlm.h:103
vlm_media_instance_Clean
static void vlm_media_instance_Clean(vlm_media_instance_t *p_instance)
Cleanup vlm_media_instance_t.
Definition: vlc_vlm.h:325
vlm_query_e
vlm_query_e
VLM control query.
Definition: vlc_vlm.h:123
vlm_media_instance_Delete
static void vlm_media_instance_Delete(vlm_media_instance_t *p_instance)
Delete a vlm_media_instance_t.
Definition: vlc_vlm.h:346
vlm_Control
VLC_EXPORT int vlm_Control(vlm_t *p_vlm, int i_query,...)
Definition: vlm.c:978
VLM_GET_MEDIA_ID
@ VLM_GET_MEDIA_ID
Definition: vlc_vlm.h:140
vlm_media_Init
static void vlm_media_Init(vlm_media_t *p_media)
Initialize a vlm_media_t instance.
Definition: vlc_vlm.h:206
VLM_DEL_MEDIA
@ VLM_DEL_MEDIA
Definition: vlc_vlm.h:134
vlm_media_t::id
int64_t id
Definition: vlc_vlm.h:46
VLC_FORMAT
#define VLC_FORMAT(x, y)
String format function annotation.
Definition: vlc_common.h:141
VLM_EVENT_MEDIA_INSTANCE_STOPPED
@ VLM_EVENT_MEDIA_INSTANCE_STOPPED
Definition: vlc_vlm.h:99
vlm_event_t::i_type
int i_type
Definition: vlc_vlm.h:115
vlm_event_type_e
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:90
vlm_MessageAdd
VLC_EXPORT vlm_message_t * vlm_MessageAdd(vlm_message_t *, vlm_message_t *)
Definition: missing.c:203
VLM_PLAYING_S
@ VLM_PLAYING_S
Definition: vlc_vlm.h:107
strdup
char * strdup(const char *)
VLM_GET_MEDIA_INSTANCES
@ VLM_GET_MEDIA_INSTANCES
Definition: vlc_vlm.h:144
VLM_EVENT_MEDIA_REMOVED
@ VLM_EVENT_MEDIA_REMOVED
Definition: vlc_vlm.h:94
vlm_media_t::i_option
int i_option
Definition: vlc_vlm.h:54
vlm_media_instance_t
VLM media instance.
Definition: vlc_vlm.h:67
TAB_INIT
#define TAB_INIT(count, tab)
Definition: vlc_arrays.h:55
TAB_APPEND_CAST
#define TAB_APPEND_CAST(cast, count, tab, p)
Definition: vlc_arrays.h:68
VLM_END_S
@ VLM_END_S
Definition: vlc_vlm.h:109
vlm_media_t::b_loop
bool b_loop
Definition: vlc_vlm.h:61
VLM_INIT_S
@ VLM_INIT_S
Definition: vlc_vlm.h:105
vlm_message_t
Definition: vlc_vlm.h:176
vlm_media_Duplicate
static vlm_media_t * vlm_media_Duplicate(vlm_media_t *p_src)
Copy a vlm_media_t instance.
Definition: vlc_vlm.h:297
vlm_message_t::child
vlm_message_t ** child
Definition: vlc_vlm.h:182
vlm_media_t::ppsz_input
char ** ppsz_input
Definition: vlc_vlm.h:52
VLM_CLEAR_SCHEDULES
@ VLM_CLEAR_SCHEDULES
Definition: vlc_vlm.h:163
VLM_GET_MEDIA_INSTANCE_POSITION
@ VLM_GET_MEDIA_INSTANCE_POSITION
Definition: vlc_vlm.h:158
vlm_message_t::psz_value
char * psz_value
Definition: vlc_vlm.h:179
vlm_event_t::psz_instance_name
const char * psz_instance_name
Definition: vlc_vlm.h:118
vlm_media_instance_t::b_paused
bool b_paused
Definition: vlc_vlm.h:74
vlm_MessageDelete
VLC_EXPORT void vlm_MessageDelete(vlm_message_t *)
Definition: missing.c:210
VLM_GET_MEDIA_INSTANCE_TIME
@ VLM_GET_MEDIA_INSTANCE_TIME
Definition: vlc_vlm.h:154
VLM_SET_MEDIA_INSTANCE_TIME
@ VLM_SET_MEDIA_INSTANCE_TIME
Definition: vlc_vlm.h:156
vlm_media_instance_New
static vlm_media_instance_t * vlm_media_instance_New(void)
Allocate a new vlm_media_instance_t.
Definition: vlc_vlm.h:334