Hi all,
Please find attached a patch that parses and add RTCP source reports and added
the info to the corresponding the switch event.
It adds the following headers, numbered by source :
Event arrived : RECV_RTCP_MESSAGE
Event Header : Event-Name -> RECV_RTCP_MESSAGE
Event Header : Core-UUID -> 649cbe4e-7bb8-4edd-a0f5-2662246966f8
Event Header : FreeSWITCH-Hostname -> sal
Event Header : FreeSWITCH-IPv4 -> 192.168.0.89
Event Header : FreeSWITCH-IPv6 -> ::1
Event Header : Event-Date-Local -> 2010-06-29 12:11:00
Event Header : Event-Date-GMT -> Tue, 29 Jun 2010 10:11:00 GMT
Event Header : Event-Date-Timestamp -> 1277806260737911
Event Header : Event-Calling-File -> mod_sofia.c
Event Header : Event-Calling-Function -> sofia_read_frame
Event Header : Event-Calling-Line-Number -> 907
Event Header : Unique-ID -> 4fa7d00b-64f2-47ff-b2db-266943ee5fe2
Event Header : SSRC -> 402076d6
Event Header : NTP-Most-Significant-Word -> 3486795060
Event Header : NTP-Least-Significant-Word -> 3111085330
Event Header : RTP-Timestamp -> 40160
Event Header : Sender-Packet-Count -> 246
Event Header : Octect-Packet-Count -> 39360
Event Header : Last-RTP-Timestamp -> 39840
Event Header : RTP-Rate -> 8000
Event Header : Capture-Time -> 1277806260738059
--> HERE
Event Header : Source0-SSRC -> 18320497
Event Header : Source0-Fraction -> 0
Event Header : Source0-Lost -> 0
Event Header : Source0-Highest-Sequence-Number-Received -> 40032
Event Header : Source0-Jitter -> 5
Event Header : Source0-LSR -> 0
Event Header : Source0-DLSR -> 0
Guillaume BINET.
Guillaume Binet
Mobile: +32 487 57 35 81
Fax: +32 2 223 01 15
Ch. de la Hulpe 181 Terhulpsesteenweg
Bruxelles B-1170 Brussel
www.mondialtelecom.be
To discover the innovation of Mondial Telecom,
becherry.be
From 64ad0c160f02be7b2087b38973a7d5255f024ec6 Mon Sep 17 00:00:00 2001
From: Guillaume BINET <[email protected]>
Date: Tue, 29 Jun 2010 11:25:47 +0200
Subject: [PATCH] RTCP source parsing
---
src/include/switch_rtcp_frame.h | 25 ++++++++++
src/mod/endpoints/mod_sofia/mod_sofia.c | 81 ++++++++++++++++++++----------
src/switch_rtp.c | 31 ++++++++++++
3 files changed, 110 insertions(+), 27 deletions(-)
diff --git a/src/include/switch_rtcp_frame.h b/src/include/switch_rtcp_frame.h
index 1c718a0..cff39bf 100644
--- a/src/include/switch_rtcp_frame.h
+++ b/src/include/switch_rtcp_frame.h
@@ -38,7 +38,28 @@
#include <switch.h>
+#define MAX_REPORT_BLOCKS 5
+
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
+
+ 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
+
+ uint32_t dlsr; // The delay, expressed in units of 1/65536 seconds, between receiving the last SR packet from source SSRC_n and sending this reception report block
+
+};
+
/*! \brief An abstraction of a rtcp frame */
struct switch_rtcp_frame {
@@ -58,6 +79,10 @@ SWITCH_BEGIN_EXTERN_C
uint32_t octect_count;
+ uint32_t nb_reports;
+
+ struct switch_rtcp_report_block_frame reports[MAX_REPORT_BLOCKS];
+
};
SWITCH_END_EXTERN_C
diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c
index a49a198..48d7a6b 100644
--- a/src/mod/endpoints/mod_sofia/mod_sofia.c
+++ b/src/mod/endpoints/mod_sofia/mod_sofia.c
@@ -905,39 +905,66 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
switch_event_t *event;
if (switch_event_create(&event, SWITCH_EVENT_RECV_RTCP_MESSAGE) == SWITCH_STATUS_SUCCESS) {
- char buf[30];
+ char value[30];
+ char header[50];
+ int i;
char *uuid = switch_core_session_get_uuid(session);
if (uuid) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(session));
}
- snprintf(buf, sizeof(buf), "%.8x", rtcp_frame.ssrc);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "SSRC", buf);
-
- snprintf(buf, sizeof(buf), "%u", rtcp_frame.ntp_msw);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "NTP-Most-Significant-Word", buf);
-
- snprintf(buf, sizeof(buf), "%u", rtcp_frame.ntp_lsw);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "NTP-Least-Significant-Word", buf);
-
- snprintf(buf, sizeof(buf), "%u", rtcp_frame.timestamp);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "RTP-Timestamp", buf);
-
- snprintf(buf, sizeof(buf), "%u", rtcp_frame.packet_count);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Sender-Packet-Count", buf);
-
- snprintf(buf, sizeof(buf), "%u", rtcp_frame.octect_count);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Octect-Packet-Count", buf);
-
- snprintf(buf, sizeof(buf), "%" SWITCH_SIZE_T_FMT, tech_pvt->read_frame.timestamp);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Last-RTP-Timestamp", buf);
-
- snprintf(buf, sizeof(buf), "%u", tech_pvt->read_frame.rate);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "RTP-Rate", buf);
-
- snprintf(buf, sizeof(buf), "%" SWITCH_TIME_T_FMT, switch_time_now());
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Capture-Time", buf);
+ snprintf(value, sizeof(value), "%.8x", rtcp_frame.ssrc);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "SSRC", value);
+
+ snprintf(value, sizeof(value), "%u", rtcp_frame.ntp_msw);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "NTP-Most-Significant-Word", value);
+
+ snprintf(value, sizeof(value), "%u", rtcp_frame.ntp_lsw);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "NTP-Least-Significant-Word", value);
+
+ snprintf(value, sizeof(value), "%u", rtcp_frame.timestamp);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "RTP-Timestamp", value);
+
+ snprintf(value, sizeof(value), "%u", rtcp_frame.packet_count);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Sender-Packet-Count", value);
+
+ snprintf(value, sizeof(value), "%u", rtcp_frame.octect_count);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Octect-Packet-Count", value);
+
+ snprintf(value, sizeof(value), "%" SWITCH_SIZE_T_FMT, tech_pvt->read_frame.timestamp);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Last-RTP-Timestamp", value);
+
+ snprintf(value, sizeof(value), "%u", tech_pvt->read_frame.rate);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "RTP-Rate", value);
+
+ snprintf(value, sizeof(value), "%" SWITCH_TIME_T_FMT, switch_time_now());
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Capture-Time", value);
+
+ // Add sources info
+ for (i = 0; i < rtcp_frame.report_count; i++) {
+ snprintf(header, sizeof(header), "Source%u-SSRC", i);
+ snprintf(value, sizeof(value), "%.8x", rtcp_frame.reports[i].ssrc);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
+ snprintf(header, sizeof(header), "Source%u-Fraction", i);
+ snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].fraction);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
+ snprintf(header, sizeof(header), "Source%u-Lost", i);
+ snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].lost);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
+ snprintf(header, sizeof(header), "Source%u-Highest-Sequence-Number-Received", i);
+ snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].highest_sequence_number_received);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
+ snprintf(header, sizeof(header), "Source%u-Jitter", i);
+ snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].jitter);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
+ snprintf(header, sizeof(header), "Source%u-LSR", i);
+ snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].lsr);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
+ snprintf(header, sizeof(header), "Source%u-DLSR", i);
+ snprintf(value, sizeof(value), "%u", rtcp_frame.reports[i].dlsr);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
+ }
switch_event_fire(&event);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG10, "Dispatched RTCP event\n");
diff --git a/src/switch_rtp.c b/src/switch_rtp.c
index 0d4420e..1fcc77c 100644
--- a/src/switch_rtp.c
+++ b/src/switch_rtp.c
@@ -34,6 +34,7 @@
//#define RTP_DEBUG_WRITE_DELTA
#include <switch.h>
#include <switch_stun.h>
+#include <apr_network_io.h>
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
@@ -250,6 +251,16 @@ struct switch_rtcp_senderinfo {
unsigned oc:32;
};
+struct switch_rtcp_report_block {
+ uint32_t ssrc; // The SSRC identifier of the source to which the information in this reception report block pertains.
+ unsigned int fraction :8; // The fraction of RTP data packets from source SSRC_n lost since the previous SR or RR packet was sent
+ int lost :24; // The total number of RTP data packets from source SSRC_n that have been lost since the beginning of reception
+ 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
+ uint32_t dlsr; // The delay, expressed in units of 1/65536 seconds, between receiving the last SR packet from source SSRC_n and sending this reception report block
+};
+
static int global_init = 0;
static int rtp_common_write(switch_rtp_t *rtp_session,
rtp_msg_t *send_msg, void *data, uint32_t datalen, switch_payload_t payload, uint32_t timestamp, switch_frame_flag_t *flags);
@@ -2979,6 +2990,10 @@ SWITCH_DECLARE(switch_status_t) switch_rtcp_zerocopy_read_frame(switch_rtp_t *rt
/* A fresh frame has been found! */
if (rtp_session->rtcp_fresh_frame) {
struct switch_rtcp_senderinfo* sr = (struct switch_rtcp_senderinfo*)rtp_session->rtcp_recv_msg.body;
+ unsigned packet_length = (ntohs((uint16_t) rtp_session->rtcp_recv_msg.header.length) + 1) * 4 - sizeof(switch_rtcp_hdr_t); // we remove the header lenght because with directly have a pointer on the body
+ unsigned int reportsOffset = sizeof(struct switch_rtcp_senderinfo);
+ int i = 0;
+
/* turn the flag off! */
rtp_session->rtcp_fresh_frame = 0;
@@ -2990,6 +3005,22 @@ SWITCH_DECLARE(switch_status_t) switch_rtcp_zerocopy_read_frame(switch_rtp_t *rt
frame->packet_count = ntohl(sr->pc);
frame->octect_count = ntohl(sr->oc);
+ for (int offset = reportsOffset; offset < packet_length; offset += sizeof(struct switch_rtcp_report_block)) {
+ struct switch_rtcp_report_block* report = (struct switch_rtcp_report_block*) (rtp_session->rtcp_recv_msg.body + offset);
+ frame->reports[i].ssrc = ntohl(report->ssrc);
+ frame->reports[i].fraction = ntohl(report->fraction);
+ frame->reports[i].lost = ntohl(report->lost);
+ frame->reports[i].highest_sequence_number_received = ntohl(report->highest_sequence_number_received);
+ frame->reports[i].jitter = ntohl(report->jitter);
+ frame->reports[i].lsr = ntohl(report->lsr);
+ frame->reports[i].dlsr = ntohl(report->dlsr);
+ i++;
+ if (i >= MAX_REPORT_BLOCKS) {
+ break;
+ }
+ }
+ frame->report_count = i;
+
return SWITCH_STATUS_SUCCESS;
}
--
1.7.1
_______________________________________________
FreeSWITCH-dev mailing list
[email protected]
http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev
http://www.freeswitch.org