X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fstream_output%2Fsap.c;h=c0caf436e15126ebd59641d0d7b87f258c8a5900;hb=2e7e22467bd0ba3d9ef6cb2211fab3133ae40486;hp=606fbec3afaa07daf86163677578ab1be003079e;hpb=d6a7c477213c5b927459372e89c8ddc3b67a9475;p=vlc diff --git a/src/stream_output/sap.c b/src/stream_output/sap.c index 606fbec3af..c0caf436e1 100644 --- a/src/stream_output/sap.c +++ b/src/stream_output/sap.c @@ -1,7 +1,7 @@ /***************************************************************************** * sap.c : SAP announce handler ***************************************************************************** - * Copyright (C) 2002-2005 the VideoLAN team + * Copyright (C) 2002-2007 the VideoLAN team * $Id$ * * Authors: Clément Stenac @@ -26,12 +26,17 @@ * Preamble *****************************************************************************/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include /* free() */ #include /* sprintf() */ -#include /* strerror() */ +#include #include /* tolower(), isxdigit() */ +#include #include #include @@ -89,10 +94,7 @@ struct sap_session_t { * Local prototypes *****************************************************************************/ static void RunThread( vlc_object_t *p_this); -static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address ); -static char *SDPGenerate( sap_handler_t *p_sap, - const session_descriptor_t *p_session, - const sap_address_t *p_addr, vlc_bool_t b_ssm ); +static int ComputeRate( sap_address_t *p_address ); static int announce_SendSAPAnnounce( sap_handler_t *p_sap, sap_session_t *p_session ); @@ -183,7 +185,7 @@ void announce_SAPHandlerDestroy( sap_handler_t *p_sap ) } /* Free the structure */ - vlc_object_destroy( p_sap ); + vlc_object_release( p_sap ); } /** @@ -207,7 +209,7 @@ static void RunThread( vlc_object_t *p_this) { if( p_sap->pp_addresses[i]->b_enabled == VLC_TRUE ) { - CalculateRate( p_sap, p_sap->pp_addresses[i] ); + ComputeRate( p_sap->pp_addresses[i] ); } } } @@ -380,7 +382,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, p_address->i_wfd = net_ConnectUDP( VLC_OBJECT(p_sap), psz_addr, SAP_PORT, 255 ); if( p_address->i_wfd != -1 ) { - net_StopRecv( p_address->i_wfd ); + shutdown( p_address->i_wfd, SHUT_RD ); p_address->origlen = sizeof (p_address->orig); getsockname (p_address->i_wfd, (struct sockaddr *)&p_address->orig, &p_address->origlen); @@ -390,7 +392,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, { p_address->i_rfd = net_ListenUDP1( (vlc_object_t*)p_sap, psz_addr, SAP_PORT ); if( p_address->i_rfd != -1 ) - net_StopSend( p_address->i_rfd ); + shutdown( p_address->i_rfd, SHUT_WR ); p_address->i_buff = 0; p_address->b_enabled = VLC_TRUE; p_address->b_ready = VLC_FALSE; @@ -419,9 +421,8 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, p_sap_session->p_address = p_address; } - if (p_session->origlen == 0) - memcpy (&p_session->orig, &p_sap_session->p_address->orig, - p_session->origlen = p_sap_session->p_address->origlen); + memcpy (&p_session->orig, &p_sap_session->p_address->orig, + p_session->origlen = p_sap_session->p_address->origlen); size_t headsize = 20; switch (p_session->orig.ss_family) @@ -442,16 +443,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, } /* If needed, build the SDP */ - if( p_session->psz_sdp == NULL ) - { - p_session->psz_sdp = SDPGenerate( p_sap, p_session, - p_sap_session->p_address, b_ssm ); - if( p_session->psz_sdp == NULL ) - { - vlc_mutex_unlock( &p_sap->object_lock ); - return VLC_ENOMEM; - } - } + assert( p_session->psz_sdp != NULL ); p_sap_session->i_last = 0; p_sap_session->i_length = headsize + strlen (p_session->psz_sdp); @@ -585,62 +577,13 @@ static int announce_SendSAPAnnounce( sap_handler_t *p_sap, p_session->i_next = p_session->i_last + p_session->p_address->i_interval*1000000; } - else - { - return VLC_SUCCESS; - } return VLC_SUCCESS; } -static char *SDPGenerate( sap_handler_t *p_sap, - const session_descriptor_t *p_session, - const sap_address_t *p_addr, vlc_bool_t b_ssm ) +static int ComputeRate( sap_address_t *p_address ) { - char *psz_group, *psz_name, *psz_sdp; - - char *head = StartSDP (p_session->psz_name, p_session->description, - p_session->url, p_session->email, p_session->phone, b_ssm, - (const struct sockaddr *)&p_session->orig, p_session->origlen, - (const struct sockaddr *)&p_session->addr, p_session->addrlen); - if (head == NULL) - return NULL; - - psz_group = p_session->psz_group; - psz_name = p_session->psz_name; - - char *plgroup; - if ((psz_group == NULL) - || (asprintf (&plgroup, "a=x-plgroup:%s\r\n", psz_group) == -1)) - plgroup = NULL; - - const char *comedia = NULL; - if (!strncasecmp (p_session->sdpformat, "DCCP", 4) - || !strncasecmp (p_session->sdpformat, "TCP", 3)) - comedia = "a=setup:passive\r\n" - "a=connection:new\r\n"; - - int res = asprintf (&psz_sdp, "%s" "%s" "%s" - "m=video %d %s\r\n", - head, - plgroup ?: "", - comedia ?: "", - ntohs (net_GetPort ((const struct sockaddr *)&p_session->addr)), - p_session->sdpformat); - free (plgroup); - - if (res == -1) - return NULL; - - msg_Dbg( p_sap, "Generated SDP (%i bytes):\n%s", strlen(psz_sdp), - psz_sdp ); - return psz_sdp; -} - -static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address ) -{ - int i_read; uint8_t buffer[SAP_MAX_BUFFER]; - int i_tot = 0; + ssize_t i_tot = 0; mtime_t i_temp; int i_rate; @@ -649,13 +592,14 @@ static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address ) p_address->t1 = mdate(); return VLC_SUCCESS; } - do + for (;;) { /* Might be too slow if we have huge data */ - i_read = net_ReadNonBlock( p_sap, p_address->i_rfd, NULL, buffer, - SAP_MAX_BUFFER, 0 ); + ssize_t i_read = recv( p_address->i_rfd, buffer, SAP_MAX_BUFFER, 0 ); + if (i_read == -1) + break; i_tot += i_read; - } while( i_read > 0 ); + } i_temp = mdate();