Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

m3u.c

00001 /*****************************************************************************
00002  * m3u.c: a meta demux to parse pls, m3u, asx et b4s playlists
00003  *****************************************************************************
00004  * Copyright (C) 2001-2004 the VideoLAN team
00005  * $Id: m3u.c 12836 2005-10-15 13:23:08Z sigmunau $
00006  *
00007  * Authors: Sigmund Augdal Helberg <[email protected]>
00008  *          Gildas Bazin <[email protected]>
00009  *          Clément Stenac <[email protected]>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027  * Preamble
00028  *****************************************************************************/
00029 #include <stdlib.h>                                      /* malloc(), free() */
00030 
00031 #include <vlc/vlc.h>
00032 #include <vlc/input.h>
00033 #include <vlc_playlist.h>
00034 
00035 /*****************************************************************************
00036  * Constants and structures
00037  *****************************************************************************/
00038 #define MAX_LINE 8192
00039 
00040 #define TYPE_UNKNOWN 0
00041 #define TYPE_M3U 1
00042 #define TYPE_ASX 2
00043 #define TYPE_HTML 3
00044 #define TYPE_PLS 4
00045 #define TYPE_B4S 5
00046 #define TYPE_WMP 6
00047 #define TYPE_RTSP 7
00048 
00049 struct demux_sys_t
00050 {
00051     int i_type;                                   /* playlist type (m3u/asx) */
00052 };
00053 
00054 /*****************************************************************************
00055  * Local prototypes
00056  *****************************************************************************/
00057 static int  Activate  ( vlc_object_t * );
00058 static void Deactivate( vlc_object_t * );
00059 static int  Demux     ( demux_t * );
00060 static int  Control   ( demux_t *, int, va_list );
00061 
00062 /*****************************************************************************
00063  * Module descriptor
00064  *****************************************************************************/
00065 vlc_module_begin();
00066     set_category( CAT_INPUT );
00067     set_subcategory( SUBCAT_INPUT_DEMUX );
00068     set_description( _("Playlist metademux") );
00069     set_capability( "demux2", 5 );
00070     set_callbacks( Activate, Deactivate );
00071     add_shortcut( "m3u" );
00072     add_shortcut( "asx" );
00073     add_shortcut( "html" );
00074     add_shortcut( "pls" );
00075     add_shortcut( "b4s" );
00076 vlc_module_end();
00077 
00078 /*****************************************************************************
00079  * Activate: initializes m3u demux structures
00080  *****************************************************************************/
00081 static int Activate( vlc_object_t * p_this )
00082 {
00083     demux_t *p_demux = (demux_t *)p_this;
00084     char    *psz_ext;
00085     int     i_type  = TYPE_UNKNOWN;
00086     int     i_type2 = TYPE_UNKNOWN;
00087 
00088     p_demux->pf_control = Control;
00089     p_demux->pf_demux = Demux;
00090 
00091     /* Check for m3u/asx file extension or if the demux has been forced */
00092     psz_ext = strrchr ( p_demux->psz_path, '.' );
00093 
00094     if( ( psz_ext && !strcasecmp( psz_ext, ".m3u") ) ||
00095         /* a .ram file can contain a single rtsp link */
00096         ( psz_ext && !strcasecmp( psz_ext, ".ram") ) ||
00097         ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "m3u") ) )
00098     {
00099         i_type = TYPE_M3U;
00100     }
00101     else if( ( psz_ext && !strcasecmp( psz_ext, ".asx") ) ||
00102              ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "asx") ) )
00103     {
00104         i_type = TYPE_ASX;
00105     }
00106     else if( ( psz_ext && !strcasecmp( psz_ext, ".html") ) ||
00107              ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "html") ) )
00108     {
00109         i_type = TYPE_HTML;
00110     }
00111     else if( ( psz_ext && !strcasecmp( psz_ext, ".pls") ) ||
00112              ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "pls") ) )
00113     {
00114         i_type = TYPE_PLS;
00115     }
00116     else if( ( psz_ext && !strcasecmp( psz_ext, ".b4s") ) ||
00117              ( p_demux->psz_demux && !strcmp(p_demux->psz_demux, "b4s") ) )
00118     {
00119         i_type = TYPE_B4S;
00120     }
00121 
00122     /* we had no luck looking at the file extention, so we have a look
00123      * at the content. This is useful for .asp, .php and similar files
00124      * that are actually html. Also useful for some asx files that have
00125      * another extension */
00126     /* We double check for file != m3u as some asx are just m3u file */
00127     if( i_type != TYPE_M3U )
00128     {
00129         char *p_peek;
00130         int i_size = stream_Peek( p_demux->s, (uint8_t **)&p_peek, MAX_LINE );
00131         i_size -= sizeof("[Reference]") - 1;
00132 
00133         if( i_size > 0 )
00134         {
00135             while( i_size &&
00136                    strncasecmp(p_peek, "[playlist]", sizeof("[playlist]") - 1)
00137                    && strncasecmp( p_peek, "[Reference]", sizeof("[Reference]") - 1 )
00138                    && strncasecmp( p_peek, "<html>", sizeof("<html>") - 1 )
00139                    && strncasecmp( p_peek, "<asx", sizeof("<asx") - 1 )
00140                    && strncasecmp( p_peek, "rtsptext", sizeof("rtsptext") - 1 )
00141                    && strncasecmp( p_peek, "<?xml", sizeof("<?xml") -1 ) )
00142             {
00143                 p_peek++;
00144                 i_size--;
00145             }
00146             if( !i_size )
00147             {
00148                 ;
00149             }
00150             else if( !strncasecmp( p_peek, "[playlist]", sizeof("[playlist]") -1 ) )
00151             {
00152                 i_type2 = TYPE_PLS;
00153             }
00154             else if( !strncasecmp( p_peek, "[Reference]", sizeof("[Reference]") -1 ) )
00155             {
00156                 i_type2 = TYPE_WMP;
00157             }
00158             else if( !strncasecmp( p_peek, "<html>", sizeof("<html>") -1 ) )
00159             {
00160                 i_type2 = TYPE_HTML;
00161             }
00162             else if( !strncasecmp( p_peek, "<asx", sizeof("<asx") -1 ) )
00163             {
00164                 i_type2 = TYPE_ASX;
00165             }
00166             else if( !strncasecmp( p_peek, "rtsptext", sizeof("rtsptext") -1 ) )
00167             {
00168                 i_type2 = TYPE_RTSP;
00169             }
00170 #if 0
00171             else if( !strncasecmp( p_peek, "<?xml", sizeof("<?xml") -1 ) )
00172             {
00173                 i_type2 = TYPE_B4S;
00174             }
00175 #endif
00176         }
00177     }
00178     if( i_type == TYPE_UNKNOWN && i_type2 == TYPE_UNKNOWN)
00179     {
00180         return VLC_EGENERIC;
00181     }
00182     if( i_type  != TYPE_UNKNOWN && i_type2 == TYPE_UNKNOWN )
00183     {
00184         i_type = TYPE_M3U;
00185     }
00186     else
00187     {
00188         i_type = i_type2;
00189     }
00190 
00191     /* Allocate p_m3u */
00192     p_demux->p_sys = malloc( sizeof( demux_sys_t ) );
00193     p_demux->p_sys->i_type = i_type;
00194     msg_Dbg( p_this, "Playlist type: %d - %d", i_type, i_type2 );
00195 
00196     return VLC_SUCCESS;
00197 }
00198 
00199 /*****************************************************************************
00200  * Deactivate: frees unused data
00201  *****************************************************************************/
00202 static void Deactivate( vlc_object_t *p_this )
00203 {
00204     demux_t *p_demux = (demux_t *)p_this;
00205     free( p_demux->p_sys );
00206 }
00207 
00208 /*****************************************************************************
00209  * XMLSpecialChars: Handle the special chars in a XML file.
00210  * ***************************************************************************/
00211 static void XMLSpecialChars ( char *str )
00212 {
00213     char *src = str;
00214     char *dst = str;
00215 
00216     while( *src )
00217     {
00218         if( *src == '&' )
00219         {
00220             if( !strncasecmp( src, "&#xe0;", 6 ) ) *dst++ = 'à';
00221             else if( !strncasecmp( src, "&#xee;", 6 ) ) *dst++ = 'î';
00222             else if( !strncasecmp( src, "&apos;", 6 ) ) *dst++ = '\'';
00223             else if( !strncasecmp( src, "&#xe8;", 6 ) ) *dst++ = 'è';
00224             else if( !strncasecmp( src, "&#xe9;", 6 ) ) *dst++ = 'é';
00225             else if( !strncasecmp( src, "&#xea;", 6 ) ) *dst++ = 'ê';
00226             else
00227             {
00228                 *dst++ = '?';
00229             }
00230             src += 6;
00231         }
00232         else
00233         {
00234             *dst++ = *src++;
00235         }
00236     }
00237 
00238     *dst = '\0';
00239 }
00240 
00241 /*****************************************************************************
00242  * ParseLine: read a "line" from the file and add any entries found
00243  * to the playlist. Returns:
00244  * 0 if nothing was found
00245  * 1 if a URI was found (it is then copied in psz_data)
00246  * 2 if a name was found (  "  )
00247  *
00248  * XXX psz_data has the same length that psz_line so no problem if you don't
00249  * expand it
00250  *    psz_line is \0 terminated
00251  *****************************************************************************/
00252 static int ParseLine( demux_t *p_demux, char *psz_line, char *psz_data,
00253                       vlc_bool_t *pb_done )
00254 {
00255     demux_sys_t *p_m3u = p_demux->p_sys;
00256     char        *psz_bol, *psz_name;
00257 
00258     psz_bol = psz_line;
00259     *pb_done = VLC_FALSE;
00260 
00261     /* Remove unnecessary tabs or spaces at the beginning of line */
00262     while( *psz_bol == ' ' || *psz_bol == '\t' ||
00263            *psz_bol == '\n' || *psz_bol == '\r' )
00264     {
00265         psz_bol++;
00266     }
00267 
00268     if( p_m3u->i_type == TYPE_M3U )
00269     {
00270         /* Check for comment line */
00271         if( *psz_bol == '#' )
00272         {
00273             while( *psz_bol &&
00274                    strncasecmp( psz_bol, "EXTINF:",
00275                                 sizeof("EXTINF:") - 1 ) &&
00276                    strncasecmp( psz_bol, "EXTVLCOPT:",
00277                                 sizeof("EXTVLCOPT:") - 1 ) ) psz_bol++;
00278 
00279             if( !*psz_bol ) return 0;
00280 
00281             if( !strncasecmp( psz_bol, "EXTINF:", sizeof("EXTINF:") - 1 ) )
00282             {
00283                 psz_bol = strchr( psz_bol, ',' );
00284                 if ( !psz_bol ) return 0;
00285                 psz_bol++;
00286 
00287                 /* From now, we have a name line */
00288                 strcpy( psz_data , psz_bol );
00289                 return 2;
00290             }
00291             else
00292             {
00293                 psz_bol = strchr( psz_bol, ':' );
00294                 if ( !psz_bol ) return 0;
00295                 psz_bol++;
00296 
00297                 strcpy( psz_data , psz_bol );
00298                 return 3;
00299             }
00300         }
00301         /* If we don't have a comment, the line is directly the URI */
00302     }
00303     else if( p_m3u->i_type == TYPE_PLS )
00304     {
00305         /* We are dealing with .pls files from shoutcast
00306          * We are looking for lines like "File1=http://..." */
00307         if( !strncasecmp( psz_bol, "File", sizeof("File") - 1 ) )
00308         {
00309             psz_bol += sizeof("File") - 1;
00310             psz_bol = strchr( psz_bol, '=' );
00311             if ( !psz_bol ) return 0;
00312             psz_bol++;
00313         }
00314         else
00315         {
00316             return 0;
00317         }
00318     }
00319     else if( p_m3u->i_type == TYPE_WMP )
00320     {
00321         /* We are dealing with some weird WMP stream playlist format
00322          * Hurray for idiotic M$. Lines look like: "Ref1=http://..." */
00323         if( !strncasecmp( psz_bol, "Ref", sizeof("Ref") - 1 ) )
00324         {
00325             psz_bol += sizeof("Ref") - 1;
00326             psz_bol = strchr( psz_bol, '=' );
00327             if ( !psz_bol ) return 0;
00328             psz_bol++;
00329             if( !strncasecmp( psz_bol, "http://", sizeof("http://") -1 ) )
00330             {
00331                 psz_bol[0] = 'm'; psz_bol[1] = 'm'; psz_bol[2] = 's'; psz_bol[3] = 'h';
00332             }
00333         }
00334         else
00335         {
00336             return 0;
00337         }
00338     }
00339     else if( p_m3u->i_type == TYPE_ASX )
00340     {
00341         /* We are dealing with ASX files.
00342          * We are looking for "<ref href=" xml markups that
00343          * begins with "mms://", "http://" or "file://" */
00344         char *psz_eol;
00345 
00346         while( *psz_bol &&
00347                strncasecmp( psz_bol, "ref", sizeof("ref") - 1 ) )
00348             psz_bol++;
00349 
00350         if( !*psz_bol ) return 0;
00351 
00352         while( *psz_bol &&
00353                strncasecmp( psz_bol, "href", sizeof("href") - 1 ) )
00354             psz_bol++;
00355 
00356         if( !*psz_bol ) return 0;
00357 
00358         while( *psz_bol &&
00359                strncasecmp( psz_bol, "mms://",
00360                             sizeof("mms://") - 1 ) &&
00361                strncasecmp( psz_bol, "mmsu://",
00362                             sizeof("mmsu://") - 1 ) &&
00363                strncasecmp( psz_bol, "mmst://",
00364                             sizeof("mmst://") - 1 ) &&
00365                strncasecmp( psz_bol, "http://",
00366                             sizeof("http://") - 1 ) &&
00367                strncasecmp( psz_bol, "file://",
00368                             sizeof("file://") - 1 ) )
00369             psz_bol++;
00370 
00371         if( !*psz_bol ) return 0;
00372 
00373         psz_eol = strchr( psz_bol, '"');
00374         if( !psz_eol )
00375           return 0;
00376 
00377         *psz_eol = '\0';
00378     }
00379     else if( p_m3u->i_type == TYPE_HTML )
00380     {
00381         /* We are dealing with a html file with embedded
00382          * video.  We are looking for "<param name="filename"
00383          * value=" html markups that begin with "http://" */
00384         char *psz_eol;
00385 
00386         while( *psz_bol &&
00387                strncasecmp( psz_bol, "param", sizeof("param") - 1 ) )
00388             psz_bol++;
00389 
00390         if( !*psz_bol ) return 0;
00391 
00392         while( *psz_bol &&
00393                strncasecmp( psz_bol, "filename", sizeof("filename") - 1 ) )
00394             psz_bol++;
00395 
00396         if( !*psz_bol ) return 0;
00397 
00398         while( *psz_bol &&
00399                strncasecmp( psz_bol, "http://",
00400                             sizeof("http://") - 1 ) )
00401             psz_bol++;
00402 
00403         if( !*psz_bol ) return 0;
00404 
00405         psz_eol = strchr( psz_bol, '"');
00406         if( !psz_eol )
00407           return 0;
00408 
00409         *psz_eol = '\0';
00410 
00411     }
00412     else if( p_m3u->i_type == TYPE_B4S )
00413     {
00414 
00415         char *psz_eol;
00416 
00417         msg_Dbg( p_demux, "b4s line=%s", psz_line );
00418         /* We are dealing with a B4S file from Winamp 3 */
00419 
00420         /* First, search for name *
00421          * <Name>Blabla</Name> */
00422 
00423         if( strstr ( psz_bol, "<Name>" ) )
00424         {
00425             /* We have a name */
00426             while ( *psz_bol &&
00427                     strncasecmp( psz_bol,"Name",sizeof("Name") -1 ) )
00428                 psz_bol++;
00429 
00430             if( !*psz_bol ) return 0;
00431 
00432             psz_bol = psz_bol + 5 ;
00433             /* We are now at the beginning of the name */
00434 
00435             if( !psz_bol ) return 0;
00436 
00437 
00438             psz_eol = strchr(psz_bol, '<' );
00439             if( !psz_eol) return 0;
00440 
00441             *psz_eol='\0';
00442 
00443             XMLSpecialChars( psz_bol );
00444 
00445             strcpy( psz_data, psz_bol );
00446             return 2;
00447         }
00448         else if( strstr( psz_bol, "</entry>" ) || strstr( psz_bol, "</Entry>" ))
00449         {
00450             *pb_done = VLC_TRUE;
00451             return 0;
00452         }
00453 
00454         /* We are looking for <entry Playstring="blabla"> */
00455 
00456         while( *psz_bol &&
00457                strncasecmp( psz_bol,"Playstring",sizeof("Playstring") -1 ) )
00458             psz_bol++;
00459 
00460         if( !*psz_bol ) return 0;
00461 
00462         psz_bol = strchr( psz_bol, '=' );
00463         if ( !psz_bol ) return 0;
00464 
00465         psz_bol += 2;
00466 
00467         psz_eol= strchr(psz_bol, '"');
00468         if( !psz_eol ) return 0;
00469 
00470         *psz_eol= '\0';
00471 
00472         /* Handle the XML special characters */
00473         XMLSpecialChars( psz_bol );
00474     }
00475     else if( p_m3u->i_type == TYPE_RTSP )
00476     {
00477         /* We are dealing with rtsptext reference files
00478          * Ignore anthying that doesn't start with rtsp://..." */
00479         if( strncasecmp( psz_bol, "rtsp://", sizeof("rtsp://") - 1 ) )
00480         /* ignore */ return 0;
00481     }
00482     else
00483     {
00484         msg_Warn( p_demux, "unknown file type" );
00485         return 0;
00486     }
00487 
00488     /* empty line */
00489     if ( !*psz_bol ) return 0;
00490 
00491     /*
00492      * From now on, we know we've got a meaningful line
00493      */
00494 
00495     /* check for a protocol name */
00496     /* for URL, we should look for "://"
00497      * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
00498      * we should look for ":"
00499      * so we end up looking simply for ":"*/
00500     /* PB: on some file systems, ':' are valid characters though*/
00501     psz_name = psz_bol;
00502     while( *psz_name && *psz_name!=':' )
00503     {
00504         psz_name++;
00505     }
00506 #ifdef WIN32
00507     if ( *psz_name && ( psz_name == psz_bol + 1 ) )
00508     {
00509         /* if it is not an URL,
00510          * as it is unlikely to be an MRL (PB: if it is ?)
00511          * it should be an absolute file name with the drive letter */
00512         if ( *(psz_name+1) == '/' )/* "*:/" */
00513         {
00514             if ( *(psz_name+2) != '/' )/* not "*://" */
00515                 while ( *psz_name ) *psz_name++;/* so now (*psz_name==0) */
00516         }
00517         else while ( *psz_name ) *psz_name++;/* "*:*"*/
00518     }
00519 #endif
00520 
00521     /* if the line doesn't specify a protocol name,
00522      * check if the line has an absolute or relative path */
00523 #ifndef WIN32
00524     if( !*psz_name && *psz_bol != '/' )
00525          /* If this line doesn't begin with a '/' */
00526 #else
00527     if( !*psz_name
00528             && *psz_bol!='/'
00529             && *psz_bol!='\\'
00530             && *(psz_bol+1)!=':' )
00531          /* if this line doesn't begin with
00532           *  "/" or "\" or "*:" or "*:\" or "*:/" or "\\" */
00533 #endif
00534     {
00535         /* assume the path is relative to the path of the m3u file. */
00536         char *psz_path = strdup( p_demux->psz_path );
00537 
00538 #ifndef WIN32
00539         psz_name = strrchr( psz_path, '/' );
00540 #else
00541         psz_name = strrchr( psz_path, '\\' );
00542         if ( ! psz_name ) psz_name = strrchr( psz_path, '/' );
00543 #endif
00544         if( psz_name ) *psz_name = '\0';
00545         else *psz_path = '\0';
00546 #ifndef WIN32
00547         psz_name = malloc( strlen(psz_path) + strlen(psz_bol) + 2 );
00548         sprintf( psz_name, "%s/%s", psz_path, psz_bol );
00549 #else
00550         if ( *psz_path != '\0' )
00551         {
00552             psz_name = malloc( strlen(psz_path) + strlen(psz_bol) + 2 );
00553             sprintf( psz_name, "%s\\%s", psz_path, psz_bol );
00554         }
00555         else psz_name = strdup( psz_bol );
00556 #endif
00557         free( psz_path );
00558     }
00559     else
00560     {
00561         psz_name = strdup( psz_bol );
00562     }
00563 
00564     strcpy(psz_data, psz_name ) ;
00565 
00566     free( psz_name );
00567 
00568     if( p_m3u->i_type != TYPE_B4S )
00569     {
00570        *pb_done = VLC_TRUE;
00571     }
00572 
00573     return 1;
00574 }
00575 
00576 static void ProcessLine ( demux_t *p_demux, playlist_t *p_playlist,
00577                           playlist_item_t *p_parent,
00578                           char *psz_line, char **ppsz_uri, char **ppsz_name,
00579                           int *pi_options, char ***pppsz_options,
00580                           vlc_bool_t b_flush )
00581 {
00582     char psz_data[MAX_LINE];
00583     vlc_bool_t b_done;
00584 
00585     switch( ParseLine( p_demux, psz_line, psz_data, &b_done ) )
00586     {
00587         case 1:
00588             if( *ppsz_uri ) free( *ppsz_uri );
00589             *ppsz_uri = strdup( psz_data );
00590             break;
00591         case 2:
00592             if( *ppsz_name ) free( *ppsz_name );
00593             *ppsz_name = strdup( psz_data );
00594             break;
00595         case 3:
00596             (*pi_options)++;
00597             *pppsz_options = realloc( *pppsz_options,
00598                                       sizeof(char *) * *pi_options );
00599             (*pppsz_options)[*pi_options - 1] = strdup( psz_data );
00600             break;
00601         case 0:
00602         default:
00603             break;
00604     }
00605 
00606     if( (b_done || b_flush) && *ppsz_uri )
00607     {
00608         playlist_item_t *p_item =
00609             playlist_ItemNew( p_playlist, *ppsz_uri, *ppsz_name );
00610         int i;
00611 
00612         for( i = 0; i < *pi_options; i++ )
00613         {
00614             playlist_ItemAddOption( p_item, *pppsz_options[i] );
00615         }
00616 
00617         playlist_NodeAddItem( p_playlist, p_item,
00618                               p_parent->pp_parents[0]->i_view,
00619                               p_parent, PLAYLIST_APPEND, PLAYLIST_END );
00620 
00621         /* We need to declare the parents of the node as the
00622          * same of the parent's ones */
00623         playlist_CopyParents( p_parent, p_item );
00624 
00625         vlc_input_item_CopyOptions( &p_parent->input, &p_item->input );
00626 
00627         if( *ppsz_name ) free( *ppsz_name ); *ppsz_name = NULL;
00628         free( *ppsz_uri ); *ppsz_uri  = NULL;
00629 
00630         for( ; *pi_options; (*pi_options)-- )
00631         {
00632             free( (*pppsz_options)[*pi_options - 1] );
00633             if( *pi_options == 1 ) free( *pppsz_options );
00634         }
00635         *pppsz_options = NULL;
00636     }
00637 }
00638 
00639 static vlc_bool_t FindItem( demux_t *p_demux, playlist_t *p_playlist,
00640                             playlist_item_t **pp_item )
00641 {
00642      vlc_bool_t b_play;
00643 
00644      if( &p_playlist->status.p_item->input ==
00645          ((input_thread_t *)p_demux->p_parent)->input.p_item )
00646      {
00647          msg_Dbg( p_playlist, "starting playlist playback" );
00648          *pp_item = p_playlist->status.p_item;
00649          b_play = VLC_TRUE;
00650      }
00651      else
00652      {
00653          input_item_t *p_current =
00654              ((input_thread_t*)p_demux->p_parent)->input.p_item;
00655          *pp_item = playlist_LockItemGetByInput( p_playlist, p_current );
00656 
00657          if( !*pp_item )
00658              msg_Dbg( p_playlist, "unable to find item in playlist");
00659 
00660          b_play = VLC_FALSE;
00661      }
00662 
00663      return b_play;
00664 }
00665 
00666 /*****************************************************************************
00667  * Demux: reads and demuxes data packets
00668  *****************************************************************************
00669  * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
00670  *****************************************************************************/
00671 static int Demux( demux_t *p_demux )
00672 {
00673     demux_sys_t   *p_m3u = p_demux->p_sys;
00674 
00675     char          psz_line[MAX_LINE];
00676     char          p_buf[MAX_LINE], eol_tok;
00677     int           i_size, i_bufpos, i_linepos = 0;
00678     vlc_bool_t    b_discard = VLC_FALSE;
00679 
00680     char          *psz_name = NULL;
00681     char          *psz_uri  = NULL;
00682     int           i_options = 0;
00683     char          **ppsz_options = NULL;
00684 
00685     playlist_t      *p_playlist;
00686     playlist_item_t *p_parent;
00687     vlc_bool_t      b_play;
00688 
00689     p_playlist = (playlist_t *) vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST,
00690                                                  FIND_ANYWHERE );
00691     if( !p_playlist )
00692     {
00693         msg_Err( p_demux, "can't find playlist" );
00694         return -1;
00695     }
00696 
00697     b_play = FindItem( p_demux, p_playlist, &p_parent );
00698     playlist_ItemToNode( p_playlist, p_parent );
00699     p_parent->input.i_type = ITEM_TYPE_PLAYLIST;
00700 
00701     /* Depending on wether we are dealing with an m3u/asf file, the end of
00702      * line token will be different */
00703     if( p_m3u->i_type == TYPE_ASX || p_m3u->i_type == TYPE_HTML )
00704         eol_tok = '>';
00705     else
00706         eol_tok = '\n';
00707 
00708     while( ( i_size = stream_Read( p_demux->s, p_buf, MAX_LINE ) ) )
00709     {
00710         i_bufpos = 0;
00711 
00712         while( i_size )
00713         {
00714             /* Build a line < MAX_LINE */
00715             while( p_buf[i_bufpos] != eol_tok && i_size )
00716             {
00717                 if( i_linepos == MAX_LINE || b_discard == VLC_TRUE )
00718                 {
00719                     /* line is bigger than MAX_LINE, discard it */
00720                     i_linepos = 0;
00721                     b_discard = VLC_TRUE;
00722                 }
00723                 else
00724                 {
00725                     if ( eol_tok != '\n' || p_buf[i_bufpos] != '\r' )
00726                     {
00727                         psz_line[i_linepos] = p_buf[i_bufpos];
00728                         i_linepos++;
00729                     }
00730                 }
00731 
00732                 i_size--; i_bufpos++;
00733             }
00734 
00735             /* Check if we need more data */
00736             if( !i_size ) continue;
00737 
00738             i_size--; i_bufpos++;
00739             b_discard = VLC_FALSE;
00740 
00741             /* Check for empty line */
00742             if( !i_linepos ) continue;
00743 
00744             psz_line[i_linepos] = '\0';
00745             i_linepos = 0;
00746 
00747             ProcessLine( p_demux, p_playlist, p_parent,
00748                          psz_line, &psz_uri, &psz_name,
00749                          &i_options, &ppsz_options, VLC_FALSE );
00750         }
00751     }
00752 
00753     if( i_linepos && b_discard != VLC_TRUE && eol_tok == '\n' )
00754     {
00755         psz_line[i_linepos] = '\0';
00756 
00757         ProcessLine( p_demux, p_playlist, p_parent,
00758                      psz_line, &psz_uri, &psz_name,
00759                      &i_options, &ppsz_options, VLC_TRUE );
00760     }
00761 
00762     if( psz_uri ) free( psz_uri );
00763     if( psz_name ) free( psz_name );
00764     for( ; i_options; i_options-- )
00765     {
00766         free( ppsz_options[i_options - 1] );
00767         if( i_options == 1 ) free( ppsz_options );
00768     }
00769 
00770     /* Go back and play the playlist */
00771     if( b_play )
00772     {
00773         playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
00774                           p_playlist->status.i_view,
00775                           p_playlist->status.p_item, NULL );
00776     }
00777 
00778     vlc_object_release( p_playlist );
00779 
00780     return 0;
00781 }
00782 
00783 static int Control( demux_t *p_demux, int i_query, va_list args )
00784 {
00785     return VLC_EGENERIC;
00786 }

Generated on Tue Dec 20 10:14:32 2005 for vlc-0.8.4a by  doxygen 1.4.2