Question #661623 on rohc changed:
https://answers.launchpad.net/rohc/+question/661623

regulararmy posted a new comment:
I  modify the code in the RTP callback,it shows as follows:
uint8_t count = 0;
uint32_t ssrc[4] = {0};
static bool rtp_detect_cb(const unsigned char *const ip,
                          const unsigned char *const udp,
                          const unsigned char *const payload,
                          const unsigned int payload_size,
                          void *const rtp_private)
{
        const uint16_t max_well_known_port = 1024;
        const uint16_t sip_port = 5060;
        uint16_t udp_sport;
        uint16_t udp_dport;
        uint16_t udp_len;
        uint8_t rtp_pt;
        uint32_t currentSsrc ;
        bool is_rtp = false;

        assert(ip != NULL);
        assert(udp != NULL);
        assert(payload != NULL);
        assert(rtp_private == NULL);

        /* retrieve UDP source and destination ports and UDP length */
        memcpy(&udp_sport, udp, sizeof(uint16_t));
        memcpy(&udp_dport, udp + 2, sizeof(uint16_t));
        memcpy(&udp_len, udp + 4, sizeof(uint16_t));

        /* RTP streams do not use well known ports */
        if(ntohs(udp_sport) <= max_well_known_port ||
           ntohs(udp_dport) <= max_well_known_port)
        {
                goto not_rtp;
        }

        /* SIP (UDP/5060) is not RTP */
        if(ntohs(udp_sport) == sip_port && ntohs(udp_dport) == sip_port)
        {
                goto not_rtp;
        }

        /* the UDP destination port of RTP packet is even (the RTCP destination
         * port are RTP destination port + 1, so it is odd) */
        if((ntohs(udp_dport) % 2) != 0)
        {
                goto not_rtp;
        }

        /* UDP Length shall not be too large */
        if(ntohs(udp_len) > 200)
        {
                goto not_rtp;
        }

        /* UDP payload shall at least contain the smallest RTP header */
        if(payload_size < 12)
        {
                goto not_rtp;
        }

        /* RTP version bits shall be 2 */
        if(((payload[0] >> 6) & 0x3) != 0x2)
        {
                goto not_rtp;
        }

        /* RTP payload type shall be GSM (0x03), ITU-T G.723 (0x04),
         * ITU-T G.729 (0x12), dynamic RTP type 97 (0x61),
         * telephony-event (0x65), Speex (0x72),
         * or dynamic RTP type 125 (0x7d) */
        rtp_pt = payload[1] & 0x7f;
        if(rtp_pt != 0x03 && rtp_pt != 0x04 && rtp_pt != 0x12 && rtp_pt != 0x61 
&&
           rtp_pt != 0x65 && rtp_pt != 0x72 && rtp_pt != 0x7d)
        {
                goto not_rtp;
        }

    memcpy(&currentSsrc, payload + 8, sizeof(uint32_t));
    if(ssrc[0] != ntohl(currentSsrc) || ssrc[1] != ntohl(currentSsrc)||ssrc[2] 
!= ntohl(currentSsrc) || ssrc[3] != ntohl(currentSsrc))
    {
        ssrc[count++ & 0x03] = ntohl(currentSsrc);
        goto not_rtp;
    }
        /* we think that the UDP packet is a RTP packet */
        is_rtp = true;

not_rtp:
        return is_rtp;
}

-- 
You received this question notification because your team ROHC Team is
an answer contact for rohc.

_______________________________________________
Mailing list: https://launchpad.net/~rohc
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~rohc
More help   : https://help.launchpad.net/ListHelp

Reply via email to