[core] Add SEND_RTCP_MESSAGE

We utilize: https://github.com/sipcapture/hepipe.js to monitor RTCP for our calls. As such, it's super helpful to get the sent RTCP data along with the received RTCP data. The new: SEND_RTCP_MESSAGE basically mirrors the existing RECV_RTCP_MESSAGE.
This commit is contained in:
Noah Mehl 2020-06-18 09:53:49 -04:00 committed by Dragos Oancea
parent 0924fed31d
commit d24280c700
6 changed files with 98 additions and 3 deletions

View File

@ -132,6 +132,7 @@ static const char *EVENT_NAMES[] = {
"SEND_INFO",
"RECV_INFO",
"RECV_RTCP_MESSAGE",
"SEND_RTCP_MESSAGE",
"CALL_SECURE",
"NAT",
"RECORD_START",

View File

@ -120,6 +120,7 @@ typedef enum {
ESL_EVENT_SEND_INFO,
ESL_EVENT_RECV_INFO,
ESL_EVENT_RECV_RTCP_MESSAGE,
ESL_EVENT_SEND_RTCP_MESSAGE,
ESL_EVENT_CALL_SECURE,
ESL_EVENT_NAT,
ESL_EVENT_RECORD_START,

View File

@ -843,6 +843,7 @@ typedef enum {
SWITCH_RTP_FLAG_PASSTHRU,
SWITCH_RTP_FLAG_SECURE_SEND_MKI,
SWITCH_RTP_FLAG_SECURE_RECV_MKI,
SWITCH_RTP_FLAG_VIDEO_FIRE_SEND_RTCP_EVENT,
SWITCH_RTP_FLAG_INVALID
} switch_rtp_flag_t;
@ -2037,6 +2038,7 @@ typedef uint32_t switch_io_flag_t;
SWITCH_EVENT_SEND_INFO
SWITCH_EVENT_RECV_INFO
SWITCH_EVENT_RECV_RTCP_MESSAGE
SWITCH_EVENT_SEND_RTCP_MESSAGE
SWITCH_EVENT_CALL_SECURE
SWITCH_EVENT_NAT - NAT Management (new/del/status)
SWITCH_EVENT_RECORD_START
@ -2132,6 +2134,7 @@ typedef enum {
SWITCH_EVENT_SEND_INFO,
SWITCH_EVENT_RECV_INFO,
SWITCH_EVENT_RECV_RTCP_MESSAGE,
SWITCH_EVENT_SEND_RTCP_MESSAGE,
SWITCH_EVENT_CALL_SECURE,
SWITCH_EVENT_NAT,
SWITCH_EVENT_RECORD_START,

View File

@ -9510,6 +9510,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi
if (v_engine->tmmbr) {
flags[SWITCH_RTP_FLAG_TMMBR]++;
}
if (switch_channel_var_true(session->channel, "enable_send_rtcp_message_event_video")) {
flags[SWITCH_RTP_FLAG_VIDEO_FIRE_SEND_RTCP_EVENT] = 1;
}
v_engine->rtp_session = switch_rtp_new(a_engine->local_sdp_ip,
v_engine->local_sdp_port,

View File

@ -207,6 +207,7 @@ static char *EVENT_NAMES[] = {
"SEND_INFO",
"RECV_INFO",
"RECV_RTCP_MESSAGE",
"SEND_RTCP_MESSAGE",
"CALL_SECURE",
"NAT",
"RECORD_START",

View File

@ -26,6 +26,7 @@
* Anthony Minessale II <anthm@freeswitch.org>
* Marcel Barbulescu <marcelbarbulescu@gmail.com>
* Seven Du <dujinfang@gmail.com>
* Noah Mehl - Open Telecom Foundation <https://opentelecom.foundation>
*
* switch_rtp.c -- RTP
*
@ -1816,10 +1817,10 @@ static void rtcp_generate_sender_info(switch_rtp_t *rtp_session, struct switch_r
sr->oc = htonl(rtp_session->stats.outbound.raw_bytes - rtp_session->stats.outbound.packet_count * sizeof(srtp_hdr_t));
switch_time_exp_gmt(&now_hr,now);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG10,"Sending an RTCP packet[%04d-%02d-%02d %02d:%02d:%02d.%d] lsr[%u] msw[%u] lsw[%u] stats_ssrc[%u]\n",
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG10,"Sending an RTCP packet[%04d-%02d-%02d %02d:%02d:%02d.%d] lsr[%u] msw[%u] lsw[%u] stats_ssrc[%u] packet_count[%u] OC[%u]\n",
1900 + now_hr.tm_year, now_hr.tm_mday, now_hr.tm_mon, now_hr.tm_hour, now_hr.tm_min, now_hr.tm_sec, now_hr.tm_usec,
(ntohl(sr->ntp_lsw)&0xffff0000)>>16 | (ntohl(sr->ntp_msw)&0x0000ffff)<<16,
ntohl(sr->ntp_msw),ntohl(sr->ntp_lsw), rtp_session->stats.rtcp.ssrc
ntohl(sr->ntp_msw),ntohl(sr->ntp_lsw), rtp_session->stats.rtcp.ssrc, ntohl(sr->pc), ntohl(sr->oc)
);
}
@ -1895,7 +1896,13 @@ static void rtcp_generate_report_block(switch_rtp_t *rtp_session, struct switch_
}
rtcp_report_block->lsr = stats->last_recv_lsr_peer;
rtcp_report_block->dlsr = htonl(dlsr);
rtcp_report_block->ssrc = htonl(rtp_session->stats.rtcp.peer_ssrc);
if (rtp_session->stats.rtcp.peer_ssrc) {
rtcp_report_block->ssrc = htonl(rtp_session->stats.rtcp.peer_ssrc);
} else {
/* if remote is not sending rtcp reports, take ssrc as assigned from rtp */
rtcp_report_block->ssrc = htonl(rtp_session->remote_ssrc);
}
stats->rtcp_rtp_count++;
}
@ -2057,6 +2064,79 @@ static int using_ice(switch_rtp_t *rtp_session)
return 0;
}
static void switch_send_rtcp_event(switch_rtp_t *rtp_session ,struct switch_rtcp_sender_report *sr,struct switch_rtcp_report_block *rtcp_report_block)
{
if (sr && rtcp_report_block) {
switch_event_t *event;
if (switch_event_create(&event, SWITCH_EVENT_SEND_RTCP_MESSAGE) == SWITCH_STATUS_SUCCESS) {
char value[30];
char header[50];
uint32_t tmpLost;
char *uuid = switch_core_session_get_uuid(rtp_session->session);
if (uuid) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(rtp_session->session));
}
snprintf(value, sizeof(value), "%.8x", rtp_session->stats.rtcp.ssrc);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "SSRC", value);
snprintf(value, sizeof(value), "%u", ntohl(sr->sender_info.ntp_msw));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "NTP-Most-Significant-Word", value);
snprintf(value, sizeof(value), "%u", ntohl(sr->sender_info.ntp_lsw));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "NTP-Least-Significant-Word", value);
snprintf(value, sizeof(value), "%u", ntohl(sr->sender_info.ts));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "RTP-Timestamp", value);
snprintf(value, sizeof(value), "%u", ntohl(sr->sender_info.pc));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Sender-Packet-Count", value);
snprintf(value, sizeof(value), "%u", ntohl(sr->sender_info.oc));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Octect-Packet-Count", value);
snprintf(value, sizeof(value), "%u", ntohl(sr->sender_info.ts));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Last-RTP-Timestamp", 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 */
snprintf(header, sizeof(header), "Source-SSRC");
snprintf(value, sizeof(value), "%.8x", rtp_session->stats.rtcp.peer_ssrc);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
snprintf(header, sizeof(header), "Source-Fraction");
snprintf(value, sizeof(value), "%u", (uint8_t)rtcp_report_block->fraction);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
snprintf(header, sizeof(header), "Source-Lost");
#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
tmpLost = report->lost; /* signed 24bit will extended signess to int32_t automatically */
#else
tmpLost = ntohl(rtcp_report_block->lost)>>8;
tmpLost = tmpLost | ((tmpLost & 0x00800000) ? 0xff000000 : 0x00000000); /* ...and signess compensation */
#endif
snprintf(value, sizeof(value), "%u", tmpLost);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
snprintf(header, sizeof(header), "Source-Highest-Sequence-Number-Received");
snprintf(value, sizeof(value), "%u", ntohl(rtcp_report_block->highest_sequence_number_received));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
snprintf(header, sizeof(header), "Source-Jitter");
snprintf(value, sizeof(value), "%u", ntohl(rtcp_report_block->jitter));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
snprintf(header, sizeof(header), "Source-LSR");
snprintf(value, sizeof(value), "%u", ntohl(rtcp_report_block->lsr));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
snprintf(header, sizeof(header), "Source-DLSR");
snprintf(value, sizeof(value), "%u", ntohl(rtcp_report_block->dlsr));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header, value);
switch_event_fire(&event);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG10, "Dispatched RTCP SEND event\n");
}
}
}
#define MAX_NACK 10
static int check_rtcp_and_ice(switch_rtp_t *rtp_session)
{
@ -2206,6 +2286,11 @@ static int check_rtcp_and_ice(switch_rtp_t *rtp_session)
rtcp_generate_report_block(rtp_session, rtcp_report_block, nack_dup);
rtp_session->rtcp_send_msg.header.count = 1; /* reception report block count */
stats->sent_pkt_count = 0;
/* send event for audio, or video if flag set */
if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO_FIRE_SEND_RTCP_EVENT] ||
!(rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] || rtp_session->flags[SWITCH_RTP_FLAG_TEXT])) {
switch_send_rtcp_event(rtp_session, sr, rtcp_report_block);
}
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG1, "Sending RTCP SR (ssrc=%u)\n", rtp_session->ssrc);
}