+static int ReadICYMeta( access_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 */
+ i_read = net_Read( p_access, p_sys->fd, p_sys->p_vs, &buffer, 1,
+ VLC_TRUE );
+ if( i_read <= 0 )
+ return VLC_EGENERIC;
+ if( buffer == 0 )
+ return VLC_SUCCESS;
+
+ i_read = buffer << 4;
+ /* msg_Dbg( p_access, "ICY meta size=%u", i_read); */
+
+ psz_meta = malloc( i_read + 1 );
+ if( net_Read( p_access, p_sys->fd, p_sys->p_vs,
+ (uint8_t *)psz_meta, i_read, VLC_TRUE ) != i_read )
+ return VLC_EGENERIC;
+
+ 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] ) )
+ {
+ if( p_sys->psz_icy_title )
+ free( p_sys->psz_icy_title );
+ p_sys->psz_icy_title = strdup( &p[1] );
+ p_access->info.i_update |= INPUT_UPDATE_META;
+
+ msg_Dbg( p_access, "New Title=%s", p_sys->psz_icy_title );
+ }
+ }
+ free( psz_meta );
+
+ return VLC_SUCCESS;
+}
+