Commit 21f7e7ea authored by Rafaël Carré's avatar Rafaël Carré Committed by Jean-Paul Saman

MMS: close access on network timeout

defaults to timeout on 5s (configurable) without data (there will be 10 tries before returning EOF)
fix some EOF return paths
check malloc()
Signed-off-by: default avatarJean-Paul Saman <jpsaman@videolan.org>
parent d0641277
......@@ -65,6 +65,9 @@ static void Close( vlc_object_t * );
"http://[user[:pass]@]myproxy.mydomain:myport/ ; " \
"if empty, the http_proxy environment variable will be tried." )
#define TIMEOUT_TEXT N_("TCP/UDP timeout (ms)")
#define TIMEOUT_LONGTEXT N_("Amount of time (in ms) to wait before aborting network reception of data. Note that there will be 10 retries before completely giving up.")
vlc_module_begin();
set_shortname( "MMS" );
set_description( _("Microsoft Media Server (MMS) input") );
......@@ -75,6 +78,9 @@ vlc_module_begin();
add_integer( "mms-caching", 19 * DEFAULT_PTS_DELAY / 1000, NULL,
CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
add_integer( "mms-timeout", 5000, NULL, TIMEOUT_TEXT, TIMEOUT_LONGTEXT,
VLC_TRUE );
add_bool( "mms-all", 0, NULL, ALL_TEXT, ALL_LONGTEXT, VLC_TRUE );
add_integer( "mms-maxbitrate", 0, NULL, BITRATE_TEXT, BITRATE_LONGTEXT ,
VLC_FALSE );
......
......@@ -111,8 +111,11 @@ int E_(MMSTUOpen)( access_t *p_access )
p_access->info.i_title = 0;
p_access->info.i_seekpoint = 0;
p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
if( !p_sys ) return VLC_ENOMEM;
memset( p_sys, 0, sizeof( access_sys_t ) );
p_sys->i_timeout = var_CreateGetInteger( p_access, "mms-timeout" );
/* *** Parse URL and get server addr/port and path *** */
vlc_UrlParse( &p_sys->url, p_access->psz_path, 0 );
if( p_sys->url.psz_host == NULL || *p_sys->url.psz_host == '\0' )
......@@ -345,7 +348,12 @@ static int Seek( access_t * p_access, int64_t i_pos )
while( !p_access->b_die )
{
mms_HeaderMediaRead( p_access, MMS_PACKET_CMD );
if( mms_HeaderMediaRead( p_access, MMS_PACKET_CMD ) < 0 )
{
p_access->info.b_eof = VLC_TRUE;
return VLC_EGENERIC;
}
if( p_sys->i_command == 0x1e )
{
msg_Dbg( p_access, "received 0x1e (seek)" );
......@@ -355,7 +363,11 @@ static int Seek( access_t * p_access, int64_t i_pos )
while( !p_access->b_die )
{
mms_HeaderMediaRead( p_access, MMS_PACKET_CMD );
if( mms_HeaderMediaRead( p_access, MMS_PACKET_CMD ) < 0 )
{
p_access->info.b_eof = VLC_TRUE;
return VLC_EGENERIC;
}
if( p_sys->i_command == 0x05 )
{
msg_Dbg( p_access, "received 0x05 (seek)" );
......@@ -364,7 +376,12 @@ static int Seek( access_t * p_access, int64_t i_pos )
}
/* get a packet */
mms_HeaderMediaRead( p_access, MMS_PACKET_MEDIA );
if( mms_HeaderMediaRead( p_access, MMS_PACKET_MEDIA ) < 0 )
{
p_access->info.b_eof = VLC_TRUE;
return VLC_EGENERIC;
}
msg_Dbg( p_access, "Streaming restarted" );
p_sys->i_media_used += i_offset;
......@@ -386,7 +403,7 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
i_data = 0;
/* *** now send data if needed *** */
while( i_data < (size_t)i_len )
while( i_data < i_len )
{
if( p_access->info.i_pos < p_sys->i_header )
{
......@@ -503,7 +520,7 @@ static int MMSOpen( access_t *p_access, vlc_url_t *p_url, int i_proto )
p_sys->i_buffer_udp = 0;
p_sys->p_cmd = NULL;
p_sys->i_cmd = 0;
p_access->info.b_eof = 0;
p_access->info.b_eof = VLC_FALSE;
/* *** send command 1 : connection request *** */
var_buffer_initwrite( &buffer, 0 );
......@@ -852,14 +869,15 @@ static int MMSStart( access_t *p_access, uint32_t i_packet )
msg_Err( p_access,
"unknown answer (0x%x instead of 0x05)",
p_sys->i_command );
return( -1 );
return -1;
}
else
{
/* get a packet */
mms_HeaderMediaRead( p_access, MMS_PACKET_MEDIA );
if( mms_HeaderMediaRead( p_access, MMS_PACKET_MEDIA ) < 0 )
return -1;
msg_Dbg( p_access, "streaming started" );
return( 0 );
return 0;
}
}
......@@ -1029,6 +1047,12 @@ static int NetFillBuffer( access_t *p_access )
/* We'll wait 0.5 second if nothing happens */
timeout = 500;
if( i_try * timeout > p_sys->i_timeout )
{
msg_Err(p_access, "no data received");
return -1;
}
if( i_try > 3 && (p_sys->i_buffer_tcp > 0 || p_sys->i_buffer_udp > 0) )
{
return -1;
......@@ -1443,17 +1467,18 @@ static int mms_CommandRead( access_t *p_access, int i_command1,
{
case 0x03:
msg_Warn( p_access, "socket closed by server" );
p_access->info.b_eof = 1;
p_access->info.b_eof = VLC_TRUE;
return VLC_EGENERIC;
case 0x1e:
msg_Warn( p_access, "end of media stream" );
p_access->info.b_eof = 1;
p_access->info.b_eof = VLC_TRUE;
return VLC_EGENERIC;
default:
break;
}
}
}
p_access->info.b_eof = VLC_TRUE;
msg_Warn( p_access, "failed to receive command (aborting)" );
return VLC_EGENERIC;
......@@ -1490,11 +1515,11 @@ static int mms_HeaderMediaRead( access_t *p_access, int i_type )
{
case 0x03:
msg_Warn( p_access, "socket closed by server" );
p_access->info.b_eof = 1;
p_access->info.b_eof = VLC_TRUE;
return -1;
case 0x1e:
msg_Warn( p_access, "end of media stream" );
p_access->info.b_eof = 1;
p_access->info.b_eof = VLC_TRUE;
return -1;
case 0x20:
/* XXX not too dificult to be done EXCEPT that we
......@@ -1512,6 +1537,7 @@ static int mms_HeaderMediaRead( access_t *p_access, int i_type )
msg_Err( p_access, "cannot receive %s (aborting)",
( i_type == MMS_PACKET_HEADER ) ? "header" : "media data" );
p_access->info.b_eof = VLC_TRUE;
return -1;
}
......@@ -45,6 +45,8 @@ struct access_sys_t
asf_header_t asfh;
unsigned i_timeout;
/* */
uint8_t buffer_tcp[MMS_BUFFER_SIZE];
int i_buffer_tcp;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment