Commit 5deafc16 authored by Laurent Aimar's avatar Laurent Aimar

* all: use net_*.

parent 83c6d1f7
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mms.c: MMS over tcp, udp and http access plug-in * mms.c: MMS over tcp, udp and http access plug-in
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: mms.c,v 1.34 2003/05/15 22:27:36 massiot Exp $ * $Id: mms.c,v 1.35 2004/01/21 16:56:16 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -69,11 +69,6 @@ vlc_module_begin(); ...@@ -69,11 +69,6 @@ vlc_module_begin();
add_bool( "mms-all", 0, NULL, add_bool( "mms-all", 0, NULL,
"force selection of all streams", "force selection of all streams",
"force selection of all streams", VLC_TRUE ); "force selection of all streams", VLC_TRUE );
#if 0
add_string( "mms-stream", NULL, NULL,
"streams selection",
"force this stream selection", VLC_TRUE );
#endif
add_integer( "mms-maxbitrate", 0, NULL, add_integer( "mms-maxbitrate", 0, NULL,
"max bitrate", "max bitrate",
"set max bitrate for auto streams selections", VLC_FALSE ); "set max bitrate for auto streams selections", VLC_FALSE );
...@@ -89,9 +84,14 @@ static int Open( vlc_object_t *p_this ) ...@@ -89,9 +84,14 @@ static int Open( vlc_object_t *p_this )
{ {
input_thread_t *p_input = (input_thread_t*)p_this; input_thread_t *p_input = (input_thread_t*)p_this;
int i_err; /* First set ipv4/ipv6 */
var_Create( p_input, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
var_Create( p_input, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
/* mms-caching */
var_Create( p_input, "mms-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
/* use specified method */
if( *p_input->psz_access ) if( *p_input->psz_access )
{ {
if( !strncmp( p_input->psz_access, "mmsu", 4 ) ) if( !strncmp( p_input->psz_access, "mmsu", 4 ) )
...@@ -108,15 +108,12 @@ static int Open( vlc_object_t *p_this ) ...@@ -108,15 +108,12 @@ static int Open( vlc_object_t *p_this )
} }
} }
if( E_( MMSTUOpen )( p_input ) )
i_err = E_( MMSTUOpen )( p_input );
if( i_err )
{ {
i_err = E_( MMSHOpen )( p_input ); /* try mmsh if mmstu failed */
return E_( MMSHOpen )( p_input );
} }
return VLC_SUCCESS;
return i_err;
} }
/***************************************************************************** /*****************************************************************************
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mmsh.c: * mmsh.c:
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: mmsh.c,v 1.6 2003/08/26 00:51:19 fenrir Exp $ * $Id: mmsh.c,v 1.7 2004/01/21 16:56:16 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -35,32 +35,6 @@ ...@@ -35,32 +35,6 @@
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/input.h> #include <vlc/input.h>
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#if defined( UNDER_CE )
# include <winsock.h>
#elif defined( WIN32 )
# include <winsock2.h>
# include <ws2tcpip.h>
# ifndef IN_MULTICAST
# define IN_MULTICAST(a) IN_CLASSD(a)
# endif
#else
# include <sys/socket.h>
#endif
#include "network.h" #include "network.h"
#include "asf.h" #include "asf.h"
#include "buffer.h" #include "buffer.h"
...@@ -71,20 +45,22 @@ ...@@ -71,20 +45,22 @@
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
int E_( MMSHOpen ) ( input_thread_t * ); int E_(MMSHOpen) ( input_thread_t * );
void E_( MMSHClose ) ( input_thread_t * ); void E_(MMSHClose) ( input_thread_t * );
static ssize_t Read( input_thread_t *, byte_t *, size_t );
static void Seek( input_thread_t *, off_t );
static ssize_t Read ( input_thread_t * p_input, byte_t * p_buffer, static ssize_t NetFill( input_thread_t *, access_sys_t *, int );
size_t i_len );
static void Seek ( input_thread_t *, off_t );
/**************************************************************************** static int mmsh_start ( input_thread_t *, off_t );
**************************************************************************** static void mmsh_stop ( input_thread_t * );
******************* ******************* static int mmsh_get_packet( input_thread_t *, chunk_t * );
******************* Main functions *******************
******************* ******************* static http_answer_t *http_answer_parse( uint8_t *, int );
**************************************************************************** static void http_answer_free ( http_answer_t * );
****************************************************************************/ static http_field_t *http_field_find ( http_field_t *, char * );
static int chunk_parse( chunk_t *, uint8_t *, int );
/**************************************************************************** /****************************************************************************
* Open: connect to ftp server and ask for file * Open: connect to ftp server and ask for file
...@@ -98,11 +74,13 @@ int E_( MMSHOpen ) ( input_thread_t *p_input ) ...@@ -98,11 +74,13 @@ int E_( MMSHOpen ) ( input_thread_t *p_input )
http_field_t *p_field; http_field_t *p_field;
chunk_t ck; chunk_t ck;
vlc_value_t val;
/* init p_sys */ /* init p_sys */
p_input->p_access_data = p_sys = malloc( sizeof( access_sys_t ) ); p_input->p_access_data = p_sys = malloc( sizeof( access_sys_t ) );
p_sys->i_proto = MMS_PROTO_HTTP; p_sys->i_proto = MMS_PROTO_HTTP;
p_sys->p_socket = NULL; p_sys->fd = -1;
p_sys->i_request_context = 1; p_sys->i_request_context = 1;
p_sys->i_buffer = 0; p_sys->i_buffer = 0;
p_sys->i_buffer_pos = 0; p_sys->i_buffer_pos = 0;
...@@ -128,7 +106,8 @@ int E_( MMSHOpen ) ( input_thread_t *p_input ) ...@@ -128,7 +106,8 @@ int E_( MMSHOpen ) ( input_thread_t *p_input )
p_sys->p_url->i_port = 80; p_sys->p_url->i_port = 80;
} }
if( ( p_sys->p_socket = NetOpenTCP( p_input, p_sys->p_url ) ) == NULL ) if( ( p_sys->fd = net_OpenTCP( p_input, p_sys->p_url->psz_host,
p_sys->p_url->i_port ) ) < 0 )
{ {
msg_Err( p_input, "cannot connect" ); msg_Err( p_input, "cannot connect" );
goto exit_error; goto exit_error;
...@@ -146,16 +125,15 @@ int E_( MMSHOpen ) ( input_thread_t *p_input ) ...@@ -146,16 +125,15 @@ int E_( MMSHOpen ) ( input_thread_t *p_input )
p += sprintf( p, "Pragma: xClientGUID={"GUID_FMT"}\r\n", p += sprintf( p, "Pragma: xClientGUID={"GUID_FMT"}\r\n",
GUID_PRINT( p_sys->guid ) ); GUID_PRINT( p_sys->guid ) );
p += sprintf( p, "Connection: Close\r\n\r\n" ); p += sprintf( p, "Connection: Close\r\n\r\n" );
NetWrite( p_input, p_sys->p_socket, p_sys->buffer, p - p_sys->buffer );
net_Write( p_input, p_sys->fd, p_sys->buffer, p - p_sys->buffer );
if( NetFill ( p_input, p_sys, BUFFER_SIZE ) <= 0 ) if( NetFill ( p_input, p_sys, BUFFER_SIZE ) <= 0 )
{ {
msg_Err( p_input, "cannot read answer" ); msg_Err( p_input, "cannot read answer" );
goto exit_error; goto exit_error;
} }
NetClose( p_input, p_sys->p_socket ); net_Close( p_sys->fd ); p_sys->fd = -1;
p_sys->p_socket = NULL;
p_ans = http_answer_parse( p_sys->buffer, p_sys->i_buffer ); p_ans = http_answer_parse( p_sys->buffer, p_sys->i_buffer );
if( !p_ans ) if( !p_ans )
...@@ -300,21 +278,21 @@ int E_( MMSHOpen ) ( input_thread_t *p_input ) ...@@ -300,21 +278,21 @@ int E_( MMSHOpen ) ( input_thread_t *p_input )
p_input->stream.i_method = INPUT_METHOD_NETWORK; p_input->stream.i_method = INPUT_METHOD_NETWORK;
vlc_mutex_unlock( &p_input->stream.stream_lock ); vlc_mutex_unlock( &p_input->stream.stream_lock );
/* Update default_pts to a suitable value for ftp access */ /* Update default_pts to a suitable value for mms access */
p_input->i_pts_delay = config_GetInt( p_input, "mms-caching" ) * 1000; var_Get( p_input, "mms-caching", &val );
p_input->i_pts_delay = val.i_int * 1000;
return( VLC_SUCCESS ); return VLC_SUCCESS;
exit_error: exit_error:
E_( url_free )( p_sys->p_url ); E_( url_free )( p_sys->p_url );
if( p_sys->p_socket ) if( p_sys->fd > 0 )
{ {
NetClose( p_input, p_sys->p_socket ); net_Close( p_sys->fd );
} }
free( p_sys ); free( p_sys );
return( VLC_EGENERIC ); return VLC_EGENERIC;
} }
/***************************************************************************** /*****************************************************************************
...@@ -331,74 +309,6 @@ void E_( MMSHClose ) ( input_thread_t *p_input ) ...@@ -331,74 +309,6 @@ void E_( MMSHClose ) ( input_thread_t *p_input )
free( p_sys ); free( p_sys );
} }
static int mmsh_get_packet( input_thread_t * p_input,
chunk_t *p_ck )
{
access_sys_t *p_sys = p_input->p_access_data;
int i_mov = p_sys->i_buffer - p_sys->i_buffer_pos;
if( p_sys->i_buffer_pos > BUFFER_SIZE / 2 )
{
if( i_mov > 0 )
{
memmove( &p_sys->buffer[0],
&p_sys->buffer[p_sys->i_buffer_pos],
i_mov );
}
p_sys->i_buffer = i_mov;
p_sys->i_buffer_pos = 0;
}
if( NetFill( p_input, p_sys, 12 ) < 12 )
{
msg_Warn( p_input, "cannot fill buffer" );
return VLC_EGENERIC;
}
chunk_parse( p_ck, &p_sys->buffer[p_sys->i_buffer_pos],
p_sys->i_buffer - p_sys->i_buffer_pos );
if( p_ck->i_type == 0x4524 ) // Transfer complete
{
msg_Warn( p_input, "EOF" );
return VLC_EGENERIC;
}
else if( p_ck->i_type != 0x4824 && p_ck->i_type != 0x4424 )
{
msg_Err( p_input, "invalid chunk FATAL" );
return VLC_EGENERIC;
}
if( p_ck->i_data < p_ck->i_size2 - 8 )
{
if( NetFill( p_input, p_sys, p_ck->i_size2 - 8 - p_ck->i_data ) <= 0 )
{
msg_Warn( p_input, "cannot fill buffer" );
return VLC_EGENERIC;
}
chunk_parse( p_ck, &p_sys->buffer[p_sys->i_buffer_pos],
p_sys->i_buffer - p_sys->i_buffer_pos );
}
if( p_sys->i_packet_sequence != 0 &&
p_ck->i_sequence != p_sys->i_packet_sequence )
{
msg_Warn( p_input, "packet lost ?" );
}
p_sys->i_packet_sequence = p_ck->i_sequence + 1;
p_sys->i_packet_used = 0;
p_sys->i_packet_length = p_ck->i_data;
p_sys->p_packet = p_ck->p_data;
p_sys->i_buffer_pos += 12 + p_ck->i_data;
return VLC_SUCCESS;
}
/***************************************************************************** /*****************************************************************************
* Seek: try to go at the right place * Seek: try to go at the right place
*****************************************************************************/ *****************************************************************************/
...@@ -437,10 +347,8 @@ static void Seek( input_thread_t * p_input, off_t i_pos ) ...@@ -437,10 +347,8 @@ static void Seek( input_thread_t * p_input, off_t i_pos )
p_sys->i_pos = i_pos; p_sys->i_pos = i_pos;
p_sys->i_packet_used += i_offset; p_sys->i_packet_used += i_offset;
p_input->stream.p_selected_area->i_tell = i_pos; p_input->stream.p_selected_area->i_tell = i_pos;
vlc_mutex_unlock( &p_input->stream.stream_lock ); vlc_mutex_unlock( &p_input->stream.stream_lock );
} }
/***************************************************************************** /*****************************************************************************
...@@ -498,15 +406,60 @@ static ssize_t Read ( input_thread_t * p_input, byte_t * p_buffer, ...@@ -498,15 +406,60 @@ static ssize_t Read ( input_thread_t * p_input, byte_t * p_buffer,
return( i_data ); return( i_data );
} }
/*****************************************************************************
* NetFill:
*****************************************************************************/
static ssize_t NetFill( input_thread_t *p_input, access_sys_t *p_sys, int i_size )
{
int i_try = 0;
int i_total = 0;
i_size = __MIN( i_size, BUFFER_SIZE - p_sys->i_buffer );
if( i_size <= 0 )
{
return 0;
}
for( ;; )
{
int i_read;
i_read = net_Read( p_input, p_sys->fd,
&p_sys->buffer[p_sys->i_buffer], i_size, VLC_FALSE );
if( i_read == 0 )
{
if( i_try++ > 2 )
{
break;
}
msg_Dbg( p_input, "another try %d/2", i_try );
continue;
}
if( i_read < 0 || p_input->b_die || p_input->b_error )
{
break;
}
i_total += i_read;
p_sys->i_buffer += i_read;
if( i_total >= i_size )
{
break;
}
}
p_sys->buffer[p_sys->i_buffer] = '\0';
return i_total;
}
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
static int mmsh_start( input_thread_t *p_input, /*****************************************************************************
off_t i_pos ) *
*****************************************************************************/
static int mmsh_start( input_thread_t *p_input, off_t i_pos )
{ {
access_sys_t *p_sys = p_input->p_access_data; access_sys_t *p_sys = p_input->p_access_data;
uint8_t *p; uint8_t *p;
...@@ -516,7 +469,8 @@ static int mmsh_start( input_thread_t *p_input, ...@@ -516,7 +469,8 @@ static int mmsh_start( input_thread_t *p_input,
msg_Dbg( p_input, "starting stream" ); msg_Dbg( p_input, "starting stream" );
if( ( p_sys->p_socket = NetOpenTCP( p_input, p_sys->p_url ) ) == NULL ) if( ( p_sys->fd = net_OpenTCP( p_input, p_sys->p_url->psz_host,
p_sys->p_url->i_port ) ) < 0 )
{ {
/* should not occur */ /* should not occur */
msg_Err( p_input, "cannot connect to the server" ); msg_Err( p_input, "cannot connect to the server" );
...@@ -574,8 +528,7 @@ static int mmsh_start( input_thread_t *p_input, ...@@ -574,8 +528,7 @@ static int mmsh_start( input_thread_t *p_input,
p += sprintf( p, "\r\n" ); p += sprintf( p, "\r\n" );
p += sprintf( p, "Connection: Close\r\n\r\n" ); p += sprintf( p, "Connection: Close\r\n\r\n" );
net_Write( p_input, p_sys->fd, p_sys->buffer, p - p_sys->buffer );
NetWrite( p_input, p_sys->p_socket, p_sys->buffer, p - p_sys->buffer );
msg_Dbg( p_input, "filling buffer" ); msg_Dbg( p_input, "filling buffer" );
/* we read until we found a \r\n\r\n or \n\n */ /* we read until we found a \r\n\r\n or \n\n */
...@@ -588,10 +541,7 @@ static int mmsh_start( input_thread_t *p_input, ...@@ -588,10 +541,7 @@ static int mmsh_start( input_thread_t *p_input,
uint8_t *p; uint8_t *p;
p = &p_sys->buffer[p_sys->i_buffer]; p = &p_sys->buffer[p_sys->i_buffer];
i_read = i_read = net_Read( p_input, p_sys->fd, &p_sys->buffer[p_sys->i_buffer], 1024, VLC_FALSE );
NetRead( p_input, p_sys->p_socket,
&p_sys->buffer[p_sys->i_buffer],
1024 );
if( i_read == 0 ) if( i_read == 0 )
{ {
...@@ -651,229 +601,89 @@ static int mmsh_start( input_thread_t *p_input, ...@@ -651,229 +601,89 @@ static int mmsh_start( input_thread_t *p_input,
return VLC_SUCCESS; return VLC_SUCCESS;
} }
/*****************************************************************************
*
*****************************************************************************/
static void mmsh_stop( input_thread_t *p_input ) static void mmsh_stop( input_thread_t *p_input )
{ {
access_sys_t *p_sys = p_input->p_access_data; access_sys_t *p_sys = p_input->p_access_data;
msg_Dbg( p_input, "closing stream" ); msg_Dbg( p_input, "closing stream" );
NetClose( p_input, p_sys->p_socket ); net_Close( p_sys->fd ); p_sys->fd = -1;
p_sys->p_socket = NULL;
} }
static ssize_t NetFill( input_thread_t *p_input, /*****************************************************************************
access_sys_t *p_sys, int i_size ) *
*****************************************************************************/
static int mmsh_get_packet( input_thread_t * p_input, chunk_t *p_ck )
{ {
int i_try = 0; access_sys_t *p_sys = p_input->p_access_data;
int i_total = 0;
i_size = __MIN( i_size, BUFFER_SIZE - p_sys->i_buffer );
if( i_size <= 0 )
{
return 0;
}
for( ;; )
{
int i_read;
i_read = NetRead( p_input, p_sys->p_socket,
&p_sys->buffer[p_sys->i_buffer], i_size );
if( i_read == 0 ) int i_mov = p_sys->i_buffer - p_sys->i_buffer_pos;
{
if( i_try++ > 2 )
{
break;
}
msg_Dbg( p_input, "another try %d/2", i_try );
continue;
}
if( i_read < 0 || p_input->b_die || p_input->b_error ) if( p_sys->i_buffer_pos > BUFFER_SIZE / 2 )
{ {
break; if( i_mov > 0 )
}
i_total += i_read;
p_sys->i_buffer += i_read;
if( i_total >= i_size )
{ {
break; memmove( &p_sys->buffer[0],
} &p_sys->buffer[p_sys->i_buffer_pos],
i_mov );
} }
p_sys->buffer[p_sys->i_buffer] = '\0'; p_sys->i_buffer = i_mov;
p_sys->i_buffer_pos = 0;
return i_total;
}
/****************************************************************************
* NetOpenTCP:
****************************************************************************/
static input_socket_t * NetOpenTCP( input_thread_t *p_input, url_t *p_url )
{
input_socket_t *p_socket;
char *psz_network;
module_t *p_network;
network_socket_t socket_desc;
p_socket = malloc( sizeof( input_socket_t ) );
memset( p_socket, 0, sizeof( input_socket_t ) );
psz_network = "";
if( config_GetInt( p_input, "ipv4" ) )
{
psz_network = "ipv4";
}
else if( config_GetInt( p_input, "ipv6" ) )
{
psz_network = "ipv6";
} }
msg_Dbg( p_input, "waiting for connection..." ); if( NetFill( p_input, p_sys, 12 ) < 12 )
socket_desc.i_type = NETWORK_TCP;
socket_desc.psz_server_addr = p_url->psz_host;
socket_desc.i_server_port = p_url->i_port;
socket_desc.psz_bind_addr = "";
socket_desc.i_bind_port = 0;
socket_desc.i_ttl = 0;
p_input->p_private = (void*)&socket_desc;
if( !( p_network = module_Need( p_input, "network", psz_network ) ) )
{ {
msg_Err( p_input, "failed to connect with server" ); msg_Warn( p_input, "cannot fill buffer" );
return NULL; return VLC_EGENERIC;
} }
module_Unneed( p_input, p_network );
p_socket->i_handle = socket_desc.i_handle;
p_input->i_mtu = socket_desc.i_mtu;
msg_Dbg( p_input,
"connection with \"%s:%d\" successful",
p_url->psz_host,
p_url->i_port );
return p_socket; chunk_parse( p_ck, &p_sys->buffer[p_sys->i_buffer_pos],
} p_sys->i_buffer - p_sys->i_buffer_pos );
/*****************************************************************************
* Read: read on a file descriptor, checking b_die periodically
*****************************************************************************/
static ssize_t NetRead( input_thread_t *p_input,
input_socket_t *p_socket,
byte_t *p_buffer, size_t i_len )
{
struct timeval timeout;
fd_set fds;
ssize_t i_recv;
int i_ret;
/* Initialize file descriptor set */
FD_ZERO( &fds );
FD_SET( p_socket->i_handle, &fds );
/* We'll wait 1 second if nothing happens */
timeout.tv_sec = 1;
timeout.tv_usec = 0;
/* Find if some data is available */
while( ( i_ret = select( p_socket->i_handle + 1, &fds,
NULL, NULL, &timeout )) == 0 ||
#ifdef HAVE_ERRNO_H
( i_ret < 0 && errno == EINTR )
#endif
)
{
FD_ZERO( &fds );
FD_SET( p_socket->i_handle, &fds );
timeout.tv_sec = 1;
timeout.tv_usec = 0;
if( p_input->b_die || p_input->b_error )
{
return 0;
}
}
if( i_ret < 0 ) if( p_ck->i_type == 0x4524 ) // Transfer complete
{ {
msg_Err( p_input, "network select error (%s)", strerror(errno) ); msg_Warn( p_input, "EOF" );
return -1; return VLC_EGENERIC;
} }
else if( p_ck->i_type != 0x4824 && p_ck->i_type != 0x4424 )
i_recv = recv( p_socket->i_handle, p_buffer, i_len, 0 );
if( i_recv < 0 )
{ {
msg_Err( p_input, "recv failed (%s)", strerror(errno) ); msg_Err( p_input, "invalid chunk FATAL" );
return VLC_EGENERIC;
} }
return i_recv; if( p_ck->i_data < p_ck->i_size2 - 8 )
}
static ssize_t NetWrite( input_thread_t *p_input,
input_socket_t *p_socket,
byte_t *p_buffer, size_t i_len )
{
struct timeval timeout;
fd_set fds;
ssize_t i_send;
int i_ret;
/* Initialize file descriptor set */
FD_ZERO( &fds );
FD_SET( p_socket->i_handle, &fds );
/* We'll wait 1 second if nothing happens */
timeout.tv_sec = 1;
timeout.tv_usec = 0;
/* Find if some data is available */
while( ( i_ret = select( p_socket->i_handle + 1, NULL, &fds, NULL, &timeout ) ) == 0 ||
#ifdef HAVE_ERRNO_H
( i_ret < 0 && errno == EINTR )
#endif
)
{ {
FD_ZERO( &fds ); if( NetFill( p_input, p_sys, p_ck->i_size2 - 8 - p_ck->i_data ) <= 0 )
FD_SET( p_socket->i_handle, &fds );
timeout.tv_sec = 1;
timeout.tv_usec = 0;
if( p_input->b_die || p_input->b_error )
{ {
return 0; msg_Warn( p_input, "cannot fill buffer" );
} return VLC_EGENERIC;
} }
chunk_parse( p_ck, &p_sys->buffer[p_sys->i_buffer_pos],
if( i_ret < 0 ) p_sys->i_buffer - p_sys->i_buffer_pos );
{
msg_Err( p_input, "network select error (%s)", strerror(errno) );
return -1;
} }
i_send = send( p_socket->i_handle, p_buffer, i_len, 0 ); if( p_sys->i_packet_sequence != 0 &&
p_ck->i_sequence != p_sys->i_packet_sequence )
if( i_send < 0 )
{ {
msg_Err( p_input, "send failed (%s)", strerror(errno) ); msg_Warn( p_input, "packet lost ?" );
} }
return i_send; p_sys->i_packet_sequence = p_ck->i_sequence + 1;
} p_sys->i_packet_used = 0;
p_sys->i_packet_length = p_ck->i_data;
p_sys->p_packet = p_ck->p_data;
static void NetClose( input_thread_t *p_input, input_socket_t *p_socket ) p_sys->i_buffer_pos += 12 + p_ck->i_data;
{
#if defined( WIN32 ) || defined( UNDER_CE )
closesocket( p_socket->i_handle );
#else
close( p_socket->i_handle );
#endif
free( p_socket ); return VLC_SUCCESS;
} }
/*****************************************************************************
*
*****************************************************************************/
static int http_next_line( uint8_t **pp_data, int *pi_data ) static int http_next_line( uint8_t **pp_data, int *pi_data )
{ {
char *p, *p_end = *pp_data + *pi_data; char *p, *p_end = *pp_data + *pi_data;
...@@ -898,6 +708,9 @@ static int http_next_line( uint8_t **pp_data, int *pi_data ) ...@@ -898,6 +708,9 @@ static int http_next_line( uint8_t **pp_data, int *pi_data )
return VLC_EGENERIC; return VLC_EGENERIC;
} }
/*****************************************************************************
*
*****************************************************************************/
static http_answer_t *http_answer_parse( uint8_t *p_data, int i_data ) static http_answer_t *http_answer_parse( uint8_t *p_data, int i_data )
{ {
http_answer_t *ans = malloc( sizeof( http_answer_t ) ); http_answer_t *ans = malloc( sizeof( http_answer_t ) );
...@@ -981,6 +794,9 @@ static http_answer_t *http_answer_parse( uint8_t *p_data, int i_data ) ...@@ -981,6 +794,9 @@ static http_answer_t *http_answer_parse( uint8_t *p_data, int i_data )
return ans; return ans;
} }
/*****************************************************************************
*
*****************************************************************************/
static void http_answer_free( http_answer_t *ans ) static void http_answer_free( http_answer_t *ans )
{ {
http_field_t *p_field = ans->p_fields; http_field_t *p_field = ans->p_fields;
...@@ -1001,6 +817,9 @@ static void http_answer_free( http_answer_t *ans ) ...@@ -1001,6 +817,9 @@ static void http_answer_free( http_answer_t *ans )
free( ans ); free( ans );
} }
/*****************************************************************************
*
*****************************************************************************/
static http_field_t *http_field_find( http_field_t *p_field, char *psz_name ) static http_field_t *http_field_find( http_field_t *p_field, char *psz_name )
{ {
...@@ -1017,6 +836,9 @@ static http_field_t *http_field_find( http_field_t *p_field, char *psz_name ) ...@@ -1017,6 +836,9 @@ static http_field_t *http_field_find( http_field_t *p_field, char *psz_name )
return NULL; return NULL;
} }
/*****************************************************************************
*
*****************************************************************************/
static int chunk_parse( chunk_t *ck, uint8_t *p_data, int i_data ) static int chunk_parse( chunk_t *ck, uint8_t *p_data, int i_data )
{ {
if( i_data < 12 ) if( i_data < 12 )
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mmsh.h: * mmsh.h:
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: mmsh.h,v 1.4 2003/08/26 00:51:19 fenrir Exp $ * $Id: mmsh.h,v 1.5 2004/01/21 16:56:16 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -36,14 +36,12 @@ typedef struct ...@@ -36,14 +36,12 @@ typedef struct
} chunk_t; } chunk_t;
static int chunk_parse( chunk_t *, uint8_t *, int );
#define BUFFER_SIZE 150000 #define BUFFER_SIZE 150000
struct access_sys_t struct access_sys_t
{ {
int i_proto; int i_proto;
input_socket_t *p_socket; int fd;
url_t *p_url; url_t *p_url;
int i_request_context; int i_request_context;
...@@ -68,14 +66,6 @@ struct access_sys_t ...@@ -68,14 +66,6 @@ struct access_sys_t
guid_t guid; guid_t guid;
}; };
static input_socket_t * NetOpenTCP ( input_thread_t *, url_t * );
static ssize_t NetRead ( input_thread_t *, input_socket_t *, byte_t *, size_t );
static ssize_t NetWrite ( input_thread_t *, input_socket_t *, byte_t *, size_t );
static void NetClose ( input_thread_t *, input_socket_t * );
static ssize_t NetFill( input_thread_t *, access_sys_t *, int );
typedef struct http_field_s typedef struct http_field_s
{ {
char *psz_name; char *psz_name;
...@@ -98,10 +88,4 @@ typedef struct ...@@ -98,10 +88,4 @@ typedef struct
} http_answer_t; } http_answer_t;
static http_answer_t *http_answer_parse ( uint8_t *, int );
static void http_answer_free ( http_answer_t * );
/* static char *http_field_get_value ( http_answer_t *, char * ); */
static http_field_t *http_field_find ( http_field_t *, char * );
static int mmsh_start( input_thread_t *, off_t );
static void mmsh_stop ( input_thread_t * );
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mms.c: MMS access plug-in * mms.c: MMS access plug-in
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: mmstu.c,v 1.6 2003/07/31 23:44:49 fenrir Exp $ * $Id: mmstu.c,v 1.7 2004/01/21 16:56:16 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -81,7 +81,7 @@ static ssize_t Read ( input_thread_t * p_input, byte_t * p_buffer, ...@@ -81,7 +81,7 @@ static ssize_t Read ( input_thread_t * p_input, byte_t * p_buffer,
size_t i_len ); size_t i_len );
static void Seek ( input_thread_t *, off_t ); static void Seek ( input_thread_t *, off_t );
static int MMSOpen( input_thread_t *, url_t *, int, char * ); static int MMSOpen( input_thread_t *, url_t *, int );
static int MMSStart ( input_thread_t *, uint32_t ); static int MMSStart ( input_thread_t *, uint32_t );
static int MMSStop ( input_thread_t *p_input ); static int MMSStop ( input_thread_t *p_input );
...@@ -96,9 +96,6 @@ static int mms_HeaderMediaRead( input_thread_t *, int ); ...@@ -96,9 +96,6 @@ static int mms_HeaderMediaRead( input_thread_t *, int );
static int mms_ReceivePacket( input_thread_t * ); static int mms_ReceivePacket( input_thread_t * );
//static void mms_ParseURL( url_t *p_url, char *psz_url );
/* /*
* XXX DON'T FREE MY MEMORY !!! XXX * XXX DON'T FREE MY MEMORY !!! XXX
...@@ -121,8 +118,8 @@ int E_( MMSTUOpen ) ( input_thread_t *p_input ) ...@@ -121,8 +118,8 @@ int E_( MMSTUOpen ) ( input_thread_t *p_input )
{ {
access_sys_t *p_sys; access_sys_t *p_sys;
int i_proto; int i_proto;
char *psz_network;
int i_status; int i_status;
vlc_value_t val;
/* *** allocate p_sys_data *** */ /* *** allocate p_sys_data *** */
p_input->p_access_data = p_sys = malloc( sizeof( access_sys_t ) ); p_input->p_access_data = p_sys = malloc( sizeof( access_sys_t ) );
...@@ -130,28 +127,21 @@ int E_( MMSTUOpen ) ( input_thread_t *p_input ) ...@@ -130,28 +127,21 @@ int E_( MMSTUOpen ) ( input_thread_t *p_input )
/* *** Parse URL and get server addr/port and path *** */ /* *** Parse URL and get server addr/port and path *** */
//mms_ParseURL( &p_sys->url, p_input->psz_name );
p_sys->p_url = E_( url_new )( p_input->psz_name ); p_sys->p_url = E_( url_new )( p_input->psz_name );
if( *p_sys->p_url->psz_host == '\0' ) if( *p_sys->p_url->psz_host == '\0' )
{ {
E_( url_free )( p_sys->p_url ); E_( url_free )( p_sys->p_url );
msg_Err( p_input, "invalid server name" ); msg_Err( p_input, "invalid server name" );
return( -1 ); return VLC_EGENERIC;
} }
if( p_sys->p_url->i_port <= 0 ) if( p_sys->p_url->i_port <= 0 )
{ {
p_sys->p_url->i_port = 1755; p_sys->p_url->i_port = 1755;
} }
#if 0
if( p_sys->url.i_bind_port == 0 )
{
p_sys->url.i_bind_port = 7000; /* default port */
}
#endif
/* *** connect to this server *** */ /* *** connect to this server *** */
/* 1: look at requested protocol (udp/tcp) */ /* look at requested protocol (udp/tcp) */
i_proto = MMS_PROTO_AUTO; i_proto = MMS_PROTO_AUTO;
if( *p_input->psz_access ) if( *p_input->psz_access )
{ {
...@@ -164,42 +154,28 @@ int E_( MMSTUOpen ) ( input_thread_t *p_input ) ...@@ -164,42 +154,28 @@ int E_( MMSTUOpen ) ( input_thread_t *p_input )
i_proto = MMS_PROTO_TCP; i_proto = MMS_PROTO_TCP;
} }
} }
/* 2: look at ip version ipv4/ipv6 */
psz_network = ""; /* connect */
if( config_GetInt( p_input, "ipv4" ) )
{
psz_network = "ipv4";
}
else if( config_GetInt( p_input, "ipv6" ) )
{
psz_network = "ipv6";
}
/* 3: connect */
if( i_proto == MMS_PROTO_AUTO ) if( i_proto == MMS_PROTO_AUTO )
{ /* first try with TCP */ { /* first try with TCP */
i_status = if( ( i_status = MMSOpen( p_input, p_sys->p_url, MMS_PROTO_TCP ) ) )
MMSOpen( p_input, p_sys->p_url, MMS_PROTO_TCP, psz_network );
if( i_status < 0 )
{ /* then with UDP */ { /* then with UDP */
i_status = i_status = MMSOpen( p_input, p_sys->p_url, MMS_PROTO_UDP );
MMSOpen( p_input, p_sys->p_url, MMS_PROTO_UDP, psz_network );
} }
} }
else else
{ {
i_status = MMSOpen( p_input, p_sys->p_url, i_proto );
i_status =
MMSOpen( p_input, p_sys->p_url, i_proto, psz_network );
} }
if( i_status < 0 ) if( i_status )
{ {
msg_Err( p_input, "cannot connect to server" ); msg_Err( p_input, "cannot connect to server" );
E_( url_free )( p_sys->p_url ); E_( url_free )( p_sys->p_url );
return( -1 ); return VLC_EGENERIC;
} }
msg_Dbg( p_input, "connected to %s:%d", p_sys->p_url->psz_host, p_sys->p_url->i_port );
msg_Dbg( p_input, "connected to %s:%d", p_sys->p_url->psz_host, p_sys->p_url->i_port );
/* *** set exported functions *** */ /* *** set exported functions *** */
p_input->pf_read = Read; p_input->pf_read = Read;
...@@ -241,13 +217,14 @@ int E_( MMSTUOpen ) ( input_thread_t *p_input ) ...@@ -241,13 +217,14 @@ int E_( MMSTUOpen ) ( input_thread_t *p_input )
msg_Err( p_input, "cannot start stream" ); msg_Err( p_input, "cannot start stream" );
MMSClose( p_input ); MMSClose( p_input );
E_( url_free )( p_sys->p_url ); E_( url_free )( p_sys->p_url );
return( -1 ); return VLC_EGENERIC;
} }
/* Update default_pts to a suitable value for mms access */ /* Update default_pts to a suitable value for mms access */
p_input->i_pts_delay = config_GetInt( p_input, "mms-caching" ) * 1000; var_Get( p_input, "mms-caching", &val );
p_input->i_pts_delay = val.i_int * 1000;
return( 0 ); return VLC_SUCCESS;
} }
/***************************************************************************** /*****************************************************************************
...@@ -419,15 +396,9 @@ static ssize_t Read ( input_thread_t * p_input, byte_t * p_buffer, ...@@ -419,15 +396,9 @@ static ssize_t Read ( input_thread_t * p_input, byte_t * p_buffer,
/**************************************************************************** /****************************************************************************
* MMSOpen : Open a connection with the server over mmst or mmsu * MMSOpen : Open a connection with the server over mmst or mmsu
****************************************************************************/ ****************************************************************************/
static int MMSOpen( input_thread_t *p_input, static int MMSOpen( input_thread_t *p_input, url_t *p_url, int i_proto )
url_t *p_url,
int i_proto,
char *psz_network ) /* "", "ipv4", "ipv6" */
{ {
module_t *p_network;
access_sys_t *p_sys = p_input->p_access_data; access_sys_t *p_sys = p_input->p_access_data;
network_socket_t socket_desc;
int b_udp = ( i_proto == MMS_PROTO_UDP ) ? 1 : 0; int b_udp = ( i_proto == MMS_PROTO_UDP ) ? 1 : 0;
var_buffer_t buffer; var_buffer_t buffer;
...@@ -444,21 +415,13 @@ static int MMSOpen( input_thread_t *p_input, ...@@ -444,21 +415,13 @@ static int MMSOpen( input_thread_t *p_input,
/* *** Open a TCP connection with server *** */ /* *** Open a TCP connection with server *** */
msg_Dbg( p_input, "waiting for connection..." ); msg_Dbg( p_input, "waiting for connection..." );
socket_desc.i_type = NETWORK_TCP; p_sys->socket_tcp.i_handle = net_OpenTCP( p_input, p_url->psz_host, p_url->i_port );
socket_desc.psz_server_addr = p_url->psz_host; if( p_sys->socket_tcp.i_handle < 0 )
socket_desc.i_server_port = p_url->i_port;
socket_desc.psz_bind_addr = "";
socket_desc.i_bind_port = 0;
socket_desc.i_ttl = 0;
p_input->p_private = (void*)&socket_desc;
if( !( p_network = module_Need( p_input, "network", psz_network ) ) )
{ {
msg_Err( p_input, "failed to open a connection (tcp)" ); msg_Err( p_input, "failed to open a connection (tcp)" );
return( -1 ); return VLC_EGENERIC;
} }
module_Unneed( p_input, p_network ); p_input->i_mtu = 0;
p_sys->socket_tcp.i_handle = socket_desc.i_handle;
p_input->i_mtu = 0; /*socket_desc.i_mtu;*/
msg_Dbg( p_input, msg_Dbg( p_input,
"connection(tcp) with \"%s:%d\" successful", "connection(tcp) with \"%s:%d\" successful",
p_url->psz_host, p_url->psz_host,
...@@ -475,44 +438,21 @@ static int MMSOpen( input_thread_t *p_input, ...@@ -475,44 +438,21 @@ static int MMSOpen( input_thread_t *p_input,
{ {
msg_Err( p_input, "for udp you have to provide bind address (mms://<server_addr>@<bind_addr/<path> (FIXME)" ); msg_Err( p_input, "for udp you have to provide bind address (mms://<server_addr>@<bind_addr/<path> (FIXME)" );
#if defined( UNDER_CE ) net_Close( p_sys->socket_tcp.i_handle );
CloseHandle( (HANDLE)p_sys->socket_tcp.i_handle ); return VLC_EGENERIC;
#elif defined( WIN32 )
closesocket( p_sys->socket_tcp.i_handle );
#else
close( p_sys->socket_tcp.i_handle );
#endif
return( -1 );
} }
p_sys->psz_bind_addr = inet_ntoa( name.sin_addr ); p_sys->psz_bind_addr = inet_ntoa( name.sin_addr );
socket_desc.i_type = NETWORK_UDP; p_sys->socket_udp.i_handle = net_OpenUDP( p_input, p_sys->psz_bind_addr, 7000, "", 0 );
socket_desc.psz_server_addr = ""; if( p_sys->socket_udp.i_handle < 0 )
socket_desc.i_server_port = 0;
socket_desc.psz_bind_addr = p_sys->psz_bind_addr;
socket_desc.i_bind_port = 7000; //p_url->i_bind_port; FIXME
socket_desc.i_ttl = 0;
p_input->p_private = (void*)&socket_desc;
if( !( p_network = module_Need( p_input, "network", psz_network ) ) )
{ {
msg_Err( p_input, "failed to open a connection (udp)" ); msg_Err( p_input, "failed to open a connection (udp)" );
#if defined( UNDER_CE ) net_Close( p_sys->socket_tcp.i_handle );
CloseHandle( (HANDLE)p_sys->socket_tcp.i_handle ); return VLC_EGENERIC;
#elif defined( WIN32 )
closesocket( p_sys->socket_tcp.i_handle );
#else
close( p_sys->socket_tcp.i_handle );
#endif
return( -1 );
} }
module_Unneed( p_input, p_network );
p_sys->socket_udp.i_handle = socket_desc.i_handle;
p_input->i_mtu = 0;/*socket_desc.i_mtu; FIXME */
msg_Dbg( p_input, msg_Dbg( p_input,
"connection(udp) at \"%s:%d\" successful", "connection(udp) at \"%s:%d\" successful",
p_sys->psz_bind_addr, p_sys->psz_bind_addr, 7000 );
7000 );
} }
else else
{ {
...@@ -564,7 +504,7 @@ static int MMSOpen( input_thread_t *p_input, ...@@ -564,7 +504,7 @@ static int MMSOpen( input_thread_t *p_input,
{ {
var_buffer_free( &buffer ); var_buffer_free( &buffer );
MMSClose( p_input ); MMSClose( p_input );
return( -1 ); return VLC_EGENERIC;
} }
i_server_version = GetDWLE( p_sys->p_cmd + MMS_CMD_HEADERSIZE + 32 ); i_server_version = GetDWLE( p_sys->p_cmd + MMS_CMD_HEADERSIZE + 32 );
...@@ -631,7 +571,7 @@ static int MMSOpen( input_thread_t *p_input, ...@@ -631,7 +571,7 @@ static int MMSOpen( input_thread_t *p_input,
"%s protocol selection failed", b_udp ? "UDP" : "TCP" ); "%s protocol selection failed", b_udp ? "UDP" : "TCP" );
var_buffer_free( &buffer ); var_buffer_free( &buffer );
MMSClose( p_input ); MMSClose( p_input );
return( -1 ); return VLC_EGENERIC;
} }
else if( p_sys->i_command != 0x02 ) else if( p_sys->i_command != 0x02 )
{ {
...@@ -660,7 +600,7 @@ static int MMSOpen( input_thread_t *p_input, ...@@ -660,7 +600,7 @@ static int MMSOpen( input_thread_t *p_input,
/* FIXME */ /* FIXME */
var_buffer_free( &buffer ); var_buffer_free( &buffer );
MMSClose( p_input ); MMSClose( p_input );
return( -1 ); return VLC_EGENERIC;
} }
if( p_sys->i_command != 0x06 ) if( p_sys->i_command != 0x06 )
{ {
...@@ -687,7 +627,7 @@ static int MMSOpen( input_thread_t *p_input, ...@@ -687,7 +627,7 @@ static int MMSOpen( input_thread_t *p_input,
GetDWLE( p_sys->p_cmd + MMS_CMD_HEADERSIZE ) ); GetDWLE( p_sys->p_cmd + MMS_CMD_HEADERSIZE ) );
var_buffer_free( &buffer ); var_buffer_free( &buffer );
MMSClose( p_input ); MMSClose( p_input );
return( -1 ); return VLC_EGENERIC;
} }
p_sys->i_flags_broadcast = p_sys->i_flags_broadcast =
...@@ -756,7 +696,7 @@ static int MMSOpen( input_thread_t *p_input, ...@@ -756,7 +696,7 @@ static int MMSOpen( input_thread_t *p_input,
msg_Err( p_input, "cannot receive header" ); msg_Err( p_input, "cannot receive header" );
var_buffer_free( &buffer ); var_buffer_free( &buffer );
MMSClose( p_input ); MMSClose( p_input );
return( -1 ); return VLC_EGENERIC;
} }
if( p_sys->i_header >= p_sys->i_header_size ) if( p_sys->i_header >= p_sys->i_header_size )
{ {
...@@ -834,7 +774,7 @@ static int MMSOpen( input_thread_t *p_input, ...@@ -834,7 +774,7 @@ static int MMSOpen( input_thread_t *p_input,
msg_Err( p_input, "cannot find any stream" ); msg_Err( p_input, "cannot find any stream" );
var_buffer_free( &buffer ); var_buffer_free( &buffer );
MMSClose( p_input ); MMSClose( p_input );
return( -1 ); return VLC_EGENERIC;
} }
mms_CommandSend( p_input, 0x33, mms_CommandSend( p_input, 0x33,
i_streams, i_streams,
...@@ -849,7 +789,7 @@ static int MMSOpen( input_thread_t *p_input, ...@@ -849,7 +789,7 @@ static int MMSOpen( input_thread_t *p_input,
p_sys->i_command ); p_sys->i_command );
var_buffer_free( &buffer ); var_buffer_free( &buffer );
MMSClose( p_input ); MMSClose( p_input );
return( -1 ); return VLC_EGENERIC;
} }
...@@ -857,7 +797,7 @@ static int MMSOpen( input_thread_t *p_input, ...@@ -857,7 +797,7 @@ static int MMSOpen( input_thread_t *p_input,
msg_Info( p_input, "connection sucessful" ); msg_Info( p_input, "connection sucessful" );
return( 0 ); return VLC_SUCCESS;
} }
/**************************************************************************** /****************************************************************************
...@@ -933,24 +873,12 @@ static int MMSClose ( input_thread_t *p_input ) ...@@ -933,24 +873,12 @@ static int MMSClose ( input_thread_t *p_input )
p_sys->i_command_level, p_sys->i_command_level,
0x00000001, 0x00000001,
NULL, 0 ); NULL, 0 );
/* *** close sockets *** */
#if defined( UNDER_CE )
CloseHandle( (HANDLE)p_sys->socket_tcp.i_handle );
#elif defined( WIN32 )
closesocket( p_sys->socket_tcp.i_handle );
#else
close( p_sys->socket_tcp.i_handle );
#endif
/* *** close sockets *** */
net_Close( p_sys->socket_tcp.i_handle );
if( p_sys->i_proto == MMS_PROTO_UDP ) if( p_sys->i_proto == MMS_PROTO_UDP )
{ {
#if defined( UNDER_CE ) net_Close( p_sys->socket_udp.i_handle );
CloseHandle( (HANDLE)p_sys->socket_udp.i_handle );
#elif defined( WIN32 )
closesocket( p_sys->socket_udp.i_handle );
#else
close( p_sys->socket_udp.i_handle );
#endif
} }
FREE( p_sys->p_cmd ); FREE( p_sys->p_cmd );
......
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