← Back to team overview

rohc team mailing list archive

Re: [Question #269935]: IP/UDP/RTP header compression issue

 

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

Description changed to:
Hi,

I am trying to compress IP/UDP/RTP packet .But i am only getting 2 bytes
of header compression out of 40 bytes. The following is my
program.Please check it and suggest me where i am going wrong.

I am using O RTP library for rtp packet generation .

#include "rohc_rtp.h"

int runcond=1;

void stophandler(int signum)
{
    runcond=0;
}


static int gen_random_num(const struct rohc_comp *const comp,void *const user_context)
{
        return rand();
}

static bool rtp_detect(const unsigned char *const ip,
                       const unsigned char *const udp,
                       const unsigned char *const payload,
                       const unsigned int payload_size,
                       void *const rtp_private)
{
    uint16_t udp_dport;
    bool is_rtp;

    /* check UDP destination port */
    memcpy(&udp_dport, udp + 2, sizeof(uint16_t));
    if(ntohs(udp_dport) == 10042)
    {
        /* we think that the UDP packet is a RTP packet */
        fprintf(stderr, "RTP packet detected (expected UDP port)\n");
        is_rtp = true;
    }
    else
    {
        /* we think that the UDP packet is not a RTP packet */
        fprintf(stderr, "RTP packet not detected (wrong UDP port)\n");
        is_rtp = false;
    }

    return is_rtp;
}

static void print_rohc_traces(void *const priv_ctxt,
                              const rohc_trace_level_t level,
                              const rohc_trace_entity_t entity,
                              const int profile,
                              const char *const format,
                              ...)
{
        va_list args;
        va_start(args, format);
        vfprintf(stdout, format, args);
        va_end(args);
}

int main()
{
        char buffer[160]="",data[256]="";
        int i;
        FILE *infile;
        char *ssrc;
        uint32_t user_ts=0;
        int clockslide=0;
        int jitter=0;
        mblk_t *m=NULL;

        uint8_t rtp_buffer[BUFFER_SIZE]="";
        struct rohc_buf rtp_r_packet = rohc_buf_init_empty(rtp_buffer, BUFFER_SIZE);

        uint8_t rohc_buffer[BUFFER_SIZE]="";
        struct rohc_buf rohc_packet = rohc_buf_init_empty(rohc_buffer, BUFFER_SIZE);

        struct rohc_comp *compressor=NULL;
        unsigned int *rtpheader = (unsigned int*)data;
        RtpSession *rtp_session=NULL;
        rohc_status_t rohc_status;
        rtp_header_t *rtp_h;


        printf("Testing RTP header compression\n");

        /*create ROHC compressor */

        compressor = rohc_comp_new2(ROHC_SMALL_CID, ROHC_SMALL_CID_MAX,gen_random_num, NULL);
         if(compressor == NULL)
         {
                printf("Failed create the ROHC compressor\n");
                return 1;
         }

         if(!rohc_comp_set_traces_cb2(compressor, print_rohc_traces, NULL))
         {
                printf("failed to set the callback for traces on compressor\n");
                return 1;
         }


        /* Compressor profile creation */

        if(!rohc_comp_enable_profile(compressor, ROHC_PROFILE_RTP))
        {
                printf("failed to enable the RTP profile\n");
                /* cleanup compressor, then leave with an error code */
                rohc_comp_free(compressor);
                return 1;
        }

        /*Prepare Fake RTP packet */

         /* Create the actual packet that we will be sending */

        ortp_init();
        ortp_scheduler_init();
        rtp_session=rtp_session_new(RTP_SESSION_SENDONLY);
        rtp_session_set_scheduling_mode(rtp_session,1);
        rtp_session_set_blocking_mode(rtp_session,1);
        rtp_session_set_remote_addr(rtp_session,"192.168.1.36",5087);
        rtp_session_set_payload_type(rtp_session,0);
        ssrc=getenv("SSRC");
        if (ssrc!=NULL) {
                printf("using SSRC=%i.\n",atoi(ssrc));
                rtp_session_set_ssrc(rtp_session,atoi(ssrc));
        }
        infile=fopen("/home/vravi/lat-tests/prepaid-press1-listen-lastcall.wav","r");
        if (infile==NULL) {
                perror("Cannot open file");
                return -1;
        }
        signal(SIGINT,stophandler);
        printf("Reading  DATA FROM FILE AND CREATING RTP STREAM\n");
     while( ((i=fread(buffer,1,160,infile))>0) && (runcond) )
         {
                rohc_buf_reset(&rtp_r_packet);
                rohc_buf_reset(&rohc_packet);
                m = rtp_session_create_packet_with_data(rtp_session,(char*)buffer,i,NULL);
                ((rtp_header_t*) m->b_rptr)->seq_number = 156;
                ((rtp_header_t*) m->b_rptr)->timestamp = time(0);
                printf("SIZE OF ACTUAL RTP :  < %d > , RTP  HEADER LENGTH : < %d > , RTP PAYLOAD LENGTH : < %d > \n",  msgdsize(m),rtpheader_size(m),rtppayload_size(m));


                rtp_r_packet.len = 5 * 4 + 8 + 12 + rtppayload_size(m);
        //      rtp_r_packet.len = 5 * 4 + 8 + 12 ;

        /* IPv4 header */
        rohc_buf_byte_at(rtp_r_packet, 0) = 4 << 4; /* IP version 4 */
        rohc_buf_byte_at(rtp_r_packet, 0) |= 5; /* IHL: minimal IPv4 header length (in 32-bit words) */
        rohc_buf_byte_at(rtp_r_packet, 1) = 0; /* TOS */
        rohc_buf_byte_at(rtp_r_packet, 2) = (rtp_r_packet.len >> 8) & 0xff; /* Total Length */
        rohc_buf_byte_at(rtp_r_packet, 3) = rtp_r_packet.len & 0xff;
        rohc_buf_byte_at(rtp_r_packet, 4) = 0; /* IP-ID */
        rohc_buf_byte_at(rtp_r_packet, 5) = 0;
        rohc_buf_byte_at(rtp_r_packet, 6) = 0; /* Fragment Offset and IP flags */
        rohc_buf_byte_at(rtp_r_packet, 7) = 0;
        rohc_buf_byte_at(rtp_r_packet, 8) = 1; /* TTL */
        rohc_buf_byte_at(rtp_r_packet, 9) = 17; /* Protocol: UDP */
        rohc_buf_byte_at(rtp_r_packet, 10) = 0xa9; /* fake Checksum */
        rohc_buf_byte_at(rtp_r_packet, 11) = 0xa0;
        rohc_buf_byte_at(rtp_r_packet, 12) = 0x01; /* Source address */
        rohc_buf_byte_at(rtp_r_packet, 13) = 0x02;
        rohc_buf_byte_at(rtp_r_packet, 14) = 0x03;
        rohc_buf_byte_at(rtp_r_packet, 15) = 0x04;
        rohc_buf_byte_at(rtp_r_packet, 16) = 0x05; /* Destination address */
        rohc_buf_byte_at(rtp_r_packet, 17) = 0x06;
        rohc_buf_byte_at(rtp_r_packet, 18) = 0x07;
        rohc_buf_byte_at(rtp_r_packet, 19) = 0x08;

        /* UDP header */
        rohc_buf_byte_at(rtp_r_packet, 20) = 0x42; /* source port */
        rohc_buf_byte_at(rtp_r_packet, 21) = 0x42;
        rohc_buf_byte_at(rtp_r_packet, 22) = 0x27; /* destination port = 10042 */
        rohc_buf_byte_at(rtp_r_packet, 23) = 0x3a;
        rohc_buf_byte_at(rtp_r_packet, 24) = 0x00; /* UDP length */
        //rohc_buf_byte_at(rtp_r_packet, 25) = 8 + 12;
        rohc_buf_byte_at(rtp_r_packet, 25) = 8 + 12 + rtppayload_size(m);
        rohc_buf_byte_at(rtp_r_packet, 26) = 0x00; /* UDP checksum = 0 */
        rohc_buf_byte_at(rtp_r_packet, 27) = 0x00;

        /* RTP header */

//               rohc_buf_append(&rtp_r_packet, (uint8_t *)m->b_rptr , rtpheader_size(m));
//               rohc_buf_append(&rtp_r_packet, (uint8_t *)m->b_cont->b_rptr , rtppayload_size(m));


                memcpy(rohc_buf_data_at(rtp_r_packet, 28), (uint8_t *)m->b_rptr,rtpheader_size(m));

                /* copy the payload just after the IP/UDP/RTP headers */

        memcpy(rohc_buf_data_at(rtp_r_packet, 40), (uint8_t
*)m->b_cont->b_rptr,rtppayload_size(m));

        printf(" RTP detection Check uncompress \n");

                if(!rohc_comp_set_rtp_detection_cb(compressor, rtp_detect, NULL))
        {
                printf("failed to set RTP detection callback\n");
                return 1;
        }
                printf("IP/UDP/RTP PACKET SIZE BEFORE COMPRESSION : HEADER : < %d > , PAYLOAD : < %d > , TOTAL PACKET SIZE : < %d >\n" ,28 + rtpheader_size(m),rtppayload_size(m),28 + rtpheader_size(m) + rtppayload_size(m));
                /*compress the packet */
                rohc_status = rohc_compress4(compressor,rtp_r_packet, &rohc_packet);
                if(rohc_status != ROHC_STATUS_OK)
                {
                printf("compression of fake RTP packet failed: %s (%d)\n",rohc_strerror(rohc_status), rohc_status);
                rohc_comp_free(compressor);
                        fclose(infile);
                        rtp_session_destroy(rtp_session);
                        ortp_exit();
                return 1;
            }
                /*Print the size of compressed one */

                memset(buffer,0,sizeof(buffer));
        }
        fclose(infile);
        rtp_session_destroy(rtp_session);
        ortp_exit();
//      ortp_global_stats_display();


        /* Free compressor */
        if(compressor){
                rohc_comp_free(compressor);
        }
        return 0;
}


The following is the answer i got.


RTP packet detected (expected UDP port)
[c_rtp.c:343 c_rtp_check_profile()] RTP packet detected by the RTP callback
[rohc_comp.c:4813 rohc_comp_find_ctxt()] using profile 'IP/UDP/RTP' (0x0001)
[rohc_comp.c:4843 rohc_comp_find_ctxt()] using context CID = 0
[rohc_comp.c:1435 rohc_compress4()] compress the packet #355
[c_rtp.c:1441 rtp_changed_rtp_dynamic()] find changes in RTP dynamic fields
[c_rtp.c:1573 rtp_changed_rtp_dynamic()] TS_STRIDE changed now or in the last few packets
[c_rtp.c:1577 rtp_changed_rtp_dynamic()] 1 RTP dynamic fields changed
[c_generic.c:1218 c_generic_detect_changes()] SN = 65025
[c_generic.c:6310 detect_ip_id_behaviour()] 1) old_id = 0x0000 new_id = 0x0000
[c_generic.c:6315 detect_ip_id_behaviour()] IP-ID is constant (SID detected)
[c_generic.c:6357 detect_ip_id_behaviour()] NBO = 1, RND = 0, SID = 1
[c_generic.c:5932 changed_dynamic_both_hdr()] check for changed fields in the outer IP header
[c_generic.c:1283 c_generic_detect_changes()] send_static = 0, send_dynamic = 0
[c_rtp.c:1008 rtp_decide_state()] 1 RTP dynamic fields changed, stay in IR state
[c_generic.c:6427 encode_uncomp_fields()] compressor is in state 1
[c_generic.c:6432 encode_uncomp_fields()] new SN = 65025 / 0xfe01
[c_generic.c:6440 encode_uncomp_fields()] IR state: force using 16 bits to encode new SN
[c_generic.c:6455 encode_uncomp_fields()] 16 bits are required to encode new SN
[c_generic.c:6476 encode_uncomp_fields()] new outer IP-ID delta = 0x1ff / 511 (NBO = 1, RND = 0, SID = 1)
[c_generic.c:6484 encode_uncomp_fields()] IR state: force using 16 bits to encode new outer IP-ID delta
[c_generic.c:6507 encode_uncomp_fields()] 16 bits are required to encode new outer IP-ID delta
[scaled_rtp_ts.c:143 c_add_ts()] Timestamp = 2870067029
[scaled_rtp_ts.c:175 c_add_ts()] SN delta = 256
[scaled_rtp_ts.c:187 c_add_ts()] TS delta = 0
[scaled_rtp_ts.c:192 c_add_ts()] TS is constant, go in INIT_TS state
[c_rtp.c:1133 rtp_encode_uncomp_fields()] unscaled TS = 2870067029 on 0 bits
[c_rtp.c:1172 rtp_encode_uncomp_fields()] 0 bits are required to encode new TS
[c_generic.c:1498 decide_packet()] decide packet in IR state
[c_generic.c:1543 decide_packet()] packet 'IR' chosen
[c_generic.c:1720 code_IR_packet()] code IR packet (CID = 0)
[c_generic.c:1739 code_IR_packet()] small CID 0 encoded on 0 byte(s)
[c_generic.c:1751 code_IR_packet()] type of packet + D flag = 0xfd
[c_generic.c:1763 code_IR_packet()] profile ID = 0x01
[c_generic.c:1769 code_IR_packet()] CRC = 0x00 for CRC calculation
[c_generic.c:2090 code_ipv4_static_part()] version = 0x40
[c_generic.c:2095 code_ipv4_static_part()] protocol = 0x11
[c_generic.c:2104 code_ipv4_static_part()] src addr = 01020304 (1.2.3.4)
[c_generic.c:2111 code_ipv4_static_part()] dst addr = 05060708 (5.6.7.8)
[c_udp.c:490 udp_code_static_udp_part()] UDP source port = 0x4242
[c_udp.c:495 udp_code_static_udp_part()] UDP dest port = 0x3a27
[c_rtp.c:1227 rtp_code_static_rtp_part()] RTP SSRC = 0x6be71f9d
[c_generic.c:2340 code_ipv4_dynamic_part()] TOS = 0x00
[c_generic.c:2347 code_ipv4_dynamic_part()] TTL = 0x01
[c_generic.c:2357 code_ipv4_dynamic_part()] IP-ID = 0x00 0x00
[c_generic.c:2378 code_ipv4_dynamic_part()] (DF = 0, RND = 0, NBO = 1, SID = 1) = 0x30
[c_generic.c:2390 code_ipv4_dynamic_part()] Generic extension header list = 0x00
[c_rtp.c:1293 rtp_code_dynamic_rtp_part()] UDP checksum = 0x0000
[c_rtp.c:1314 rtp_code_dynamic_rtp_part()] (V = 2, P = 0, RX = 0, CC = 0x0) = 0x80
[c_rtp.c:1324 rtp_code_dynamic_rtp_part()] (M = 0, PT = 0x00) = 0x00
[c_rtp.c:1331 rtp_code_dynamic_rtp_part()] SN = 0xfe 0x01
[c_rtp.c:1339 rtp_code_dynamic_rtp_part()] TS = 0xab 0x11 0xbf 0x55
[c_rtp.c:1345 rtp_code_dynamic_rtp_part()] Generic CSRC list not supported yet, put a 0x00 byte
[c_generic.c:1809 code_IR_packet()] CRC (header length = 38, crc = 0x2f)
[rohc_comp.c:1563 rohc_compress4()] copy full 160-byte payload
[rohc_comp.c:1573 rohc_compress4()] ROHC size = 198 bytes (header = 38, payload = 160), output buffer size = 2048
SIZE OF ACTUAL RTP :  < 172 > , RTP  HEADER LENGTH : < 12 > , RTP PAYLOAD LENGTH : < 160 >
 RTP detection Check uncompress
