/*****************************************************************************
* m3u.c: a meta demux to parse pls, m3u, asx et b4s playlists
*****************************************************************************
- * Copyright (C) 2001 VideoLAN
- * $Id: m3u.c,v 1.21 2003/06/28 19:19:55 fenrir Exp $
+ * Copyright (C) 2001-2004 VideoLAN
+ * $Id$
*
* Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
* Gildas Bazin <gbazin@netcourrier.com>
/*****************************************************************************
* Constants and structures
*****************************************************************************/
-#define MAX_LINE 1024
+#define MAX_LINE 8192
#define TYPE_UNKNOWN 0
#define TYPE_M3U 1
*****************************************************************************/
static int Activate ( vlc_object_t * );
static void Deactivate( vlc_object_t * );
-static int Demux ( input_thread_t * );
+static int Demux ( demux_t * );
+static int Control ( demux_t *, int, va_list );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin();
- set_description( _("playlist metademux") );
- set_capability( "demux", 180 );
+ set_description( _("Playlist metademux") );
+ set_capability( "demux2", 180 );
set_callbacks( Activate, Deactivate );
add_shortcut( "m3u" );
add_shortcut( "asx" );
*****************************************************************************/
static int Activate( vlc_object_t * p_this )
{
- input_thread_t *p_input = (input_thread_t *)p_this;
- char *psz_ext;
- int i_type = TYPE_UNKNOWN;
- int i_type2 = TYPE_UNKNOWN;
+ demux_t *p_demux = (demux_t *)p_this;
+ char *psz_ext;
+ int i_type = TYPE_UNKNOWN;
+ int i_type2 = TYPE_UNKNOWN;
- /* Initialize access plug-in structures. */
- if( p_input->i_mtu == 0 )
- {
- /* Improve speed. */
- p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
- }
-
- p_input->pf_demux = Demux;
- p_input->pf_rewind = NULL;
+ p_demux->pf_control = Control;
+ p_demux->pf_demux = Demux;
/* Check for m3u/asx file extension or if the demux has been forced */
- psz_ext = strrchr ( p_input->psz_name, '.' );
+ psz_ext = strrchr ( p_demux->psz_path, '.' );
if( ( psz_ext && !strcasecmp( psz_ext, ".m3u") ) ||
- ( p_input->psz_demux && !strcmp(p_input->psz_demux, "m3u") ) )
+ /* a .ram file can contain a single rtsp link */
+ ( psz_ext && !strcasecmp( psz_ext, ".ram") ) ||
+ ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "m3u") ) )
{
i_type = TYPE_M3U;
}
else if( ( psz_ext && !strcasecmp( psz_ext, ".asx") ) ||
- ( p_input->psz_demux && !strcmp(p_input->psz_demux, "asx") ) )
+ ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "asx") ) )
{
i_type = TYPE_ASX;
}
else if( ( psz_ext && !strcasecmp( psz_ext, ".html") ) ||
- ( p_input->psz_demux && !strcmp(p_input->psz_demux, "html") ) )
+ ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "html") ) )
{
i_type = TYPE_HTML;
}
else if( ( psz_ext && !strcasecmp( psz_ext, ".pls") ) ||
- ( p_input->psz_demux && !strcmp(p_input->psz_demux, "pls") ) )
+ ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "pls") ) )
{
i_type = TYPE_PLS;
}
else if( ( psz_ext && !strcasecmp( psz_ext, ".b4s") ) ||
- ( p_input->psz_demux && !strcmp(p_input->psz_demux, "b4s") ) )
+ ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "b4s") ) )
{
i_type = TYPE_B4S;
}
/* we had no luck looking at the file extention, so we have a look
* at the content. This is useful for .asp, .php and similar files
- * that are actually html. Also useful for som asx files that have
- * another extention */
+ * that are actually html. Also useful for some asx files that have
+ * another extension */
/* XXX we double check for file != m3u as some asx ... are just m3u file */
if( i_type != TYPE_M3U )
{
- byte_t *p_peek;
- int i_size = input_Peek( p_input, &p_peek, MAX_LINE );
+ uint8_t *p_peek;
+ int i_size = stream_Peek( p_demux->s, &p_peek, MAX_LINE );
i_size -= sizeof("[playlist]") - 1;
- if ( i_size > 0 ) {
- while ( i_size
- && strncasecmp( p_peek, "[playlist]", sizeof("[playlist]") - 1 )
- && strncasecmp( p_peek, "<html>", sizeof("<html>") - 1 )
- && strncasecmp( p_peek, "<asx", sizeof("<asx") - 1 )
- && strncasecmp( p_peek, "<?xml", sizeof("<?xml") -1 ) )
+
+ if( i_size > 0 )
+ {
+ while( i_size &&
+ strncasecmp(p_peek, "[playlist]", sizeof("[playlist]") - 1)
+ && strncasecmp( p_peek, "<html>", sizeof("<html>") - 1 )
+ && strncasecmp( p_peek, "<asx", sizeof("<asx") - 1 )
+ && strncasecmp( p_peek, "<?xml", sizeof("<?xml") -1 ) )
{
p_peek++;
i_size--;
}
- if ( !i_size )
+ if( !i_size )
{
;
}
- else if ( !strncasecmp( p_peek, "[playlist]", sizeof("[playlist]") -1 ) )
+ else if( !strncasecmp( p_peek, "[playlist]", sizeof("[playlist]") -1 ) )
{
i_type2 = TYPE_PLS;
}
- else if ( !strncasecmp( p_peek, "<html>", sizeof("<html>") -1 ) )
+ else if( !strncasecmp( p_peek, "<html>", sizeof("<html>") -1 ) )
{
i_type2 = TYPE_HTML;
}
- else if ( !strncasecmp( p_peek, "<asx", sizeof("<asx") -1 ) )
+ else if( !strncasecmp( p_peek, "<asx", sizeof("<asx") -1 ) )
{
i_type2 = TYPE_ASX;
}
- else if ( !strncasecmp( p_peek, "<?xml", sizeof("<?xml") -1 ) )
+#if 0
+ else if( !strncasecmp( p_peek, "<?xml", sizeof("<?xml") -1 ) )
{
i_type2 = TYPE_B4S;
}
+#endif
}
}
- if ( i_type == TYPE_UNKNOWN && i_type2 == TYPE_UNKNOWN)
+ if( i_type == TYPE_UNKNOWN && i_type2 == TYPE_UNKNOWN)
{
return VLC_EGENERIC;
}
- if ( i_type != TYPE_UNKNOWN && i_type2 == TYPE_UNKNOWN )
+ if( i_type != TYPE_UNKNOWN && i_type2 == TYPE_UNKNOWN )
{
i_type = TYPE_M3U;
}
}
/* Allocate p_m3u */
- p_input->p_demux_data = malloc( sizeof( demux_sys_t ) );
- p_input->p_demux_data->i_type = i_type;
+ p_demux->p_sys = malloc( sizeof( demux_sys_t ) );
+ p_demux->p_sys->i_type = i_type;
return VLC_SUCCESS;
}
*****************************************************************************/
static void Deactivate( vlc_object_t *p_this )
{
- input_thread_t *p_input = (input_thread_t *)p_this;
-
- free( p_input->p_demux_data );
+ demux_t *p_demux = (demux_t *)p_this;
+ free( p_demux->p_sys );
}
/*****************************************************************************
*dst = '\0';
}
-
/*****************************************************************************
* ParseLine: read a "line" from the file and add any entries found
* to the playlist. Returns:
* XXX psz_data has the same length that psz_line so no problem if you don't
* expand it
* psz_line is \0 terminated
- ******************************************************************************/
-static int ParseLine ( input_thread_t *p_input, char *psz_line, char *psz_data, vlc_bool_t *pb_next )
+ *****************************************************************************/
+static int ParseLine( demux_t *p_demux, char *psz_line, char *psz_data,
+ vlc_bool_t *pb_next )
{
- demux_sys_t *p_m3u = p_input->p_demux_data;
-
- char *psz_bol, *psz_name;
+ demux_sys_t *p_m3u = p_demux->p_sys;
+ char *psz_bol, *psz_name;
psz_bol = psz_line;
if( *psz_bol == '#' )
{
while( *psz_bol &&
- strncasecmp( psz_bol, "EXTINF:", sizeof("EXTINF:") - 1 ) )
- psz_bol++;
+ strncasecmp( psz_bol, "EXTINF:",
+ sizeof("EXTINF:") - 1 ) &&
+ strncasecmp( psz_bol, "EXTVLCOPT:",
+ sizeof("EXTVLCOPT:") - 1 ) ) psz_bol++;
+
if( !*psz_bol ) return 0;
- psz_bol = strchr( psz_bol, ',' );
- if ( !psz_bol ) return 0;
- psz_bol++;
- /* From now, we have a name line */
+ if( !strncasecmp( psz_bol, "EXTINF:", sizeof("EXTINF:") - 1 ) )
+ {
+ psz_bol = strchr( psz_bol, ',' );
+ if ( !psz_bol ) return 0;
+ psz_bol++;
- strcpy( psz_data , psz_bol );
- return 2;
+ /* From now, we have a name line */
+ strcpy( psz_data , psz_bol );
+ return 2;
+ }
+ else
+ {
+ psz_bol = strchr( psz_bol, ':' );
+ if ( !psz_bol ) return 0;
+ psz_bol++;
+
+ strcpy( psz_data , psz_bol );
+ return 3;
+ }
}
/* If we don't have a comment, the line is directly the URI */
}
char *psz_eol;
- msg_Dbg( p_input, "b4s line=%s", psz_line );
+ msg_Dbg( p_demux, "b4s line=%s", psz_line );
/* We are dealing with a B4S file from Winamp 3 */
/* First, search for name *
if( strstr ( psz_bol, "<Name>" ) )
{
- msg_Dbg( p_input, "###########<Name>");
/* We have a name */
while ( *psz_bol &&
strncasecmp( psz_bol,"Name",sizeof("Name") -1 ) )
}
else if( strstr( psz_bol, "</entry>" ) || strstr( psz_bol, "</Entry>" ))
{
- msg_Dbg( p_input, "###########<Entry>");
*pb_next = VLC_TRUE;
return 0;
}
}
else
{
- msg_Warn( p_input, "unknown file type" );
+ msg_Warn( p_demux, "unknown file type" );
return 0;
}
/* empty line */
if ( !*psz_bol ) return 0;
- msg_Dbg( p_input, "############Line=%s", psz_bol );
/*
* From now on, we know we've got a meaningful line
*/
#endif
{
/* assume the path is relative to the path of the m3u file. */
- char *psz_path = strdup( p_input->psz_name );
+ char *psz_path = strdup( p_demux->psz_path );
#ifndef WIN32
psz_name = strrchr( psz_path, '/' );
return 1;
}
-static void ProcessLine ( input_thread_t *p_input, playlist_t *p_playlist,
- char *psz_line,
- char **ppsz_uri, char **ppsz_name )
+static void ProcessLine ( demux_t *p_demux, playlist_t *p_playlist,
+ char *psz_line, char **ppsz_uri, char **ppsz_name,
+ int *pi_options, char ***pppsz_options,
+ int *pi_position )
{
char psz_data[MAX_LINE];
vlc_bool_t b_next;
- msg_Dbg( p_input, "ProcessLine(0): name=%s uri=%s ", *ppsz_name, *ppsz_uri );
-
- switch( ParseLine( p_input, psz_line, psz_data, &b_next ) )
+ switch( ParseLine( p_demux, psz_line, psz_data, &b_next ) )
{
case 1:
if( *ppsz_uri )
}
*ppsz_name = strdup( psz_data );
break;
+ case 3:
+ (*pi_options)++;
+ *pppsz_options = realloc( *pppsz_options,
+ sizeof(char *) * *pi_options );
+ (*pppsz_options)[*pi_options - 1] = strdup( psz_data );
+ break;
case 0:
default:
break;
}
- msg_Dbg( p_input, "name=%s uri=%s next=%d", *ppsz_name, *ppsz_uri, b_next );
+
if( b_next && *ppsz_uri )
{
- playlist_AddName( p_playlist,
- *ppsz_name ? *ppsz_name : *ppsz_uri,
- *ppsz_uri,
- PLAYLIST_INSERT, PLAYLIST_END );
- if( *ppsz_name )
+ playlist_AddExt( p_playlist, *ppsz_uri, *ppsz_name,
+ PLAYLIST_INSERT, *pi_position,
+ -1, (const char **)*pppsz_options, *pi_options );
+
+ (*pi_position)++;
+ if( *ppsz_name ) free( *ppsz_name ); *ppsz_name = NULL;
+ free( *ppsz_uri ); *ppsz_uri = NULL;
+
+ for( ; *pi_options; (*pi_options)-- )
{
- free( *ppsz_name );
+ free( (*pppsz_options)[*pi_options - 1] );
+ if( *pi_options == 1 ) free( *pppsz_options );
}
- free( *ppsz_uri );
- *ppsz_name = NULL;
- *ppsz_uri = NULL;
+ *pppsz_options = NULL;
}
- msg_Dbg( p_input, "ProcessLine(1:: name=%s uri=%s ", *ppsz_name, *ppsz_uri );
}
/*****************************************************************************
*****************************************************************************
* Returns -1 in case of error, 0 in case of EOF, 1 otherwise
*****************************************************************************/
-static int Demux ( input_thread_t *p_input )
+static int Demux( demux_t *p_demux )
{
- demux_sys_t *p_m3u = p_input->p_demux_data;
+ demux_sys_t *p_m3u = p_demux->p_sys;
- data_packet_t *p_data;
char psz_line[MAX_LINE];
- char *p_buf, eol_tok;
+ char p_buf[MAX_LINE], eol_tok;
int i_size, i_bufpos, i_linepos = 0;
playlist_t *p_playlist;
vlc_bool_t b_discard = VLC_FALSE;
-
char *psz_name = NULL;
char *psz_uri = NULL;
+ int i_options = 0;
+ char **ppsz_options = NULL;
+
+ int i_position;
- p_playlist = (playlist_t *) vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
+ p_playlist = (playlist_t *) vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( !p_playlist )
{
- msg_Err( p_input, "can't find playlist" );
+ msg_Err( p_demux, "can't find playlist" );
return -1;
}
p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
+ i_position = p_playlist->i_index + 1;
/* Depending on wether we are dealing with an m3u/asf file, the end of
* line token will be different */
else
eol_tok = '\n';
- while( ( i_size = input_SplitBuffer( p_input, &p_data, MAX_LINE ) ) > 0 )
+ while( ( i_size = stream_Read( p_demux->s, p_buf, MAX_LINE ) ) )
{
- i_bufpos = 0; p_buf = p_data->p_payload_start;
+ i_bufpos = 0;
while( i_size )
{
psz_line[i_linepos] = '\0';
i_linepos = 0;
- ProcessLine( p_input, p_playlist, psz_line, &psz_uri, &psz_name );
+ ProcessLine( p_demux, p_playlist, psz_line, &psz_uri, &psz_name,
+ &i_options, &ppsz_options, &i_position );
}
-
- input_DeletePacket( p_input->p_method_data, p_data );
}
if ( i_linepos && b_discard != VLC_TRUE && eol_tok == '\n' )
{
psz_line[i_linepos] = '\0';
- ProcessLine( p_input, p_playlist, psz_line, &psz_uri, &psz_name );
- /* is there a pendding uri without b_next */
+ ProcessLine( p_demux, p_playlist, psz_line, &psz_uri, &psz_name,
+ &i_options, &ppsz_options, &i_position );
+
+ /* Is there a pendding uri without b_next */
if( psz_uri )
{
- playlist_Add( p_playlist, psz_uri, PLAYLIST_INSERT, PLAYLIST_END );
+ playlist_AddExt( p_playlist, psz_uri, psz_name,
+ PLAYLIST_INSERT, i_position,
+ -1, (const char **)ppsz_options, i_options );
}
}
- if( psz_uri )
+ if( psz_uri ) free( psz_uri );
+ if( psz_name ) free( psz_name );
+ for( ; i_options; i_options-- )
{
- free( psz_uri );
- }
- if( psz_name )
- {
- free( psz_name );
+ free( ppsz_options[i_options - 1] );
+ if( i_options == 1 ) free( ppsz_options );
}
vlc_object_release( p_playlist );
return 0;
}
+
+static int Control( demux_t *p_demux, int i_query, va_list args )
+{
+ return VLC_EGENERIC;
+}