1 /*
2 mediastreamer2 library - modular sound and video processing and streaming
3 
4  * Copyright (C) 2011  Belledonne Communications, Grenoble, France
5 
6 	 Author: Simon Morlat <simon.morlat@linphone.org>
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21  */
22 
23 
24 #ifndef msqosanalyzer_hh
25 #define msqosanalyzer_hh
26 
27 #include "mediastreamer2/bitratecontrol.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 
34 	/**************************************************************************/
35 	/*************************** Simple QoS analyzer **************************/
36 	/**************************************************************************/
37 	#define STATS_HISTORY 3
38 	#define ESTIM_HISTORY 30
39 	static const float unacceptable_loss_rate=10;
40 	static const int big_jitter=10; /*ms */
41 	static const float significant_delay=0.2f; /*seconds*/
42 
43 	typedef struct rtpstats{
44 		float lost_percentage; /*percentage of lost packet since last report*/
45 		float int_jitter; /*interrarrival jitter */
46 		float rt_prop; /*round trip propagation*/
47 	}rtpstats_t;
48 
49 	typedef struct _MSSimpleQosAnalyzer{
50 		MSQosAnalyzer parent;
51 		RtpSession *session;
52 		int clockrate;
53 		rtpstats_t stats[STATS_HISTORY];
54 		int curindex;
55 		bool_t rt_prop_doubled;
56 		bool_t pad[3];
57 	}MSSimpleQosAnalyzer;
58 
59 
60 	/**************************************************************************/
61 	/************************* Stateful QoS analyzer **************************/
62 	/**************************************************************************/
63 	#define BW_HISTORY 10
64 
65 	typedef struct {
66 		time_t timestamp;
67 		double bandwidth;
68 		double loss_percent;
69 		double rtt;
70 	} rtcpstatspoint_t;
71 
72 	typedef struct {
73 		uint32_t seq_number;
74 		float up_bandwidth;
75 	} bandwidthseqnum;
76 
77 
78 	typedef enum _MSStatefulQosAnalyzerBurstState{
79 		MSStatefulQosAnalyzerBurstDisable,
80 		MSStatefulQosAnalyzerBurstInProgress,
81 		MSStatefulQosAnalyzerBurstEnable,
82 	}MSStatefulQosAnalyzerBurstState;
83 
84 	typedef struct _MSStatefulQosAnalyzer{
85 		MSQosAnalyzer parent;
86 		RtpSession *session;
87 		int curindex;
88 
89 		MSList *rtcpstatspoint;
90 		rtcpstatspoint_t *latest;
91 		double network_loss_rate;
92 		double congestion_bandwidth;
93 
94 		MSStatefulQosAnalyzerBurstState burst_state;
95 		struct timeval start_time;
96 
97 		uint32_t upload_bandwidth_count; /*deprecated*/
98 		double upload_bandwidth_sum; /*deprecated*/
99 		double upload_bandwidth_latest;
100 		int upload_bandwidth_cur;
101 		bandwidthseqnum upload_bandwidth[BW_HISTORY];
102 
103 		double burst_ratio;
104 		double burst_duration_ms;
105 	}MSStatefulQosAnalyzer;
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif
111