Fix for ticket 1198 (with patch)

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

 



Hi there,
I've implemented a fix for the ticket https://trac.pjsip.org/repos/ticket/1198.

Would be great if this could get integrated.

Kind regards,
Michael
Index: pjmedia/include/pjmedia/rtcp.h
===================================================================
--- pjmedia/include/pjmedia/rtcp.h	(revision 6033)
+++ pjmedia/include/pjmedia/rtcp.h	(working copy)
@@ -239,7 +239,8 @@
     unsigned		    rtp_last_ts;/**< Last timestamp in RX RTP pkt.  */
 
     unsigned		    clock_rate;	/**< Clock rate of the stream	    */
-    unsigned		    pkt_size;	/**< Avg pkt size, in samples.	    */
+    unsigned		    rx_frm_size;/**< RX frame size, in samples.	    */
+    unsigned		    tx_pkt_size;/**< TX pkt size, in samples.	    */
     pj_uint32_t		    received;   /**< # pkt received		    */
     pj_uint32_t		    exp_prior;	/**< # pkt expected at last interval*/
     pj_uint32_t		    rx_prior;	/**< # pkt received at last interval*/
@@ -276,11 +277,12 @@
  */
 typedef struct pjmedia_rtcp_session_setting
 {
-    char	    *name;		/**< RTCP session name.		*/
-    unsigned	     clock_rate;	/**< Sequence.			*/
-    unsigned	     samples_per_frame;	/**< Timestamp.			*/
-    pj_uint32_t	     ssrc;		/**< Sender SSRC.		*/
-    pj_uint32_t	     rtp_ts_base;	/**< Base RTP timestamp.	*/
+    char	    *name;		    /**< RTCP session name.	*/
+    unsigned	     clock_rate;	    /**< Sequence.		*/
+    unsigned	     rx_samples_per_frame;  /**< RX samples per frame.	*/
+    unsigned	     tx_samples_per_pkt;    /**< TX samples per packet.	*/
+    pj_uint32_t	     ssrc;		    /**< Sender SSRC.		*/
+    pj_uint32_t	     rtp_ts_base;	    /**< Base RTP timestamp.	*/
 } pjmedia_rtcp_session_setting;
 
 
@@ -304,17 +306,19 @@
 /**
  * Initialize RTCP session.
  *
- * @param session	    The session
- * @param name		    Optional name to identify the session (for
- *			    logging purpose).
- * @param clock_rate	    Codec clock rate in samples per second.
- * @param samples_per_frame Average number of samples per frame.
- * @param ssrc		    The SSRC used in to identify the session.
+ * @param session		The session
+ * @param name			Optional name to identify the session (for
+ *				logging purpose).
+ * @param clock_rate		Codec clock rate in samples per second.
+ * @param rx_samples_per_frame	RX samples per frame.
+ * @param tx_samples_per_pkt	TX samples per packet.
+ * @param ssrc			The SSRC used in to identify the session.
  */
 PJ_DECL(void) pjmedia_rtcp_init( pjmedia_rtcp_session *session, 
 				 char *name,
 				 unsigned clock_rate,
-				 unsigned samples_per_frame,
+				 unsigned rx_samples_per_frame,
+				 unsigned tx_samples_per_pkt,
 				 pj_uint32_t ssrc );
 
 
@@ -381,6 +385,25 @@
 
 
 /**
+ * Call this function everytime an RTP packet is received to let the RTCP
+ * session do its internal calculations.
+ *
+ * @param session	The session.
+ * @param seq		The RTP packet sequence number, in host byte order.
+ * @param ts		The RTP packet timestamp, in host byte order.
+ * @param payload	Size of the payload.
+ * @param discarded	Flag to specify whether the packet is discarded.
+ * @param frms_per_pkt	Received frames per packet.
+ */
+PJ_DECL(void) pjmedia_rtcp_rx_rtp3(pjmedia_rtcp_session *session,
+				   unsigned seq,
+				   unsigned ts,
+				   unsigned payload,
+				   pj_bool_t discarded,
+				   unsigned frms_per_pkt);
+
+
+/**
  * Call this function everytime an RTP packet is sent to let the RTCP session
  * do its internal calculations.
  *
Index: pjmedia/src/pjmedia/rtcp.c
===================================================================
--- pjmedia/src/pjmedia/rtcp.c	(revision 6033)
+++ pjmedia/src/pjmedia/rtcp.c	(working copy)
@@ -192,7 +192,8 @@
 PJ_DEF(void) pjmedia_rtcp_init(pjmedia_rtcp_session *sess, 
 			       char *name,
 			       unsigned clock_rate,
-			       unsigned samples_per_frame,
+			       unsigned rx_samples_per_frame,
+			       unsigned tx_samples_per_pkt,
 			       pj_uint32_t ssrc)
 {
     pjmedia_rtcp_session_setting settings;
@@ -200,7 +201,8 @@
     pjmedia_rtcp_session_setting_default(&settings);
     settings.name = name;
     settings.clock_rate = clock_rate;
-    settings.samples_per_frame = samples_per_frame;
+    settings.rx_samples_per_frame = rx_samples_per_frame;
+    settings.tx_samples_per_pkt = tx_samples_per_pkt;
     settings.ssrc = ssrc;
 
     pjmedia_rtcp_init2(sess, &settings);
@@ -227,7 +229,8 @@
 
     /* Set clock rate */
     sess->clock_rate = settings->clock_rate;
