Commit 21b8cec3 authored by Simon Morlat's avatar Simon Morlat

implement jitter buffer size measurement.

parent a73a8924
......@@ -80,6 +80,7 @@ typedef struct jitter_stats
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_ts; /* date (in ms since Epoch) of the biggest interarrival jitter */
float jitter_buffer_size_ms; /* mean jitter buffer size in milliseconds.*/
} jitter_stats_t;
#define RTP_TIMESTAMP_IS_NEWER_THAN(ts1,ts2) \
......
......@@ -62,7 +62,7 @@ typedef struct _JBParameters{
typedef struct _JitterControl
{
int count;
unsigned int count;
int jitt_comp; /* the user jitt_comp in miliseconds*/
int jitt_comp_ts; /* the jitt_comp converted in rtp time (same unit as timestamp) */
int adapt_jitt_comp_ts;
......@@ -73,6 +73,9 @@ typedef struct _JitterControl
float inter_jitter; /* interarrival jitter as defined in the RFC */
int corrective_step;
int corrective_slide;
uint64_t cum_jitter_buffer_size; /*in timestamp units*/
unsigned int cum_jitter_buffer_count; /*used for computation of jitter buffer size*/
int clock_rate;
bool_t adaptive;
bool_t enabled;
} JitterControl;
......
......@@ -43,7 +43,10 @@ void jitter_control_init(JitterControl *ctl, int base_jiitt_time, PayloadType *p
ctl->jitter=0;
ctl->inter_jitter=0;
ctl->slide=0;
ctl->cum_jitter_buffer_count=0;
ctl->cum_jitter_buffer_size=0;
if (base_jiitt_time!=-1) ctl->jitt_comp = base_jiitt_time;
ctl->clock_rate=8000;
/* convert in timestamp unit: */
if (payload!=NULL){
jitter_control_set_payload(ctl,payload);
......@@ -62,6 +65,7 @@ void jitter_control_set_payload(JitterControl *ctl, PayloadType *pt){
/*make correction by not less than 10ms */
ctl->corrective_step=(int) (0.01 * (float)pt->clock_rate);
ctl->adapt_jitt_comp_ts=ctl->jitt_comp_ts;
ctl->clock_rate=pt->clock_rate;
}
......@@ -85,6 +89,17 @@ void jitter_control_update_corrective_slide(JitterControl *ctl){
}
}
void jitter_control_update_size(JitterControl *ctl, queue_t *q){
mblk_t *newest=qlast(q);
mblk_t *oldest=qbegin(q);
uint32_t newest_ts,oldest_ts;
if (newest==NULL) return;
newest_ts=rtp_get_timestamp(newest);
oldest_ts=rtp_get_timestamp(oldest);
ctl->cum_jitter_buffer_count++;
ctl->cum_jitter_buffer_size+=(uint32_t)(newest_ts-oldest_ts);
}
/*
The algorithm computes two values:
slide: an average of difference between the expected and the socket-received timestamp
......@@ -125,7 +140,15 @@ void jitter_control_new_packet(JitterControl *ctl, uint32_t packet_ts, uint32_t
return ;
}
float jitter_control_compute_mean_size(JitterControl *ctl){
if (ctl->cum_jitter_buffer_count!=0){
double tmp=((double)ctl->cum_jitter_buffer_size)/(double)ctl->cum_jitter_buffer_count;
ctl->cum_jitter_buffer_size=0;
ctl->cum_jitter_buffer_count=0;
return 1000.0*(float)tmp/(float)ctl->clock_rate;
}
return 0;
}
......
......@@ -34,6 +34,8 @@ void jitter_control_new_packet(JitterControl *ctl, uint32_t packet_ts, uint32_t
#define jitter_control_adaptive_enabled(ctl) ((ctl)->adaptive)
void jitter_control_set_payload(JitterControl *ctl, PayloadType *pt);
void jitter_control_update_corrective_slide(JitterControl *ctl);
void jitter_control_update_size(JitterControl *ctl, queue_t *q);
float jitter_control_compute_mean_size(JitterControl *ctl);
static inline uint32_t jitter_control_get_compensated_timestamp(JitterControl *obj , uint32_t user_ts){
return (uint32_t)( (int64_t)user_ts+obj->slide-(int64_t)obj->adapt_jitt_comp_ts);
......
......@@ -32,6 +32,7 @@
#include "ortp/rtcp.h"
#include "utils.h"
#include "rtpsession_priv.h"
#include "jitterctl.h"
#define rtcp_bye_set_ssrc(b,pos,ssrc) (b)->ssrc[pos]=htonl(ssrc)
#define rtcp_bye_get_ssrc(b,pos) ntohl((b)->ssrc[pos])
......@@ -311,6 +312,8 @@ static void extended_statistics( RtpSession *session, report_block_t * rb ) {
gettimeofday( &now, NULL );
session->rtp.jitter_stats.max_jitter_ts = ( now.tv_sec * 1000LL ) + ( now.tv_usec / 1000LL );
}
/* compute mean jitter buffer size */
session->rtp.jitter_stats.jitter_buffer_size_ms=jitter_control_compute_mean_size(&session->rtp.jittctl);
}
......
......@@ -23,7 +23,7 @@
#include "utils.h"
#include "rtpsession_priv.h"
static void queue_packet(queue_t *q, int maxrqsz, mblk_t *mp, rtp_header_t *rtp, int *discarded)
static bool_t queue_packet(queue_t *q, int maxrqsz, mblk_t *mp, rtp_header_t *rtp, int *discarded)
{
mblk_t *tmp;
int header_size;
......@@ -33,7 +33,7 @@ static void queue_packet(queue_t *q, int maxrqsz, mblk_t *mp, rtp_header_t *rtp,
ortp_debug("Rtp packet contains no data.");
(*discarded)++;
freemsg(mp);
return;
return FALSE;
}
/* and then add the packet to the queue */
......@@ -50,6 +50,7 @@ static void queue_packet(queue_t *q, int maxrqsz, mblk_t *mp, rtp_header_t *rtp,
(*discarded)++;
}
}
return TRUE;
}
void rtp_session_rtp_parse(RtpSession *session, mblk_t *mp, uint32_t local_str_ts, struct sockaddr *addr, socklen_t addrlen)
......@@ -231,7 +232,8 @@ void rtp_session_rtp_parse(RtpSession *session, mblk_t *mp, uint32_t local_str_t
}
}
queue_packet(&session->rtp.rq,session->rtp.max_rq_size,mp,rtp,&i);
if (queue_packet(&session->rtp.rq,session->rtp.max_rq_size,mp,rtp,&i))
jitter_control_update_size(&session->rtp.jittctl,&session->rtp.rq);
stats->discarded+=i;
ortp_global_stats.discarded+=i;
}
......
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