Commit 6e9ac1d1 authored by Simon Morlat's avatar Simon Morlat

improve rtcp processing

parent 7b39874d
......@@ -62,7 +62,8 @@ OrtpEventType ortp_event_get_type(const OrtpEvent *ev);
#define ORTP_EVENT_STUN_PACKET_RECEIVED 1
#define ORTP_EVENT_PAYLOAD_TYPE_CHANGED 2
#define ORTP_EVENT_TELEPHONE_EVENT 3
#define ORTP_EVENT_RTCP_PACKET_RECEIVED 4
#define ORTP_EVENT_RTCP_PACKET_RECEIVED 4 /**<when a RTCP packet is received from far end */
#define ORTP_EVENT_RTCP_PACKET_EMITTED 5 /**<fired when oRTP decides to send an automatic RTCP SR or RR */
OrtpEventData * ortp_event_get_data(OrtpEvent *ev);
void ortp_event_destroy(OrtpEvent *ev);
OrtpEvent *ortp_event_dup(OrtpEvent *ev);
......
......@@ -67,7 +67,6 @@ typedef struct rtp_stats
uint64_t recv; /* bytes of payload received and delivered in time to the application */
uint64_t hw_recv; /* bytes of payload received */
uint64_t packet_recv; /* number of packets received */
uint64_t unavaillable; /* totally useless*/
uint64_t outoftime; /* number of packets that were received too late */
uint64_t cum_packet_loss; /* cumulative number of packet lost */
uint64_t bad; /* packets that did not appear to be RTP */
......@@ -77,8 +76,9 @@ typedef struct rtp_stats
typedef struct jitter_stats
{
uint32_t jitter; /* interarrival jitter at last emitted sender report */
uint32_t max_jitter; /* biggest interarrival jitter (value in stream clock unit) */
uint64_t sum_jitter; /* sum of all interarrival jitter (value in stream clock unit) */
uint64_t max_jitter; /* biggest interarrival jitter (value in stream clock unit) */
uint64_t max_jitter_ts; /* date (in ms since Epoch) of the biggest interarrival jitter */
} jitter_stats_t;
......
......@@ -181,12 +181,12 @@ struct _RtpSession
{
RtpSession *next; /* next RtpSession, when the session are enqueued by the scheduler */
int mask_pos; /* the position in the scheduler mask of RtpSession : do not move this field: it is part of the ABI since the session_set macros use it*/
struct {
RtpProfile *profile;
int pt;
unsigned int ssrc;
WaitPoint wp;
int telephone_events_pt; /* the payload type used for telephony events */
struct {
RtpProfile *profile;
int pt;
unsigned int ssrc;
WaitPoint wp;
int telephone_events_pt; /* the payload type used for telephony events */
} snd,rcv;
unsigned int inc_ssrc_candidate;
int inc_same_ssrc_count;
......
......@@ -228,17 +228,12 @@ static void sender_info_init(sender_info_t *info, RtpSession *session){
static void report_block_init(report_block_t *b, RtpSession *session){
int packet_loss=0;
uint8_t loss_fraction=0;
int loss_fraction=0;
RtpStream *stream=&session->rtp;
uint32_t delay_snc_last_sr=0;
uint32_t fl_cnpl;
/* compute the statistics */
/*printf("hwrcv_extseq.one=%u, hwrcv_seq_at_last_SR=%u hwrcv_since_last_SR=%u\n",
stream->hwrcv_extseq.one,
stream->hwrcv_seq_at_last_SR,
stream->hwrcv_since_last_SR
);*/
if (stream->hwrcv_since_last_SR!=0){
if ( session->flags & RTCP_OVERRIDE_LOST_PACKETS ) {
/* If the test mode is enabled, replace the lost packet field with the test vector value set by rtp_session_rtcp_set_lost_packet_value() */
......@@ -303,9 +298,9 @@ static void report_block_init(report_block_t *b, RtpSession *session){
static void extended_statistics( RtpSession *session, report_block_t * rb ) {
session->rtp.stats.sent_rtcp_packets ++;
/* the jitter raw value is kept in stream clock units */
uint32_t jitter = ntohl( rb->interarrival_jitter );
uint32_t jitter = session->rtp.jittctl.inter_jitter;
session->rtp.jitter_stats.sum_jitter += jitter;
session->rtp.jitter_stats.jitter=jitter;
/* stores the biggest jitter for that session and its date (in millisecond) since Epoch */
if ( jitter > session->rtp.jitter_stats.max_jitter ) {
session->rtp.jitter_stats.max_jitter = jitter ;
......@@ -381,6 +376,17 @@ static mblk_t * make_sr(RtpSession *session){
return cm;
}
static void notify_sent_rtcp(RtpSession *session, mblk_t *rtcp){
if (session->eventqs!=NULL){
OrtpEvent *ev;
OrtpEventData *evd;
ev=ortp_event_new(ORTP_EVENT_RTCP_PACKET_EMITTED);
evd=ortp_event_get_data(ev);
evd->packet=dupmsg(rtcp);
rtp_session_dispatch_event(session,ev);
}
}
void rtp_session_rtcp_process_send(RtpSession *session){
RtpStream *st=&session->rtp;
mblk_t *m;
......@@ -390,6 +396,7 @@ void rtp_session_rtcp_process_send(RtpSession *session){
st->last_rtcp_report_snt_s=st->snd_last_ts;
m=make_sr(session);
/* send the compound packet */
notify_sent_rtcp(session,m);
rtp_session_rtcp_send(session,m);
ortp_debug("Rtcp compound message sent.");
}
......@@ -412,6 +419,7 @@ void rtp_session_rtcp_process_recv(RtpSession *session){
}
if (m!=NULL){
/* send the compound packet */
notify_sent_rtcp(session,m);
rtp_session_rtcp_send(session,m);
ortp_debug("Rtcp compound message sent.");
}
......
......@@ -1088,8 +1088,6 @@ rtp_session_recvm_with_ts (RtpSession * session, uint32_t user_ts)
else
{
ortp_debug ("No mp for timestamp queried");
stream->stats.unavaillable++;
ortp_global_stats.unavaillable++;
}
rtp_session_rtcp_process_recv(session);
......
......@@ -1027,12 +1027,11 @@ void rtp_session_notify_inc_rtcp(RtpSession *session, mblk_t *m){
else freemsg(m); /* avoid memory leak */
}
static void compute_rtt(RtpSession *session, rtcp_sr_t *sr){
RtpStream * rtpstream = &session->rtp;
uint64_t curntp=ortp_timeval_to_ntp(&rtpstream->last_rcv_SR_time);
static void compute_rtt(RtpSession *session, const struct timeval *now, const report_block_t *rb){
uint64_t curntp=ortp_timeval_to_ntp(now);
uint32_t approx_ntp=(curntp>>16) & 0xFFFFFFFF;
uint32_t last_sr_time=report_block_get_last_SR_time(&sr->rb[0]);
uint32_t sr_delay=report_block_get_last_SR_delay(&sr->rb[0]);
uint32_t last_sr_time=report_block_get_last_SR_time(rb);
uint32_t sr_delay=report_block_get_last_SR_delay(rb);
/*ortp_message("rtt curntp=%u, last_sr_time=%u, sr_delay=%u",approx_ntp,last_sr_time,sr_delay);*/
if (last_sr_time!=0 && sr_delay!=0){
double rtt_frac=approx_ntp-last_sr_time-sr_delay;
......@@ -1061,24 +1060,13 @@ static void process_rtcp_packet( RtpSession *session, mblk_t *block ) {
rtcp = (rtcp_common_header_t *)block->b_rptr;
/* compound rtcp packet can be composed by more than one rtcp message */
while ( msgsize >= RTCP_COMMON_HEADER_SIZE ) {
if ( rtcp->version != 2 ) {
ortp_debug( "Receiving an illegal RTCP packet (version number <> 2)" );
return;
}
/* Convert header data from network order to host order */
rtcp->length = ntohs( rtcp->length );
do{
struct timeval reception_date;
/* compute length */
int rtcp_pk_size = ( rtcp->length + 1 ) * 4;
/* Sanity check of simple RTCP packet length. */
if ( rtcp_pk_size > msgsize ) {
ortp_debug( "Receiving a RTCP packet shorter than the specified length" );
return;
}
/* Getting the reception date from the main clock */
gettimeofday( &reception_date, NULL );
if ( rtcp->packet_type == RTCP_SR ) {
if (rtcp_is_SR(block) ) {
rtcp_sr_t *sr = (rtcp_sr_t *) rtcp;
/* The session descriptor values are reset in case there is an error in the SR block parsing */
......@@ -1097,19 +1085,18 @@ static void process_rtcp_packet( RtpSession *session, mblk_t *block ) {
return;
}
/* Getting the reception date from the main clock */
struct timeval reception_date;
gettimeofday( &reception_date, NULL );
/* Saving the data to fill LSR and DLSR field in next RTCP report to be transmitted */
/* This value will be the LSR field of the next RTCP report (only the central 32 bits are kept, as described in par.4 of RC3550) */
rtpstream->last_rcv_SR_ts = ( ntohl( sr->si.ntp_timestamp_msw ) << 16 ) | ( ntohl( sr->si.ntp_timestamp_lsw ) >> 16 );
/* This value will help in processing the DLSR of the next RTCP report ( see report_block_init() in rtcp.cc ) */
rtpstream->last_rcv_SR_time.tv_usec = reception_date.tv_usec;
rtpstream->last_rcv_SR_time.tv_sec = reception_date.tv_sec;
compute_rtt(session,sr);
compute_rtt(session,&reception_date,&sr->rb[0]);
}else if ( rtcp_is_RR(block)){
compute_rtt(session,&reception_date,rtcp_RR_get_report_block(block,0));
}
}
}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