* udp.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
- * $Id: udp.c,v 1.10 2003/06/19 18:45:06 gbazin Exp $
+ * $Id: udp.c,v 1.16 2003/11/17 14:46:37 massiot Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
-static int Write( sout_access_out_t *, sout_buffer_t * );
-static int Seek ( sout_access_out_t *, off_t );
+static int Write ( sout_access_out_t *, sout_buffer_t * );
+static int WriteRaw( sout_access_out_t *, sout_buffer_t * );
+static int Seek ( sout_access_out_t *, off_t );
static void ThreadWrite( vlc_object_t * );
int i_handle;
+ int64_t i_caching;
+
} sout_access_thread_t;
struct sout_access_out_sys_t
module_t *p_network;
network_socket_t socket_desc;
+ char *val;
+
if( !( p_sys = p_access->p_sys =
malloc( sizeof( sout_access_out_sys_t ) ) ) )
{
socket_desc.i_server_port = i_dst_port;
socket_desc.psz_bind_addr = "";
socket_desc.i_bind_port = 0;
+ socket_desc.i_ttl = 0;
+ if( ( val = sout_cfg_find_value( p_access->p_cfg, "ttl" ) ) )
+ {
+ socket_desc.i_ttl = atoi( val );
+ }
p_sys->p_thread->p_private = (void*)&socket_desc;
if( !( p_network = module_Need( p_sys->p_thread,
"network", "" ) ) )
module_Unneed( p_sys->p_thread, p_network );
p_sys->p_thread->i_handle = socket_desc.i_handle;
+ p_sys->p_thread->i_caching = config_GetInt( p_this, "udp-sout-caching" ) * 1000;
+ if( ( val = sout_cfg_find_value( p_access->p_cfg, "caching" ) ) )
+ {
+ p_sys->p_thread->i_caching = atoll( val ) * 1000;
+ }
+
p_sys->i_mtu = socket_desc.i_mtu;
if( vlc_thread_create( p_sys->p_thread, "sout write thread", ThreadWrite,
p_sys->i_sequence_number = rand()&0xffff;
p_sys->i_ssrc = rand()&0xffffffff;
- p_access->pf_write = Write;
+ if( sout_cfg_find( p_access->p_cfg, "raw" ) )
+ {
+ p_access->pf_write = WriteRaw;
+ }
+ else
+ {
+ p_access->pf_write = Write;
+ }
p_access->pf_seek = Seek;
msg_Info( p_access, "Open: addr:`%s' port:`%d'",
}
/*****************************************************************************
- * Read: standard read on a file descriptor.
+ * Write: standard write on a file descriptor.
*****************************************************************************/
static int Write( sout_access_out_t *p_access, sout_buffer_t *p_buffer )
{
return( p_sys->p_thread->b_error ? -1 : 0 );
}
+/*****************************************************************************
+ * WriteRaw: write p_buffer without trying to fill mtu
+ *****************************************************************************/
+static int WriteRaw( sout_access_out_t *p_access, sout_buffer_t *p_buffer )
+{
+ sout_access_out_sys_t *p_sys = p_access->p_sys;
+
+ sout_FifoPut( p_sys->p_thread->p_fifo, p_buffer );
+
+ return( p_sys->p_thread->b_error ? -1 : 0 );
+}
+
/*****************************************************************************
* Seek: seek to a specific location in a file
*****************************************************************************/
{
sout_access_thread_t *p_thread = (sout_access_thread_t*)p_this;
sout_instance_t *p_sout = p_thread->p_sout;
- sout_buffer_t *p_buffer;
- mtime_t i_date, i_pts_delay;
-
- /* Get the i_pts_delay value */
- i_pts_delay = config_GetInt( p_this, "udp-sout-caching" ) * 1000;
+ mtime_t i_date_last = -1;
- p_buffer = sout_FifoGet( p_thread->p_fifo );
- if( p_thread->b_die ) return;
-
- i_date = mdate() + i_pts_delay - p_buffer->i_dts;
-
- while( 1 )
+ while( ! p_thread->b_die )
{
- mtime_t i_wait;
+ sout_buffer_t *p_pk;
+ mtime_t i_date, i_sent;
- i_wait = i_date + p_buffer->i_dts;
+ p_pk = sout_FifoGet( p_thread->p_fifo );
- if( i_wait - mdate() > MAX_ERROR || i_wait - mdate() < -MAX_ERROR )
+ i_date = p_thread->i_caching + p_pk->i_dts;
+ if( i_date_last > 0 )
{
- msg_Warn( p_sout, "resetting clock" );
- i_date = mdate() + i_pts_delay - p_buffer->i_dts;
+ if( i_date - i_date_last > 2000000 )
+ {
+ msg_Dbg( p_thread, "mmh, hole > 2s -> drop" );
+
+ sout_BufferDelete( p_sout, p_pk );
+ i_date_last = i_date;
+ continue;
+ }
+ else if( i_date - i_date_last < 0 )
+ {
+ msg_Dbg( p_thread, "mmh, paquets in the past -> drop" );
+
+ sout_BufferDelete( p_sout, p_pk );
+ i_date_last = i_date;
+ continue;
+ }
}
- else
+
+ mwait( i_date );
+ send( p_thread->i_handle, p_pk->p_buffer, p_pk->i_size, 0 );
+ i_sent = mdate();
+ if ( i_sent > i_date + 20000 )
{
- mwait( i_wait );
+ msg_Dbg( p_thread, "packet has been sent too late (" I64Fd ")",
+ i_sent - i_date );
}
-
- send( p_thread->i_handle, p_buffer->p_buffer, p_buffer->i_size, 0 );
-
- sout_BufferDelete( p_sout, p_buffer );
-
- p_buffer = sout_FifoGet( p_thread->p_fifo );
- if( p_thread->b_die ) return;
+ sout_BufferDelete( p_sout, p_pk );
+ i_date_last = i_date;
}
}