vlc_vlm.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_vlm.h: VLM core structures
00003  *****************************************************************************
00004  * Copyright (C) 2000, 2001 VLC authors and VideoLAN
00005  * $Id: 12a0eda4979b1e1bc507794d89e5794e6911e97a $
00006  *
00007  * Authors: Simon Latapie <garf@videolan.org>
00008  *          Laurent Aimar <fenrir@videolan.org>
00009  *
00010  * This program is free software; you can redistribute it and/or modify it
00011  * under the terms of the GNU Lesser General Public License as published by
00012  * the Free Software Foundation; either version 2.1 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018  * GNU Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public License
00021  * along with this program; if not, write to the Free Software Foundation,
00022  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef VLC_VLM_H
00026 #define VLC_VLM_H 1
00027 
00028 /**
00029  * \file
00030  * This file defines VLM core functions and structures in vlc
00031  */
00032 
00033 #include <vlc_input.h>
00034 
00035 /**
00036  * \defgroup server VLM
00037  * VLM is the server core in vlc that allows streaming of multiple media streams
00038  * at the same time. It provides broadcast, schedule and video on demand features
00039  * for streaming using several streaming and network protocols.
00040  * @{
00041  */
00042 
00043 /** VLM media */
00044 typedef struct
00045 {
00046     int64_t     id;     /*< numeric id for vlm_media_t item */
00047     bool  b_enabled;    /*< vlm_media_t is enabled */
00048 
00049     char *psz_name;     /*< descriptive name of vlm_media_t item */
00050 
00051     int  i_input;       /*< number of input options */
00052     char **ppsz_input;  /*< array of input options */
00053 
00054     int  i_option;      /*< number of output options */
00055     char **ppsz_option; /*< array of output options */
00056 
00057     char *psz_output;   /*< */
00058 
00059     bool b_vod;         /*< vlm_media_t is of type VOD */
00060     struct
00061     {
00062         bool b_loop;    /*< this vlc_media_t broadcast item should loop */
00063     } broadcast;        /*< Broadcast specific information */
00064     struct
00065     {
00066         char *psz_mux;  /*< name of muxer to use */
00067     } vod;              /*< VOD specific information */
00068 
00069 } vlm_media_t;
00070 
00071 /** VLM media instance */
00072 typedef struct
00073 {
00074     char *psz_name;         /*< vlm media instance descriptive name */
00075 
00076     int64_t     i_time;     /*< vlm media instance vlm media current time */
00077     int64_t     i_length;   /*< vlm media instance vlm media item length */
00078     double      d_position; /*< vlm media instance position in stream */
00079     bool        b_paused;   /*< vlm media instance is paused */
00080     int         i_rate;     // normal is INPUT_RATE_DEFAULT
00081 } vlm_media_instance_t;
00082 
00083 #if 0
00084 typedef struct
00085 {
00086 
00087 } vlm_schedule_t
00088 #endif
00089 
00090 /** VLM events
00091  * You can catch vlm event by adding a callback on the variable "intf-event"
00092  * of the VLM object.
00093  * This variable is an address that will hold a vlm_event_t* value.
00094  */
00095 enum vlm_event_type_e
00096 {
00097     /* */
00098     VLM_EVENT_MEDIA_ADDED   = 0x100,
00099     VLM_EVENT_MEDIA_REMOVED,
00100     VLM_EVENT_MEDIA_CHANGED,
00101 
00102     /* */
00103     VLM_EVENT_MEDIA_INSTANCE_STARTED    = 0x200,
00104     VLM_EVENT_MEDIA_INSTANCE_STOPPED,
00105     VLM_EVENT_MEDIA_INSTANCE_STATE,
00106 };
00107 
00108 typedef struct
00109 {
00110     int            i_type;            /* a vlm_event_type_e value */
00111     int64_t        id;                /* Media ID */
00112     const char    *psz_name;          /* Media name */
00113     const char    *psz_instance_name; /* Instance name or NULL */
00114     input_state_e  input_state;       /* Input instance event type */
00115 } vlm_event_t;
00116 
00117 /** VLM control query */
00118 enum vlm_query_e
00119 {
00120     /* --- Media control */
00121     /* Get all medias */
00122     VLM_GET_MEDIAS,                     /* arg1=vlm_media_t ***, int *pi_media      */
00123     /* Delete all medias */
00124     VLM_CLEAR_MEDIAS,                   /* no arg */
00125 
00126     /* Add a new media */
00127     VLM_ADD_MEDIA,                      /* arg1=vlm_media_t* arg2=int64_t *p_id         res=can fail */
00128     /* Delete an existing media */
00129     VLM_DEL_MEDIA,                      /* arg1=int64_t id */
00130     /* Change properties of an existing media (all fields but id and b_vod) */
00131     VLM_CHANGE_MEDIA,                   /* arg1=vlm_media_t*                            res=can fail */
00132     /* Get 1 media by it's ID */
00133     VLM_GET_MEDIA,                      /* arg1=int64_t id arg2=vlm_media_t **  */
00134     /* Get media ID from its name */
00135     VLM_GET_MEDIA_ID,                   /* arg1=const char *psz_name arg2=int64_t*  */
00136 
00137     /* Media instance control XXX VOD control are for internal use only */
00138     /* Get all media instances */
00139     VLM_GET_MEDIA_INSTANCES,            /* arg1=int64_t id arg2=vlm_media_instance_t *** arg3=int *pi_instance */
00140     /* Delete all media instances */
00141     VLM_CLEAR_MEDIA_INSTANCES,          /* arg1=int64_t id */
00142     /* Control broadcast instance */
00143     VLM_START_MEDIA_BROADCAST_INSTANCE, /* arg1=int64_t id, arg2=const char *psz_instance_name, int i_input_index  res=can fail */
00144     /* Control VOD instance */
00145     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 */
00146     /* Stop an instance */
00147     VLM_STOP_MEDIA_INSTANCE,            /* arg1=int64_t id, arg2=const char *psz_instance_name      res=can fail */
00148     /* Pause an instance */
00149     VLM_PAUSE_MEDIA_INSTANCE,           /* arg1=int64_t id, arg2=const char *psz_instance_name      res=can fail */
00150     /* Get instance position time (in microsecond) */
00151     VLM_GET_MEDIA_INSTANCE_TIME,        /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t *   */
00152     /* Set instance position time (in microsecond) */
00153     VLM_SET_MEDIA_INSTANCE_TIME,        /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=int64_t     */
00154     /* Get instance position ([0.0 .. 1.0]) */
00155     VLM_GET_MEDIA_INSTANCE_POSITION,    /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double *   */
00156     /* Set instance position ([0.0 .. 1.0]) */
00157     VLM_SET_MEDIA_INSTANCE_POSITION,    /* arg1=int64_t id, arg2=const char *psz_instance_name arg3=double     */
00158 
00159     /* Schedule control */
00160     VLM_CLEAR_SCHEDULES,                /* no arg */
00161     /* TODO: missing schedule control */
00162 
00163     /* */
00164 };
00165 
00166 
00167 /* VLM specific - structures and functions */
00168 
00169 /* ok, here is the structure of a vlm_message:
00170    The parent node is ( name_of_the_command , NULL ), or
00171    ( name_of_the_command , message_error ) on error.
00172    If a node has children, it should not have a value (=NULL).*/
00173 struct vlm_message_t
00174 {
00175     char *psz_name;         /*< message name */
00176     char *psz_value;        /*< message value */
00177 
00178     int           i_child;  /*< number of child messages */
00179     vlm_message_t **child;  /*< array of vlm_message_t */
00180 };
00181 
00182 
00183 #ifdef __cpluplus
00184 extern "C" {
00185 #endif
00186 
00187 VLC_API vlm_t * vlm_New( vlc_object_t * );
00188 #define vlm_New( a ) vlm_New( VLC_OBJECT(a) )
00189 VLC_API void vlm_Delete( vlm_t * );
00190 VLC_API int vlm_ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
00191 VLC_API int vlm_Control( vlm_t *p_vlm, int i_query, ... );
00192 
00193 VLC_API vlm_message_t * vlm_MessageSimpleNew( const char * );
00194 VLC_API vlm_message_t * vlm_MessageNew( const char *, const char *, ... ) VLC_FORMAT( 2, 3 );
00195 VLC_API vlm_message_t * vlm_MessageAdd( vlm_message_t *, vlm_message_t * );
00196 VLC_API void vlm_MessageDelete( vlm_message_t * );
00197 
00198 /* media helpers */
00199 
00200 /**
00201  * Initialize a vlm_media_t instance
00202  * \param p_media vlm_media_t instance to initialize
00203  */
00204 static inline void vlm_media_Init( vlm_media_t *p_media )
00205 {
00206     memset( p_media, 0, sizeof(vlm_media_t) );
00207     p_media->id = 0;    // invalid id
00208     p_media->psz_name = NULL;
00209     TAB_INIT( p_media->i_input, p_media->ppsz_input );
00210     TAB_INIT( p_media->i_option, p_media->ppsz_option );
00211     p_media->psz_output = NULL;
00212     p_media->b_vod = false;
00213 
00214     p_media->vod.psz_mux = NULL;
00215     p_media->broadcast.b_loop = false;
00216 }
00217 
00218 /**
00219  * Copy a vlm_media_t instance into another vlm_media_t instance
00220  * \param p_dst vlm_media_t instance to copy to
00221  * \param p_src vlm_media_t instance to copy from
00222  */
00223 static inline void
00224 #ifndef __cplusplus
00225 vlm_media_Copy( vlm_media_t *restrict p_dst, const vlm_media_t *restrict p_src )
00226 #else
00227 vlm_media_Copy( vlm_media_t *p_dst, const vlm_media_t *p_src )
00228 #endif
00229 {
00230     int i;
00231 
00232     memset( p_dst, 0, sizeof(vlm_media_t) );
00233     p_dst->id = p_src->id;
00234     p_dst->b_enabled = p_src->b_enabled;
00235     if( p_src->psz_name )
00236         p_dst->psz_name = strdup( p_src->psz_name );
00237 
00238     for( i = 0; i < p_src->i_input; i++ )
00239         TAB_APPEND_CAST( (char**), p_dst->i_input, p_dst->ppsz_input, strdup(p_src->ppsz_input[i]) );
00240     for( i = 0; i < p_src->i_option; i++ )
00241         TAB_APPEND_CAST( (char**), p_dst->i_option, p_dst->ppsz_option, strdup(p_src->ppsz_option[i]) );
00242 
00243     if( p_src->psz_output )
00244         p_dst->psz_output = strdup( p_src->psz_output );
00245 
00246     p_dst->b_vod = p_src->b_vod;
00247     if( p_src->b_vod )
00248     {
00249         if( p_src->vod.psz_mux )
00250             p_dst->vod.psz_mux = strdup( p_src->vod.psz_mux );
00251     }
00252     else
00253     {
00254         p_dst->broadcast.b_loop = p_src->broadcast.b_loop;
00255     }
00256 }
00257 
00258 /**
00259  * Cleanup and release memory associated with this vlm_media_t instance.
00260  * You still need to release p_media itself with vlm_media_Delete().
00261  * \param p_media vlm_media_t to cleanup
00262  */
00263 static inline void vlm_media_Clean( vlm_media_t *p_media )
00264 {
00265     int i;
00266     free( p_media->psz_name );
00267 
00268     for( i = 0; i < p_media->i_input; i++ )
00269         free( p_media->ppsz_input[i]);
00270     TAB_CLEAN(p_media->i_input, p_media->ppsz_input );
00271 
00272     for( i = 0; i < p_media->i_option; i++ )
00273         free( p_media->ppsz_option[i]);
00274     TAB_CLEAN(p_media->i_option, p_media->ppsz_option );
00275 
00276     free( p_media->psz_output );
00277     if( p_media->b_vod )
00278         free( p_media->vod.psz_mux );
00279 }
00280 
00281 /**
00282  * Allocate a new vlm_media_t instance
00283  * \return vlm_media_t instance
00284  */
00285 static inline vlm_media_t *vlm_media_New(void)
00286 {
00287     vlm_media_t *p_media = (vlm_media_t *)malloc( sizeof(vlm_media_t) );
00288     if( p_media )
00289         vlm_media_Init( p_media );
00290     return p_media;
00291 }
00292 
00293 /**
00294  * Delete a vlm_media_t instance
00295  * \param p_media vlm_media_t instance to delete
00296  */
00297 static inline void vlm_media_Delete( vlm_media_t *p_media )
00298 {
00299     vlm_media_Clean( p_media );
00300     free( p_media );
00301 }
00302 
00303 /**
00304  * Copy a vlm_media_t instance
00305  * \param p_src vlm_media_t instance to copy
00306  * \return vlm_media_t duplicate of p_src
00307  */
00308 static inline vlm_media_t *vlm_media_Duplicate( vlm_media_t *p_src )
00309 {
00310     vlm_media_t *p_dst = vlm_media_New();
00311     if( p_dst )
00312         vlm_media_Copy( p_dst, p_src );
00313     return p_dst;
00314 }
00315 
00316 /* media instance helpers */
00317 /**
00318  * Initialize vlm_media_instance_t
00319  * \param p_instance vlm_media_instance_t to initialize
00320  */
00321 static inline void vlm_media_instance_Init( vlm_media_instance_t *p_instance )
00322 {
00323     memset( p_instance, 0, sizeof(vlm_media_instance_t) );
00324     p_instance->psz_name = NULL;
00325     p_instance->i_time = 0;
00326     p_instance->i_length = 0;
00327     p_instance->d_position = 0.0;
00328     p_instance->b_paused = false;
00329     p_instance->i_rate = INPUT_RATE_DEFAULT;
00330 }
00331 
00332 /**
00333  * Cleanup vlm_media_instance_t
00334  * \param p_instance vlm_media_instance_t to cleanup
00335  */
00336 static inline void vlm_media_instance_Clean( vlm_media_instance_t *p_instance )
00337 {
00338     free( p_instance->psz_name );
00339 }
00340 
00341 /**
00342  * Allocate a new vlm_media_instance_t
00343  * \return a new vlm_media_instance_t
00344  */
00345 static inline vlm_media_instance_t *vlm_media_instance_New(void)
00346 {
00347     vlm_media_instance_t *p_instance = (vlm_media_instance_t *) malloc( sizeof(vlm_media_instance_t) );
00348     if( p_instance )
00349         vlm_media_instance_Init( p_instance );
00350     return p_instance;
00351 }
00352 
00353 /**
00354  * Delete a vlm_media_instance_t
00355  * \param p_instance vlm_media_instance_t to delete
00356  */
00357 static inline void vlm_media_instance_Delete( vlm_media_instance_t *p_instance )
00358 {
00359     vlm_media_instance_Clean( p_instance );
00360     free( p_instance );
00361 }
00362 
00363 #ifdef __cpluplus
00364 }
00365 #endif
00366 
00367 /**@}*/
00368 
00369 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines