vlc_vlm.h 11.8 KB
Newer Older
1
/*****************************************************************************
2
 * vlc_vlm.h: VLM core structures
3
 *****************************************************************************
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2000, 2001 VLC authors and VideoLAN
5
 * $Id$
6 7 8 9
 *
 * Authors: Simon Latapie <garf@videolan.org>
 *          Laurent Aimar <fenrir@videolan.org>
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
10 11 12
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
13
 * (at your option) any later version.
14
 *
15 16
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
17 18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
19
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
20 21 22
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24
 *****************************************************************************/

25 26
#ifndef VLC_VLM_H
#define VLC_VLM_H 1
27

Clément Stenac's avatar
Clément Stenac committed
28 29
#include <vlc_input.h>

30 31
/**
 * \defgroup server VLM
32
 * \ingroup interface
33 34
 * VLC stream manager
 *
35 36 37 38
 * VLM is the server core in vlc that allows streaming of multiple media streams
 * at the same time. It provides broadcast, schedule and video on demand features
 * for streaming using several streaming and network protocols.
 * @{
39 40
 * \file
 * VLC stream manager interface
41 42
 */

43
/** VLM media */
44 45
typedef struct
{
46 47
    int64_t     id;     /*< numeric id for vlm_media_t item */
    bool  b_enabled;    /*< vlm_media_t is enabled */
48

49
    char *psz_name;     /*< descriptive name of vlm_media_t item */
50

51 52
    int  i_input;       /*< number of input options */
    char **ppsz_input;  /*< array of input options */
53

54 55
    int  i_option;      /*< number of output options */
    char **ppsz_option; /*< array of output options */
56

57
    char *psz_output;   /*< */
58

59
    bool b_vod;         /*< vlm_media_t is of type VOD */
60 61
    struct
    {
62 63
        bool b_loop;    /*< this vlc_media_t broadcast item should loop */
    } broadcast;        /*< Broadcast specific information */
64 65
    struct
    {
66 67
        char *psz_mux;  /*< name of muxer to use */
    } vod;              /*< VOD specific information */
68 69 70

} vlm_media_t;

71
/** VLM media instance */
72 73
typedef struct
{
74
    char *psz_name;         /*< vlm media instance descriptive name */
75

76 77 78 79
    int64_t     i_time;     /*< vlm media instance vlm media current time */
    int64_t     i_length;   /*< vlm media instance vlm media item length */
    double      d_position; /*< vlm media instance position in stream */
    bool        b_paused;   /*< vlm media instance is paused */
80 81 82 83 84 85 86 87 88 89
    int         i_rate;     // normal is INPUT_RATE_DEFAULT
} vlm_media_instance_t;

#if 0
typedef struct
{

} vlm_schedule_t
#endif

Laurent Aimar's avatar
Laurent Aimar committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
/** VLM events
 * You can catch vlm event by adding a callback on the variable "intf-event"
 * of the VLM object.
 * This variable is an address that will hold a vlm_event_t* value.
 */
enum vlm_event_type_e
{
    /* */
    VLM_EVENT_MEDIA_ADDED   = 0x100,
    VLM_EVENT_MEDIA_REMOVED,
    VLM_EVENT_MEDIA_CHANGED,

    /* */
    VLM_EVENT_MEDIA_INSTANCE_STARTED    = 0x200,
    VLM_EVENT_MEDIA_INSTANCE_STOPPED,
Sébastien Escudier's avatar
Sébastien Escudier committed
105
    VLM_EVENT_MEDIA_INSTANCE_STATE,
Laurent Aimar's avatar
Laurent Aimar committed
106 107 108 109
};

typedef struct
{
Sébastien Escudier's avatar
Sébastien Escudier committed
110 111 112 113
    int            i_type;            /* a vlm_event_type_e value */
    int64_t        id;                /* Media ID */
    const char    *psz_name;          /* Media name */
    const char    *psz_instance_name; /* Instance name or NULL */
Laurent Aimar's avatar
Laurent Aimar committed
114
    input_state_e  input_state;       /* Input instance event type */
Laurent Aimar's avatar
Laurent Aimar committed
115 116
} vlm_event_t;

117
/** VLM control query */
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
enum vlm_query_e
{
    /* --- Media control */
    /* Get all medias */
    VLM_GET_MEDIAS,                     /* arg1=vlm_media_t ***, int *pi_media      */
    /* Delete all medias */
    VLM_CLEAR_MEDIAS,                   /* no arg */

    /* Add a new media */
    VLM_ADD_MEDIA,                      /* arg1=vlm_media_t* arg2=int64_t *p_id         res=can fail */
    /* Delete an existing media */
    VLM_DEL_MEDIA,                      /* arg1=int64_t id */
    /* Change properties of an existing media (all fields but id and b_vod) */
    VLM_CHANGE_MEDIA,                   /* arg1=vlm_media_t*                            res=can fail */
    /* Get 1 media by it's ID */
    VLM_GET_MEDIA,                      /* arg1=int64_t id arg2=vlm_media_t **  */
    /* Get media ID from its name */
    VLM_GET_MEDIA_ID,                   /* arg1=const char *psz_name arg2=int64_t*  */

