Commit 555e2ac8 authored by Gildas Bazin's avatar Gildas Bazin

* src/misc/vlm.c:

   + major cleanup and bug fixing.
   + added support for spawning and controlling several media instances.
parent 454ccc41
...@@ -29,9 +29,23 @@ ...@@ -29,9 +29,23 @@
enum enum
{ {
VOD_TYPE = 0, VOD_TYPE = 0,
BROADCAST_TYPE = 1, BROADCAST_TYPE,
SCHEDULE_TYPE,
}; };
typedef struct
{
/* instance name */
char *psz_name;
/* "playlist" index */
int i_index;
input_item_t item;
input_thread_t *p_input;
} vlm_media_instance_t;
typedef struct typedef struct
{ {
vlc_bool_t b_enabled; vlc_bool_t b_enabled;
...@@ -39,27 +53,26 @@ typedef struct ...@@ -39,27 +53,26 @@ typedef struct
/* name "media" is reserved */ /* name "media" is reserved */
char *psz_name; char *psz_name;
input_item_t item;
/* "playlist" */
int i_input; int i_input;
char **input; char **input;
int i_option;
char **option;
char *psz_output;
/* only for broadcast */ /* only for broadcast */
vlc_bool_t b_loop; vlc_bool_t b_loop;
/* only for vod */ /* only for vod */
vod_media_t *vod_media; vod_media_t *vod_media;
/* "playlist" index */ /* actual input instances */
int i_index; int i_instance;
vlm_media_instance_t **instance;
char *psz_output;
int i_option;
char **option;
/* global options for all inputs */
input_item_t item;
input_thread_t *p_input;
} vlm_media_t; } vlm_media_t;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* *
* Authors: Simon Latapie <garf@videolan.org> * Authors: Simon Latapie <garf@videolan.org>
* Laurent Aimar <fenrir@videolan.org> * Laurent Aimar <fenrir@videolan.org>
* Gildas Bazin <gbazin@videolan.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -47,16 +48,17 @@ static vlm_message_t *vlm_Show( vlm_t *, vlm_media_t *, vlm_schedule_t *, char * ...@@ -47,16 +48,17 @@ static vlm_message_t *vlm_Show( vlm_t *, vlm_media_t *, vlm_schedule_t *, char *
static vlm_message_t *vlm_Help( vlm_t *, char * ); static vlm_message_t *vlm_Help( vlm_t *, char * );
static vlm_media_t *vlm_MediaNew ( vlm_t *, char *, int ); static vlm_media_t *vlm_MediaNew ( vlm_t *, char *, int );
static int vlm_MediaDelete ( vlm_t *, vlm_media_t *, char * ); static void vlm_MediaDelete ( vlm_t *, vlm_media_t *, char * );
static vlm_media_t *vlm_MediaSearch ( vlm_t *, char * ); static vlm_media_t *vlm_MediaSearch ( vlm_t *, char * );
static int vlm_MediaSetup ( vlm_t *, vlm_media_t *, char *, char * ); static int vlm_MediaSetup ( vlm_t *, vlm_media_t *, char *, char * );
static int vlm_MediaControl( vlm_t *, vlm_media_t *, char *, char * ); static int vlm_MediaControl( vlm_t *, vlm_media_t *, char *, char *, char * );
static vlm_media_instance_t *vlm_MediaInstanceSearch( vlm_t *, vlm_media_t *, char * );
static vlm_message_t* vlm_MessageNew( char *, char * ); static vlm_message_t *vlm_MessageNew( char *, const char *, ... );
static vlm_message_t* vlm_MessageAdd( vlm_message_t*, vlm_message_t* ); static vlm_message_t *vlm_MessageAdd( vlm_message_t*, vlm_message_t* );
static vlm_schedule_t *vlm_ScheduleNew( vlm_t *, char *); static vlm_schedule_t *vlm_ScheduleNew( vlm_t *, char *);
static int vlm_ScheduleDelete( vlm_t *, vlm_schedule_t *, char *); static void vlm_ScheduleDelete( vlm_t *, vlm_schedule_t *, char *);
static int vlm_ScheduleSetup( vlm_schedule_t *, char *, char *); static int vlm_ScheduleSetup( vlm_schedule_t *, char *, char *);
static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *, char *); static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *, char *);
...@@ -114,7 +116,6 @@ vlm_t *__vlm_New ( vlc_object_t *p_this ) ...@@ -114,7 +116,6 @@ vlm_t *__vlm_New ( vlc_object_t *p_this )
void vlm_Delete( vlm_t *vlm ) void vlm_Delete( vlm_t *vlm )
{ {
vlc_value_t lockval; vlc_value_t lockval;
int i;
var_Get( vlm->p_libvlc, "vlm_mutex", &lockval ); var_Get( vlm->p_libvlc, "vlm_mutex", &lockval );
vlc_mutex_lock( lockval.p_address ); vlc_mutex_lock( lockval.p_address );
...@@ -132,20 +133,10 @@ void vlm_Delete( vlm_t *vlm ) ...@@ -132,20 +133,10 @@ void vlm_Delete( vlm_t *vlm )
vlc_mutex_destroy( &vlm->lock ); vlc_mutex_destroy( &vlm->lock );
for( i = 0; i < vlm->i_media; i++ ) while( vlm->i_media ) vlm_MediaDelete( vlm, vlm->media[0], NULL );
{
vlm_media_t *media = vlm->media[i];
vlm_MediaDelete( vlm, media, NULL );
}
if( vlm->media ) free( vlm->media ); if( vlm->media ) free( vlm->media );
for( i = 0; i < vlm->i_schedule; i++ ) while( vlm->i_schedule ) vlm_ScheduleDelete( vlm, vlm->schedule[0], NULL );
{
vlm_ScheduleDelete( vlm, vlm->schedule[i], NULL );
}
if( vlm->schedule ) free( vlm->schedule ); if( vlm->schedule ) free( vlm->schedule );
vlc_object_detach( vlm ); vlc_object_detach( vlm );
...@@ -168,136 +159,88 @@ int vlm_ExecuteCommand( vlm_t *vlm, char *command, vlm_message_t **message) ...@@ -168,136 +159,88 @@ int vlm_ExecuteCommand( vlm_t *vlm, char *command, vlm_message_t **message)
} }
/***************************************************************************** /*****************************************************************************
* * FindEndCommand
*****************************************************************************/ *****************************************************************************/
#if 1
static char *FindEndCommand( char *psz ) static char *FindEndCommand( char *psz )
{ {
char *s_sent = psz; char *psz_sent = psz;
switch( *s_sent ) switch( *psz_sent )
{ {
case '\"': case '\"':
{ psz_sent++;
s_sent++;
while( ( *s_sent != '\"' ) && ( *s_sent != '\0' ) )
{
if( *s_sent == '\'' )
{
s_sent = FindEndCommand( s_sent );
if( s_sent == NULL ) while( ( *psz_sent != '\"' ) && ( *psz_sent != '\0' ) )
{ {
return NULL; if( *psz_sent == '\'' )
}
}
else
{ {
s_sent++; psz_sent = FindEndCommand( psz_sent );
if( psz_sent == NULL ) return NULL;
} }
else psz_sent++;
} }
if( *s_sent == '\"' ) if( *psz_sent == '\"' )
{
s_sent++;
return s_sent;
}
else /* *s_sent == '\0' , which means the number of " is incorrect */
{ {
return NULL; psz_sent++;
return psz_sent;
} }
/* *psz_sent == '\0' -> number of " is incorrect */
else return NULL;
break; break;
}
case '\'':
{
s_sent++;
while( ( *s_sent != '\'' ) && ( *s_sent != '\0' ) ) case '\'':
{ psz_sent++;
if( *s_sent == '\"' )
{
s_sent = FindEndCommand( s_sent );
if( s_sent == NULL ) while( ( *psz_sent != '\'' ) && ( *psz_sent != '\0' ) )
{ {
return NULL; if( *psz_sent == '\"' )
}
}
else
{ {
s_sent++; psz_sent = FindEndCommand( psz_sent );
if( psz_sent == NULL ) return NULL;
} }
else psz_sent++;
} }
if( *s_sent == '\'' ) if( *psz_sent == '\'' )
{ {
s_sent++; psz_sent++;
return s_sent; return psz_sent;
}
else /* *s_sent == '\0' , which means the number of ' is incorrect */
{
return NULL;
} }
/* *psz_sent == '\0' -> number of " is incorrect */
else return NULL;
break; break;
}
default: /* now we can look for spaces */ default: /* now we can look for spaces */
while( ( *psz_sent != ' ' ) && ( *psz_sent != '\0' ) )
{ {
while( ( *s_sent != ' ' ) && ( *s_sent != '\0' ) ) if( ( *psz_sent == '\'' ) || ( *psz_sent == '\"' ) )
{
if( ( *s_sent == '\'' ) || ( *s_sent == '\"' ) )
{ {
s_sent = FindEndCommand( s_sent ); psz_sent = FindEndCommand( psz_sent );
}
else
{
s_sent++;
}
} }
return s_sent; else psz_sent++;
} }
}
}
#else
static char *FindEndCommand( char *psz )
{
char *s_sent = psz;
while( *psz &&
*psz != ' ' && *psz != '\t' &&
*psz != '\n' && *psz != '\r' )
{
if( *psz == '\'' || *psz == '"' )
{
char d = *psz++;
while( *psz && *psz != d && *psz != *psz != '\n' && *psz != '\r' ) return psz_sent;
{
if( ( d == '\'' && *psz == '"' ) ||
( d == '"' && *psz == '\'' ) )
{
psz = FindEndCommand( psz );
}
}
if( psz != d )
{
return NULL;
}
}
psz++;
} }
} }
#endif
/* Execute a command which ends by '\0' (string) */ /*****************************************************************************
* ExecuteCommand: The main state machine
*****************************************************************************
* Execute a command which ends with '\0' (string)
*****************************************************************************/
static int ExecuteCommand(vlm_t *vlm, char *command, vlm_message_t **p_message) static int ExecuteCommand(vlm_t *vlm, char *command, vlm_message_t **p_message)
{ {
int i_return = 0;
int i_command = 0; int i_command = 0;
char **p_command = NULL; char **p_command = NULL;
char *cmd = command; char *cmd = command;
vlm_message_t *message = NULL; vlm_message_t *message = NULL;
int i; int i, j;
/* First, parse the line and cut it */ /* First, parse the line and cut it */
while( *cmd != '\0' ) while( *cmd != '\0' )
...@@ -314,109 +257,38 @@ static int ExecuteCommand(vlm_t *vlm, char *command, vlm_message_t **p_message) ...@@ -314,109 +257,38 @@ static int ExecuteCommand(vlm_t *vlm, char *command, vlm_message_t **p_message)
p_temp = FindEndCommand( cmd ); p_temp = FindEndCommand( cmd );
if( p_temp == NULL ) if( p_temp == NULL ) goto error;
{
i_return = 1;
goto end_seq;
}
i_temp = p_temp - cmd; i_temp = p_temp - cmd;
p_command = realloc( p_command, (i_command + 1) * sizeof( char* ) ); p_command = realloc( p_command, (i_command + 1) * sizeof(char*) );
p_command[ i_command ] = malloc( (i_temp + 1) * sizeof( char ) ); // don't forget the '\0' p_command[ i_command ] = malloc( (i_temp + 1) * sizeof(char) );
strncpy( p_command[ i_command ], cmd, i_temp ); strncpy( p_command[ i_command ], cmd, i_temp );
(p_command[ i_command ])[ i_temp ] = '\0'; p_command[ i_command ][ i_temp ] = '\0';
i_command++; i_command++;
cmd = p_temp; cmd = p_temp;
} }
} }
/* And then Interpret it */ /*
* And then Interpret it
*/
if( i_command == 0 ) if( i_command == 0 )
{ {
message = vlm_MessageNew( "", NULL ); message = vlm_MessageNew( "", NULL );
i_return = 0; goto success;
goto end_seq;
} }
if( strcmp(p_command[0], "new") == 0 ) if( strcmp(p_command[0], "new") == 0 )
{
if( i_command >= 3 )
{ {
int i_type; int i_type;
vlm_media_t *media;
vlm_schedule_t *schedule;
if( strcmp(p_command[2], "schedule") == 0 )
{
/* new vlm_schedule */
if( vlm_ScheduleSearch( vlm, p_command[1] ) != NULL ||
strcmp(p_command[1], "schedule") == 0 )
{
char *error_message;
asprintf( &error_message, "%s is already used",
p_command[1] );
message = vlm_MessageNew( "new", error_message );
free( error_message );
i_return = 1;
goto end_seq;
}
schedule = vlm_ScheduleNew( vlm, p_command[1] );
if( i_command > 3 ) // hey, there are properties
{
for( i = 3 ; i < i_command ; i++ )
{
if( strcmp( p_command[i], "enabled" ) == 0 ||
strcmp( p_command[i], "disabled" ) == 0 )
{
vlm_ScheduleSetup( schedule, p_command[i], NULL );
}
/* Beware: evrything behind append is considered as command line */
else if( strcmp( p_command[i], "append" ) == 0 )
{
i++;
if( i < i_command )
{
int j;
for( j = (i + 1); j < i_command; j++ )
{
p_command[i] = realloc( p_command[i], strlen(p_command[i]) + strlen(p_command[j]) + 1 + 1);
strcat( p_command[i], " " );
strcat( p_command[i], p_command[j] );
}
vlm_ScheduleSetup( schedule, p_command[i - 1], p_command[i] );
}
i = i_command;
}
else
{
if( (i+1) < i_command )
{
vlm_ScheduleSetup( schedule, p_command[i], p_command[i+1] );
i++;
}
else
{
vlm_ScheduleDelete( vlm, schedule, NULL );
message = vlm_MessageNew( p_command[i], "Wrong properties syntax" );
i_return = 1;
goto end_seq;
}
}
}
}
message = vlm_MessageNew( "new", NULL ); /* Check the number of arguments */
i_return = 0; if( i_command < 3 ) goto syntax_error;
goto end_seq;
}
/* Get type */
if( strcmp(p_command[2], "vod") == 0 ) if( strcmp(p_command[2], "vod") == 0 )
{ {
i_type = VOD_TYPE; i_type = VOD_TYPE;
...@@ -425,169 +297,132 @@ static int ExecuteCommand(vlm_t *vlm, char *command, vlm_message_t **p_message) ...@@ -425,169 +297,132 @@ static int ExecuteCommand(vlm_t *vlm, char *command, vlm_message_t **p_message)
{ {
i_type = BROADCAST_TYPE; i_type = BROADCAST_TYPE;
} }
else if( strcmp(p_command[2], "schedule") == 0 )
{
i_type = SCHEDULE_TYPE;
}
else else
{ {
char *error_message; message = vlm_MessageNew( "new", "%s: Choose between vod, "
"broadcast or schedule", p_command[1] );
asprintf( &error_message, goto error;
"%s: Choose between vod or broadcast",
p_command[1] );
message = vlm_MessageNew( "new", error_message );
free( error_message );
i_return = 1;
goto end_seq;
} }
/* new vlm_media */ /* Check for forbidden media names */
if( vlm_MediaSearch( vlm, p_command[1] ) != NULL || if( strcmp(p_command[1], "all") == 0 ||
strcmp(p_command[1], "media") == 0 ) strcmp(p_command[1], "media") == 0 ||
strcmp(p_command[1], "schedule") == 0 )
{ {
char *error_message; message = vlm_MessageNew( "new", "\"all\", \"media\" and "
asprintf( &error_message, "%s is already used", "\"schedule\" are reserved names" );
p_command[1] ); goto error;
message = vlm_MessageNew( "new", error_message );
free( error_message );
i_return = 1;
goto end_seq;
} }
media = vlm_MediaNew( vlm, p_command[1], i_type ); /* Check the name is not already in use */
if( !media ) if( vlm_ScheduleSearch( vlm, p_command[1] ) ||
vlm_MediaSearch( vlm, p_command[1] ) )
{ {
message = vlm_MessageNew( "new", "could not create media" ); message = vlm_MessageNew( "new", "%s: Name already in use",
i_return = 1; p_command[1] );
goto end_seq; goto error;
} }
if( i_command > 3 ) // hey, there are properties /* Schedule */
{ if( i_type == SCHEDULE_TYPE )
for( i = 3; i < i_command; i++ )
{ {
if( strcmp( p_command[i], "enabled" ) == 0 || vlm_schedule_t *schedule;
strcmp( p_command[i], "disabled" ) == 0 ) schedule = vlm_ScheduleNew( vlm, p_command[1] );
if( !schedule )
{ {
vlm_MediaSetup( vlm, media, p_command[i], NULL ); message = vlm_MessageNew( "new", "could not create schedule" );
goto error;
} }
else
{
if( (i+1) < i_command )
{
vlm_MediaSetup( vlm, media, p_command[i], p_command[i+1] );
i++;
} }
/* Media */
else else
{ {
vlm_MediaDelete( vlm, media, NULL ); vlm_media_t *media;
message = vlm_MessageNew( p_command[i], "Wrong properties syntax" ); media = vlm_MediaNew( vlm, p_command[1], i_type );
i_return = 1; if( !media )
goto end_seq; {
} message = vlm_MessageNew( "new", "could not create media" );
} goto error;
} }
} }
if( media->i_type == VOD_TYPE ) if( i_command <= 3 )
message = vlm_MessageNew( "new", "Warning: VOD is not " {
"implemented yet" );
else
message = vlm_MessageNew( "new", NULL ); message = vlm_MessageNew( "new", NULL );
i_return = 0; goto success;
goto end_seq;
} }
else
{ /* Properties will be dealt with later on */
message = vlm_MessageNew( "new", "Wrong command syntax" );
i_return = 1;
goto end_seq;
} }
else if( strcmp(p_command[0], "setup") == 0 )
{
if( i_command < 2 ) goto syntax_error;
/* Properties will be dealt with later on */
} }
else if( strcmp(p_command[0], "del") == 0 ) else if( strcmp(p_command[0], "del") == 0 )
{
if( i_command >= 2 )
{ {
vlm_media_t *media; vlm_media_t *media;
vlm_schedule_t *schedule; vlm_schedule_t *schedule;
if( i_command < 2 ) goto syntax_error;
media = vlm_MediaSearch( vlm, p_command[1] ); media = vlm_MediaSearch( vlm, p_command[1] );
schedule = vlm_ScheduleSearch( vlm, p_command[1] ); schedule = vlm_ScheduleSearch( vlm, p_command[1] );
if( schedule != NULL ) if( schedule != NULL )
{ {
vlm_ScheduleDelete( vlm, schedule, NULL ); vlm_ScheduleDelete( vlm, schedule, NULL );
message = vlm_MessageNew( "del", NULL );
i_return = 0;
goto end_seq;
} }
else if( media != NULL ) else if( media != NULL )
{ {
vlm_MediaDelete( vlm, media, NULL ); vlm_MediaDelete( vlm, media, NULL );
message = vlm_MessageNew( "del", NULL );
i_return = 0;
goto end_seq;
} }
else if( strcmp(p_command[1], "media") == 0 ) else if( strcmp(p_command[1], "media") == 0 )
{ {
for( i = 0; i < vlm->i_media; i++ ) while( vlm->i_media ) vlm_MediaDelete( vlm, vlm->media[0], NULL );
{
vlm_MediaDelete( vlm, vlm->media[i], NULL );
}
message = vlm_MessageNew( "del", NULL );
goto end_seq;
} }
else if( strcmp(p_command[1], "schedule") == 0 ) else if( strcmp(p_command[1], "schedule") == 0 )
{ {
for( i = 0; i < vlm->i_schedule; i++ ) while( vlm->i_schedule )
{ vlm_ScheduleDelete( vlm, vlm->schedule[0], NULL );
vlm_ScheduleDelete( vlm, vlm->schedule[i], NULL );
}
message = vlm_MessageNew( "del", NULL );
goto end_seq;
} }
else if( strcmp(p_command[1], "all") == 0 ) else if( strcmp(p_command[1], "all") == 0 )
{ {
for( i = 0; i < vlm->i_media; i++ ) while( vlm->i_media ) vlm_MediaDelete( vlm, vlm->media[0], NULL );
{
vlm_MediaDelete( vlm, vlm->media[i], NULL );
}
for( i = 0; i < vlm->i_schedule; i++ ) while( vlm->i_schedule )
{ vlm_ScheduleDelete( vlm, vlm->schedule[0], NULL );
vlm_ScheduleDelete( vlm, vlm->schedule[i], NULL );
}
i_return = 0;
message = vlm_MessageNew( "del", NULL );
goto end_seq;
}
else
{
char *error_message;
asprintf( &error_message, "%s: media unknown", p_command[1] );
message = vlm_MessageNew( "del", error_message );
free( error_message );
i_return = 1;
goto end_seq;
}
} }
else else
{ {
message = vlm_MessageNew( "setup", "Wrong command syntax" ); message = vlm_MessageNew( "del", "%s: media unknown",
i_return = 1; p_command[1] );
goto end_seq; goto error;
} }
message = vlm_MessageNew( "del", NULL );
goto success;
} }
else if( strcmp(p_command[0], "show") == 0 ) else if( strcmp(p_command[0], "show") == 0 )
{ {
vlm_media_t *media;
vlm_schedule_t *schedule;
if( i_command == 1 ) if( i_command == 1 )
{ {
message = vlm_Show( vlm, NULL, NULL, NULL ); message = vlm_Show( vlm, NULL, NULL, NULL );
i_return = 0; goto success;
goto end_seq;
} }
else if( i_command == 2 ) else if( i_command > 2 ) goto syntax_error;
{
vlm_media_t *media;
vlm_schedule_t *schedule;
media = vlm_MediaSearch( vlm, p_command[1] ); media = vlm_MediaSearch( vlm, p_command[1] );
schedule = vlm_ScheduleSearch( vlm, p_command[1] ); schedule = vlm_ScheduleSearch( vlm, p_command[1] );
...@@ -605,304 +440,264 @@ static int ExecuteCommand(vlm_t *vlm, char *command, vlm_message_t **p_message) ...@@ -605,304 +440,264 @@ static int ExecuteCommand(vlm_t *vlm, char *command, vlm_message_t **p_message)
message = vlm_Show( vlm, NULL, NULL, p_command[1] ); message = vlm_Show( vlm, NULL, NULL, p_command[1] );
} }
i_return = 0; goto success;
goto end_seq;
}
else
{
message = vlm_MessageNew( "show", "Wrong command syntax" );
i_return = 1;
goto end_seq;
}
} }
else if( strcmp(p_command[0], "help") == 0 ) else if( strcmp(p_command[0], "help") == 0 )
{ {
if( i_command == 1 ) if( i_command != 1 ) goto syntax_error;
{
message = vlm_Help( vlm, NULL ); message = vlm_Help( vlm, NULL );
i_return = 0; goto success;
goto end_seq;
}
else
{
message = vlm_MessageNew( "help", "Wrong command syntax" );
i_return = 1;
goto end_seq;
} }
}
else if( strcmp(p_command[0], "setup") == 0 ) else if( strcmp(p_command[0], "control") == 0 )
{
if( i_command >= 2 )
{ {
vlm_media_t *media; vlm_media_t *media;
vlm_schedule_t *schedule;
media = vlm_MediaSearch( vlm, p_command[1] ); if( i_command < 3 ) goto syntax_error;
schedule = vlm_ScheduleSearch( vlm, p_command[1] );
if( schedule != NULL ) if( !(media = vlm_MediaSearch( vlm, p_command[1] ) ) )
{
for( i = 2 ; i < i_command ; i++ )
{ {
if( strcmp( p_command[i], "enabled" ) == 0 || message = vlm_MessageNew( "control", "%s: media unknown",
strcmp( p_command[i], "disabled" ) == 0 ) p_command[1] );
{ goto error;
vlm_ScheduleSetup( schedule, p_command[i], NULL );
} }
/* Beware: evrything behind append is considered as command line */ else
else if( strcmp( p_command[i], "append" ) == 0 )
{ {
i++; char *psz_command, *psz_arg = 0, *psz_instance = 0;
int i_index = 2;
if( i < i_command ) if( strcmp(p_command[2], "play") && strcmp(p_command[2], "stop") &&
strcmp(p_command[2], "pause") && strcmp(p_command[2], "seek") )
{ {
int j; i_index++;
for( j = (i + 1); j < i_command; j++ ) psz_instance = p_command[2];
{
p_command[i] = realloc( p_command[i], strlen(p_command[i]) + strlen(p_command[j]) + 1 + 1); if( i_command < 4 ) goto syntax_error;
strcat( p_command[i], " " );
strcat( p_command[i], p_command[j] );
} }
vlm_ScheduleSetup( schedule, p_command[i - 1], p_command[i] ); psz_command = p_command[i_index];
if( i_command >= i_index + 2 ) psz_arg = p_command[i_index + 1];
vlm_MediaControl( vlm, media, psz_instance, psz_command, psz_arg );
message = vlm_MessageNew( "control", NULL );
goto success;
} }
i = i_command;
} }
else
else if( strcmp(p_command[0], "save") == 0 )
{ {
if( (i+1) < i_command ) FILE *file;
if( i_command != 2 ) goto syntax_error;
file = fopen( p_command[1], "w" );
if( file == NULL )
{ {
vlm_ScheduleSetup( schedule, p_command[i], p_command[i+1] ); message = vlm_MessageNew( "save", "Unable to save file" );
i++; goto error;
} }
else else
{ {
vlm_ScheduleDelete( vlm, schedule, NULL ); char *save = vlm_Save( vlm );
message = vlm_MessageNew( "setup", "Wrong properties syntax" ); fwrite( save, strlen( save ), 1, file );
i_return = 1; fclose( file );
goto end_seq; free( save );
} message = vlm_MessageNew( "save", NULL );
goto success;
} }
} }
message = vlm_MessageNew( "setup", NULL ); else if( strcmp(p_command[0], "load") == 0 )
i_return = 0;
goto end_seq;
}
else if( media != NULL )
{ {
for( i = 2 ; i < i_command ; i++ ) FILE *file;
if( i_command != 2 ) goto syntax_error;
file = fopen( p_command[1], "r" );
if( file == NULL )
{ {
if( strcmp( p_command[i], "enabled" ) == 0 || message = vlm_MessageNew( "load", "Unable to load file" );
strcmp( p_command[i], "disabled" ) == 0 ) goto error;
{ /* only one argument */
vlm_MediaSetup( vlm, media, p_command[i], NULL );
}
else if( strcmp( p_command[i], "loop" ) == 0 ||
strcmp( p_command[i], "unloop" ) == 0 )
{
if( media->i_type != BROADCAST_TYPE )
{
message = vlm_MessageNew( "setup", "loop only available for broadcast" );
i_return = 1;
goto end_seq;
} }
else else
{ {
vlm_MediaSetup( vlm, media, p_command[i], NULL ); int64_t size;
} char *buffer;
}
else if( fseek( file, 0, SEEK_END) == 0 )
{ {
if( (i+1) < i_command ) size = ftell( file );
fseek( file, 0, SEEK_SET);
buffer = malloc( size + 1 );
fread( buffer, 1, size, file);
buffer[ size ] = '\0';
if( vlm_Load( vlm, buffer ) )
{ {
vlm_MediaSetup( vlm, media, p_command[i], p_command[i+1] ); free( buffer );
i++; message = vlm_MessageNew( "load", "error while loading "
"file" );
goto error;
}
free( buffer );
} }
else else
{ {
vlm_MediaDelete( vlm, media, NULL ); message = vlm_MessageNew( "load", "read file error" );
message = vlm_MessageNew( "setup", "Wrong properties syntax" ); goto error;
i_return = 1;
goto end_seq;
}
}
} }
message = vlm_MessageNew( "setup", NULL ); fclose( file );
i_return = 0; message = vlm_MessageNew( "load", NULL );
goto end_seq; goto success;
} }
else
{
char *error_message;
asprintf( &error_message, "%s unknown", p_command[1] );
message = vlm_MessageNew( "setup", error_message );
free( error_message );
i_return = 1;
goto end_seq;
} }
}
else else
{ {
message = vlm_MessageNew( "setup", "Wrong command syntax" ); message = vlm_MessageNew( p_command[0], "Unknown command" );
i_return = 1; goto error;
goto end_seq;
}
} }
else if( strcmp(p_command[0], "control") == 0 )
{
if( i_command >= 3 ) /* Common code between "new" and "setup" */
if( strcmp(p_command[0], "new") == 0 ||
strcmp(p_command[0], "setup") == 0 )
{ {
int i_command_start = strcmp(p_command[0], "new") ? 2 : 3;
vlm_media_t *media; vlm_media_t *media;
vlm_schedule_t *schedule;
if( i_command < i_command_start ) goto syntax_error;
media = vlm_MediaSearch( vlm, p_command[1] ); media = vlm_MediaSearch( vlm, p_command[1] );
schedule = vlm_ScheduleSearch( vlm, p_command[1] );
if( media == NULL ) if( !media && !schedule )
{ {
char *error_message; message = vlm_MessageNew( p_command[0], "%s unknown",
asprintf( &error_message, "%s: media unknown", p_command[1] ); p_command[1] );
message = vlm_MessageNew( "control", error_message ); goto error;
free( error_message );
i_return = 1;
goto end_seq;
} }
else
{
char *psz_args;
if( i_command >= 4 ) if( schedule != NULL )
{ {
psz_args = p_command[3]; for( i = i_command_start ; i < i_command ; i++ )
} {
else if( strcmp( p_command[i], "enabled" ) == 0 ||
strcmp( p_command[i], "disabled" ) == 0 )
{ {
psz_args = NULL; vlm_ScheduleSetup( schedule, p_command[i], NULL );
} }
/* for now */ /* Beware: everything behind append is considered as
vlm_MediaControl( vlm, media, p_command[2], psz_args ); * command line */
message = vlm_MessageNew( "control", NULL ); else if( strcmp( p_command[i], "append" ) == 0 )
i_return = 0;
goto end_seq;
}
}
else
{ {
message = vlm_MessageNew( "control", "Wrong command syntax" ); if( ++i >= i_command ) break;
i_return = 1;
goto end_seq; for( j = i + 1; j < i_command; j++ )
{
p_command[i] =
realloc( p_command[i], strlen(p_command[i]) +
strlen(p_command[j]) + 1 + 1 );
strcat( p_command[i], " " );
strcat( p_command[i], p_command[j] );
} }
vlm_ScheduleSetup( schedule, p_command[i - 1],
p_command[i] );
break;
} }
else if( strcmp(p_command[0], "save") == 0 ) else
{
if( i_command == 2 )
{ {
FILE *file; if( i + 1 >= i_command && !strcmp(p_command[0], "new") )
file = fopen( p_command[1], "w" );
if( file == NULL )
{ {
message = vlm_MessageNew( "save", "Unable to save file" ); vlm_ScheduleDelete( vlm, schedule, NULL );
i_return = 1; message = vlm_MessageNew( p_command[0],
goto end_seq; "Wrong properties syntax" );
goto error;
} }
else else if( i + 1 >= i_command )
{ {
char *save; message = vlm_MessageNew( p_command[0],
"Wrong properties syntax" );
save = vlm_Save( vlm ); goto error;
fwrite( save, strlen( save ), 1, file );
fclose( file );
free( save );
message = vlm_MessageNew( "save", NULL );
i_return = 0;
goto end_seq;
} }
vlm_ScheduleSetup( schedule, p_command[i],
p_command[i+1] );
i++;
} }
else
{
message = vlm_MessageNew( "save", "Wrong command" );
i_return = 1;
goto end_seq;
} }
} }
else if( strcmp(p_command[0], "load") == 0 )
{
if( i_command == 2 ) else if( media != NULL )
{ {
FILE *file; for( i = i_command_start ; i < i_command ; i++ )
file = fopen( p_command[1], "r" );
if( file == NULL )
{ {
message = vlm_MessageNew( "load", "Unable to load file" ); if( strcmp( p_command[i], "enabled" ) == 0 ||
i_return = 1; strcmp( p_command[i], "disabled" ) == 0 )
goto end_seq;
}
else
{ {
int64_t size; vlm_MediaSetup( vlm, media, p_command[i], NULL );
char *buffer; }
else if( strcmp( p_command[i], "loop" ) == 0 ||
if( fseek( file, 0, SEEK_END) == 0 ) strcmp( p_command[i], "unloop" ) == 0 )
{ {
size = ftell( file ); if( media->i_type != BROADCAST_TYPE )
fseek( file, 0, SEEK_SET);
buffer = malloc( size + 1 );
fread( buffer, 1, size, file);
buffer[ size ] = '\0';
if( vlm_Load( vlm, buffer ) )
{ {
free( buffer ); message = vlm_MessageNew( p_command[0],
message = vlm_MessageNew( "load", "error while loading file" ); "loop only available for broadcast" );
i_return = 1;
goto end_seq;
}
free( buffer );
} }
else else
{ {
message = vlm_MessageNew( "load", "read file error" ); vlm_MediaSetup( vlm, media, p_command[i], NULL );
i_return = 1;
goto end_seq;
}
fclose( file );
message = vlm_MessageNew( "load", NULL );
i_return = 0;
goto end_seq;
} }
} }
else else
{ {
message = vlm_MessageNew( "load", "Wrong command" ); if( i + 1 >= i_command && !strcmp(p_command[0], "new") )
i_return = 1; {
goto end_seq; vlm_MediaDelete( vlm, media, NULL );
} message = vlm_MessageNew( p_command[0],
"Wrong properties syntax" );
goto error;
} }
else else if( i + 1 >= i_command )
{ {
message = vlm_MessageNew( p_command[0], "Unknown command" ); message = vlm_MessageNew( p_command[0],
i_return = 1; "Wrong properties syntax" );
goto end_seq; goto error;
} }
end_seq: vlm_MediaSetup( vlm, media, p_command[i], p_command[i+1] );
i++;
}
}
}
for( i = 0 ; i < i_command ; i++ ) message = vlm_MessageNew( p_command[0], NULL );
{ goto success;
free( p_command[i] );
} }
success:
for( i = 0 ; i < i_command ; i++ ) free( p_command[i] );
if( p_command ) free( p_command );
*p_message = message;
return VLC_SUCCESS;
syntax_error:
message = vlm_MessageNew( p_command[0], "Wrong command syntax" );
error:
for( i = 0 ; i < i_command ; i++ ) free( p_command[i] );
if( p_command ) free( p_command );
*p_message = message; *p_message = message;
return i_return; return VLC_EGENERIC;
} }
static vlm_media_t *vlm_MediaSearch( vlm_t *vlm, char *psz_name ) static vlm_media_t *vlm_MediaSearch( vlm_t *vlm, char *psz_name )
...@@ -920,6 +715,27 @@ static vlm_media_t *vlm_MediaSearch( vlm_t *vlm, char *psz_name ) ...@@ -920,6 +715,27 @@ static vlm_media_t *vlm_MediaSearch( vlm_t *vlm, char *psz_name )
return NULL; return NULL;
} }
/*****************************************************************************
* Media handling
*****************************************************************************/
static vlm_media_instance_t *
vlm_MediaInstanceSearch( vlm_t *vlm, vlm_media_t *media, char *psz_name )
{
int i;
for( i = 0; i < media->i_instance; 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];
}
}
return NULL;
}
static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type ) static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type )
{ {
vlm_media_t *media = malloc( sizeof( vlm_media_t ) ); vlm_media_t *media = malloc( sizeof( vlm_media_t ) );
...@@ -933,6 +749,9 @@ static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type ) ...@@ -933,6 +749,9 @@ static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type )
if( !vlm->vod->p_module ) if( !vlm->vod->p_module )
{ {
msg_Err( vlm, "cannot find vod server" ); msg_Err( vlm, "cannot find vod server" );
vlc_object_detach( vlm->vod );
vlc_object_destroy( vlm->vod );
vlm->vod = 0;
free( media ); free( media );
return NULL; return NULL;
} }
...@@ -945,23 +764,15 @@ static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type ) ...@@ -945,23 +764,15 @@ static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type )
media->vod_media = NULL; media->vod_media = NULL;
media->i_input = 0; media->i_input = 0;
media->input = NULL; media->input = NULL;
media->i_index = 0;
media->psz_output = NULL; media->psz_output = NULL;
media->i_option = 0; media->i_option = 0;
media->option = NULL; media->option = NULL;
media->i_type = i_type; media->i_type = i_type;
media->p_input = NULL; media->i_instance = 0;
media->instance = NULL;
media->item.psz_uri = strdup( psz_name ); media->item.psz_uri = strdup( psz_name );
media->item.psz_name = NULL; vlc_input_item_Init( VLC_OBJECT(vlm), &media->item );
media->item.i_duration = -1;
media->item.ppsz_options = NULL;
media->item.i_options = 0;
media->item.i_categories = 0;
media->item.pp_categories = NULL;
media->item.i_es = 0;
media->item.es = 0;
vlc_mutex_init( vlm, &media->item.lock );
TAB_APPEND( vlm->i_media, vlm->media, media ); TAB_APPEND( vlm->i_media, vlm->media, media );
...@@ -969,19 +780,14 @@ static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type ) ...@@ -969,19 +780,14 @@ static vlm_media_t *vlm_MediaNew( vlm_t *vlm, char *psz_name, int i_type )
} }
/* for now, simple delete. After, del with options (last arg) */ /* for now, simple delete. After, del with options (last arg) */
static int vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, char *psz_name ) static void vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, char *psz_name )
{ {
int i; if( media == NULL ) return;
if( media == NULL ) return 1; while( media->i_instance )
if( media->p_input )
{ {
input_StopThread( media->p_input ); vlm_media_instance_t *p_instance = media->instance[0];
vlm_MediaControl( vlm, media, p_instance->psz_name, "stop", 0 );
input_DestroyThread( media->p_input );
vlc_object_detach( media->p_input );
vlc_object_destroy( media->p_input );
} }
TAB_REMOVE( vlm->i_media, vlm->media, media ); TAB_REMOVE( vlm->i_media, vlm->media, media );
...@@ -1005,27 +811,17 @@ static int vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, char *psz_name ) ...@@ -1005,27 +811,17 @@ static int vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, char *psz_name )
free( media->psz_name ); free( media->psz_name );
for( i = 0; i < media->i_input; i++ ) free( media->input[i] ); while( media->i_input-- ) free( media->input[media->i_input] );
if( media->input ) free( media->input ); if( media->input ) free( media->input );
if( media->psz_output ) free( media->psz_output ); if( media->psz_output ) free( media->psz_output );
for( i = 0; i < media->i_option; i++ ) free( media->option[i] ); while( media->i_option-- ) free( media->option[media->i_option] );
if(media->option) free( media->option ); if( media->option ) free( media->option );
if( media->item.psz_uri ) free( media->item.psz_uri ); vlc_input_item_Clean( &media->item );
if( media->item.psz_name ) free( media->item.psz_name );
vlc_mutex_destroy( &media->item.lock );
for( i = 0; i < media->item.i_options; i++ )
{
free( media->item.ppsz_options[i] );
}
if( media->item.ppsz_options ) free( media->item.ppsz_options );
/* FIXME: free the info categories. */
free( media ); free( media );
return 0;
} }
static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd, static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd,
...@@ -1085,7 +881,7 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd, ...@@ -1085,7 +881,7 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd,
} }
else else
{ {
return 1; return VLC_EGENERIC;
} }
/* Check if we need to create/delete a vod media */ /* Check if we need to create/delete a vod media */
...@@ -1093,49 +889,48 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd, ...@@ -1093,49 +889,48 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd,
{ {
if( !media->b_enabled && media->vod_media ) if( !media->b_enabled && media->vod_media )
{ {
int i;
for( i = 0; i < media->item.i_es; i++ )
{
es_format_Clean( media->item.es[i] );
free( media->item.es[i] );
}
if( media->item.es ) free( media->item.es );
media->item.es = 0;
media->item.i_es = 0;
vlm->vod->pf_media_del( vlm->vod, media->vod_media ); vlm->vod->pf_media_del( vlm->vod, media->vod_media );
media->vod_media = 0; media->vod_media = 0;
} }
else if( media->b_enabled && !media->vod_media ) else if( media->b_enabled && !media->vod_media && media->i_input )
{ {
/* Pre-parse the input */ /* Pre-parse the input */
char *psz_output = media->psz_output; input_thread_t *p_input;
char *psz_output;
int i;
vlc_input_item_Clean( &media->item );
vlc_input_item_Init( VLC_OBJECT(vlm), &media->item );
if( media->psz_output ) if( media->psz_output )
{ asprintf( &psz_output, "%s:description", media->psz_output );
asprintf( &media->psz_output, "%s:description",
media->psz_output );
}
else else
asprintf( &psz_output, "#description" );
media->item.psz_uri = strdup( media->input[0] );
media->item.ppsz_options = malloc( sizeof( char* ) );
asprintf( &media->item.ppsz_options[0], "sout=%s", psz_output);
media->item.i_options = 1;
for( i = 0; i < media->i_option; i++ )
{ {
asprintf( &media->psz_output, "#description" ); media->item.i_options++;
media->item.ppsz_options =
realloc( media->item.ppsz_options,
media->item.i_options * sizeof( char* ) );
media->item.ppsz_options[ media->item.i_options - 1 ] =
strdup( media->option[i] );
} }
if( !vlm_MediaControl( vlm, media, "play", 0 ) && media->p_input ) if( (p_input = input_CreateThread( vlm, &media->item ) ) )
{ {
while( !media->p_input->b_eof && !media->p_input->b_error ) while( !p_input->b_eof && !p_input->b_error ) msleep( 100000 );
{
msleep( 100000 );
}
input_StopThread( media->p_input ); input_StopThread( p_input );
input_DestroyThread( media->p_input ); input_DestroyThread( p_input );
vlc_object_detach( media->p_input ); vlc_object_detach( p_input );
vlc_object_destroy( media->p_input ); vlc_object_destroy( p_input );
media->p_input = NULL;
} }
free( media->psz_output ); free( psz_output );
media->psz_output = psz_output;
media->vod_media = media->vod_media =
vlm->vod->pf_media_new( vlm->vod, media->psz_name, vlm->vod->pf_media_new( vlm->vod, media->psz_name,
...@@ -1143,70 +938,81 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd, ...@@ -1143,70 +938,81 @@ static int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, char *psz_cmd,
} }
} }
return 0; return VLC_SUCCESS;
} }
static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_name, static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_id,
char *psz_args ) char *psz_command, char *psz_args )
{ {
if( strcmp( psz_name, "play" ) == 0 ) vlm_media_instance_t *p_instance;
{
int i; int i;
if( media->b_enabled == VLC_TRUE && media->i_input > 0 ) p_instance = vlm_MediaInstanceSearch( vlm, media, psz_id );
{
if( psz_args != NULL && sscanf( psz_args, "%d", &i ) == 1 && if( strcmp( psz_command, "play" ) == 0 && !p_instance )
i < media->i_input )
{
media->i_index = i;
}
else
{ {
media->i_index = 0; if( !media->b_enabled || media->i_input == 0 ) return 0;
}
if( media->item.psz_uri ) if( !p_instance )
{ {
free( media->item.psz_uri ); p_instance = malloc( sizeof(vlm_media_instance_t) );
media->item.psz_uri =NULL; memset( p_instance, 0, sizeof(vlm_media_instance_t) );
} vlc_input_item_Init( VLC_OBJECT(vlm), &p_instance->item );
media->item.psz_uri = strdup( media->input[media->i_index] ); p_instance->p_input = 0;
/* FIXME!!! we need an input_item_t per input spawned */
//input_ItemNew( &media->item );
if( media->psz_output != NULL ) if( media->psz_output != NULL )
{ {
media->item.ppsz_options = malloc( sizeof( char* ) ); p_instance->item.ppsz_options = malloc( sizeof( char* ) );
asprintf( &media->item.ppsz_options[0], "sout=%s", asprintf( &p_instance->item.ppsz_options[0], "sout=%s",
media->psz_output ); media->psz_output );
media->item.i_options = 1; p_instance->item.i_options = 1;
}
else
{
media->item.ppsz_options = NULL;
media->item.i_options = 0;
} }
for( i = 0; i < media->i_option; i++ ) for( i = 0; i < media->i_option; i++ )
{ {
media->item.i_options++; p_instance->item.i_options++;
media->item.ppsz_options = p_instance->item.ppsz_options =
realloc( media->item.ppsz_options, realloc( p_instance->item.ppsz_options,
media->item.i_options * sizeof( char* ) ); p_instance->item.i_options * sizeof( char* ) );
media->item.ppsz_options[ media->item.i_options - 1 ] = p_instance->item.ppsz_options[p_instance->item.i_options - 1] =
strdup( media->option[i] ); strdup( media->option[i] );
} }
media->p_input = input_CreateThread( vlm, &media->item ); p_instance->psz_name = psz_id ? strdup(psz_id) : 0;
TAB_APPEND( media->i_instance, media->instance, p_instance );
}
return 0; if( psz_args && sscanf(psz_args, "%d", &i) == 1 && i < media->i_input )
{
p_instance->i_index = i;
} }
else
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 )
{ {
return 1; input_StopThread( p_instance->p_input );
input_DestroyThread( p_instance->p_input );
vlc_object_detach( p_instance->p_input );
vlc_object_destroy( p_instance->p_input );
}
p_instance->p_input = input_CreateThread( vlm, &p_instance->item );
if( !p_instance->p_input )
{
TAB_REMOVE( media->i_instance, media->instance, p_instance );
vlc_input_item_Clean( &p_instance->item );
if( p_instance->psz_name ) free( p_instance->psz_name );
} }
return VLC_SUCCESS;
} }
else if( strcmp( psz_name, "seek" ) == 0 )
if( !p_instance ) return VLC_EGENERIC;
if( strcmp( psz_command, "seek" ) == 0 )
{ {
vlc_value_t val; vlc_value_t val;
float f_percentage; float f_percentage;
...@@ -1214,167 +1020,429 @@ static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_name, ...@@ -1214,167 +1020,429 @@ static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_name,
if( psz_args && sscanf( psz_args, "%f", &f_percentage ) == 1 ) if( psz_args && sscanf( psz_args, "%f", &f_percentage ) == 1 )
{ {
val.f_float = f_percentage / 100.0 ; val.f_float = f_percentage / 100.0 ;
var_Set( media->p_input, "position", val ); var_Set( p_instance->p_input, "position", val );
return 0; return VLC_SUCCESS;
} }
} }
else if( strcmp( psz_name, "stop" ) == 0 ) else if( strcmp( psz_command, "stop" ) == 0 )
{ {
/* FIXME!!! we need an input_item_t per input spawned */ TAB_REMOVE( media->i_instance, media->instance, p_instance );
if( media->p_input )
{
input_StopThread( media->p_input );
input_DestroyThread( media->p_input );
vlc_object_detach( media->p_input );
vlc_object_destroy( media->p_input );
media->p_input = NULL;
//input_ItemDelete( &media->item ); if( p_instance->p_input )
{
input_StopThread( p_instance->p_input );
input_DestroyThread( p_instance->p_input );
vlc_object_detach( p_instance->p_input );
vlc_object_destroy( p_instance->p_input );
} }
return 0; vlc_input_item_Clean( &p_instance->item );
if( p_instance->psz_name ) free( p_instance->psz_name );
free( p_instance );
return VLC_SUCCESS;
} }
else if( strcmp( psz_name, "pause" ) == 0 ) else if( strcmp( psz_command, "pause" ) == 0 )
{ {
vlc_value_t val; vlc_value_t val;
val.i_int = 0; if( !p_instance->p_input ) return VLC_SUCCESS;
if( media->p_input != NULL ) var_Get( p_instance->p_input, "state", &val );
{
var_Get( media->p_input, "state", &val );
}
if( val.i_int == PAUSE_S ) if( val.i_int == PAUSE_S ) val.i_int = PLAYING_S;
{ else val.i_int = PAUSE_S;
if( media->p_input ) var_Set( p_instance->p_input, "state", val );
{
val.i_int = PLAYING_S; return VLC_SUCCESS;
var_Set( media->p_input, "state", val );
}
}
else
{
if( media->p_input )
{
val.i_int = PAUSE_S;
var_Set( media->p_input, "state", val );
}
}
return 0;
} }
return 1; return VLC_EGENERIC;
} }
static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media, /*****************************************************************************
vlm_schedule_t *schedule, char *psz_filter ) * Schedule handling
*****************************************************************************/
static vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm, char *psz_name )
{ {
vlm_schedule_t *sched = malloc( sizeof( vlm_schedule_t ) );
if( media != NULL ) sched->psz_name = strdup( psz_name );
{ sched->b_enabled = VLC_FALSE;
int i; sched->i_command = 0;
vlm_message_t *message; sched->command = NULL;
vlm_message_t *message_media; sched->i_date = 0;
vlm_message_t *message_child; sched->i_period = 0;
sched->i_repeat = -1;
message = vlm_MessageNew( "show", NULL );
message_media = TAB_APPEND( vlm->i_schedule, vlm->schedule, sched );
vlm_MessageAdd( message, vlm_MessageNew( media->psz_name, NULL ) );
return sched;
if( media->i_type == VOD_TYPE ) }
{
vlm_MessageAdd(message_media, vlm_MessageNew("type", "vod")); /* for now, simple delete. After, del with options (last arg) */
} static void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_t *sched,
else char *psz_name )
{
if( sched == NULL ) return;
TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched );
if( vlm->i_schedule == 0 && vlm->schedule ) free( vlm->schedule );
free( sched->psz_name );
while( sched->i_command-- ) free( sched->command[sched->i_command] );
free( sched );
}
static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *vlm, char *psz_name )
{
int i;
for( i = 0; i < vlm->i_schedule; i++ )
{
if( strcmp( psz_name, vlm->schedule[i]->psz_name ) == 0 )
{ {
vlm_MessageAdd(message_media, vlm_MessageNew("type", "broadcast")); return vlm->schedule[i];
}
} }
vlm_MessageAdd( message_media, return NULL;
vlm_MessageNew( "enabled", media->b_enabled ? }
"yes" : "no" ) );
vlm_MessageAdd( message_media, /* Ok, setup schedule command will be able to support only one (argument value) at a time */
vlm_MessageNew( "loop", media->b_loop ? static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
"yes" : "no" ) ); char *psz_value )
{
if( strcmp( psz_cmd, "enabled" ) == 0 )
{
schedule->b_enabled = VLC_TRUE;
}
else if( strcmp( psz_cmd, "disabled" ) == 0 )
{
schedule->b_enabled = VLC_FALSE;
}
else if( strcmp( psz_cmd, "date" ) == 0 )
{
struct tm time;
char *p;
time_t date;
message_child = vlm_MessageAdd( message_media, time.tm_sec = 0; /* seconds */
vlm_MessageNew( "inputs", NULL ) ); 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 = 0; /* 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( strcmp( psz_value, "now" ) == 0 )
{ {
vlm_MessageAdd( message_child, schedule->i_date = 0;
vlm_MessageNew( media->input[i], NULL ) );
} }
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
{
int i,j,k;
vlm_MessageAdd( message_media, switch( sscanf( p + 1, "%d:%d:%d", &i, &j, &k ) )
vlm_MessageNew( "output", media->psz_output ? {
media->psz_output : "" ) ); 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;
}
message_child = vlm_MessageAdd( message_media, *p = '\0';
vlm_MessageNew( "options", NULL ) );
for( i=0 ; i < (media->i_option) ; i++ ) switch( sscanf( psz_value, "%d/%d/%d", &i, &j, &k ) )
{ {
vlm_MessageAdd( message_child, case 1:
vlm_MessageNew( media->option[i], NULL ) ); 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;
} }
if( media->p_input != NULL ) date = mktime( &time );
schedule->i_date = ((mtime_t) date) * 1000000;
}
}
else if( strcmp( psz_cmd, "period" ) == 0 )
{ {
vlc_value_t val; struct tm time;
char *p;
char *psz_time = NULL, *psz_date = NULL;
time_t date;
int i,j,k;
/* First, if date or period are modified, repeat should be equal to -1 */
schedule->i_repeat = -1;
time.tm_sec = 0; /* seconds */
time.tm_min = 0; /* minutes */
time.tm_hour = 0; /* hours */
time.tm_mday = 0; /* day of the month */
time.tm_mon = 0; /* month */
time.tm_year = 0; /* year */
time.tm_wday = 0; /* day of the week */
time.tm_yday = 0; /* day in the year */
time.tm_isdst = 0; /* daylight saving time */
var_Get( media->p_input, "state", &val ); /* date should be year/month/day-hour:minutes:seconds */
p = strchr( psz_value, '-' );
if( p )
{
psz_date = psz_value;
psz_time = p + 1;
if( val.i_int == PLAYING_S ) *p = '\0';
}
else
{
psz_time = psz_value;
}
switch( sscanf( psz_time, "%d:%d:%d", &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, "%d/%d/%d", &i, &j, &k ) )
{ {
vlm_MessageAdd( message_media, case 1:
vlm_MessageNew( "state", "playing" ) ); 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( val.i_int == PAUSE_S ) else if( strcmp( psz_cmd, "repeat" ) == 0 )
{
int i;
if( sscanf( psz_value, "%d", &i ) == 1 )
{ {
vlm_MessageAdd( message_media, schedule->i_repeat = i;
vlm_MessageNew( "state", "paused" ) );
} }
else else
{ {
vlm_MessageAdd( message_media, return 1;
vlm_MessageNew( "state", "stop" ) );
} }
} }
else if( strcmp( psz_cmd, "append" ) == 0 )
{
char *command = strdup( psz_value );
TAB_APPEND( schedule->i_command, schedule->command, command );
}
else else
{ {
vlm_MessageAdd( message_media, return 1;
vlm_MessageNew( "state", "stop" ) );
} }
return 0;
}
return message; /*****************************************************************************
* Message handling functions
*****************************************************************************/
static vlm_message_t *vlm_MessageNew( char *psz_name,
const char *psz_format, ... )
{
vlm_message_t *p_message;
va_list args;
if( !psz_name ) return 0;
p_message = malloc( sizeof(vlm_message_t) );
p_message->psz_value = 0;
if( psz_format )
{
va_start( args, psz_format );
if( vasprintf( &p_message->psz_value, psz_format, args ) < 0 )
{
va_end( args );
free( p_message );
return 0;
}
va_end( args );
}
p_message->psz_name = strdup( psz_name );
p_message->i_child = 0;
p_message->child = NULL;
return p_message;
}
void vlm_MessageDelete( vlm_message_t *p_message )
{
if( p_message->psz_name ) free( p_message->psz_name );
if( p_message->psz_value ) free( p_message->psz_value );
while( p_message->i_child-- )
vlm_MessageDelete( p_message->child[p_message->i_child] );
if( p_message->child ) free( p_message->child );
free( p_message );
}
/* Add a child */
static vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message,
vlm_message_t *p_child )
{
if( p_message == NULL ) return NULL;
if( p_child )
{
TAB_APPEND( p_message->i_child, p_message->child, p_child );
} }
else if( schedule != NULL )
return p_child;
}
/*****************************************************************************
* Misc utility functions
*****************************************************************************/
static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media,
vlm_schedule_t *schedule, char *psz_filter )
{
if( media != NULL )
{ {
int i; int i;
vlm_message_t *message; vlm_message_t *msg;
vlm_message_t *message_schedule; vlm_message_t *msg_media;
vlm_message_t *message_child; vlm_message_t *msg_child;
char buffer[100];
message = vlm_MessageNew( "show", NULL ); msg = vlm_MessageNew( "show", NULL );
message_schedule = msg_media = vlm_MessageAdd( msg, vlm_MessageNew( media->psz_name, 0 ));
vlm_MessageAdd( message, vlm_MessageNew( schedule->psz_name, 0 ) );
vlm_MessageAdd( message_schedule, vlm_MessageNew("type", "schedule") ); 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( schedule->b_enabled == VLC_TRUE ) vlm_MessageAdd( msg_media,
vlm_MessageNew( "loop", media->b_loop ?
"yes" : "no" ) );
msg_child = vlm_MessageAdd( msg_media,
vlm_MessageNew( "inputs", NULL ) );
for( i = 0; i < media->i_input; i++ )
{ {
vlm_MessageAdd(message_schedule, vlm_MessageNew("enabled", "yes")); vlm_MessageAdd( msg_child,
vlm_MessageNew( media->input[i], NULL ) );
} }
else
vlm_MessageAdd( msg_media,
vlm_MessageNew( "output", media->psz_output ?
media->psz_output : "" ) );
msg_child = vlm_MessageAdd( msg_media, vlm_MessageNew( "options", 0 ));
for( i = 0; i < media->i_option; i++ )
{
vlm_MessageAdd( msg_child, vlm_MessageNew( media->option[i], 0 ) );
}
msg_child = vlm_MessageAdd( msg_media,
vlm_MessageNew( "instances", NULL ) );
for( i = 0; i < media->i_instance; i++ )
{ {
vlm_MessageAdd(message_schedule, vlm_MessageNew("enabled", "no")); vlm_media_instance_t *p_instance = media->instance[i];
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_child,
vlm_MessageNew( p_instance->psz_name ?
p_instance->psz_name : "default",
val.i_int == PLAYING_S ? "playing" :
val.i_int == PAUSE_S ? "paused" :
"stopped" ) );
}
return msg;
} }
else if( schedule != NULL )
{
int i;
vlm_message_t *msg;
vlm_message_t *msg_schedule;
vlm_message_t *msg_child;
char buffer[100];
msg = vlm_MessageNew( "show", NULL );
msg_schedule =
vlm_MessageAdd( msg, vlm_MessageNew( schedule->psz_name, 0 ) );
vlm_MessageAdd( msg_schedule, vlm_MessageNew("type", "schedule") );
vlm_MessageAdd( msg_schedule,
vlm_MessageNew( "enabled", schedule->b_enabled ?
"yes" : "no" ) );
if( schedule->i_date != 0 ) if( schedule->i_date != 0 )
{ {
struct tm date; struct tm date;
...@@ -1392,13 +1460,13 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media, ...@@ -1392,13 +1460,13 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media,
date.tm_year + 1900, date.tm_mon + 1, date.tm_mday, date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
date.tm_hour, date.tm_min, date.tm_sec ); date.tm_hour, date.tm_min, date.tm_sec );
vlm_MessageAdd( message_schedule, vlm_MessageAdd( msg_schedule,
vlm_MessageNew( "date", psz_date ) ); vlm_MessageNew( "date", psz_date ) );
free( psz_date ); free( psz_date );
} }
else else
{ {
vlm_MessageAdd( message_schedule, vlm_MessageNew("date", "now") ); vlm_MessageAdd( msg_schedule, vlm_MessageNew("date", "now") );
} }
if( schedule->i_period != 0 ) if( schedule->i_period != 0 )
...@@ -1422,124 +1490,106 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media, ...@@ -1422,124 +1490,106 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media,
sprintf( buffer, "%d/%d/%d-%d:%d:%d", date.tm_year, date.tm_mon, 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); date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec);
vlm_MessageAdd(message_schedule, vlm_MessageNew("period", buffer)); vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", buffer) );
} }
else else
{ {
vlm_MessageAdd(message_schedule, vlm_MessageNew("period", "0")); vlm_MessageAdd( msg_schedule, vlm_MessageNew("period", "0") );
} }
sprintf( buffer, "%d", schedule->i_repeat ); sprintf( buffer, "%d", schedule->i_repeat );
vlm_MessageAdd( message_schedule, vlm_MessageNew( "repeat", buffer ) ); vlm_MessageAdd( msg_schedule, vlm_MessageNew( "repeat", buffer ) );
message_child = msg_child =
vlm_MessageAdd( message_schedule, vlm_MessageNew("commands", 0) ); vlm_MessageAdd( msg_schedule, vlm_MessageNew("commands", 0) );
for( i = 0 ; i < schedule->i_command ; i++ ) for( i = 0; i < schedule->i_command; i++ )
{ {
vlm_MessageAdd( message_child, vlm_MessageAdd( msg_child,
vlm_MessageNew( schedule->command[i], NULL ) ); vlm_MessageNew( schedule->command[i], NULL ) );
} }
return message; return msg;
} }
else if( psz_filter && strcmp( psz_filter, "media") == 0 ) else if( psz_filter && strcmp( psz_filter, "media") == 0 )
{ {
int i; int i, j;
vlm_message_t *message; vlm_message_t *msg;
vlm_message_t *message_child; vlm_message_t *msg_child;
message = vlm_MessageNew( "show", NULL ); msg = vlm_MessageNew( "show", NULL );
message_child = msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "media", NULL ) );
vlm_MessageAdd( message, vlm_MessageNew( "media", NULL ) );
for( i = 0; i < vlm->i_media; i++ ) for( i = 0; i < vlm->i_media; i++ )
{ {
vlm_media_t *m = vlm->media[i]; vlm_media_t *m = vlm->media[i];
vlm_message_t *message_media = vlm_message_t *msg_media, *msg_instance;
vlm_MessageAdd(message_child, vlm_MessageNew(m->psz_name, 0));
if( m->i_type == VOD_TYPE ) msg_media = vlm_MessageAdd( msg_child,
{ vlm_MessageNew( m->psz_name, 0 ) );
vlm_MessageAdd( message_media,
vlm_MessageNew( "type", "vod" ) );
}
else
{
vlm_MessageAdd( message_media,
vlm_MessageNew( "type", "broadcast" ) );
}
if( m->b_enabled == VLC_TRUE ) vlm_MessageAdd( msg_media,
{ vlm_MessageNew( "type", m->i_type == VOD_TYPE ?
vlm_MessageAdd( message_media, "vod" : "broadcast" ) );
vlm_MessageNew( "enabled", "yes" ) );
} vlm_MessageAdd( msg_media,
else vlm_MessageNew( "enabled", m->b_enabled ?
{ "yes" : "no" ) );
vlm_MessageAdd( message_media,
vlm_MessageNew( "enabled", "no" ) ); msg_instance = vlm_MessageAdd( msg_media,
} vlm_MessageNew( "instances", 0 ) );
if( m->p_input != NULL ) for( j = 0; j < m->i_instance; j++ )
{ {
vlm_media_instance_t *p_instance = m->instance[j];
vlc_value_t val; vlc_value_t val;
var_Get( m->p_input, "state", &val ); if( !p_instance->p_input ) val.i_int = END_S;
else var_Get( p_instance->p_input, "state", &val );
if( val.i_int == PLAYING_S ) vlm_MessageAdd( msg_instance,
{ vlm_MessageNew( p_instance->psz_name ?
vlm_MessageAdd( message_media, p_instance->psz_name : "default",
vlm_MessageNew( "state", "playing" ) ); val.i_int == PLAYING_S ? "playing" :
} val.i_int == PAUSE_S ? "paused" :
else if( val.i_int == PAUSE_S ) "stopped" ) );
{
vlm_MessageAdd( message_media,
vlm_MessageNew( "state", "paused" ) );
}
else
{
vlm_MessageAdd( message_media,
vlm_MessageNew( "state", "stop" ) );
}
}
else
{
vlm_MessageAdd( message_media,
vlm_MessageNew( "state", "stop" ) );
} }
} }
return message; return msg;
} }
else if( psz_filter && strcmp( psz_filter, "schedule") == 0 ) else if( psz_filter && strcmp( psz_filter, "schedule") == 0 )
{ {
int i; int i;
vlm_message_t *message; vlm_message_t *msg;
vlm_message_t *message_child; vlm_message_t *msg_child;
message = vlm_MessageNew( "show", NULL ); msg = vlm_MessageNew( "show", NULL );
message_child = msg_child = vlm_MessageAdd( msg, vlm_MessageNew( "schedule", NULL ) );
vlm_MessageAdd( message, vlm_MessageNew( "schedule", NULL ) );
for( i = 0; i < vlm->i_schedule; i++ ) for( i = 0; i < vlm->i_schedule; i++ )
{ {
vlm_schedule_t *s = vlm->schedule[i]; vlm_schedule_t *s = vlm->schedule[i];
vlm_message_t *message_schedule = vlm_message_t *msg_schedule;
vlm_MessageAdd(message_child, vlm_MessageNew(s->psz_name, 0)); mtime_t i_time, i_next_date;
msg_schedule = vlm_MessageAdd( msg_child,
vlm_MessageNew( s->psz_name, 0 ) );
vlm_MessageAdd( msg_schedule,
vlm_MessageNew( "enabled", s->b_enabled ?
"yes" : "no" ) );
if( !s->b_enabled ) return msg;
if( s->b_enabled == VLC_TRUE )
{
mtime_t i_time;
mtime_t i_next_date;
vlm_MessageAdd( message_schedule, vlm_MessageAdd( msg_schedule,
vlm_MessageNew( "enabled", "yes" ) ); vlm_MessageNew( "enabled", "yes" ) );
/* calculate next date */ /* calculate next date */
i_time = mdate(); i_time = mdate();
i_next_date = s->i_date; i_next_date = s->i_date;
if( s->i_period != 0 ) if( s->i_period != 0 )
...@@ -1565,19 +1615,14 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media, ...@@ -1565,19 +1615,14 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media,
char *psz_date = ctime( &i_date ); char *psz_date = ctime( &i_date );
#endif #endif
vlm_MessageAdd( message_schedule, vlm_MessageAdd( msg_schedule,
vlm_MessageNew("next launch", psz_date) ); vlm_MessageNew( "next launch", psz_date ) );
}
}
else
{
vlm_MessageAdd( message_schedule,
vlm_MessageNew( "enabled", "no" ) );
} }
} }
return message; return msg;
} }
else if( psz_filter == NULL && media == NULL && schedule == NULL ) else if( psz_filter == NULL && media == NULL && schedule == NULL )
{ {
vlm_message_t *show1 = vlm_Show( vlm, NULL, NULL, "media" ); vlm_message_t *show1 = vlm_Show( vlm, NULL, NULL, "media" );
...@@ -1592,6 +1637,7 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media, ...@@ -1592,6 +1637,7 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media,
return show1; return show1;
} }
else else
{ {
return vlm_MessageNew( "show", NULL ); return vlm_MessageNew( "show", NULL );
...@@ -1637,523 +1683,278 @@ static vlm_message_t *vlm_Help( vlm_t *vlm, char *psz_filter ) ...@@ -1637,523 +1683,278 @@ static vlm_message_t *vlm_Help( vlm_t *vlm, char *psz_filter )
return vlm_MessageNew( "help", NULL ); return vlm_MessageNew( "help", NULL );
} }
/* file must end by '\0' */ /*****************************************************************************
static int vlm_Load( vlm_t *vlm, char *file ) * Config handling functions
{ *****************************************************************************/
char *pf = file; static int vlm_Load( vlm_t *vlm, char *file )
{
while( *pf != '\0' ) char *pf = file;
{
vlm_message_t *message = NULL;
int i_temp = 0;
int i_next;
while( pf[i_temp] != '\n' && pf[i_temp] != '\0' && pf[i_temp] != '\r' )
{
i_temp++;
}
if( pf[i_temp] == '\r' || pf[i_temp] == '\n' )
{
pf[i_temp] = '\0';
i_next = i_temp + 1;
}
else
{
i_next = i_temp;
}
if( ExecuteCommand( vlm, pf, &message ) )
{
free( message );
return 1;
}
free( message );
pf += i_next;
}
return 0;
}
static char *vlm_Save( vlm_t *vlm )
{
char *save = NULL;
char *p;
int i,j;
int i_length = 0;
for( i = 0; i < vlm->i_media; i++ )
{
vlm_media_t *media = vlm->media[i];
if( media->i_type == VOD_TYPE )
{
i_length += strlen( "new vod " ) + strlen(media->psz_name);
}
else
{
i_length += strlen( "new broadcast " ) + strlen(media->psz_name);
}
if( media->b_enabled == VLC_TRUE )
{
i_length += strlen( "enabled" );
}
else
{
i_length += strlen( "disabled" );
}
if( media->b_loop == VLC_TRUE )
{
i_length += strlen( " loop\n" );
}
else
{
i_length += strlen( "\n" );
}
for( j = 0; j < media->i_input; j++ )
{
i_length += strlen( "setup input \"\"\n" ) +
strlen( media->psz_name ) + strlen( media->input[j] );
}
if( media->psz_output != NULL )
{
i_length += strlen(media->psz_name) + strlen(media->psz_output) +
strlen( "setup output \n" );
}
for( j=0 ; j < media->i_option ; j++ )
{
i_length += strlen(media->psz_name) + strlen(media->option[j]) +
strlen("setup option \n");
}
}
for( i = 0; i < vlm->i_schedule; i++ )
{
vlm_schedule_t *schedule = vlm->schedule[i];
i_length += strlen( "new schedule " ) + strlen( schedule->psz_name );
if( schedule->b_enabled == VLC_TRUE )
{
i_length += strlen( "date //-:: enabled\n" ) + 14;
}
else
{
i_length += strlen( "date //-:: disabled\n" ) + 14;
}
while( *pf != '\0' )
{
vlm_message_t *message = NULL;
int i_temp = 0;
int i_next;
if( schedule->i_period != 0 ) while( pf[i_temp] != '\n' && pf[i_temp] != '\0' && pf[i_temp] != '\r' )
{ {
i_length += strlen( "setup " ) + strlen( schedule->psz_name ) + i_temp++;
strlen( "period //-::\n" ) + 14;
} }
if( schedule->i_repeat >= 0 ) if( pf[i_temp] == '\r' || pf[i_temp] == '\n' )
{ {
char buffer[12]; pf[i_temp] = '\0';
i_next = i_temp + 1;
sprintf( buffer, "%d", schedule->i_repeat );
i_length += strlen( "setup repeat \n" ) +
strlen( schedule->psz_name ) + strlen( buffer );
} }
else else
{ {
i_length++; i_next = i_temp;
} }
for( j = 0; j < schedule->i_command; j++ ) if( ExecuteCommand( vlm, pf, &message ) )
{ {
i_length += strlen( "setup append \n" ) + free( message );
strlen( schedule->psz_name ) + strlen( schedule->command[j] ); return 1;
} }
free( message );
pf += i_next;
} }
/* Don't forget the '\0' */ return 0;
i_length++; }
/* now we have the length of save */
p = save = malloc( i_length ); static char *vlm_Save( vlm_t *vlm )
*save = '\0'; {
char *save = NULL;
char *p;
int i,j;
int i_length = 0;
/* finally we can write in it */
for( i = 0; i < vlm->i_media; i++ ) for( i = 0; i < vlm->i_media; i++ )
{ {
vlm_media_t *media = vlm->media[i]; vlm_media_t *media = vlm->media[i];
if( media->i_type == VOD_TYPE ) if( media->i_type == VOD_TYPE )
{ {
p += sprintf( p, "new %s vod ", media->psz_name); i_length += strlen( "new vod " ) + strlen(media->psz_name);
} }
else else
{ {
p += sprintf( p, "new %s broadcast ", media->psz_name); i_length += strlen( "new broadcast " ) + strlen(media->psz_name);
} }
if( media->b_enabled == VLC_TRUE ) if( media->b_enabled == VLC_TRUE )
{ {
p += sprintf( p, "enabled" ); i_length += strlen( "enabled" );
} }
else else
{ {
p += sprintf( p, "disabled" ); i_length += strlen( "disabled" );
} }
if( media->b_loop == VLC_TRUE ) if( media->b_loop == VLC_TRUE )
{ {
p += sprintf( p, " loop\n" ); i_length += strlen( " loop\n" );
} }
else else
{ {
p += sprintf( p, "\n" ); i_length += strlen( "\n" );
} }
for( j = 0; j < media->i_input; j++ ) for( j = 0; j < media->i_input; j++ )
{ {
p += sprintf( p, "setup %s input \"%s\"\n", media->psz_name, i_length += strlen( "setup input \"\"\n" ) +
media->input[j] ); strlen( media->psz_name ) + strlen( media->input[j] );
} }
if( media->psz_output != NULL ) if( media->psz_output != NULL )
{ {
p += sprintf( p, "setup %s output %s\n", media->psz_name, i_length += strlen(media->psz_name) + strlen(media->psz_output) +
media->psz_output ); strlen( "setup output \n" );
} }
for( j = 0; j < media->i_option; j++ ) for( j=0 ; j < media->i_option ; j++ )
{ {
p += sprintf( p, "setup %s option %s\n", media->psz_name, i_length += strlen(media->psz_name) + strlen(media->option[j]) +
media->option[j] ); strlen("setup option \n");
} }
} }
/* and now, the schedule scripts */
for( i = 0; i < vlm->i_schedule; i++ ) for( i = 0; i < vlm->i_schedule; i++ )
{ {
vlm_schedule_t *schedule = vlm->schedule[i]; vlm_schedule_t *schedule = vlm->schedule[i];
struct tm date;
time_t i_time = (time_t) ( schedule->i_date / 1000000 );
#ifdef HAVE_LOCALTIME_R
localtime_r( &i_time, &date);
#else
struct tm *p_date = localtime( &i_time );
date = *p_date;
#endif
p += sprintf( p, "new %s schedule ", schedule->psz_name); i_length += strlen( "new schedule " ) + strlen( schedule->psz_name );
if( schedule->b_enabled == VLC_TRUE ) if( schedule->b_enabled == VLC_TRUE )
{ {
p += sprintf( p, "date %d/%d/%d-%d:%d:%d enabled\n", i_length += strlen( "date //-:: enabled\n" ) + 14;
date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
date.tm_hour, date.tm_min, date.tm_sec );
}
else
{
p += sprintf( p, "date %d/%d/%d-%d:%d:%d disabled\n",
date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
date.tm_hour, date.tm_min, date.tm_sec);
}
if( schedule->i_period != 0 )
{
p += sprintf( p, "setup %s ", schedule->psz_name );
i_time = (time_t) ( schedule->i_period / 1000000 );
date.tm_sec = (int)( i_time % 60 );
i_time = i_time / 60;
date.tm_min = (int)( i_time % 60 );
i_time = i_time / 60;
date.tm_hour = (int)( i_time % 24 );
i_time = i_time / 24;
date.tm_mday = (int)( i_time % 30 );
i_time = i_time / 30;
/* okay, okay, months are not always 30 days long */
date.tm_mon = (int)( i_time % 12 );
i_time = i_time / 12;
date.tm_year = (int)i_time;
p += sprintf( p, "period %d/%d/%d-%d:%d:%d\n",
date.tm_year, date.tm_mon, date.tm_mday,
date.tm_hour, date.tm_min, date.tm_sec);
}
if( schedule->i_repeat >= 0 )
{
p += sprintf( p, "setup %s repeat %d\n",
schedule->psz_name, schedule->i_repeat );
}
else
{
p += sprintf( p, "\n" );
}
for( j = 0; j < schedule->i_command; j++ )
{
p += sprintf( p, "setup %s append %s\n",
schedule->psz_name, schedule->command[j] );
}
}
return save;
}
static vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm, char *psz_name )
{
vlm_schedule_t *sched = malloc( sizeof( vlm_schedule_t ) );
sched->psz_name = strdup( psz_name );
sched->b_enabled = VLC_FALSE;
sched->i_command = 0;
sched->command = NULL;
sched->i_date = 0;
sched->i_period = 0;
sched->i_repeat = -1;
TAB_APPEND( vlm->i_schedule, vlm->schedule, sched );
return sched;
}
/* for now, simple delete. After, del with options (last arg) */
static int vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_t *sched,
char *psz_name )
{
int i;
if( sched == NULL )
{
return 1;
}
TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched );
if( vlm->i_schedule == 0 && vlm->schedule ) free( vlm->schedule );
free( sched->psz_name );
for( i = 0; i < sched->i_command; i++ )
{
free( sched->command[i] );
}
free( sched );
return 0;
}
static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *vlm, char *psz_name )
{
int i;
for( i = 0; i < vlm->i_schedule; i++ )
{
if( strcmp( psz_name, vlm->schedule[i]->psz_name ) == 0 )
{
return vlm->schedule[i];
}
}
return NULL;
}
/* Ok, setup schedule command will be able to support only one (argument value) at a time */
static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
char *psz_value )
{
if( strcmp( psz_cmd, "enabled" ) == 0 )
{
schedule->b_enabled = VLC_TRUE;
}
else if( strcmp( psz_cmd, "disabled" ) == 0 )
{
schedule->b_enabled = VLC_FALSE;
}
else if( strcmp( psz_cmd, "date" ) == 0 )
{
struct tm time;
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 = 0; /* daylight saving time */
/* date should be year/month/day-hour:minutes:seconds */
p = strchr( psz_value, '-' );
if( strcmp( psz_value, "now" ) == 0 )
{
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 else
{ {
int i,j,k; i_length += strlen( "date //-:: disabled\n" ) + 14;
switch( sscanf( p + 1, "%d:%d:%d", &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;
} }
*p = '\0';
switch( sscanf( psz_value, "%d/%d/%d", &i, &j, &k ) ) if( schedule->i_period != 0 )
{ {
case 1: i_length += strlen( "setup " ) + strlen( schedule->psz_name ) +
time.tm_mday = i; strlen( "period //-::\n" ) + 14;
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 ); if( schedule->i_repeat >= 0 )
schedule->i_date = ((mtime_t) date) * 1000000; {
char buffer[12];
sprintf( buffer, "%d", schedule->i_repeat );
i_length += strlen( "setup repeat \n" ) +
strlen( schedule->psz_name ) + strlen( buffer );
} }
else
{
i_length++;
} }
else if( strcmp( psz_cmd, "period" ) == 0 )
for( j = 0; j < schedule->i_command; j++ )
{ {
struct tm time; i_length += strlen( "setup append \n" ) +
char *p; strlen( schedule->psz_name ) + strlen( schedule->command[j] );
char *psz_time = NULL, *psz_date = NULL; }
time_t date;
int i,j,k;
/* First, if date or period are modified, repeat should be equal to -1 */ }
schedule->i_repeat = -1;
time.tm_sec = 0; /* seconds */ /* Don't forget the '\0' */
time.tm_min = 0; /* minutes */ i_length++;
time.tm_hour = 0; /* hours */ /* now we have the length of save */
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 = 0; /* daylight saving time */
/* date should be year/month/day-hour:minutes:seconds */ p = save = malloc( i_length );
p = strchr( psz_value, '-' ); *save = '\0';
if( p )
/* finally we can write in it */
for( i = 0; i < vlm->i_media; i++ )
{ {
psz_date = psz_value; vlm_media_t *media = vlm->media[i];
psz_time = p + 1;
*p = '\0'; if( media->i_type == VOD_TYPE )
{
p += sprintf( p, "new %s vod ", media->psz_name);
} }
else else
{ {
psz_time = psz_value; p += sprintf( p, "new %s broadcast ", media->psz_name);
} }
if( media->b_enabled == VLC_TRUE )
{
p += sprintf( p, "enabled" );
}
else
{
p += sprintf( p, "disabled" );
}
switch( sscanf( psz_time, "%d:%d:%d", &i, &j, &k ) ) if( media->b_loop == VLC_TRUE )
{ {
case 1: p += sprintf( p, " loop\n" );
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 ) else
{ {
switch( sscanf( psz_date, "%d/%d/%d", &i, &j, &k ) ) p += sprintf( p, "\n" );
}
for( j = 0; j < media->i_input; j++ )
{ {
case 1: p += sprintf( p, "setup %s input \"%s\"\n", media->psz_name,
time.tm_mday = i; media->input[j] );
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;
} }
if( media->psz_output != NULL )
{
p += sprintf( p, "setup %s output %s\n", media->psz_name,
media->psz_output );
} }
/* ok, that's stupid... who is going to schedule streams every 42 years ? */ for( j = 0; j < media->i_option; j++ )
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; p += sprintf( p, "setup %s option %s\n", media->psz_name,
media->option[j] );
} }
else if( strcmp( psz_cmd, "repeat" ) == 0 ) }
/* and now, the schedule scripts */
for( i = 0; i < vlm->i_schedule; i++ )
{ {
int i; vlm_schedule_t *schedule = vlm->schedule[i];
struct tm date;
time_t i_time = (time_t) ( schedule->i_date / 1000000 );
if( sscanf( psz_value, "%d", &i ) == 1 ) #ifdef HAVE_LOCALTIME_R
localtime_r( &i_time, &date);
#else
struct tm *p_date = localtime( &i_time );
date = *p_date;
#endif
p += sprintf( p, "new %s schedule ", schedule->psz_name);
if( schedule->b_enabled == VLC_TRUE )
{ {
schedule->i_repeat = i; 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 else
{ {
return 1; 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);
} }
else if( strcmp( psz_cmd, "append" ) == 0 )
if( schedule->i_period != 0 )
{ {
char *command = strdup( psz_value ); p += sprintf( p, "setup %s ", schedule->psz_name );
TAB_APPEND( schedule->i_command, schedule->command, command ); i_time = (time_t) ( schedule->i_period / 1000000 );
date.tm_sec = (int)( i_time % 60 );
i_time = i_time / 60;
date.tm_min = (int)( i_time % 60 );
i_time = i_time / 60;
date.tm_hour = (int)( i_time % 24 );
i_time = i_time / 24;
date.tm_mday = (int)( i_time % 30 );
i_time = i_time / 30;
/* okay, okay, months are not always 30 days long */
date.tm_mon = (int)( i_time % 12 );
i_time = i_time / 12;
date.tm_year = (int)i_time;
p += sprintf( p, "period %d/%d/%d-%d:%d:%d\n",
date.tm_year, date.tm_mon, date.tm_mday,
date.tm_hour, date.tm_min, date.tm_sec);
}
if( schedule->i_repeat >= 0 )
{
p += sprintf( p, "setup %s repeat %d\n",
schedule->psz_name, schedule->i_repeat );
} }
else else
{ {
return 1; p += sprintf( p, "\n" );
} }
return 0;
for( j = 0; j < schedule->i_command; j++ )
{
p += sprintf( p, "setup %s append %s\n",
schedule->psz_name, schedule->command[j] );
}
}
return save;
} }
/***************************************************************************** /*****************************************************************************
...@@ -2162,7 +1963,7 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd, ...@@ -2162,7 +1963,7 @@ static int vlm_ScheduleSetup( vlm_schedule_t *schedule, char *psz_cmd,
static int Manage( vlc_object_t* p_object ) static int Manage( vlc_object_t* p_object )
{ {
vlm_t *vlm = (vlm_t*)p_object; vlm_t *vlm = (vlm_t*)p_object;
int i,j; int i, j;
mtime_t i_lastcheck; mtime_t i_lastcheck;
mtime_t i_time; mtime_t i_time;
...@@ -2177,31 +1978,37 @@ static int Manage( vlc_object_t* p_object ) ...@@ -2177,31 +1978,37 @@ static int Manage( vlc_object_t* p_object )
/* destroy the inputs that wants to die, and launch the next input */ /* destroy the inputs that wants to die, and launch the next input */
for( i = 0; i < vlm->i_media; i++ ) for( i = 0; i < vlm->i_media; i++ )
{ {
vlm_media_t *media = vlm->media[i]; vlm_media_t *p_media = vlm->media[i];
if( media->p_input != NULL && for( j = 0; j < p_media->i_instance; j++ )
( media->p_input->b_eof || media->p_input->b_error ) )
{ {
input_StopThread( media->p_input ); vlm_media_instance_t *p_instance = p_media->instance[j];
input_DestroyThread( media->p_input ); if( !p_instance->p_input ||
vlc_object_detach( media->p_input ); ( !p_instance->p_input->b_eof &&
vlc_object_destroy( media->p_input ); !p_instance->p_input->b_error ) ) continue;
media->p_input = NULL;
media->i_index++;
if( media->i_index == media->i_input && input_StopThread( p_instance->p_input );
media->b_loop == VLC_TRUE ) input_DestroyThread( p_instance->p_input );
{ vlc_object_detach( p_instance->p_input );
media->i_index = 0; vlc_object_destroy( p_instance->p_input );
}
if( media->i_index < media->i_input ) p_instance->i_index++;
if( p_instance->i_index == p_media->i_input &&
p_media->b_loop ) p_instance->i_index = 0;
if( p_instance->i_index < p_media->i_input )
{ {
/* FIXME, find a way to select the right instance */
char buffer[12]; char buffer[12];
sprintf( buffer, "%d", p_instance->i_index );
sprintf( buffer, "%d", media->i_index ); vlm_MediaControl( vlm, p_media, p_instance->psz_name,
vlm_MediaControl( vlm, media, "play", buffer ); "play", buffer );
}
else
{
if( vlm_MediaControl( vlm, p_media, p_instance->psz_name,
"stop", 0 ) == VLC_SUCCESS ) i--;
} }
} }
} }
...@@ -2260,60 +2067,3 @@ static int Manage( vlc_object_t* p_object ) ...@@ -2260,60 +2067,3 @@ static int Manage( vlc_object_t* p_object )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static vlm_message_t* vlm_MessageNew( char *psz_name, char *psz_value )
{
vlm_message_t *message = malloc( sizeof(vlm_message_t) );
if( psz_name )
{
message->psz_name = strdup( psz_name );
}
else
{
return NULL;
}
if( psz_value )
{
message->psz_value = strdup( psz_value );
}
else
{
message->psz_value = NULL;
}
message->i_child = 0;
message->child = NULL;
return message;
}
void vlm_MessageDelete( vlm_message_t* message )
{
int i;
if( message->psz_name ) free( message->psz_name );
if( message->psz_value ) free( message->psz_value );
for( i = 0; i < message->i_child; i++)
{
vlm_MessageDelete( message->child[i] );
}
free( message );
}
/* Add a child */
static vlm_message_t *vlm_MessageAdd( vlm_message_t* message,
vlm_message_t* child )
{
if( message == NULL ) return NULL;
if( child )
{
TAB_APPEND( message->i_child, message->child, child );
}
return child;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment