← Back to team overview

rohc team mailing list archive

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

 

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

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;
}


Regards,
V Ravi Kumar

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