linphone-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Linphone-developers] oRTP patch: parsing received RTCP packets


From: Nicola Baldo
Subject: [Linphone-developers] oRTP patch: parsing received RTCP packets
Date: Mon, 13 Jun 2005 23:34:48 +0200
User-agent: Debian Thunderbird 1.0.2 (X11/20050331)

Hi Simon & everybody,

I've made some modifications to the oRTP library to add parsing of received RTCP packets. Please find attached the patch to the CVS version plus the oRTP/src/rtcpparse.c file I've written from scratch (it seems that you need write access to the CVS repository in order to do "cvs add <file>"...).

I've added a general framework for parsing RTCP packets within a compoud RTCP packet; also, parsing of RTCP Sender Reports and Receiver Reports is included. Parsing of RTCP SDES, BYE and APP packet is still not implemented, but could be added easily.

Parsing received RTCP packets gives access to a whole bunch of interesting statistics, e.g. Round Trip Time (for which I've implemented the calculation as per RFC 1889), packet count and packet losses at the other transmission end, etc. I think it could be nice and useful to store this information somewhere (what about session->rtp->stats ?). I've not done this myself in order to modify the original source code as little as possible.

Of course, I would be delighted if this patch could be merged into the current version. Unfortunately, I have no time for further developments, at least in the near future...

Regards,

Nicola
? .in
? config.h.in
? coreapi/.libs
? coreapi/arts.lo
? coreapi/authentication.lo
? coreapi/chat.lo
? coreapi/enum.lo
? coreapi/exevents.lo
? coreapi/friend.lo
? coreapi/liblinphone.la
? coreapi/linphonecore.lo
? coreapi/lpconfig.lo
? coreapi/misc.lo
? coreapi/presence.lo
? coreapi/proxy.lo
? coreapi/sdphandler.lo
? exosip/.deps
? exosip/.libs
? exosip/Makefile
? exosip/Makefile.in
? exosip/eXosip.lo
? exosip/eXutils.lo
? exosip/jauth.lo
? exosip/jcall.lo
? exosip/jcallback.lo
? exosip/jdialog.lo
? exosip/jevents.lo
? exosip/jfreinds.lo
? exosip/jidentity.lo
? exosip/jnotify.lo
? exosip/jpipe.lo
? exosip/jpublish.lo
? exosip/jreg.lo
? exosip/jrequest.lo
? exosip/jresponse.lo
? exosip/jsubscribe.lo
? exosip/jsubscribers.lo
? exosip/libeXosip.la
? exosip/misc.lo
? exosip/sdp_offans.lo
? exosip/udp.lo
? ipkg/Makefile
? ipkg/Makefile.in
? m4/Makefile
? m4/Makefile.in
? mediastreamer/test_speex
? mediastreamer2/.deps
? mediastreamer2/.libs
? mediastreamer2/Makefile
? mediastreamer2/Makefile.in
? mediastreamer2/alsacard.lo
? mediastreamer2/hpuxsndcard.lo
? mediastreamer2/jackcard.lo
? mediastreamer2/libmediastreamer2.la
? mediastreamer2/ms.lo
? mediastreamer2/msAlawdec.lo
? mediastreamer2/msAlawenc.lo
? mediastreamer2/msbuffer.lo
? mediastreamer2/msfifo.lo
? mediastreamer2/msfilter.lo
? mediastreamer2/msqueue.lo
? mediastreamer2/msringplayer.lo
? mediastreamer2/mssndread.lo
? mediastreamer2/mssndwrite.lo
? mediastreamer2/mssync.lo
? mediastreamer2/osscard.lo
? mediastreamer2/sndcard.lo
? oRTP/acinclude.m4
? oRTP/config.guess
? oRTP/config.sub
? oRTP/depcomp
? oRTP/install-sh
? oRTP/ltmain.sh
? oRTP/missing
? oRTP/build/win32/Makefile
? oRTP/build/win32/Makefile.in
? oRTP/include/Makefile
? oRTP/include/Makefile.in
? oRTP/include/ortp/Makefile
? oRTP/include/ortp/Makefile.in
? oRTP/src/rtcpparse.c
? oRTP/src/tests/.deps
? oRTP/src/tests/.libs
? oRTP/src/tests/Makefile
? oRTP/src/tests/Makefile.in
? oRTP/src/tests/mrtprecv
? oRTP/src/tests/mrtpsend
? oRTP/src/tests/rtpmemtest
? oRTP/src/tests/rtprecv
? oRTP/src/tests/rtpsend
? oRTP/src/tests/test_timer
? oRTP/src/tests/tevmrtprecv
? oRTP/src/tests/tevrtprecv
? oRTP/src/tests/tevrtpsend
? share/linphone.pc
? support/.deps
? support/Makefile
? support/Makefile.in
Index: m4/ilbc.m4
===================================================================
RCS file: /cvsroot/linphone/linphone/m4/ilbc.m4,v
retrieving revision 1.2
diff -u -r1.2 ilbc.m4
--- m4/ilbc.m4  19 May 2005 15:56:58 -0000      1.2
+++ m4/ilbc.m4  13 Jun 2005 20:56:15 -0000
@@ -13,9 +13,11 @@
        CPPFLAGS=$ILBC_CFLAGS
        LDFLAGS_save=$LDFLAGS
        LDFLAGS=$ILBC_LIBS
+       dnl AC_CHECK_LIB adds ilbc to LIBS, I don't want that !
+       LIBS_save=$LIBS
        
AC_CHECK_HEADERS(iLBC_decode.h,[AC_CHECK_LIB(ilbc,iLBC_decode,ilbc_found=yes,ilbc_found=no)
        ],ilbc_found=no)
-       
+       LIBS=$LIBS_save
        CPPFLAGS=$CPPFLAGS_save
        LDFLAGS=$LDFLAGS_save
        
Index: oRTP/include/ortp/rtcp.h
===================================================================
RCS file: /cvsroot/linphone/linphone/oRTP/include/ortp/rtcp.h,v
retrieving revision 1.1
diff -u -r1.1 rtcp.h
--- oRTP/include/ortp/rtcp.h    4 Mar 2005 13:30:14 -0000       1.1
+++ oRTP/include/ortp/rtcp.h    13 Jun 2005 20:56:15 -0000
@@ -27,6 +27,8 @@
 
 #define RTCP_SENDER_INFO_SIZE 20
 #define RTCP_REPORT_BLOCK_SIZE 24
+#define RTCP_COMMON_HEADER_SIZE 4
+#define RTCP_SSRC_FIELD_SIZE 4
 
 
 /* RTCP common header */
Index: oRTP/include/ortp/rtpsession.h
===================================================================
RCS file: /cvsroot/linphone/linphone/oRTP/include/ortp/rtpsession.h,v
retrieving revision 1.2
diff -u -r1.2 rtpsession.h
--- oRTP/include/ortp/rtpsession.h      3 Jun 2005 14:32:22 -0000       1.2
+++ oRTP/include/ortp/rtpsession.h      13 Jun 2005 20:56:15 -0000
@@ -126,8 +126,8 @@
        poly32_t hwrcv_extseq; /* last received on socket extended sequence 
number */
        guint32 hwrcv_seq_at_last_SR;
        guint hwrcv_since_last_SR;
-       guint32 last_rcv_SR_ts;
-       struct timeval last_rcv_SR_time;
+       guint32 last_rcv_SR_ts;     /* NTP timestamp (middle 32 bits) of last 
received SR */
+       struct timeval last_rcv_SR_time;   /* time at which last SR was 
received  */
        guint16 snd_seq; /* send sequence number */
        guint32 last_rtcp_report_snt_r; /* the time of the last rtcp report 
sent, in recv timestamp unit */
        guint32 last_rtcp_report_snt_s; /* the time of the last rtcp report 
sent, in send timestamp unit */
Index: oRTP/src/Makefile.am
===================================================================
RCS file: /cvsroot/linphone/linphone/oRTP/src/Makefile.am,v
retrieving revision 1.37
diff -u -r1.37 Makefile.am
--- oRTP/src/Makefile.am        4 Mar 2005 13:30:15 -0000       1.37
+++ oRTP/src/Makefile.am        13 Jun 2005 20:56:16 -0000
@@ -27,7 +27,8 @@
                        ortp-config-win32.h errno-win32.h \
                        payloadtype.c \
                        rtcp.c  \
-                       utils.c utils.h
+                       utils.c utils.h \
+                       rtcpparse.c 
 
 
 libortp_la_LIBADD=$(GLIB_LIBS) $(PTHREAD_LIBS) -lm
Index: oRTP/src/rtcp.c
===================================================================
RCS file: /cvsroot/linphone/linphone/oRTP/src/rtcp.c,v
retrieving revision 1.7
diff -u -r1.7 rtcp.c
--- oRTP/src/rtcp.c     4 Mar 2005 13:30:15 -0000       1.7
+++ oRTP/src/rtcp.c     13 Jun 2005 20:56:16 -0000
@@ -234,7 +234,7 @@
        b->cum_num_packet_lost=htonl((guint32)stream->stats.cum_packet_loss);
        b->interarrival_jitter=htonl((guint32) stream->jittctl.inter_jitter);
        b->ext_high_seq_num_rec=htonl(stream->hwrcv_extseq.one);
-       b->lsr=stream->last_rcv_SR_ts;
+       b->lsr=htonl(stream->last_rcv_SR_ts);
        b->delay_snc_last_sr=htonl(delay_snc_last_sr);
 }
 
