Commit df7cbb74 authored by Sam Hocevar's avatar Sam Hocevar

* ./Makefile.am: fixed rc compilation under mingw32/cygwin.

  * ./modules/access/http.c: fixed a segfault (unchecked strstr return value).
  * ./src/input/input_ext-plugins.c: removed platform-specific code and put
    it in plugins. This leads to some code duplication but I have an evil
    plan to get rid of that, too.
parent 901789ff
...@@ -479,7 +479,7 @@ DATA_win32_rc = $(noinst_share_vlc_win32_rc_DATA) ...@@ -479,7 +479,7 @@ DATA_win32_rc = $(noinst_share_vlc_win32_rc_DATA)
noinst_share_vlc_win32_rc_DATA = share/vlc_win32_rc.$(OBJEXT) noinst_share_vlc_win32_rc_DATA = share/vlc_win32_rc.$(OBJEXT)
noinst_share_vlc_win32_rcdir = $(libdir) noinst_share_vlc_win32_rcdir = $(libdir)
share/vlc_win32_rc.$(OBJEXT): share/vlc_win32_rc.rc share/vlc_win32_rc.$(OBJEXT): share/vlc_win32_rc.rc
$(WINDRES) -i $< -o $@ $(WINDRES) --include-dir share -i $< -o $@
endif endif
############################################################################### ###############################################################################
...@@ -558,7 +558,7 @@ DATA_npvlc_rc = $(noinst_mozilla_npvlc_rc_DATA) ...@@ -558,7 +558,7 @@ DATA_npvlc_rc = $(noinst_mozilla_npvlc_rc_DATA)
noinst_mozilla_npvlc_rc_DATA = mozilla/npvlc_rc.$(OBJEXT) noinst_mozilla_npvlc_rc_DATA = mozilla/npvlc_rc.$(OBJEXT)
noinst_mozilla_npvlc_rcdir = $(libdir) noinst_mozilla_npvlc_rcdir = $(libdir)
mozilla/npvlc_rc.$(OBJEXT): mozilla/npvlc_rc.rc mozilla/npvlc_rc.$(OBJEXT): mozilla/npvlc_rc.rc
$(WINDRES) -i $< -o $@ $(WINDRES) --include-dir mozilla -i $< -o $@
endif endif
endif endif
......
...@@ -122,6 +122,7 @@ case "x${target_os}" in ...@@ -122,6 +122,7 @@ case "x${target_os}" in
esac esac
if test "x$SYS" = "xmingw32"; then if test "x$SYS" = "xmingw32"; then
# add ws2_32 for closesocket, select, recv
CPPFLAGS_save="${CPPFLAGS_save} -D_OFF_T_ -D_off_t=long" CPPFLAGS_save="${CPPFLAGS_save} -D_OFF_T_ -D_off_t=long"
CPPFLAGS="${CPPFLAGS_save}" CPPFLAGS="${CPPFLAGS_save}"
LDFLAGS_vlc="${LDFLAGS_vlc} -lws2_32 -lnetapi32 -mwindows" LDFLAGS_vlc="${LDFLAGS_vlc} -lws2_32 -lnetapi32 -mwindows"
...@@ -129,6 +130,8 @@ case "x${target_os}" in ...@@ -129,6 +130,8 @@ case "x${target_os}" in
LDFLAGS_ipv6="${LDFLAGS_ipv6} -lws2_32" LDFLAGS_ipv6="${LDFLAGS_ipv6} -lws2_32"
LDFLAGS_access_http="${LDFLAGS_http} -lws2_32" LDFLAGS_access_http="${LDFLAGS_http} -lws2_32"
LDFLAGS_access_mms="${LDFLAGS_mms} -lws2_32" LDFLAGS_access_mms="${LDFLAGS_mms} -lws2_32"
LDFLAGS_access_rtp="${LDFLAGS_rtp} -lws2_32"
LDFLAGS_access_udp="${LDFLAGS_udp} -lws2_32"
LDFLAGS_rc="${LDFLAGS_rc} -lws2_32" LDFLAGS_rc="${LDFLAGS_rc} -lws2_32"
fi fi
;; ;;
...@@ -238,6 +241,9 @@ AC_CHECK_FUNC(connect,,[ ...@@ -238,6 +241,9 @@ AC_CHECK_FUNC(connect,,[
AC_CHECK_FUNC(send,,[ AC_CHECK_FUNC(send,,[
AC_CHECK_LIB(socket,send, AC_CHECK_LIB(socket,send,
LDFLAGS_http="${LDFLAGS_http} -lsocket" LDFLAGS_http="${LDFLAGS_http} -lsocket"
LDFLAGS_mms="${LDFLAGS_mms} -lsocket"
LDFLAGS_rtp="${LDFLAGS_rtp} -lsocket"
LDFLAGS_udp="${LDFLAGS_udp} -lsocket"
)]) )])
AC_CHECK_FUNC(gethostbyname,,[ AC_CHECK_FUNC(gethostbyname,,[
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* but exported to plug-ins * but exported to plug-ins
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2002 VideoLAN * Copyright (C) 1999-2002 VideoLAN
* $Id: input_ext-plugins.h,v 1.37 2002/11/11 14:39:11 sam Exp $ * $Id: input_ext-plugins.h,v 1.38 2002/11/12 13:57:12 sam Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -156,14 +156,3 @@ struct input_socket_t ...@@ -156,14 +156,3 @@ struct input_socket_t
int i_handle; int i_handle;
}; };
/*****************************************************************************
* Prototypes
*****************************************************************************/
VLC_EXPORT( void, __input_FDClose, ( vlc_object_t * ) );
#define input_FDClose(a) __input_FDClose(VLC_OBJECT(a))
VLC_EXPORT( void, __input_FDNetworkClose, ( vlc_object_t * ) );
#define input_FDNetworkClose(a) __input_FDNetworkClose(VLC_OBJECT(a))
VLC_EXPORT( ssize_t, input_FDRead, ( input_thread_t *, byte_t *, size_t ) );
VLC_EXPORT( ssize_t, input_FDNetworkRead, ( input_thread_t *, byte_t *, size_t ) );
VLC_EXPORT( void, input_FDSeek, ( input_thread_t *, off_t ) );
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* file.c: file input (file: access plug-in) * file.c: file input (file: access plug-in)
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: file.c,v 1.2 2002/09/30 11:05:34 sam Exp $ * $Id: file.c,v 1.3 2002/11/12 13:57:12 sam Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -36,10 +36,30 @@ ...@@ -36,10 +36,30 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#elif defined( _MSC_VER ) && defined( _WIN32 ) #elif defined( _MSC_VER ) && defined( _WIN32 ) && !defined( UNDER_CE )
# include <io.h> # include <io.h>
#endif #endif
/*****************************************************************************
* Exported prototypes
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static void Seek ( input_thread_t *, off_t );
static ssize_t Read ( input_thread_t *, byte_t *, size_t );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( _("Standard filesystem file reading") );
set_capability( "access", 50 );
add_shortcut( "file" );
add_shortcut( "stream" );
set_callbacks( Open, Close );
vlc_module_end();
/***************************************************************************** /*****************************************************************************
* Open: open the file * Open: open the file
*****************************************************************************/ *****************************************************************************/
...@@ -60,13 +80,13 @@ static int Open( vlc_object_t *p_this ) ...@@ -60,13 +80,13 @@ static int Open( vlc_object_t *p_this )
{ {
msg_Err( p_input, "cannot stat() file `%s' (%s)", msg_Err( p_input, "cannot stat() file `%s' (%s)",
psz_name, strerror(errno)); psz_name, strerror(errno));
return( -1 ); return VLC_EGENERIC;
} }
p_input->pf_read = input_FDRead; p_input->pf_read = Read;
p_input->pf_set_program = input_SetProgram; p_input->pf_set_program = input_SetProgram;
p_input->pf_set_area = NULL; p_input->pf_set_area = NULL;
p_input->pf_seek = input_FDSeek; p_input->pf_seek = Seek;
vlc_mutex_lock( &p_input->stream.stream_lock ); vlc_mutex_lock( &p_input->stream.stream_lock );
...@@ -106,7 +126,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -106,7 +126,7 @@ static int Open( vlc_object_t *p_this )
{ {
vlc_mutex_unlock( &p_input->stream.stream_lock ); vlc_mutex_unlock( &p_input->stream.stream_lock );
msg_Err( p_input, "unknown file type for `%s'", psz_name ); msg_Err( p_input, "unknown file type for `%s'", psz_name );
return( -1 ); return VLC_EGENERIC;
} }
} }
...@@ -120,7 +140,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -120,7 +140,7 @@ static int Open( vlc_object_t *p_this )
if( p_access_data == NULL ) if( p_access_data == NULL )
{ {
msg_Err( p_input, "out of memory" ); msg_Err( p_input, "out of memory" );
return( -1 ); return VLC_ENOMEM;
} }
if( b_stdin ) if( b_stdin )
...@@ -133,20 +153,85 @@ static int Open( vlc_object_t *p_this ) ...@@ -133,20 +153,85 @@ static int Open( vlc_object_t *p_this )
msg_Err( p_input, "cannot open file %s (%s)", psz_name, msg_Err( p_input, "cannot open file %s (%s)", psz_name,
strerror(errno) ); strerror(errno) );
free( p_access_data ); free( p_access_data );
return( -1 ); return VLC_EGENERIC;
} }
return( 0 ); return VLC_SUCCESS;
} }
/***************************************************************************** /*****************************************************************************
* Module descriptor * Close: close the target
*****************************************************************************/ *****************************************************************************/
vlc_module_begin(); static void Close( vlc_object_t * p_this )
set_description( _("Standard filesystem file reading") ); {
set_capability( "access", 50 ); input_thread_t * p_input = (input_thread_t *)p_this;
add_shortcut( "file" ); input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
add_shortcut( "stream" );
set_callbacks( Open, __input_FDClose ); msg_Info( p_input, "closing `%s/%s://%s'",
vlc_module_end(); p_input->psz_access, p_input->psz_demux, p_input->psz_name );
#ifdef UNDER_CE
CloseHandle( (HANDLE)p_access_data->i_handle );
#else
close( p_access_data->i_handle );
#endif
free( p_access_data );
}
/*****************************************************************************
* Read: standard read on a file descriptor.
*****************************************************************************/
static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
{
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
ssize_t i_ret;
#ifdef UNDER_CE
if( !ReadFile( (HANDLE)p_access_data->i_handle, p_buffer, i_len,
(LPWORD)&i_ret, NULL ) )
{
i_ret = -1;
}
#else
i_ret = read( p_access_data->i_handle, p_buffer, i_len );
#endif
if( i_ret < 0 )
{
# ifdef HAVE_ERRNO_H
msg_Err( p_input, "read failed (%s)", strerror(errno) );
# else
msg_Err( p_input, "read failed" );
# endif
}
return i_ret;
}
/*****************************************************************************
* Seek: seek to a specific location in a file
*****************************************************************************/
static void Seek( input_thread_t * p_input, off_t i_pos )
{
#define S p_input->stream
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
lseek( p_access_data->i_handle, i_pos, SEEK_SET );
vlc_mutex_lock( &S.stream_lock );
S.p_selected_area->i_tell = i_pos;
if( S.p_selected_area->i_tell > S.p_selected_area->i_size )
{
msg_Err( p_input, "seeking too far" );
S.p_selected_area->i_tell = S.p_selected_area->i_size;
}
else if( S.p_selected_area->i_tell < 0 )
{
msg_Err( p_input, "seeking too early" );
S.p_selected_area->i_tell = 0;
}
vlc_mutex_unlock( &S.stream_lock );
#undef S
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* http.c: HTTP access plug-in * http.c: HTTP access plug-in
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: http.c,v 1.8 2002/11/10 15:37:39 fenrir Exp $ * $Id: http.c,v 1.9 2002/11/12 13:57:12 sam Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -60,6 +60,7 @@ static void Close ( vlc_object_t * ); ...@@ -60,6 +60,7 @@ static void Close ( vlc_object_t * );
static int SetProgram ( input_thread_t *, pgrm_descriptor_t * ); static int SetProgram ( input_thread_t *, pgrm_descriptor_t * );
static void Seek ( input_thread_t *, off_t ); static void Seek ( input_thread_t *, off_t );
static ssize_t Read ( input_thread_t *, byte_t *, size_t );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
...@@ -98,15 +99,15 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell ) ...@@ -98,15 +99,15 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
byte_t * psz_parser; byte_t * psz_parser;
int i_returncode, i, i_size; int i_returncode, i, i_size;
char * psz_return_alpha; char * psz_return_alpha;
char *psz_protocol; char *psz_protocol;
/* Find an appropriate network module */ /* Find an appropriate network module */
p_access_data = (_input_socket_t *)p_input->p_access_data; p_access_data = (_input_socket_t *)p_input->p_access_data;
p_input->p_private = (void*) &p_access_data->socket_desc; p_input->p_private = (void*) &p_access_data->socket_desc;
p_network = module_Need( p_input, "network", p_access_data->psz_network ); p_network = module_Need( p_input, "network", p_access_data->psz_network );
if( p_network == NULL ) if( p_network == NULL )
{ {
return( -1 ); return VLC_ENOMOD;
} }
module_Unneed( p_input, p_network ); module_Unneed( p_input, p_network );
...@@ -137,8 +138,8 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell ) ...@@ -137,8 +138,8 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
strlen( psz_buffer ), 0 ) == (-1) ) strlen( psz_buffer ), 0 ) == (-1) )
{ {
msg_Err( p_input, "cannot send request (%s)", strerror(errno) ); msg_Err( p_input, "cannot send request (%s)", strerror(errno) );
input_FDNetworkClose( p_input ); Close( VLC_OBJECT(p_input) );
return( -1 ); return VLC_EGENERIC;
} }
/* Prepare the input thread for reading. */ /* Prepare the input thread for reading. */
...@@ -146,14 +147,14 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell ) ...@@ -146,14 +147,14 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
/* FIXME: we shouldn't have to do that ! It's UGLY but mandatory because /* FIXME: we shouldn't have to do that ! It's UGLY but mandatory because
* input_FillBuffer assumes p_input->pf_read exists */ * input_FillBuffer assumes p_input->pf_read exists */
p_input->pf_read = input_FDNetworkRead; p_input->pf_read = Read;
while( !input_FillBuffer( p_input ) ) while( !input_FillBuffer( p_input ) )
{ {
if( p_input->b_die || p_input->b_error ) if( p_input->b_die || p_input->b_error )
{ {
input_FDNetworkClose( p_input ); Close( VLC_OBJECT(p_input) );
return( -1 ); return VLC_EGENERIC;
} }
} }
...@@ -164,11 +165,11 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell ) ...@@ -164,11 +165,11 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
if( (i_size = input_Peek( p_input, &psz_parser, MAX_LINE )) <= 0 ) if( (i_size = input_Peek( p_input, &psz_parser, MAX_LINE )) <= 0 )
{ {
msg_Err( p_input, "not enough data" ); msg_Err( p_input, "not enough data" );
input_FDNetworkClose( p_input ); Close( VLC_OBJECT(p_input) );
return( -1 ); return VLC_EGENERIC;
} }
if( ( ( i_size >= sizeof("HTTP/1.") + 1 ) && if( ( ( i_size >= sizeof("HTTP/1.") + 1 ) &&
!strncmp( psz_parser, "HTTP/1.", sizeof("HTTP/1.") - 1 ) ) ) !strncmp( psz_parser, "HTTP/1.", strlen("HTTP/1.") ) ) )
{ {
psz_protocol = "HTTP"; psz_protocol = "HTTP";
} }
...@@ -185,7 +186,7 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell ) ...@@ -185,7 +186,7 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
else else
{ {
msg_Err( p_input, "invalid http reply" ); msg_Err( p_input, "invalid http reply" );
return -1; return VLC_EGENERIC;
} }
msg_Dbg( p_input, "detected %s server", psz_protocol ); msg_Dbg( p_input, "detected %s server", psz_protocol );
...@@ -213,7 +214,7 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell ) ...@@ -213,7 +214,7 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
if ( (i == i_size - 1) && (psz_parser[i+1] != '\n') ) if ( (i == i_size - 1) && (psz_parser[i+1] != '\n') )
{ {
msg_Err( p_input, "stream not compliant with HTTP/1.x" ); msg_Err( p_input, "stream not compliant with HTTP/1.x" );
return -1; return VLC_EGENERIC;
} }
psz_return_alpha = malloc( i + 1 ); psz_return_alpha = malloc( i + 1 );
...@@ -222,9 +223,8 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell ) ...@@ -222,9 +223,8 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
if ( i_returncode >= 400 ) /* something is wrong */ if ( i_returncode >= 400 ) /* something is wrong */
{ {
msg_Err( p_input, "%i %s", i_returncode, msg_Err( p_input, "%i %s", i_returncode, psz_return_alpha );
psz_return_alpha ); return VLC_EGENERIC;
return -1;
} }
for( ; ; ) for( ; ; )
...@@ -232,8 +232,8 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell ) ...@@ -232,8 +232,8 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
if( input_Peek( p_input, &psz_parser, MAX_LINE ) <= 0 ) if( input_Peek( p_input, &psz_parser, MAX_LINE ) <= 0 )
{ {
msg_Err( p_input, "not enough data" ); msg_Err( p_input, "not enough data" );
input_FDNetworkClose( p_input ); Close( VLC_OBJECT(p_input) );
return( -1 ); return VLC_EGENERIC;
} }
if( psz_parser[0] == '\r' && psz_parser[1] == '\n' ) if( psz_parser[0] == '\r' && psz_parser[1] == '\n' )
...@@ -284,7 +284,7 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell ) ...@@ -284,7 +284,7 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
p_input->stream.b_changed = 1; p_input->stream.b_changed = 1;
vlc_mutex_unlock( &p_input->stream.stream_lock ); vlc_mutex_unlock( &p_input->stream.stream_lock );
return( 0 ); return VLC_SUCCESS;
} }
/***************************************************************************** /*****************************************************************************
...@@ -479,7 +479,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -479,7 +479,7 @@ static int Open( vlc_object_t *p_this )
msg_Dbg( p_input, "opening server=%s port=%d path=%s", msg_Dbg( p_input, "opening server=%s port=%d path=%s",
psz_server_addr, i_server_port, psz_path ); psz_server_addr, i_server_port, psz_path );
p_input->pf_read = input_FDNetworkRead; p_input->pf_read = Read;
p_input->pf_set_program = SetProgram; p_input->pf_set_program = SetProgram;
p_input->pf_set_area = NULL; p_input->pf_set_area = NULL;
p_input->pf_seek = Seek; p_input->pf_seek = Seek;
...@@ -495,17 +495,25 @@ static int Open( vlc_object_t *p_this ) ...@@ -495,17 +495,25 @@ static int Open( vlc_object_t *p_this )
if( HTTPConnect( p_input, 0 ) ) if( HTTPConnect( p_input, 0 ) )
{ {
char * psz_pos = strstr(p_access_data->psz_buffer, "HTTP/1.1"); /* Request failed, try again with HTTP/1.0 */
char * psz_pos = strstr( p_access_data->psz_buffer, "HTTP/1.1" );
if( !psz_pos )
{
return VLC_EGENERIC;
}
p_input->stream.b_seekable = 0; p_input->stream.b_seekable = 0;
psz_pos[7] = '0'; psz_pos[7] = '0';
if( HTTPConnect( p_input, 0 ) ) if( HTTPConnect( p_input, 0 ) )
{ {
free( p_input->p_access_data ); free( p_input->p_access_data );
free( psz_name ); free( psz_name );
return( -1 ); return VLC_EGENERIC;
} }
} }
return 0;
return VLC_SUCCESS;
} }
/***************************************************************************** /*****************************************************************************
...@@ -514,11 +522,23 @@ static int Open( vlc_object_t *p_this ) ...@@ -514,11 +522,23 @@ static int Open( vlc_object_t *p_this )
static void Close( vlc_object_t *p_this ) static void Close( 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_handle = ((network_socket_t *)p_input->p_access_data)->i_handle;
_input_socket_t * p_access_data = _input_socket_t * p_access_data =
(_input_socket_t *)p_input->p_access_data; (_input_socket_t *)p_input->p_access_data;
free( p_access_data->psz_name ); free( p_access_data->psz_name );
input_FDNetworkClose( p_input );
msg_Info( p_input, "closing HTTP target `%s'", p_input->psz_source );
#ifdef UNDER_CE
CloseHandle( (HANDLE)i_handle );
#elif defined( WIN32 )
closesocket( i_handle );
#else
close( i_handle );
#endif
free( p_access_data );
} }
/***************************************************************************** /*****************************************************************************
...@@ -536,8 +556,68 @@ static int SetProgram( input_thread_t * p_input, ...@@ -536,8 +556,68 @@ static int SetProgram( input_thread_t * p_input,
static void Seek( input_thread_t * p_input, off_t i_pos ) static void Seek( input_thread_t * p_input, off_t i_pos )
{ {
_input_socket_t *p_access_data = (_input_socket_t*)p_input->p_access_data; _input_socket_t *p_access_data = (_input_socket_t*)p_input->p_access_data;
#ifdef UNDER_CE
CloseHandle( (HANDLE)p_access_data->_socket.i_handle );
#elif defined( WIN32 )
closesocket( p_access_data->_socket.i_handle );
#else
close( p_access_data->_socket.i_handle ); close( p_access_data->_socket.i_handle );
#endif
msg_Dbg( p_input, "seeking to position "I64Fd, i_pos ); msg_Dbg( p_input, "seeking to position "I64Fd, i_pos );
HTTPConnect( p_input, i_pos ); HTTPConnect( p_input, i_pos );
} }
/*****************************************************************************
* Read: read on a file descriptor, checking b_die periodically
*****************************************************************************/
static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
{
#ifdef UNDER_CE
return -1;
#else
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
struct timeval timeout;
fd_set fds;
int i_ret;
/* Initialize file descriptor set */
FD_ZERO( &fds );
FD_SET( p_access_data->i_handle, &fds );
/* We'll wait 0.5 second if nothing happens */
timeout.tv_sec = 0;
timeout.tv_usec = 500000;
/* Find if some data is available */
i_ret = select( p_access_data->i_handle + 1, &fds,
NULL, NULL, &timeout );
if( i_ret == -1 && errno != EINTR )
{
msg_Err( p_input, "network select error (%s)", strerror(errno) );
}
else if( i_ret > 0 )
{
ssize_t i_recv = recv( p_access_data->i_handle, p_buffer, i_len, 0 );
if( i_recv > 0 )
{
vlc_mutex_lock( &p_input->stream.stream_lock );
p_input->stream.p_selected_area->i_tell += i_recv;
vlc_mutex_unlock( &p_input->stream.stream_lock );
}
if( i_recv < 0 )
{
msg_Err( p_input, "recv failed (%s)", strerror(errno) );
}
return i_recv;
}
return 0;
#endif
}
...@@ -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: mms.c,v 1.1 2002/11/12 00:54:40 fenrir Exp $ * $Id: mms.c,v 1.2 2002/11/12 13:57:12 sam Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -75,6 +75,8 @@ static void Close ( vlc_object_t * ); ...@@ -75,6 +75,8 @@ static void Close ( vlc_object_t * );
static int Read ( input_thread_t * p_input, byte_t * p_buffer, static int Read ( input_thread_t * p_input, byte_t * p_buffer,
size_t i_len ); size_t i_len );
static ssize_t NetRead ( input_thread_t * p_input, input_socket_t * p_socket,
byte_t * p_buffer, size_t i_len );
static void Seek ( input_thread_t *, off_t ); static void Seek ( input_thread_t *, off_t );
static int SetProgram ( input_thread_t *, pgrm_descriptor_t * ); static int SetProgram ( input_thread_t *, pgrm_descriptor_t * );
...@@ -102,16 +104,10 @@ static void mms_ParseURL( url_t *p_url, char *psz_url ); ...@@ -102,16 +104,10 @@ 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
* non mais :P * non mais :P
*/ */
#define INPUT_FDNETWORKCLOSE( p_input ) \
{ \
void *__p_access = p_input->p_access_data; \
input_socket_t *__p_socket = malloc( sizeof( input_socket_t ) ); \
memcpy( __p_socket, __p_access, sizeof( input_socket_t ) ); \
p_input->p_access_data = (void*)__p_socket; \
input_FDNetworkClose( p_input ); \
p_input->p_access_data = __p_access; \
}
/*
* Ok, ok, j'le ferai plus...
*/
/***************************************************************************** /*****************************************************************************
...@@ -394,6 +390,59 @@ static int Read ( input_thread_t * p_input, byte_t * p_buffer, ...@@ -394,6 +390,59 @@ static int Read ( input_thread_t * p_input, byte_t * p_buffer,
return( i_data ); return( i_data );
} }
/*****************************************************************************
* NetRead: 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 )
{
#ifdef UNDER_CE
return -1;
#else
struct timeval timeout;
fd_set fds;
int i_ret;
/* Initialize file descriptor set */
FD_ZERO( &fds );
FD_SET( p_socket->i_handle, &fds );
/* We'll wait 0.5 second if nothing happens */
timeout.tv_sec = 0;
timeout.tv_usec = 500000;
/* Find if some data is available */
i_ret = select( p_socket->i_handle + 1, &fds,
NULL, NULL, &timeout );
if( i_ret == -1 && errno != EINTR )
{
msg_Err( p_input, "network select error (%s)", strerror(errno) );
}
else if( i_ret > 0 )
{
ssize_t i_recv = recv( p_socket->i_handle, p_buffer, i_len, 0 );
if( i_recv > 0 )
{
vlc_mutex_lock( &p_input->stream.stream_lock );
p_input->stream.p_selected_area->i_tell += i_recv;
vlc_mutex_unlock( &p_input->stream.stream_lock );
}
if( i_recv < 0 )
{
msg_Err( p_input, "recv failed (%s)", strerror(errno) );
}
return i_recv;
}
return 0;
#endif
}
static void asf_HeaderParse( mms_stream_t stream[128], static void asf_HeaderParse( mms_stream_t stream[128],
uint8_t *p_header, int i_header ) uint8_t *p_header, int i_header )
...@@ -534,12 +583,15 @@ static int MMSOpen( input_thread_t *p_input, ...@@ -534,12 +583,15 @@ static int MMSOpen( input_thread_t *p_input,
msg_Err( p_input, msg_Err( p_input,
"MMS/UDP not yet implemented" ); "MMS/UDP not yet implemented" );
// close socket // close socket
p_access->_socket = p_access->socket_server; #if defined( UNDER_CE )
INPUT_FDNETWORKCLOSE( p_input ); CloseHandle( (HANDLE)p_access->socket_server.i_handle );
#elif defined( WIN32 )
closesocket( p_access->socket_server.i_handle );
#else
close( p_access->socket_server.i_handle );
#endif
return( -1 ); return( -1 );
} }
/* *** Default socket is the one for server communication *** */
p_access->_socket = p_access->socket_server;
/* *** Init context for mms prototcol *** */ /* *** Init context for mms prototcol *** */
GenerateGuid( &p_access->guid ); // used to identify client by server GenerateGuid( &p_access->guid ); // used to identify client by server
...@@ -916,13 +968,23 @@ static int MMSClose ( input_thread_t *p_input ) ...@@ -916,13 +968,23 @@ static int MMSClose ( input_thread_t *p_input )
0x00000001, 0x00000001,
NULL, 0 ); NULL, 0 );
/* *** close sockets *** */ /* *** close sockets *** */
p_access->_socket = p_access->socket_server; #if defined( UNDER_CE )
INPUT_FDNETWORKCLOSE( p_input ); CloseHandle( (HANDLE)p_access->socket_server.i_handle );
#elif defined( WIN32 )
closesocket( p_access->socket_server.i_handle );
#else
close( p_access->socket_server.i_handle );
#endif
if( p_access->i_proto == MMS_PROTO_UDP ) if( p_access->i_proto == MMS_PROTO_UDP )
{ {
p_access->_socket = p_access->socket_data; #if defined( UNDER_CE )
INPUT_FDNETWORKCLOSE( p_input ); CloseHandle( (HANDLE)p_access->socket_data.i_handle );
#elif defined( WIN32 )
closesocket( p_access->socket_data.i_handle );
#else
close( p_access->socket_data.i_handle );
#endif
} }
FREE( p_access->p_media ); FREE( p_access->p_media );
...@@ -995,11 +1057,13 @@ static int mms_ReadData( input_thread_t *p_input, ...@@ -995,11 +1057,13 @@ static int mms_ReadData( input_thread_t *p_input,
uint8_t *p_data, uint8_t *p_data,
int i_data ) int i_data )
{ {
access_t *p_access = (access_t*)p_input->p_access_data;
int i_read; int i_read;
while( i_data > 0 ) while( i_data > 0 )
{ {
i_read = input_FDNetworkRead( p_input, p_data, i_data ); i_read = NetRead( p_input, &p_access->socket_server, p_data, i_data );
if( i_read < 0 ) if( i_read < 0 )
{ {
msg_Err( p_input, "failed to read data" ); msg_Err( p_input, "failed to read data" );
...@@ -1053,7 +1117,7 @@ static int mms_CommandSend( input_thread_t *p_input, ...@@ -1053,7 +1117,7 @@ static int mms_CommandSend( input_thread_t *p_input,
} }
/* send it */ /* send it */
if( send( p_access->_socket.i_handle, if( send( p_access->socket_server.i_handle,
buffer.p_data, buffer.p_data,
buffer.i_data, buffer.i_data,
0 ) == -1 ) 0 ) == -1 )
...@@ -1081,8 +1145,8 @@ static int mms_ReceiveCommand( input_thread_t *p_input ) ...@@ -1081,8 +1145,8 @@ static int mms_ReceiveCommand( input_thread_t *p_input )
// see for UDP mode // see for UDP mode
/* *** Read complete command *** */ /* *** Read complete command *** */
p_access->i_cmd = p_access->i_cmd = NetRead( p_input, &p_access->socket_server,
input_FDNetworkRead( p_input, p_access->p_cmd, BUF_SIZE ); p_access->p_cmd, BUF_SIZE );
if( p_access->i_cmd < 12 ) if( p_access->i_cmd < 12 )
{ {
msg_Warn( p_input, "failed to receive command" ); msg_Warn( p_input, "failed to receive command" );
...@@ -1188,7 +1252,8 @@ static int mms_ReceivePacket( input_thread_t *p_input ) ...@@ -1188,7 +1252,8 @@ static int mms_ReceivePacket( input_thread_t *p_input )
{ {
for( ;; ) for( ;; )
{ {
if( ( i_read = input_FDNetworkRead( p_input, preheader, 8 ) ) < 8 ) i_read = NetRead( p_input, &p_access->socket_server, preheader, 8 );
if( i_read < 8 )
{ {
msg_Warn( p_input, "cannot read preheader" ); msg_Warn( p_input, "cannot read preheader" );
return( -1 ); return( -1 );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mms.h: MMS access plug-in * mms.h: MMS access plug-in
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: mms.h,v 1.1 2002/11/12 00:54:40 fenrir Exp $ * $Id: mms.h,v 1.2 2002/11/12 13:57:13 sam Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -64,9 +64,6 @@ typedef struct mms_stream_s ...@@ -64,9 +64,6 @@ typedef struct mms_stream_s
typedef struct access_s typedef struct access_s
{ {
/* XXX must be the first field because of __input_FD* XXX */
input_socket_t _socket;
int i_proto; // MMS_PROTO_TCP, MMS_PROTO_UDP int i_proto; // MMS_PROTO_TCP, MMS_PROTO_UDP
input_socket_t socket_server; // TCP socket for communication with server input_socket_t socket_server; // TCP socket for communication with server
input_socket_t socket_data; // Optional UDP socket for data(media/header packet) input_socket_t socket_data; // Optional UDP socket for data(media/header packet)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* rtp.c: RTP access plug-in * rtp.c: RTP access plug-in
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: rtp.c,v 1.4 2002/10/03 21:45:16 massiot Exp $ * $Id: rtp.c,v 1.5 2002/11/12 13:57:12 sam Exp $
* *
* Authors: Tristan Leteurtre <tooney@via.ecp.fr> * Authors: Tristan Leteurtre <tooney@via.ecp.fr>
* *
...@@ -40,6 +40,16 @@ ...@@ -40,6 +40,16 @@
# include <io.h> # include <io.h>
#endif #endif
#ifdef WIN32
# include <winsock2.h>
# include <ws2tcpip.h>
# ifndef IN_MULTICAST
# define IN_MULTICAST(a) IN_CLASSD(a)
# endif
#else
# include <sys/socket.h>
#endif
#ifdef HAVE_ALLOCA_H #ifdef HAVE_ALLOCA_H
# include <alloca.h> # include <alloca.h>
#endif #endif
...@@ -52,7 +62,9 @@ ...@@ -52,7 +62,9 @@
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
static int Open ( vlc_object_t * ); static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static ssize_t RTPNetworkRead( input_thread_t *, byte_t *, size_t ); static ssize_t RTPNetworkRead( input_thread_t *, byte_t *, size_t );
static ssize_t Read ( input_thread_t *, byte_t *, size_t );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
...@@ -64,7 +76,7 @@ vlc_module_begin(); ...@@ -64,7 +76,7 @@ vlc_module_begin();
add_shortcut( "rtpstream" ); add_shortcut( "rtpstream" );
add_shortcut( "rtp4" ); add_shortcut( "rtp4" );
add_shortcut( "rtp6" ); add_shortcut( "rtp6" );
set_callbacks( Open, __input_FDNetworkClose ); set_callbacks( Open, Close );
vlc_module_end(); vlc_module_end();
/***************************************************************************** /*****************************************************************************
...@@ -262,6 +274,27 @@ static int Open( vlc_object_t *p_this ) ...@@ -262,6 +274,27 @@ static int Open( vlc_object_t *p_this )
return( 0 ); return( 0 );
} }
/*****************************************************************************
* Close: free unused data structures
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
input_thread_t * p_input = (input_thread_t *)p_this;
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
msg_Info( p_input, "closing RTP target `%s'", p_input->psz_source );
#ifdef UNDER_CE
CloseHandle( (HANDLE)p_access_data->i_handle );
#elif defined( WIN32 )
closesocket( p_access_data->i_handle );
#else
close( p_access_data->i_handle );
#endif
free( p_access_data );
}
/***************************************************************************** /*****************************************************************************
* RTPNetworkRead : Read for the network, and parses the RTP header * RTPNetworkRead : Read for the network, and parses the RTP header
*****************************************************************************/ *****************************************************************************/
...@@ -276,8 +309,7 @@ static ssize_t RTPNetworkRead( input_thread_t * p_input, byte_t * p_buffer, ...@@ -276,8 +309,7 @@ static ssize_t RTPNetworkRead( input_thread_t * p_input, byte_t * p_buffer,
/* Get the raw data from the socket. /* Get the raw data from the socket.
* We first assume that RTP header size is the classic RTP_HEADER_LEN. */ * We first assume that RTP header size is the classic RTP_HEADER_LEN. */
ssize_t i_ret = input_FDNetworkRead( p_input, p_tmp_buffer, ssize_t i_ret = Read( p_input, p_tmp_buffer, p_input->i_mtu );
p_input->i_mtu );
if (!i_ret) return 0; if (!i_ret) return 0;
...@@ -311,3 +343,58 @@ static ssize_t RTPNetworkRead( input_thread_t * p_input, byte_t * p_buffer, ...@@ -311,3 +343,58 @@ static ssize_t RTPNetworkRead( input_thread_t * p_input, byte_t * p_buffer,
return i_ret; return i_ret;
} }
/*****************************************************************************
* Read: read on a file descriptor, checking b_die periodically
*****************************************************************************/
static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
{
#ifdef UNDER_CE
return -1;
#else
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
struct timeval timeout;
fd_set fds;
int i_ret;
/* Initialize file descriptor set */
FD_ZERO( &fds );
FD_SET( p_access_data->i_handle, &fds );
/* We'll wait 0.5 second if nothing happens */
timeout.tv_sec = 0;
timeout.tv_usec = 500000;
/* Find if some data is available */
i_ret = select( p_access_data->i_handle + 1, &fds,
NULL, NULL, &timeout );
if( i_ret == -1 && errno != EINTR )
{
msg_Err( p_input, "network select error (%s)", strerror(errno) );
}
else if( i_ret > 0 )
{
ssize_t i_recv = recv( p_access_data->i_handle, p_buffer, i_len, 0 );
if( i_recv > 0 )
{
vlc_mutex_lock( &p_input->stream.stream_lock );
p_input->stream.p_selected_area->i_tell += i_recv;
vlc_mutex_unlock( &p_input->stream.stream_lock );
}
if( i_recv < 0 )
{
msg_Err( p_input, "recv failed (%s)", strerror(errno) );
}
return i_recv;
}
return 0;
#endif
}
...@@ -326,13 +326,15 @@ void E_(Close) ( vlc_object_t *p_this ) ...@@ -326,13 +326,15 @@ void E_(Close) ( vlc_object_t *p_this )
close( p_satellite->i_handle ); close( p_satellite->i_handle );
} }
/***************************************************************************** /*****************************************************************************
* SatelliteRead: reads data from the satellite card * SatelliteRead: reads data from the satellite card
*****************************************************************************/ *****************************************************************************/
static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer, static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
size_t i_len ) size_t i_len )
{ {
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
ssize_t i_ret;
int i; int i;
/* if not set, set filters to the PMTs */ /* if not set, set filters to the PMTs */
...@@ -348,11 +350,19 @@ static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer, ...@@ -348,11 +350,19 @@ static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
} }
} }
return input_FDRead( p_input, p_buffer, i_len ); i_ret = read( p_access_data->i_handle, p_buffer, i_len );
}
if( i_ret < 0 )
{
# ifdef HAVE_ERRNO_H
msg_Err( p_input, "read failed (%s)", strerror(errno) );
# else
msg_Err( p_input, "read failed" );
# endif
}
return i_ret;
}
/***************************************************************************** /*****************************************************************************
* SatelliteSetArea : Does nothing * SatelliteSetArea : Does nothing
...@@ -423,7 +433,7 @@ int SatelliteSetProgram( input_thread_t * p_input, ...@@ -423,7 +433,7 @@ int SatelliteSetProgram( input_thread_t * p_input,
p_input->stream.p_selected_program = p_new_prg; p_input->stream.p_selected_program = p_new_prg;
return( 0 ); return 0;
} }
/***************************************************************************** /*****************************************************************************
...@@ -431,5 +441,6 @@ int SatelliteSetProgram( input_thread_t * p_input, ...@@ -431,5 +441,6 @@ int SatelliteSetProgram( input_thread_t * p_input,
*****************************************************************************/ *****************************************************************************/
static void SatelliteSeek( input_thread_t * p_input, off_t i_off ) static void SatelliteSeek( input_thread_t * p_input, off_t i_off )
{ {
return; ;
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* udp.c: raw UDP access plug-in * udp.c: raw UDP access plug-in
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: udp.c,v 1.3 2002/09/30 11:05:34 sam Exp $ * $Id: udp.c,v 1.4 2002/11/12 13:57:12 sam Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -40,12 +40,24 @@ ...@@ -40,12 +40,24 @@
# include <io.h> # include <io.h>
#endif #endif
#ifdef 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"
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
static int Open ( vlc_object_t * ); static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static ssize_t Read ( input_thread_t *, byte_t *, size_t );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
...@@ -57,7 +69,7 @@ vlc_module_begin(); ...@@ -57,7 +69,7 @@ vlc_module_begin();
add_shortcut( "udpstream" ); add_shortcut( "udpstream" );
add_shortcut( "udp4" ); add_shortcut( "udp4" );
add_shortcut( "udp6" ); add_shortcut( "udp6" );
set_callbacks( Open, __input_FDNetworkClose ); set_callbacks( Open, Close );
vlc_module_end(); vlc_module_end();
/***************************************************************************** /*****************************************************************************
...@@ -193,7 +205,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -193,7 +205,7 @@ static int Open( vlc_object_t *p_this )
} }
} }
p_input->pf_read = input_FDNetworkRead; p_input->pf_read = Read;
p_input->pf_set_program = input_SetProgram; p_input->pf_set_program = input_SetProgram;
p_input->pf_set_area = NULL; p_input->pf_set_area = NULL;
p_input->pf_seek = NULL; p_input->pf_seek = NULL;
...@@ -252,3 +264,79 @@ static int Open( vlc_object_t *p_this ) ...@@ -252,3 +264,79 @@ static int Open( vlc_object_t *p_this )
return( 0 ); return( 0 );
} }
/*****************************************************************************
* Close: free unused data structures
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
input_thread_t * p_input = (input_thread_t *)p_this;
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
msg_Info( p_input, "closing UDP target `%s'", p_input->psz_source );
#ifdef UNDER_CE
CloseHandle( (HANDLE)p_access_data->i_handle );
#elif defined( WIN32 )
closesocket( p_access_data->i_handle );
#else
close( p_access_data->i_handle );
#endif
free( p_access_data );
}
/*****************************************************************************
* Read: read on a file descriptor, checking b_die periodically
*****************************************************************************/
static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
{
#ifdef UNDER_CE
return -1;
#else
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
struct timeval timeout;
fd_set fds;
int i_ret;
/* Initialize file descriptor set */
FD_ZERO( &fds );
FD_SET( p_access_data->i_handle, &fds );
/* We'll wait 0.5 second if nothing happens */
timeout.tv_sec = 0;
timeout.tv_usec = 500000;
/* Find if some data is available */
i_ret = select( p_access_data->i_handle + 1, &fds,
NULL, NULL, &timeout );
if( i_ret == -1 && errno != EINTR )
{
msg_Err( p_input, "network select error (%s)", strerror(errno) );
}
else if( i_ret > 0 )
{
ssize_t i_recv = recv( p_access_data->i_handle, p_buffer, i_len, 0 );
if( i_recv > 0 )
{
vlc_mutex_lock( &p_input->stream.stream_lock );
p_input->stream.p_selected_area->i_tell += i_recv;
vlc_mutex_unlock( &p_input->stream.stream_lock );
}
if( i_recv < 0 )
{
msg_Err( p_input, "recv failed (%s)", strerror(errno) );
}
return i_recv;
}
return 0;
#endif
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* common.c : audio output management of common data structures * common.c : audio output management of common data structures
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: common.c,v 1.6 2002/11/01 15:06:23 gbazin Exp $ * $Id: common.c,v 1.7 2002/11/12 13:57:13 sam Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -320,8 +320,7 @@ mtime_t aout_FifoNextStart( aout_instance_t * p_aout, aout_fifo_t * p_fifo ) ...@@ -320,8 +320,7 @@ mtime_t aout_FifoNextStart( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
*****************************************************************************/ *****************************************************************************/
mtime_t aout_FifoFirstDate( aout_instance_t * p_aout, aout_fifo_t * p_fifo ) mtime_t aout_FifoFirstDate( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
{ {
return p_fifo->p_first ? return p_fifo->p_first ? p_fifo->p_first->start_date : 0;
aout_DateGet( &p_fifo->p_first->start_date ) : 0;
} }
/***************************************************************************** /*****************************************************************************
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* input_ext-plugins.c: useful functions for access and demux plug-ins * input_ext-plugins.c: useful functions for access and demux plug-ins
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: input_ext-plugins.c,v 1.22 2002/11/11 14:39:12 sam Exp $ * $Id: input_ext-plugins.c,v 1.23 2002/11/12 13:57:13 sam Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -29,38 +29,6 @@ ...@@ -29,38 +29,6 @@
#include <vlc/vlc.h> #include <vlc/vlc.h>
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#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>
#elif defined( _MSC_VER ) && defined( _WIN32 ) && !defined( UNDER_CE )
# include <io.h>
#endif
#ifdef UNDER_CE
/* No network support (FIXME: use winsock1?) */
#elif defined( WIN32 )
# include <winsock2.h>
# include <ws2tcpip.h>
#elif !defined( SYS_BEOS ) && !defined( SYS_NTO )
# include <sys/types.h>
# include <sys/socket.h> /* recv() */
#endif
#include "stream_control.h" #include "stream_control.h"
#include "input_ext-intf.h" #include "input_ext-intf.h"
#include "input_ext-dec.h" #include "input_ext-dec.h"
...@@ -652,182 +620,3 @@ void input_AccessEnd( input_thread_t * p_input ) ...@@ -652,182 +620,3 @@ void input_AccessEnd( input_thread_t * p_input )
input_BuffersEnd( p_input, p_input->p_method_data ); input_BuffersEnd( p_input, p_input->p_method_data );
} }
/*
* Optional file descriptor management functions, for use by access plug-ins
* base on file descriptors (file, udp, http...).
*/
/*****************************************************************************
* input_FDClose: close the target
*****************************************************************************/
void __input_FDClose( vlc_object_t * p_this )
{
input_thread_t * p_input = (input_thread_t *)p_this;
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
msg_Info( p_input, "closing `%s/%s://%s'",
p_input->psz_access, p_input->psz_demux, p_input->psz_name );
#ifdef UNDER_CE
CloseHandle( (HANDLE)p_access_data->i_handle );
#else
close( p_access_data->i_handle );
#endif
free( p_access_data );
}
/*****************************************************************************
* input_FDNetworkClose: close a network target
*****************************************************************************/
void __input_FDNetworkClose( vlc_object_t * p_this )
{
input_thread_t * p_input = (input_thread_t *)p_this;
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
msg_Info( p_input, "closing network `%s/%s://%s'",
p_input->psz_access, p_input->psz_demux, p_input->psz_name );
#ifdef UNDER_CE
CloseHandle( (HANDLE)p_access_data->i_handle );
#elif defined( WIN32 )
closesocket( p_access_data->i_handle );
#else
close( p_access_data->i_handle );
#endif
free( p_access_data );
}
/*****************************************************************************
* input_FDRead: standard read on a file descriptor.
*****************************************************************************/
ssize_t input_FDRead( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
{
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
ssize_t i_ret;
#ifdef UNDER_CE
if( !ReadFile( (HANDLE)p_access_data->i_handle, p_buffer, i_len,
(LPWORD)&i_ret, NULL ) )
{
i_ret = -1;
}
#else
i_ret = read( p_access_data->i_handle, p_buffer, i_len );
#endif
if( i_ret < 0 )
{
# ifdef HAVE_ERRNO_H
msg_Err( p_input, "read failed (%s)", strerror(errno) );
# else
msg_Err( p_input, "read failed" );
# endif
}
return i_ret;
}
/*****************************************************************************
* NetworkSelect: Checks whether data is available on a file descriptor
*****************************************************************************/
static inline int NetworkSelect( input_thread_t * p_input )
{
#ifdef UNDER_CE
return -1;
#else
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
struct timeval timeout;
fd_set fds;
int i_ret;
/* Initialize file descriptor set */
FD_ZERO( &fds );
FD_SET( p_access_data->i_handle, &fds );
/* We'll wait 0.5 second if nothing happens */
timeout.tv_sec = 0;
timeout.tv_usec = 500000;
/* Find if some data is available */
i_ret = select( p_access_data->i_handle + 1, &fds,
NULL, NULL, &timeout );
if( i_ret == -1 && errno != EINTR )
{
msg_Err( p_input, "network select error (%s)", strerror(errno) );
}
return i_ret;
#endif
}
/*****************************************************************************
* input_FDNetworkRead: read on a file descriptor, checking periodically
* p_input->b_die
*****************************************************************************/
ssize_t input_FDNetworkRead( input_thread_t * p_input, byte_t * p_buffer,
size_t i_len )
{
#ifdef UNDER_CE
return -1;
#else
if( NetworkSelect( p_input ) > 0 )
{
input_socket_t * p_access_data
= (input_socket_t *)p_input->p_access_data;
ssize_t i_ret = recv( p_access_data->i_handle, p_buffer, i_len, 0 );
if( i_ret > 0 )
{
vlc_mutex_lock( &p_input->stream.stream_lock );
p_input->stream.p_selected_area->i_tell += i_ret;
vlc_mutex_unlock( &p_input->stream.stream_lock );
}
if( i_ret < 0 )
{
msg_Err( p_input, "recv failed (%s)", strerror(errno) );
}
return i_ret;
}
return 0;
#endif
}
/*****************************************************************************
* input_FDSeek: seek to a specific location in a file
*****************************************************************************/
void input_FDSeek( input_thread_t * p_input, off_t i_pos )
{
#define S p_input->stream
input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
lseek( p_access_data->i_handle, i_pos, SEEK_SET );
vlc_mutex_lock( &S.stream_lock );
S.p_selected_area->i_tell = i_pos;
if( S.p_selected_area->i_tell > S.p_selected_area->i_size )
{
msg_Err( p_input, "seeking too far" );
S.p_selected_area->i_tell = S.p_selected_area->i_size;
}
else if( S.p_selected_area->i_tell < 0 )
{
msg_Err( p_input, "seeking too early" );
S.p_selected_area->i_tell = 0;
}
vlc_mutex_unlock( &S.stream_lock );
#undef S
}
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