-    sess->pkt_size = settings->samples_per_frame;
+    sess->rx_frm_size = settings->rx_samples_per_frame;
+    sess->tx_pkt_size = settings->tx_samples_per_pkt;
 
     /* Init common RTCP SR header */
     sr_pkt->common.version = 2;
@@ -288,6 +291,16 @@
 				  unsigned rtp_ts,
 				  unsigned payload,
 				  pj_bool_t discarded)
+{
+    pjmedia_rtcp_rx_rtp3(sess, seq, rtp_ts, payload, discarded, 1);
+}
+
+PJ_DEF(void) pjmedia_rtcp_rx_rtp3(pjmedia_rtcp_session *sess,
+				  unsigned seq,
+				  unsigned rtp_ts,
+				  unsigned payload,
+				  pj_bool_t discarded,
+				  unsigned frms_per_pkt)
 {   
     pj_timestamp ts;
     pj_uint32_t arrival;
@@ -347,7 +360,8 @@
 	unsigned count = seq_st.diff - 1;
 	unsigned period;
 
-	period = count * sess->pkt_size * 1000 / sess->clock_rate;
+	period = (count * sess->rx_frm_size * frms_per_pkt * 1000) /
+	    sess->clock_rate;
 	period *= 1000;
 
 	/* Update packet lost. 
@@ -558,7 +572,7 @@
 	unsigned period;
 
 	/* Loss period in msec */
-	period = (sess->stat.tx.loss - last_loss) * sess->pkt_size *
+	period = (sess->stat.tx.loss - last_loss) * sess->tx_pkt_size *
 		 1000 / sess->clock_rate;
 
 	/* Loss period in usec */
Index: pjmedia/src/pjmedia/stream.c
===================================================================
--- pjmedia/src/pjmedia/stream.c	(revision 6033)
+++ pjmedia/src/pjmedia/stream.c	(working copy)
@@ -1747,6 +1747,7 @@
     pjmedia_rtp_status seq_st;
     pj_status_t status;
     pj_bool_t pkt_discarded = PJ_FALSE;
+    unsigned frm_count = 1;
 
     /* Check for errors */
     if (bytes_read < 0) {
@@ -2040,6 +2041,9 @@
 		pkt_discarded = PJ_TRUE;
 	}
 
+	/* copy frame count */
+	frm_count = count;
+
 #if TRACE_JB
 	trace_jb_put(stream, hdr, payloadlen, count);
 #endif
@@ -2068,8 +2072,9 @@
     if (stream->rtcp.peer_ssrc == 0)
 	stream->rtcp.peer_ssrc = channel->rtp.peer_ssrc;
 
-    pjmedia_rtcp_rx_rtp2(&stream->rtcp, pj_ntohs(hdr->seq),
-			 pj_ntohl(hdr->ts), payloadlen, pkt_discarded);
+    pjmedia_rtcp_rx_rtp3(&stream->rtcp, pj_ntohs(hdr->seq),
+			 pj_ntohl(hdr->ts), payloadlen, pkt_discarded,
+			 frm_count);
 
     /* RTCP-FB generic NACK */
     if (stream->rtcp.received >= 10 && seq_st.diff > 1 &&
@@ -2600,13 +2605,15 @@
 	rtcp_setting.ssrc = info->ssrc;
 	rtcp_setting.rtp_ts_base = pj_ntohl(stream->enc->rtp.out_hdr.ts);
 	rtcp_setting.clock_rate = info->fmt.clock_rate;
-	rtcp_setting.samples_per_frame = PJMEDIA_AFD_SPF(afd);
+	rtcp_setting.rx_samples_per_frame = PJMEDIA_PIA_SPF(&stream->port.info);
+	rtcp_setting.tx_samples_per_pkt = stream->enc_samples_per_pkt;
 
 #if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG!=0)
 	/* Special case for G.722 */
 	if (info->fmt.pt == PJMEDIA_RTP_PT_G722) {
-	    rtcp_setting.clock_rate = 8000;
-	    rtcp_setting.samples_per_frame = 160;
+	    rtcp_setting.rx_samples_per_frame =
+		PJMEDIA_PIA_SPF(&stream->port.info) * 2;
+	    rtcp_setting.tx_samples_per_pkt = stream->enc_samples_per_pkt * 2;
 	}
 #endif
 
_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux