X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Fplaylist%2Fpls.c;h=6c308319cc01a2decfc0bcb2af000e49afb91460;hb=80bd0c5d39ba8ac1c52f747da6d2b18a4e20ff7f;hp=c0427eb47ef4c3dad1ff601958cf5293a9ab080b;hpb=75c556adcbc9c2ef2b9f075f09c4f1706f20bd0e;p=vlc diff --git a/modules/demux/playlist/pls.c b/modules/demux/playlist/pls.c index c0427eb47e..6c308319cc 100644 --- a/modules/demux/playlist/pls.c +++ b/modules/demux/playlist/pls.c @@ -1,25 +1,25 @@ /***************************************************************************** * pls.c : PLS playlist format import ***************************************************************************** - * Copyright (C) 2004 the VideoLAN team + * Copyright (C) 2004 VLC authors and VideoLAN * $Id$ * * Authors: Clément Stenac * Authors: Sigmund Augdal Helberg * - * 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 - * the Free Software Foundation; either version 2 of the License, or + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -43,7 +43,6 @@ struct demux_sys_t * Local prototypes *****************************************************************************/ static int Demux( demux_t *p_demux); -static int Control( demux_t *p_demux, int i_query, va_list args ); /***************************************************************************** * Import_PLS: main import function @@ -79,7 +78,6 @@ void Close_PLS( vlc_object_t *p_this ) static int Demux( demux_t *p_demux ) { - mtime_t i_duration = -1; char *psz_name = NULL; char *psz_line; char *psz_mrl = NULL; @@ -87,12 +85,12 @@ static int Demux( demux_t *p_demux ) char *psz_key; char *psz_value; int i_item = -1; - int i_new_item = 0; - int i_key_length; input_item_t *p_input; input_item_t *p_current_input = GetCurrentItem(p_demux); + input_item_node_t *p_subitems = input_item_node_Create( p_current_input ); + while( ( psz_line = stream_ReadLine( p_demux->s ) ) ) { if( !strncasecmp( psz_line, "[playlist]", sizeof("[playlist]")-1 ) || @@ -110,7 +108,6 @@ static int Demux( demux_t *p_demux ) } else { - msg_Warn( p_demux, "invalid line in pls file" ); free( psz_line ); continue; } @@ -126,43 +123,29 @@ static int Demux( demux_t *p_demux ) free( psz_line); continue; } + /* find the number part of of file1, title1 or length1 etc */ - i_key_length = strlen( psz_key ); - if( i_key_length >= 4 ) /* Ref1 type case */ - { - i_new_item = atoi( psz_key + 3 ); - if( i_new_item == 0 && i_key_length >= 5 ) /* file1 type case */ - { - i_new_item = atoi( psz_key + 4 ); - if( i_new_item == 0 && i_key_length >= 6 ) /* title1 type case */ - { - i_new_item = atoi( psz_key + 5 ); - if( i_new_item == 0 && i_key_length >= 7 ) /* length1 type case */ - { - i_new_item = atoi( psz_key + 6 ); - } - } - } - } - if( i_new_item == 0 ) + int i_new_item; + if( sscanf( psz_key, "%*[^0-9]%d", &i_new_item ) != 1 ) { msg_Warn( p_demux, "couldn't find number of items" ); free( psz_line ); continue; } + if( i_item == -1 ) - { i_item = i_new_item; - } - /* we found a new item, insert the previous */ - if( i_item != i_new_item ) + else if( i_item != i_new_item ) { + /* we found a new item, insert the previous */ if( psz_mrl ) { - p_input = input_item_New( p_demux, psz_mrl, psz_name ); + p_input = input_item_New( psz_mrl, psz_name ); input_item_CopyOptions( p_current_input, p_input ); - input_item_AddSubItem( p_current_input, p_input ); + input_item_node_AppendItem( p_subitems, p_input ); vlc_gc_decref( p_input ); + free( psz_mrl_orig ); + psz_mrl_orig = psz_mrl = NULL; } else { @@ -170,10 +153,9 @@ static int Demux( demux_t *p_demux ) } free( psz_name ); psz_name = NULL; - i_duration = -1; i_item = i_new_item; - i_new_item = 0; } + if( !strncasecmp( psz_key, "file", sizeof("file") -1 ) || !strncasecmp( psz_key, "Ref", sizeof("Ref") -1 ) ) { @@ -184,12 +166,7 @@ static int Demux( demux_t *p_demux ) if( !strncasecmp( psz_key, "Ref", sizeof("Ref") -1 ) ) { if( !strncasecmp( psz_mrl, "http://", sizeof("http://") -1 ) ) - { - psz_mrl++; - psz_mrl[0] = 'm'; - psz_mrl[1] = 'm'; - psz_mrl[2] = 's'; - } + memcpy( psz_mrl, "mmsh", 4 ); } } else if( !strncasecmp( psz_key, "title", sizeof("title") -1 ) ) @@ -198,13 +175,7 @@ static int Demux( demux_t *p_demux ) psz_name = strdup( psz_value ); } else if( !strncasecmp( psz_key, "length", sizeof("length") -1 ) ) - { - i_duration = atoi( psz_value ); - if( i_duration != -1 ) - { - i_duration *= 1000000; - } - } + /* duration in seconds */; else { msg_Warn( p_demux, "unknown key found in pls file: %s", psz_key ); @@ -214,12 +185,11 @@ static int Demux( demux_t *p_demux ) /* Add last object */ if( psz_mrl ) { - p_input = input_item_New( p_demux, psz_mrl, psz_name ); + p_input = input_item_New( psz_mrl, psz_name ); input_item_CopyOptions( p_current_input, p_input ); - input_item_AddSubItem( p_current_input, p_input ); + input_item_node_AppendItem( p_subitems, p_input ); vlc_gc_decref( p_input ); free( psz_mrl_orig ); - psz_mrl = NULL; } else { @@ -228,12 +198,8 @@ static int Demux( demux_t *p_demux ) free( psz_name ); psz_name = NULL; + input_item_node_PostAndDelete( p_subitems ); + vlc_gc_decref(p_current_input); return 0; /* Needed for correct operation of go back */ } - -static int Control( demux_t *p_demux, int i_query, va_list args ) -{ - VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args); - return VLC_EGENERIC; -}