Commit a01f44d5 authored by gbazin's avatar gbazin

* modules/demux/playlist, src/input/stream.c: fixed a shitload of bugs in...

* modules/demux/playlist, src/input/stream.c: fixed a shitload of bugs in playlist demuxers + simplified a lot.
parent b1ddf918
......@@ -37,8 +37,6 @@
struct demux_sys_t
{
char *psz_prefix;
char **ppsz_options;
int i_options;
};
/*****************************************************************************
......@@ -59,7 +57,6 @@ int Import_M3U( vlc_object_t *p_this )
if( stream_Peek( p_demux->s , &p_peek, 7 ) < 7 )
{
msg_Err( p_demux, "cannot peek" );
return VLC_EGENERIC;
}
psz_ext = strrchr ( p_demux->psz_path, '.' );
......@@ -69,14 +66,14 @@ int Import_M3U( vlc_object_t *p_this )
;
}
else if( ( psz_ext && !strcasecmp( psz_ext, ".m3u") ) ||
( psz_ext && !strcasecmp( psz_ext, ".ram") ) || /* a .ram file can contain a single rtsp link */
( psz_ext && !strcasecmp( psz_ext, ".ram") ) ||
/* A .ram file can contain a single rtsp link */
( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "m3u") ) )
{
;
}
else
{
msg_Warn(p_demux, "m3u import module discarded");
return VLC_EGENERIC;
}
msg_Dbg( p_demux, "found valid M3U playlist file");
......@@ -91,9 +88,6 @@ int Import_M3U( vlc_object_t *p_this )
}
p_demux->p_sys->psz_prefix = FindPrefix( p_demux );
p_demux->p_sys->ppsz_options = NULL;
p_demux->p_sys->i_options = 0 ;
return VLC_SUCCESS;
}
......@@ -103,26 +97,23 @@ int Import_M3U( vlc_object_t *p_this )
void Close_M3U( vlc_object_t *p_this )
{
demux_t *p_demux = (demux_t *)p_this;
if( p_demux->p_sys->psz_prefix )
{
free( p_demux->p_sys->psz_prefix );
}
if( p_demux->p_sys->psz_prefix ) free( p_demux->p_sys->psz_prefix );
free( p_demux->p_sys );
}
static int Demux( demux_t *p_demux )
{
mtime_t i_duration = -1;
char *psz_name = NULL;
char *psz_line;
char *psz_parse;
char *psz_duration;
char *psz_mrl;
playlist_t *p_playlist;
int i_position;
char *psz_option = NULL;
int i;
playlist_t *p_playlist;
char *psz_line;
int i_position;
char *psz_name = NULL;
mtime_t i_duration = -1;
char **ppsz_options = NULL;
int i_options = 0;
vlc_bool_t b_cleanup = VLC_FALSE;
p_playlist = (playlist_t *) vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST,
FIND_PARENT );
......@@ -132,89 +123,101 @@ static int Demux( demux_t *p_demux )
return -1;
}
vlc_mutex_lock( &p_playlist->object_lock );
p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
i_position = p_playlist->i_index + 1;
while( ( psz_line = stream_ReadLine( p_demux->s ) ) )
vlc_mutex_unlock( &p_playlist->object_lock );
psz_line = stream_ReadLine( p_demux->s );
while( psz_line )
{
char *psz_parse = psz_line;
/* Skip leading tabs and spaces */
while( *psz_line == ' ' || *psz_line == '\t' ||
*psz_line == '\n' || *psz_line == '\r' )
{
psz_line++;
}
while( *psz_parse == ' ' || *psz_parse == '\t' ||
*psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++;
if( *psz_line == '#' )
if( *psz_parse == '#' )
{
/* parse extra info */
psz_parse = psz_line;
while( *psz_parse &&
strncasecmp( psz_parse, "EXTINF:", sizeof("EXTINF:") - 1 ) &&
strncasecmp( psz_parse, "EXTVLCOPT:",sizeof("EXTVLCOPT:") -1))
psz_parse++;
if( *psz_parse )
/* Parse extra info */
/* Skip leading tabs and spaces */
while( *psz_parse == ' ' || *psz_parse == '\t' ||
*psz_parse == '\n' || *psz_parse == '\r' ||
*psz_parse == '#' ) psz_parse++;
if( !*psz_parse ) goto error;
if( !strncasecmp( psz_parse, "EXTINF:", sizeof("EXTINF:") -1 ) )
{
if( !strncasecmp( psz_parse, "EXTINF:", sizeof("EXTINF:") - 1 ) )
/* Extended info */
char *psz_duration;
psz_parse += sizeof("EXTINF:") - 1;
while( *psz_parse == '\t' || *psz_parse == ' ' ) psz_parse++;
psz_duration = psz_parse;
psz_parse = strchr( psz_parse, ',' );
if( psz_parse )
{
psz_parse += sizeof("EXTINF:") - 1;
while( *psz_parse == '\t' || *psz_parse == ' ' )
psz_parse++;
psz_duration = psz_parse;
psz_parse = strchr( psz_parse, ',' );
if ( psz_parse )
{
i_duration *= 1000000;
*psz_parse = '\0';
psz_parse++;
psz_name = strdup( psz_parse );
i_duration = atoi( psz_duration );
if( i_duration != -1 )
{
i_duration *= 1000000;
}
}
}
else
{
/* Option line */
psz_parse = strchr( psz_parse, ':' );
if( !psz_parse ) return 0;
*psz_parse = '\0';
psz_parse++;
psz_name = strdup( psz_parse );
i_duration = atoi( psz_duration );
if( i_duration != -1 ) i_duration *= 1000000;
}
}
else if( !strncasecmp( psz_parse, "EXTVLCOPT:",
sizeof("EXTVLCOPT:") -1 ) )
psz_option = strdup( psz_parse );
INSERT_ELEM( p_demux->p_sys->ppsz_options,
p_demux->p_sys->i_options,
p_demux->p_sys->i_options,
{
/* VLC Option */
char *psz_option;
psz_parse += sizeof("EXTVLCOPT:") -1;
if( !*psz_parse ) goto error;
psz_option = strdup( psz_parse );
if( psz_option )
INSERT_ELEM( ppsz_options, i_options, i_options,
psz_option );
}
}
}
else
else if( *psz_parse )
{
psz_mrl = ProcessMRL( psz_line, p_demux->p_sys->psz_prefix );
char *psz_mrl =
ProcessMRL( psz_parse, p_demux->p_sys->psz_prefix );
b_cleanup = VLC_TRUE;
if( !psz_mrl ) goto error;
playlist_AddExt( p_playlist, psz_mrl, psz_name,
PLAYLIST_INSERT, i_position, i_duration,
(const char **)p_demux->p_sys->ppsz_options,
p_demux->p_sys->i_options );
for( i = 0 ; i < p_demux->p_sys->i_options ; i++)
{
char *psz_option = p_demux->p_sys->ppsz_options[i];
REMOVE_ELEM( p_demux->p_sys->ppsz_options,
p_demux->p_sys->i_options,
i );
if( psz_option ) free( psz_option );
}
free( psz_mrl );
PLAYLIST_INSERT, i_position, i_duration,
(const char **)ppsz_options, i_options );
i_position++;
free( psz_mrl );
}
error:
/* Fetch another line */
free( psz_line );
psz_line = stream_ReadLine( p_demux->s );
if( !psz_line ) b_cleanup = VLC_TRUE;
if( b_cleanup )
{
/* Cleanup state */
while( i_options-- ) free( ppsz_options[i_options] );
if( ppsz_options ) free( ppsz_options );
ppsz_options = NULL; i_options = 0;
if( psz_name ) free( psz_name );
psz_name = NULL;
i_duration = -1;
if( psz_name )
{
free( psz_name );
psz_name = NULL;
}
b_cleanup = VLC_FALSE;
}
free( psz_line);
}
vlc_object_release( p_playlist );
return VLC_SUCCESS;
}
......
......@@ -41,15 +41,16 @@ vlc_module_begin();
set_callbacks( Import_Old , NULL );
add_submodule();
set_description( _("M3U playlist import") );
add_shortcut( "m3u-open" );
set_capability( "demux2" , 10 );
set_callbacks( Import_M3U , Close_M3U );
set_description( _("M3U playlist import") );
add_shortcut( "m3u-open" );
set_capability( "demux2" , 10 );
set_callbacks( Import_M3U , Close_M3U );
add_submodule();
set_description( _("PLS playlist import") );
add_shortcut( "pls-open" );
set_capability( "demux2" , 10 );
set_callbacks( Import_PLS , Close_PLS );
set_description( _("PLS playlist import") );
add_shortcut( "pls-open" );
set_capability( "demux2" , 10 );
set_callbacks( Import_PLS , Close_PLS );
vlc_module_end();
......@@ -66,10 +67,11 @@ char *FindPrefix( demux_t *p_demux )
psz_name = strrchr( psz_path, '/' );
#else
psz_name = strrchr( psz_path, '\\' );
if ( ! psz_name ) psz_name = strrchr( psz_path, '/' );
if( !psz_name ) psz_name = strrchr( psz_path, '/' );
#endif
if( psz_name ) *psz_name = '\0';
if( psz_name ) psz_name[1] = '\0';
else *psz_path = '\0';
return psz_path;
}
......@@ -79,63 +81,24 @@ char *FindPrefix( demux_t *p_demux )
*/
char *ProcessMRL( char *psz_mrl, char *psz_prefix )
{
char *psz_name;
/* check for a protocol name */
/* for URL, we should look for "://"
/* Check for a protocol name.
* for URL, we should look for "://"
* for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
* we should look for ":"
* so we end up looking simply for ":"*/
/* PB: on some file systems, ':' are valid characters though*/
psz_name = psz_mrl;
while( *psz_name && *psz_name!=':' )
{
psz_name++;
}
#ifdef WIN32
if ( *psz_name && ( psz_name == psz_mrl + 1 ) )
{
/* if it is not an URL,
* as it is unlikely to be an MRL (PB: if it is ?)
* it should be an absolute file name with the drive letter */
if ( *(psz_name+1) == '/' )/* "*:/" */
{
if ( *(psz_name+2) != '/' )/* not "*://" */
while ( *psz_name ) *psz_name++;/* so now (*psz_name==0) */
}
else while ( *psz_name ) *psz_name++;/* "*:*"*/
}
#endif
* we should look for ":", so we end up looking simply for ":"
* PB: on some file systems, ':' are valid characters though */
/* if the line doesn't specify a protocol name,
* check if the line has an absolute or relative path */
#ifndef WIN32
if( !*psz_name && *psz_mrl != '/' )
/* If this line doesn't begin with a '/' */
#else
if( !*psz_name
&& *psz_mrl!='/'
&& *psz_mrl!='\\'
&& *(psz_mrl+1)!=':' )
/* if this line doesn't begin with
* "/" or "\" or "*:" or "*:\" or "*:/" or "\\" */
#endif
{
#ifndef WIN32
psz_name = malloc( strlen(psz_prefix) + strlen(psz_mrl) + 2 );
sprintf( psz_name, "%s/%s", psz_prefix, psz_mrl );
#else
if ( *psz_prefix != '\0' )
{
psz_name = malloc( strlen(psz_prefix) + strlen(psz_mrl) + 2 );
sprintf( psz_name, "%s\\%s", psz_prefix, psz_mrl );
}
else psz_name = strdup( psz_mrl );
#endif
}
else
{
psz_name = strdup( psz_mrl );
}
return psz_name;
}
/* Simple cases first */
if( !psz_mrl || !*psz_mrl ) return NULL;
if( !psz_prefix || !*psz_prefix ) return strdup( psz_mrl );
/* Check if the line specifies an absolute path */
if( *psz_mrl == '/' || *psz_mrl == '\\' ) return strdup( psz_mrl );
/* Check if the line specifies an mrl/url
* (and on win32, contains a drive letter) */
if( strchr( psz_mrl, ':' ) ) return strdup( psz_mrl );
/* This a relative path, prepend the prefix */
asprintf( &psz_mrl, "%s%s", psz_prefix, psz_mrl );
return psz_mrl;
}
......@@ -1152,76 +1152,65 @@ static void AStreamPrebufferStream( stream_t *s )
* \param s Stream handle to read from
* \return A null-terminated string. This must be freed,
*/
#define STREAM_PROBE_LINE 1024
#define STREAM_PROBE_LINE 2048
#define STREAM_LINE_MAX (2048*100)
char *stream_ReadLine( stream_t *s )
{
char *p_line = NULL;
int i_line = 0;
char *p_line = NULL;
int i_line = 0, i_read = 0;
for( ;; )
while( i_read < STREAM_LINE_MAX )
{
char *psz_lf, *psz_cr;
char *psz_eol;
uint8_t *p_data;
int i_data;
int i_read;
int i_data;
/* Probe new data */
i_data = stream_Peek( s, &p_data, STREAM_PROBE_LINE );
if( i_data <= 0 ) break; /* No more data */
if( i_data <= 0 ) /* No data */
goto exit;
/* See if there is a '\n' */
psz_lf = memchr( p_data, '\n', __MAX( i_data - 1, 1 ) );
psz_cr = memchr( p_data, '\r', __MAX( i_data - 1, 1 ) );
if( psz_lf && !psz_cr && p_data[i_data-1] == '\r' )
/* Check if there is an EOL */
if( ( psz_eol = memchr( p_data, '\n', i_data ) ) )
{
psz_cr = &p_data[i_data-1];
}
if( psz_cr && !psz_lf && p_data[i_data-1] == '\n' )
{
psz_lf = &p_data[i_data-1];
}
if( psz_lf || psz_cr )
{
char *psz;
if( !psz_lf )
psz = psz_cr;
else if( !psz_cr )
psz = psz_lf;
else
psz = __MIN( psz_cr, psz_lf );
i_data = (psz_eol - (char *)p_data) + 1;
p_line = realloc( p_line, i_line + i_data + 1 );
i_data = stream_Read( s, &p_line[i_line], i_data );
if( i_data <= 0 ) break; /* Hmmm */
i_line += (i_data - 1);
i_read += i_data;
/* Remove trailing LF/CR */
while( stream_Peek( s, &p_data, 1 ) == 1 &&
i_read < STREAM_LINE_MAX )
{
if( p_data[0] != '\n' && p_data[0] != '\r' ) break;
i_read = (psz - (char*)p_data) + 1;
p_line = realloc( p_line, i_read + 1 ); /* +1 for easy \0 append */
i_read = stream_Read( s, &p_line[i_line], i_read );
if( i_read > 0 )
i_line += i_read;
i_data = stream_Read( s, NULL, 1 );
if( i_data <= 0 ) break; /* Hmmm */
i_read += i_data;
}
goto exit;
/* We have our line */
break;
}
/* Read data (+1 for easy \0 append) */
p_line = realloc( p_line, i_line + STREAM_PROBE_LINE + 1 );
i_read = stream_Read( s, &p_line[i_line], STREAM_PROBE_LINE );
if( i_read <= 0 )
goto exit;
i_line += i_read;
i_data = stream_Read( s, &p_line[i_line], STREAM_PROBE_LINE );
if( i_data <= 0 ) break; /* Hmmm */
i_line += i_data;
i_read += i_data;
}
exit:
while( i_line > 0 &&
( p_line[i_line-1] == '\n' || p_line[i_line-1] == '\r' ) )
{
i_line--;
}
/* Remove trailing CR */
while( i_line > 0 && p_line[i_line-1] == '\r' ) i_line--;
if( i_line > 0 )
{
p_line[i_line] = '\0';
return p_line;
}
return p_line;
if( p_line ) free( p_line );
return NULL;
}
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