- 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);
- }
-
- if( media->b_enabled == VLC_TRUE )
- {
- i_length += strlen( "enabled" );
- }
- else
- {
- i_length += strlen( "disabled" );
- }
-
- if( media->b_loop == VLC_TRUE )
- {
- i_length += strlen( " loop\n" );
- }
- else
- {
- i_length += strlen( "\n" );
- }
-
- for( j = 0; j < media->i_input; j++ )
- {
- i_length += strlen( "setup input \"\"\n" ) +
- strlen( media->psz_name ) + strlen( media->input[j] );
- }
-
- if( media->psz_output != NULL )
- {
- i_length += strlen(media->psz_name) + strlen(media->psz_output) +
- strlen( "setup output \n" );
- }
-
- for( j=0 ; j < media->i_option ; j++ )
- {
- i_length += strlen(media->psz_name) + strlen(media->option[j]) +
- strlen("setup option \n");
- }
- }
-
- for( i = 0; i < vlm->i_schedule; i++ )
- {
- vlm_schedule_t *schedule = vlm->schedule[i];
-
- i_length += strlen( "new schedule " ) + strlen( schedule->psz_name );
-
- if( schedule->b_enabled == VLC_TRUE )
- {
- i_length += strlen( "date //-:: enabled\n" ) + 14;
- }
- else
- {
- i_length += strlen( "date //-:: disabled\n" ) + 14;
- }
-
-
- if( schedule->i_period != 0 )
- {
- i_length += strlen( "setup " ) + strlen( schedule->psz_name ) +
- strlen( "period //-::\n" ) + 14;
- }
-
- if( schedule->i_repeat >= 0 )
- {
- char buffer[12];
-
- sprintf( buffer, "%d", schedule->i_repeat );
- i_length += strlen( "setup repeat \n" ) +
- strlen( schedule->psz_name ) + strlen( buffer );
- }
- else
- {
- i_length++;
- }
-
- for( j = 0; j < schedule->i_command; j++ )
- {
- i_length += strlen( "setup append \n" ) +
- strlen( schedule->psz_name ) + strlen( schedule->command[j] );
- }
-
- }
-
- /* Don't forget the '\0' */
- i_length++;
- /* now we have the length of save */
-
- p = save = malloc( i_length );
- *save = '\0';
-
- p += sprintf( p, "%s", psz_header );
-
- /* finally we can write in it */
- for( i = 0; i < vlm->i_media; i++ )
- {
- vlm_media_t *media = vlm->media[i];
-
- if( media->i_type == VOD_TYPE )
- {
- p += sprintf( p, "new %s vod ", media->psz_name);
- }
- else
- {
- p += sprintf( p, "new %s broadcast ", media->psz_name);
- }
-
- if( media->b_enabled == VLC_TRUE )
- {
- p += sprintf( p, "enabled" );
- }
- else
- {
- p += sprintf( p, "disabled" );
- }
-
- if( media->b_loop == VLC_TRUE )
- {
- p += sprintf( p, " loop\n" );
- }
- else
- {
- p += sprintf( p, "\n" );
- }
-
- for( j = 0; j < media->i_input; j++ )
- {
- p += sprintf( p, "setup %s input \"%s\"\n", media->psz_name,
- media->input[j] );
- }
-
- if( media->psz_output != NULL )
- {
- p += sprintf( p, "setup %s output %s\n", media->psz_name,
- media->psz_output );
- }
-
- for( j = 0; j < media->i_option; j++ )
- {
- p += sprintf( p, "setup %s option %s\n", media->psz_name,
- media->option[j] );
- }
- }
-
- /* and now, the schedule scripts */
-#if !defined( UNDER_CE )
- for( i = 0; i < vlm->i_schedule; i++ )
- {
- vlm_schedule_t *schedule = vlm->schedule[i];
- 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 )
- {
- p += sprintf( p, "date %d/%d/%d-%d:%d:%d enabled\n",
- date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
- date.tm_hour, date.tm_min, date.tm_sec );
- }
- else
- {
- p += sprintf( p, "date %d/%d/%d-%d:%d:%d disabled\n",
- date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
- date.tm_hour, date.tm_min, date.tm_sec);
- }
-
- if( schedule->i_period != 0 )
- {
- p += sprintf( p, "setup %s ", schedule->psz_name );
-
- i_time = (time_t) ( schedule->i_period / 1000000 );
-
- 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;
-
- p += sprintf( p, "period %d/%d/%d-%d:%d:%d\n",
- date.tm_year, date.tm_mon, date.tm_mday,
- date.tm_hour, date.tm_min, date.tm_sec);
- }
-
- if( schedule->i_repeat >= 0 )
- {
- p += sprintf( p, "setup %s repeat %d\n",
- schedule->psz_name, schedule->i_repeat );
- }
- else
- {
- p += sprintf( p, "\n" );
- }
-
- for( j = 0; j < schedule->i_command; j++ )
- {
- p += sprintf( p, "setup %s append %s\n",
- schedule->psz_name, schedule->command[j] );
- }
-
- }
-#endif /* UNDER_CE */
-
- return save;
-}
-
-/*****************************************************************************
- * Manage:
- *****************************************************************************/
-static int vlm_MediaVodControl( void *p_private, vod_media_t *p_vod_media,
- const char *psz_id, int i_query, va_list args )
-{
- vlm_t *vlm = (vlm_t *)p_private;
- int i, i_ret = VLC_EGENERIC;
-
- if( !p_private || !p_vod_media ) return VLC_EGENERIC;
-
- vlc_mutex_lock( &vlm->lock );
-
- /* Find media */
- for( i = 0; i < vlm->i_media; i++ )
- {
- if( p_vod_media == vlm->media[i]->vod_media ) break;
- }
-
- if( i == vlm->i_media )
- {
- vlc_mutex_unlock( &vlm->lock );
- return VLC_EGENERIC;
- }
-
- switch( i_query )
- {
- case VOD_MEDIA_PLAY:
- vlm->media[i]->psz_vod_output = (char *)va_arg( args, char * );
- i_ret = vlm_MediaControl( vlm, vlm->media[i], psz_id, "play", 0 );
- vlm->media[i]->psz_vod_output = 0;
- break;
-
- case VOD_MEDIA_PAUSE:
- i_ret = vlm_MediaControl( vlm, vlm->media[i], psz_id, "pause", 0 );
- break;
-
- case VOD_MEDIA_STOP:
- i_ret = vlm_MediaControl( vlm, vlm->media[i], psz_id, "stop", 0 );
- break;
-
- case VOD_MEDIA_SEEK:
- {
- double f_pos = (double)va_arg( args, double );
- char psz_pos[50];
- lldiv_t div = lldiv( f_pos * 10000000, 10000000 );
- sprintf( psz_pos, I64Fd".%07u", div.quot, (unsigned int) div.rem );
- i_ret = vlm_MediaControl( vlm, vlm->media[i], psz_id, "seek", psz_pos);
- break;
- }
-
- case VOD_MEDIA_REWIND:
- {
- double f_scale = (double)va_arg( args, double );
- char psz_scale[50];
- lldiv_t div = lldiv( f_scale * 10000000, 10000000 );
- sprintf( psz_scale, I64Fd".%07u", div.quot, (unsigned int) div.rem );
- i_ret = vlm_MediaControl( vlm, vlm->media[i], psz_id, "rewind", psz_scale );
- break;
- }
-
- case VOD_MEDIA_FORWARD:
- {
- double f_scale = (double)va_arg( args, double );
- char psz_scale[50];
- lldiv_t div = lldiv( f_scale * 10000000, 10000000 );
- sprintf( psz_scale, I64Fd".%07u", div.quot, (unsigned int) div.rem );
- i_ret = vlm_MediaControl( vlm, vlm->media[i], psz_id, "forward", psz_scale );
- break;
- }
-
- default:
- break;
- }
-
- vlc_mutex_unlock( &vlm->lock );
-
- return i_ret;
-}
-
-
-/*****************************************************************************
- * Manage:
- *****************************************************************************/
-static int Manage( vlc_object_t* p_object )
-{
- vlm_t *vlm = (vlm_t*)p_object;
- int i, j;
- mtime_t i_lastcheck;
- mtime_t i_time;
-
- i_lastcheck = vlm_Date();
-
- while( !vlm->b_die )
- {
- char **ppsz_scheduled_commands = NULL;
- int i_scheduled_commands = 0;
- vlc_mutex_lock( &vlm->lock );
-
- /* destroy the inputs that wants to die, and launch the next input */
- for( i = 0; i < vlm->i_media; i++ )
- {
- vlm_media_t *p_media = vlm->media[i];
-
- for( j = 0; j < p_media->i_instance; j++ )
- {
- vlm_media_instance_t *p_instance = p_media->instance[j];
-
- if( !p_instance->p_input ||
- ( !p_instance->p_input->b_eof && !p_instance->p_input->b_error ) )
- continue;
-
- p_instance->i_index++;
- if( p_instance->i_index >= p_media->i_input && p_media->b_loop )
- p_instance->i_index = 0;
-
- if( p_instance->i_index < p_media->i_input )
- {
- char psz_index[32];
-
- /* FIXME, find a way to select the right instance */
- snprintf( psz_index, sizeof(psz_index), "%d", p_instance->i_index+1 );
- vlm_MediaControl( vlm, p_media, p_instance->psz_name,
- "play", psz_index );
- }
- else
- {
- if( vlm_MediaControl( vlm, p_media, p_instance->psz_name,
- "stop", 0 ) == VLC_SUCCESS )
- {
- j--; /* the aray is one element smaller now. */
- }
- }
- }
- }
-
- /* scheduling */
- i_time = vlm_Date();
-
- for( i = 0; i < vlm->i_schedule; i++ )
- {
- mtime_t i_real_date = vlm->schedule[i]->i_date;
-
- if( vlm->schedule[i]->b_enabled == VLC_TRUE )
- {
- if( vlm->schedule[i]->i_date == 0 ) // now !
- {
- vlm->schedule[i]->i_date = (i_time / 1000000) * 1000000 ;
- i_real_date = i_time;
- }
- else if( vlm->schedule[i]->i_period != 0 )
- {
- int j = 0;
- while( vlm->schedule[i]->i_date + j *
- vlm->schedule[i]->i_period <= i_lastcheck &&
- ( vlm->schedule[i]->i_repeat > j ||
- vlm->schedule[i]->i_repeat == -1 ) )
- {
- j++;
- }
-
- i_real_date = vlm->schedule[i]->i_date + j *
- vlm->schedule[i]->i_period;
- }
-
- if( i_real_date <= i_time && i_real_date > i_lastcheck )
- {
- for( j = 0; j < vlm->schedule[i]->i_command; j++ )
- {
- TAB_APPEND( i_scheduled_commands,
- ppsz_scheduled_commands,
- strdup(vlm->schedule[i]->command[j] ) );
- }
- }
- }
- }
- while( i_scheduled_commands )
- {
- vlm_message_t *message = NULL;
- char *psz_command = ppsz_scheduled_commands[0];
- ExecuteCommand( vlm, psz_command,&message );
-
- /* for now, drop the message */
- vlm_MessageDelete( message );
- TAB_REMOVE( i_scheduled_commands,
- ppsz_scheduled_commands,
- psz_command );
- free( psz_command );
- }
-
- i_lastcheck = i_time;
-
- vlc_mutex_unlock( &vlm->lock );
-
- msleep( 100000 );
- }
-
- return VLC_SUCCESS;
-}
-
-#else /* ENABLE_VLM */
-
-/* We just define an empty wrapper */
-vlm_t *__vlm_New( vlc_object_t *a )
-{
- msg_Err( a, "VideoLAN manager support is disabled" );
- return NULL;
-}
-void vlm_Delete( vlm_t *a )
-{
- ;
-}
-int vlm_ExecuteCommand( vlm_t *a, char *b, vlm_message_t **c )
-{
- return -1;
-}
-void vlm_MessageDelete( vlm_message_t *a )
-{
- ;
-}
-vlm_media_t *vlm_MediaNew( vlm_t *a, char *b, int c )
-{
- return NULL;
-}
-vlm_media_t *vlm_MediaSearch (vlm_t *a, const char *b )
-{
- return NULL;
-}
-void vlm_MediaDelete( vlm_t *a, vlm_media_t *b, char *c )
-{
- ;
-}
-int vlm_MediaSetup( vlm_t *a, vlm_media_t *b, char *c, char *d )
-{
- return -1;
-}
-int vlm_MediaControl( vlm_t *a, vlm_media_t *b, char *c, char *d, char *e )
-{
- return -1;