Index: oRTP/src/rtpsession.c
===================================================================
RCS file: /cvsroot/linphone/linphone/oRTP/src/rtpsession.c,v
retrieving revision 1.96
diff -u -r1.96 rtpsession.c
--- oRTP/src/rtpsession.c       3 Jun 2005 14:32:22 -0000       1.96
+++ oRTP/src/rtpsession.c       13 Jun 2005 20:56:19 -0000
@@ -1252,7 +1252,7 @@
        return error;
 }
 
-
+extern void rtcp_parse(RtpSession *session, mblk_t *mp);
 
 static gint
 rtcp_recv (RtpSession * session)
@@ -1293,8 +1293,8 @@
                                mp->b_wptr = p;
                        mp->b_wptr += error;
                        mp->b_datap->db_lim = mp->b_wptr;
-                       /* then parse the message and put on queue */
-                       //rtcp_parse (session, mp);
+                       /* then parse the message */
+                       rtcp_parse (session, mp);
                        freemsg(mp);
                        session->rtcp.cached_mp=NULL;
                        if (addrlen>0){
/*
  The oRTP library is an RTP (Realtime Transport Protocol - rfc1889) stack.
  Copyright (C) 2001  Simon MORLAT address@hidden

  This source code file was written by Nicola Baldo as an extension of 
  the oRTP library. Copyright (C) 2005 Nicola Baldo address@hidden

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/


#include <ortp/ortp.h>



void report_block_parse(RtpSession *session, report_block_t *rb, struct timeval 
rcv_time_tv)
{               
  rb->ssrc = ntohl(rb->ssrc);

  if ( rb->ssrc != session->send_ssrc )

    {
      ortp_debug("Received rtcp report block related to unknown ssrc (not from 
us)... discarded");
      return;
    }       

  else

    {
      guint32 rcv_time_msw;        
      guint32 rcv_time_lsw;
      guint32 rcv_time;
      double rtt;

      rcv_time_msw = rcv_time_tv.tv_sec;
      rcv_time_lsw = (guint32) 
((double)rcv_time_tv.tv_usec*(double)(1LL<<32)*1.0e-6);
      rcv_time = (rcv_time_msw<<16) | (rcv_time_lsw >> 16);

      rb->cum_num_packet_lost = ntohl(rb->cum_num_packet_lost);
      rb->ext_high_seq_num_rec = ntohl(rb->ext_high_seq_num_rec);
      rb->interarrival_jitter = ntohl(rb->interarrival_jitter);
      rb->lsr = ntohl(rb->lsr);
      rb->delay_snc_last_sr = ntohl(rb->delay_snc_last_sr);

                  
      /* calculating Round Trip Time*/ 
      if (rb->lsr != 0)
        {
          rtt = (double) (rcv_time - rb->delay_snc_last_sr - rb->lsr);
          rtt = rtt/65536;        
          //printf("RTT = %f s\n",rtt);
        }

    }

}


