* http.c: HTTP access plug-in
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
- * $Id: http.c,v 1.15 2002/12/06 12:54:30 sam Exp $
+ * $Id: http.c,v 1.35 2003/05/15 22:27:36 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
# 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
#if defined( UNDER_CE )
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
-static int SetProgram ( input_thread_t *, pgrm_descriptor_t * );
static void Seek ( input_thread_t *, off_t );
static ssize_t Read ( input_thread_t *, byte_t *, size_t );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
-#define PROXY_TEXT N_("specify an HTTP proxy")
+#define PROXY_TEXT N_("Specify an HTTP proxy")
#define PROXY_LONGTEXT N_( \
"Specify an HTTP proxy to use. It must be in the form " \
- "http://myproxy.mydomain:myport . If none is specified, the HTTP_PROXY" \
+ "http://myproxy.mydomain:myport. If none is specified, the HTTP_PROXY " \
"environment variable will be tried." )
+#define CACHING_TEXT N_("Caching value in ms")
+#define CACHING_LONGTEXT N_( \
+ "Allows you to modify the default caching value for http streams. This " \
+ "value should be set in miliseconds units." )
+
vlc_module_begin();
- add_category_hint( N_("http"), NULL );
- add_string( "http-proxy", NULL, NULL, PROXY_TEXT, PROXY_LONGTEXT );
- set_description( _("HTTP access module") );
+ add_category_hint( N_("http"), NULL, VLC_FALSE );
+ add_string( "http-proxy", NULL, NULL, PROXY_TEXT, PROXY_LONGTEXT, VLC_FALSE );
+ add_integer( "http-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
+ set_description( _("HTTP input") );
set_capability( "access", 0 );
add_shortcut( "http" );
add_shortcut( "http4" );
#ifdef HAVE_ATOLL
i_size = i_tell + atoll( psz_value );
#else
- psz_parser = psz_value;
- while( psz_parser[0] >= '0' && psz_parser[0] <= '9' )
+ int sign = 1;
+
+ if( *psz_value == '-' ) sign = -1;
+ while( *psz_value >= '0' && *psz_value <= '9' )
{
- i_size *= 10;
- i_size += psz_parser[0] - '0';
+ i_size = i_size * 10 + *psz_value++ - '0';
}
- i_size += i_tell;
+ i_size = i_tell + ( i_size * sign );
#endif
msg_Dbg( p_input, "stream size is "I64Fd, i_size );
p_playlist->pp_items[p_playlist->i_index]->b_autodeletion
= VLC_TRUE;
playlist_Add( p_playlist, psz_value,
- PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
+ PLAYLIST_INSERT | PLAYLIST_GO,
+ p_playlist->i_index + 1 );
vlc_object_release( p_playlist );
}
if( p_input->stream.p_selected_area->i_size )
{
- p_input->stream.p_selected_area->i_tell = i_tell
- + (p_input->p_last_data - p_input->p_current_data);
+ p_input->stream.p_selected_area->i_tell = i_tell;
}
else
{
while( *psz_parser && *psz_parser != ':' && *psz_parser != '/' )
{
+ if( *psz_parser == '[' )
+ {
+ /* IPv6 address */
+ while( *psz_parser && *psz_parser != ']' )
+ {
+ psz_parser++;
+ }
+ }
psz_parser++;
}
p_access_data->socket_desc.i_type = NETWORK_TCP;
snprintf( p_access_data->psz_buffer, MAX_QUERY_SIZE,
- "GET http://%s:%d/%s\r\n HTTP/1.0\r\n",
+ "GET http://%s:%d/%s HTTP/1.0\r\n",
psz_server_addr, i_server_port, psz_path );
}
else
psz_server_addr, i_server_port, psz_path );
p_input->pf_read = Read;
- p_input->pf_set_program = SetProgram;
+ p_input->pf_set_program = input_SetProgram;
p_input->pf_set_area = NULL;
p_input->pf_seek = Seek;
}
}
+ /* Update default_pts to a suitable value for http access */
+ p_input->i_pts_delay = config_GetInt( p_input, "http-caching" ) * 1000;
+
return VLC_SUCCESS;
}
free( p_access_data );
}
-/*****************************************************************************
- * SetProgram: do nothing
- *****************************************************************************/
-static int SetProgram( input_thread_t * p_input,
- pgrm_descriptor_t * p_program )
-{
- return VLC_SUCCESS;
-}
-
/*****************************************************************************
* Seek: close and re-open a connection at the right place
*****************************************************************************/
}
/*****************************************************************************
- * Read: read on a file descriptor, checking b_die periodically
+ * Read: Read up to i_len bytes from the http connection and place in
+ * p_buffer. Return the actual number of bytes read
*****************************************************************************/
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;
struct timeval timeout;
fd_set fds;
+ ssize_t i_recv;
int i_ret;
/* Initialize file descriptor set */
timeout.tv_usec = 500000;
/* Find if some data is available */
- i_ret = select( p_access_data->i_handle + 1, &fds,
- NULL, NULL, &timeout );
-
+ while( (i_ret = select( p_access_data->i_handle + 1, &fds,
+ NULL, NULL, &timeout )) == 0
#ifdef HAVE_ERRNO_H
- if( i_ret == -1 && errno != EINTR )
+ || (i_ret < 0 && errno == EINTR)
+#endif
+ )
{
- msg_Err( p_input, "network select error (%s)", strerror(errno) );
+ FD_ZERO( &fds );
+ FD_SET( p_access_data->i_handle, &fds );
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 500000;
+
+ if( p_input->b_die || p_input->b_error )
+ {
+ return 0;
+ }
}
-#else
- if( i_ret == -1 )
+
+ if( i_ret < 0 )
{
msg_Err( p_input, "network select error" );
+ return -1;
}
-#endif
- 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 );
- }
+ i_recv = recv( p_access_data->i_handle, p_buffer, i_len, 0 );
- if( i_recv < 0 )
- {
+ if( i_recv < 0 )
+ {
#ifdef HAVE_ERRNO_H
- msg_Err( p_input, "recv failed (%s)", strerror(errno) );
+ msg_Err( p_input, "recv failed (%s)", strerror(errno) );
#else
- msg_Err( p_input, "recv failed" );
+ msg_Err( p_input, "recv failed" );
#endif
- }
-
- return i_recv;
}
- return 0;
+ return i_recv;
}