    /* Media instance control XXX VOD control are for internal use only */
    /* Get all media instances */
    VLM_GET_MEDIA_INSTANCES,            /* arg1=int64_t id arg2=vlm_media_instance_t *** arg3=int *pi_instance */
    /* Delete all media instances */
    VLM_CLEAR_MEDIA_INSTANCES,          /* arg1=int64_t id */
    /* Control broadcast instance */
    VLM_START_MEDIA_BROADCAST_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name, int i_input_index  res=can fail */
    /* Control VOD instance */
    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 */
    /* Stop an instance */
    VLM_STOP_MEDIA_INSTANCE,            /* arg1=int64_t id, arg2=const char *psz_instance_name      res=can fail */
    /* Pause an instance */
    VLM_PAUSE_MEDIA_INSTANCE,           /* arg1=int64_t id, arg2=const char *psz_instance_name      res=can fail */
    /* Get instance position time (in microsecond) */
    VLM_GET_MEDIA_INSTANCE_TIME,        /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t *   */
    /* Set instance position time (in microsecond) */
    VLM_SET_MEDIA_INSTANCE_TIME,        /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t     */
    /* Get instance position ([0.0 .. 1.0]) */
    VLM_GET_MEDIA_INSTANCE_POSITION,    /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double *   */
    /* Set instance position ([0.0 .. 1.0]) */
    VLM_SET_MEDIA_INSTANCE_POSITION,    /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double     */

    /* Schedule control */
    VLM_CLEAR_SCHEDULES,                /* no arg */
    /* TODO: missing schedule control */

    /* */
};


167 168
/* VLM specific - structures and functions */

169 170 171 172
/* ok, here is the structure of a vlm_message:
   The parent node is ( name_of_the_command , NULL ), or
   ( name_of_the_command , message_error ) on error.
   If a node has children, it should not have a value (=NULL).*/
173
struct vlm_message_t
174
{
175 176
    char *psz_name;         /*< message name */
    char *psz_value;        /*< message value */
177

178 179
    int           i_child;  /*< number of child messages */
    vlm_message_t **child;  /*< array of vlm_message_t */
180
};
181

182

