Changeset 5774 for pjproject


Ignore:
Timestamp:
Apr 3, 2018 5:01:20 AM (6 years ago)
Author:
ming
Message:

Fixed #2108: Fixed RTP socket to bind to any available port if port is zero

Location:
pjproject/trunk/pjsip/src/pjsua-lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r5768 r5774  
    2323 
    2424#define THIS_FILE   "pjsua_core.c" 
     25 
     26#define DEFAULT_RTP_PORT        4000 
    2527 
    2628 
     
    289291#endif 
    290292    pjsua_transport_config_default(&cfg->rtp_cfg); 
     293    cfg->rtp_cfg.port = DEFAULT_RTP_PORT; 
    291294 
    292295    pjsua_media_config_default(&med_cfg); 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c

    r5755 r5774  
    2424#define THIS_FILE               "pjsua_media.c" 
    2525 
    26 #define DEFAULT_RTP_PORT        4000 
    27  
    2826#ifndef PJSUA_REQUIRE_CONSECUTIVE_RTCP_PORT 
    2927#   define PJSUA_REQUIRE_CONSECUTIVE_RTCP_PORT  0 
     
    268266    } 
    269267 
    270     if (acc->next_rtp_port == 0) 
     268    if (acc->next_rtp_port == 0 || cfg->port == 0) 
    271269        acc->next_rtp_port = (pj_uint16_t)cfg->port; 
    272  
    273     if (acc->next_rtp_port == 0) 
    274         acc->next_rtp_port = (pj_uint16_t)DEFAULT_RTP_PORT; 
    275270 
    276271    for (i=0; i<2; ++i) 
     
    321316            sock[0] = PJ_INVALID_SOCKET; 
    322317            continue; 
     318        } 
     319         
     320        /* If bound to random port, find out the port number. */ 
     321        if (acc->next_rtp_port == 0) { 
     322            pj_sockaddr sock_addr; 
     323            int addr_len = sizeof(pj_sockaddr); 
     324 
     325            status = pj_sock_getsockname(sock[0], &sock_addr, &addr_len); 
     326            if (status != PJ_SUCCESS) { 
     327                pjsua_perror(THIS_FILE, "getsockname() error", status); 
     328                pj_sock_close(sock[0]); 
     329                return status; 
     330            } 
     331            acc->next_rtp_port = pj_sockaddr_get_port(&sock_addr); 
    323332        } 
    324333 
Note: See TracChangeset for help on using the changeset viewer.