IP/UDP/RTP PACKET SIZE BEFORE COMPRESSION : HEADER : < 40 > , PAYLOAD : < 160 > , TOTAL PACKET SIZE : < 200 >
[net_pkt.c:75 net_pkt_parse()] outer IP header: 200 bytes
[net_pkt.c:77 net_pkt_parse()] outer IP header: version 4
[net_pkt.c:82 net_pkt_parse()] outer IP header: next header is of type 17
[net_pkt.c:87 net_pkt_parse()] outer IP header: next layer is of type 17
[rohc_comp.c:4608 c_get_profile_from_packet()] try to find the best profile for packet with transport protocol 17
[c_rtp.c:291 c_rtp_check_profile()] Called rtp check profile function -RAVI

RTP packet detected (expected UDP port)
[c_rtp.c:343 c_rtp_check_profile()] RTP packet detected by the RTP callback
[rohc_comp.c:4813 rohc_comp_find_ctxt()] using profile 'IP/UDP/RTP' (0x0001)
[rohc_comp.c:4843 rohc_comp_find_ctxt()] using context CID = 0
[rohc_comp.c:1435 rohc_compress4()] compress the packet #356
[c_rtp.c:1441 rtp_changed_rtp_dynamic()] find changes in RTP dynamic fields
[c_rtp.c:1573 rtp_changed_rtp_dynamic()] TS_STRIDE changed now or in the last few packets
[c_rtp.c:1577 rtp_changed_rtp_dynamic()] 1 RTP dynamic fields changed
[c_generic.c:1218 c_generic_detect_changes()] SN = 65281
[c_generic.c:6310 detect_ip_id_behaviour()] 1) old_id = 0x0000 new_id = 0x0000
[c_generic.c:6315 detect_ip_id_behaviour()] IP-ID is constant (SID detected)
[c_generic.c:6357 detect_ip_id_behaviour()] NBO = 1, RND = 0, SID = 1
[c_generic.c:5932 changed_dynamic_both_hdr()] check for changed fields in the outer IP header
[c_generic.c:1283 c_generic_detect_changes()] send_static = 0, send_dynamic = 0
[c_rtp.c:1008 rtp_decide_state()] 1 RTP dynamic fields changed, stay in IR state
[c_generic.c:6427 encode_uncomp_fields()] compressor is in state 1
[c_generic.c:6432 encode_uncomp_fields()] new SN = 65281 / 0xff01
[c_generic.c:6440 encode_uncomp_fields()] IR state: force using 16 bits to encode new SN
[c_generic.c:6455 encode_uncomp_fields()] 16 bits are required to encode new SN
[c_generic.c:6476 encode_uncomp_fields()] new outer IP-ID delta = 0xff / 255 (NBO = 1, RND = 0, SID = 1)
[c_generic.c:6484 encode_uncomp_fields()] IR state: force using 16 bits to encode new outer IP-ID delta
[c_generic.c:6507 encode_uncomp_fields()] 16 bits are required to encode new outer IP-ID delta
[scaled_rtp_ts.c:143 c_add_ts()] Timestamp = 2870067029
[scaled_rtp_ts.c:175 c_add_ts()] SN delta = 256
[scaled_rtp_ts.c:187 c_add_ts()] TS delta = 0
[scaled_rtp_ts.c:192 c_add_ts()] TS is constant, go in INIT_TS state
[c_rtp.c:1133 rtp_encode_uncomp_fields()] unscaled TS = 2870067029 on 0 bits
[c_rtp.c:1172 rtp_encode_uncomp_fields()] 0 bits are required to encode new TS
[c_generic.c:1498 decide_packet()] decide packet in IR state
[c_generic.c:1543 decide_packet()] packet 'IR' chosen
[c_generic.c:1720 code_IR_packet()] code IR packet (CID = 0)
[c_generic.c:1739 code_IR_packet()] small CID 0 encoded on 0 byte(s)
[c_generic.c:1751 code_IR_packet()] type of packet + D flag = 0xfd
[c_generic.c:1763 code_IR_packet()] profile ID = 0x01
[c_generic.c:1769 code_IR_packet()] CRC = 0x00 for CRC calculation
[c_generic.c:2090 code_ipv4_static_part()] version = 0x40
[c_generic.c:2095 code_ipv4_static_part()] protocol = 0x11
[c_generic.c:2104 code_ipv4_static_part()] src addr = 01020304 (1.2.3.4)
[c_generic.c:2111 code_ipv4_static_part()] dst addr = 05060708 (5.6.7.8)
[c_udp.c:490 udp_code_static_udp_part()] UDP source port = 0x4242
[c_udp.c:495 udp_code_static_udp_part()] UDP dest port = 0x3a27
[c_rtp.c:1227 rtp_code_static_rtp_part()] RTP SSRC = 0x6be71f9d
[c_generic.c:2340 code_ipv4_dynamic_part()] TOS = 0x00
[c_generic.c:2347 code_ipv4_dynamic_part()] TTL = 0x01
[c_generic.c:2357 code_ipv4_dynamic_part()] IP-ID = 0x00 0x00
[c_generic.c:2378 code_ipv4_dynamic_part()] (DF = 0, RND = 0, NBO = 1, SID = 1) = 0x30
[c_generic.c:2390 code_ipv4_dynamic_part()] Generic extension header list = 0x00
[c_rtp.c:1293 rtp_code_dynamic_rtp_part()] UDP checksum = 0x0000
[c_rtp.c:1314 rtp_code_dynamic_rtp_part()] (V = 2, P = 0, RX = 0, CC = 0x0) = 0x80
[c_rtp.c:1324 rtp_code_dynamic_rtp_part()] (M = 0, PT = 0x00) = 0x00
[c_rtp.c:1331 rtp_code_dynamic_rtp_part()] SN = 0xff 0x01
[c_rtp.c:1339 rtp_code_dynamic_rtp_part()] TS = 0xab 0x11 0xbf 0x55
[c_rtp.c:1345 rtp_code_dynamic_rtp_part()] Generic CSRC list not supported yet, put a 0x00 byte
[c_generic.c:1809 code_IR_packet()] CRC (header length = 38, crc = 0x7e)
[rohc_comp.c:1563 rohc_compress4()] copy full 160-byte payload
[rohc_comp.c:1573 rohc_compress4()] ROHC size = 198 bytes (header = 38, payload = 160), output buffer size = 2048


Regards,
V Ravi Kumar

-- 
You received this question notification because you are a member of ROHC
Team, which is an answer contact for rohc.