183
#ifdef __cplusplus
184 185 186
extern "C" {
#endif

187 188
VLC_API vlm_t * vlm_New( vlc_object_t *, const char *path );
#define vlm_New( a, p ) vlm_New( VLC_OBJECT(a), p )
189 190 191
VLC_API void vlm_Delete( vlm_t * );
VLC_API int vlm_ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
VLC_API int vlm_Control( vlm_t *p_vlm, int i_query, ... );
192

193
VLC_API vlm_message_t * vlm_MessageSimpleNew( const char * );
194
VLC_API vlm_message_t * vlm_MessageNew( const char *, const char *, ... ) VLC_FORMAT( 2, 3 );
195 196
VLC_API vlm_message_t * vlm_MessageAdd( vlm_message_t *, vlm_message_t * );
VLC_API void vlm_MessageDelete( vlm_message_t * );
197

198
/* media helpers */
199 200 201 202 203

/**
 * Initialize a vlm_media_t instance
 * \param p_media vlm_media_t instance to initialize
 */
204 205 206 207 208 209 210 211
static inline void vlm_media_Init( vlm_media_t *p_media )
{
    memset( p_media, 0, sizeof(vlm_media_t) );
    p_media->id = 0;    // invalid id
    p_media->psz_name = NULL;
    TAB_INIT( p_media->i_input, p_media->ppsz_input );
    TAB_INIT( p_media->i_option, p_media->ppsz_option );
    p_media->psz_output = NULL;
212
    p_media->b_vod = false;
213 214

    p_media->vod.psz_mux = NULL;
215
    p_media->broadcast.b_loop = false;
216 217
}

218 219 220 221 222
/**
 * Copy a vlm_media_t instance into another vlm_media_t instance
 * \param p_dst vlm_media_t instance to copy to
 * \param p_src vlm_media_t instance to copy from
 */
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
223 224 225 226 227 228
static inline void
#ifndef __cplusplus
vlm_media_Copy( vlm_media_t *restrict p_dst, const vlm_media_t *restrict p_src )
#else
vlm_media_Copy( vlm_media_t *p_dst, const vlm_media_t *p_src )
#endif
229 230 231 232 233 234 235 236 237 238
{
    int i;

    memset( p_dst, 0, sizeof(vlm_media_t) );
    p_dst->id = p_src->id;
    p_dst->b_enabled = p_src->b_enabled;
    if( p_src->psz_name )
        p_dst->psz_name = strdup( p_src->psz_name );

    for( i = 0; i < p_src->i_input; i++ )
239
        TAB_APPEND_CAST( (char**), p_dst->i_input, p_dst->ppsz_input, strdup(p_src->ppsz_input[i]) );
240
    for( i = 0; i < p_src->i_option; i++ )
241
        TAB_APPEND_CAST( (char**), p_dst->i_option, p_dst->ppsz_option, strdup(p_src->ppsz_option[i]) );
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256

    if( p_src->psz_output )
        p_dst->psz_output = strdup( p_src->psz_output );

    p_dst->b_vod = p_src->b_vod;
    if( p_src->b_vod )
    {
        if( p_src->vod.psz_mux )
            p_dst->vod.psz_mux = strdup( p_src->vod.psz_mux );
    }
    else
    {
        p_dst->broadcast.b_loop = p_src->broadcast.b_loop;
    }
}
257 258 259 260 261 262

/**
 * Cleanup and release memory associated with this vlm_media_t instance.
 * You still need to release p_media itself with vlm_media_Delete().
 * \param p_media vlm_media_t to cleanup
 */
263 264 265
static inline void vlm_media_Clean( vlm_media_t *p_media )
{
    int i;
266
    free( p_media->psz_name );
267 268

    for( i = 0; i < p_media->i_input; i++ )
269
        free( p_media->ppsz_input[i]);
270 271 272
    TAB_CLEAN(p_media->i_input, p_media->ppsz_input );

    for( i = 0; i < p_media->i_option; i++ )
273
        free( p_media->ppsz_option[i]);
274 275
    TAB_CLEAN(p_media->i_option, p_media->ppsz_option );

276
    free( p_media->psz_output );
277
    if( p_media->b_vod )
278
        free( p_media->vod.psz_mux );
279
}
280 281 282 283 284

/**
 * Allocate a new vlm_media_t instance
 * \return vlm_media_t instance
 */
285 286
static inline vlm_media_t *vlm_media_New(void)
{
287
    vlm_media_t *p_media = (vlm_media_t *)malloc( sizeof(vlm_media_t) );
288 289 290 291
    if( p_media )
        vlm_media_Init( p_media );
    return p_media;
}
292 293 294 295 296

/**
 * Delete a vlm_media_t instance
 * \param p_media vlm_media_t instance to delete
 */
297 298 299 300 301
static inline void vlm_media_Delete( vlm_media_t *p_media )
{
    vlm_media_Clean( p_media );
    free( p_media );
}
302 303 304 305 306 307

/**
 * Copy a vlm_media_t instance
 * \param p_src vlm_media_t instance to copy
 * \return vlm_media_t duplicate of p_src
 */
308 309 310 311 312 313 314 315 316
static inline vlm_media_t *vlm_media_Duplicate( vlm_media_t *p_src )
{
    vlm_media_t *p_dst = vlm_media_New();
    if( p_dst )
        vlm_media_Copy( p_dst, p_src );
    return p_dst;
}

/* media instance helpers */
317 318 319 320
/**
 * Initialize vlm_media_instance_t
 * \param p_instance vlm_media_instance_t to initialize
 */
321 322 323 324 325 326 327
static inline void vlm_media_instance_Init( vlm_media_instance_t *p_instance )
{
    memset( p_instance, 0, sizeof(vlm_media_instance_t) );
    p_instance->psz_name = NULL;
    p_instance->i_time = 0;
    p_instance->i_length = 0;
    p_instance->d_position = 0.0;
328
    p_instance->b_paused = false;
329 330
    p_instance->i_rate = INPUT_RATE_DEFAULT;
}
331 332 333 334 335

/**
 * Cleanup vlm_media_instance_t
 * \param p_instance vlm_media_instance_t to cleanup
 */
336 337
static inline void vlm_media_instance_Clean( vlm_media_instance_t *p_instance )
{
338
    free( p_instance->psz_name );
339
}
340 341 342 343 344

/**
 * Allocate a new vlm_media_instance_t
 * \return a new vlm_media_instance_t
 */
345 346
static inline vlm_media_instance_t *vlm_media_instance_New(void)
{
347
    vlm_media_instance_t *p_instance = (vlm_media_instance_t *) malloc( sizeof(vlm_media_instance_t) );
348 349 350 351
    if( p_instance )
        vlm_media_instance_Init( p_instance );
    return p_instance;
}
352 353 354 355 356

/**
 * Delete a vlm_media_instance_t
 * \param p_instance vlm_media_instance_t to delete
 */
357 358 359 360 361 362
static inline void vlm_media_instance_Delete( vlm_media_instance_t *p_instance )
{
    vlm_media_instance_Clean( p_instance );
    free( p_instance );
}

363
#ifdef __cplusplus
Clément Stenac's avatar
Clément Stenac committed
364 365 366
}
#endif

367 368
/**@}*/

369
#endif