X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Finput%2Fvlm.c;h=c532a4e2f03491b7c847f3f55def0f74ddc3a829;hb=dd2c908fc5096d6462c61f096c564dbc4c5f0c2d;hp=64081ac92f16b706216581c1007ce9b857571179;hpb=39df335044bacc905f61b48ddfa7a5edca3c0d14;p=vlc diff --git a/src/input/vlm.c b/src/input/vlm.c index 64081ac92f..c532a4e2f0 100644 --- a/src/input/vlm.c +++ b/src/input/vlm.c @@ -26,15 +26,23 @@ /***************************************************************************** * Preamble *****************************************************************************/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include -#include /* malloc(), free() */ #include /* tolower() */ #include +#include + #ifdef ENABLE_VLM +#ifndef WIN32 +# include /* gettimeofday() */ +#endif #ifdef HAVE_TIME_H # include /* ctime() */ @@ -44,22 +52,28 @@ #include #include "input_internal.h" #include -#include #include "vlm_internal.h" #include #include #include #include "../stream_output/stream_output.h" +#include "../libvlc.h" /***************************************************************************** * Local prototypes. *****************************************************************************/ + +/* ugly kludge to avoid "null format string" warnings, + * even if we handle NULL format string in vlm_MessageNew() */ +static const char *vlm_NULL = NULL; + +static void vlm_Destructor( vlm_t *p_vlm ); + /* */ static int vlm_ControlInternal( vlm_t *, int, ... ); /* */ static vlm_message_t *vlm_Show( vlm_t *, vlm_media_sys_t *, vlm_schedule_sys_t *, const char * ); -static vlm_message_t *vlm_Help( vlm_t *, char * ); static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *, const char * ); @@ -71,7 +85,7 @@ static int ExecuteCommand( vlm_t *, const char *, vlm_message_t ** ); static int Manage( vlc_object_t * ); static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name ); -static void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched, const char *psz_name ); +static void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched ); static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd, const char *psz_value ); @@ -88,10 +102,11 @@ vlm_t *__vlm_New ( vlc_object_t *p_this ) vlc_value_t lockval; vlm_t *p_vlm = NULL; char *psz_vlmconf; + static const char vlm_object_name[] = "vlm daemon"; /* Avoid multiple creation */ - if( var_Create( p_this->p_libvlc_global, "vlm_mutex", VLC_VAR_MUTEX ) || - var_Get( p_this->p_libvlc_global, "vlm_mutex", &lockval ) ) + if( var_Create( p_this->p_libvlc, "vlm_mutex", VLC_VAR_MUTEX ) || + var_Get( p_this->p_libvlc, "vlm_mutex", &lockval ) ) return NULL; vlc_mutex_lock( lockval.p_address ); @@ -106,7 +121,8 @@ vlm_t *__vlm_New ( vlc_object_t *p_this ) msg_Dbg( p_this, "creating VLM" ); - p_vlm = vlc_object_create( p_this, VLC_OBJECT_VLM ); + p_vlm = vlc_custom_create( p_this, sizeof( *p_vlm ), VLC_OBJECT_VLM, + vlm_object_name ); if( !p_vlm ) { vlc_mutex_unlock( lockval.p_address ); @@ -119,14 +135,13 @@ vlm_t *__vlm_New ( vlc_object_t *p_this ) TAB_INIT( p_vlm->i_schedule, p_vlm->schedule ); p_vlm->i_vod = 0; p_vlm->p_vod = NULL; - vlc_object_yield( p_vlm ); vlc_object_attach( p_vlm, p_this->p_libvlc ); if( vlc_thread_create( p_vlm, "vlm thread", Manage, VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) ) { vlc_mutex_destroy( &p_vlm->lock ); - vlc_object_destroy( p_vlm ); + vlc_object_release( p_vlm ); return NULL; } @@ -151,6 +166,7 @@ vlm_t *__vlm_New ( vlc_object_t *p_this ) } free(psz_vlmconf); + vlc_object_set_destructor( p_vlm, (vlc_destructor_t)vlm_Destructor ); vlc_mutex_unlock( lockval.p_address ); return p_vlm; @@ -161,24 +177,14 @@ vlm_t *__vlm_New ( vlc_object_t *p_this ) *****************************************************************************/ void vlm_Delete( vlm_t *p_vlm ) { - vlc_value_t lockval; - - var_Get( p_vlm->p_libvlc_global, "vlm_mutex", &lockval ); - vlc_mutex_lock( lockval.p_address ); - vlc_object_release( p_vlm ); +} - if( p_vlm->i_refcount > 0 ) - { - vlc_mutex_unlock( lockval.p_address ); - return; - } - - p_vlm->b_die = VLC_TRUE; - vlc_thread_join( p_vlm ); - - vlc_object_detach( p_vlm ); - +/***************************************************************************** + * vlm_Destructor: + *****************************************************************************/ +static void vlm_Destructor( vlm_t *p_vlm ) +{ vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS ); TAB_CLEAN( p_vlm->i_media, p_vlm->media ); @@ -186,9 +192,6 @@ void vlm_Delete( vlm_t *p_vlm ) TAB_CLEAN( p_vlm->schedule, p_vlm->schedule ); vlc_mutex_destroy( &p_vlm->lock ); - - vlc_object_destroy( p_vlm ); - vlc_mutex_unlock( lockval.p_address ); } /***************************************************************************** @@ -364,7 +367,7 @@ static int ExecuteDel( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_st if( p_schedule != NULL ) { - vlm_ScheduleDelete( p_vlm, p_schedule, NULL ); + vlm_ScheduleDelete( p_vlm, p_schedule ); } else if( p_media != NULL ) { @@ -389,7 +392,7 @@ static int ExecuteDel( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_st return VLC_EGENERIC; } - *pp_status = vlm_MessageNew( "del", NULL ); + *pp_status = vlm_MessageNew( "del", vlm_NULL ); return VLC_SUCCESS; } @@ -417,9 +420,52 @@ static int ExecuteShow( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_s return VLC_SUCCESS; } -static int ExecuteHelp( vlm_t *p_vlm, vlm_message_t **pp_status ) +static int ExecuteHelp( vlm_message_t *p_status ) { - *pp_status = vlm_Help( p_vlm, NULL ); + vlm_message_t *message_child; + +#define MessageAdd( a ) \ + vlm_MessageAdd( p_status, vlm_MessageNew( a, vlm_NULL ) ); +#define MessageAddChild( a ) \ + vlm_MessageAdd( message_child, vlm_MessageNew( a, vlm_NULL ) ); + + p_status = vlm_MessageNew( "help", vlm_NULL ); + + message_child = MessageAdd( "Commands Syntax:" ); + MessageAddChild( "new (name) vod|broadcast|schedule [properties]" ); + MessageAddChild( "setup (name) (properties)" ); + MessageAddChild( "show [(name)|media|schedule]" ); + MessageAddChild( "del (name)|all|media|schedule" ); + MessageAddChild( "control (name) [instance_name] (command)" ); + MessageAddChild( "save (config_file)" ); + MessageAddChild( "export" ); + MessageAddChild( "load (config_file)" ); + + message_child = MessageAdd( "Media Proprieties Syntax:" ); + MessageAddChild( "input (input_name)" ); + MessageAddChild( "inputdel (input_name)|all" ); + MessageAddChild( "inputdeln input_number" ); + MessageAddChild( "output (output_name)" ); + MessageAddChild( "option (option_name)[=value]" ); + MessageAddChild( "enabled|disabled" ); + MessageAddChild( "loop|unloop (broadcast only)" ); + MessageAddChild( "mux (mux_name)" ); + + message_child = MessageAdd( "Schedule Proprieties Syntax:" ); + MessageAddChild( "enabled|disabled" ); + MessageAddChild( "append (command_until_rest_of_the_line)" ); + MessageAddChild( "date (year)/(month)/(day)-(hour):(minutes):" + "(seconds)|now" ); + MessageAddChild( "period (years_aka_12_months)/(months_aka_30_days)/" + "(days)-(hours):(minutes):(seconds)" ); + MessageAddChild( "repeat (number_of_repetitions)" ); + + message_child = MessageAdd( "Control Commands Syntax:" ); + MessageAddChild( "play [input_number]" ); + MessageAddChild( "pause" ); + MessageAddChild( "stop" ); + MessageAddChild( "seek [+-](percentage) | [+-](seconds)s | [+-](miliseconds)ms" ); + return VLC_SUCCESS; } @@ -465,7 +511,22 @@ static int ExecuteControl( vlm_t *p_vlm, const char *psz_name, const int i_arg, int i; if( ( psz_argument && sscanf(psz_argument, "%d", &i) == 1 ) && i > 0 && i-1 < p_media->cfg.i_input ) + { i_input_index = i-1; + } + else if( psz_argument ) + { + int j; + vlm_media_t *p_cfg = &p_media->cfg; + for ( j=0; j < p_cfg->i_input; j++) + { + if( !strcmp( p_cfg->ppsz_input[j], psz_argument ) ) + { + i_input_index = j; + break; + } + } + } if( p_media->cfg.b_vod ) i_result = vlm_ControlInternal( p_vlm, VLM_START_MEDIA_VOD_INSTANCE, p_media->cfg.id, psz_instance, i_input_index, NULL ); // we should get here now @@ -581,7 +642,7 @@ static int ExecuteControl( vlm_t *p_vlm, const char *psz_name, const int i_arg, *pp_status = vlm_MessageNew( "control", "unknown error" ); return VLC_SUCCESS; } - *pp_status = vlm_MessageNew( "control", NULL ); + *pp_status = vlm_MessageNew( "control", vlm_NULL ); return VLC_SUCCESS; } @@ -612,7 +673,7 @@ static int ExecuteSave( vlm_t *p_vlm, const char *psz_file, vlm_message_t **pp_s free( psz_save ); fclose( f ); - *pp_status = vlm_MessageNew( "save", NULL ); + *pp_status = vlm_MessageNew( "save", vlm_NULL ); return VLC_SUCCESS; error: @@ -667,7 +728,7 @@ static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_st free( psz_buffer ); - *pp_status = vlm_MessageNew( "load", NULL ); + *pp_status = vlm_MessageNew( "load", vlm_NULL ); return VLC_SUCCESS; } @@ -710,7 +771,7 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule if( i + 1 >= i_property ) { if( b_new ) - vlm_ScheduleDelete( p_vlm, p_schedule, NULL ); + vlm_ScheduleDelete( p_vlm, p_schedule ); return ExecuteSyntaxError( psz_cmd, pp_status ); } @@ -718,7 +779,7 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule i++; } } - *pp_status = vlm_MessageNew( psz_cmd, NULL ); + *pp_status = vlm_MessageNew( psz_cmd, vlm_NULL ); return VLC_SUCCESS; } @@ -730,6 +791,8 @@ static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, vlc_bool_t b_new, int i_result; int i; +#undef ERROR +#undef MISSING #define ERROR( txt ) do { *pp_status = vlm_MessageNew( psz_cmd, txt); goto error; } while(0) if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA, id, &p_cfg ) ) ERROR( "unknown media" ); @@ -781,7 +844,7 @@ static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, vlc_bool_t b_new, int i_index; MISSING( "inputdeln" ); - + i_index = atoi( psz_value ); if( i_index > 0 && i_index <= p_cfg->i_input ) TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[i_index-1] ); @@ -791,8 +854,7 @@ static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, vlc_bool_t b_new, { MISSING( "output" ); - if( p_cfg->psz_output != NULL ) - free( p_cfg->psz_output ); + free( p_cfg->psz_output ); p_cfg->psz_output = *psz_value ? strdup( psz_value ) : NULL; i++; } @@ -821,8 +883,7 @@ static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, vlc_bool_t b_new, if( !p_cfg->b_vod ) ERROR( "invalid mux option for broadcast" ); - if( p_cfg->vod.psz_mux ) - free( p_cfg->vod.psz_mux ); + free( p_cfg->vod.psz_mux ); p_cfg->vod.psz_mux = *psz_value ? strdup( psz_value ) : NULL; i++; } @@ -839,7 +900,7 @@ static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, vlc_bool_t b_new, i_result = vlm_ControlInternal( p_vlm, VLM_CHANGE_MEDIA, p_cfg ); vlm_media_Delete( p_cfg ); - *pp_status = vlm_MessageNew( psz_cmd, NULL ); + *pp_status = vlm_MessageNew( psz_cmd, vlm_NULL ); return i_result; error: @@ -851,6 +912,7 @@ error: } return VLC_EGENERIC; } + static int ExecuteNew( vlm_t *p_vlm, const char *psz_name, const char *psz_type, const int i_property, char *ppsz_property[], vlm_message_t **pp_status ) { /* Check name */ @@ -942,7 +1004,7 @@ static int ExecuteCommand( vlm_t *p_vlm, const char *psz_command, /* support for comments */ if( i_command == 0 && *psz_command == '#') { - p_message = vlm_MessageNew( "", NULL ); + p_message = vlm_MessageNew( "", vlm_NULL ); goto success; } @@ -976,12 +1038,12 @@ static int ExecuteCommand( vlm_t *p_vlm, const char *psz_command, #define IF_EXECUTE( name, check, cmd ) if( !strcmp(ppsz_command[0], name ) ) { if( (check) ) goto syntax_error; if( (cmd) ) goto error; goto success; } if( i_command == 0 ) { - p_message = vlm_MessageNew( "", NULL ); + p_message = vlm_MessageNew( "", vlm_NULL ); goto success; } else IF_EXECUTE( "del", (i_command != 2), ExecuteDel(p_vlm, ppsz_command[1], &p_message) ) else IF_EXECUTE( "show", (i_command > 2), ExecuteShow(p_vlm, i_command > 1 ? ppsz_command[1] : NULL, &p_message) ) - else IF_EXECUTE( "help", (i_command != 1), ExecuteHelp(p_vlm, &p_message) ) + else IF_EXECUTE( "help", (i_command != 1), ExecuteHelp( p_message) ) else IF_EXECUTE( "control", (i_command < 3), ExecuteControl(p_vlm, ppsz_command[1], i_command - 2, &ppsz_command[2], &p_message) ) else IF_EXECUTE( "save", (i_command != 2), ExecuteSave(p_vlm, ppsz_command[1], &p_message) ) else IF_EXECUTE( "export", (i_command != 1), ExecuteExport(p_vlm, &p_message) ) @@ -1033,7 +1095,11 @@ static int64_t vlm_Date(void) ftime( &tm ); return ((int64_t)tm.time) * 1000000 + ((int64_t)tm.millitm) * 1000; #else - return mdate(); + struct timeval tv_date; + + /* gettimeofday() cannot fail given &tv_date is a valid address */ + (void)gettimeofday( &tv_date, NULL ); + return (mtime_t) tv_date.tv_sec * 1000000 + (mtime_t) tv_date.tv_usec; #endif } @@ -1065,14 +1131,13 @@ static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name ) } /* for now, simple delete. After, del with options (last arg) */ -static void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched, - const char *psz_name ) +static void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched ) { if( sched == NULL ) return; TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched ); - if( vlm->i_schedule == 0 && vlm->schedule ) free( vlm->schedule ); + if( vlm->i_schedule == 0 ) free( vlm->schedule ); free( sched->psz_name ); while( sched->i_command ) { @@ -1326,11 +1391,11 @@ vlm_message_t *vlm_MessageNew( const char *psz_name, void vlm_MessageDelete( vlm_message_t *p_message ) { - if( p_message->psz_name ) free( p_message->psz_name ); - if( p_message->psz_value ) free( p_message->psz_value ); + free( p_message->psz_name ); + free( p_message->psz_value ); while( p_message->i_child-- ) vlm_MessageDelete( p_message->child[p_message->i_child] ); - if( p_message->child ) free( p_message->child ); + free( p_message->child ); free( p_message ); } @@ -1351,14 +1416,14 @@ vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message, /***************************************************************************** * Misc utility functions *****************************************************************************/ -static vlm_message_t *vlm_ShowMedia( vlm_t *p_vlm, vlm_media_sys_t *p_media ) +static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media ) { vlm_media_t *p_cfg = &p_media->cfg; vlm_message_t *p_msg; vlm_message_t *p_msg_sub; int i; - p_msg = vlm_MessageNew( p_cfg->psz_name, 0 ); + p_msg = vlm_MessageNew( p_cfg->psz_name, vlm_NULL ); vlm_MessageAdd( p_msg, vlm_MessageNew( "type", p_cfg->b_vod ? "vod" : "broadcast" ) ); vlm_MessageAdd( p_msg, @@ -1371,7 +1436,7 @@ static vlm_message_t *vlm_ShowMedia( vlm_t *p_vlm, vlm_media_sys_t *p_media ) vlm_MessageAdd( p_msg, vlm_MessageNew( "loop", p_cfg->broadcast.b_loop ? "yes" : "no" ) ); - p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "inputs", NULL ) ); + p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "inputs", vlm_NULL ) ); for( i = 0; i < p_cfg->i_input; i++ ) { char *psz_tmp; @@ -1384,11 +1449,11 @@ static vlm_message_t *vlm_ShowMedia( vlm_t *p_vlm, vlm_media_sys_t *p_media ) vlm_MessageAdd( p_msg, vlm_MessageNew( "output", p_cfg->psz_output ? p_cfg->psz_output : "" ) ); - p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "options", 0 ) ); + p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "options", vlm_NULL ) ); for( i = 0; i < p_cfg->i_option; i++ ) - vlm_MessageAdd( p_msg_sub, vlm_MessageNew( p_cfg->ppsz_option[i], 0 ) ); + vlm_MessageAdd( p_msg_sub, vlm_MessageNew( p_cfg->ppsz_option[i], vlm_NULL ) ); - p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "instances", NULL ) ); + p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "instances", vlm_NULL ) ); for( i = 0; i < p_media->i_instance; i++ ) { vlm_media_instance_sys_t *p_instance = p_media->instance[i]; @@ -1400,7 +1465,7 @@ static vlm_message_t *vlm_ShowMedia( vlm_t *p_vlm, vlm_media_sys_t *p_media ) if( p_instance->p_input ) var_Get( p_instance->p_input, "state", &val ); - p_msg_instance = vlm_MessageAdd( p_msg_sub, vlm_MessageNew( "instance" , NULL ) ); + p_msg_instance = vlm_MessageAdd( p_msg_sub, vlm_MessageNew( "instance" , vlm_NULL ) ); vlm_MessageAdd( p_msg_instance, vlm_MessageNew( "name" , p_instance->psz_name ? p_instance->psz_name : "default" ) ); @@ -1440,9 +1505,9 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media, { if( media != NULL ) { - vlm_message_t *p_msg = vlm_MessageNew( "show", NULL ); + vlm_message_t *p_msg = vlm_MessageNew( "show", vlm_NULL ); if( p_msg ) - vlm_MessageAdd( p_msg, vlm_ShowMedia( vlm, media ) ); + vlm_MessageAdd( p_msg, vlm_ShowMedia( media ) ); return p_msg; } @@ -1454,9 +1519,9 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media, vlm_message_t *msg_child; char buffer[100]; - msg = vlm_MessageNew( "show", NULL ); + msg = vlm_MessageNew( "show", vlm_NULL ); msg_schedule = - vlm_MessageAdd( msg, vlm_MessageNew( schedule->psz_name, 0 ) ); + vlm_MessageAdd( msg, vlm_MessageNew( schedule->psz_name, vlm_NULL ) ); vlm_MessageAdd( msg_schedule, vlm_MessageNew("type", "schedule") ); @@ -1471,13 +1536,7 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media, time_t i_time = (time_t)( schedule->i_date / 1000000 ); char *psz_date; -#ifdef HAVE_LOCALTIME_R localtime_r( &i_time, &date); -#else - struct tm *p_date = localtime( &i_time ); - date = *p_date; -#endif - asprintf( &psz_date, "%d/%d/%d-%d:%d:%d", date.tm_year + 1900, date.tm_mon + 1, date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec ); @@ -1524,12 +1583,12 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media, vlm_MessageAdd( msg_schedule, vlm_MessageNew( "repeat", buffer ) ); msg_child = - vlm_MessageAdd( msg_schedule, vlm_MessageNew("commands", 0) ); + vlm_MessageAdd( msg_schedule, vlm_MessageNew("commands", vlm_NULL ) ); for( i = 0; i < schedule->i_command; i++ ) { vlm_MessageAdd( msg_child, - vlm_MessageNew( schedule->command[i], NULL ) ); + vlm_MessageNew( schedule->command[i], vlm_NULL ) ); } return msg; @@ -1554,12 +1613,12 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media, asprintf( &psz_count, "( %d broadcast - %d vod )", i_broadcast, i_vod); - p_msg = vlm_MessageNew( "show", NULL ); + p_msg = vlm_MessageNew( "show", vlm_NULL ); p_msg_child = vlm_MessageAdd( p_msg, vlm_MessageNew( "media", psz_count ) ); free( psz_count ); for( i = 0; i < vlm->i_media; i++ ) - vlm_MessageAdd( p_msg_child, vlm_ShowMedia( vlm, vlm->media[i] ) ); + vlm_MessageAdd( p_msg_child, vlm_ShowMedia( vlm->media[i] ) ); return p_msg; } @@ -1570,8 +1629,8 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media, vlm_message_t *msg; vlm_message_t *msg_child; - msg = vlm_MessageNew( "show", NULL ); - msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "schedule", NULL ) ); + msg = vlm_MessageNew( "show", vlm_NULL ); + msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "schedule", vlm_NULL ) ); for( i = 0; i < vlm->i_schedule; i++ ) { @@ -1580,7 +1639,7 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media, mtime_t i_time, i_next_date; msg_schedule = vlm_MessageAdd( msg_child, - vlm_MessageNew( s->psz_name, 0 ) ); + vlm_MessageNew( s->psz_name, vlm_NULL ) ); vlm_MessageAdd( msg_schedule, vlm_MessageNew( "enabled", s->b_enabled ? "yes" : "no" ) ); @@ -1639,64 +1698,10 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media, else { - return vlm_MessageNew( "show", NULL ); + return vlm_MessageNew( "show", vlm_NULL ); } } -static vlm_message_t *vlm_Help( vlm_t *vlm, char *psz_filter ) -{ - vlm_message_t *message, *message_child; - -#define MessageAdd( a ) \ - vlm_MessageAdd( message, vlm_MessageNew( a, NULL ) ); -#define MessageAddChild( a ) \ - vlm_MessageAdd( message_child, vlm_MessageNew( a, NULL ) ); - - if( psz_filter == NULL ) - { - message = vlm_MessageNew( "help", NULL ); - - message_child = MessageAdd( "Commands Syntax:" ); - MessageAddChild( "new (name) vod|broadcast|schedule [properties]" ); - MessageAddChild( "setup (name) (properties)" ); - MessageAddChild( "show [(name)|media|schedule]" ); - MessageAddChild( "del (name)|all|media|schedule" ); - MessageAddChild( "control (name) [instance_name] (command)" ); - MessageAddChild( "save (config_file)" ); - MessageAddChild( "export" ); - MessageAddChild( "load (config_file)" ); - - message_child = MessageAdd( "Media Proprieties Syntax:" ); - MessageAddChild( "input (input_name)" ); - MessageAddChild( "inputdel (input_name)|all" ); - MessageAddChild( "inputdeln input_number" ); - MessageAddChild( "output (output_name)" ); - MessageAddChild( "option (option_name)[=value]" ); - MessageAddChild( "enabled|disabled" ); - MessageAddChild( "loop|unloop (broadcast only)" ); - MessageAddChild( "mux (mux_name)" ); - - message_child = MessageAdd( "Schedule Proprieties Syntax:" ); - MessageAddChild( "enabled|disabled" ); - MessageAddChild( "append (command_until_rest_of_the_line)" ); - MessageAddChild( "date (year)/(month)/(day)-(hour):(minutes):" - "(seconds)|now" ); - MessageAddChild( "period (years_aka_12_months)/(months_aka_30_days)/" - "(days)-(hours):(minutes):(seconds)" ); - MessageAddChild( "repeat (number_of_repetitions)" ); - - message_child = MessageAdd( "Control Commands Syntax:" ); - MessageAddChild( "play [input_number]" ); - MessageAddChild( "pause" ); - MessageAddChild( "stop" ); - MessageAddChild( "seek [+-](percentage) | [+-](seconds)s | [+-](miliseconds)ms" ); - - return message; - } - - return vlm_MessageNew( "help", NULL ); -} - /***************************************************************************** * Config handling functions *****************************************************************************/ @@ -1833,6 +1838,7 @@ static char *Save( vlm_t *vlm ) /* now we have the length of save */ p = save = malloc( i_length ); + if( !save ) return NULL; *save = '\0'; p += sprintf( p, "%s", psz_header ); @@ -1879,13 +1885,7 @@ static char *Save( vlm_t *vlm ) struct tm date; time_t i_time = (time_t) ( schedule->i_date / 1000000 ); -#ifdef HAVE_LOCALTIME_R localtime_r( &i_time, &date); -#else - struct tm *p_date = localtime( &i_time ); - date = *p_date; -#endif - p += sprintf( p, "new %s schedule ", schedule->psz_name); if( schedule->b_enabled == VLC_TRUE ) @@ -2236,37 +2236,32 @@ static int vlm_OnMediaUpdate( vlm_t *p_vlm, vlm_media_sys_t *p_media ) char *psz_dup; int i; - input_ItemClean( &p_media->vod.item ); - input_ItemInit( VLC_OBJECT(p_vlm), &p_media->vod.item ); + vlc_gc_decref( p_media->vod.p_item ); + p_media->vod.p_item = input_ItemNew( p_vlm, p_cfg->ppsz_input[0], + p_cfg->psz_name ); if( p_cfg->psz_output ) asprintf( &psz_output, "%s:description", p_cfg->psz_output ); else asprintf( &psz_output, "#description" ); - p_media->vod.item.psz_uri = strdup( p_cfg->ppsz_input[0] ); - - TAB_INIT( p_media->vod.item.i_options, p_media->vod.item.ppsz_options ); - asprintf( &psz_dup, "sout=%s", psz_output); - TAB_APPEND( p_media->vod.item.i_options, p_media->vod.item.ppsz_options, psz_dup ); + input_ItemAddOption( p_media->vod.p_item, psz_dup ); + free( psz_dup ); for( i = 0; i < p_cfg->i_option; i++ ) - { - psz_dup = strdup( p_cfg->ppsz_option[i] ); - TAB_APPEND( p_media->vod.item.i_options, p_media->vod.item.ppsz_options, psz_dup ); - } - psz_dup = strdup( "no-sout-keep" ); - TAB_APPEND( p_media->vod.item.i_options, p_media->vod.item.ppsz_options, psz_dup ); + input_ItemAddOption( p_media->vod.p_item, + p_cfg->ppsz_option[i] ); + input_ItemAddOption( p_media->vod.p_item, "no-sout-keep" ); asprintf( &psz_header, _("Media: %s"), p_cfg->psz_name ); - if( (p_input = input_CreateThreadExtended( p_vlm, &p_media->vod.item, psz_header, NULL ) ) ) + if( (p_input = input_CreateThreadExtended( p_vlm, p_media->vod.p_item, psz_header, NULL ) ) ) { while( !p_input->b_eof && !p_input->b_error ) msleep( 100000 ); input_StopThread( p_input ); - input_DestroyThreadExtended( p_input, NULL ); + vlc_object_release( p_input ); } free( psz_output ); free( psz_header ); @@ -2281,7 +2276,8 @@ static int vlm_OnMediaUpdate( vlm_t *p_vlm, vlm_media_sys_t *p_media ) fourcc[0] = tolower(fourcc[0]); fourcc[1] = tolower(fourcc[1]); fourcc[2] = tolower(fourcc[2]); fourcc[3] = tolower(fourcc[3]); - item = p_media->vod.item; + /* XXX: Don't do it that way, but properly use a new input item ref. */ + item = *p_media->vod.p_item; item.i_es = 1; item.es = &p_es; es_format_Init( &es, VIDEO_ES, *((int *)fourcc) ); @@ -2292,7 +2288,7 @@ static int vlm_OnMediaUpdate( vlm_t *p_vlm, vlm_media_sys_t *p_media ) else { p_media->vod.p_media = - p_vlm->p_vod->pf_media_new( p_vlm->p_vod, p_cfg->psz_name, &p_media->vod.item ); + p_vlm->p_vod->pf_media_new( p_vlm->p_vod, p_cfg->psz_name, p_media->vod.p_item ); } } } @@ -2325,6 +2321,7 @@ static int vlm_ControlMediaChange( vlm_t *p_vlm, vlm_media_t *p_cfg ) return vlm_OnMediaUpdate( p_vlm, p_media ); } + static int vlm_ControlMediaAdd( vlm_t *p_vlm, vlm_media_t *p_cfg, int64_t *p_id ) { vlm_media_sys_t *p_media; @@ -2337,14 +2334,15 @@ static int vlm_ControlMediaAdd( vlm_t *p_vlm, vlm_media_t *p_cfg, int64_t *p_id /* Check if we need to load the VOD server */ if( p_cfg->b_vod && !p_vlm->i_vod ) { - p_vlm->p_vod = vlc_object_create( p_vlm, VLC_OBJECT_VOD ); + p_vlm->p_vod = vlc_custom_create( VLC_OBJECT(p_vlm), sizeof( vod_t ), + VLC_OBJECT_GENERIC, "vod server" ); vlc_object_attach( p_vlm->p_vod, p_vlm ); p_vlm->p_vod->p_module = module_Need( p_vlm->p_vod, "vod server", 0, 0 ); if( !p_vlm->p_vod->p_module ) { msg_Err( p_vlm, "cannot find vod server" ); vlc_object_detach( p_vlm->p_vod ); - vlc_object_destroy( p_vlm->p_vod ); + vlc_object_release( p_vlm->p_vod ); p_vlm->p_vod = 0; return VLC_EGENERIC; } @@ -2352,17 +2350,23 @@ static int vlm_ControlMediaAdd( vlm_t *p_vlm, vlm_media_t *p_cfg, int64_t *p_id p_vlm->p_vod->p_data = p_vlm; p_vlm->p_vod->pf_media_control = vlm_MediaVodControl; } - if( p_cfg->b_vod ) - p_vlm->i_vod++; p_media = malloc( sizeof( vlm_media_sys_t ) ); + if( !p_media ) + { + msg_Err( p_vlm, "out of memory" ); + return VLC_ENOMEM; + } memset( p_media, 0, sizeof(vlm_media_sys_t) ); + if( p_cfg->b_vod ) + p_vlm->i_vod++; + vlm_media_Copy( &p_media->cfg, p_cfg ); p_media->cfg.id = p_vlm->i_id++; /* FIXME do we do something here if enabled is true ? */ - input_ItemInit( VLC_OBJECT(p_vlm), &p_media->vod.item ); + p_media->vod.p_item = input_ItemNew( p_vlm, NULL, NULL ); p_media->vod.p_media = NULL; TAB_INIT( p_media->i_instance, p_media->instance ); @@ -2395,7 +2399,7 @@ static int vlm_ControlMediaDel( vlm_t *p_vlm, int64_t id ) vlm_media_Clean( &p_media->cfg ); - input_ItemClean( &p_media->vod.item ); + vlc_gc_decref( p_media->vod.p_item ); TAB_REMOVE( p_vlm->i_media, p_vlm->media, p_media ); @@ -2406,7 +2410,7 @@ static int vlm_ControlMediaDel( vlm_t *p_vlm, int64_t id ) { module_Unneed( p_vlm->p_vod, p_vlm->p_vod->p_module ); vlc_object_detach( p_vlm->p_vod ); - vlc_object_destroy( p_vlm->p_vod ); + vlc_object_release( p_vlm->p_vod ); p_vlm->p_vod = NULL; } return VLC_SUCCESS; @@ -2481,7 +2485,7 @@ static vlm_media_instance_sys_t *vlm_MediaInstanceNew( vlm_t *p_vlm, const char if( psz_name ) p_instance->psz_name = strdup( psz_name ); - input_ItemInit( VLC_OBJECT(p_vlm), &p_instance->item ); + p_instance->p_item = input_ItemNew( p_vlm, NULL, NULL ); p_instance->i_index = 0; p_instance->b_sout_keep = VLC_FALSE; @@ -2495,14 +2499,14 @@ static void vlm_MediaInstanceDelete( vlm_media_instance_sys_t *p_instance ) if( p_instance->p_input ) { input_StopThread( p_instance->p_input ); - input_DestroyThreadExtended( p_instance->p_input, &p_instance->p_sout ); + p_instance->p_sout = input_DetachSout( p_instance->p_input ); + vlc_object_release( p_instance->p_input ); } if( p_instance->p_sout ) sout_DeleteInstance( p_instance->p_sout ); - input_ItemClean( &p_instance->item ); - if( p_instance->psz_name ) - free( p_instance->psz_name ); + vlc_gc_decref( p_instance->p_item ); + free( p_instance->psz_name ); free( p_instance ); } @@ -2528,15 +2532,13 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char * if( !p_instance ) { vlm_media_t *p_cfg = &p_media->cfg; - char *psz_keep; + const char *psz_keep; int i; p_instance = vlm_MediaInstanceNew( p_vlm, psz_id ); if( !p_instance ) return VLC_ENOMEM; - TAB_INIT( p_instance->item.i_options, p_instance->item.ppsz_options ); - if( p_cfg->psz_output != NULL || psz_vod_output != NULL ) { char *psz_buffer; @@ -2544,7 +2546,8 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char * p_cfg->psz_output ? p_cfg->psz_output : "", (p_cfg->psz_output && psz_vod_output) ? ":" : psz_vod_output ? "#" : "", psz_vod_output ? psz_vod_output : "" ); - TAB_APPEND( p_instance->item.i_options, p_instance->item.ppsz_options, psz_buffer ); + input_ItemAddOption( p_instance->p_item, psz_buffer ); + free( psz_buffer ); } for( i = 0; i < p_cfg->i_option; i++ ) @@ -2554,16 +2557,16 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char * else if( !strcmp( p_cfg->ppsz_option[i], "nosout-keep" ) || !strcmp( p_cfg->ppsz_option[i], "no-sout-keep" ) ) p_instance->b_sout_keep = VLC_FALSE; else - TAB_APPEND( p_instance->item.i_options, p_instance->item.ppsz_options, strdup( p_cfg->ppsz_option[i] ) ); + input_ItemAddOption( p_instance->p_item, p_cfg->ppsz_option[i] ); } /* We force the right sout-keep value (avoid using the sout-keep from the global configuration) * FIXME implement input list for VOD (need sout-keep) * */ if( !p_cfg->b_vod && p_instance->b_sout_keep ) - psz_keep = strdup( "sout-keep" ); + psz_keep = "sout-keep"; else - psz_keep = strdup( "no-sout-keep" ); - TAB_APPEND( p_instance->item.i_options, p_instance->item.ppsz_options, psz_keep ); + psz_keep = "no-sout-keep"; + input_ItemAddOption( p_instance->p_item, psz_keep ); TAB_APPEND( p_media->i_instance, p_media->instance, p_instance ); } @@ -2580,7 +2583,8 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char * } input_StopThread( p_instance->p_input ); - input_DestroyThreadExtended( p_instance->p_input, &p_instance->p_sout ); + p_instance->p_sout = input_DetachSout( p_instance->p_input ); + vlc_object_release( p_instance->p_input ); if( !p_instance->b_sout_keep && p_instance->p_sout ) { sout_DeleteInstance( p_instance->p_sout ); @@ -2590,12 +2594,10 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char * /* Start new one */ p_instance->i_index = i_input_index; - if( p_instance->item.psz_uri ) - free( p_instance->item.psz_uri ); - p_instance->item.psz_uri = strdup( p_media->cfg.ppsz_input[p_instance->i_index] ); + input_item_SetURI( p_instance->p_item, p_media->cfg.ppsz_input[p_instance->i_index] ) ; asprintf( &psz_log, _("Media: %s"), p_media->cfg.psz_name ); - p_instance->p_input = input_CreateThreadExtended( p_vlm, &p_instance->item, psz_log, p_instance->p_sout ); + p_instance->p_input = input_CreateThreadExtended( p_vlm, p_instance->p_item, psz_log, p_instance->p_sout ); if( !p_instance->p_input ) { TAB_REMOVE( p_media->i_instance, p_media->instance, p_instance ); @@ -2732,7 +2734,7 @@ static int vlm_ControlMediaInstanceClear( vlm_t *p_vlm, int64_t id ) static int vlm_ControlScheduleClear( vlm_t *p_vlm ) { while( p_vlm->i_schedule > 0 ) - vlm_ScheduleDelete( p_vlm, p_vlm->schedule[0], NULL ); + vlm_ScheduleDelete( p_vlm, p_vlm->schedule[0] ); return VLC_SUCCESS; } @@ -2892,31 +2894,38 @@ vlm_t *__vlm_New( vlc_object_t *a ) msg_Err( a, "VideoLAN manager support is disabled" ); return NULL; } + void vlm_Delete( vlm_t *a ) { - ; + (void)a; } -int vlm_ExecuteCommand( vlm_t *a, char *b, vlm_message_t **c ) + +int vlm_ExecuteCommand( vlm_t *a, const char *b, vlm_message_t **c ) { - return -1; + abort(); } + vlm_message_t *vlm_MessageNew( const char *psz_name, const char *psz_format, ... ) { + (void)psz_name; (void)psz_format; return NULL; } + vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message, vlm_message_t *p_child ) { - return NULL; + abort(); } + void vlm_MessageDelete( vlm_message_t *a ) { - ; + (void)a; } int vlm_Control( vlm_t *p_vlm, int i_query, ... ) { + (void)p_vlm; (void)i_query; return VLC_EGENERIC; }