[vlc-devel] [PATCH 2/4] old http: Replace ICY metadata stream parsing
Marvin Scholz
epirat07 at gmail.com
Wed Nov 1 05:16:34 CET 2017
Remove the ICY metadata stream parsing and instead set the metaint
for the ICY stream_filter to handle the ICY parsing/filtering.
---
modules/access/http.c | 112 ++------------------------------------------------
1 file changed, 4 insertions(+), 108 deletions(-)
diff --git a/modules/access/http.c b/modules/access/http.c
index 1ace2db902..2471521da8 100644
--- a/modules/access/http.c
+++ b/modules/access/http.c
@@ -119,11 +119,8 @@ struct access_sys_t
char *psz_location;
bool b_icecast;
- int i_icy_meta;
- uint64_t i_icy_offset;
char *psz_icy_name;
char *psz_icy_genre;
- char *psz_icy_title;
uint64_t offset;
uint64_t size;
@@ -170,11 +167,8 @@ static int Open( vlc_object_t *p_this )
p_sys->psz_referrer = NULL;
p_sys->psz_username = NULL;
p_sys->psz_password = NULL;
- p_sys->i_icy_meta = 0;
- p_sys->i_icy_offset = 0;
p_sys->psz_icy_name = NULL;
p_sys->psz_icy_genre = NULL;
- p_sys->psz_icy_title = NULL;
p_sys->b_has_size = false;
p_sys->offset = 0;
p_sys->size = 0;
@@ -391,7 +385,6 @@ static void Close( vlc_object_t *p_this )
free( p_sys->psz_icy_name );
free( p_sys->psz_icy_genre );
- free( p_sys->psz_icy_title );
free( p_sys->psz_user_agent );
free( p_sys->psz_referrer );
@@ -417,7 +410,6 @@ static int ReadData( stream_t *p_access, int *pi_read,
* Read: Read up to i_len bytes from the http connection and place in
* p_buffer. Return the actual number of bytes read
*****************************************************************************/
-static int ReadICYMeta( stream_t *p_access );
static ssize_t Read( stream_t *p_access, void *p_buffer, size_t i_len )
{
access_sys_t *p_sys = p_access->p_sys;
@@ -429,20 +421,6 @@ static ssize_t Read( stream_t *p_access, void *p_buffer, size_t i_len )
if( i_len == 0 )
return 0;
- if( p_sys->i_icy_meta > 0 && p_sys->offset - p_sys->i_icy_offset > 0 )
- {
- int i_next = p_sys->i_icy_meta -
- (p_sys->offset - p_sys->i_icy_offset) % p_sys->i_icy_meta;
-
- if( i_next == p_sys->i_icy_meta )
- {
- if( ReadICYMeta( p_access ) )
- return 0;
- }
- if( i_len > (size_t)i_next )
- i_len = i_next;
- }
-
if( ReadData( p_access, &i_read, p_buffer, i_len ) )
return 0;
@@ -469,82 +447,6 @@ static ssize_t Read( stream_t *p_access, void *p_buffer, size_t i_len )
return i_read;
}
-static int ReadICYMeta( stream_t *p_access )
-{
- access_sys_t *p_sys = p_access->p_sys;
-
- uint8_t buffer;
- char *p, *psz_meta;
- int i_read;
-
- /* Read meta data length */
- if( ReadData( p_access, &i_read, &buffer, 1 ) )
- return VLC_EGENERIC;
- if( i_read != 1 )
- return VLC_EGENERIC;
- const int i_size = buffer << 4;
- /* msg_Dbg( p_access, "ICY meta size=%u", i_size); */
-
- psz_meta = malloc( i_size + 1 );
- for( i_read = 0; i_read < i_size; )
- {
- int i_tmp;
- if( ReadData( p_access, &i_tmp, (uint8_t *)&psz_meta[i_read], i_size - i_read ) || i_tmp <= 0 )
- {
- free( psz_meta );
- return VLC_EGENERIC;
- }
- i_read += i_tmp;
- }
- psz_meta[i_read] = '\0'; /* Just in case */
-
- /* msg_Dbg( p_access, "icy-meta=%s", psz_meta ); */
-
- /* Now parse the meta */
- /* Look for StreamTitle= */
- p = strcasestr( (char *)psz_meta, "StreamTitle=" );
- if( p )
- {
- p += strlen( "StreamTitle=" );
- if( *p == '\'' || *p == '"' )
- {
- char closing[] = { p[0], ';', '\0' };
- char *psz = strstr( &p[1], closing );
- if( !psz )
- psz = strchr( &p[1], ';' );
-
- if( psz ) *psz = '\0';
- }
- else
- {
- char *psz = strchr( &p[1], ';' );
- if( psz ) *psz = '\0';
- }
-
- if( !p_sys->psz_icy_title ||
- strcmp( p_sys->psz_icy_title, &p[1] ) )
- {
- free( p_sys->psz_icy_title );
- char *psz_tmp = strdup( &p[1] );
- p_sys->psz_icy_title = EnsureUTF8( psz_tmp );
- if( !p_sys->psz_icy_title )
- free( psz_tmp );
-
- msg_Dbg( p_access, "New Icy-Title=%s", p_sys->psz_icy_title );
- input_thread_t *p_input = p_access->p_input;
- if( p_input )
- {
- input_item_t *p_input_item = input_GetItem( p_access->p_input );
- if( p_input_item )
- input_item_SetMeta( p_input_item, vlc_meta_NowPlaying, p_sys->psz_icy_title );
- }
- }
- }
- free( psz_meta );
-
- return VLC_SUCCESS;
-}
-
/*****************************************************************************
* Seek: close and re-open a connection at the right place
*****************************************************************************/
@@ -636,17 +538,13 @@ static int Connect( stream_t *p_access )
free( p_sys->psz_icy_genre );
free( p_sys->psz_icy_name );
- free( p_sys->psz_icy_title );
vlc_http_auth_Init( &p_sys->auth );
vlc_http_auth_Init( &p_sys->proxy_auth );
p_sys->psz_location = NULL;
p_sys->psz_mime = NULL;
- p_sys->i_icy_meta = 0;
- p_sys->i_icy_offset = 0;
p_sys->psz_icy_name = NULL;
p_sys->psz_icy_genre = NULL;
- p_sys->psz_icy_title = NULL;
p_sys->b_has_size = false;
p_sys->offset = 0;
p_sys->size = 0;
@@ -883,13 +781,11 @@ static int Connect( stream_t *p_access )
else if( !strcasecmp( psz, "Icy-MetaInt" ) )
{
msg_Dbg( p_access, "Icy-MetaInt: %s", p );
- p_sys->i_icy_meta = atoi( p );
- if( p_sys->i_icy_meta < 0 )
- p_sys->i_icy_meta = 0;
- if( p_sys->i_icy_meta > 0 )
+ int icy_meta = atoi( p );
+ if( icy_meta > 0 ) {
p_sys->b_icecast = true;
-
- msg_Warn( p_access, "ICY metaint=%d", p_sys->i_icy_meta );
+ config_PutInt( p_access, "icy-metaint", icy_meta );
+ }
}
else if( !strcasecmp( psz, "Icy-Name" ) )
{
--
2.13.5 (Apple Git-94)
More information about the vlc-devel
mailing list