X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess_output%2Fudp.c;h=12230dfe0395eaa40a02806d56c58c577d6c04ee;hb=af72dcc4b4e4c3df31c6701b9e819a8e80ebc7a6;hp=cec3b199a777dbc06ea9d2c209aedb4dc2654763;hpb=e6d75333082caa647477fc2f19350ee4810aa10f;p=vlc diff --git a/modules/access_output/udp.c b/modules/access_output/udp.c index cec3b199a7..12230dfe03 100644 --- a/modules/access_output/udp.c +++ b/modules/access_output/udp.c @@ -1,7 +1,7 @@ /***************************************************************************** * udp.c ***************************************************************************** - * Copyright (C) 2001-2005 VideoLAN + * Copyright (C) 2001-2005 the VideoLAN team * $Id$ * * Authors: Laurent Aimar @@ -53,6 +53,17 @@ #define MAX_EMPTY_BLOCKS 200 +#if defined(WIN32) || defined(UNDER_CE) +# define WINSOCK_STRERROR_SIZE 20 +static const char *winsock_strerror( char *buf ) +{ + snprintf( buf, WINSOCK_STRERROR_SIZE, "Winsock error %d", + WSAGetLastError( ) ); + buf[WINSOCK_STRERROR_SIZE - 1] = '\0'; + return buf; +} +#endif + /***************************************************************************** * Module descriptor *****************************************************************************/ @@ -66,10 +77,6 @@ static void Close( vlc_object_t * ); "Allows you to modify the default caching value for UDP streams. This " \ "value should be set in millisecond units." ) -#define TTL_TEXT N_("Time To Live") -#define TTL_LONGTEXT N_("Allows you to define the time to live of the " \ - "outgoing stream.") - #define GROUP_TEXT N_("Group packets") #define GROUP_LONGTEXT N_("Packets can be sent one by one at the right time " \ "or by groups. This allows you to give the number " \ @@ -88,8 +95,6 @@ vlc_module_begin(); set_category( CAT_SOUT ); set_subcategory( SUBCAT_SOUT_ACO ); add_integer( SOUT_CFG_PREFIX "caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE ); - add_integer( SOUT_CFG_PREFIX "ttl", 0, NULL,TTL_TEXT, TTL_LONGTEXT, - VLC_TRUE ); add_integer( SOUT_CFG_PREFIX "group", 1, NULL, GROUP_TEXT, GROUP_LONGTEXT, VLC_TRUE ); add_suppressed_integer( SOUT_CFG_PREFIX "late" ); @@ -108,7 +113,6 @@ vlc_module_end(); static const char *ppsz_sout_options[] = { "caching", - "ttl", "group", "raw", NULL @@ -188,8 +192,6 @@ static int Open( vlc_object_t *p_this ) if( p_access->psz_access != NULL && !strcmp( p_access->psz_access, "rtp" ) ) { - msg_Warn( p_access, "be careful that rtp output only works with ts " - "payload (not an error)" ); p_sys->b_rtpts = 1; } else @@ -240,23 +242,35 @@ static int Open( vlc_object_t *p_this ) p_sys->p_thread->i_empty_depth = 0; vlc_mutex_init( p_access, &p_sys->p_thread->blocks_lock ); + /* FIXME: use net_OpenUDP API */ socket_desc.psz_server_addr = psz_dst_addr; socket_desc.i_server_port = i_dst_port; socket_desc.psz_bind_addr = ""; socket_desc.i_bind_port = 0; - - var_Get( p_access, SOUT_CFG_PREFIX "ttl", &val ); - socket_desc.i_ttl = val.i_int; + socket_desc.i_handle = -1; + socket_desc.v6only = 0; + socket_desc.i_ttl = 0; p_sys->p_thread->p_private = (void*)&socket_desc; - if( !( p_network = module_Need( p_sys->p_thread, "network", NULL, 0 ) ) ) + p_network = module_Need( p_sys->p_thread, "network", "ipv4", VLC_TRUE ); + if( p_network != NULL ) + module_Unneed( p_sys->p_thread, p_network ); + + if( socket_desc.i_handle == -1 ) { - msg_Err( p_access, "failed to open a connection (udp)" ); - return VLC_EGENERIC; + p_network = module_Need( p_sys->p_thread, "network", "ipv6", VLC_TRUE ); + if( p_network != NULL ) + module_Unneed( p_sys->p_thread, p_network ); + + if( socket_desc.i_handle == -1 ) + { + msg_Err( p_access, "failed to open a connection (udp)" ); + return VLC_EGENERIC; + } } - module_Unneed( p_sys->p_thread, p_network ); p_sys->p_thread->i_handle = socket_desc.i_handle; + net_StopRecv( socket_desc.i_handle ); var_Get( p_access, SOUT_CFG_PREFIX "caching", &val ); p_sys->p_thread->i_caching = (int64_t)val.i_int * 1000; @@ -266,13 +280,8 @@ static int Open( vlc_object_t *p_this ) p_sys->i_mtu = socket_desc.i_mtu; -#ifdef WIN32 if( vlc_thread_create( p_sys->p_thread, "sout write thread", ThreadWrite, VLC_THREAD_PRIORITY_HIGHEST, VLC_FALSE ) ) -#else - if( vlc_thread_create( p_sys->p_thread, "sout write thread", ThreadWrite, - VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) ) -#endif { msg_Err( p_access->p_sout, "cannot spawn sout access thread" ); vlc_object_destroy( p_sys->p_thread ); @@ -317,6 +326,7 @@ static void Close( vlc_object_t * p_this ) p_dummy->i_dts = 0; p_dummy->i_pts = 0; p_dummy->i_length = 0; + memset( p_dummy->p_buffer, 0, p_dummy->i_buffer ); block_FifoPut( p_sys->p_thread->p_fifo, p_dummy ); } vlc_thread_join( p_sys->p_thread ); @@ -519,6 +529,10 @@ static void ThreadWrite( vlc_object_t *p_this ) mtime_t i_date_last = -1; mtime_t i_to_send = p_thread->i_group; int i_dropped_packets = 0; +#if defined(WIN32) || defined(UNDER_CE) + char strerror_buf[WINSOCK_STRERROR_SIZE]; +# define strerror( x ) winsock_strerror( strerror_buf ) +#endif while( !p_thread->b_die ) { @@ -555,12 +569,16 @@ static void ThreadWrite( vlc_object_t *p_this ) } i_to_send--; - if ( !i_to_send || (p_pk->i_flags & BLOCK_FLAG_CLOCK) ) + if( !i_to_send || (p_pk->i_flags & BLOCK_FLAG_CLOCK) ) { mwait( i_date ); i_to_send = p_thread->i_group; } - send( p_thread->i_handle, p_pk->p_buffer, p_pk->i_buffer, 0 ); + if( send( p_thread->i_handle, p_pk->p_buffer, p_pk->i_buffer, 0 ) + == -1 ) + { + msg_Warn( p_thread, "send error: %s", strerror(errno) ); + } if( i_dropped_packets ) {