Ignore:
Timestamp:
May 9, 2018 6:58:48 AM (6 years ago)
Author:
ming
Message:

Fixed #2087: Support for RTP and RTCP multiplexing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/transport_udp.c

    r5783 r5788  
    8383    char                rtp_pkt[RTP_LEN];/**< Incoming RTP packet buffer    */ 
    8484 
     85    pj_bool_t           enable_rtcp_mux;/**< Enable RTP & RTCP multiplexing?*/ 
     86    pj_bool_t           use_rtcp_mux;   /**< Use RTP & RTCP multiplexing?   */ 
    8587    pj_sock_t           rtcp_sock;      /**< RTCP socket                    */ 
    8688    pj_sockaddr         rtcp_addr_name; /**< Published RTCP address.        */ 
     
    179181}; 
    180182 
     183static const pj_str_t STR_RTCP_MUX      = { "rtcp-mux", 8 }; 
    181184 
    182185/** 
     
    398401    if (status != PJ_EPENDING) 
    399402        goto on_error; 
    400 #endif     
     403#endif   
    401404 
    402405    tp->ioqueue = ioqueue; 
     
    535538                                        sizeof(addr_text), 3))); 
    536539 
    537             /* Also update remote RTCP address if actual RTCP source 
    538              * address is not heard yet. 
    539              */ 
    540             if (!pj_sockaddr_has_addr(&udp->rtcp_src_addr)) { 
     540            if (udp->use_rtcp_mux) { 
     541                pj_sockaddr_cp(&udp->rem_rtcp_addr, &udp->rem_rtp_addr); 
     542                pj_sockaddr_cp(&udp->rtcp_src_addr, &udp->rem_rtcp_addr); 
     543            } else if (!pj_sockaddr_has_addr(&udp->rtcp_src_addr)) { 
     544                /* Also update remote RTCP address if actual RTCP source 
     545                 * address is not heard yet. 
     546                 */ 
    541547                pj_uint16_t port; 
    542548 
     
    666672    info->sock_info.rtp_addr_name = udp->rtp_addr_name; 
    667673    info->sock_info.rtcp_sock = udp->rtcp_sock; 
    668     info->sock_info.rtcp_addr_name = udp->rtcp_addr_name; 
     674    info->sock_info.rtcp_addr_name = (udp->use_rtcp_mux? 
     675                                      udp->rtp_addr_name: 
     676                                      udp->rtcp_addr_name); 
    669677 
    670678    /* Get remote address originating RTP & RTCP. */ 
     
    709717    /* Must not be "attached" to existing application */ 
    710718    //PJ_ASSERT_RETURN(!udp->attached, PJ_EINVALIDOP); 
     719 
     720    /* Check again if we are multiplexing RTP & RTCP. */ 
     721    udp->use_rtcp_mux = (pj_sockaddr_has_addr(rem_addr) && 
     722                         pj_sockaddr_cmp(rem_addr, rem_rtcp) == 0); 
    711723 
    712724    /* Lock the ioqueue keys to make sure that callbacks are 
     
    978990 
    979991    sent = size; 
    980     status = pj_ioqueue_sendto( udp->rtcp_key, &udp->rtcp_write_op, 
     992    status = pj_ioqueue_sendto( (udp->use_rtcp_mux? udp->rtp_key: 
     993                                 udp->rtcp_key), &udp->rtcp_write_op, 
    981994                                pkt, &sent, 0, addr, addr_len); 
    982995 
     
    9981011    PJ_ASSERT_RETURN(tp && pool, PJ_EINVAL); 
    9991012    udp->media_options = options; 
     1013    udp->enable_rtcp_mux = ((options & PJMEDIA_TPMED_RTCP_MUX) != 0); 
    10001014 
    10011015    PJ_UNUSED_ARG(sdp_remote); 
     
    10261040            pjmedia_sdp_media_deactivate(pool, m_loc); 
    10271041            return PJMEDIA_SDP_EINPROTO; 
     1042        } 
     1043    } 
     1044     
     1045    if (udp->enable_rtcp_mux) { 
     1046        pjmedia_sdp_media *m = sdp_local->media[media_index]; 
     1047        pjmedia_sdp_attr *attr; 
     1048        pj_bool_t add_rtcp_mux = PJ_TRUE; 
     1049 
     1050        udp->use_rtcp_mux = PJ_FALSE; 
     1051 
     1052        /* Check if remote wants RTCP mux */ 
     1053        if (rem_sdp) { 
     1054            pjmedia_sdp_media *rem_m = rem_sdp->media[media_index]; 
     1055             
     1056            attr = pjmedia_sdp_attr_find(rem_m->attr_count, rem_m->attr,  
     1057                                         &STR_RTCP_MUX, NULL); 
     1058            udp->use_rtcp_mux = (attr? PJ_TRUE: PJ_FALSE); 
     1059            add_rtcp_mux = udp->use_rtcp_mux; 
     1060        } 
     1061 
     1062        /* Remove RTCP attribute because for subsequent offers/answers, 
     1063         * the address (obtained from transport_get_info() ) may be 
     1064         * incorrect if we are not yet confirmed to use RTCP mux 
     1065         * (because we are still waiting for remote answer) or 
     1066         * if remote rejects it. 
     1067         */ 
     1068        pjmedia_sdp_attr_remove_all(&m->attr_count, m->attr, "rtcp"); 
     1069         
     1070        if (!udp->use_rtcp_mux) { 
     1071           /* Add RTCP attribute if the remote doesn't offer or 
     1072            * rejects it. 
     1073            */ 
     1074            attr = pjmedia_sdp_attr_create_rtcp(pool, 
     1075                                                &udp->rtcp_addr_name);   
     1076            if (attr) 
     1077                pjmedia_sdp_attr_add(&m->attr_count, m->attr, attr); 
     1078        } 
     1079 
     1080        /* Add a=rtcp-mux attribute. */ 
     1081        if (add_rtcp_mux) { 
     1082            attr = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_attr); 
     1083            attr->name = STR_RTCP_MUX; 
     1084            m->attr[m->attr_count++] = attr; 
    10281085        } 
    10291086    } 
Note: See TracChangeset for help on using the changeset viewer.