VLC  3.0.21
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  * $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 it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 
25 #ifndef VLC_VLM_H
26 #define VLC_VLM_H 1
27 
28 #include <vlc_input.h>
29 
30 /**
31  * \defgroup server VLM
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  int i_rate; // normal is INPUT_RATE_DEFAULT
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  /* */
100 
101  /* */
105 };
106 
107 typedef struct
108 {
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;
115 
116 /** VLM control query */
118 {
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 */
124 
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* */
135 
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 */
157 
158  /* Schedule control */
159  VLM_CLEAR_SCHEDULES, /* no arg */
160  /* TODO: missing schedule control */
161 
162  /* */
163 };
164 
165 
166 /* VLM specific - structures and functions */
167 
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).*/
173 {
174  char *psz_name; /*< message name */
175  char *psz_value; /*< message value */
176 
177  int i_child; /*< number of child messages */
178  vlm_message_t **child; /*< array of vlm_message_t */
179 };
180 
181 
182 #ifdef __cplusplus
183 extern "C" {
184 #endif
185 
187 #define vlm_New( a ) vlm_New( VLC_OBJECT(a) )
188 VLC_API void vlm_Delete( vlm_t * );
189 VLC_API int vlm_ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
190 VLC_API int vlm_Control( vlm_t *p_vlm, int i_query, ... );
191 
192 VLC_API vlm_message_t * vlm_MessageSimpleNew( const char * );
193 VLC_API vlm_message_t * vlm_MessageNew( const char *, const char *, ... ) VLC_FORMAT( 2, 3 );
196 
197 /* media helpers */
198 
199 /**
200  * Initialize a vlm_media_t instance
201  * \param p_media vlm_media_t instance to initialize
202  */
203 static inline void vlm_media_Init( vlm_media_t *p_media )
204 {
205  memset( p_media, 0, sizeof(vlm_media_t) );
206  p_media->id = 0; // invalid id
207  p_media->psz_name = NULL;
208  TAB_INIT( p_media->i_input, p_media->ppsz_input );
209  TAB_INIT( p_media->i_option, p_media->ppsz_option );
210  p_media->psz_output = NULL;
211  p_media->b_vod = false;
212 
213  p_media->vod.psz_mux = NULL;
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->b_vod = p_src->b_vod;
246  if( p_src->b_vod )
247  {
248  if( p_src->vod.psz_mux )
249  p_dst->vod.psz_mux = strdup( p_src->vod.psz_mux );
250  }
251  else
252  {
253  p_dst->broadcast.b_loop = p_src->broadcast.b_loop;
254  }
255 }
256 
257 /**
258  * Cleanup and release memory associated with this vlm_media_t instance.
259  * You still need to release p_media itself with vlm_media_Delete().
260  * \param p_media vlm_media_t to cleanup
261  */
262 static inline void vlm_media_Clean( vlm_media_t *p_media )
263 {
264  int i;
265  free( p_media->psz_name );
266 
267  for( i = 0; i < p_media->i_input; i++ )
268  free( p_media->ppsz_input[i]);
269  TAB_CLEAN(p_media->i_input, p_media->ppsz_input );
270 
271  for( i = 0; i < p_media->i_option; i++ )
272  free( p_media->ppsz_option[i]);
273  TAB_CLEAN(p_media->i_option, p_media->ppsz_option );
274 
275  free( p_media->psz_output );
276  if( p_media->b_vod )
277  free( p_media->vod.psz_mux );
278 }
279 
280 /**
281  * Allocate a new vlm_media_t instance
282  * \return vlm_media_t instance
283  */
284 static inline vlm_media_t *vlm_media_New(void)
285 {
286  vlm_media_t *p_media = (vlm_media_t *)malloc( sizeof(vlm_media_t) );
287  if( p_media )
288  vlm_media_Init( p_media );
289  return p_media;
290 }
291 
292 /**
293  * Delete a vlm_media_t instance
294  * \param p_media vlm_media_t instance to delete
295  */
296 static inline void vlm_media_Delete( vlm_media_t *p_media )
297 {
298  vlm_media_Clean( p_media );
299  free( p_media );
300 }
301 
302 /**
303  * Copy a vlm_media_t instance
304  * \param p_src vlm_media_t instance to copy
305  * \return vlm_media_t duplicate of p_src
306  */
308 {
309  vlm_media_t *p_dst = vlm_media_New();
310  if( p_dst )
311  vlm_media_Copy( p_dst, p_src );
312  return p_dst;
313 }
314 
315 /* media instance helpers */
316 /**
317  * Initialize vlm_media_instance_t
318  * \param p_instance vlm_media_instance_t to initialize
319  */
320 static inline void vlm_media_instance_Init( vlm_media_instance_t *p_instance )
321 {
322  memset( p_instance, 0, sizeof(vlm_media_instance_t) );
323  p_instance->psz_name = NULL;
324  p_instance->i_time = 0;
325  p_instance->i_length = 0;
326  p_instance->d_position = 0.0;
327  p_instance->b_paused = false;
328  p_instance->i_rate = INPUT_RATE_DEFAULT;
329 }
330 
331 /**
332  * Cleanup vlm_media_instance_t
333  * \param p_instance vlm_media_instance_t to cleanup
334  */
335 static inline void vlm_media_instance_Clean( vlm_media_instance_t *p_instance )
336 {
337  free( p_instance->psz_name );
338 }
339 
340 /**
341  * Allocate a new vlm_media_instance_t
342  * \return a new vlm_media_instance_t
343  */
345 {
346  vlm_media_instance_t *p_instance = (vlm_media_instance_t *) malloc( sizeof(vlm_media_instance_t) );
347  if( p_instance )
348  vlm_media_instance_Init( p_instance );
349  return p_instance;
350 }
351 
352 /**
353  * Delete a vlm_media_instance_t
354  * \param p_instance vlm_media_instance_t to delete
355  */
356 static inline void vlm_media_instance_Delete( vlm_media_instance_t *p_instance )
357 {
358  vlm_media_instance_Clean( p_instance );
359  free( p_instance );
360 }
361 
362 #ifdef __cplusplus
363 }
364 #endif
365 
366 /**@}*/
367 
368 #endif
vlm_media_New
static vlm_media_t * vlm_media_New(void)
Allocate a new vlm_media_t instance.
Definition: vlc_vlm.h:284
VLC_FORMAT
#define VLC_FORMAT(x, y)
Definition: vlc_common.h:100
VLM_EVENT_MEDIA_INSTANCE_STATE
Definition: vlc_vlm.h:104
VLC_API
#define VLC_API
Definition: fourcc_gen.c:30
INPUT_RATE_DEFAULT
#define INPUT_RATE_DEFAULT
Input rate.
Definition: vlc_input.h:306
TAB_CLEAN
#define TAB_CLEAN(count, tab)
Definition: vlc_arrays.h:46
vlm_event_t
Definition: vlc_vlm.h:107
VLM_EVENT_MEDIA_ADDED
Definition: vlc_vlm.h:97
vlm_MessageSimpleNew
vlm_message_t * vlm_MessageSimpleNew(const char *)
Definition: missing.c:229
VLM_CLEAR_MEDIAS
Definition: vlc_vlm.h:123
vlm_event_t::id
int64_t id
Definition: vlc_vlm.h:110
vlm_media_instance_t::d_position
double d_position
Definition: vlc_vlm.h:77
vlc_common.h
vlm_media_instance_t::psz_name
char * psz_name
Definition: vlc_vlm.h:73
vlm_media_t::broadcast
struct vlm_media_t::@205 broadcast
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:224
vlm_media_t::ppsz_option
char ** ppsz_option
Definition: vlc_vlm.h:54
vlm_media_t::psz_name
char * psz_name
Definition: vlc_vlm.h:48
vlm_event_t::psz_name
const char * psz_name
Definition: vlc_vlm.h:111
vlm_media_t::b_enabled
bool b_enabled
Definition: vlc_vlm.h:46
VLM_EVENT_MEDIA_CHANGED
Definition: vlc_vlm.h:99
VLM_EVENT_MEDIA_INSTANCE_STARTED
Definition: vlc_vlm.h:102
VLM_START_MEDIA_VOD_INSTANCE
Definition: vlc_vlm.h:144
vlm_media_t::i_input
int i_input
Definition: vlc_vlm.h:50
vlm_message_t::i_child
int i_child
Definition: vlc_vlm.h:177
vlm_event_t::input_state
input_state_e input_state
Definition: vlc_vlm.h:113
vlm_media_Delete
static void vlm_media_Delete(vlm_media_t *p_media)
Delete a vlm_media_t instance.
Definition: vlc_vlm.h:296
vlm_media_t::psz_output
char * psz_output
Definition: vlc_vlm.h:56
VLM_START_MEDIA_BROADCAST_INSTANCE
Definition: vlc_vlm.h:142
vlm_media_instance_t::i_time
int64_t i_time
Definition: vlc_vlm.h:75
vlm_message_t::psz_name
char * psz_name
Definition: vlc_vlm.h:174
input_state_e
input_state_e
Input state.
Definition: vlc_input.h:280
vlc_input.h
vlm_Delete
void vlm_Delete(vlm_t *)
Definition: vlm.c:209
vlm_ExecuteCommand
int vlm_ExecuteCommand(vlm_t *, const char *, vlm_message_t **)
Definition: vlm.c:260
vlm_media_instance_t::i_length
int64_t i_length
Definition: vlc_vlm.h:76
VLM_STOP_MEDIA_INSTANCE
Definition: vlc_vlm.h:146
VLM_GET_MEDIAS
Definition: vlc_vlm.h:121
VLM_GET_MEDIA
Definition: vlc_vlm.h:132
vlm_MessageDelete
void vlm_MessageDelete(vlm_message_t *)
Definition: missing.c:223
VLM_PAUSE_MEDIA_INSTANCE
Definition: vlc_vlm.h:148
i_type
int i_type
Definition: httpd.c:1252
vlm_media_t
VLM media.
Definition: vlc_vlm.h:43
VLM_ADD_MEDIA
Definition: vlc_vlm.h:126
vlm_t
Definition: vlm_internal.h:83
VLM_CLEAR_MEDIA_INSTANCES
Definition: vlc_vlm.h:140
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:262
VLM_SET_MEDIA_INSTANCE_POSITION
Definition: vlc_vlm.h:156
VLM_CHANGE_MEDIA
Definition: vlc_vlm.h:130
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:320
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:335
psz_name
const char * psz_name
Definition: vlc_codecs.h:315
vlm_query_e
vlm_query_e
VLM control query.
Definition: vlc_vlm.h:117
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:356
VLM_GET_MEDIA_ID
Definition: vlc_vlm.h:134
vlm_media_Init
static void vlm_media_Init(vlm_media_t *p_media)
Initialize a vlm_media_t instance.
Definition: vlc_vlm.h:203
VLM_DEL_MEDIA
Definition: vlc_vlm.h:128
vlm_MessageAdd
vlm_message_t * vlm_MessageAdd(vlm_message_t *, vlm_message_t *)
Definition: missing.c:216
vlm_media_t::id
int64_t id
Definition: vlc_vlm.h:45
VLM_EVENT_MEDIA_INSTANCE_STOPPED
Definition: vlc_vlm.h:103
vlm_event_t::i_type
int i_type
Definition: vlc_vlm.h:109
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:94
vlc_object_t
The main vlc_object_t structure.
Definition: vlc_objects.h:39
strdup
char * strdup(const char *)
VLM_GET_MEDIA_INSTANCES
Definition: vlc_vlm.h:138
VLM_EVENT_MEDIA_REMOVED
Definition: vlc_vlm.h:98
vlm_media_t::i_option
int i_option
Definition: vlc_vlm.h:53
vlm_media_instance_t
VLM media instance.
Definition: vlc_vlm.h:71
TAB_INIT
#define TAB_INIT(count, tab)
Definition: vlc_arrays.h:40
vlm_MessageNew
vlm_message_t * vlm_MessageNew(const char *, const char *,...)
Definition: missing.c:235
TAB_APPEND_CAST
#define TAB_APPEND_CAST(cast, count, tab, p)
Definition: vlc_arrays.h:53
vlm_media_t::b_loop
bool b_loop
Definition: vlc_vlm.h:61
vlm_Control
int vlm_Control(vlm_t *p_vlm, int i_query,...)
Definition: vlm.c:1321
vlm_message_t
Definition: vlc_vlm.h:172
vlm_media_t::b_vod
bool b_vod
Definition: vlc_vlm.h:58
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:307
vlm_media_instance_t::i_rate
int i_rate
Definition: vlc_vlm.h:79
vlm_message_t::child
vlm_message_t ** child
Definition: vlc_vlm.h:178
vlm_media_t::ppsz_input
char ** ppsz_input
Definition: vlc_vlm.h:51
VLM_CLEAR_SCHEDULES
Definition: vlc_vlm.h:159
vlm_New
#define vlm_New(a)
Definition: vlc_vlm.h:187
VLM_GET_MEDIA_INSTANCE_POSITION
Definition: vlc_vlm.h:154
vlm_message_t::psz_value
char * psz_value
Definition: vlc_vlm.h:175
vlm_event_t::psz_instance_name
const char * psz_instance_name
Definition: vlc_vlm.h:112
vlm_media_instance_t::b_paused
bool b_paused
Definition: vlc_vlm.h:78
VLM_GET_MEDIA_INSTANCE_TIME
Definition: vlc_vlm.h:150
vlm_media_t::psz_mux
char * psz_mux
Definition: vlc_vlm.h:65
vlm_media_t::vod
struct vlm_media_t::@206 vod
VLM_SET_MEDIA_INSTANCE_TIME
Definition: vlc_vlm.h:152
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:344