Commit 3c6e9bf1 authored by Simon Morlat's avatar Simon Morlat

call quality indicator improvements

parent cdf6517b
......@@ -167,9 +167,11 @@ MS2_PUBLIC void audio_stream_set_default_card(int cardindex);
/* retrieve RTP statistics*/
MS2_PUBLIC void audio_stream_get_local_rtp_stats(AudioStream *stream, rtp_stats_t *stats);
/* returns an indicator of the stream quality between 0 and 5 */
/* returns a realtime indicator of the stream quality between 0 and 5 */
MS2_PUBLIC float audio_stream_get_quality_rating(AudioStream *stream);
/* returns the quality rating as an average since the start of the streaming session.*/
MS2_PUBLIC float audio_stream_get_average_quality_rating(AudioStream *stream);
/*****************
Video Support
......
......@@ -33,6 +33,8 @@ MSQualityIndicator *ms_quality_indicator_new(RtpSession *session);
float ms_quality_indicator_get_rating(MSQualityIndicator *qi);
float ms_quality_indicator_get_average_rating(MSQualityIndicator *qi);
void ms_quality_indicator_update_from_feedback(MSQualityIndicator *qi, mblk_t *rtcp);
void ms_quality_indicator_update_local(MSQualityIndicator *qi);
......
......@@ -173,9 +173,13 @@ void audio_stream_iterate(AudioStream *stream){
if (stream->evq){
OrtpEvent *ev=ortp_ev_queue_get(stream->evq);
if (ev!=NULL){
if (ortp_event_get_type(ev)==ORTP_EVENT_RTCP_PACKET_RECEIVED){
OrtpEventType evt=ortp_event_get_type(ev);
if (evt==ORTP_EVENT_RTCP_PACKET_RECEIVED){
audio_stream_process_rtcp(stream,ortp_event_get_data(ev)->packet);
stream->last_packet_time=ms_time(NULL);
}else if (evt==ORTP_EVENT_RTCP_PACKET_EMITTED){
/*we choose to update the quality indicator when the oRTP stack decides to emit a RTCP report */
ms_quality_indicator_update_local(stream->qi);
}
ortp_event_destroy(ev);
}
......@@ -745,8 +749,14 @@ void audio_stream_mute_rtp(AudioStream *stream, bool_t val)
float audio_stream_get_quality_rating(AudioStream *stream){
if (stream->qi){
ms_quality_indicator_update_local(stream->qi);
return ms_quality_indicator_get_rating(stream->qi);
}
return 0;
}
MS2_PUBLIC float audio_stream_get_average_quality_rating(AudioStream *stream){
if (stream->qi){
return ms_quality_indicator_get_average_rating(stream->qi);
}
return 0;
}
......@@ -20,6 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/qualityindicator.h"
#include <math.h>
#define RATING_SCALE 5.0
#define WORSE_JITTER 0.2
#define WORSE_RT_PROP 5.0
......@@ -29,12 +31,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
struct _MSQualityIndicator{
RtpSession *session;
int clockrate;
double sum_ratings;
float rating;
float local_rating;
float remote_rating;
uint64_t last_packet_count;
uint32_t last_lost;
uint32_t last_late;
int count;
};
MSQualityIndicator *ms_quality_indicator_new(RtpSession *session){
......@@ -62,12 +66,25 @@ static float rt_prop_rating(float rt_prop){
return 1.0-(0.7*tmp);
}
static float loss_rating(float loss){
/* the exp function allows to have a rating that decrease rapidly at the begining.
Indeed even with 10% loss, the quality is significantly affected. It is not good at all.
With this formula:
5% losses gives a rating of 4/5
20% losses gives a rating of 2.2/5
80% losses gives a rating of 0.2
*/
return expf(-loss*4.0);
}
static float compute_rating(float loss_rate, float inter_jitter, float late_rate, float rt_prop){
return (1.0-loss_rate)*inter_jitter_rating(inter_jitter)*(1.0-late_rate)*rt_prop_rating(rt_prop);
return loss_rating(loss_rate)*inter_jitter_rating(inter_jitter)*loss_rating(late_rate)*rt_prop_rating(rt_prop);
}
static void update_global_rating(MSQualityIndicator *qi){
qi->rating=RATING_SCALE*qi->remote_rating*qi->local_rating;
qi->sum_ratings+=qi->rating;
qi->count++;
}
void ms_quality_indicator_update_from_feedback(MSQualityIndicator *qi, mblk_t *rtcp){
......@@ -124,7 +141,12 @@ void ms_quality_indicator_update_local(MSQualityIndicator *qi){
update_global_rating(qi);
}
float ms_quality_indicator_get_average_rating(MSQualityIndicator *qi){
return (float)(qi->sum_ratings/(double)qi->count);
}
void ms_quality_indicator_destroy(MSQualityIndicator *qi){
ms_free(qi);
}
......@@ -483,6 +483,7 @@ static void run_media_streams(int localport, const char *remote_ip, int remotepo
}
printf("stopping all...\n");
printf("Average quality indicator: %f",audio ? audio_stream_get_average_quality_rating(audio) : -1);
if (audio) audio_stream_stop(audio);
#ifdef VIDEO_ENABLED
......
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