/***************************************************************************** * Demux: The important stuff *****************************************************************************/ static int Demux( demux_t *p_demux ) { playlist_t *p_playlist; char *psz_line; playlist_item_t *p_current; vlc_bool_t b_play; p_playlist = (playlist_t *) vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( !p_playlist ) { msg_Err( p_demux, "can't find playlist" ); return -1; } b_play = E_(FindItem)( p_demux, p_playlist, &p_current ); playlist_ItemToNode( p_playlist, p_current ); p_current->input.i_type = ITEM_TYPE_PLAYLIST; while( (psz_line = stream_ReadLine( p_demux->s )) ) { playlist_item_t *p_item; char **ppsz_options = NULL; int i, i_options = 0; char *psz_name = NULL; if( !ParseLine( psz_line, &psz_name, &ppsz_options, &i_options ) ) { free( psz_line ); continue; } EnsureUTF8( psz_name ); p_item = playlist_ItemNew( p_playlist, "dvb:", psz_name ); for( i = 0; i< i_options; i++ ) { EnsureUTF8( ppsz_options[i] ); playlist_ItemAddOption( p_item, ppsz_options[i] ); } playlist_NodeAddItem( p_playlist, p_item, p_current->pp_parents[0]->i_view, p_current, PLAYLIST_APPEND, PLAYLIST_END ); /* We need to declare the parents of the node as the * * same of the parent's ones */ playlist_CopyParents( p_current, p_item ); vlc_input_item_CopyOptions( &p_current->input, &p_item->input ); while( i_options-- ) free( ppsz_options[i_options] ); if( ppsz_options ) free( ppsz_options ); free( psz_line ); } /* Go back and play the playlist */ if( b_play && p_playlist->status.p_item && p_playlist->status.p_item->i_children > 0 ) { playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_playlist->status.i_view, p_playlist->status.p_item, p_playlist->status.p_item->pp_children[0] ); } vlc_object_release( p_playlist ); return VLC_SUCCESS; }
static int Demux( demux_t *p_demux ) { mtime_t i_duration = -1; char *psz_name = NULL; char *psz_line; char *psz_mrl = NULL; char *psz_key; char *psz_value; playlist_t *p_playlist; int i_position; int i_item = -1; int i_new_item = 0; int i_key_length; playlist_item_t *p_parent; vlc_bool_t b_play; p_playlist = (playlist_t *) vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( !p_playlist ) { msg_Err( p_demux, "can't find playlist" ); return -1; } b_play = E_(FindItem)( p_demux, p_playlist, &p_parent ); p_parent->input.i_type = ITEM_TYPE_PLAYLIST; /* Change the item to a node */ if( p_parent->i_children == -1) { playlist_ItemToNode( p_playlist,p_parent ); } while( ( psz_line = stream_ReadLine( p_demux->s ) ) ) { if( !strncasecmp( psz_line, "[playlist]", sizeof("[playlist]")-1 ) ) { free( psz_line ); continue; } psz_key = psz_line; psz_value = strchr( psz_line, '=' ); if( psz_value ) { *psz_value='\0'; psz_value++; } else { msg_Warn( p_demux, "invalid line in pls file" ); free( psz_line ); continue; } if( !strcasecmp( psz_key, "version" ) ) { msg_Dbg( p_demux, "pls file version: %s", psz_value ); 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 >= 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 ) { 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 ) { if( psz_mrl ) { playlist_item_t *p_item = playlist_ItemNew( p_playlist, psz_mrl, psz_name ); playlist_NodeAddItem( p_playlist,p_item, p_parent->pp_parents[0]->i_view, p_parent, PLAYLIST_APPEND, PLAYLIST_END ); playlist_CopyParents( p_parent, p_item ); if( i_duration != -1 ) { //playlist_SetDuration( p_playlist, i_position, i_duration ); } i_position++; free( psz_mrl ); psz_mrl = NULL; vlc_input_item_CopyOptions( &p_parent->input, &p_item->input ); } else { msg_Warn( p_demux, "no file= part found for item %d", i_item ); } if( psz_name ) { 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 ) ) { psz_mrl = E_(ProcessMRL)( psz_value, p_demux->p_sys->psz_prefix ); } else if( !strncasecmp( psz_key, "title", sizeof("title") -1 ) ) { 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; } } else { msg_Warn( p_demux, "unknown key found in pls file: %s", psz_key ); } free( psz_line ); } /* Add last object */ if( psz_mrl ) { playlist_item_t *p_item = playlist_ItemNew( p_playlist, psz_mrl, psz_name ); playlist_NodeAddItem( p_playlist,p_item, p_parent->pp_parents[0]->i_view, p_parent, PLAYLIST_APPEND, PLAYLIST_END ); playlist_CopyParents( p_parent, p_item ); if( i_duration != -1 ) { //playlist_SetDuration( p_playlist, i_position, i_duration ); } free( psz_mrl ); psz_mrl = NULL; vlc_input_item_CopyOptions( &p_parent->input, &p_item->input ); } else { msg_Warn( p_demux, "no file= part found for item %d", i_item ); } if( psz_name ) { free( psz_name ); psz_name = NULL; } if( b_play && p_playlist->status.p_item && p_playlist->status.p_item->i_children > 0 ) { playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_playlist->status.i_view, p_playlist->status.p_item, p_playlist->status.p_item->pp_children[0] ); } vlc_object_release( p_playlist ); return VLC_SUCCESS; }