void rtcp_parse(RtpSession *session, mblk_t *mp)
{
  rtcp_common_header_t *rtcp;
  int msgsize;
  int rtcp_pk_size;
  RtpStream *rtpstream=&session->rtp;
  struct timeval rcv_time_tv;

  
  gettimeofday(&rcv_time_tv,NULL);
        
  g_return_if_fail(mp!=NULL);
        
  msgsize=mp->b_wptr-mp->b_rptr;

 

  if (msgsize < RTCP_COMMON_HEADER_SIZE)
    {
      ortp_debug("Receiving too short rtcp packet... discarded");
      return;
    }

  rtcp=(rtcp_common_header_t *)mp->b_rptr;


  /* compound rtcp packet can be composed by more than one rtcp message */
  while (msgsize >= RTCP_COMMON_HEADER_SIZE)

    {      

      if (rtcp->version!=2)
        {
          ortp_debug("Receiving rtcp packet with version number 
!=2...discarded");
          return;
        }
        
      /* convert header data from network order to host order */
      rtcp->length = ntohs(rtcp->length);


      switch (rtcp->packet_type)   

        {

        case RTCP_SR:

          {
            rtcp_sr_t *sr = (rtcp_sr_t *) rtcp;
            report_block_t *rb;
            int i;

            if ( ntohl(sr->ssrc) != session->recv_ssrc )
              {
                ortp_debug("Receiving rtcp sr packet from unknown ssrc.. 
discarded");           
                return;
              }     

            if (msgsize < RTCP_COMMON_HEADER_SIZE + RTCP_SSRC_FIELD_SIZE + 
RTCP_SENDER_INFO_SIZE + (RTCP_REPORT_BLOCK_SIZE*sr->ch.rc))
              {
                ortp_debug("Receiving too short rtcp sr packet... discarded");
                return;
              }     

            /* parsing RTCP Sender Info */ 
            sr->si.ntp_timestamp_msw = ntohl(sr->si.ntp_timestamp_msw);
            sr->si.ntp_timestamp_lsw = ntohl(sr->si.ntp_timestamp_lsw);
            sr->si.rtp_timestamp = ntohl(sr->si.rtp_timestamp);
            sr->si.senders_packet_count = ntohl(sr->si.senders_packet_count);
            sr->si.senders_octet_count = ntohl(sr->si.senders_octet_count);     
    

            /* saving data to fill LSR and DLSR field in next RTCP report to be 
transmitted  */
            rtpstream->last_rcv_SR_ts = (sr->si.ntp_timestamp_msw << 16) | 
(sr->si.ntp_timestamp_lsw >> 16);  
            rtpstream->last_rcv_SR_time.tv_usec = rcv_time_tv.tv_usec;
            rtpstream->last_rcv_SR_time.tv_sec = rcv_time_tv.tv_sec;            
    


            /* parsing all RTCP report blocks */          
            for (i=0; i<sr->ch.rc; i++)
              { 
                rb = &(sr->rb[i]);              
                report_block_parse(session, rb, rcv_time_tv);           
              }

          }
          break;



        case RTCP_RR:

          {
            rtcp_rr_t *rr = (rtcp_rr_t *) rtcp;
            report_block_t *rb;
            int i;

            if ( ntohl(rr->ssrc) != session->recv_ssrc )
              {
                ortp_debug("Receiving rtcp rr packet from unknown ssrc.. 
discarded");
                return;
              }

            if (msgsize < RTCP_COMMON_HEADER_SIZE + RTCP_SSRC_FIELD_SIZE + 
(RTCP_REPORT_BLOCK_SIZE*rr->ch.rc))
              {
                ortp_debug("Receiving too short rtcp sr packet... discarded");
                return;
              }     

            /* parsing all RTCP report blocks */          
            for (i=0; i<rr->ch.rc; i++)
              { 
                rb = &(rr->rb[i]);              
                report_block_parse(session, rb, rcv_time_tv);           
              }
  
          }
          break;
          
          
        case RTCP_SDES: 
          /* to be implemented */
          break;
                  
          
        case RTCP_BYE:
          /* to be implemented */
          break;
          
          
        case RTCP_APP:
          /* to be implemented */
          break;

          
        default:

          ortp_debug("Receiving unknown rtcp packet type... discarded");
          return;

        }

      
      rtcp_pk_size = ((rtcp->length)+1)*4;  /* current RTCP packet size, in 
octets */
      msgsize -= rtcp_pk_size;              /* size of unparsed portion of UDP 
packet, in octets */
      rtcp = (rtcp_common_header_t *) (rtcp_pk_size + (char *) rtcp);  /* 
pointer to next RTCP packet in current UDP packet */

    }
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]