Commit ea0b76fe authored by Laurent Aimar's avatar Laurent Aimar

Improved the way input-list is given to stream_AccessNew.

parent 8e2e5e13
......@@ -98,8 +98,9 @@ static void SlaveSeek( input_thread_t *p_input );
static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta );
static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta );
static char *InputGetExtraFiles( input_thread_t *p_input,
const char *psz_access, const char *psz_path );
static void InputGetExtraFiles( input_thread_t *p_input,
int *pi_list, char ***pppsz_list,
const char *psz_access, const char *psz_path );
static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
int i_new, input_attachment_t **pp_new );
......@@ -2482,27 +2483,55 @@ static int InputSourceInit( input_thread_t *p_input,
var_Set( p_input, "can-seek", val );
}
/* TODO (maybe)
* do not let stream_AccessNew access input-list
* but give it a list of access ? */
/* */
int i_input_list;
char **ppsz_input_list;
TAB_INIT( i_input_list, ppsz_input_list );
/* On master stream only, use input-list */
if( &p_input->p->input == in )
{
char *psz_list;
char *psz_parser;
psz_list =
psz_parser = var_CreateGetNonEmptyString( p_input, "input-list" );
while( psz_parser && *psz_parser )
{
char *p = strchr( psz_parser, ',' );
if( p )
*p++ = '\0';
if( *psz_parser )
{
char *psz_name = strdup( psz_parser );
if( psz_name )
TAB_APPEND( i_input_list, ppsz_input_list, psz_name );
}
psz_parser = p;
}
free( psz_list );
}
/* Autodetect extra files if none specified */
char *psz_input_list = var_CreateGetNonEmptyString( p_input, "input-list" );
if( !psz_input_list )
if( i_input_list <= 0 )
{
char *psz_extra_files = InputGetExtraFiles( p_input, psz_access, psz_path );
if( psz_extra_files )
var_SetString( p_input, "input-list", psz_extra_files );
free( psz_extra_files );
InputGetExtraFiles( p_input, &i_input_list, &ppsz_input_list,
psz_access, psz_path );
}
if( i_input_list > 0 )
TAB_APPEND( i_input_list, ppsz_input_list, NULL );
/* Create the stream_t */
in->p_stream = stream_AccessNew( in->p_access );
/* Restore old value */
if( !psz_input_list )
var_SetString( p_input, "input-list", "" );
free( psz_input_list );
in->p_stream = stream_AccessNew( in->p_access, ppsz_input_list );
if( ppsz_input_list )
{
for( int i = 0; ppsz_input_list[i] != NULL; i++ )
free( ppsz_input_list[i] );
TAB_CLEAN( i_input_list, ppsz_input_list );
}
if( in->p_stream == NULL )
{
......@@ -2875,22 +2904,26 @@ static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_atta
* InputGetExtraFiles
* Autodetect extra input list
*****************************************************************************/
static char *InputGetExtraFiles( input_thread_t *p_input,
const char *psz_access, const char *psz_path )
static void InputGetExtraFiles( input_thread_t *p_input,
int *pi_list, char ***pppsz_list,
const char *psz_access, const char *psz_path )
{
char *psz_list = NULL;
int i_list;
char **ppsz_list;
TAB_INIT( i_list, ppsz_list );
if( ( psz_access && *psz_access && strcmp( psz_access, "file" ) ) || !psz_path )
return NULL;
goto exit;
const char *psz_ext = strrchr( psz_path, '.' );
if( !psz_ext || strcmp( psz_ext, ".001" ) )
return NULL;
goto exit;
char *psz_file = strdup( psz_path );
if( !psz_file )
return NULL;
goto exit;
/* Try to list .xyz files */
for( int i = 2; i < 999; i++ )
......@@ -2900,30 +2933,20 @@ static char *InputGetExtraFiles( input_thread_t *p_input,
snprintf( psz_ext, 5, ".%.3d", i );
if( utf8_stat( psz_file, &st )
|| !S_ISREG( st.st_mode ) || !st.st_size )
if( utf8_stat( psz_file, &st ) ||
!S_ISREG( st.st_mode ) || !st.st_size )
continue;
msg_Dbg( p_input, "Detected extra file `%s'", psz_file );
if( psz_list )
{
char *psz_old = psz_list;
/* FIXME how to handle file with ',' ?*/
if( asprintf( &psz_list, "%s,%s", psz_old, psz_file ) < 0 )
{
psz_list = psz_old;
break;
}
}
else
{
psz_list = strdup( psz_file );
}
char *psz_tmp = strdup( psz_file );
if( psz_tmp )
TAB_APPEND( i_list, ppsz_list, psz_tmp );
}
free( psz_file );
return psz_list;
exit:
*pi_list = i_list;
*pppsz_list = ppsz_list;
}
......
......@@ -266,7 +266,7 @@ stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
return NULL;
}
if( !( p_res = stream_AccessNew( p_access ) ) )
if( !( p_res = stream_AccessNew( p_access, NULL ) ) )
{
access_Delete( p_access );
return NULL;
......@@ -276,16 +276,15 @@ stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
return p_res;
}
stream_t *stream_AccessNew( access_t *p_access )
stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list )
{
stream_t *s = stream_CommonNew( VLC_OBJECT(p_access) );
stream_sys_t *p_sys;
char *psz_list = NULL;
if( !s )
return NULL;
s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) );
s->p_sys = p_sys = malloc( sizeof( *p_sys ) );
if( !p_sys )
{
stream_CommonDelete( s );
......@@ -317,67 +316,54 @@ stream_t *stream_AccessNew( access_t *p_access )
p_sys->stat.i_seek_count = 0;
p_sys->stat.i_seek_time = 0;
p_sys->i_list = 0;
p_sys->list = 0;
TAB_INIT( p_sys->i_list, p_sys->list );
p_sys->i_list_index = 0;
p_sys->p_list_access = 0;
p_sys->p_list_access = NULL;
/* Get the additional list of inputs if any (for concatenation) */
if( (psz_list = var_CreateGetString( s, "input-list" )) && *psz_list )
if( ppsz_list && ppsz_list[0] )
{
access_entry_t *p_entry = malloc( sizeof(access_entry_t) );
if( p_entry == NULL )
access_entry_t *p_entry = malloc( sizeof(*p_entry) );
if( !p_entry )
goto error;
char *psz_name, *psz_parser = psz_name = psz_list;
p_sys->p_list_access = p_access;
p_entry->i_size = p_access->info.i_size;
p_entry->psz_path = strdup( p_access->psz_path );
if( p_entry->psz_path == NULL )
if( !p_entry->psz_path )
{
free( p_entry );
goto error;
}
p_sys->p_list_access = p_access;
TAB_APPEND( p_sys->i_list, p_sys->list, p_entry );
msg_Dbg( p_access, "adding file `%s', (%"PRId64" bytes)",
p_entry->psz_path, p_access->info.i_size );
while( psz_name && *psz_name )
for( int i = 0; ppsz_list[i] != NULL; i++ )
{
psz_parser = strchr( psz_name, ',' );
if( psz_parser ) *psz_parser = 0;
char *psz_name = strdup( ppsz_list[i] );
psz_name = strdup( psz_name );
if( psz_name )
{
access_t *p_tmp = access_New( p_access, p_access->psz_access,
"", psz_name );
if( !psz_name )
break;
if( !p_tmp )
{
psz_name = psz_parser;
if( psz_name ) psz_name++;
continue;
}
access_t *p_tmp = access_New( p_access,
p_access->psz_access, "", psz_name );
if( !p_tmp )
continue;
msg_Dbg( p_access, "adding file `%s', (%"PRId64" bytes)",
psz_name, p_tmp->info.i_size );
msg_Dbg( p_access, "adding file `%s', (%"PRId64" bytes)",
psz_name, p_tmp->info.i_size );
p_entry = malloc( sizeof(access_entry_t) );
if( p_entry == NULL )
goto error;
p_entry = malloc( sizeof(*p_entry) );
if( p_entry )
{
p_entry->i_size = p_tmp->info.i_size;
p_entry->psz_path = psz_name;
TAB_APPEND( p_sys->i_list, p_sys->list, p_entry );
access_Delete( p_tmp );
}
psz_name = psz_parser;
if( psz_name ) psz_name++;
access_Delete( p_tmp );
}
}
FREENULL( psz_list );
/* Peek */
p_sys->i_peek = 0;
......@@ -464,7 +450,6 @@ error:
while( p_sys->i_list > 0 )
free( p_sys->list[--(p_sys->i_list)] );
free( p_sys->list );
free( psz_list );
free( s->p_sys );
vlc_object_detach( s );
stream_CommonDelete( s );
......
......@@ -44,14 +44,35 @@ struct stream_text_t
stream_t *stream_CommonNew( vlc_object_t * );
void stream_CommonDelete( stream_t * );
/* */
stream_t *stream_AccessNew( access_t *p_access );
/**
* This function creates a stream_t from a provided access_t.
*
* An optional NULL terminated list of file may be provided. The content
* of these extra files will be concatenated after to the main access.
*
* XXX ppsz_list is treated as const (I failed to avoid a warning when
* using const keywords for pointer of pointers)
*/
stream_t *stream_AccessNew( access_t *p_access, char **ppsz_list );
/* */
/**
* This function creates a new stream_t filter.
*
* You must release it using stream_Delete unless it is used as a
* source to another filter.
*/
stream_t *stream_FilterNew( stream_t *p_source,
const char *psz_stream_filter );
/* */
/**
* This function creates a chain of filters:
* - first, automatic probed stream filters are inserted.
* - then, optional user filters (configured by psz_chain) are inserted.
* - finaly, an optional record filter is inserted if b_record is true.
*
* You must release the returned value using stream_Delete unless it is used as a
* source to another filter.
*/
stream_t *stream_FilterChainNew( stream_t *p_source,
const char *psz_chain,
bool b_record );
......
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