Changeset 483


Ignore:
Timestamp:
Jun 1, 2006 11:37:30 AM (18 years ago)
Author:
bennylp
Message:

Added options in pjmedia UDP transport to disable source address checking

Location:
pjproject/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/transport_udp.h

    r452 r483  
    3030 
    3131/** 
    32  * Create UDP stream transport. 
     32 * Options that can be specified when creating UDP transport. 
     33 */ 
     34enum pjmedia_transport_udp_options 
     35{ 
     36    /** 
     37     * Normally the UDP transport will continuously check the source address 
     38     * of incoming packets to see if it is different than the configured 
     39     * remote address, and switch the remote address to the source address 
     40     * of the packet if they are different after several packets are 
     41     * received. 
     42     * Specifying this option will disable this feature. 
     43     */ 
     44    PJMEDIA_UDP_NO_SRC_ADDR_CHECKING = 1, 
     45}; 
     46 
     47 
     48/** 
     49 * Create an RTP and RTCP sockets and bind RTP the socket to the specified 
     50 * port to create media transport. 
     51 * 
     52 * @param endpt     The media endpoint instance. 
     53 * @param name      Optional name to be assigned to the transport. 
     54 * @param port      UDP port number for the RTP socket. The RTCP port number 
     55 *                  will be set to one above RTP port. 
     56 * @param options   Options, bitmask of #pjmedia_transport_udp_options. 
     57 * @param p_tp      Pointer to receive the transport instance. 
     58 * 
     59 * @return          PJ_SUCCESS on success. 
    3360 */ 
    3461PJ_DECL(pj_status_t) pjmedia_transport_udp_create(pjmedia_endpt *endpt, 
    3562                                                  const char *name, 
    3663                                                  int port, 
     64                                                  unsigned options, 
    3765                                                  pjmedia_transport **p_tp); 
    3866 
    3967 
    4068/** 
    41  * Create UDP stream transport from existing socket info. 
     69 * Create UDP stream transport from existing sockets. Use this function when 
     70 * the sockets have previously been created. 
     71 * 
     72 * @param endpt     The media endpoint instance. 
     73 * @param name      Optional name to be assigned to the transport. 
     74 * @param si        Media socket info containing the RTP and RTCP sockets. 
     75 * @param options   Options, bitmask of #pjmedia_transport_udp_options. 
     76 * @param p_tp      Pointer to receive the transport instance. 
     77 * 
     78 * @return          PJ_SUCCESS on success. 
    4279 */ 
    4380PJ_DECL(pj_status_t) pjmedia_transport_udp_attach(pjmedia_endpt *endpt, 
    4481                                                  const char *name, 
    4582                                                  const pjmedia_sock_info *si, 
     83                                                  unsigned options, 
    4684                                                  pjmedia_transport **p_tp); 
    4785 
    4886 
    4987/** 
    50  * Close UDP transport. 
     88 * Close UDP transport. Application can also use the "destroy" member of 
     89 * media transport interface to close the UDP transport. 
    5190 */ 
    5291PJ_DECL(pj_status_t) pjmedia_transport_udp_close(pjmedia_transport *tp); 
  • pjproject/trunk/pjmedia/src/pjmedia/transport_udp.c

    r479 r483  
    3737 
    3838    pj_pool_t          *pool;           /**< Memory pool                    */ 
    39  
     39    unsigned            options;        /**< Transport options.             */ 
    4040    pjmedia_stream     *stream;         /**< Stream user (may be NULL)      */ 
    4141    pj_sockaddr_in      rem_rtp_addr;   /**< Remote RTP address             */ 
     
    109109                                                  const char *name, 
    110110                                                  int port, 
     111                                                  unsigned options, 
    111112                                                  pjmedia_transport **p_tp) 
    112113{ 
     
    153154     
    154155    /* Create UDP transport by attaching socket info */ 
    155     return pjmedia_transport_udp_attach( endpt, name, &si, p_tp); 
     156    return pjmedia_transport_udp_attach( endpt, name, &si, options, p_tp); 
    156157 
    157158 
     
    171172                                                  const char *name, 
    172173                                                  const pjmedia_sock_info *si, 
     174                                                  unsigned options, 
    173175                                                  pjmedia_transport **p_tp) 
    174176{ 
     
    199201    tp = pj_pool_zalloc(pool, sizeof(struct transport_udp)); 
    200202    tp->pool = pool; 
     203    tp->options = options; 
    201204    pj_ansi_strcpy(tp->base.name, name); 
    202205    tp->base.op = &transport_udp_op; 
     
    320323 
    321324        /* See if source address of RTP packet is different than the  
    322          * configured address. 
     325         * configured address, and switch RTP remote address to  
     326         * source packet address after several consecutive packets 
     327         * have been received. 
    323328         */ 
    324         if ((udp->rem_rtp_addr.sin_addr.s_addr !=  
    325              udp->rtp_src_addr.sin_addr.s_addr) || 
    326             (udp->rem_rtp_addr.sin_port !=  
    327              udp->rtp_src_addr.sin_port)) 
    328         { 
    329             udp->rtp_src_cnt++; 
    330  
    331             if (udp->rtp_src_cnt >= PJMEDIA_RTP_NAT_PROBATION_CNT) { 
    332              
    333                 udp->rem_rtp_addr = udp->rtp_src_addr; 
    334                 udp->rtp_src_cnt = 0; 
    335  
    336                 PJ_LOG(4,(udp->base.name, 
    337                           "Remote RTP address switched to %s:%d", 
    338                           pj_inet_ntoa(udp->rtp_src_addr.sin_addr), 
    339                           pj_ntohs(udp->rtp_src_addr.sin_port))); 
     329        if ((udp->options & PJMEDIA_UDP_NO_SRC_ADDR_CHECKING)==0) { 
     330            if ((udp->rem_rtp_addr.sin_addr.s_addr !=  
     331                 udp->rtp_src_addr.sin_addr.s_addr) || 
     332                (udp->rem_rtp_addr.sin_port !=  
     333                 udp->rtp_src_addr.sin_port)) 
     334            { 
     335                udp->rtp_src_cnt++; 
     336 
     337                if (udp->rtp_src_cnt >= PJMEDIA_RTP_NAT_PROBATION_CNT) { 
     338                 
     339                    pj_uint16_t port; 
     340 
     341                    /* Set remote RTP address to source address */ 
     342                    udp->rem_rtp_addr = udp->rtp_src_addr; 
     343 
     344                    /* Also update remote RTCP address */ 
     345                    pj_memcpy(&udp->rem_rtcp_addr, &udp->rem_rtp_addr,  
     346                              sizeof(pj_sockaddr_in)); 
     347                    port = (pj_uint16_t) 
     348                           (pj_ntohs(udp->rem_rtp_addr.sin_port)+1); 
     349                    udp->rem_rtcp_addr.sin_port = pj_htons(port); 
     350 
     351                    /* Reset counter */ 
     352                    udp->rtp_src_cnt = 0; 
     353 
     354                    PJ_LOG(4,(udp->base.name, 
     355                              "Remote RTP address switched to %s:%d", 
     356                              pj_inet_ntoa(udp->rtp_src_addr.sin_addr), 
     357                              pj_ntohs(udp->rtp_src_addr.sin_port))); 
     358                } 
    340359            } 
    341360        } 
  • pjproject/trunk/pjsip-apps/src/samples/simpleua.c

    r452 r483  
    284284    /* Create media transport */ 
    285285    status = pjmedia_transport_udp_attach(g_med_endpt, NULL, &g_med_skinfo, 
    286                                           &g_med_transport); 
     286                                          0, &g_med_transport); 
    287287    if (status != PJ_SUCCESS) { 
    288288        app_perror(THIS_FILE, "Unable to create media transport", status); 
  • pjproject/trunk/pjsip-apps/src/samples/streamutil.c

    r464 r483  
    133133    /* Create media transport */ 
    134134    status = pjmedia_transport_udp_create(med_endpt, NULL, local_port, 
    135                                           &transport); 
     135                                          0, &transport); 
    136136    if (status != PJ_SUCCESS) 
    137137        return status; 
Note: See TracChangeset for help on using the changeset viewer.