- if( !strcmp( psz_cmd, "loop" ) )
- {
- media->b_loop = VLC_TRUE;
- }
- else if( !strcmp( psz_cmd, "unloop" ) )
- {
- media->b_loop = VLC_FALSE;
- }
- else if( !strcmp( psz_cmd, "enabled" ) )
- {
- media->b_enabled = VLC_TRUE;
- }
- else if( !strcmp( psz_cmd, "disabled" ) )
- {
- media->b_enabled = VLC_FALSE;
- }
- else if( !strcmp( psz_cmd, "mux" ) )
- {
- if( media->psz_mux ) free( media->psz_mux );
- media->psz_mux = NULL;
- if( psz_value ) media->psz_mux = strdup( psz_value );
- }
- else if( !strcmp( psz_cmd, "input" ) )
- {
- char *input;
-
- input = strdup( psz_value );
-
- TAB_APPEND( media->i_input, media->input, input );
- }
- else if( !strcmp( psz_cmd, "inputdel" ) && !strcmp( psz_value, "all" ) )
- {
- while( media->i_input > 0 )
- {
- TAB_REMOVE( media->i_input, media->input, media->input[0] );
- }
- }
- else if( !strcmp( psz_cmd, "inputdel" ) )
- {
- char *input;
- int i;
-
- input = strdup( psz_value );
-
- for( i = 0; i < media->i_input; i++ )
- {
- if( !strcmp( input, media->input[i] ) )
- {
- TAB_REMOVE( media->i_input, media->input, media->input[i] );
- break;
- }
- }
- }
- else if( !strcmp( psz_cmd, "inputdeln" ) )
- {
- int index = atoi( psz_value );
- if( index > 0 && index <= media->i_input )
- {
- TAB_REMOVE( media->i_input, media->input, media->input[index-1] );
- }
- }
- else if( !strcmp( psz_cmd, "output" ) )
- {
- if( media->psz_output != NULL )
- {
- free( media->psz_output );
- }
- media->psz_output = strdup( psz_value );
- }
- else if( !strcmp( psz_cmd, "option" ) )
- {
- char *psz_option;
- psz_option = strdup( psz_value );
-
- TAB_APPEND( media->i_option, media->option, psz_option );
- }
- else
- {
- return VLC_EGENERIC;
- }
-
- /* Check if we need to create/delete a vod media */
- if( media->i_type == VOD_TYPE )
- {
- if( !media->b_enabled && media->vod_media )
- {
- vlm->vod->pf_media_del( vlm->vod, media->vod_media );
- media->vod_media = 0;
- }
- else if( media->b_enabled && !media->vod_media && media->i_input )
- {
- /* Pre-parse the input */
- input_thread_t *p_input;
- char *psz_output;
- char *psz_header;
- int i;
-
- input_ItemClean( &media->item );
- input_ItemInit( VLC_OBJECT(vlm), &media->item );
-
- if( media->psz_output )
- asprintf( &psz_output, "%s:description", media->psz_output );
- else
- asprintf( &psz_output, "#description" );
-
- media->item.psz_uri = strdup( media->input[0] );
- media->item.ppsz_options = malloc( sizeof( char* ) );
- asprintf( &media->item.ppsz_options[0], "sout=%s", psz_output);
- media->item.i_options = 1;
- for( i = 0; i < media->i_option; i++ )
- {
- media->item.i_options++;
- media->item.ppsz_options =
- realloc( media->item.ppsz_options,
- media->item.i_options * sizeof( char* ) );
- media->item.ppsz_options[ media->item.i_options - 1 ] =
- strdup( media->option[i] );
- }
-
- asprintf( &psz_header, _("Media: %s"), media->psz_name );
-
- if( (p_input = input_CreateThread2( vlm, &media->item, psz_header
- ) ) )
- {
- while( !p_input->b_eof && !p_input->b_error ) msleep( 100000 );
-
- input_StopThread( p_input );
- input_DestroyThread( p_input );
- }
- free( psz_output );
- free( psz_header );
-
- if( media->psz_mux )
- {
- input_item_t item;
- es_format_t es, *p_es = &es;
- char fourcc[5];
-
- sprintf( fourcc, "%4.4s", media->psz_mux );
- fourcc[0] = tolower(fourcc[0]); fourcc[1] = tolower(fourcc[1]);
- fourcc[2] = tolower(fourcc[2]); fourcc[3] = tolower(fourcc[3]);
-
- item = media->item;
- item.i_es = 1;
- item.es = &p_es;
- es_format_Init( &es, VIDEO_ES, *((int *)fourcc) );
-
- media->vod_media =
- vlm->vod->pf_media_new( vlm->vod, media->psz_name, &item );
- return VLC_SUCCESS;
- }
-
- media->vod_media =
- vlm->vod->pf_media_new( vlm->vod, media->psz_name,
- &media->item );
- }
- }
-
- return VLC_SUCCESS;
-}
-
-int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, const char *psz_id,
- const char *psz_command, const char *psz_args )
-{
- vlm_media_instance_t *p_instance;
- int i;
- char *psz_header;
-
- p_instance = vlm_MediaInstanceSearch( vlm, media, psz_id );
-
- if( !strcmp( psz_command, "play" ) )
- {
- if( !media->b_enabled || media->i_input == 0 ) return 0;
-
- if( !p_instance )
- {
- p_instance = malloc( sizeof(vlm_media_instance_t) );
- if( !p_instance ) return VLC_EGENERIC;
- memset( p_instance, 0, sizeof(vlm_media_instance_t) );
- input_ItemInit( VLC_OBJECT(vlm), &p_instance->item );
- p_instance->p_input = NULL;
-
- if( ( media->psz_output != NULL ) || ( media->psz_vod_output != NULL ) )
- {
- p_instance->item.ppsz_options = malloc( sizeof( char* ) );
- asprintf( &p_instance->item.ppsz_options[0], "sout=%s%s%s",
- media->psz_output ? media->psz_output : "",
- (media->psz_output && media->psz_vod_output) ?
- ":" : media->psz_vod_output ? "#" : "",
- media->psz_vod_output ? media->psz_vod_output : "" );
- p_instance->item.i_options = 1;
- }
-
- for( i = 0; i < media->i_option; i++ )
- {
- p_instance->item.i_options++;
- p_instance->item.ppsz_options =
- realloc( p_instance->item.ppsz_options,
- p_instance->item.i_options * sizeof( char* ) );
- p_instance->item.ppsz_options[p_instance->item.i_options - 1] =
- strdup( media->option[i] );
- }
-
- p_instance->psz_name = psz_id ? strdup( psz_id ) : NULL;
- TAB_APPEND( media->i_instance, media->instance, p_instance );
- }
-
- if( ( psz_args && sscanf(psz_args, "%d", &i) == 1 ) && i > 0 && i-1 < media->i_input )
- {
- p_instance->i_index = i-1;
- }
-
- if( p_instance->item.psz_uri ) free( p_instance->item.psz_uri );
- p_instance->item.psz_uri =
- strdup( media->input[p_instance->i_index] );
-
- if( p_instance->p_input )
- {
- input_StopThread( p_instance->p_input );
- input_DestroyThread( p_instance->p_input );
- }
-
- asprintf( &psz_header, _("Media: %s"), media->psz_name );
- p_instance->p_input = input_CreateThread2( vlm, &p_instance->item,
- psz_header );
- if( !p_instance->p_input )
- {
- TAB_REMOVE( media->i_instance, media->instance, p_instance );
- input_ItemClean( &p_instance->item );
- if( p_instance->psz_name ) free( p_instance->psz_name );
- }
- free( psz_header );
-
- return VLC_SUCCESS;
- }
-
- if( !p_instance ) return VLC_EGENERIC;
-
- if( !strcmp( psz_command, "seek" ) )
- {
- if( psz_args )
- {
- vlc_bool_t i_rel;
- float f_value = i18n_atof( psz_args );
- if( psz_args[0] == '+' || psz_args[0] == '-' )
- i_rel = VLC_TRUE;
- else
- i_rel = VLC_FALSE;
- if( strstr( psz_args, "ms" ) )
- {
- /* milliseconds */
- int64_t i_msec = 1000 * (int64_t)atoi( psz_args );
- if( i_rel )
- {
- var_SetTime( p_instance->p_input, "time-offset",
- i_msec );
- }
- else if( i_msec >= 0
- && i_msec < var_GetTime( p_instance->p_input, "length" ) )
- {
- var_SetTime( p_instance->p_input, "time",
- i_msec );
- }
- }
- else if( strchr( psz_args, 's' ) )
- {
- /* seconds */
- int64_t i_sec = 1000000 * (int64_t)atoi( psz_args );
- if( i_rel )
- {
- var_SetTime( p_instance->p_input, "time-offset",
- i_sec );
- }
- else if( i_sec >= 0
- && i_sec < var_GetTime( p_instance->p_input, "length" ) )
- {
- var_SetTime( p_instance->p_input, "time",
- i_sec );
- }
- }
- else
- {
- /* percentage */
- f_value /= 100.;
- if( i_rel )
- {
- float f_orig = var_GetFloat( p_instance->p_input,
- "position" );
- f_value += f_orig;
- }
- if( f_value >= 0.0 && f_value <= 1.0 )
- {
- var_SetFloat( p_instance->p_input, "position",
- f_value );
- return VLC_SUCCESS;
- }
- }
- }
- }
- else if( !strcmp( psz_command, "rewind" ) )
- {
- float f_pos;
- float f_scale;
-
- if( psz_args )
- {
- f_scale = i18n_atof( psz_args );
- f_pos = var_GetFloat( p_instance->p_input, "position" );
- f_pos -= (f_scale / 1000.0);
- if( f_pos < 0. )
- f_pos = 0.;
- var_SetFloat( p_instance->p_input, "position", f_pos );
- return VLC_SUCCESS;
- }
- }
- else if( !strcmp( psz_command, "forward" ) )
- {
- float f_pos;
- float f_scale;
-
- if( psz_args )
- {
- f_scale = i18n_atof( psz_args );
- f_pos = var_GetFloat( p_instance->p_input, "position" );
- f_pos += (f_scale / 1000.0);
- if( f_pos > 1.0 )
- f_pos = 1.0;
- var_SetFloat( p_instance->p_input, "position", f_pos );
- return VLC_SUCCESS;
- }
- }
- else if( !strcmp( psz_command, "stop" ) )
- {
- TAB_REMOVE( media->i_instance, media->instance, p_instance );
-
- if( p_instance->p_input )
- {
- input_StopThread( p_instance->p_input );
- input_DestroyThread( p_instance->p_input );
- }
-
- input_ItemClean( &p_instance->item );
- if( p_instance->psz_name ) free( p_instance->psz_name );
- free( p_instance );
-
- return VLC_SUCCESS;
- }
- else if( !strcmp( psz_command, "pause" ) )
- {
- int i_state;
-
- if( !p_instance->p_input ) return VLC_SUCCESS;
-
- i_state = var_GetInteger( p_instance->p_input, "state" );
-
- if( i_state == PAUSE_S ) i_state = PLAYING_S;
- else i_state = PAUSE_S;
- var_SetInteger( p_instance->p_input, "state", i_state );
-
- return VLC_SUCCESS;
- }
-
- return VLC_EGENERIC;
-}
-
-/*****************************************************************************
- * Schedule handling
- *****************************************************************************/
-static int64_t vlm_Date(void)
-{
-#ifdef WIN32
- struct timeb tm;
- ftime( &tm );
- return ((int64_t)tm.time) * 1000000 + ((int64_t)tm.millitm) * 1000;
-#else
- return mdate();
-#endif
-}
-
-vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name )
-{
- vlm_schedule_t *p_sched = malloc( sizeof( vlm_schedule_t ) );
-
- if( !p_sched )
- {
- return NULL;
- }
-
- if( !psz_name )
- {
- return NULL;
- }
-
- p_sched->psz_name = strdup( psz_name );
- p_sched->b_enabled = VLC_FALSE;
- p_sched->i_command = 0;
- p_sched->command = NULL;
- p_sched->i_date = 0;
- p_sched->i_period = 0;
- p_sched->i_repeat = -1;
-
- TAB_APPEND( vlm->i_schedule, vlm->schedule, p_sched );
-
- return p_sched;
-}
-
-/* for now, simple delete. After, del with options (last arg) */
-void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_t *sched,
- const char *psz_name )
-{
- if( sched == NULL ) return;
-
- TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched );
-
- if( vlm->i_schedule == 0 && vlm->schedule ) free( vlm->schedule );
- free( sched->psz_name );
- while( sched->i_command )
- {
- char *psz_cmd = sched->command[0];
- TAB_REMOVE( sched->i_command, sched->command, psz_cmd );
- free( psz_cmd );
- }
- free( sched );
-}
-
-static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *vlm, const char *psz_name )
-{
- int i;
-
- for( i = 0; i < vlm->i_schedule; i++ )
- {
- if( strcmp( psz_name, vlm->schedule[i]->psz_name ) == 0 )
- {
- return vlm->schedule[i];
- }
- }
-
- return NULL;
-}
-
-/* Ok, setup schedule command will be able to support only one (argument value) at a time */
-int vlm_ScheduleSetup( vlm_schedule_t *schedule, const char *psz_cmd,
- const char *psz_value )
-{
- if( !strcmp( psz_cmd, "enabled" ) )
- {
- schedule->b_enabled = VLC_TRUE;
- }
- else if( !strcmp( psz_cmd, "disabled" ) )
- {
- schedule->b_enabled = VLC_FALSE;
- }
-#if !defined( UNDER_CE )
- else if( !strcmp( psz_cmd, "date" ) )
- {
- struct tm time;
- const char *p;
- time_t date;
-
- time.tm_sec = 0; /* seconds */
- time.tm_min = 0; /* minutes */
- time.tm_hour = 0; /* hours */
- time.tm_mday = 0; /* day of the month */
- time.tm_mon = 0; /* month */
- time.tm_year = 0; /* year */
- time.tm_wday = 0; /* day of the week */
- time.tm_yday = 0; /* day in the year */
- time.tm_isdst = -1; /* daylight saving time */
-
- /* date should be year/month/day-hour:minutes:seconds */
- p = strchr( psz_value, '-' );
-
- if( !strcmp( psz_value, "now" ) )
- {
- schedule->i_date = 0;
- }
- else if( (p == NULL) && sscanf( psz_value, "%d:%d:%d", &time.tm_hour,
- &time.tm_min, &time.tm_sec ) != 3 )
- /* it must be a hour:minutes:seconds */
- {
- return 1;
- }
- else
- {
- unsigned i,j,k;
-
- switch( sscanf( p + 1, "%u:%u:%u", &i, &j, &k ) )
- {
- case 1:
- time.tm_sec = i;
- break;
- case 2:
- time.tm_min = i;
- time.tm_sec = j;
- break;
- case 3:
- time.tm_hour = i;
- time.tm_min = j;
- time.tm_sec = k;
- break;
- default:
- return 1;
- }
-
- switch( sscanf( psz_value, "%d/%d/%d", &i, &j, &k ) )
- {
- case 1:
- time.tm_mday = i;
- break;
- case 2:
- time.tm_mon = i - 1;
- time.tm_mday = j;
- break;
- case 3:
- time.tm_year = i - 1900;
- time.tm_mon = j - 1;
- time.tm_mday = k;
- break;
- default:
- return 1;
- }
-
- date = mktime( &time );
- schedule->i_date = ((mtime_t) date) * 1000000;
- }
- }
- else if( !strcmp( psz_cmd, "period" ) )
- {
- struct tm time;
- const char *p;
- const char *psz_time = NULL, *psz_date = NULL;
- time_t date;
- unsigned i,j,k;
-
- /* First, if date or period are modified, repeat should be equal to -1 */
- schedule->i_repeat = -1;
-
- time.tm_sec = 0; /* seconds */
- time.tm_min = 0; /* minutes */
- time.tm_hour = 0; /* hours */
- time.tm_mday = 0; /* day of the month */
- time.tm_mon = 0; /* month */
- time.tm_year = 0; /* year */
- time.tm_wday = 0; /* day of the week */
- time.tm_yday = 0; /* day in the year */
- time.tm_isdst = -1; /* daylight saving time */
-
- /* date should be year/month/day-hour:minutes:seconds */
- p = strchr( psz_value, '-' );
- if( p )
- {
- psz_date = psz_value;
- psz_time = p + 1;
- }
- else
- {
- psz_time = psz_value;
- }
-
- switch( sscanf( psz_time, "%u:%u:%u", &i, &j, &k ) )
- {
- case 1:
- time.tm_sec = i;
- break;
- case 2:
- time.tm_min = i;
- time.tm_sec = j;
- break;
- case 3:
- time.tm_hour = i;
- time.tm_min = j;
- time.tm_sec = k;
- break;
- default:
- return 1;
- }
- if( psz_date )
- {
- switch( sscanf( psz_date, "%u/%u/%u", &i, &j, &k ) )
- {
- case 1:
- time.tm_mday = i;
- break;
- case 2:
- time.tm_mon = i;
- time.tm_mday = j;
- break;
- case 3:
- time.tm_year = i;
- time.tm_mon = j;
- time.tm_mday = k;
- break;
- default:
- return 1;
- }
- }
-
- /* ok, that's stupid... who is going to schedule streams every 42 years ? */
- date = (((( time.tm_year * 12 + time.tm_mon ) * 30 + time.tm_mday ) * 24 + time.tm_hour ) * 60 + time.tm_min ) * 60 + time.tm_sec ;
- schedule->i_period = ((mtime_t) date) * 1000000;
- }
-#endif /* UNDER_CE */
- else if( !strcmp( psz_cmd, "repeat" ) )
- {
- int i;
-
- if( sscanf( psz_value, "%d", &i ) == 1 )
- {
- schedule->i_repeat = i;
- }
- else
- {
- return 1;
- }
- }
- else if( !strcmp( psz_cmd, "append" ) )
- {
- char *command = strdup( psz_value );
-
- TAB_APPEND( schedule->i_command, schedule->command, command );
- }
- else
- {
- return 1;
- }
- return 0;
-}
-
-/*****************************************************************************
- * Message handling functions
- *****************************************************************************/
-vlm_message_t *vlm_MessageNew( const char *psz_name,
- const char *psz_format, ... )
-{
- vlm_message_t *p_message;
- va_list args;
-
- if( !psz_name ) return NULL;
-
- p_message = malloc( sizeof(vlm_message_t) );
- if( !p_message)
- {
- return NULL;
- }
-
- p_message->psz_value = 0;
-
- if( psz_format )
- {
- va_start( args, psz_format );
- if( vasprintf( &p_message->psz_value, psz_format, args ) == -1 )
- {
- va_end( args );
- free( p_message );
- return NULL;
- }
- va_end( args );
- }
-
- p_message->psz_name = strdup( psz_name );
- p_message->i_child = 0;
- p_message->child = NULL;
-
- return p_message;
-}
-
-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 );
- 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 );
-}
-
-/* Add a child */
-vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message,
- vlm_message_t *p_child )
-{
- if( p_message == NULL ) return NULL;
-
- if( p_child )
- {
- TAB_APPEND( p_message->i_child, p_message->child, p_child );
- }
-
- return p_child;
-}
-
-/*****************************************************************************
- * Misc utility functions
- *****************************************************************************/
-static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media,
- vlm_schedule_t *schedule,
- const char *psz_filter )
-{
- if( media != NULL )
- {
- int i;
- vlm_message_t *msg;
- vlm_message_t *msg_media;
- vlm_message_t *msg_child;
-
- msg = vlm_MessageNew( "show", NULL );
- msg_media = vlm_MessageAdd( msg, vlm_MessageNew( media->psz_name, 0 ));
-
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "type", media->i_type == VOD_TYPE ?
- "vod" : "broadcast" ) );
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "enabled", media->b_enabled ?
- "yes" : "no" ) );
-
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "loop", media->b_loop ?
- "yes" : "no" ) );
-
- if( media->i_type == VOD_TYPE && media->psz_mux )
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "mux", media->psz_mux ) );
-
- msg_child = vlm_MessageAdd( msg_media,
- vlm_MessageNew( "inputs", NULL ) );
-
- for( i = 0; i < media->i_input; i++ )
- {
- vlm_MessageAdd( msg_child,
- vlm_MessageNew( media->input[i], NULL ) );
- }
-
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "output", media->psz_output ?
- media->psz_output : "" ) );
-
- msg_child = vlm_MessageAdd( msg_media, vlm_MessageNew( "options", 0 ));
-
- for( i = 0; i < media->i_option; i++ )
- {
- vlm_MessageAdd( msg_child, vlm_MessageNew( media->option[i], 0 ) );
- }
-
- msg_child = vlm_MessageAdd( msg_media,
- vlm_MessageNew( "instances", NULL ) );
-
- for( i = 0; i < media->i_instance; i++ )
- {
- vlm_media_instance_t *p_instance = media->instance[i];
- vlc_value_t val;
- vlm_message_t *msg_instance;
- char *psz_tmp;
-
- if( !p_instance->p_input ) val.i_int = END_S;
- else var_Get( p_instance->p_input, "state", &val );
-
- msg_instance = vlm_MessageNew( "instance" , NULL );
- vlm_MessageAdd( msg_instance, vlm_MessageNew( "name" , p_instance->psz_name ? p_instance->psz_name : "default" ) );
- vlm_MessageAdd( msg_instance, vlm_MessageNew( "state",
- val.i_int == PLAYING_S ? "playing" :
- val.i_int == PAUSE_S ? "paused" :
- "stopped" ) );
-#define APPEND_INPUT_INFO( a, format, type ) \
- asprintf( &psz_tmp, format, \
- var_Get ## type( p_instance->p_input, a ) ); \
- vlm_MessageAdd( msg_instance, vlm_MessageNew( a, psz_tmp ) ); \
- free( psz_tmp );
- APPEND_INPUT_INFO( "position", "%f", Float );
- APPEND_INPUT_INFO( "time", I64Fi, Time );
- APPEND_INPUT_INFO( "length", I64Fi, Time );
- APPEND_INPUT_INFO( "rate", "%d", Integer );
- APPEND_INPUT_INFO( "title", "%d", Integer );
- APPEND_INPUT_INFO( "chapter", "%d", Integer );
- APPEND_INPUT_INFO( "seekable", "%d", Bool );
-#undef APPEND_INPUT_INFO
- asprintf( &psz_tmp, "%d", p_instance->i_index + 1 );
- vlm_MessageAdd( msg_instance, vlm_MessageNew( "playlistindex", psz_tmp ) );
- free( psz_tmp );
- vlm_MessageAdd( msg_child, msg_instance );
- }
-
- return msg;
-
- }
-
- else if( schedule != NULL )
- {
- int i;
- vlm_message_t *msg;
- vlm_message_t *msg_schedule;
- vlm_message_t *msg_child;
- char buffer[100];
-
- msg = vlm_MessageNew( "show", NULL );
- msg_schedule =
- vlm_MessageAdd( msg, vlm_MessageNew( schedule->psz_name, 0 ) );
-
- vlm_MessageAdd( msg_schedule, vlm_MessageNew("type", "schedule") );
-
- vlm_MessageAdd( msg_schedule,
- vlm_MessageNew( "enabled", schedule->b_enabled ?
- "yes" : "no" ) );
-
-#if !defined( UNDER_CE )
- if( schedule->i_date != 0 )
- {
- struct tm date;
- 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 );
-
- vlm_MessageAdd( msg_schedule,
- vlm_MessageNew( "date", psz_date ) );
- free( psz_date );
- }
- else
- {
- vlm_MessageAdd( msg_schedule, vlm_MessageNew("date", "now") );
- }
-
- if( schedule->i_period != 0 )
- {
- time_t i_time = (time_t) ( schedule->i_period / 1000000 );
- struct tm date;
-
- date.tm_sec = (int)( i_time % 60 );
- i_time = i_time / 60;
- date.tm_min = (int)( i_time % 60 );
- i_time = i_time / 60;
- date.tm_hour = (int)( i_time % 24 );
- i_time = i_time / 24;
- date.tm_mday = (int)( i_time % 30 );
- i_time = i_time / 30;
- /* okay, okay, months are not always 30 days long */
- date.tm_mon = (int)( i_time % 12 );
- i_time = i_time / 12;
- date.tm_year = (int)i_time;
-
- sprintf( buffer, "%d/%d/%d-%d:%d:%d", date.tm_year, date.tm_mon,
- date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec);
-
- vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", buffer) );
- }
- else
- {
- vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "0") );
- }
-#endif /* UNDER_CE */
-
- sprintf( buffer, "%d", schedule->i_repeat );
- vlm_MessageAdd( msg_schedule, vlm_MessageNew( "repeat", buffer ) );
-
- msg_child =
- vlm_MessageAdd( msg_schedule, vlm_MessageNew("commands", 0) );
-
- for( i = 0; i < schedule->i_command; i++ )
- {
- vlm_MessageAdd( msg_child,
- vlm_MessageNew( schedule->command[i], NULL ) );
- }
-
- return msg;
-
- }
-
- else if( psz_filter && !strcmp( psz_filter, "media" ) )
- {
- int i, j;
- vlm_message_t *msg;
- vlm_message_t *msg_child;
- int i_vod = 0, i_broadcast = 0;
- char *psz_count;
-
- for( i = 0; i < vlm->i_media; i++ )
- {
- if( vlm->media[i]->i_type == VOD_TYPE )
- i_vod ++;
- else
- i_broadcast ++;
- }
-
- asprintf( &psz_count, "( %d broadcast - %d vod )", i_broadcast, i_vod);
-
- msg = vlm_MessageNew( "show", NULL );
- msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "media", psz_count ) );
- free( psz_count );
-
- for( i = 0; i < vlm->i_media; i++ )
- {
- vlm_media_t *m = vlm->media[i];
- vlm_message_t *msg_media, *msg_instance;
-
- msg_media = vlm_MessageAdd( msg_child,
- vlm_MessageNew( m->psz_name, 0 ) );
-
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "type", m->i_type == VOD_TYPE ?
- "vod" : "broadcast" ) );
-
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "enabled", m->b_enabled ?
- "yes" : "no" ) );
-
- if( m->i_type == VOD_TYPE && m->psz_mux )
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "mux", m->psz_mux ) );
-
- msg_instance = vlm_MessageAdd( msg_media,
- vlm_MessageNew( "instances", 0 ) );
-
- for( j = 0; j < m->i_instance; j++ )
- {
- vlm_media_instance_t *p_instance = m->instance[j];
- vlc_value_t val;
-
- if( !p_instance->p_input ) val.i_int = END_S;
- else var_Get( p_instance->p_input, "state", &val );
-
- vlm_MessageAdd( msg_instance,
- vlm_MessageNew( p_instance->psz_name ?
- p_instance->psz_name : "default",
- val.i_int == PLAYING_S ? "playing" :
- val.i_int == PAUSE_S ? "paused" :
- "stopped" ) );
- }
- }
-
- return msg;
- }
-
- else if( psz_filter && !strcmp( psz_filter, "schedule" ) )
- {
- int i;
- vlm_message_t *msg;
- vlm_message_t *msg_child;
-
- msg = vlm_MessageNew( "show", NULL );
- msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "schedule", NULL ) );
-
- for( i = 0; i < vlm->i_schedule; i++ )
- {
- vlm_schedule_t *s = vlm->schedule[i];
- vlm_message_t *msg_schedule;
- mtime_t i_time, i_next_date;
-
- msg_schedule = vlm_MessageAdd( msg_child,
- vlm_MessageNew( s->psz_name, 0 ) );
- vlm_MessageAdd( msg_schedule,
- vlm_MessageNew( "enabled", s->b_enabled ?
- "yes" : "no" ) );
-
- /* calculate next date */
- i_time = vlm_Date();
- i_next_date = s->i_date;
-
- if( s->i_period != 0 )
- {
- int j = 0;
- while( s->i_date + j * s->i_period <= i_time &&
- s->i_repeat > j )
- {
- j++;
- }
-
- i_next_date = s->i_date + j * s->i_period;
- }
-
- if( i_next_date > i_time )
- {
- time_t i_date = (time_t) (i_next_date / 1000000) ;
-
-#if !defined( UNDER_CE )
-#ifdef HAVE_CTIME_R
- char psz_date[500];
- ctime_r( &i_date, psz_date );
-#else
- char *psz_date = ctime( &i_date );
-#endif
-
- vlm_MessageAdd( msg_schedule,
- vlm_MessageNew( "next launch", psz_date ) );
-#endif
- }
- }
-
- return msg;
- }
-
- else if( ( psz_filter == NULL ) && ( media == NULL ) && ( schedule == NULL ) )
- {
- vlm_message_t *show1 = vlm_Show( vlm, NULL, NULL, "media" );
- vlm_message_t *show2 = vlm_Show( vlm, NULL, NULL, "schedule" );
-
- vlm_MessageAdd( show1, show2->child[0] );
-
- /* We must destroy the parent node "show" of show2
- * and not the children */
- free( show2->psz_name );
- free( show2 );
-
- return show1;
- }
-
- else
- {
- return vlm_MessageNew( "show", 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
- *****************************************************************************/
-static int Load( vlm_t *vlm, char *file )
-{
- char *pf = file;
- int i_line = 1;
-
- while( *pf != '\0' )
- {
- vlm_message_t *message = NULL;
- int i_end = 0;
-
- while( pf[i_end] != '\n' && pf[i_end] != '\0' && pf[i_end] != '\r' )
- {
- i_end++;
- }
-
- if( pf[i_end] == '\r' || pf[i_end] == '\n' )
- {
- pf[i_end] = '\0';
- i_end++;
- if( pf[i_end] == '\n' ) i_end++;
- }
-
- if( *pf && ExecuteCommand( vlm, pf, &message ) )
- {
- if( message )
- {
- if( message->psz_value )
- msg_Err( vlm, "Load error on line %d: %s: %s",
- i_line, message->psz_name, message->psz_value );
- vlm_MessageDelete( message );
- }
- return 1;
- }
- if( message ) vlm_MessageDelete( message );
-
- pf += i_end;
- i_line++;
- }
-
- return 0;
-}
-
-static char *Save( vlm_t *vlm )
-{
- char *save = NULL;
- char psz_header[] = "\n"
- "# VLC media player VLM command batch\n"
- "# http://www.videolan.org/vlc/\n\n" ;
- char *p;
- int i,j;
- int i_length = strlen( psz_header );
-
- for( i = 0; i < vlm->i_media; i++ )
- {
- vlm_media_t *media = vlm->media[i];
-
- if( media->i_type == VOD_TYPE )
- {
- i_length += strlen( "new vod " ) + strlen(media->psz_name);
- }
- else
- {
- i_length += strlen( "new broadcast " ) + strlen(media->psz_name);
- }