]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11056: [core] fix RTCP lost calculation
authorSergey Khripchenko <shripchenko@intermedia.net>
Wed, 28 Feb 2018 16:27:30 +0000 (08:27 -0800)
committerMuteesa Fred <muteesafred@hotmail.com>
Tue, 24 Jul 2018 07:21:41 +0000 (07:21 +0000)
RTCP/Receiver Report/lost field is a _signed_ 24bit integer and it could be negative (in case of UDP duplication)
+ any negatives now threated as huge uint32_t
+ set this field properly on __BIG_ENDIAN
+ correctly read this value in received RTCP on all arches

src/include/switch_rtcp_frame.h
src/switch_rtp.c

index 9e5af7622664c09363b660775128cb70ef90d687..965599b6238d30e9e087276432000c10a69238f3 100644 (file)
@@ -45,7 +45,7 @@ SWITCH_BEGIN_EXTERN_C
 struct switch_rtcp_report_block_frame {
        uint32_t ssrc; /* The SSRC identifier of the source to which the information in this reception report block pertains. */
        uint8_t fraction; /* The fraction of RTP data packets from source SSRC_n lost since the previous SR or RR packet was sent */
-       uint32_t lost;  /* The total number of RTP data packets from source SSRC_n that have been lost since the beginning of reception */
+       int32_t lost;  /* The total number of RTP data packets from source SSRC_n that have been lost since the beginning of reception. could be negative. */
        uint32_t highest_sequence_number_received;
        uint32_t jitter; /* An estimate of the statistical variance of the RTP data packet interarrival time, measured in timestamp units and expressed as an unsigned integer. */
        uint32_t lsr; /* The middle 32 bits out of 64 in the NTP timestamp */
index 44c4b041c4bc019f681a88fba19069d34fac44d2..3e637da509b06ac20a1455f616b00caa2acc1187 100644 (file)
@@ -1820,9 +1820,11 @@ static void rtcp_generate_report_block(switch_rtp_t *rtp_session, struct switch_
        } else {
                rtcp_report_block->fraction = 0;
        }
-#if SWITCH_BYTE_ORDER != __BIG_ENDIAN
+#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
+       rtcp_report_block->lost = stats->cum_lost;
+#else
        /* Reversing byte order for 24bits */
-       rtcp_report_block->lost = (((stats->cum_lost&0x0000FF)<<16) | ((stats->cum_lost&0x00FF00)) | ((stats->cum_lost&0xFF0000)>>16));
+       rtcp_report_block->lost = htonl(stats->cum_lost) >> 8;
 #endif
 
 #ifdef DEBUG_RTCP
@@ -6568,7 +6570,12 @@ static switch_status_t process_rtcp_report(switch_rtp_t *rtp_session, rtcp_msg_t
 
                                rtp_session->rtcp_frame.reports[i].ssrc = ntohl(report->ssrc);
                                rtp_session->rtcp_frame.reports[i].fraction = (uint8_t)report->fraction;
-                               rtp_session->rtcp_frame.reports[i].lost = ntohl(report->lost);
+#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
+                               rtp_session->rtcp_frame.reports[i].lost = report->lost; // signed 24bit will extended signess to int32_t automatically
+#else
+                               rtp_session->rtcp_frame.reports[i].lost = ntohl(report->lost)>>8; // signed 24bit casted to uint32_t need >>8 after ntohl()...
+                               rtp_session->rtcp_frame.reports[i].lost = rtp_session->rtcp_frame.reports[i].lost | ((rtp_session->rtcp_frame.reports[i].lost & 0x00800000) ? 0xff000000 : 0x00000000); // ...and signess compensation
+#endif
                                rtp_session->rtcp_frame.reports[i].highest_sequence_number_received = ntohl(report->highest_sequence_number_received);
                                rtp_session->rtcp_frame.reports[i].jitter = ntohl(report->jitter);
                                rtp_session->rtcp_frame.reports[i].lsr = ntohl(report->lsr);