Commit fb7f4f8b authored by Ghislain MARY's avatar Ghislain MARY

Fill the RTCP XR dlrr packets correctly.

parent c0418933
......@@ -137,6 +137,11 @@ typedef struct OrtpRtcpXrConfiguration {
OrtpRtcpXrStatSummaryFlag stat_summary_flags;
} OrtpRtcpXrConfiguration;
typedef struct OrtpRtcpXrStats {
uint32_t last_rcvr_rtt_ts; /* NTP timestamp (middle 32 bits) of last received XR rcvr-rtt */
struct timeval last_rcvr_rtt_time; /* Time at which last XR rcvr-rtt was received */
} OrtpRtcpXrStats;
typedef struct _RtpStream
{
ortp_socket_t socket;
......@@ -255,6 +260,7 @@ struct _RtpSession
msgb_allocator_t allocator;
RtpStream rtp;
RtcpStream rtcp;
OrtpRtcpXrStats rtcp_xr_stats;
RtpSessionMode mode;
struct _RtpScheduler *sched;
uint32_t flags;
......
......@@ -543,12 +543,23 @@ static int rtcp_xr_rcvr_rtt_init(uint8_t *buf, RtpSession *session) {
}
static int rtcp_xr_dlrr_init(uint8_t *buf, RtpSession *session) {
uint32_t dlrr = 0;
rtcp_xr_dlrr_report_block_t *block = (rtcp_xr_dlrr_report_block_t *)buf;
block->bh.bt = RTCP_XR_DLRR;
block->bh.flags = 0; // Reserved bits
block->bh.length = htons(3);
// TODO: Fill the rest of the block and handle multiple subblocks
block->content[0].ssrc = htonl(rtp_session_get_recv_ssrc(session));
block->content[0].lrr = htonl(session->rtcp_xr_stats.last_rcvr_rtt_ts);
if (session->rtcp_xr_stats.last_rcvr_rtt_time.tv_sec != 0) {
struct timeval now;
double delay;
ortp_gettimeofday(&now, NULL);
delay = ((now.tv_sec - session->rtcp_xr_stats.last_rcvr_rtt_time.tv_sec)
+ ((now.tv_usec - session->rtcp_xr_stats.last_rcvr_rtt_time.tv_usec) * 1e-6)) * 65536;
dlrr = (uint32_t) delay;
}
block->content[0].dlrr = htonl(dlrr);
return sizeof(rtcp_xr_dlrr_report_block_t);
}
......
......@@ -1338,6 +1338,22 @@ static void compute_rtt(RtpSession *session, const struct timeval *now, const re
}
}
static void compute_rtcp_xr_statistics(RtpSession *session, mblk_t *block, struct timeval reception_date) {
uint64_t ntp_timestamp;
OrtpRtcpXrStats *stats = &session->rtcp_xr_stats;
switch (rtcp_XR_get_block_type(block)) {
case RTCP_XR_RCVR_RTT:
ntp_timestamp = rtcp_XR_rcvr_rtt_get_ntp_timestamp(block);
stats->last_rcvr_rtt_ts = (ntp_timestamp >> 16) & 0xffffffff;
stats->last_rcvr_rtt_time.tv_sec = reception_date.tv_sec;
stats->last_rcvr_rtt_time.tv_usec = reception_date.tv_usec;
break;
default:
break;
}
}
/*
* @brief : for SR packets, retrieves their timestamp, gets the date, and stores these information into the session descriptor. The date values may be used for setting some fields of the report block of the next RTCP packet to be sent.
* @param session : the current session descriptor.
......@@ -1416,6 +1432,8 @@ static int process_rtcp_packet( RtpSession *session, mblk_t *block, struct socka
}else if ( rtcp_is_RR(block)){
rb=rtcp_RR_get_report_block(block,0);
if (rb) compute_rtt(session,&reception_date,rb);
} else if (rtcp_is_XR(block)) {
compute_rtcp_xr_statistics(session, block, reception_date);
}
}while (rtcp_next_packet(block));
rtcp_rewind(block);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment