Changeset e2dedca13cdfff43592c0fc5065446f11d248307

Show
Ignore:
Timestamp:
31/05/05 21:48:21 (4 years ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1117568901 +0000
git-parent:

[1d8cad44a85cb72173d9e00eb21802f3c7bfc363]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1117568901 +0000
Message:

- hopefuly fix sending of SAP announces over IPv6
- automatically select SAP multicast address (closes #141)
- some clean up

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/stream_output.h

    r97704de re2dedca  
    260260 
    261261    /* For SAP */ 
    262     int i_ip_version; 
    263262    char *psz_address; /* If we use a custom address */ 
    264     char sz_ipv6_scope; 
    265 }; 
    266  
    267  
    268 /* SAP Specific structures */ 
    269  
    270 /* 100ms */ 
    271 #define SAP_IDLE ((mtime_t)(0.100*CLOCK_FREQ)) 
    272 #define SAP_MAX_BUFFER 65534 
    273 #define MIN_INTERVAL 2 
    274 #define MAX_INTERVAL 300 
    275  
    276 /* A SAP announce address. For each of these, we run the 
    277  * control flow algorithm */ 
    278 struct sap_address_t 
    279 
    280     char *psz_address; 
    281     int i_ip_version; 
    282     int i_port; 
    283     int i_rfd; /* Read socket */ 
    284     int i_wfd; /* Write socket */ 
    285  
    286     /* Used for flow control */ 
    287     mtime_t t1; 
    288     vlc_bool_t b_enabled; 
    289     vlc_bool_t b_ready; 
    290     int i_interval; 
    291     int i_buff; 
    292     int i_limit; 
    293 }; 
     263}; 
     264 
    294265 
    295266/* A SAP session descriptor, enqueued in the SAP handler queue */ 
  • modules/stream_out/rtp.c

    rfb751f6 re2dedca  
    12351235    sout_stream_sys_t *p_sys = p_stream->p_sys; 
    12361236    sout_instance_t   *p_sout = p_stream->p_sout; 
     1237    /* FIXME: use sout_AnnounceMethodCreate */ 
    12371238    announce_method_t *p_method = (announce_method_t *) 
    12381239                                  malloc(sizeof(announce_method_t)); 
     
    12471248    p_method->i_type = METHOD_TYPE_SAP; 
    12481249    p_method->psz_address = NULL; /* FIXME */ 
    1249     p_method->i_ip_version = 4; /* FIXME ! */ 
    12501250 
    12511251    if( p_sys->i_es > 0 && p_sys->psz_sdp && *p_sys->psz_sdp ) 
  • modules/stream_out/standard.c

    rcdce7f8 re2dedca  
    6464#define SAP_LONGTEXT N_("Announce this session with SAP") 
    6565 
    66 #define SAPv6_TEXT N_("SAP IPv6 announcing") 
    67 #define SAPv6_LONGTEXT N_("Use IPv6 to announce this session with SAP") 
    68  
    6966#define SLP_TEXT N_("SLP announcing") 
    7067#define SLP_LONGTEXT N_("Announce this session with SLP") 
     
    9693    add_string( SOUT_CFG_PREFIX "group", "", NULL, GROUP_TEXT, GROUP_LONGTEXT, 
    9794                                        VLC_TRUE ); 
    98     add_bool( SOUT_CFG_PREFIX "sap-ipv6", 0, NULL, SAPv6_TEXT, SAPv6_LONGTEXT, 
    99                                         VLC_TRUE ); 
     95    add_deprecated( SOUT_CFG_PREFIX "sap-ipv6", VLC_FALSE ); 
    10096 
    10197    add_bool( SOUT_CFG_PREFIX "slp", 0, NULL, SLP_TEXT, SLP_LONGTEXT, VLC_TRUE ); 
     
    110106static const char *ppsz_sout_options[] = { 
    111107    "access", "mux", "url", 
    112     "sap", "name", "sap-ipv6", "group", 
    113     "slp", NULL 
     108    "sap", "name", "group", "slp", NULL 
    114109}; 
    115110 
    116 #define DEFAULT_IPV6_SCOPE '8' 
    117111#define DEFAULT_PORT 1234 
    118112 
     
    350344        free( val.psz_string ); 
    351345 
    352         var_Get( p_stream, SOUT_CFG_PREFIX "sap-ipv6", &val ); 
    353         p_method->i_ip_version = val.b_bool ? 6 : 4; 
    354  
    355346        /* Now, parse the URL to extract host and port */ 
    356347        vlc_UrlParse( &url, psz_url , 0); 
     
    370361 
    371362            sout_AnnounceRegister( p_sout, p_session, p_method ); 
    372  
    373             /* FIXME: Free p_method */ 
    374  
    375363            p_stream->p_sys->p_session = p_session; 
    376364        } 
    377365        vlc_UrlClean( &url ); 
    378366 
     367        /* FIXME: Free p_method */ 
    379368        if( p_method->psz_address) free( p_method->psz_address ); 
    380369        free( p_method ); 
  • src/stream_output/announce.c

    r97704de re2dedca  
    205205        p_method->i_type = i_type; 
    206206        if( i_type == METHOD_TYPE_SAP ) 
    207         { 
    208             /* Default values */ 
     207            /* Default value */ 
    209208            p_method->psz_address = NULL; 
    210             p_method->i_ip_version = 4 ; 
    211             p_method->sz_ipv6_scope = '\0'; 
    212         } 
    213209    } 
    214210    return p_method; 
  • src/stream_output/sap.c

    r97704de re2dedca  
    22 * sap.c : SAP announce handler 
    33 ***************************************************************************** 
    4  * Copyright (C) 2002-2004 VideoLAN 
     4 * Copyright (C) 2002-2005 VideoLAN 
    55 * $Id$ 
    66 * 
     
    2828#include <stdio.h>                                              /* sprintf() */ 
    2929#include <string.h>                                            /* strerror() */ 
     30#include <ctype.h>                                  /* tolower(), isxdigit() */ 
    3031 
    3132#include <vlc/vlc.h> 
    3233#include <vlc/sout.h> 
    3334 
    34 #include <network.h> 
     35#include "network.h" 
     36#if defined( WIN32 ) || defined( UNDER_CE ) 
     37#   if defined(UNDER_CE) && defined(sockaddr_storage) 
     38#       undef sockaddr_storage 
     39#   endif 
     40#   include <winsock2.h> 
     41#   include <ws2tcpip.h> 
     42#else 
     43#   include <netdb.h> 
     44#endif 
    3545#include "charset.h" 
    3646 
    37 #define SAP_IPV4_ADDR "224.2.127.254" /* Standard port and address for SAP */ 
     47/* SAP is always on that port */ 
    3848#define SAP_PORT 9875 
    3949 
    40 #define SAP_IPV6_ADDR_1 "FF0" 
    41 #define SAP_IPV6_ADDR_2 "::2:7FFE" 
    42  
    43 #define DEFAULT_IPV6_SCOPE '8' 
    44  
    4550#define DEFAULT_PORT "1234" 
    4651 
    4752#undef EXTRA_DEBUG 
     53 
     54/* SAP Specific structures */ 
     55 
     56/* 100ms */ 
     57#define SAP_IDLE ((mtime_t)(0.100*CLOCK_FREQ)) 
     58#define SAP_MAX_BUFFER 65534 
     59#define MIN_INTERVAL 2 
     60#define MAX_INTERVAL 300 
     61 
     62/* A SAP announce address. For each of these, we run the 
     63 * control flow algorithm */ 
     64struct sap_address_t 
     65{ 
     66    char *psz_address; 
     67    int i_port; 
     68    int i_rfd; /* Read socket */ 
     69    int i_wfd; /* Write socket */ 
     70 
     71    /* Used for flow control */ 
     72    mtime_t t1; 
     73    vlc_bool_t b_enabled; 
     74    vlc_bool_t b_ready; 
     75    int i_interval; 
     76    int i_buff; 
     77    int i_limit; 
     78}; 
    4879 
    4980/***************************************************************************** 
     
    228259    int i_header_size; 
    229260    char *psz_head; 
    230     vlc_bool_t b_found = VLC_FALSE
     261    vlc_bool_t b_found = VLC_FALSE, b_ipv6
    231262    sap_session_t *p_sap_session; 
    232263    mtime_t i_hash; 
     
    244275    } 
    245276 
    246     if( !p_method->psz_address ) 
    247     { 
    248         if( p_method->i_ip_version == 6 ) 
    249         { 
    250             char sz_scope; 
    251             if( p_method->sz_ipv6_scope ) 
     277    if( p_method->psz_address == NULL ) 
     278    { 
     279        /* Determine SAP multicast address automatically */ 
     280        char psz_buf[NI_MAXHOST]; 
     281        const char *psz_addr; 
     282        struct addrinfo hints, *res; 
     283 
     284        if( p_session->psz_uri == NULL ) 
     285        { 
     286            msg_Err( p_sap, "*FIXME* Unexpected NULL URI for SAP announce" ); 
     287            msg_Err( p_sap, "This should not happen. VLC needs fixing." ); 
     288            vlc_mutex_unlock( &p_sap->object_lock ); 
     289            return VLC_EGENERIC; 
     290        } 
     291 
     292        /* Canonicalize IP address (e.g. 224.00.010.1 => 224.0.10.1) */ 
     293        memset( &hints, 0, sizeof( hints ) ); 
     294        hints.ai_socktype = SOCK_DGRAM; 
     295        hints.ai_flags = AI_NUMERICHOST; 
     296 
     297        i = vlc_getaddrinfo( (vlc_object_t *)p_sap, p_session->psz_uri, NULL, 
     298                             &hints, &res ); 
     299        if( i == 0 ) 
     300            i = vlc_getnameinfo( (vlc_object_t *)p_sap, res->ai_addr, 
     301                                 res->ai_addrlen, psz_buf, sizeof( psz_buf ), 
     302                                 NULL, 0, NI_NUMERICHOST ); 
     303        if( i ) 
     304        { 
     305            msg_Err( p_sap, "Invalid URI for SAP announce : %s : %s", 
     306                     p_session->psz_uri, vlc_gai_strerror( i ) ); 
     307            vlc_mutex_unlock( &p_sap->object_lock ); 
     308            return VLC_EGENERIC; 
     309        } 
     310 
     311        if( strchr( psz_buf, ':' ) != NULL ) 
     312        { 
     313            b_ipv6 = VLC_TRUE; 
     314 
     315            /* See RFC3513 for list of valid IPv6 scopes */ 
     316            if( ( tolower( psz_buf[0] ) == 'f' ) 
     317             && ( tolower( psz_buf[1] ) == 'f' ) 
     318             && isxdigit( psz_buf[2] ) && isxdigit( psz_buf[3] ) ) 
    252319            { 
    253                 sz_scope = p_method->sz_ipv6_scope; 
     320                /* Multicast IPv6 */ 
     321                psz_buf[2] = '0'; /* force flags to zero */ 
     322                /* keep scope in psz_addr[3] */ 
     323                memcpy( &psz_buf[4], "::2:7ffe", sizeof( "::2:7ffe" ) ); 
     324                psz_addr = psz_buf; 
    254325            } 
    255326            else 
    256             { 
    257                 sz_scope = DEFAULT_IPV6_SCOPE; 
    258             } 
    259             p_method->psz_address = (char*)malloc( 30*sizeof(char )); 
    260             sprintf( p_method->psz_address, "%s%c%s", 
    261                             SAP_IPV6_ADDR_1, sz_scope, SAP_IPV6_ADDR_2 ); 
     327                /* Unicast IPv6 - assume global scope */ 
     328                psz_addr = "ff0e::2:7ffe"; 
    262329        } 
    263330        else 
    264331        { 
    265             /* IPv4 */ 
    266             p_method->psz_address = (char*)malloc( 15*sizeof(char) ); 
    267             snprintf(p_method->psz_address, 15, SAP_IPV4_ADDR ); 
    268         } 
    269     } 
    270     msg_Dbg( p_sap, "using SAP address: %s",p_method->psz_address); 
     332            b_ipv6 = VLC_FALSE; 
     333 
     334            /* See RFC2365 for IPv4 scopes */ 
     335            if( memcmp( psz_buf, "224.0.0.", 8 ) == 0 ) 
     336                psz_addr = "224.0.0.255"; 
     337            else 
     338            if( memcmp( psz_buf, "239.255.", 8 ) == 0 ) 
     339                psz_addr = "239.255.255.255"; 
     340            else 
     341            if( ( memcmp( psz_buf, "239.19", 6 ) == 0 ) 
     342             && ( ( psz_buf[6] >= '2' ) && ( psz_buf[6] <= '5' ) ) ) 
     343                psz_addr = "239.195.255.255"; 
     344            else 
     345                /* assume global scope */ 
     346                psz_addr = "224.2.127.254"; 
     347        } 
     348 
     349        p_method->psz_address = strdup( psz_addr ); 
     350    } 
     351    else 
     352        b_ipv6 == (strchr( p_method->psz_address, ':' ) != NULL); 
     353 
     354    msg_Dbg( p_sap, "using SAP address: %s", p_method->psz_address); 
    271355 
    272356    /* XXX: Check for dupes */ 
     
    297381        } 
    298382        p_address->psz_address = strdup( p_method->psz_address ); 
    299         p_address->i_ip_version = p_method->i_ip_version; 
    300383        p_address->i_port  =  9875; 
    301384        p_address->i_wfd = net_OpenUDP( p_sap, "", 0, 
     
    337420 
    338421    /* Build the SAP Headers */ 
    339     i_header_size = ( p_method->i_ip_version == 6 ? 20 : 8 ) + strlen( psz_type ) + 1; 
     422    i_header_size = ( b_ipv6 ? 20 : 8 ) + strlen( psz_type ) + 1; 
    340423    psz_head = (char *) malloc( i_header_size * sizeof( char ) ); 
    341424    if( ! psz_head ) 
     
    352435    psz_head[3] = (i_hash & 0xFF);        /* Msg id hash 2 */ 
    353436 
    354     if( p_method->i_ip_version == 6 ) 
     437    if( b_ipv6 ) 
    355438    { 
    356439        /* in_addr_t ip_server = inet_addr( ip ); */ 
     
    499582    int     i_sdp_version = 1 + p_sap->i_sessions + (rand()&0xfff); 
    500583    char *psz_group, *psz_name; 
     584    char ipv; 
    501585 
    502586    psz_group = convert_to_utf8( p_sap, p_session->psz_group ); 
    503587    psz_name = convert_to_utf8( p_sap, p_session->psz_name ); 
     588 
     589    ipv = ( strchr( p_session->psz_uri, ':' )  != NULL) ? '6' : '4'; 
    504590 
    505591    /* see the lists in modules/stream_out/rtp.c for compliance stuff */ 
     
    529615                            "s=%s\r\n" 
    530616                            "t=0 0\r\n" 
    531                             "c=IN IP4 %s/%d\r\n" 
     617                            "c=IN IP%c %s/%d\r\n" 
    532618                            "m=video %d udp %d\r\n" 
    533619                            "a=tool:"PACKAGE_STRING"\r\n" 
    534620                            "a=type:broadcast\r\n", 
    535621                            i_sdp_id, i_sdp_version, 
    536                             psz_name, 
     622                            psz_name, ipv, 
    537623                            p_session->psz_uri, p_session->i_ttl, 
    538624                            p_session->i_port, p_session->i_payload );