[vlc-devel] commit: MMS: close access on network timeout ( Rafaël Carré )
git version control
git at videolan.org
Fri Mar 28 10:54:26 CET 2008
vlc | branch: master | Rafaël Carré <funman at videolan.org> | Fri Mar 28 10:45:25 2008 +0100| [21f7e7ea477453871b494758c2dec31e0c23287c]
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: Jean-Paul Saman <jpsaman at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=21f7e7ea477453871b494758c2dec31e0c23287c
---
modules/access/mms/mms.c | 6 +++++
modules/access/mms/mmstu.c | 50 +++++++++++++++++++++++++++++++++----------
modules/access/mms/mmstu.h | 2 +
3 files changed, 46 insertions(+), 12 deletions(-)
diff --git a/modules/access/mms/mms.c b/modules/access/mms/mms.c
index ed1dd8d..1cb77aa 100644
--- a/modules/access/mms/mms.c
+++ b/modules/access/mms/mms.c
@@ -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 );
diff --git a/modules/access/mms/mmstu.c b/modules/access/mms/mmstu.c
index 3779a06..bfe7429 100644
--- a/modules/access/mms/mmstu.c
+++ b/modules/access/mms/mmstu.c
@@ -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;
}
diff --git a/modules/access/mms/mmstu.h b/modules/access/mms/mmstu.h
index 2fa24ef..a2b2a14 100644
--- a/modules/access/mms/mmstu.h
+++ b/modules/access/mms/mmstu.h
@@ -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;
More information about the vlc-devel
mailing list