ram.c
资源名称:vlc-1.0.5.zip [点击查看]
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:17k
源码类别:
midi
开发平台:
Unix_Linux
- /*****************************************************************************
- * ram.c : RAM playlist format import
- *****************************************************************************
- * Copyright (C) 2009 the VideoLAN team
- * $Id: bdcbb5a5f587dc153053f9b2a7b020ce80fdf26d $
- *
- * Authors: Srikanth Raju <srikiraju@gmail.com>
- *
- * 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
- * (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.
- *
- * 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.
- *****************************************************************************/
- /*
- An example:
- rtsp://helixserver.example.com/video1.rm?rpcontextheight=250
- &rpcontextwidth=280&rpcontexturl="http://www.example.com/relatedinfo1.html"
- rtsp://helixserver.example.com/video2.rm?rpurl="http://www.example.com/index.html"
- rtsp://helixserver.example.com/sample1.smil?screensize=full
- rtsp://helixserver.example.com/audio1.rm?start=55&end=1:25
- rtsp://helixserver.example.com/introvid.rm?title="Introduction to Streaming Media
- Production"&author="RealNetworks, Inc."©right="©2001, RealNetworks, Inc."
- rtsp://helixserver.example.com/song1.rm?clipinfo="title=Artist of the Year|artist name=Your Name
- Here|album name=My Debut|genre=Rock|copyright=2001|year=2001|comments=This one really
- knows how to rock!"
- See also:
- http://service.real.com/help/library/guides/realone/IntroGuide/HTML/htmfiles/ramsum.htm
- http://service.real.com/help/library/guides/realone/IntroGuide/HTML/htmfiles/ramfile.htm
- */
- /*****************************************************************************
- * Preamble
- *****************************************************************************/
- #ifdef HAVE_CONFIG_H
- # include "config.h"
- #endif
- #include <vlc_common.h>
- #include <vlc_demux.h>
- #include <vlc_charset.h>
- #include <ctype.h>
- #include "playlist.h"
- struct demux_sys_t
- {
- char *psz_prefix;
- };
- /*****************************************************************************
- * Local prototypes
- *****************************************************************************/
- static int Demux( demux_t *p_demux);
- static int Control( demux_t *p_demux, int i_query, va_list args );
- static void ParseClipInfo( const char * psz_clipinfo, char **ppsz_artist, char **ppsz_title,
- char **ppsz_album, char **ppsz_genre, char **ppsz_year,
- char **ppsz_cdnum, char **ppsz_comments );
- /**
- * Import_RAM: main import function
- * @param p_this: this demux object
- * @return VLC_SUCCESS if everything is okay
- */
- int Import_RAM( vlc_object_t *p_this )
- {
- demux_t *p_demux = (demux_t *)p_this;
- const uint8_t *p_peek;
- CHECK_PEEK( p_peek, 8 );
- if(! demux_IsPathExtension( p_demux, ".ram" ) ||
- demux_IsPathExtension( p_demux, ".rm" ) )
- return VLC_EGENERIC;
- STANDARD_DEMUX_INIT_MSG( "found valid RAM playlist" );
- p_demux->p_sys->psz_prefix = FindPrefix( p_demux );
- return VLC_SUCCESS;
- }
- /**
- * Frees up memory on module close
- * @param p_this: this demux object
- */
- void Close_RAM( vlc_object_t *p_this )
- {
- demux_t *p_demux = (demux_t *)p_this;
- free( p_demux->p_sys->psz_prefix );
- free( p_demux->p_sys );
- }
- /**
- * Returns a UTF8 encoded version of the string
- * @param str: input string
- * @return pointer to UTF8 string
- */
- static inline char *MaybeFromLocaleDup (const char *str)
- {
- if (str == NULL)
- return NULL;
- return IsUTF8 (str) ? strdup (str) : FromLocaleDup (str);
- }
- /**
- * Converts a string to UTF8 encoding
- * @param str: input string
- */
- static inline void MaybeFromLocaleRep (char **str)
- {
- char *const orig_str = *str;
- if ((orig_str != NULL) && !IsUTF8 (orig_str))
- {
- *str = FromLocaleDup (orig_str);
- free (orig_str);
- }
- }
- /**
- * Skips blanks in a given buffer
- * @param s: input string
- * @param i_strlen: length of the buffer
- */
- static const char *SkipBlanks( const char *s, size_t i_strlen )
- {
- while( i_strlen > 0 ) {
- switch( *s )
- {
- case ' ':
- case 't':
- case 'r':
- case 'n':
- --i_strlen;
- ++s;
- break;
- default:
- i_strlen = 0;
- }
- }
- return s;
- }
- /**
- * Converts a time of format hour:minutes:sec.fraction to seconds
- * @param s: input string
- * @param i_strlen: length of the buffer
- * @return time in seconds
- */
- static int ParseTime( const char *s, size_t i_strlen)
- {
- // need to parse hour:minutes:sec.fraction string
- int result = 0;
- int val;
- const char *end = s + i_strlen;
- // skip leading spaces if any
- s = SkipBlanks(s, i_strlen);
- val = 0;
- while( (s < end) && isdigit(*s) )
- {
- int newval = val*10 + (*s - '0');
- if( newval < val )
- {
- // overflow
- val = 0;
- break;
- }
- val = newval;
- ++s;
- }
- result = val;
- s = SkipBlanks(s, end-s);
- if( *s == ':' )
- {
- ++s;
- s = SkipBlanks(s, end-s);
- result = result * 60;
- val = 0;
- while( (s < end) && isdigit(*s) )
- {
- int newval = val*10 + (*s - '0');
- if( newval < val )
- {
- // overflow
- val = 0;
- break;
- }
- val = newval;
- ++s;
- }
- result += val;
- s = SkipBlanks(s, end-s);
- if( *s == ':' )
- {
- ++s;
- s = SkipBlanks(s, end-s);
- result = result * 60;
- val = 0;
- while( (s < end) && isdigit(*s) )
- {
- int newval = val*10 + (*s - '0');
- if( newval < val )
- {
- // overflow
- val = 0;
- break;
- }
- val = newval;
- ++s;
- }
- result += val;
- // TODO: one day, we may need to parse fraction for sub-second resolution
- }
- }
- return result;
- }
- /**
- * Main demux callback function
- * @param p_demux: this demux object
- */
- static int Demux( demux_t *p_demux )
- {
- char *psz_line;
- char *psz_name = NULL;
- char *psz_artist = NULL, *psz_album = NULL, *psz_genre = NULL, *psz_year = NULL;
- char *psz_author = NULL, *psz_title = NULL, *psz_copyright = NULL, *psz_cdnum = NULL, *psz_comments = NULL;
- int i_parsed_duration = 0;
- mtime_t i_duration = -1;
- const char **ppsz_options = NULL;
- int i_options = 0, i_start = 0, i_stop = 0;
- bool b_cleanup = false;
- input_item_t *p_input;
- INIT_PLAYLIST_STUFF;
- psz_line = stream_ReadLine( p_demux->s );
- while( psz_line )
- {
- char *psz_parse = psz_line;
- /* Skip leading tabs and spaces */
- while( *psz_parse == ' ' || *psz_parse == 't' ||
- *psz_parse == 'n' || *psz_parse == 'r' ) psz_parse++;
- if( *psz_parse == '#' )
- {
- /* Ignore comments */
- }
- else if( *psz_parse )
- {
- char *psz_mrl, *psz_option_start, *psz_option_next, *psz_temp_mrl, *psz_option;
- char *psz_param, *psz_value;
- if( !psz_name || !*psz_name )
- {
- /* Default filename as name for relative entries
- TODO: Currently not used. Either remove or use */
- psz_name = MaybeFromLocaleDup( psz_parse );
- }
- /* Get the MRL from the file. Note that this might contain parameters of form ?param1=value1¶m2=value2 in a RAM file */
- psz_mrl = ProcessMRL( psz_parse, p_demux->p_sys->psz_prefix );
- MaybeFromLocaleRep( &psz_mrl );
- b_cleanup = true;
- if ( !psz_mrl ) goto error;
- /* We have the MRL, now we have to check for options and parse them from MRL */
- psz_temp_mrl = strdup( psz_mrl );
- psz_option_start = strchr( psz_temp_mrl, '?' ); /* Look for start of options */
- if( psz_option_start )
- {
- psz_option_start++;
- psz_option_next = psz_option_start;
- while( 1 ) /* Process each option */
- {
- /* Look for end of first option which maybe a & or