/*****************************************************************************
* Local prototypes.
*****************************************************************************/
-static vlm_message_t *vlm_Show( vlm_t *, vlm_media_t *, vlm_schedule_t *, const char * );
-static vlm_message_t *vlm_Help( vlm_t *, char * );
+/* */
+static int vlm_ControlInternal( vlm_t *, int, ... );
-static vlm_media_instance_t *vlm_MediaInstanceSearch( vlm_t *, vlm_media_t *, const char * );
+/* */
+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_t *vlm_ScheduleSearch( vlm_t *, const char * );
+static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *, const char * );
static char *Save( vlm_t * );
static int Load( vlm_t *, char * );
-static int ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
-static int Manage( vlc_object_t * );
-static int vlm_Save( vlm_t *p_vlm, const char *psz_file );
-static int vlm_Load( vlm_t *p_vlm, const char *psz_file );
+static int ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
+static int Manage( vlc_object_t * );
-static vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name );
-static void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_t *sched, const char *psz_name );
-static int vlm_ScheduleSetup( vlm_schedule_t *schedule, const char *psz_cmd,
- const char *psz_value );
+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 int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
+ const char *psz_value );
static int vlm_MediaVodControl( void *, vod_media_t *, const char *, int, va_list );
-
-static vlm_media_t *vlm_MediaNew( vlm_t *, const char *, int );
-static void vlm_MediaDelete( vlm_t *, vlm_media_t *, const char * );
-static int vlm_MediaSetup( vlm_t *, vlm_media_t *, const char *, const char * );
-static int vlm_MediaControl( vlm_t *, vlm_media_t *, const char *, const char *, const char * );
-static vlm_media_t *vlm_MediaSearch( vlm_t *, const char *);
+/* */
+static vlm_media_sys_t *vlm_MediaSearch( vlm_t *, const char *);
/*****************************************************************************
* vlm_New:
}
vlc_mutex_init( p_this->p_libvlc, &p_vlm->lock );
+ p_vlm->i_id = 1;
TAB_INIT( p_vlm->i_media, p_vlm->media );
TAB_INIT( p_vlm->i_schedule, p_vlm->schedule );
p_vlm->i_vod = 0;
- p_vlm->vod = NULL;
+ p_vlm->p_vod = NULL;
vlc_object_yield( p_vlm );
vlc_object_attach( p_vlm, p_this->p_libvlc );
vlc_object_detach( p_vlm );
- while( p_vlm->i_media )
- vlm_MediaDelete( p_vlm, p_vlm->media[0], NULL );
+ vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
TAB_CLEAN( p_vlm->i_media, p_vlm->media );
- while( p_vlm->i_schedule )
- vlm_ScheduleDelete( p_vlm, p_vlm->schedule[0], NULL );
+ vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
TAB_CLEAN( p_vlm->schedule, p_vlm->schedule );
vlc_mutex_destroy( &p_vlm->lock );
*****************************************************************************
* Execute a command which ends with '\0' (string)
*****************************************************************************/
-static int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
- vlm_message_t **pp_message )
+static int ExecuteSyntaxError( const char *psz_cmd, vlm_message_t **pp_status )
{
- size_t i_command = 0;
- char buf[strlen (psz_command) + 1], *psz_buf = buf;
- char *ppsz_command[sizeof (buf) / 2];
- vlm_message_t *p_message = NULL;
+ *pp_status = vlm_MessageNew( psz_cmd, "Wrong command syntax" );
+ return VLC_EGENERIC;
+}
- /* First, parse the line and cut it */
- while( *psz_command != '\0' )
- {
- const char *psz_temp;
+static vlc_bool_t ExecuteIsMedia( vlm_t *p_vlm, const char *psz_name )
+{
+ int64_t id;
- if(isspace (*psz_command))
- {
- psz_command++;
- continue;
- }
+ if( !psz_name || vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) )
+ return VLC_FALSE;
+ return VLC_TRUE;
+}
+static vlc_bool_t ExecuteIsSchedule( vlm_t *p_vlm, const char *psz_name )
+{
+ if( !psz_name || !vlm_ScheduleSearch( p_vlm, psz_name ) )
+ return VLC_FALSE;
+ return VLC_TRUE;
+}
- /* support for comments */
- if( i_command == 0 && *psz_command == '#')
- {
- p_message = vlm_MessageNew( "", NULL );
- goto success;
- }
+static int ExecuteDel( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_status )
+{
+ vlm_media_sys_t *p_media;
+ vlm_schedule_sys_t *p_schedule;
- psz_temp = FindCommandEnd( psz_command );
+ p_media = vlm_MediaSearch( p_vlm, psz_name );
+ p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
- if( psz_temp == NULL )
- {
- p_message = vlm_MessageNew( "Incomplete command", psz_command );
- goto error;
- }
+ if( p_schedule != NULL )
+ {
+ vlm_ScheduleDelete( p_vlm, p_schedule, NULL );
+ }
+ else if( p_media != NULL )
+ {
+ vlm_ControlInternal( p_vlm, VLM_DEL_MEDIA, p_media->cfg.id );
+ }
+ else if( !strcmp(psz_name, "media") )
+ {
+ vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
+ }
+ else if( !strcmp(psz_name, "schedule") )
+ {
+ vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
+ }
+ else if( !strcmp(psz_name, "all") )
+ {
+ vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
+ vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
+ }
+ else
+ {
+ *pp_status = vlm_MessageNew( "del", "%s: media unknown", psz_name );
+ return VLC_EGENERIC;
+ }
- assert (i_command < (sizeof (ppsz_command) / sizeof (ppsz_command[0])));
+ *pp_status = vlm_MessageNew( "del", NULL );
+ return VLC_SUCCESS;
+}
- ppsz_command[i_command] = psz_buf;
- memcpy (psz_buf, psz_command, psz_temp - psz_command);
- psz_buf[psz_temp - psz_command] = '\0';
+static int ExecuteShow( vlm_t *p_vlm, const char *psz_name, vlm_message_t **pp_status )
+{
+ vlm_media_sys_t *p_media;
+ vlm_schedule_sys_t *p_schedule;
- Unescape (psz_buf, psz_buf);
+ if( !psz_name )
+ {
+ *pp_status = vlm_Show( p_vlm, NULL, NULL, NULL );
+ return VLC_SUCCESS;
+ }
- i_command++;
- psz_buf += psz_temp - psz_command + 1;
- psz_command = psz_temp;
+ p_media = vlm_MediaSearch( p_vlm, psz_name );
+ p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
- assert (buf + sizeof (buf) >= psz_buf);
- }
+ if( p_schedule != NULL )
+ *pp_status = vlm_Show( p_vlm, NULL, p_schedule, NULL );
+ else if( p_media != NULL )
+ *pp_status = vlm_Show( p_vlm, p_media, NULL, NULL );
+ else
+ *pp_status = vlm_Show( p_vlm, NULL, NULL, psz_name );
- /*
- * And then Interpret it
- */
+ return VLC_SUCCESS;
+}
- if( i_command == 0 )
+static int ExecuteHelp( vlm_t *p_vlm, vlm_message_t **pp_status )
+{
+ *pp_status = vlm_Help( p_vlm, NULL );
+ return VLC_SUCCESS;
+}
+
+static int ExecuteControl( vlm_t *p_vlm, const char *psz_name, const int i_arg, char ** ppsz_arg, vlm_message_t **pp_status )
+{
+ vlm_media_sys_t *p_media;
+ const char *psz_control = NULL;
+ const char *psz_instance = NULL;
+ const char *psz_argument = NULL;
+ int i_index;
+ int i_result;
+
+ if( !ExecuteIsMedia( p_vlm, psz_name ) )
{
- p_message = vlm_MessageNew( "", NULL );
- goto success;
+ *pp_status = vlm_MessageNew( "control", "%s: media unknown", psz_name );
+ return VLC_EGENERIC;
}
- if( !strcmp(ppsz_command[0], "new") )
+ assert( i_arg > 0 );
+
+#define IS(txt) ( !strcmp( ppsz_arg[i_index], (txt) ) )
+ i_index = 0;
+ if( !IS("play") && !IS("stop") && !IS("pause") && !IS("seek") )
{
- int i_type;
+ i_index = 1;
+ psz_instance = ppsz_arg[0];
- /* Check the number of arguments */
- if( i_command < 3 ) goto syntax_error;
+ if( i_index >= i_arg || ( !IS("play") && !IS("stop") && !IS("pause") && !IS("seek") ) )
+ return ExecuteSyntaxError( "control", pp_status );
+ }
+#undef IS
+ psz_control = ppsz_arg[i_index];
- /* Get type */
- if( !strcmp(ppsz_command[2], "vod") )
- {
- i_type = VOD_TYPE;
- }
- else if( !strcmp(ppsz_command[2], "broadcast") )
- {
- i_type = BROADCAST_TYPE;
- }
- else if( !strcmp(ppsz_command[2], "schedule") )
- {
- i_type = SCHEDULE_TYPE;
- }
- else
- {
- p_message =
- vlm_MessageNew( "new", "%s: Choose between vod, "
- "broadcast or schedule", ppsz_command[1] );
- goto error;
- }
+ if( i_index+1 < i_arg )
+ psz_argument = ppsz_arg[i_index+1];
- /* Check for forbidden media names */
- if( !strcmp(ppsz_command[1], "all") ||
- !strcmp(ppsz_command[1], "media") ||
- !strcmp(ppsz_command[1], "schedule") )
- {
- p_message = vlm_MessageNew( "new", "\"all\", \"media\" and "
- "\"schedule\" are reserved names" );
- goto error;
- }
+ p_media = vlm_MediaSearch( p_vlm, psz_name );
+ assert( p_media );
- /* Check the name is not already in use */
- if( vlm_ScheduleSearch( p_vlm, ppsz_command[1] ) ||
- vlm_MediaSearch( p_vlm, ppsz_command[1] ) )
- {
- p_message = vlm_MessageNew( "new", "%s: Name already in use",
- ppsz_command[1] );
- goto error;
- }
+ if( !strcmp( psz_control, "play" ) )
+ {
+ int i_input_index = 0;
+ int i;
- /* Schedule */
- if( i_type == SCHEDULE_TYPE )
- {
- vlm_schedule_t *p_schedule;
- p_schedule = vlm_ScheduleNew( p_vlm, ppsz_command[1] );
- if( !p_schedule )
- {
- p_message = vlm_MessageNew( "new", "could not create schedule" );
- goto error;
- }
- }
+ if( ( psz_argument && sscanf(psz_argument, "%d", &i) == 1 ) && i > 0 && i-1 < p_media->cfg.i_input )
+ i_input_index = i-1;
- /* Media */
+ 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
else
- {
- vlm_media_t *p_media;
- p_media = vlm_MediaNew( p_vlm, ppsz_command[1], i_type );
- if( !p_media )
- {
- p_message = vlm_MessageNew( "new", "could not create media" );
- goto error;
- }
- }
-
- if( i_command <= 3 )
- {
- p_message = vlm_MessageNew( "new", NULL );
- goto success;
- }
-
- /* Properties will be dealt with later on */
+ i_result = vlm_ControlInternal( p_vlm, VLM_START_MEDIA_BROADCAST_INSTANCE, p_media->cfg.id, psz_instance, i_input_index );
}
-
- else if( !strcmp(ppsz_command[0], "setup") )
+ else if( !strcmp( psz_control, "seek" ) )
{
- if( i_command < 2 ) goto syntax_error;
+ if( psz_argument )
+ {
+ vlc_bool_t b_relative;
+ if( psz_argument[0] == '+' || psz_argument[0] == '-' )
+ b_relative = VLC_TRUE;
+ else
+ b_relative = VLC_FALSE;
- /* Properties will be dealt with later on */
- }
+ if( strstr( psz_argument, "ms" ) || strstr( psz_argument, "s" ) )
+ {
+ /* Time (ms or s) */
+ int64_t i_new_time;
- else if( !strcmp(ppsz_command[0], "del") )
- {
- vlm_media_t *p_media;
- vlm_schedule_t *p_schedule;
+ if( strstr( psz_argument, "ms" ) )
+ i_new_time = 1000 * (int64_t)atoi( psz_argument );
+ else
+ i_new_time = 1000000 * (int64_t)atoi( psz_argument );
- if( i_command < 2 ) goto syntax_error;
+ if( b_relative )
+ {
+ int64_t i_time = 0;
+ vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_TIME, p_media->cfg.id, psz_instance, &i_time );
+ i_new_time += i_time;
+ }
+ if( i_new_time < 0 )
+ i_new_time = 0;
+ i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_TIME, p_media->cfg.id, psz_instance, i_new_time );
+ }
+ else
+ {
+ /* Percent */
+ double d_new_position = i18n_atof( psz_argument ) / 100.0;
- p_media = vlm_MediaSearch( p_vlm, ppsz_command[1] );
- p_schedule = vlm_ScheduleSearch( p_vlm, ppsz_command[1] );
+ if( b_relative )
+ {
+ double d_position = 0.0;
- if( p_schedule != NULL )
- {
- vlm_ScheduleDelete( p_vlm, p_schedule, NULL );
- }
- else if( p_media != NULL )
- {
- vlm_MediaDelete( p_vlm, p_media, NULL );
- }
- else if( !strcmp(ppsz_command[1], "media") )
- {
- while( p_vlm->i_media ) vlm_MediaDelete( p_vlm, p_vlm->media[0],
- NULL );
+ vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
+ d_new_position += d_position;
+ }
+ if( d_new_position < 0.0 )
+ d_new_position = 0.0;
+ else if( d_new_position > 1.0 )
+ d_new_position = 1.0;
+ i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_new_position );
+ }
}
- else if( !strcmp(ppsz_command[1], "schedule") )
+ else
{
- while( p_vlm->i_schedule )
- vlm_ScheduleDelete( p_vlm, p_vlm->schedule[0], NULL );
+ i_result = VLC_EGENERIC;
}
- else if( !strcmp(ppsz_command[1], "all") )
+ }
+ else if( !strcmp( psz_control, "rewind" ) )
+ {
+ if( psz_argument )
{
- while( p_vlm->i_media ) vlm_MediaDelete( p_vlm, p_vlm->media[0],
- NULL );
+ const double d_scale = i18n_atof( psz_argument );
+ double d_position;
- while( p_vlm->i_schedule )
- vlm_ScheduleDelete( p_vlm, p_vlm->schedule[0], NULL );
+ vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
+ d_position -= (d_scale / 1000.0);
+ if( d_position < 0.0 )
+ d_position = 0.0;
+ i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
}
else
{
- p_message = vlm_MessageNew( "del", "%s: media unknown",
- ppsz_command[1] );
- goto error;
+ i_result = VLC_EGENERIC;
}
-
- p_message = vlm_MessageNew( "del", NULL );
- goto success;
}
-
- else if( !strcmp(ppsz_command[0], "show") )
+ else if( !strcmp( psz_control, "forward" ) )
{
- vlm_media_t *p_media;
- vlm_schedule_t *p_schedule;
-
- if( i_command == 1 )
+ if( psz_argument )
{
- p_message = vlm_Show( p_vlm, NULL, NULL, NULL );
- goto success;
- }
- else if( i_command > 2 ) goto syntax_error;
+ const double d_scale = i18n_atof( psz_argument );
+ double d_position;
- p_media = vlm_MediaSearch( p_vlm, ppsz_command[1] );
- p_schedule = vlm_ScheduleSearch( p_vlm, ppsz_command[1] );
+ vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
+ d_position += (d_scale / 1000.0);
+ if( d_position > 1.0 )
+ d_position = 1.0;
+ i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
- if( p_schedule != NULL )
- {
- p_message = vlm_Show( p_vlm, NULL, p_schedule, NULL );
- }
- else if( p_media != NULL )
- {
- p_message = vlm_Show( p_vlm, p_media, NULL, NULL );
}
else
{
- p_message = vlm_Show( p_vlm, NULL, NULL, ppsz_command[1] );
+ i_result = VLC_EGENERIC;
}
-
- goto success;
}
-
- else if( !strcmp(ppsz_command[0], "help") )
+ else if( !strcmp( psz_control, "stop" ) )
{
- if( i_command != 1 ) goto syntax_error;
-
- p_message = vlm_Help( p_vlm, NULL );
- goto success;
+ i_result = vlm_ControlInternal( p_vlm, VLM_STOP_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );
+ }
+ else if( !strcmp( psz_control, "pause" ) )
+ {
+ i_result = vlm_ControlInternal( p_vlm, VLM_PAUSE_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );
+ }
+ else
+ {
+ i_result = VLC_EGENERIC;
}
- else if( !strcmp(ppsz_command[0], "control") )
+ if( i_result )
{
- vlm_media_t *p_media;
+ *pp_status = vlm_MessageNew( "control", "unknown error" );
+ return VLC_SUCCESS;
+ }
+ *pp_status = vlm_MessageNew( "control", NULL );
+ return VLC_SUCCESS;
+}
- if( i_command < 3 ) goto syntax_error;
+static int ExecuteExport( vlm_t *p_vlm, vlm_message_t **pp_status )
+{
+ char *psz_export = Save( p_vlm );
- if( !(p_media = vlm_MediaSearch( p_vlm, ppsz_command[1] ) ) )
- {
- p_message = vlm_MessageNew( "control", "%s: media unknown",
- ppsz_command[1] );
- goto error;
- }
- else
- {
- char *psz_command, *psz_arg = 0, *psz_instance = 0;
- size_t i_index = 2;
+ *pp_status = vlm_MessageNew( "export", psz_export );
+ free( psz_export );
+ return VLC_SUCCESS;
+}
- if( strcmp( ppsz_command[2], "play" ) &&
- strcmp( ppsz_command[2], "stop" ) &&
- strcmp( ppsz_command[2], "pause" ) &&
- strcmp( ppsz_command[2], "seek" ) )
- {
- i_index++;
- psz_instance = ppsz_command[2];
+static int ExecuteSave( vlm_t *p_vlm, const char *psz_file, vlm_message_t **pp_status )
+{
+ FILE *f = utf8_fopen( psz_file, "wt" );
+ char *psz_save;
- if( i_command < 4 ) goto syntax_error;
+ if( !f )
+ goto error;
- if( strcmp( ppsz_command[3], "play" ) &&
- strcmp( ppsz_command[3], "stop" ) &&
- strcmp( ppsz_command[3], "pause" ) &&
- strcmp( ppsz_command[3], "seek" ) )
- goto syntax_error;
- }
+ psz_save = Save( p_vlm );
+ if( psz_save == NULL )
+ {
+ fclose( f );
+ goto error;
+ }
+ fwrite( psz_save, strlen( psz_save ), 1, f );
+ free( psz_save );
+ fclose( f );
- psz_command = ppsz_command[i_index];
+ *pp_status = vlm_MessageNew( "save", NULL );
+ return VLC_SUCCESS;
+
+error:
+ *pp_status = vlm_MessageNew( "save", "Unable to save to file" );
+ return VLC_EGENERIC;
+}
- if( i_command >= i_index + 2 ) psz_arg = ppsz_command[i_index + 1];
+static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_status )
+{
+ stream_t *p_stream = stream_UrlNew( p_vlm, psz_url );
+ int64_t i_size;
+ char *psz_buffer;
- vlm_MediaControl( p_vlm, p_media, psz_instance, psz_command,
- psz_arg );
- p_message = vlm_MessageNew( "control", NULL );
- goto success;
- }
+ if( !p_stream )
+ {
+ *pp_status = vlm_MessageNew( "load", "Unable to load from file" );
+ return VLC_EGENERIC;
}
- else if( !strcmp(ppsz_command[0], "save") )
+ /* FIXME needed ? */
+ if( stream_Seek( p_stream, 0 ) != 0 )
{
- if( i_command != 2 ) goto syntax_error;
+ stream_Delete( p_stream );
- if( vlm_Save( p_vlm, ppsz_command[1] ) )
- {
- p_message = vlm_MessageNew( "save", "Unable to save to file" );
- goto error;
- }
- else
- {
- p_message = vlm_MessageNew( "save", NULL );
- goto success;
- }
+ *pp_status = vlm_MessageNew( "load", "Read file error" );
+ return VLC_EGENERIC;
}
- else if( !strcmp(ppsz_command[0], "export" ) )
- {
- char *psz_buf;
-
- if( i_command != 1 ) goto syntax_error;
+ i_size = stream_Size( p_stream );
- p_message = vlm_MessageNew( "export", psz_buf = Save( p_vlm ) );
- free( psz_buf );
+ psz_buffer = malloc( i_size + 1 );
+ if( !psz_buffer )
+ {
+ stream_Delete( p_stream );
- goto success;
+ *pp_status = vlm_MessageNew( "load", "Read file error" );
+ return VLC_EGENERIC;
}
- else if( !strcmp(ppsz_command[0], "load") )
- {
- if( i_command != 2 ) goto syntax_error;
+ stream_Read( p_stream, psz_buffer, i_size );
+ psz_buffer[i_size] = '\0';
- switch( vlm_Load( p_vlm, ppsz_command[1] ) )
- {
- case 0:
- p_message = vlm_MessageNew( "load", NULL );
- goto success;
- case 2:
- p_message = vlm_MessageNew( "load", "Read file error" );
- goto error;
- case 3:
- p_message =
- vlm_MessageNew( "load", "Error while loading file" );
- goto error;
- default:
- p_message =
- vlm_MessageNew( "load", "Unable to load from file" );
- goto error;
- }
- }
+ stream_Delete( p_stream );
- else
+ if( Load( p_vlm, psz_buffer ) )
{
- p_message = vlm_MessageNew( ppsz_command[0], "Unknown command" );
- goto error;
+ free( psz_buffer );
+
+ *pp_status = vlm_MessageNew( "load", "Error while loading file" );
+ return VLC_EGENERIC;
}
- /* Common code between "new" and "setup" */
- if( !strcmp(ppsz_command[0], "new") ||
- !strcmp(ppsz_command[0], "setup") )
- {
- size_t i_command_start = strcmp(ppsz_command[0], "new") ? 2 : 3;
- vlm_media_t *p_media;
- vlm_schedule_t *p_schedule;
+ free( psz_buffer );
- if( i_command < i_command_start ) goto syntax_error;
+ *pp_status = vlm_MessageNew( "load", NULL );
+ return VLC_SUCCESS;
+}
- p_media = vlm_MediaSearch( p_vlm, ppsz_command[1] );
- p_schedule = vlm_ScheduleSearch( p_vlm, ppsz_command[1] );
+static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule, vlc_bool_t b_new,
+ const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
+{
+ const char *psz_cmd = b_new ? "new" : "setup";
+ int i;
- if( !p_media && !p_schedule )
+ for( i = 0; i < i_property; i++ )
+ {
+ if( !strcmp( ppsz_property[i], "enabled" ) ||
+ !strcmp( ppsz_property[i], "disabled" ) )
{
- p_message = vlm_MessageNew( ppsz_command[0], "%s unknown",
- ppsz_command[1] );
- goto error;
+ vlm_ScheduleSetup( p_schedule, ppsz_property[i], NULL );
}
-
- if( p_schedule != NULL )
+ else if( !strcmp( ppsz_property[i], "append" ) )
{
- size_t i;
+ char *psz_line;
+ int j;
+ /* Beware: everything behind append is considered as
+ * command line */
- for( i = i_command_start ; i < i_command ; i++ )
- {
- if( !strcmp( ppsz_command[i], "enabled" ) ||
- !strcmp( ppsz_command[i], "disabled" ) )
- {
- vlm_ScheduleSetup( p_schedule, ppsz_command[i], NULL );
- }
+ if( ++i >= i_property )
+ break;
- /* Beware: everything behind append is considered as
- * command line */
- else if( !strcmp( ppsz_command[i], "append" ) )
- {
- size_t j;
+ psz_line = strdup( ppsz_property[i] );
+ for( j = i+1; j < i_property; j++ )
+ {
+ psz_line = realloc( psz_line, strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 );
+ strcat( psz_line, " " );
+ strcat( psz_line, ppsz_property[j] );
+ }
- if( ++i >= i_command ) break;
+ vlm_ScheduleSetup( p_schedule, "append", psz_line );
+ break;
+ }
+ else
+ {
+ if( i + 1 >= i_property )
+ {
+ if( b_new )
+ vlm_ScheduleDelete( p_vlm, p_schedule, NULL );
+ return ExecuteSyntaxError( psz_cmd, pp_status );
+ }
- for( j = i + 1; j < i_command; j++ )
- {
- ppsz_command[i] =
- realloc( ppsz_command[i], strlen(ppsz_command[i]) +
- strlen(ppsz_command[j]) + 1 + 1 );
- strcat( ppsz_command[i], " " );
- strcat( ppsz_command[i], ppsz_command[j] );
- }
+ vlm_ScheduleSetup( p_schedule, ppsz_property[i], ppsz_property[i+1] );
+ i++;
+ }
+ }
+ *pp_status = vlm_MessageNew( psz_cmd, NULL );
+ return VLC_SUCCESS;
+}
- vlm_ScheduleSetup( p_schedule, ppsz_command[i - 1],
- ppsz_command[i] );
- break;
- }
- else
- {
- if( i + 1 >= i_command && !strcmp(ppsz_command[0], "new") )
- {
- vlm_ScheduleDelete( p_vlm, p_schedule, NULL );
- p_message =
- vlm_MessageNew( ppsz_command[0],
- "Wrong properties syntax" );
- goto error;
- }
- else if( i + 1 >= i_command )
- {
- p_message =
- vlm_MessageNew( ppsz_command[0],
- "Wrong properties syntax" );
- goto error;
- }
+static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, vlc_bool_t b_new,
+ const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
+{
+ const char *psz_cmd = b_new ? "new" : "setup";
+ vlm_media_t *p_cfg = NULL;
+ int i_result;
+ int i;
- vlm_ScheduleSetup( p_schedule, ppsz_command[i],
- ppsz_command[i+1] );
- i++;
- }
- }
- }
+#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" );
- else if( p_media != NULL )
+#define MISSING(cmd) do { if( !psz_value ) ERROR( "missing argument for " cmd ); } while(0)
+ for( i = 0; i < i_property; i++ )
+ {
+ const char *psz_option = ppsz_property[i];
+ const char *psz_value = i+1 < i_property ? ppsz_property[i+1] : NULL;
+
+ if( !strcmp( psz_option, "enabled" ) )
+ {
+ p_cfg->b_enabled = VLC_TRUE;
+ }
+ else if( !strcmp( psz_option, "disabled" ) )
{
- size_t i;
+ p_cfg->b_enabled = VLC_FALSE;
+ }
+ else if( !strcmp( psz_option, "input" ) )
+ {
+ MISSING( "input" );
+ TAB_APPEND( p_cfg->i_input, p_cfg->ppsz_input, strdup(psz_value) );
+ i++;
+ }
+ else if( !strcmp( psz_option, "inputdel" ) && psz_value && !strcmp( psz_value, "all" ) )
+ {
+ while( p_cfg->i_input > 0 )
+ TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[0] );
+ i++;
+ }
+ else if( !strcmp( psz_option, "inputdel" ) )
+ {
+ int j;
- for( i = i_command_start ; i < i_command ; i++ )
+ MISSING( "inputdel" );
+
+ for( j = 0; j < p_cfg->i_input; j++ )
{
- if( !strcmp( ppsz_command[i], "enabled" ) ||
- !strcmp( ppsz_command[i], "disabled" ) )
- {
- vlm_MediaSetup( p_vlm, p_media, ppsz_command[i], NULL );
- }
- else if( i + 1 >= i_command &&
- !strcmp( ppsz_command[i], "mux") )
- {
- if( p_media->i_type != VOD_TYPE )
- {
- p_message = vlm_MessageNew( ppsz_command[0],
- "mux only available for broadcast" );
- }
- else
- {
- vlm_MediaSetup( p_vlm, p_media, ppsz_command[i],
- ppsz_command[i+1] );
- i++;
- }
- }
- else if( !strcmp( ppsz_command[i], "loop" ) ||
- !strcmp( ppsz_command[i], "unloop" ) )
- {
- if( p_media->i_type != BROADCAST_TYPE )
- {
- p_message = vlm_MessageNew( ppsz_command[0],
- "loop only available for broadcast" );
- }
- else
- {
- vlm_MediaSetup( p_vlm, p_media, ppsz_command[i], NULL );
- }
- }
- else
+ if( !strcmp( p_cfg->ppsz_input[j], psz_value ) )
{
- if( ( (i + 1) >= i_command ) &&
- !strcmp(ppsz_command[0], "new") )
- {
- vlm_MediaDelete( p_vlm, p_media, NULL );
- p_message =
- vlm_MessageNew( ppsz_command[0],
- "Wrong properties syntax" );
- goto error;
- }
- else if( (i + 1) >= i_command )
- {
- p_message =
- vlm_MessageNew( ppsz_command[0],
- "Wrong properties syntax" );
- goto error;
- }
-
- vlm_MediaSetup( p_vlm, p_media, ppsz_command[i],
- ppsz_command[i+1] );
- i++;
+ TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[j] );
+ break;
}
}
+ i++;
}
+ else if( !strcmp( psz_option, "inputdeln" ) )
+ {
+ int i_index;
- p_message = vlm_MessageNew( ppsz_command[0], NULL );
- goto success;
+ 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] );
+ i++;
+ }
+ else if( !strcmp( psz_option, "output" ) )
+ {
+ MISSING( "output" );
+
+ if( p_cfg->psz_output != NULL )
+ free( p_cfg->psz_output );
+ p_cfg->psz_output = *psz_value ? strdup( psz_value ) : NULL;
+ i++;
+ }
+ else if( !strcmp( psz_option, "option" ) )
+ {
+ MISSING( "option" );
+
+ TAB_APPEND( p_cfg->i_option, p_cfg->ppsz_option, strdup( psz_value ) );
+ i++;
+ }
+ else if( !strcmp( psz_option, "loop" ) )
+ {
+ if( p_cfg->b_vod )
+ ERROR( "invalid loop option for vod" );
+ p_cfg->broadcast.b_loop = VLC_TRUE;
+ }
+ else if( !strcmp( psz_option, "unloop" ) )
+ {
+ if( p_cfg->b_vod )
+ ERROR( "invalid unloop option for vod" );
+ p_cfg->broadcast.b_loop = VLC_FALSE;
+ }
+ else if( !strcmp( psz_option, "mux" ) )
+ {
+ MISSING( "mux" );
+ if( !p_cfg->b_vod )
+ ERROR( "invalid mux option for broadcast" );
+
+ if( p_cfg->vod.psz_mux )
+ free( p_cfg->vod.psz_mux );
+ p_cfg->vod.psz_mux = *psz_value ? strdup( psz_value ) : NULL;
+ i++;
+ }
+ else
+ {
+ fprintf( stderr, "PROP: name=%s unknown\n", psz_option );
+ ERROR( "Wrong command syntax" );
+ }
}
+#undef MISSING
+#undef ERROR
-success:
- *pp_message = p_message;
- return VLC_SUCCESS;
+ /* */
+ i_result = vlm_ControlInternal( p_vlm, VLM_CHANGE_MEDIA, p_cfg );
+ vlm_media_Delete( p_cfg );
-syntax_error:
- p_message = vlm_MessageNew( ppsz_command[0], "Wrong command syntax" );
+ *pp_status = vlm_MessageNew( psz_cmd, NULL );
+ return i_result;
error:
- *pp_message = p_message;
+ if( p_cfg )
+ {
+ if( b_new )
+ vlm_ControlInternal( p_vlm, VLM_DEL_MEDIA, p_cfg->id );
+ vlm_media_Delete( p_cfg );
+ }
return VLC_EGENERIC;
}
-
-vlm_media_t *vlm_MediaSearch( vlm_t *vlm, const char *psz_name )
+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 )
{
- int i;
-
- for( i = 0; i < vlm->i_media; i++ )
+ /* Check name */
+ if( !strcmp( psz_name, "all" ) || !strcmp( psz_name, "media" ) || !strcmp( psz_name, "schedule" ) )
{
- if( strcmp( psz_name, vlm->media[i]->psz_name ) == 0 )
- return vlm->media[i];
+ *pp_status = vlm_MessageNew( "new", "\"all\", \"media\" and \"schedule\" are reserved names" );
+ return VLC_EGENERIC;
+ }
+ if( ExecuteIsMedia( p_vlm, psz_name ) || ExecuteIsSchedule( p_vlm, psz_name ) )
+ {
+ *pp_status = vlm_MessageNew( "new", "%s: Name already in use", psz_name );
+ return VLC_EGENERIC;
+ }
+ /* */
+ if( !strcmp( psz_type, "schedule" ) )
+ {
+ vlm_schedule_sys_t *p_schedule = vlm_ScheduleNew( p_vlm, psz_name );
+ if( !p_schedule )
+ {
+ *pp_status = vlm_MessageNew( "new", "could not create schedule" );
+ return VLC_EGENERIC;
+ }
+ return ExecuteScheduleProperty( p_vlm, p_schedule, VLC_TRUE, i_property, ppsz_property, pp_status );
}
+ else if( !strcmp( psz_type, "vod" ) || !strcmp( psz_type, "broadcast" ) )
+ {
+ vlm_media_t cfg;
+ int64_t id;
- return NULL;
+ vlm_media_Init( &cfg );
+ cfg.psz_name = strdup( psz_name );
+ cfg.b_vod = !strcmp( psz_type, "vod" );
+
+ if( vlm_ControlInternal( p_vlm, VLM_ADD_MEDIA, &cfg, &id ) )
+ {
+ vlm_media_Clean( &cfg );
+ *pp_status = vlm_MessageNew( "new", "could not create media" );
+ return VLC_EGENERIC;
+ }
+ vlm_media_Clean( &cfg );
+ return ExecuteMediaProperty( p_vlm, id, VLC_TRUE, i_property, ppsz_property, pp_status );
+ }
+ else
+ {
+ *pp_status = vlm_MessageNew( "new", "%s: Choose between vod, broadcast or schedule", psz_type );
+ return VLC_EGENERIC;
+ }
}
-/*****************************************************************************
- * vlm_Save:
- *****************************************************************************/
-static int vlm_Save( vlm_t *p_vlm, const char *psz_file )
+static int ExecuteSetup( vlm_t *p_vlm, const char *psz_name, const int i_property, char *ppsz_property[], vlm_message_t **pp_status )
{
- FILE *file;
- char *psz_save;
-
- if( !p_vlm || !psz_file )
- return 1;
-
- file = utf8_fopen( psz_file, "wt" );
- if( file == NULL ) return 1;
-
- psz_save = Save( p_vlm );
- if( psz_save == NULL )
+ if( ExecuteIsSchedule( p_vlm, psz_name ) )
{
- fclose( file );
- return 1;
+ vlm_schedule_sys_t *p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );
+ return ExecuteScheduleProperty( p_vlm, p_schedule, VLC_FALSE, i_property, ppsz_property, pp_status );
+ }
+ else if( ExecuteIsMedia( p_vlm, psz_name ) )
+ {
+ int64_t id;
+ if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) )
+ goto error;
+ return ExecuteMediaProperty( p_vlm, id, VLC_FALSE, i_property, ppsz_property, pp_status );
}
- fwrite( psz_save, strlen( psz_save ), 1, file );
- fclose( file );
- free( psz_save );
- return 0;
+error:
+ *pp_status = vlm_MessageNew( "setup", "%s unknown", psz_name );
+ return VLC_EGENERIC;
}
-/*****************************************************************************
- * vlm_Load:
- *****************************************************************************/
-static int vlm_Load( vlm_t *p_vlm, const char *psz_file )
+static int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
+ vlm_message_t **pp_message )
{
- stream_t *p_stream;
- int64_t i_size;
- char *psz_buffer;
+ size_t i_command = 0;
+ char buf[strlen (psz_command) + 1], *psz_buf = buf;
+ char *ppsz_command[3+sizeof (buf) / 2];
+ vlm_message_t *p_message = NULL;
- if( !p_vlm || !psz_file )
- return 1;
+ /* First, parse the line and cut it */
+ while( *psz_command != '\0' )
+ {
+ const char *psz_temp;
- p_stream = stream_UrlNew( p_vlm, psz_file );
- if( p_stream == NULL ) return 1;
+ if(isspace (*psz_command))
+ {
+ psz_command++;
+ continue;
+ }
- if( stream_Seek( p_stream, 0 ) != 0 )
- {
- stream_Delete( p_stream );
- return 2;
- }
+ /* support for comments */
+ if( i_command == 0 && *psz_command == '#')
+ {
+ p_message = vlm_MessageNew( "", NULL );
+ goto success;
+ }
- i_size = stream_Size( p_stream );
+ psz_temp = FindCommandEnd( psz_command );
- psz_buffer = malloc( i_size + 1 );
- if( !psz_buffer )
- {
- stream_Delete( p_stream );
- return 2;
- }
+ if( psz_temp == NULL )
+ {
+ p_message = vlm_MessageNew( "Incomplete command", psz_command );
+ goto error;
+ }
- stream_Read( p_stream, psz_buffer, i_size );
- psz_buffer[ i_size ] = '\0';
+ assert (i_command < (sizeof (ppsz_command) / sizeof (ppsz_command[0])));
- stream_Delete( p_stream );
+ ppsz_command[i_command] = psz_buf;
+ memcpy (psz_buf, psz_command, psz_temp - psz_command);
+ psz_buf[psz_temp - psz_command] = '\0';
- if( Load( p_vlm, psz_buffer ) )
+ Unescape (psz_buf, psz_buf);
+
+ i_command++;
+ psz_buf += psz_temp - psz_command + 1;
+ psz_command = psz_temp;
+
+ assert (buf + sizeof (buf) >= psz_buf);
+ }
+
+ /*
+ * And then Interpret it
+ */
+
+#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 )
{
- free( psz_buffer );
- return 3;
+ p_message = vlm_MessageNew( "", 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( "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) )
+ else IF_EXECUTE( "load", (i_command != 2), ExecuteLoad(p_vlm, ppsz_command[1], &p_message) )
+ else IF_EXECUTE( "new", (i_command < 3), ExecuteNew(p_vlm, ppsz_command[1], ppsz_command[2], i_command-3, &ppsz_command[3], &p_message) )
+ else IF_EXECUTE( "setup", (i_command < 2), ExecuteSetup(p_vlm, ppsz_command[1], i_command-2, &ppsz_command[2], &p_message) )
+ else
+ {
+ p_message = vlm_MessageNew( ppsz_command[0], "Unknown command" );
+ goto error;
}
+#undef IF_EXECUTE
- free( psz_buffer );
+success:
+ *pp_message = p_message;
+ return VLC_SUCCESS;
- return 0;
-}
+syntax_error:
+ return ExecuteSyntaxError( ppsz_command[0], pp_message );
+error:
+ *pp_message = p_message;
+ return VLC_EGENERIC;
+}
/*****************************************************************************
* Media handling
*****************************************************************************/
-static vlm_media_instance_t *
-vlm_MediaInstanceSearch( vlm_t *vlm, vlm_media_t *media,
- const char *psz_name )
+vlm_media_sys_t *vlm_MediaSearch( vlm_t *vlm, const char *psz_name )
{
int i;
- for( i = 0; i < media->i_instance; i++ )
+ for( i = 0; i < vlm->i_media; i++ )
{
- if( ( !psz_name && !media->instance[i]->psz_name ) ||
- ( psz_name && media->instance[i]->psz_name &&
- !strcmp( psz_name, media->instance[i]->psz_name ) ) )
- {
- return media->instance[i];
- }
+ if( strcmp( psz_name, vlm->media[i]->cfg.psz_name ) == 0 )
+ return vlm->media[i];
}
return NULL;
}
-static vlm_media_t *vlm_MediaNew( vlm_t *vlm, const char *psz_name, int i_type )
+/*****************************************************************************
+ * 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
+}
+
+static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name )
{
- vlm_media_t *media = malloc( sizeof( vlm_media_t ) );
+ vlm_schedule_sys_t *p_sched = malloc( sizeof( vlm_schedule_sys_t ) );
- if( !media )
+ if( !p_sched )
{
- msg_Err( vlm, "out of memory" );
return NULL;
}
- /* Check if we need to load the VOD server */
- if( i_type == VOD_TYPE && !vlm->i_vod )
- {
- vlm->vod = vlc_object_create( vlm, VLC_OBJECT_VOD );
- vlc_object_attach( vlm->vod, vlm );
- vlm->vod->p_module = module_Need( vlm->vod, "vod server", 0, 0 );
- if( !vlm->vod->p_module )
- {
- msg_Err( vlm, "cannot find vod server" );
- vlc_object_detach( vlm->vod );
- vlc_object_destroy( vlm->vod );
- vlm->vod = 0;
- free( media );
- return NULL;
- }
-
- vlm->vod->p_data = vlm;
- vlm->vod->pf_media_control = vlm_MediaVodControl;
+ if( !psz_name )
+ {
+ return NULL;
}
- if( i_type == VOD_TYPE ) vlm->i_vod++;
-
- media->psz_name = strdup( psz_name );
- media->b_enabled = VLC_FALSE;
- media->b_loop = VLC_FALSE;
- media->vod_media = NULL;
- media->psz_vod_output = NULL;
- media->psz_mux = NULL;
- media->i_input = 0;
- media->input = NULL;
- media->psz_output = NULL;
- media->i_option = 0;
- media->option = NULL;
- media->i_type = i_type;
- media->i_instance = 0;
- media->instance = NULL;
-
- input_ItemInit( VLC_OBJECT(vlm), &media->item );
+ 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_media, vlm->media, media );
+ TAB_APPEND( vlm->i_schedule, vlm->schedule, p_sched );
- return media;
+ return p_sched;
}
/* for now, simple delete. After, del with options (last arg) */
-static void vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, const char *psz_name )
+static void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched,
+ const char *psz_name )
{
- if( media == NULL ) return;
+ if( sched == NULL ) return;
+
+ TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched );
- while( media->i_instance )
+ if( vlm->i_schedule == 0 && vlm->schedule ) free( vlm->schedule );
+ free( sched->psz_name );
+ while( sched->i_command )
{
- vlm_media_instance_t *p_instance = media->instance[0];
- vlm_MediaControl( vlm, media, p_instance->psz_name, "stop", 0 );
+ char *psz_cmd = sched->command[0];
+ TAB_REMOVE( sched->i_command, sched->command, psz_cmd );
+ free( psz_cmd );
}
+ free( sched );
+}
- TAB_REMOVE( vlm->i_media, vlm->media, media );
+static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *vlm, const char *psz_name )
+{
+ int i;
- if( media->i_type == VOD_TYPE )
+ for( i = 0; i < vlm->i_schedule; i++ )
{
- vlm_MediaSetup( vlm, media, "disabled", 0 );
- vlm->i_vod--;
- }
-
- /* Check if we need to unload the VOD server */
- if( media->i_type == VOD_TYPE && !vlm->i_vod )
- {
- module_Unneed( vlm->vod, vlm->vod->p_module );
- vlc_object_detach( vlm->vod );
- vlc_object_destroy( vlm->vod );
- vlm->vod = 0;
+ if( strcmp( psz_name, vlm->schedule[i]->psz_name ) == 0 )
+ {
+ return vlm->schedule[i];
+ }
}
- if( vlm->i_media == 0 && vlm->media ) free( vlm->media );
-
- free( media->psz_name );
-
- while( media->i_input-- ) free( media->input[media->i_input] );
- if( media->input ) free( media->input );
-
- if( media->psz_output ) free( media->psz_output );
- if( media->psz_mux ) free( media->psz_mux );
-
- while( media->i_option-- ) free( media->option[media->i_option] );
- if( media->option ) free( media->option );
-
- input_ItemClean( &media->item );
-
- free( media );
+ return NULL;
}
-static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, const char *psz_cmd,
- const char *psz_value )
+/* Ok, setup schedule command will be able to support only one (argument value) at a time */
+static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
+ const char *psz_value )
{
- if( !psz_cmd) return VLC_EGENERIC;
-
- 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" ) )
+ if( !strcmp( psz_cmd, "enabled" ) )
{
- media->b_enabled = VLC_TRUE;
+ schedule->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 );
+ schedule->b_enabled = VLC_FALSE;
}
- else if( !strcmp( psz_cmd, "input" ) )
+#if !defined( UNDER_CE )
+ else if( !strcmp( psz_cmd, "date" ) )
{
- char *input;
+ 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 */
- input = strdup( psz_value );
+ /* date should be year/month/day-hour:minutes:seconds */
+ p = strchr( 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 )
+ 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
{
- TAB_REMOVE( media->i_input, media->input, media->input[0] );
+ 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, "inputdel" ) )
+ else if( !strcmp( psz_cmd, "period" ) )
{
- char *input;
- int i;
+ 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;
- input = strdup( psz_value );
+ 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 */
- for( i = 0; i < media->i_input; i++ )
+ /* date should be year/month/day-hour:minutes:seconds */
+ p = strchr( psz_value, '-' );
+ if( p )
{
- if( !strcmp( input, media->input[i] ) )
- {
- TAB_REMOVE( media->i_input, media->input, media->input[i] );
+ 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;
}
- else if( !strcmp( psz_cmd, "inputdeln" ) )
+#endif /* UNDER_CE */
+ else if( !strcmp( psz_cmd, "repeat" ) )
{
- int index = atoi( psz_value );
- if( index > 0 && index <= media->i_input )
+ int i;
+
+ if( sscanf( psz_value, "%d", &i ) == 1 )
{
- TAB_REMOVE( media->i_input, media->input, media->input[index-1] );
+ schedule->i_repeat = i;
}
- }
- else if( !strcmp( psz_cmd, "output" ) )
- {
- if( media->psz_output != NULL )
+ else
{
- free( media->psz_output );
+ return 1;
}
- media->psz_output = strdup( psz_value );
}
- else if( !strcmp( psz_cmd, "option" ) )
+ else if( !strcmp( psz_cmd, "append" ) )
{
- char *psz_option;
- psz_option = strdup( psz_value );
+ char *command = strdup( psz_value );
- TAB_APPEND( media->i_option, media->option, psz_option );
+ TAB_APPEND( schedule->i_command, schedule->command, command );
}
else
{
- return VLC_EGENERIC;
+ return 1;
}
+ return 0;
+}
- /* Check if we need to create/delete a vod media */
- if( media->i_type == VOD_TYPE )
+/*****************************************************************************
+ * 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 )
{
- if( !media->b_enabled && media->vod_media )
+ va_start( args, psz_format );
+ if( vasprintf( &p_message->psz_value, psz_format, args ) == -1 )
{
- vlm->vod->pf_media_del( vlm->vod, media->vod_media );
- media->vod_media = 0;
+ va_end( args );
+ free( p_message );
+ return NULL;
}
- 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;
- char *psz_dup;
- int i;
+ va_end( args );
+ }
- input_ItemClean( &media->item );
- input_ItemInit( VLC_OBJECT(vlm), &media->item );
+ p_message->psz_name = strdup( psz_name );
+ p_message->i_child = 0;
+ p_message->child = NULL;
- if( media->psz_output )
- asprintf( &psz_output, "%s:description", media->psz_output );
- else
- asprintf( &psz_output, "#description" );
+ return p_message;
+}
- media->item.psz_uri = strdup( media->input[0] );
+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 );
+}
- TAB_INIT( media->item.i_options, media->item.ppsz_options );
+/* Add a child */
+vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message,
+ vlm_message_t *p_child )
+{
+ if( p_message == NULL ) return NULL;
- asprintf( &psz_dup, "sout=%s", psz_output);
- TAB_APPEND( media->item.i_options, media->item.ppsz_options, psz_dup );
- for( i = 0; i < media->i_option; i++ )
- {
- psz_dup = strdup( media->option[i] );
- TAB_APPEND( media->item.i_options, media->item.ppsz_options, psz_dup );
- }
- psz_dup = strdup( "no-sout-keep" );
- TAB_APPEND( media->item.i_options, media->item.ppsz_options, psz_dup );
+ if( p_child )
+ {
+ TAB_APPEND( p_message->i_child, p_message->child, p_child );
+ }
- asprintf( &psz_header, _("Media: %s"), media->psz_name );
+ return p_child;
+}
- if( (p_input = input_CreateThreadExtended( vlm, &media->item, psz_header, NULL ) ) )
- {
- while( !p_input->b_eof && !p_input->b_error )
- msleep( 100000 );
+/*****************************************************************************
+ * Misc utility functions
+ *****************************************************************************/
+static vlm_message_t *vlm_ShowMedia( vlm_t *p_vlm, 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;
- input_StopThread( p_input );
- input_DestroyThreadExtended( p_input, NULL );
- }
- 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) );
+ p_msg = vlm_MessageNew( p_cfg->psz_name, 0 );
+ vlm_MessageAdd( p_msg,
+ vlm_MessageNew( "type", p_cfg->b_vod ? "vod" : "broadcast" ) );
+ vlm_MessageAdd( p_msg,
+ vlm_MessageNew( "enabled", p_cfg->b_enabled ? "yes" : "no" ) );
- media->vod_media =
- vlm->vod->pf_media_new( vlm->vod, media->psz_name, &item );
- return VLC_SUCCESS;
- }
+ if( p_cfg->b_vod )
+ vlm_MessageAdd( p_msg,
+ vlm_MessageNew( "mux", p_cfg->vod.psz_mux ) );
+ else
+ vlm_MessageAdd( p_msg,
+ vlm_MessageNew( "loop", p_cfg->broadcast.b_loop ? "yes" : "no" ) );
- media->vod_media =
- vlm->vod->pf_media_new( vlm->vod, media->psz_name,
- &media->item );
- }
- }
+ p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "inputs", NULL ) );
+ for( i = 0; i < p_cfg->i_input; i++ )
+ vlm_MessageAdd( p_msg_sub, vlm_MessageNew( p_cfg->ppsz_input[i], NULL ) );
- return VLC_SUCCESS;
-}
+ vlm_MessageAdd( p_msg,
+ vlm_MessageNew( "output", p_cfg->psz_output ? p_cfg->psz_output : "" ) );
-static vlm_media_instance_t *vlm_MediaInstanceNew( vlm_t *p_vlm, const char *psz_name )
-{
- vlm_media_instance_t *p_instance = malloc( sizeof(vlm_media_instance_t) );
- if( !p_instance )
- return NULL;
+ p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "options", 0 ) );
+ for( i = 0; i < p_cfg->i_option; i++ )
+ vlm_MessageAdd( p_msg_sub, vlm_MessageNew( p_cfg->ppsz_option[i], 0 ) );
- memset( p_instance, 0, sizeof(vlm_media_instance_t) );
+ p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "instances", NULL ) );
+ for( i = 0; i < p_media->i_instance; i++ )
+ {
+ vlm_media_instance_sys_t *p_instance = p_media->instance[i];
+ vlc_value_t val;
+ vlm_message_t *p_msg_instance;
+ char *psz_tmp;
- p_instance->psz_name = NULL;
- if( psz_name )
- p_instance->psz_name = strdup( psz_name );
+ val.i_int = END_S;
+ if( p_instance->p_input )
+ var_Get( p_instance->p_input, "state", &val );
- input_ItemInit( VLC_OBJECT(p_vlm), &p_instance->item );
+ p_msg_instance = vlm_MessageAdd( p_msg_sub, vlm_MessageNew( "instance" , NULL ) );
- p_instance->i_index = 0;
- p_instance->b_sout_keep = VLC_FALSE;
- p_instance->p_input = NULL;
- p_instance->p_sout = NULL;
+ vlm_MessageAdd( p_msg_instance,
+ vlm_MessageNew( "name" , p_instance->psz_name ? p_instance->psz_name : "default" ) );
+ vlm_MessageAdd( p_msg_instance,
+ vlm_MessageNew( "state",
+ val.i_int == PLAYING_S ? "playing" :
+ val.i_int == PAUSE_S ? "paused" :
+ "stopped" ) );
- return p_instance;
+ /* FIXME should not do that this way */
+ if( p_instance->p_input )
+ {
+#define APPEND_INPUT_INFO( a, format, type ) \
+ asprintf( &psz_tmp, format, \
+ var_Get ## type( p_instance->p_input, a ) ); \
+ vlm_MessageAdd( p_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( p_msg_instance, vlm_MessageNew( "playlistindex", psz_tmp ) );
+ free( psz_tmp );
+ }
+ return p_msg;
}
-static void vlm_MediaInstanceDelete( vlm_media_instance_t *p_instance )
+
+static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
+ vlm_schedule_sys_t *schedule,
+ const char *psz_filter )
{
- if( p_instance->p_input )
+ if( media != NULL )
{
- input_StopThread( p_instance->p_input );
- input_DestroyThreadExtended( p_instance->p_input, &p_instance->p_sout );
+ vlm_message_t *p_msg = vlm_MessageNew( "show", NULL );
+ if( p_msg )
+ vlm_MessageAdd( p_msg, vlm_ShowMedia( vlm, media ) );
+ return p_msg;
}
- 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 );
- free( p_instance );
-}
+ else if( schedule != NULL )
+ {
+ int i;
+ vlm_message_t *msg;
+ vlm_message_t *msg_schedule;
+ vlm_message_t *msg_child;
+ char buffer[100];
-static 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;
+ msg = vlm_MessageNew( "show", NULL );
+ msg_schedule =
+ vlm_MessageAdd( msg, vlm_MessageNew( schedule->psz_name, 0 ) );
- p_instance = vlm_MediaInstanceSearch( vlm, media, psz_id );
+ vlm_MessageAdd( msg_schedule, vlm_MessageNew("type", "schedule") );
- if( !strcmp( psz_command, "play" ) )
- {
- if( !media->b_enabled || media->i_input == 0 ) return 0;
+ vlm_MessageAdd( msg_schedule,
+ vlm_MessageNew( "enabled", schedule->b_enabled ?
+ "yes" : "no" ) );
- if( !p_instance )
+#if !defined( UNDER_CE )
+ if( schedule->i_date != 0 )
{
- char *psz_dup;
-
- p_instance = vlm_MediaInstanceNew( vlm, psz_id );
- if( !p_instance )
- return VLC_ENOMEM;
-
- TAB_INIT( p_instance->item.i_options, p_instance->item.ppsz_options );
+ struct tm date;
+ time_t i_time = (time_t)( schedule->i_date / 1000000 );
+ char *psz_date;
- if( media->psz_output != NULL || media->psz_vod_output != NULL )
- {
- asprintf( &psz_dup, "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 : "" );
- TAB_APPEND( p_instance->item.i_options, p_instance->item.ppsz_options, psz_dup );
- }
+#ifdef HAVE_LOCALTIME_R
+ localtime_r( &i_time, &date);
+#else
+ struct tm *p_date = localtime( &i_time );
+ date = *p_date;
+#endif
- for( i = 0; i < media->i_option; i++ )
- {
- if( !strcmp( media->option[i], "sout-keep" ) )
- {
- p_instance->b_sout_keep = VLC_TRUE;
- }
- else if( !strcmp( media->option[i], "nosout-keep" ) || !strcmp( media->option[i], "no-sout-keep" ) )
- {
- p_instance->b_sout_keep = VLC_FALSE;
- }
- else
- {
- psz_dup = strdup( media->option[i] );
- TAB_APPEND( p_instance->item.i_options, p_instance->item.ppsz_options, psz_dup );
- }
- }
- /* We force the right sout-keep value (avoid using the sout-keep from the global configuration) */
- if( media->i_type != VOD_TYPE && p_instance->b_sout_keep )
- psz_dup = strdup( "sout-keep" );
- else
- psz_dup = strdup( "no-sout-keep" );
- TAB_APPEND( p_instance->item.i_options, p_instance->item.ppsz_options, psz_dup );
+ 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 );
- TAB_APPEND( media->i_instance, media->instance, p_instance );
+ vlm_MessageAdd( msg_schedule,
+ vlm_MessageNew( "date", psz_date ) );
+ free( psz_date );
}
-
- if( ( psz_args && sscanf(psz_args, "%d", &i) == 1 ) && i > 0 && i-1 < media->i_input )
+ else
{
- p_instance->i_index = i-1;
+ vlm_MessageAdd( msg_schedule, vlm_MessageNew("date", "now") );
}
- 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 )
+ if( schedule->i_period != 0 )
{
- input_StopThread( p_instance->p_input );
- input_DestroyThreadExtended( p_instance->p_input, &p_instance->p_sout );
- if( !p_instance->b_sout_keep && p_instance->p_sout )
- {
- sout_DeleteInstance( p_instance->p_sout );
- p_instance->p_sout = NULL;
- }
- }
+ 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;
- asprintf( &psz_header, _("Media: %s"), media->psz_name );
- p_instance->p_input = input_CreateThreadExtended( vlm, &p_instance->item, psz_header, p_instance->p_sout );
- if( !p_instance->p_input )
+ 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
{
- TAB_REMOVE( media->i_instance, media->instance, p_instance );
- vlm_MediaInstanceDelete( p_instance );
+ vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "0") );
}
- free( psz_header );
+#endif /* UNDER_CE */
- return VLC_SUCCESS;
- }
+ sprintf( buffer, "%d", schedule->i_repeat );
+ vlm_MessageAdd( msg_schedule, vlm_MessageNew( "repeat", buffer ) );
- if( !p_instance )
- return VLC_EGENERIC;
+ msg_child =
+ vlm_MessageAdd( msg_schedule, vlm_MessageNew("commands", 0) );
- if( !strcmp( psz_command, "seek" ) )
- {
- if( psz_args )
+ for( i = 0; i < schedule->i_command; i++ )
{
- 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;
- }
- }
+ vlm_MessageAdd( msg_child,
+ vlm_MessageNew( schedule->command[i], NULL ) );
}
- }
- 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;
- }
+ return msg;
+
}
- else if( !strcmp( psz_command, "forward" ) )
+
+ else if( psz_filter && !strcmp( psz_filter, "media" ) )
{
- float f_pos;
- float f_scale;
+ vlm_message_t *p_msg;
+ vlm_message_t *p_msg_child;
+ int i_vod = 0, i_broadcast = 0;
+ int i;
+ char *psz_count;
- if( psz_args )
+ for( i = 0; i < vlm->i_media; i++ )
{
- 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;
+ if( vlm->media[i]->cfg.b_vod )
+ i_vod++;
+ else
+ i_broadcast++;
}
- }
- else if( !strcmp( psz_command, "stop" ) )
- {
- TAB_REMOVE( media->i_instance, media->instance, p_instance );
-
- vlm_MediaInstanceDelete( p_instance );
- return VLC_SUCCESS;
- }
- else if( !strcmp( psz_command, "pause" ) )
- {
- int i_state;
- if( !p_instance->p_input ) return VLC_SUCCESS;
+ asprintf( &psz_count, "( %d broadcast - %d vod )", i_broadcast, i_vod);
- i_state = var_GetInteger( p_instance->p_input, "state" );
+ p_msg = vlm_MessageNew( "show", NULL );
+ p_msg_child = vlm_MessageAdd( p_msg, vlm_MessageNew( "media", psz_count ) );
+ free( psz_count );
- if( i_state == PAUSE_S ) i_state = PLAYING_S;
- else i_state = PAUSE_S;
- var_SetInteger( p_instance->p_input, "state", i_state );
+ for( i = 0; i < vlm->i_media; i++ )
+ vlm_MessageAdd( p_msg_child, vlm_ShowMedia( vlm, vlm->media[i] ) );
- return VLC_SUCCESS;
+ return p_msg;
}
- 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
-}
-
-static 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 )
+ else if( psz_filter && !strcmp( psz_filter, "schedule" ) )
{
- return NULL;
- }
+ int i;
+ vlm_message_t *msg;
+ vlm_message_t *msg_child;
- if( !psz_name )
- {
- return NULL;
- }
+ msg = vlm_MessageNew( "show", NULL );
+ msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "schedule", 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;
+ for( i = 0; i < vlm->i_schedule; i++ )
+ {
+ vlm_schedule_sys_t *s = vlm->schedule[i];
+ vlm_message_t *msg_schedule;
+ mtime_t i_time, i_next_date;
- TAB_APPEND( vlm->i_schedule, vlm->schedule, p_sched );
+ msg_schedule = vlm_MessageAdd( msg_child,
+ vlm_MessageNew( s->psz_name, 0 ) );
+ vlm_MessageAdd( msg_schedule,
+ vlm_MessageNew( "enabled", s->b_enabled ?
+ "yes" : "no" ) );
- return p_sched;
-}
+ /* calculate next date */
+ i_time = vlm_Date();
+ i_next_date = s->i_date;
-/* for now, simple delete. After, del with options (last arg) */
-static void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_t *sched,
- const char *psz_name )
-{
- if( sched == NULL ) return;
+ if( s->i_period != 0 )
+ {
+ int j = 0;
+ while( s->i_date + j * s->i_period <= i_time &&
+ s->i_repeat > j )
+ {
+ j++;
+ }
- TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched );
+ i_next_date = s->i_date + j * s->i_period;
+ }
- 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 );
-}
+ if( i_next_date > i_time )
+ {
+ time_t i_date = (time_t) (i_next_date / 1000000) ;
-static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *vlm, const char *psz_name )
-{
- int i;
+#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
- for( i = 0; i < vlm->i_schedule; i++ )
- {
- if( strcmp( psz_name, vlm->schedule[i]->psz_name ) == 0 )
- {
- return vlm->schedule[i];
+ vlm_MessageAdd( msg_schedule,
+ vlm_MessageNew( "next launch", psz_date ) );
+#endif
+ }
}
- }
-
- return NULL;
-}
-/* Ok, setup schedule command will be able to support only one (argument value) at a time */
-static 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;
+ return msg;
}
-#if !defined( UNDER_CE )
- else if( !strcmp( psz_cmd, "date" ) )
+
+ else if( ( psz_filter == NULL ) && ( media == NULL ) && ( schedule == NULL ) )
{
- struct tm time;
- const char *p;
- time_t date;
+ vlm_message_t *show1 = vlm_Show( vlm, NULL, NULL, "media" );
+ vlm_message_t *show2 = vlm_Show( vlm, NULL, NULL, "schedule" );
- 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 */
+ vlm_MessageAdd( show1, show2->child[0] );
- /* date should be year/month/day-hour:minutes:seconds */
- p = strchr( psz_value, '-' );
+ /* We must destroy the parent node "show" of show2
+ * and not the children */
+ free( show2->psz_name );
+ free( show2 );
- 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;
+ return show1;
+ }
- 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;
- }
+ else
+ {
+ return vlm_MessageNew( "show", NULL );
+ }
+}
- 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;
- }
+static vlm_message_t *vlm_Help( vlm_t *vlm, char *psz_filter )
+{
+ vlm_message_t *message, *message_child;
- 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;
+#define MessageAdd( a ) \
+ vlm_MessageAdd( message, vlm_MessageNew( a, NULL ) );
+#define MessageAddChild( a ) \
+ vlm_MessageAdd( message_child, vlm_MessageNew( a, NULL ) );
- /* First, if date or period are modified, repeat should be equal to -1 */
- schedule->i_repeat = -1;
+ if( psz_filter == NULL )
+ {
+ message = vlm_MessageNew( "help", NULL );
- 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 */
+ 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)" );
- /* 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;
- }
+ 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)" );
- 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;
- }
- }
+ 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)" );
- /* 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;
+ message_child = MessageAdd( "Control Commands Syntax:" );
+ MessageAddChild( "play [input_number]" );
+ MessageAddChild( "pause" );
+ MessageAddChild( "stop" );
+ MessageAddChild( "seek [+-](percentage) | [+-](seconds)s | [+-](miliseconds)ms" );
- if( sscanf( psz_value, "%d", &i ) == 1 )
- {
- schedule->i_repeat = i;
- }
- else
- {
- return 1;
- }
+ return message;
}
- else if( !strcmp( psz_cmd, "append" ) )
- {
- char *command = strdup( psz_value );
- TAB_APPEND( schedule->i_command, schedule->command, command );
- }
- else
- {
- return 1;
- }
- return 0;
+ return vlm_MessageNew( "help", NULL );
}
/*****************************************************************************
- * Message handling functions
+ * Config handling functions
*****************************************************************************/
-vlm_message_t *vlm_MessageNew( const char *psz_name,
- const char *psz_format, ... )
+static int Load( vlm_t *vlm, char *file )
{
- vlm_message_t *p_message;
- va_list args;
-
- if( !psz_name ) return NULL;
+ char *pf = file;
+ int i_line = 1;
- p_message = malloc( sizeof(vlm_message_t) );
- if( !p_message)
+ while( *pf != '\0' )
{
- return NULL;
- }
+ vlm_message_t *message = NULL;
+ int i_end = 0;
- p_message->psz_value = 0;
+ while( pf[i_end] != '\n' && pf[i_end] != '\0' && pf[i_end] != '\r' )
+ {
+ i_end++;
+ }
- if( psz_format )
- {
- va_start( args, psz_format );
- if( vasprintf( &p_message->psz_value, psz_format, args ) == -1 )
+ if( pf[i_end] == '\r' || pf[i_end] == '\n' )
{
- va_end( args );
- free( p_message );
- return NULL;
+ pf[i_end] = '\0';
+ i_end++;
+ if( pf[i_end] == '\n' ) i_end++;
}
- va_end( args );
- }
- p_message->psz_name = strdup( psz_name );
- p_message->i_child = 0;
- p_message->child = NULL;
+ 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 );
- return p_message;
-}
+ pf += i_end;
+ i_line++;
+ }
-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 );
+ return 0;
}
-/* Add a child */
-vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message,
- vlm_message_t *p_child )
+static char *Save( vlm_t *vlm )
{
- if( p_message == NULL ) return NULL;
+ 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 );
- if( p_child )
+ for( i = 0; i < vlm->i_media; i++ )
{
- TAB_APPEND( p_message->i_child, p_message->child, p_child );
- }
-
- return p_child;
-}
+ vlm_media_sys_t *media = vlm->media[i];
+ vlm_media_t *p_cfg = &media->cfg;
-/*****************************************************************************
- * 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;
+ if( p_cfg->b_vod )
+ i_length += strlen( "new * vod " ) + strlen(p_cfg->psz_name);
+ else
+ i_length += strlen( "new * broadcast " ) + strlen(p_cfg->psz_name);
- msg = vlm_MessageNew( "show", NULL );
- msg_media = vlm_MessageAdd( msg, vlm_MessageNew( media->psz_name, 0 ));
+ if( p_cfg->b_enabled == VLC_TRUE )
+ i_length += strlen( "enabled" );
+ else
+ i_length += strlen( "disabled" );
- 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" ) );
+ if( !p_cfg->b_vod && p_cfg->broadcast.b_loop == VLC_TRUE )
+ i_length += strlen( " loop\n" );
+ else
+ i_length += strlen( "\n" );
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "loop", media->b_loop ?
- "yes" : "no" ) );
+ for( j = 0; j < p_cfg->i_input; j++ )
+ i_length += strlen( "setup * input \"\"\n" ) + strlen( p_cfg->psz_name ) + strlen( p_cfg->ppsz_input[j] );
- if( media->i_type == VOD_TYPE && media->psz_mux )
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "mux", media->psz_mux ) );
+ if( p_cfg->psz_output != NULL )
+ i_length += strlen( "setup * output \n" ) + strlen(p_cfg->psz_name) + strlen(p_cfg->psz_output);
- msg_child = vlm_MessageAdd( msg_media,
- vlm_MessageNew( "inputs", NULL ) );
+ for( j = 0; j < p_cfg->i_option; j++ )
+ i_length += strlen("setup * option \n") + strlen(p_cfg->psz_name) + strlen(p_cfg->ppsz_option[j]);
- for( i = 0; i < media->i_input; i++ )
- {
- vlm_MessageAdd( msg_child,
- vlm_MessageNew( media->input[i], NULL ) );
- }
+ if( p_cfg->b_vod && p_cfg->vod.psz_mux )
+ i_length += strlen("setup * mux \n") + strlen(p_cfg->psz_name) + strlen(p_cfg->vod.psz_mux);
+ }
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "output", media->psz_output ?
- media->psz_output : "" ) );
+ for( i = 0; i < vlm->i_schedule; i++ )
+ {
+ vlm_schedule_sys_t *schedule = vlm->schedule[i];
- msg_child = vlm_MessageAdd( msg_media, vlm_MessageNew( "options", 0 ));
+ i_length += strlen( "new schedule " ) + strlen( schedule->psz_name );
- for( i = 0; i < media->i_option; i++ )
+ if( schedule->b_enabled == VLC_TRUE )
+ {
+ i_length += strlen( "date //-:: enabled\n" ) + 14;
+ }
+ else
{
- vlm_MessageAdd( msg_child, vlm_MessageNew( media->option[i], 0 ) );
+ i_length += strlen( "date //-:: disabled\n" ) + 14;
}
- msg_child = vlm_MessageAdd( msg_media,
- vlm_MessageNew( "instances", NULL ) );
- for( i = 0; i < media->i_instance; i++ )
+ if( schedule->i_period != 0 )
{
- vlm_media_instance_t *p_instance = media->instance[i];
- vlc_value_t val;
- vlm_message_t *msg_instance;
- char *psz_tmp;
+ i_length += strlen( "setup " ) + strlen( schedule->psz_name ) +
+ strlen( "period //-::\n" ) + 14;
+ }
- if( !p_instance->p_input ) val.i_int = END_S;
- else var_Get( p_instance->p_input, "state", &val );
+ if( schedule->i_repeat >= 0 )
+ {
+ char buffer[12];
- 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 );
+ sprintf( buffer, "%d", schedule->i_repeat );
+ i_length += strlen( "setup repeat \n" ) +
+ strlen( schedule->psz_name ) + strlen( buffer );
+ }
+ else
+ {
+ i_length++;
}
- return msg;
+ for( j = 0; j < schedule->i_command; j++ )
+ {
+ i_length += strlen( "setup append \n" ) +
+ strlen( schedule->psz_name ) + strlen( schedule->command[j] );
+ }
}
- else if( schedule != NULL )
+ /* 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++ )
{
- int i;
- vlm_message_t *msg;
- vlm_message_t *msg_schedule;
- vlm_message_t *msg_child;
- char buffer[100];
+ vlm_media_sys_t *media = vlm->media[i];
+ vlm_media_t *p_cfg = &media->cfg;
- msg = vlm_MessageNew( "show", NULL );
- msg_schedule =
- vlm_MessageAdd( msg, vlm_MessageNew( schedule->psz_name, 0 ) );
+ if( p_cfg->b_vod )
+ p += sprintf( p, "new %s vod ", p_cfg->psz_name );
+ else
+ p += sprintf( p, "new %s broadcast ", p_cfg->psz_name );
- vlm_MessageAdd( msg_schedule, vlm_MessageNew("type", "schedule") );
+ if( p_cfg->b_enabled )
+ p += sprintf( p, "enabled" );
+ else
+ p += sprintf( p, "disabled" );
- vlm_MessageAdd( msg_schedule,
- vlm_MessageNew( "enabled", schedule->b_enabled ?
- "yes" : "no" ) );
+ if( !p_cfg->b_vod && p_cfg->broadcast.b_loop )
+ p += sprintf( p, " loop\n" );
+ else
+ p += sprintf( p, "\n" );
+
+ for( j = 0; j < p_cfg->i_input; j++ )
+ p += sprintf( p, "setup %s input \"%s\"\n", p_cfg->psz_name, p_cfg->ppsz_input[j] );
+
+ if( p_cfg->psz_output )
+ p += sprintf( p, "setup %s output %s\n", p_cfg->psz_name, p_cfg->psz_output );
+
+ for( j = 0; j < p_cfg->i_option; j++ )
+ p += sprintf( p, "setup %s option %s\n", p_cfg->psz_name, p_cfg->ppsz_option[j] );
+
+ if( p_cfg->b_vod && p_cfg->vod.psz_mux )
+ p += sprintf( p, "setup %s mux %s\n", p_cfg->psz_name, p_cfg->vod.psz_mux );
+ }
+ /* and now, the schedule scripts */
#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;
+ for( i = 0; i < vlm->i_schedule; i++ )
+ {
+ vlm_schedule_sys_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);
+ localtime_r( &i_time, &date);
#else
- struct tm *p_date = localtime( &i_time );
- date = *p_date;
+ 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 );
+ p += sprintf( p, "new %s schedule ", schedule->psz_name);
- vlm_MessageAdd( msg_schedule,
- vlm_MessageNew( "date", psz_date ) );
- free( psz_date );
+ 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
{
- vlm_MessageAdd( msg_schedule, vlm_MessageNew("date", "now") );
+ 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 )
{
- time_t i_time = (time_t) ( schedule->i_period / 1000000 );
- struct tm date;
+ 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;
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);
+ 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);
+ }
- vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", buffer) );
+ if( schedule->i_repeat >= 0 )
+ {
+ p += sprintf( p, "setup %s repeat %d\n",
+ schedule->psz_name, schedule->i_repeat );
}
else
{
- vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "0") );
+ 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 */
- sprintf( buffer, "%d", schedule->i_repeat );
- vlm_MessageAdd( msg_schedule, vlm_MessageNew( "repeat", buffer ) );
+ return save;
+}
+
+/*****************************************************************************
+ *
+ *****************************************************************************/
+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;
+ const char *psz;
+ int64_t id;
+
+ if( !p_private || !p_vod_media )
+ return VLC_EGENERIC;
- msg_child =
- vlm_MessageAdd( msg_schedule, vlm_MessageNew("commands", 0) );
+ vlc_mutex_lock( &vlm->lock );
- for( i = 0; i < schedule->i_command; i++ )
+ /* Find media id */
+ for( i = 0, id = -1; i < vlm->i_media; i++ )
+ {
+ if( p_vod_media == vlm->media[i]->vod.p_media )
{
- vlm_MessageAdd( msg_child,
- vlm_MessageNew( schedule->command[i], NULL ) );
+ id = vlm->media[i]->cfg.id;
+ break;
}
-
- return msg;
-
+ }
+ if( id == -1 )
+ {
+ vlc_mutex_unlock( &vlm->lock );
+ return VLC_EGENERIC;
}
- else if( psz_filter && !strcmp( psz_filter, "media" ) )
+ switch( i_query )
{
- int i, j;
- vlm_message_t *msg;
- vlm_message_t *msg_child;
- int i_vod = 0, i_broadcast = 0;
- char *psz_count;
+ case VOD_MEDIA_PLAY:
+ psz = (const char *)va_arg( args, const char * );
+ i_ret = vlm_ControlInternal( vlm, VLM_START_MEDIA_VOD_INSTANCE, id, psz_id, 0, psz );
+ break;
- for( i = 0; i < vlm->i_media; i++ )
- {
- if( vlm->media[i]->i_type == VOD_TYPE )
- i_vod ++;
- else
- i_broadcast ++;
- }
+ case VOD_MEDIA_PAUSE:
+ i_ret = vlm_ControlInternal( vlm, VLM_PAUSE_MEDIA_INSTANCE, id, psz_id );
+ break;
- asprintf( &psz_count, "( %d broadcast - %d vod )", i_broadcast, i_vod);
+ case VOD_MEDIA_STOP:
+ i_ret = vlm_ControlInternal( vlm, VLM_STOP_MEDIA_INSTANCE, id, psz_id );
+ break;
- msg = vlm_MessageNew( "show", NULL );
- msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "media", psz_count ) );
- free( psz_count );
+ case VOD_MEDIA_SEEK:
+ {
+ double d_position = (double)va_arg( args, double );
+ i_ret = vlm_ControlInternal( vlm, VLM_SET_MEDIA_INSTANCE_POSITION, id, psz_id, d_position/100.0 );
+ break;
+ }
- for( i = 0; i < vlm->i_media; i++ )
- {
- vlm_media_t *m = vlm->media[i];
- vlm_message_t *msg_media, *msg_instance;
+ case VOD_MEDIA_REWIND:
+ {
+ double d_scale = (double)va_arg( args, double );
+ double d_position;
- msg_media = vlm_MessageAdd( msg_child,
- vlm_MessageNew( m->psz_name, 0 ) );
+ vlm_ControlInternal( vlm, VLM_GET_MEDIA_INSTANCE_POSITION, id, psz_id, &d_position );
+ d_position -= (d_scale / 1000.0);
+ if( d_position < 0.0 )
+ d_position = 0.0;
+ i_ret = vlm_ControlInternal( vlm, VLM_SET_MEDIA_INSTANCE_POSITION, id, psz_id, d_position );
+ break;
+ }
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "type", m->i_type == VOD_TYPE ?
- "vod" : "broadcast" ) );
+ case VOD_MEDIA_FORWARD:
+ {
+ double d_scale = (double)va_arg( args, double );
+ double d_position;
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "enabled", m->b_enabled ?
- "yes" : "no" ) );
+ vlm_ControlInternal( vlm, VLM_GET_MEDIA_INSTANCE_POSITION, id, psz_id, &d_position );
+ d_position += (d_scale / 1000.0);
+ if( d_position > 1.0 )
+ d_position = 1.0;
+ i_ret = vlm_ControlInternal( vlm, VLM_SET_MEDIA_INSTANCE_POSITION, id, psz_id, d_position );
+ break;
+ }
- if( m->i_type == VOD_TYPE && m->psz_mux )
- vlm_MessageAdd( msg_media,
- vlm_MessageNew( "mux", m->psz_mux ) );
+ default:
+ i_ret = VLC_EGENERIC;
+ break;
+ }
- msg_instance = vlm_MessageAdd( msg_media,
- vlm_MessageNew( "instances", 0 ) );
+ vlc_mutex_unlock( &vlm->lock );
- 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 i_ret;
+}
- return msg;
- }
- else if( psz_filter && !strcmp( psz_filter, "schedule" ) )
+/*****************************************************************************
+ * 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 )
{
- int i;
- vlm_message_t *msg;
- vlm_message_t *msg_child;
+ char **ppsz_scheduled_commands = NULL;
+ int i_scheduled_commands = 0;
- msg = vlm_MessageNew( "show", NULL );
- msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "schedule", NULL ) );
+ vlc_mutex_lock( &vlm->lock );
- for( i = 0; i < vlm->i_schedule; i++ )
+ /* destroy the inputs that wants to die, and launch the next input */
+ for( i = 0; i < vlm->i_media; i++ )
{
- vlm_schedule_t *s = vlm->schedule[i];
- vlm_message_t *msg_schedule;
- mtime_t i_time, i_next_date;
+ vlm_media_sys_t *p_media = vlm->media[i];
- msg_schedule = vlm_MessageAdd( msg_child,
- vlm_MessageNew( s->psz_name, 0 ) );
- vlm_MessageAdd( msg_schedule,
- vlm_MessageNew( "enabled", s->b_enabled ?
- "yes" : "no" ) );
+ for( j = 0; j < p_media->i_instance; )
+ {
+ vlm_media_instance_sys_t *p_instance = p_media->instance[j];
- /* calculate next date */
- i_time = vlm_Date();
- i_next_date = s->i_date;
+ if( p_instance->p_input && ( p_instance->p_input->b_eof || p_instance->p_input->b_error ) )
+ {
+ int i_new_input_index;
- if( s->i_period != 0 )
- {
- int j = 0;
- while( s->i_date + j * s->i_period <= i_time &&
- s->i_repeat > j )
+ /* */
+ i_new_input_index = p_instance->i_index + 1;
+ if( !p_media->cfg.b_vod && p_media->cfg.broadcast.b_loop && i_new_input_index >= p_media->cfg.i_input )
+ i_new_input_index = 0;
+
+ /* FIXME implement multiple input with VOD */
+ if( p_media->cfg.b_vod || i_new_input_index >= p_media->cfg.i_input )
+ vlm_ControlInternal( vlm, VLM_STOP_MEDIA_INSTANCE, p_media->cfg.id, p_instance->psz_name );
+ else
+ vlm_ControlInternal( vlm, VLM_START_MEDIA_BROADCAST_INSTANCE, p_media->cfg.id, p_instance->psz_name );
+
+ j = 0;
+ }
+ else
{
j++;
}
-
- i_next_date = s->i_date + j * s->i_period;
}
+ }
- if( i_next_date > i_time )
+ /* 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 )
{
- time_t i_date = (time_t) (i_next_date / 1000000) ;
+ 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++;
+ }
-#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
+ i_real_date = vlm->schedule[i]->i_date + j *
+ vlm->schedule[i]->i_period;
+ }
- vlm_MessageAdd( msg_schedule,
- vlm_MessageNew( "next launch", psz_date ) );
-#endif
+ 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 );
+ }
- return msg;
+ i_lastcheck = i_time;
+
+ vlc_mutex_unlock( &vlm->lock );
+
+ msleep( 100000 );
}
- else if( ( psz_filter == NULL ) && ( media == NULL ) && ( schedule == NULL ) )
+ return VLC_SUCCESS;
+}
+
+/* New API
+ */
+/*
+typedef struct
+{
+ struct
{
- vlm_message_t *show1 = vlm_Show( vlm, NULL, NULL, "media" );
- vlm_message_t *show2 = vlm_Show( vlm, NULL, NULL, "schedule" );
+ int i_connection_count;
+ int i_connection_active;
+ } vod;
+ struct
+ {
+ int i_count;
+ vlc_bool_t b_playing;
+ int i_playing_index;
+ } broadcast;
- vlm_MessageAdd( show1, show2->child[0] );
+} vlm_media_status_t;
+*/
- /* We must destroy the parent node "show" of show2
- * and not the children */
- free( show2->psz_name );
- free( show2 );
+/* */
+static vlm_media_sys_t *vlm_ControlMediaGetById( vlm_t *p_vlm, int64_t id )
+{
+ int i;
- return show1;
+ for( i = 0; i < p_vlm->i_media; i++ )
+ {
+ if( p_vlm->media[i]->cfg.id == id )
+ return p_vlm->media[i];
}
+ return NULL;
+}
+static vlm_media_sys_t *vlm_ControlMediaGetByName( vlm_t *p_vlm, const char *psz_name )
+{
+ int i;
- else
+ for( i = 0; i < p_vlm->i_media; i++ )
{
- return vlm_MessageNew( "show", NULL );
+ if( !strcmp( p_vlm->media[i]->cfg.psz_name, psz_name ) )
+ return p_vlm->media[i];
}
+ return NULL;
}
-
-static vlm_message_t *vlm_Help( vlm_t *vlm, char *psz_filter )
+static int vlm_MediaDescriptionCheck( vlm_t *p_vlm, vlm_media_t *p_cfg )
{
- vlm_message_t *message, *message_child;
+ int i;
-#define MessageAdd( a ) \
- vlm_MessageAdd( message, vlm_MessageNew( a, NULL ) );
-#define MessageAddChild( a ) \
- vlm_MessageAdd( message_child, vlm_MessageNew( a, NULL ) );
+ if( !p_cfg || !p_cfg->psz_name ||
+ !strcmp( p_cfg->psz_name, "all" ) || !strcmp( p_cfg->psz_name, "media" ) || !strcmp( p_cfg->psz_name, "schedule" ) )
+ return VLC_EGENERIC;
- if( psz_filter == NULL )
+ for( i = 0; i < p_vlm->i_media; i++ )
{
- message = vlm_MessageNew( "help", NULL );
+ if( p_vlm->media[i]->cfg.id == p_cfg->id )
+ continue;
+ if( !strcmp( p_vlm->media[i]->cfg.psz_name, p_cfg->psz_name ) )
+ return VLC_EGENERIC;
+ }
+ return VLC_SUCCESS;
+}
- 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)" );
+/* Called after a media description is changed/added */
+static int vlm_OnMediaUpdate( vlm_t *p_vlm, vlm_media_sys_t *p_media )
+{
+ vlm_media_t *p_cfg = &p_media->cfg;
+ /* Check if we need to create/delete a vod media */
+ if( p_cfg->b_vod )
+ {
+ if( !p_cfg->b_enabled && p_media->vod.p_media )
+ {
+ p_vlm->p_vod->pf_media_del( p_vlm->p_vod, p_media->vod.p_media );
+ p_media->vod.p_media = NULL;
+ }
+ else if( p_cfg->b_enabled && !p_media->vod.p_media && p_cfg->i_input )
+ {
+ /* Pre-parse the input */
+ input_thread_t *p_input;
+ char *psz_output;
+ char *psz_header;
+ char *psz_dup;
+ int i;
- 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)" );
+ input_ItemClean( &p_media->vod.item );
+ input_ItemInit( VLC_OBJECT(p_vlm), &p_media->vod.item );
+
+ if( p_cfg->psz_output )
+ asprintf( &psz_output, "%s:description", p_cfg->psz_output );
+ else
+ asprintf( &psz_output, "#description" );
- message_child = MessageAdd( "Control Commands Syntax:" );
- MessageAddChild( "play [input_number]" );
- MessageAddChild( "pause" );
- MessageAddChild( "stop" );
- MessageAddChild( "seek [+-](percentage) | [+-](seconds)s | [+-](miliseconds)ms" );
+ p_media->vod.item.psz_uri = strdup( p_cfg->ppsz_input[0] );
- return message;
- }
+ TAB_INIT( p_media->vod.item.i_options, p_media->vod.item.ppsz_options );
- return vlm_MessageNew( "help", NULL );
-}
+ asprintf( &psz_dup, "sout=%s", psz_output);
+ TAB_APPEND( p_media->vod.item.i_options, p_media->vod.item.ppsz_options, 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 );
-/*****************************************************************************
- * Config handling functions
- *****************************************************************************/
-static int Load( vlm_t *vlm, char *file )
-{
- char *pf = file;
- int i_line = 1;
+ asprintf( &psz_header, _("Media: %s"), p_cfg->psz_name );
- while( *pf != '\0' )
- {
- vlm_message_t *message = NULL;
- int i_end = 0;
+ if( (p_input = input_CreateThreadExtended( p_vlm, &p_media->vod.item, psz_header, NULL ) ) )
+ {
+ while( !p_input->b_eof && !p_input->b_error )
+ msleep( 100000 );
- while( pf[i_end] != '\n' && pf[i_end] != '\0' && pf[i_end] != '\r' )
- {
- i_end++;
- }
+ input_StopThread( p_input );
+ input_DestroyThreadExtended( p_input, NULL );
+ }
+ free( psz_output );
+ free( psz_header );
- if( pf[i_end] == '\r' || pf[i_end] == '\n' )
- {
- pf[i_end] = '\0';
- i_end++;
- if( pf[i_end] == '\n' ) i_end++;
- }
+ if( p_cfg->vod.psz_mux )
+ {
+ input_item_t item;
+ es_format_t es, *p_es = &es;
+ char fourcc[5];
- if( *pf && ExecuteCommand( vlm, pf, &message ) )
- {
- if( message )
+ sprintf( fourcc, "%4.4s", p_cfg->vod.psz_mux );
+ 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;
+ item.i_es = 1;
+ item.es = &p_es;
+ es_format_Init( &es, VIDEO_ES, *((int *)fourcc) );
+
+ p_media->vod.p_media =
+ p_vlm->p_vod->pf_media_new( p_vlm->p_vod, p_cfg->psz_name, &item );
+ }
+ else
{
- 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 );
+ p_media->vod.p_media =
+ p_vlm->p_vod->pf_media_new( p_vlm->p_vod, p_cfg->psz_name, &p_media->vod.item );
}
- return 1;
}
- if( message ) vlm_MessageDelete( message );
-
- pf += i_end;
- i_line++;
+ }
+ else
+ {
+ /* TODO start media if needed */
}
- return 0;
-}
+ /* TODO add support of var vlm_media_broadcast/vlm_media_vod */
-static char *Save( vlm_t *vlm )
+ return VLC_SUCCESS;
+}
+static int vlm_ControlMediaChange( vlm_t *p_vlm, vlm_media_t *p_cfg )
{
- 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 );
+ vlm_media_sys_t *p_media = vlm_ControlMediaGetById( p_vlm, p_cfg->id );
- for( i = 0; i < vlm->i_media; i++ )
+ /* */
+ if( !p_media || vlm_MediaDescriptionCheck( p_vlm, p_cfg ) )
+ return VLC_EGENERIC;
+ if( ( p_media->cfg.b_vod && !p_cfg->b_vod ) || ( !p_media->cfg.b_vod && p_cfg->b_vod ) )
+ return VLC_EGENERIC;
+
+ if( 0 )
{
- vlm_media_t *media = vlm->media[i];
+ /* TODO check what are the changes being done (stop instance if needed) */
+ }
- 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);
- }
+ vlm_media_Clean( &p_media->cfg );
+ vlm_media_Copy( &p_media->cfg, p_cfg );
- if( media->b_enabled == VLC_TRUE )
- {
- i_length += strlen( "enabled" );
- }
- else
- {
- i_length += strlen( "disabled" );
- }
+ 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;
- if( media->b_loop == VLC_TRUE )
- {
- i_length += strlen( " loop\n" );
- }
- else
+ if( vlm_MediaDescriptionCheck( p_vlm, p_cfg ) || vlm_ControlMediaGetByName( p_vlm, p_cfg->psz_name ) )
+ {
+ msg_Err( p_vlm, "invalid media description" );
+ return VLC_EGENERIC;
+ }
+ /* 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 );
+ 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 )
{
- i_length += strlen( "\n" );
+ msg_Err( p_vlm, "cannot find vod server" );
+ vlc_object_detach( p_vlm->p_vod );
+ vlc_object_destroy( p_vlm->p_vod );
+ p_vlm->p_vod = 0;
+ return VLC_EGENERIC;
}
- for( j = 0; j < media->i_input; j++ )
- {
- i_length += strlen( "setup input \"\"\n" ) +
- strlen( media->psz_name ) + strlen( media->input[j] );
- }
+ 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++;
- if( media->psz_output != NULL )
- {
- i_length += strlen(media->psz_name) + strlen(media->psz_output) +
- strlen( "setup output \n" );
- }
+ p_media = malloc( sizeof( vlm_media_sys_t ) );
+ memset( p_media, 0, sizeof(vlm_media_sys_t) );
- for( j=0 ; j < media->i_option ; j++ )
- {
- i_length += strlen(media->psz_name) + strlen(media->option[j]) +
- strlen("setup option \n");
- }
- }
+ 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 ? */
- for( i = 0; i < vlm->i_schedule; i++ )
- {
- vlm_schedule_t *schedule = vlm->schedule[i];
+ input_ItemInit( VLC_OBJECT(p_vlm), &p_media->vod.item );
- i_length += strlen( "new schedule " ) + strlen( schedule->psz_name );
+ p_media->vod.p_media = NULL;
+ TAB_INIT( p_media->i_instance, p_media->instance );
- if( schedule->b_enabled == VLC_TRUE )
- {
- i_length += strlen( "date //-:: enabled\n" ) + 14;
- }
- else
- {
- i_length += strlen( "date //-:: disabled\n" ) + 14;
- }
+ /* */
+ TAB_APPEND( p_vlm->i_media, p_vlm->media, p_media );
+ if( p_id )
+ *p_id = p_media->cfg.id;
- if( schedule->i_period != 0 )
- {
- i_length += strlen( "setup " ) + strlen( schedule->psz_name ) +
- strlen( "period //-::\n" ) + 14;
- }
+ return vlm_OnMediaUpdate( p_vlm, p_media );
+}
- if( schedule->i_repeat >= 0 )
- {
- char buffer[12];
+static int vlm_ControlMediaDel( vlm_t *p_vlm, int64_t id )
+{
+ vlm_media_sys_t *p_media = vlm_ControlMediaGetById( p_vlm, id );
- sprintf( buffer, "%d", schedule->i_repeat );
- i_length += strlen( "setup repeat \n" ) +
- strlen( schedule->psz_name ) + strlen( buffer );
- }
- else
- {
- i_length++;
- }
+ if( !p_media )
+ return VLC_EGENERIC;
- for( j = 0; j < schedule->i_command; j++ )
- {
- i_length += strlen( "setup append \n" ) +
- strlen( schedule->psz_name ) + strlen( schedule->command[j] );
- }
+ while( p_media->i_instance > 0 )
+ vlm_ControlInternal( p_vlm, VLM_STOP_MEDIA_INSTANCE, id, p_media->instance[0]->psz_name );
+ if( p_media->cfg.b_vod )
+ {
+ p_media->cfg.b_enabled = VLC_FALSE;
+ vlm_OnMediaUpdate( p_vlm, p_media );
+ p_vlm->i_vod--;
}
- /* Don't forget the '\0' */
- i_length++;
- /* now we have the length of save */
+ vlm_media_Clean( &p_media->cfg );
- p = save = malloc( i_length );
- *save = '\0';
+ input_ItemClean( &p_media->vod.item );
- p += sprintf( p, "%s", psz_header );
+ TAB_REMOVE( p_vlm->i_media, p_vlm->media, p_media );
- /* finally we can write in it */
- for( i = 0; i < vlm->i_media; i++ )
+ free( p_media );
+
+ /* Check if we need to unload the VOD server */
+ if( p_vlm->p_vod && p_vlm->i_vod <= 0 )
{
- vlm_media_t *media = vlm->media[i];
+ 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 );
+ p_vlm->p_vod = NULL;
+ }
+ return VLC_SUCCESS;
+}
- 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);
- }
+static int vlm_ControlMediaGets( vlm_t *p_vlm, vlm_media_t ***ppp_dsc, int *pi_dsc )
+{
+ vlm_media_t **pp_dsc;
+ int i_dsc;
+ int i;
- if( media->b_enabled == VLC_TRUE )
- {
- p += sprintf( p, "enabled" );
- }
- else
- {
- p += sprintf( p, "disabled" );
- }
+ TAB_INIT( i_dsc, pp_dsc );
+ for( i = 0; i < p_vlm->i_media; i++ )
+ {
+ vlm_media_t *p_dsc = vlm_media_Duplicate( &p_vlm->media[i]->cfg );
+ TAB_APPEND( i_dsc, pp_dsc, p_dsc );
+ }
- if( media->b_loop == VLC_TRUE )
- {
- p += sprintf( p, " loop\n" );
- }
- else
- {
- p += sprintf( p, "\n" );
- }
+ *ppp_dsc = pp_dsc;
+ *pi_dsc = i_dsc;
- for( j = 0; j < media->i_input; j++ )
- {
- p += sprintf( p, "setup %s input \"%s\"\n", media->psz_name,
- media->input[j] );
- }
+ return VLC_SUCCESS;
+}
+static int vlm_ControlMediaClear( vlm_t *p_vlm )
+{
+ while( p_vlm->i_media > 0 )
+ vlm_ControlMediaDel( p_vlm, p_vlm->media[0]->cfg.id );
- if( media->psz_output != NULL )
- {
- p += sprintf( p, "setup %s output %s\n", media->psz_name,
- media->psz_output );
- }
+ return VLC_SUCCESS;
+}
+static int vlm_ControlMediaGet( vlm_t *p_vlm, int64_t id, vlm_media_t **pp_dsc )
+{
+ vlm_media_sys_t *p_media = vlm_ControlMediaGetById( p_vlm, id );
+ if( !p_media )
+ return VLC_EGENERIC;
- for( j = 0; j < media->i_option; j++ )
- {
- p += sprintf( p, "setup %s option %s\n", media->psz_name,
- media->option[j] );
- }
+ *pp_dsc = vlm_media_Duplicate( &p_media->cfg );
+ return VLC_SUCCESS;
+}
+static int vlm_ControlMediaGetId( vlm_t *p_vlm, const char *psz_name, int64_t *p_id )
+{
+ vlm_media_sys_t *p_media = vlm_ControlMediaGetByName( p_vlm, psz_name );
+ if( !p_media )
+ return VLC_EGENERIC;
+
+ *p_id = p_media->cfg.id;
+ return VLC_SUCCESS;
+}
+
+static vlm_media_instance_sys_t *vlm_ControlMediaInstanceGetByName( vlm_media_sys_t *p_media, const char *psz_id )
+{
+ int i;
+
+ for( i = 0; i < p_media->i_instance; i++ )
+ {
+ const char *psz = p_media->instance[i]->psz_name;
+ if( ( psz == NULL && psz_id == NULL ) ||
+ ( psz && psz_id && !strcmp( psz, psz_id ) ) )
+ return p_media->instance[i];
}
+ return NULL;
+}
+static vlm_media_instance_sys_t *vlm_MediaInstanceNew( vlm_t *p_vlm, const char *psz_name )
+{
+ vlm_media_instance_sys_t *p_instance = malloc( sizeof(vlm_media_instance_sys_t) );
+ if( !p_instance )
+ return NULL;
- /* and now, the schedule scripts */
-#if !defined( UNDER_CE )
- for( i = 0; i < vlm->i_schedule; i++ )
+ memset( p_instance, 0, sizeof(vlm_media_instance_sys_t) );
+
+ p_instance->psz_name = NULL;
+ if( psz_name )
+ p_instance->psz_name = strdup( psz_name );
+
+ input_ItemInit( VLC_OBJECT(p_vlm), &p_instance->item );
+
+ p_instance->i_index = 0;
+ p_instance->b_sout_keep = VLC_FALSE;
+ p_instance->p_input = NULL;
+ p_instance->p_sout = NULL;
+
+ return p_instance;
+}
+static void vlm_MediaInstanceDelete( vlm_media_instance_sys_t *p_instance )
+{
+ if( p_instance->p_input )
{
- vlm_schedule_t *schedule = vlm->schedule[i];
- struct tm date;
- time_t i_time = (time_t) ( schedule->i_date / 1000000 );
+ input_StopThread( p_instance->p_input );
+ input_DestroyThreadExtended( p_instance->p_input, &p_instance->p_sout );
+ }
+ 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 );
+ free( p_instance );
+}
+
+
+static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char *psz_id, int i_input_index, const char *psz_vod_output )
+{
+ vlm_media_sys_t *p_media = vlm_ControlMediaGetById( p_vlm, id );
+ vlm_media_instance_sys_t *p_instance;
+ char *psz_log;
-#ifdef HAVE_LOCALTIME_R
- localtime_r( &i_time, &date);
-#else
- struct tm *p_date = localtime( &i_time );
- date = *p_date;
-#endif
+ if( !p_media || !p_media->cfg.b_enabled || p_media->cfg.i_input <= 0 )
+ return VLC_EGENERIC;
- p += sprintf( p, "new %s schedule ", schedule->psz_name);
+ /* TODO support multiple input for VOD with sout-keep ? */
- 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( ( p_media->cfg.b_vod && !psz_vod_output ) || ( !p_media->cfg.b_vod && psz_vod_output ) )
+ return VLC_EGENERIC;
- if( schedule->i_period != 0 )
- {
- p += sprintf( p, "setup %s ", schedule->psz_name );
+ if( i_input_index < 0 || i_input_index >= p_media->cfg.i_input )
+ return VLC_EGENERIC;
- i_time = (time_t) ( schedule->i_period / 1000000 );
+ p_instance = vlm_ControlMediaInstanceGetByName( p_media, psz_id );
+ if( !p_instance )
+ {
+ vlm_media_t *p_cfg = &p_media->cfg;
+ char *psz_keep;
+ int i;
- 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_instance = vlm_MediaInstanceNew( p_vlm, psz_id );
+ if( !p_instance )
+ return VLC_ENOMEM;
- 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);
+ 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;
+ asprintf( &psz_buffer, "sout=%s%s%s",
+ 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 );
}
- if( schedule->i_repeat >= 0 )
+ for( i = 0; i < p_cfg->i_option; i++ )
{
- p += sprintf( p, "setup %s repeat %d\n",
- schedule->psz_name, schedule->i_repeat );
+ if( !strcmp( p_cfg->ppsz_option[i], "sout-keep" ) )
+ p_instance->b_sout_keep = VLC_TRUE;
+ 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] ) );
}
+ /* 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" );
else
+ psz_keep = strdup( "no-sout-keep" );
+ TAB_APPEND( p_instance->item.i_options, p_instance->item.ppsz_options, psz_keep );
+
+ TAB_APPEND( p_media->i_instance, p_media->instance, p_instance );
+ }
+
+ /* Stop old instance */
+ if( p_instance->p_input )
+ {
+ if( p_instance->i_index == i_input_index &&
+ !p_instance->p_input->b_eof && !p_instance->p_input->b_error )
{
- p += sprintf( p, "\n" );
+ if( var_GetInteger( p_instance->p_input, "state" ) == PAUSE_S )
+ var_SetInteger( p_instance->p_input, "state", PLAYING_S );
+ return VLC_SUCCESS;
}
- for( j = 0; j < schedule->i_command; j++ )
+ input_StopThread( p_instance->p_input );
+ input_DestroyThreadExtended( p_instance->p_input, &p_instance->p_sout );
+ if( !p_instance->b_sout_keep && p_instance->p_sout )
{
- p += sprintf( p, "setup %s append %s\n",
- schedule->psz_name, schedule->command[j] );
+ sout_DeleteInstance( p_instance->p_sout );
+ p_instance->p_sout = NULL;
}
+ }
+
+ /* 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] );
+ 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 );
+ if( !p_instance->p_input )
+ {
+ TAB_REMOVE( p_media->i_instance, p_media->instance, p_instance );
+ vlm_MediaInstanceDelete( p_instance );
}
-#endif /* UNDER_CE */
+ free( psz_log );
- return save;
+ return VLC_SUCCESS;
}
-/*****************************************************************************
- * Manage:
- *****************************************************************************/
-static int vlm_MediaVodControl( void *p_private, vod_media_t *p_vod_media,
- const char *psz_id, int i_query, va_list args )
+static int vlm_ControlMediaInstanceStop( vlm_t *p_vlm, int64_t id, const char *psz_id )
{
- 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 );
+ vlm_media_sys_t *p_media = vlm_ControlMediaGetById( p_vlm, id );
+ vlm_media_instance_sys_t *p_instance;
- /* Find media */
- for( i = 0; i < vlm->i_media; i++ )
- {
- if( p_vod_media == vlm->media[i]->vod_media ) break;
- }
+ if( !p_media )
+ return VLC_EGENERIC;
- if( i == vlm->i_media )
- {
- vlc_mutex_unlock( &vlm->lock );
+ p_instance = vlm_ControlMediaInstanceGetByName( p_media, psz_id );
+ if( !p_instance )
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;
+ TAB_REMOVE( p_media->i_instance, p_media->instance, p_instance );
- case VOD_MEDIA_PAUSE:
- i_ret = vlm_MediaControl( vlm, vlm->media[i], psz_id, "pause", 0 );
- break;
+ vlm_MediaInstanceDelete( p_instance );
- case VOD_MEDIA_STOP:
- i_ret = vlm_MediaControl( vlm, vlm->media[i], psz_id, "stop", 0 );
- break;
+ return VLC_SUCCESS;
+}
+static int vlm_ControlMediaInstancePause( vlm_t *p_vlm, int64_t id, const char *psz_id )
+{
+ vlm_media_sys_t *p_media = vlm_ControlMediaGetById( p_vlm, id );
+ vlm_media_instance_sys_t *p_instance;
+ int i_state;
- 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;
- }
+ if( !p_media )
+ return VLC_EGENERIC;
- 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;
- }
+ p_instance = vlm_ControlMediaInstanceGetByName( p_media, psz_id );
+ if( !p_instance || !p_instance->p_input )
+ return VLC_EGENERIC;
- 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;
- }
+ /* Toggle pause state */
+ i_state = var_GetInteger( p_instance->p_input, "state" );
+ if( i_state == PAUSE_S )
+ var_SetInteger( p_instance->p_input, "state", PLAYING_S );
+ else if( i_state == PLAYING_S )
+ var_SetInteger( p_instance->p_input, "state", PAUSE_S );
+ return VLC_SUCCESS;
+}
+static int vlm_ControlMediaInstanceGetTimePosition( vlm_t *p_vlm, int64_t id, const char *psz_id, int64_t *pi_time, double *pd_position )
+{
+ vlm_media_sys_t *p_media = vlm_ControlMediaGetById( p_vlm, id );
+ vlm_media_instance_sys_t *p_instance;
- default:
- break;
- }
+ if( !p_media )
+ return VLC_EGENERIC;
- vlc_mutex_unlock( &vlm->lock );
+ p_instance = vlm_ControlMediaInstanceGetByName( p_media, psz_id );
+ if( !p_instance || !p_instance->p_input )
+ return VLC_EGENERIC;
- return i_ret;
+ if( pi_time )
+ *pi_time = var_GetTime( p_instance->p_input, "time" );
+ if( pd_position )
+ *pd_position = var_GetFloat( p_instance->p_input, "position" );
+ return VLC_SUCCESS;
}
+static int vlm_ControlMediaInstanceSetTimePosition( vlm_t *p_vlm, int64_t id, const char *psz_id, int64_t i_time, double d_position )
+{
+ vlm_media_sys_t *p_media = vlm_ControlMediaGetById( p_vlm, id );
+ vlm_media_instance_sys_t *p_instance;
+ if( !p_media )
+ return VLC_EGENERIC;
-/*****************************************************************************
- * Manage:
- *****************************************************************************/
-static int Manage( vlc_object_t* p_object )
+ p_instance = vlm_ControlMediaInstanceGetByName( p_media, psz_id );
+ if( !p_instance || !p_instance->p_input )
+ return VLC_EGENERIC;
+
+ if( i_time >= 0 )
+ return var_SetTime( p_instance->p_input, "time", i_time );
+ else if( d_position >= 0 && d_position <= 100 )
+ return var_SetFloat( p_instance->p_input, "position", d_position );
+ return VLC_EGENERIC;
+}
+
+static int vlm_ControlMediaInstanceGets( vlm_t *p_vlm, int64_t id, vlm_media_instance_t ***ppp_idsc, int *pi_instance )
{
- vlm_t *vlm = (vlm_t*)p_object;
- int i, j;
- mtime_t i_lastcheck;
- mtime_t i_time;
+ vlm_media_sys_t *p_media = vlm_ControlMediaGetById( p_vlm, id );
+ vlm_media_instance_t **pp_idsc;
+ int i_idsc;
+ int i;
- i_lastcheck = vlm_Date();
+ if( !p_media )
+ return VLC_EGENERIC;
- while( !vlm->b_die )
+ TAB_INIT( i_idsc, pp_idsc );
+ for( i = 0; i < p_media->i_instance; i++ )
{
- char **ppsz_scheduled_commands = NULL;
- int i_scheduled_commands = 0;
- vlc_mutex_lock( &vlm->lock );
+ vlm_media_instance_sys_t *p_instance = p_media->instance[i];
+ vlm_media_instance_t *p_idsc = vlm_media_instance_New();
- /* destroy the inputs that wants to die, and launch the next input */
- for( i = 0; i < vlm->i_media; i++ )
+ if( p_instance->psz_name )
+ p_idsc->psz_name = strdup( p_instance->psz_name );
+ if( p_instance->p_input )
{
- vlm_media_t *p_media = vlm->media[i];
+ p_idsc->i_time = var_GetTime( p_instance->p_input, "time" );
+ p_idsc->i_length = var_GetTime( p_instance->p_input, "length" );
+ p_idsc->d_position = var_GetFloat( p_instance->p_input, "position" );
+ if( var_GetInteger( p_instance->p_input, "state" ) == PAUSE_S )
+ p_idsc->b_paused = VLC_TRUE;
+ p_idsc->i_rate = var_GetInteger( p_instance->p_input, "rate" );
+ }
- for( j = 0; j < p_media->i_instance; j++ )
- {
- vlm_media_instance_t *p_instance = p_media->instance[j];
+ TAB_APPEND( i_idsc, pp_idsc, p_idsc );
+ }
+ *ppp_idsc = pp_idsc;
+ *pi_instance = i_idsc;
+ return VLC_SUCCESS;
+}
+static int vlm_ControlMediaInstanceClear( vlm_t *p_vlm, int64_t id )
+{
+ vlm_media_sys_t *p_media = vlm_ControlMediaGetById( p_vlm, id );
- if( !p_instance->p_input ||
- ( !p_instance->p_input->b_eof && !p_instance->p_input->b_error ) )
- continue;
+ if( !p_media )
+ return VLC_EGENERIC;
- p_instance->i_index++;
- if( p_instance->i_index >= p_media->i_input && p_media->b_loop )
- p_instance->i_index = 0;
+ while( p_media->i_instance > 0 )
+ vlm_ControlMediaInstanceStop( p_vlm, id, p_media->instance[0]->psz_name );
- if( p_instance->i_index < p_media->i_input )
- {
- char psz_index[32];
+ return VLC_SUCCESS;
+}
- /* 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. */
- }
- }
- }
- }
+static int vlm_ControlScheduleClear( vlm_t *p_vlm )
+{
+ while( p_vlm->i_schedule > 0 )
+ vlm_ScheduleDelete( p_vlm, p_vlm->schedule[0], NULL );
- /* scheduling */
- i_time = vlm_Date();
+ return VLC_SUCCESS;
+}
+static int vlm_vaControlInternal( vlm_t *p_vlm, int i_query, va_list args )
+{
+ vlm_media_t *p_dsc;
+ vlm_media_t **pp_dsc;
+ vlm_media_t ***ppp_dsc;
+ vlm_media_instance_t ***ppp_idsc;
+ const char *psz_id;
+ const char *psz_vod;
+ int64_t *p_id;
+ int64_t id;
+ int i_int;
+ int *pi_int;
+
+ int64_t *pi_i64;
+ int64_t i_i64;
+ double *pd_double;
+ double d_double;
- for( i = 0; i < vlm->i_schedule; i++ )
- {
- mtime_t i_real_date = vlm->schedule[i]->i_date;
+ switch( i_query )
+ {
+ /* Media control */
+ case VLM_GET_MEDIAS:
+ ppp_dsc = (vlm_media_t ***)va_arg( args, vlm_media_t *** );
+ pi_int = (int *)va_arg( args, int * );
+ return vlm_ControlMediaGets( p_vlm, ppp_dsc, pi_int );
+
+ case VLM_CLEAR_MEDIAS:
+ return vlm_ControlMediaClear( p_vlm );
+
+ case VLM_CHANGE_MEDIA:
+ p_dsc = (vlm_media_t*)va_arg( args, vlm_media_t * );
+ return vlm_ControlMediaChange( p_vlm, p_dsc );
+
+ case VLM_ADD_MEDIA:
+ p_dsc = (vlm_media_t*)va_arg( args, vlm_media_t * );
+ p_id = (int64_t*)va_arg( args, int64_t * );
+ return vlm_ControlMediaAdd( p_vlm, p_dsc, p_id );
+
+ case VLM_DEL_MEDIA:
+ id = (int64_t)va_arg( args, int64_t );
+ return vlm_ControlMediaDel( p_vlm, id );
+
+ case VLM_GET_MEDIA:
+ id = (int64_t)va_arg( args, int64_t );
+ pp_dsc = (vlm_media_t **)va_arg( args, vlm_media_t ** );
+ return vlm_ControlMediaGet( p_vlm, id, pp_dsc );
+
+ case VLM_GET_MEDIA_ID:
+ psz_id = (const char*)va_arg( args, const char * );
+ p_id = (int64_t*)va_arg( args, int64_t * );
+ return vlm_ControlMediaGetId( p_vlm, psz_id, p_id );
+
+
+ /* Media instance control */
+ case VLM_GET_MEDIA_INSTANCES:
+ id = (int64_t)va_arg( args, int64_t );
+ ppp_idsc = (vlm_media_instance_t ***)va_arg( args, vlm_media_instance_t *** );
+ pi_int = (int *)va_arg( args, int *);
+ return vlm_ControlMediaInstanceGets( p_vlm, id, ppp_idsc, pi_int );
+
+ case VLM_CLEAR_MEDIA_INSTANCES:
+ id = (int64_t)va_arg( args, int64_t );
+ return vlm_ControlMediaInstanceClear( p_vlm, id );
+
+
+ case VLM_START_MEDIA_BROADCAST_INSTANCE:
+ id = (int64_t)va_arg( args, int64_t );
+ psz_id = (const char*)va_arg( args, const char* );
+ i_int = (int)va_arg( args, int );
+ return vlm_ControlMediaInstanceStart( p_vlm, id, psz_id, i_int, NULL );
+
+ case VLM_START_MEDIA_VOD_INSTANCE:
+ id = (int64_t)va_arg( args, int64_t );
+ psz_id = (const char*)va_arg( args, const char* );
+ i_int = (int)va_arg( args, int );
+ psz_vod = (const char*)va_arg( args, const char* );
+ if( !psz_vod )
+ return VLC_EGENERIC;
+ return vlm_ControlMediaInstanceStart( p_vlm, id, psz_id, i_int, psz_vod );
+
+ case VLM_STOP_MEDIA_INSTANCE:
+ id = (int64_t)va_arg( args, int64_t );
+ psz_id = (const char*)va_arg( args, const char* );
+ return vlm_ControlMediaInstanceStop( p_vlm, id, psz_id );
+
+ case VLM_PAUSE_MEDIA_INSTANCE:
+ id = (int64_t)va_arg( args, int64_t );
+ psz_id = (const char*)va_arg( args, const char* );
+ return vlm_ControlMediaInstancePause( p_vlm, id, psz_id );
+
+ case VLM_GET_MEDIA_INSTANCE_TIME:
+ id = (int64_t)va_arg( args, int64_t );
+ psz_id = (const char*)va_arg( args, const char* );
+ pi_i64 = (int64_t*)va_arg( args, int64_t * );
+ return vlm_ControlMediaInstanceGetTimePosition( p_vlm, id, psz_id, pi_i64, NULL );
+ case VLM_GET_MEDIA_INSTANCE_POSITION:
+ id = (int64_t)va_arg( args, int64_t );
+ psz_id = (const char*)va_arg( args, const char* );
+ pd_double = (double*)va_arg( args, double* );
+ return vlm_ControlMediaInstanceGetTimePosition( p_vlm, id, psz_id, NULL, pd_double );
+
+ case VLM_SET_MEDIA_INSTANCE_TIME:
+ id = (int64_t)va_arg( args, int64_t );
+ psz_id = (const char*)va_arg( args, const char* );
+ i_i64 = (int64_t)va_arg( args, int64_t);
+ return vlm_ControlMediaInstanceSetTimePosition( p_vlm, id, psz_id, i_i64, -1 );
+ case VLM_SET_MEDIA_INSTANCE_POSITION:
+ id = (int64_t)va_arg( args, int64_t );
+ psz_id = (const char*)va_arg( args, const char* );
+ d_double = (double)va_arg( args, double );
+ return vlm_ControlMediaInstanceSetTimePosition( p_vlm, id, psz_id, -1, d_double );
+
+ case VLM_CLEAR_SCHEDULES:
+ return vlm_ControlScheduleClear( p_vlm );
- 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++;
- }
+ default:
+ msg_Err( p_vlm, "unknown VLM query" );
+ return VLC_EGENERIC;
+ }
+}
+static int vlm_ControlInternal( vlm_t *p_vlm, int i_query, ... )
+{
+ va_list args;
+ int i_result;
- i_real_date = vlm->schedule[i]->i_date + j *
- vlm->schedule[i]->i_period;
- }
+ va_start( args, i_query );
+ i_result = vlm_vaControlInternal( p_vlm, i_query, args );
+ va_end( args );
- 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 );
+ return i_result;
+}
- /* for now, drop the message */
- vlm_MessageDelete( message );
- TAB_REMOVE( i_scheduled_commands,
- ppsz_scheduled_commands,
- psz_command );
- free( psz_command );
- }
+int vlm_Control( vlm_t *p_vlm, int i_query, ... )
+{
+ va_list args;
+ int i_result;
- i_lastcheck = i_time;
+ va_start( args, i_query );
- vlc_mutex_unlock( &vlm->lock );
+ vlc_mutex_lock( &p_vlm->lock );
+ i_result = vlm_vaControlInternal( p_vlm, i_query, args );
+ vlc_mutex_unlock( &p_vlm->lock );
- msleep( 100000 );
- }
+ va_end( args );
- return VLC_SUCCESS;
+ return i_result;
}
#else /* ENABLE_VLM */
{
return -1;
}
-void vlm_MessageDelete( vlm_message_t *a )
-{
- ;
-}
-vlm_media_t *vlm_MediaNew( vlm_t *a, char *b, int c )
+vlm_message_t *vlm_MessageNew( const char *psz_name,
+ const char *psz_format, ... )
{
return NULL;
}
-vlm_media_t *vlm_MediaSearch (vlm_t *a, const char *b )
+vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message,
+ vlm_message_t *p_child )
{
return NULL;
}
-void vlm_MediaDelete( vlm_t *a, vlm_media_t *b, char *c )
+void vlm_MessageDelete( vlm_message_t *a )
{
;
}
-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 )
+
+int vlm_Control( vlm_t *p_vlm, int i_query, ... )
{
- return -1;
+ return VLC_EGENERIC;
}
#endif /* ENABLE_VLM */