/*****************************************************************************
* Includes
*****************************************************************************/
-#define _GNU_SOURCE
+#include <vlc/vlc.h>
#include <stdlib.h> /* malloc(), free() */
+#include <assert.h>
-#include <vlc/vlc.h>
#include <vlc_playlist.h>
#include <vlc_demux.h>
set_callbacks( Open, Close );
add_submodule();
- set_description( _("SDP file parser for UDP") );
+ set_description( _("SDP Descriptions parser") );
add_shortcut( "sdp" );
set_capability( "demux2", 51 );
set_callbacks( OpenDemux, CloseDemux );
{
demux_t *p_demux = (demux_t *)p_this;
uint8_t *p_peek;
- int i_max_sdp = 1024;
- int i_sdp = 0;
char *psz_sdp = NULL;
sdp_t *p_sdp = NULL;
+ int errval = VLC_EGENERIC;
if( !var_CreateGetInteger( p_demux, "sap-parse" ) )
{
return VLC_EGENERIC;
}
- /* Probe for SDP */
- if( p_demux->s )
- {
- if( stream_Peek( p_demux->s, &p_peek, 7 ) < 7 ) return VLC_EGENERIC;
+ assert( p_demux->s ); /* this is NOT an access_demux */
- if( strncmp( (char*)p_peek, "v=0\r\n", 5 ) &&
- strncmp( (char*)p_peek, "v=0\n", 4 ) &&
- ( p_peek[0] < 'a' || p_peek[0] > 'z' || p_peek[1] != '=' ) )
- {
- return VLC_EGENERIC;
- }
- }
+ /* Probe for SDP */
+ if( stream_Peek( p_demux->s, &p_peek, 7 ) < 7 )
+ return VLC_EGENERIC;
- psz_sdp = (char *)malloc( i_max_sdp );
- if( !psz_sdp ) return VLC_EGENERIC;
+ if( memcmp( p_peek, "v=0\r\no=", 7 ) && memcmp( p_peek, "v=0\no=", 6 ) )
+ return VLC_EGENERIC;
/* Gather the complete sdp file */
- for( ;; )
- {
- int i_read = stream_Read( p_demux->s,
- &psz_sdp[i_sdp], i_max_sdp - i_sdp - 1 );
+ psz_sdp = NULL;
- if( i_read < 0 )
+#define SDP_MAX 65536
+#define OFFSET 1024
+
+ for( size_t buflen = 0; buflen < SDP_MAX; buflen += OFFSET )
+ {
+ char *psz_sdp_new = realloc( psz_sdp, buflen + 1 );
+ if( psz_sdp_new == NULL )
{
- msg_Err( p_demux, "failed to read SDP" );
+ errval = VLC_ENOMEM;
goto error;
}
+ psz_sdp = psz_sdp_new;
- i_sdp += i_read;
-
- if( i_read < i_max_sdp - i_sdp - 1 )
+ ssize_t i_read = stream_Read( p_demux->s, psz_sdp + buflen, OFFSET );
+ if( i_read < 0 )
{
- psz_sdp[i_sdp] = '\0';
- break;
+ msg_Err( p_demux, "cannot read SDP" );
+ goto error;
}
- i_max_sdp += 1000;
- psz_sdp = (char *)realloc( psz_sdp, i_max_sdp );
+ psz_sdp[buflen + i_read] = '\0';
+
+ if( i_read < OFFSET )
+ break; // EOF
}
+#undef OFFSET
p_sdp = ParseSDP( VLC_OBJECT(p_demux), psz_sdp );
FREENULL( psz_sdp );
if( p_sdp ) FreeSDP( p_sdp ); p_sdp = NULL;
stream_Seek( p_demux->s, 0 );
- return VLC_EGENERIC;
+ return errval;
}
/*****************************************************************************
{
INTERFACE_INFO ifaces[10]; // Assume there will be no more than 10 IP interfaces
size_t len = sizeof(ifaces);
-
+
if( SOCKET_ERROR != WSAIoctl(s, SIO_GET_INTERFACE_LIST, NULL, 0, &ifaces, len, &len, NULL, NULL) )
{
unsigned ifcount = len/sizeof(INTERFACE_INFO);