quality_reporting.c 36.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
linphone
Copyright (C) 2014 - Belledonne Communications, Grenoble, France

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 19 20
*/

#ifdef HAVE_CONFIG_H
21
#include "config.h"
22 23
#endif

24
#include "linphone/core.h"
25
#include "private.h"
26
#include "c-wrapper/internal/c-sal.h"
27
#include "sal/sal.h"
28 29
#include "ortp/rtpsession.h"

30 31
#include <math.h>

32 33 34 35
#if TARGET_OS_IPHONE
#include <sys/sysctl.h>
#endif

36 37
#include <memory>

38 39
// For migration purpose.
#include "address/address-p.h"
40
#include "c-wrapper/c-wrapper.h"
41 42
#include "call/call-p.h"
#include "conference/session/media-session-p.h"
43

44
#define STR_REASSIGN(dest, src) {\
45 46 47 48
	if (dest != NULL) \
		ms_free(dest); \
	dest = src; \
}
49

50 51
/*since printf family functions are LOCALE dependent, float separator may differ
depending on the user's locale (LC_NUMERIC environment var).*/
52
static char * float_to_one_decimal_string(float f) {
53 54 55
	float rounded_f = floorf(f * 10 + .5f) / 10;

	int floor_part = (int) rounded_f;
56
	int one_decimal_part = (int)floorf(10 * (rounded_f - (float)floor_part) + .5f);
57

58
	return ms_strdup_printf("%d.%d", floor_part, one_decimal_part);
59 60
}

61 62 63 64
static void append_to_buffer_valist(char **buff, size_t *buff_size, size_t *offset, const char *fmt, va_list args) {
	belle_sip_error_code ret;
	size_t prevoffset = *offset;

65
	#ifndef _WIN32
66 67
		va_list cap;/*copy of our argument list: a va_list cannot be re-used (SIGSEGV on linux 64 bits)*/
		va_copy(cap,args);
68
		ret = belle_sip_snprintf_valist(*buff, *buff_size, offset, fmt, cap);
69
		va_end(cap);
70
	#else
71
		ret = belle_sip_snprintf_valist(*buff, *buff_size, offset, fmt, args);
72
	#endif
73

74
	/*if we are out of memory, we add some size to buffer*/
75
	if (ret == BELLE_SIP_BUFFER_OVERFLOW) {
76
		/*some compilers complain that size_t cannot be formatted as unsigned long, hence forcing cast*/
77
		ms_debug("QualityReporting: Buffer was too small to contain the whole report - increasing its size from %lu to %lu",
78
			(unsigned long)*buff_size, (unsigned long)*buff_size + 2048);
79 80 81 82
		*buff_size += 2048;
		*buff = (char *) ms_realloc(*buff, *buff_size);

		*offset = prevoffset;
83
		/*recall itself since we did not write all things into the buffer but
84
		only a part of it*/
85 86 87 88 89 90 91 92 93 94 95
		append_to_buffer_valist(buff, buff_size, offset, fmt, args);
	}
}

static void append_to_buffer(char **buff, size_t *buff_size, size_t *offset, const char *fmt, ...) {
	va_list args;
	va_start(args, fmt);
	append_to_buffer_valist(buff, buff_size, offset, fmt, args);
	va_end(args);
}

96
static void reset_avg_metrics(reporting_session_report_t * report){
97
	int i;
98
	reporting_content_metrics_t * metrics[2] = {&report->local_metrics, &report->remote_metrics};
99 100

	for (i = 0; i < 2; i++) {
101
		metrics[i]->rtcp_sr_count = 0;
102 103 104 105
		metrics[i]->rtcp_xr_count = 0;
		metrics[i]->jitter_buffer.nominal = 0;
		metrics[i]->jitter_buffer.max = 0;

106 107 108
		metrics[i]->quality_estimates.moslq = 0;
		metrics[i]->quality_estimates.moscq = 0;

109 110
		metrics[i]->delay.round_trip_delay = 0;
	}
111
	report->last_report_date = ms_time(NULL);
112
}
113

114 115 116 117
#define APPEND_IF_NOT_NULL_STR(buffer, size, offset, fmt, arg) if (arg != NULL) append_to_buffer(buffer, size, offset, fmt, arg)
#define APPEND_IF_NUM_IN_RANGE(buffer, size, offset, fmt, arg, inf, sup) if (inf <= arg && arg <= sup) append_to_buffer(buffer, size, offset, fmt, arg)
#define APPEND_IF(buffer, size, offset, fmt, arg, cond) if (cond) append_to_buffer(buffer, size, offset, fmt, arg)
#define IF_NUM_IN_RANGE(num, inf, sup, statement) if (inf <= num && num <= sup) statement
118

119 120 121 122 123 124
#define METRICS_PACKET_LOSS 1 << 0
#define METRICS_QUALITY_ESTIMATES 1 << 1
#define METRICS_SESSION_DESCRIPTION 1 << 2
#define METRICS_JITTER_BUFFER 1 << 3
#define METRICS_DELAY 1 << 4
#define METRICS_SIGNAL 1 << 5
125

126
static uint8_t are_metrics_filled(const reporting_content_metrics_t *rm) {
127 128
	uint8_t ret = 0;

129 130
	IF_NUM_IN_RANGE(rm->packet_loss.network_packet_loss_rate, 0, 255, ret|=METRICS_PACKET_LOSS);
	IF_NUM_IN_RANGE(rm->packet_loss.jitter_buffer_discard_rate, 0, 255, ret|=METRICS_PACKET_LOSS);
131

132 133 134 135
	if (rm->session_description.payload_type != -1) ret|=METRICS_SESSION_DESCRIPTION;
	if (rm->session_description.payload_desc != NULL) ret|=METRICS_SESSION_DESCRIPTION;
	if (rm->session_description.sample_rate != -1) ret|=METRICS_SESSION_DESCRIPTION;
	if (rm->session_description.fmtp != NULL) ret|=METRICS_SESSION_DESCRIPTION;
136

137 138
	IF_NUM_IN_RANGE(rm->jitter_buffer.adaptive, 0, 3, ret|=METRICS_JITTER_BUFFER);
	IF_NUM_IN_RANGE(rm->jitter_buffer.abs_max, 0, 65535, ret|=METRICS_JITTER_BUFFER);
139

140 141 142
	IF_NUM_IN_RANGE(rm->delay.end_system_delay, 0, 65535, ret|=METRICS_DELAY);
	IF_NUM_IN_RANGE(rm->delay.interarrival_jitter, 0, 65535, ret|=METRICS_DELAY);
	IF_NUM_IN_RANGE(rm->delay.mean_abs_jitter, 0, 65535, ret|=METRICS_DELAY);
143

144 145
	if (rm->signal.level != 127) ret|=METRICS_SIGNAL;
	if (rm->signal.noise_level != 127) ret|=METRICS_SIGNAL;
146

147 148
	IF_NUM_IN_RANGE(rm->quality_estimates.moslq, 1, 5, ret|=METRICS_QUALITY_ESTIMATES);
	IF_NUM_IN_RANGE(rm->quality_estimates.moscq, 1, 5, ret|=METRICS_QUALITY_ESTIMATES);
149

150 151 152
	if (rm->rtcp_xr_count>0){
		IF_NUM_IN_RANGE(rm->jitter_buffer.nominal/rm->rtcp_xr_count, 0, 65535, ret|=METRICS_JITTER_BUFFER);
		IF_NUM_IN_RANGE(rm->jitter_buffer.max/rm->rtcp_xr_count, 0, 65535, ret|=METRICS_JITTER_BUFFER);
153
	}
154 155
	if (rm->rtcp_sr_count+rm->rtcp_xr_count>0){
		IF_NUM_IN_RANGE(rm->delay.round_trip_delay/(rm->rtcp_sr_count+rm->rtcp_xr_count), 0, 65535, ret|=METRICS_DELAY);
156
	}
157 158

	return ret;
159
}
160

Ronan's avatar
Ronan committed
161
static bool_t quality_reporting_enabled(const LinphoneCall * call) {
162 163
	return (L_GET_PRIVATE_FROM_C_OBJECT(call)->getDestProxy()
		&& linphone_proxy_config_quality_reporting_enabled(L_GET_PRIVATE_FROM_C_OBJECT(call)->getDestProxy()));
164 165
}

Ronan's avatar
Ronan committed
166
static bool_t media_report_enabled(LinphoneCall * call, int stats_type){
167
	if (!quality_reporting_enabled(call))
168 169 170 171 172
		return FALSE;

	if (stats_type == LINPHONE_CALL_STATS_VIDEO && !linphone_call_params_video_enabled(linphone_call_get_current_params(call)))
		return FALSE;

173 174 175
	if (stats_type == LINPHONE_CALL_STATS_TEXT && !linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(call)))
		return FALSE;

176
	return (L_GET_CPP_PTR_FROM_C_OBJECT(call)->getLog()->reporting.reports[stats_type] != NULL);
177 178
}

179
static void append_metrics_to_buffer(char ** buffer, size_t * size, size_t * offset, const reporting_content_metrics_t *rm) {
180 181 182 183
	char * timestamps_start_str = NULL;
	char * timestamps_stop_str = NULL;
	char * network_packet_loss_rate_str = NULL;
	char * jitter_buffer_discard_rate_str = NULL;
184
	/*char * gap_loss_density_str = NULL;*/
185 186
	char * moslq_str = NULL;
	char * moscq_str = NULL;
187
	uint8_t available_metrics = are_metrics_filled(rm);
188

189 190 191 192
	if (rm->timestamps.start > 0)
		timestamps_start_str = linphone_timestamp_to_rfc3339_string(rm->timestamps.start);
	if (rm->timestamps.stop > 0)
		timestamps_stop_str = linphone_timestamp_to_rfc3339_string(rm->timestamps.stop);
193 194 195 196 197

	append_to_buffer(buffer, size, offset, "Timestamps:");
		APPEND_IF_NOT_NULL_STR(buffer, size, offset, " START=%s", timestamps_start_str);
		APPEND_IF_NOT_NULL_STR(buffer, size, offset, " STOP=%s", timestamps_stop_str);

198 199
	if ((available_metrics & METRICS_SESSION_DESCRIPTION) != 0){
		append_to_buffer(buffer, size, offset, "\r\nSessionDesc:");
200 201 202 203 204 205
			APPEND_IF(buffer, size, offset, " PT=%d", rm->session_description.payload_type, rm->session_description.payload_type != -1);
			APPEND_IF_NOT_NULL_STR(buffer, size, offset, " PD=%s", rm->session_description.payload_desc);
			APPEND_IF(buffer, size, offset, " SR=%d", rm->session_description.sample_rate, rm->session_description.sample_rate != -1);
			APPEND_IF(buffer, size, offset, " FD=%d", rm->session_description.frame_duration, rm->session_description.frame_duration != -1);
			APPEND_IF_NOT_NULL_STR(buffer, size, offset, " FMTP=\"%s\"", rm->session_description.fmtp);
			APPEND_IF(buffer, size, offset, " PLC=%d", rm->session_description.packet_loss_concealment, rm->session_description.packet_loss_concealment != -1);
206 207 208 209
	}

	if ((available_metrics & METRICS_JITTER_BUFFER) != 0){
		append_to_buffer(buffer, size, offset, "\r\nJitterBuffer:");
210 211 212 213
			APPEND_IF_NUM_IN_RANGE(buffer, size, offset, " JBA=%d", rm->jitter_buffer.adaptive, 0, 3);
			if (rm->rtcp_xr_count){
				APPEND_IF_NUM_IN_RANGE(buffer, size, offset, " JBN=%d", rm->jitter_buffer.nominal/rm->rtcp_xr_count, 0, 65535);
				APPEND_IF_NUM_IN_RANGE(buffer, size, offset, " JBM=%d", rm->jitter_buffer.max/rm->rtcp_xr_count, 0, 65535);
214
			}
215
			APPEND_IF_NUM_IN_RANGE(buffer, size, offset, " JBX=%d",  rm->jitter_buffer.abs_max, 0, 65535);
216 217

		append_to_buffer(buffer, size, offset, "\r\nPacketLoss:");
218 219
			IF_NUM_IN_RANGE(rm->packet_loss.network_packet_loss_rate, 0, 255, network_packet_loss_rate_str = float_to_one_decimal_string(rm->packet_loss.network_packet_loss_rate / 256));
			IF_NUM_IN_RANGE(rm->packet_loss.jitter_buffer_discard_rate, 0, 255, jitter_buffer_discard_rate_str = float_to_one_decimal_string(rm->packet_loss.jitter_buffer_discard_rate / 256));
220

221 222 223 224 225
			APPEND_IF_NOT_NULL_STR(buffer, size, offset, " NLR=%s", network_packet_loss_rate_str);
			APPEND_IF_NOT_NULL_STR(buffer, size, offset, " JDR=%s", jitter_buffer_discard_rate_str);
	}

		/*append_to_buffer(buffer, size, offset, "\r\nBurstGapLoss:");*/
226
			/*IF_NUM_IN_RANGE(rm.burst_gap_loss.gap_loss_density, 0, 10, gap_loss_density_str = float_to_one_decimal_string(rm.burst_gap_loss.gap_loss_density));*/
227 228 229 230 231 232 233 234
		/*	append_to_buffer(buffer, size, offset, " BLD=%d", rm.burst_gap_loss.burst_loss_density);*/
		/*	append_to_buffer(buffer, size, offset, " BD=%d", rm.burst_gap_loss.burst_duration);*/
		/*	APPEND_IF_NOT_NULL_STR(buffer, size, offset, " GLD=%s", gap_loss_density_str);*/
		/*	append_to_buffer(buffer, size, offset, " GD=%d", rm.burst_gap_loss.gap_duration);*/
		/*	append_to_buffer(buffer, size, offset, " GMIN=%d", rm.burst_gap_loss.min_gap_threshold);*/

	if ((available_metrics & METRICS_DELAY) != 0){
		append_to_buffer(buffer, size, offset, "\r\nDelay:");
235 236
			if (rm->rtcp_xr_count+rm->rtcp_sr_count){
				APPEND_IF_NUM_IN_RANGE(buffer, size, offset, " RTD=%d", rm->delay.round_trip_delay/(rm->rtcp_xr_count+rm->rtcp_sr_count), 0, 65535);
237
			}
238 239 240
			APPEND_IF_NUM_IN_RANGE(buffer, size, offset, " ESD=%d", rm->delay.end_system_delay, 0, 65535);
			APPEND_IF_NUM_IN_RANGE(buffer, size, offset, " IAJ=%d", rm->delay.interarrival_jitter, 0, 65535);
			APPEND_IF_NUM_IN_RANGE(buffer, size, offset, " MAJ=%d", rm->delay.mean_abs_jitter, 0, 65535);
241 242 243 244
	}

	if ((available_metrics & METRICS_SIGNAL) != 0){
		append_to_buffer(buffer, size, offset, "\r\nSignal:");
245 246
			APPEND_IF(buffer, size, offset, " SL=%d", rm->signal.level, rm->signal.level != 127);
			APPEND_IF(buffer, size, offset, " NL=%d", rm->signal.noise_level, rm->signal.noise_level != 127);
247 248
	}

249
	/*if quality estimates metrics are available, rtcp_xr_count should be always not null*/
250
	if ((available_metrics & METRICS_QUALITY_ESTIMATES) != 0){
251 252
		IF_NUM_IN_RANGE(rm->quality_estimates.moslq, 1, 5, moslq_str = float_to_one_decimal_string(rm->quality_estimates.moslq));
		IF_NUM_IN_RANGE(rm->quality_estimates.moscq, 1, 5, moscq_str = float_to_one_decimal_string(rm->quality_estimates.moscq));
253

254 255 256 257 258
		append_to_buffer(buffer, size, offset, "\r\nQualityEst:");
			APPEND_IF_NOT_NULL_STR(buffer, size, offset, " MOSLQ=%s", moslq_str);
			APPEND_IF_NOT_NULL_STR(buffer, size, offset, " MOSCQ=%s", moscq_str);
	}

259
	if (rm->user_agent!=NULL){
260
		append_to_buffer(buffer, size, offset, "\r\nLinphoneExt:");
261
			APPEND_IF_NOT_NULL_STR(buffer, size, offset, " UA=\"%s\"", rm->user_agent);
262 263
	}

264 265
	append_to_buffer(buffer, size, offset, "\r\n");

266 267 268 269
	ms_free(timestamps_start_str);
	ms_free(timestamps_stop_str);
	ms_free(network_packet_loss_rate_str);
	ms_free(jitter_buffer_discard_rate_str);
270
	/*ms_free(gap_loss_density_str);*/
271 272
	ms_free(moslq_str);
	ms_free(moscq_str);
273 274
}

275
static int send_report(LinphoneCall* call, reporting_session_report_t * report, const char * report_event) {
276
	LinphoneContent *content;
277 278 279
	size_t offset = 0;
	size_t size = 2048;
	char * buffer;
280
	int ret = 0;
281 282
	LinphoneEvent *lev;
	LinphoneAddress *request_uri;
283
	const char* collector_uri;
284
	char *collector_uri_allocated = NULL;
285
	const SalAddress *salAddress;
286

287 288
	/*if we are on a low bandwidth network, do not send reports to not overload it*/
	if (linphone_call_params_low_bandwidth_enabled(linphone_call_get_current_params(call))){
289
		ms_message("QualityReporting[%p]: Avoid sending reports on low bandwidth network", call);
290 291
		ret = 1;
		goto end;
292 293
	}

294 295
	/*if the call was hung up too early, we might have invalid IPs information
	in that case, we abort the report since it's not useful data*/
296 297
	if (report->info.local_addr.ip == NULL || strlen(report->info.local_addr.ip) == 0
		|| report->info.remote_addr.ip == NULL || strlen(report->info.remote_addr.ip) == 0) {
298
		ms_message("QualityReporting[%p]: Trying to submit a %s too early (call duration: %d sec) but %s IP could "
299
			"not be retrieved so dropping this report"
300
			, call
301
			, report_event
302 303
			, linphone_call_get_duration(call)
			, (report->info.local_addr.ip == NULL || strlen(report->info.local_addr.ip) == 0) ? "local" : "remote");
304 305
		ret = 2;
		goto end;
306 307
	}

308
	buffer = (char *) ms_malloc0(size);
309
	content = linphone_content_new();
310 311
	linphone_content_set_type(content, "application");
	linphone_content_set_subtype(content, "vq-rtcpxr");
312

313
	append_to_buffer(&buffer, &size, &offset, "%s\r\n", report_event);
314
	append_to_buffer(&buffer, &size, &offset, "CallID: %s\r\n", report->info.call_id);
315 316
	append_to_buffer(&buffer, &size, &offset, "LocalID: %s\r\n", report->info.local_addr.id);
	append_to_buffer(&buffer, &size, &offset, "RemoteID: %s\r\n", report->info.remote_addr.id);
317 318
	append_to_buffer(&buffer, &size, &offset, "OrigID: %s\r\n", report->info.orig_id);

319 320
	APPEND_IF_NOT_NULL_STR(&buffer, &size, &offset, "LocalGroup: %s\r\n", report->info.local_addr.group);
	APPEND_IF_NOT_NULL_STR(&buffer, &size, &offset, "RemoteGroup: %s\r\n", report->info.remote_addr.group);
321
	append_to_buffer(&buffer, &size, &offset, "LocalAddr: IP=%s PORT=%d SSRC=%u\r\n", report->info.local_addr.ip, report->info.local_addr.port, report->info.local_addr.ssrc);
322
	APPEND_IF_NOT_NULL_STR(&buffer, &size, &offset, "LocalMAC: %s\r\n", report->info.local_addr.mac);
323
	append_to_buffer(&buffer, &size, &offset, "RemoteAddr: IP=%s PORT=%d SSRC=%u\r\n", report->info.remote_addr.ip, report->info.remote_addr.port, report->info.remote_addr.ssrc);
324
	APPEND_IF_NOT_NULL_STR(&buffer, &size, &offset, "RemoteMAC: %s\r\n", report->info.remote_addr.mac);
325

326
	append_to_buffer(&buffer, &size, &offset, "LocalMetrics:\r\n");
327
	append_metrics_to_buffer(&buffer, &size, &offset, &report->local_metrics);
328

329
	if (are_metrics_filled(&report->remote_metrics)!=0) {
330
		append_to_buffer(&buffer, &size, &offset, "RemoteMetrics:\r\n");
331
		append_metrics_to_buffer(&buffer, &size, &offset, &report->remote_metrics);
332
	}
333 334
	APPEND_IF_NOT_NULL_STR(&buffer, &size, &offset, "DialogID: %s\r\n", report->dialog_id);

335 336
	if (report->qos_analyzer.timestamp!=NULL){
		append_to_buffer(&buffer, &size, &offset, "AdaptiveAlg:");
337 338 339 340 341 342
			APPEND_IF_NOT_NULL_STR(&buffer, &size, &offset, " NAME=\"%s\"", report->qos_analyzer.name);
			APPEND_IF_NOT_NULL_STR(&buffer, &size, &offset, " TS=\"%s\"", report->qos_analyzer.timestamp);
			APPEND_IF_NOT_NULL_STR(&buffer, &size, &offset, " IN_LEG=\"%s\"", report->qos_analyzer.input_leg);
			APPEND_IF_NOT_NULL_STR(&buffer, &size, &offset, " IN=\"%s\"", report->qos_analyzer.input);
			APPEND_IF_NOT_NULL_STR(&buffer, &size, &offset, " OUT_LEG=\"%s\"", report->qos_analyzer.output_leg);
			APPEND_IF_NOT_NULL_STR(&buffer, &size, &offset, " OUT=\"%s\"", report->qos_analyzer.output);
343 344 345
		append_to_buffer(&buffer, &size, &offset, "\r\n");
	}

346 347 348 349 350
#if TARGET_OS_IPHONE
	{
		size_t namesize;
		char *machine;
		sysctlbyname("hw.machine", NULL, &namesize, NULL, 0);
Ghislain MARY's avatar
Ghislain MARY committed
351
		machine = reinterpret_cast<char *>(malloc(namesize));
352 353 354 355 356
		sysctlbyname("hw.machine", machine, &namesize, NULL, 0);
		APPEND_IF_NOT_NULL_STR(&buffer, &size, &offset, "Device: %s\r\n", machine);
	}
#endif

357
	linphone_content_set_buffer(content, (uint8_t *)buffer, strlen(buffer));
358
	ms_free(buffer);
359

360 361 362
	if (linphone_call_get_log(call)->reporting.on_report_sent != NULL) {
		SalStreamType type = report == linphone_call_get_log(call)->reporting.reports[0] ? SalAudio : report == linphone_call_get_log(call)->reporting.reports[1] ? SalVideo : SalText;
		linphone_call_get_log(call)->reporting.on_report_sent(call, type, content);
363 364
	}

365

366
	collector_uri = linphone_proxy_config_get_quality_reporting_collector(linphone_call_get_dest_proxy(call));
367
	if (!collector_uri){
368
		collector_uri = collector_uri_allocated = ms_strdup_printf("sip:%s", linphone_proxy_config_get_domain(linphone_call_get_dest_proxy(call)));
369 370
	}
	request_uri = linphone_address_new(collector_uri);
371
	lev = linphone_core_create_one_shot_publish(linphone_call_get_core(call), request_uri, "vq-rtcpxr");
372 373 374 375
	/* Special exception for quality report PUBLISH: if the collector_uri has any transport related parameters
	 * (port, transport, maddr), then it is sent directly.
	 * Otherwise it is routed as any LinphoneEvent publish, following proxy config policy.
	 **/
376
	salAddress = L_GET_PRIVATE_FROM_C_OBJECT(request_uri)->getInternalAddress();
377 378
	if (sal_address_has_uri_param(salAddress, "transport") ||
		sal_address_has_uri_param(salAddress, "maddr") ||
379 380
		linphone_address_get_port(request_uri) != 0) {
		ms_message("Publishing report with custom route %s", collector_uri);
381
		lev->op->set_route(collector_uri);
382 383
	}

384
	if (linphone_event_send_publish(lev, content) != 0){
385
		lev=NULL;
386
		ret=4;
387 388
	} else {
		reset_avg_metrics(report);
389 390 391 392 393
		STR_REASSIGN(report->qos_analyzer.timestamp, NULL);
		STR_REASSIGN(report->qos_analyzer.input_leg, NULL);
		STR_REASSIGN(report->qos_analyzer.input, NULL);
		STR_REASSIGN(report->qos_analyzer.output_leg, NULL);
		STR_REASSIGN(report->qos_analyzer.output, NULL);
394
	}
395

Simon Morlat's avatar
Simon Morlat committed
396
	linphone_address_unref(request_uri);
397
	linphone_content_unref(content);
398
	if (collector_uri_allocated) ms_free(collector_uri_allocated);
399 400

	end:
401
	ms_message("QualityReporting[%p]: Send '%s' with status %d",
402 403 404 405 406
		call,
		report_event,
		ret
	);

407
	return ret;
408 409
}

410 411 412
static const SalStreamDescription * get_media_stream_for_desc(const SalMediaDescription * smd, SalStreamType sal_stream_type) {
	int count;
	if (smd != NULL) {
413 414
		for (count = 0; count < SAL_MEDIA_DESCRIPTION_MAX_STREAMS; ++count) {
			if (sal_stream_description_active(&smd->streams[count]) && smd->streams[count].type == sal_stream_type) {
415
				return &smd->streams[count];
416 417
			}
		}
418
	}
419 420
	return NULL;
}
421

422
static void update_ip(LinphoneCall * call, int stats_type) {
423
	SalStreamType sal_stream_type = stats_type == LINPHONE_CALL_STATS_AUDIO ? SalAudio : stats_type == LINPHONE_CALL_STATS_VIDEO ? SalVideo : SalText;
424 425 426
	const SalStreamDescription * local_desc = get_media_stream_for_desc(_linphone_call_get_local_desc(call), sal_stream_type);
	const SalStreamDescription * remote_desc = get_media_stream_for_desc(L_GET_PRIVATE_FROM_C_OBJECT(call)->getOp()->get_remote_media_description(), sal_stream_type);
	LinphoneCallLog *log = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getLog();
427

428 429 430
	if (local_desc != NULL) {
		/*since this function might be called for video stream AFTER it has been uninitialized, local description might
		be invalid. In any other case, IP/port should be always filled and valid*/
431
		if (strlen(local_desc->rtp_addr) > 0) {
432 433
			log->reporting.reports[stats_type]->info.local_addr.port = local_desc->rtp_port;
			STR_REASSIGN(log->reporting.reports[stats_type]->info.local_addr.ip, ms_strdup(local_desc->rtp_addr));
434
		}
435
	}
436

437 438
	if (remote_desc != NULL) {
		/*port is always stored in stream description struct*/
439
		log->reporting.reports[stats_type]->info.remote_addr.port = remote_desc->rtp_port;
440

441
		/*for IP it can be not set if we are using a direct route*/
442
		if (strlen(remote_desc->rtp_addr) > 0) {
443
			STR_REASSIGN(log->reporting.reports[stats_type]->info.remote_addr.ip, ms_strdup(remote_desc->rtp_addr));
444
		} else {
445
			STR_REASSIGN(log->reporting.reports[stats_type]->info.remote_addr.ip, ms_strdup(L_GET_PRIVATE_FROM_C_OBJECT(call)->getOp()->get_remote_media_description()->addr));
446
		}
447
	}
448 449
}

450
static void qos_analyzer_on_action_suggested(void *user_data, int datac, const char** datav){
451 452
	reporting_session_report_t *report = (reporting_session_report_t*)user_data;
	LinphoneCall *call = report->call;
453
	char * appendbuf;
454 455
	int i;
	int ptime = -1;
456 457 458
	int bitrate[3] = {-1, -1, -1};
	int up_bw[3] = {-1, -1, -1};
	int down_bw[3] = {-1, -1, -1};
459
	MediaStream *streams[3] = { linphone_call_get_stream(call, LinphoneStreamTypeAudio), linphone_call_get_stream(call, LinphoneStreamTypeVideo), linphone_call_get_stream(call, LinphoneStreamTypeText) };
460 461 462
	for (i = 0; i < 3; i++){
		if (streams[i] != NULL){
			if (streams[i]->encoder != NULL){
463 464
				if (ms_filter_has_method(streams[i]->encoder,MS_FILTER_GET_BITRATE)){
					ms_filter_call_method(streams[i]->encoder,MS_FILTER_GET_BITRATE,&bitrate[i]);
465
					bitrate[i] /= 1000;
466 467
				}
			}
468 469
			up_bw[i] = (int)(media_stream_get_up_bw(streams[i])/1000.f);
			down_bw[i] = (int)(media_stream_get_down_bw(streams[i])/1000.f);
470 471
		}
	}
472 473 474 475 476
	AudioStream *astream = reinterpret_cast<AudioStream *>(linphone_call_get_stream(call, LinphoneStreamTypeAudio));
	if (astream!=NULL){
		if (astream->ms.encoder!=NULL){
			if(ms_filter_has_method(astream->ms.encoder,MS_AUDIO_ENCODER_GET_PTIME)){
				ms_filter_call_method(astream->ms.encoder,MS_AUDIO_ENCODER_GET_PTIME,&ptime);
477 478 479
			}
		}
	}
480

481 482
	appendbuf=ms_strdup_printf("%s%d;", report->qos_analyzer.timestamp?report->qos_analyzer.timestamp:"", ms_time(0));
	STR_REASSIGN(report->qos_analyzer.timestamp,appendbuf);
483

484 485 486
	STR_REASSIGN(report->qos_analyzer.input_leg, ms_strdup_printf("%s aenc_ptime aenc_br a_dbw a_ubw venc_br v_dbw v_ubw tenc_br t_dbw t_ubw", datav[0]));
	appendbuf=ms_strdup_printf("%s%s %d %d %d %d %d %d %d %d %d %d;", report->qos_analyzer.input?report->qos_analyzer.input:"", datav[1],
		ptime, bitrate[0], down_bw[0], up_bw[0], bitrate[1], down_bw[1], up_bw[1], bitrate[2], down_bw[2], up_bw[2]);
487
	STR_REASSIGN(report->qos_analyzer.input,appendbuf);
488 489
	STR_REASSIGN(report->qos_analyzer.output_leg, ms_strdup(datav[2]));
	appendbuf=ms_strdup_printf("%s%s;", report->qos_analyzer.output?report->qos_analyzer.output:"", datav[3]);
490
	STR_REASSIGN(report->qos_analyzer.output, appendbuf);
491 492
}

493
void linphone_reporting_update_ip(LinphoneCall * call) {
494
	update_ip(call, LINPHONE_CALL_STATS_AUDIO);
495
	update_ip(call, LINPHONE_CALL_STATS_VIDEO);
496
	update_ip(call, LINPHONE_CALL_STATS_TEXT);
497
}
498

499
void linphone_reporting_update_media_info(LinphoneCall * call, int stats_type) {
500 501 502
	MediaStream * stream = NULL;
	const PayloadType * local_payload = NULL;
	const PayloadType * remote_payload = NULL;
503
	const LinphoneCallParams * current_params = linphone_call_get_current_params(call);
504 505
	LinphoneCallLog *log = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getLog();
	reporting_session_report_t * report = log->reporting.reports[stats_type];
506
	char * dialog_id;
507

508
	// call->op might be already released if hanging up in state LinphoneCallOutgoingInit
509
	if (!media_report_enabled(call, stats_type) || !L_GET_PRIVATE_FROM_C_OBJECT(call)->getOp())
510 511
		return;

512
	dialog_id = L_GET_PRIVATE_FROM_C_OBJECT(call)->getOp()->get_dialog_id();
513

514
	STR_REASSIGN(report->info.call_id, ms_strdup(log->call_id));
515

516
	STR_REASSIGN(report->local_metrics.user_agent, ms_strdup(linphone_core_get_user_agent(linphone_call_get_core(call))));
517 518 519 520 521
	STR_REASSIGN(report->remote_metrics.user_agent, ms_strdup(linphone_call_get_remote_user_agent(call)));

	// RFC states: "LocalGroupID provides the identification for the purposes
	// of aggregation for the local endpoint.".
	STR_REASSIGN(report->info.local_addr.group, ms_strdup_printf("%s-%s-%s"
522
		, dialog_id ? dialog_id : ""
523
		, "local"
524
		, report->local_metrics.user_agent ? report->local_metrics.user_agent : ""
525
		)
526
	);
527
	STR_REASSIGN(report->info.remote_addr.group, ms_strdup_printf("%s-%s-%s"
528
		, dialog_id ? dialog_id : ""
529
		, "remote"
530
		, report->remote_metrics.user_agent ? report->remote_metrics.user_agent : ""
531
		)
532
	);
533

534

535 536 537
	if (L_GET_CPP_PTR_FROM_C_OBJECT(call)->getDirection() == LinphoneCallIncoming) {
		STR_REASSIGN(report->info.remote_addr.id, linphone_address_as_string(log->from));
		STR_REASSIGN(report->info.local_addr.id, linphone_address_as_string(log->to));
538
		STR_REASSIGN(report->info.orig_id, ms_strdup(report->info.remote_addr.id));
539
	} else {
540 541
		STR_REASSIGN(report->info.remote_addr.id, linphone_address_as_string(log->to));
		STR_REASSIGN(report->info.local_addr.id, linphone_address_as_string(log->from));
542
		STR_REASSIGN(report->info.orig_id, ms_strdup(report->info.local_addr.id));
543
	}
544

545

546 547
	report->local_metrics.timestamps.start = log->start_date_time;
	report->local_metrics.timestamps.stop = log->start_date_time + linphone_call_get_duration(call);
548

549
	/*we use same timestamps for remote too*/
550 551
	report->remote_metrics.timestamps.start = log->start_date_time;
	report->remote_metrics.timestamps.stop = log->start_date_time + linphone_call_get_duration(call);
552

553

554
	/*yet we use the same payload config for local and remote, since this is the largest use case*/
555 556
	if (stats_type == LINPHONE_CALL_STATS_AUDIO && L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeAudio)) {
		stream = L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeAudio);
557
		local_payload = linphone_call_params_get_used_audio_codec(current_params);
558
		remote_payload = local_payload;
559 560
	} else if (stats_type == LINPHONE_CALL_STATS_VIDEO && L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeVideo)) {
		stream = L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeVideo);
561
		local_payload = linphone_call_params_get_used_video_codec(current_params);
562
		remote_payload = local_payload;
563 564
	} else if (stats_type == LINPHONE_CALL_STATS_TEXT && L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeText)) {
		stream = L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeText);
565
		local_payload = linphone_call_params_get_used_text_codec(current_params);
566
		remote_payload = local_payload;
567
	}
568

569 570
	if (stream != NULL) {
		RtpSession * session = stream->sessions.rtp_session;
571

572 573
		report->info.local_addr.ssrc = rtp_session_get_send_ssrc(session);
		report->info.remote_addr.ssrc = rtp_session_get_recv_ssrc(session);
574 575

		if (stream->qi != NULL){
576 577 578 579
			report->local_metrics.quality_estimates.moslq = ms_quality_indicator_get_average_lq_rating(stream->qi) >= 0 ?
				MAX(1, ms_quality_indicator_get_average_lq_rating(stream->qi)) : -1;
			report->local_metrics.quality_estimates.moscq = ms_quality_indicator_get_average_rating(stream->qi) >= 0 ?
				MAX(1, ms_quality_indicator_get_average_rating(stream->qi)) : -1;
580
		}
581
	}
582

583
	STR_REASSIGN(report->dialog_id, ms_strdup_printf("%s;%u", dialog_id ? dialog_id : "", report->info.local_addr.ssrc));
584

585 586
	if (local_payload != NULL) {
		report->local_metrics.session_description.payload_type = local_payload->type;
587
		if (local_payload->mime_type!=NULL) STR_REASSIGN(report->local_metrics.session_description.payload_desc, ms_strdup(local_payload->mime_type));
588
		report->local_metrics.session_description.sample_rate = local_payload->clock_rate;
589
		if (local_payload->recv_fmtp!=NULL) STR_REASSIGN(report->local_metrics.session_description.fmtp, ms_strdup(local_payload->recv_fmtp));
590
	}
591

592 593
	if (remote_payload != NULL) {
		report->remote_metrics.session_description.payload_type = remote_payload->type;
594
		STR_REASSIGN(report->remote_metrics.session_description.payload_desc, ms_strdup(remote_payload->mime_type));
595
		report->remote_metrics.session_description.sample_rate = remote_payload->clock_rate;
596
		STR_REASSIGN(report->remote_metrics.session_description.fmtp, ms_strdup(remote_payload->recv_fmtp));
597
	}
598 599

	ms_free(dialog_id);
600 601
}

602 603
/* generate random float in interval ] 0.9 t ; 1.1 t [*/
static float reporting_rand(float t){
604
	return t * (.2f * ((float)rand() / (float)RAND_MAX) + 0.9f);
605 606
}

607
void linphone_reporting_on_rtcp_update(LinphoneCall *call, SalStreamType stats_type) {
608
	reporting_session_report_t * report = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getLog()->reporting.reports[stats_type];
609
	reporting_content_metrics_t * metrics = NULL;
610
	LinphoneCallStats *stats = NULL;
611
	mblk_t *block = NULL;
612
	int report_interval;
613

614
	if (stats_type == 0) {
615
		stats = L_GET_PRIVATE_FROM_C_OBJECT(call)->getStats(LinphoneStreamTypeAudio);
616
	} else if (stats_type == 1) {
617
		stats = L_GET_PRIVATE_FROM_C_OBJECT(call)->getStats(LinphoneStreamTypeVideo);
618
	} else {
619
		stats = L_GET_PRIVATE_FROM_C_OBJECT(call)->getStats(LinphoneStreamTypeText);
620 621
	}

622
	if (! media_report_enabled(call,stats_type))
623 624
		return;

625
	report_interval = linphone_proxy_config_get_quality_reporting_interval(L_GET_PRIVATE_FROM_C_OBJECT(call)->getDestProxy());
626

627
	if (_linphone_call_stats_get_updated(stats) == LINPHONE_CALL_STATS_RECEIVED_RTCP_UPDATE) {
628
		metrics = &report->remote_metrics;
629 630
		block = _linphone_call_stats_get_received_rtcp(stats);
	} else if (_linphone_call_stats_get_updated(stats) == LINPHONE_CALL_STATS_SENT_RTCP_UPDATE) {
631
		metrics = &report->local_metrics;
632
		block = _linphone_call_stats_get_sent_rtcp(stats);
633
	}
634 635
	do{
		if (rtcp_is_XR(block) && (rtcp_XR_get_block_type(block) == RTCP_XR_VOIP_METRICS)){
636

637
			uint8_t config = rtcp_XR_voip_metrics_get_rx_config(block);
638

639
			metrics->rtcp_xr_count++;
640

641 642
			// for local mos rating, we'll use the quality indicator directly
			// because rtcp XR might not be enabled
643
			if (_linphone_call_stats_get_updated(stats) == LINPHONE_CALL_STATS_RECEIVED_RTCP_UPDATE){
644 645 646 647 648
				metrics->quality_estimates.moslq = (rtcp_XR_voip_metrics_get_mos_lq(block)==127) ?
					127 : rtcp_XR_voip_metrics_get_mos_lq(block) / 10.f;
				metrics->quality_estimates.moscq = (rtcp_XR_voip_metrics_get_mos_cq(block)==127) ?
					127 : rtcp_XR_voip_metrics_get_mos_cq(block) / 10.f;
			}
649

650 651 652 653 654 655
			metrics->jitter_buffer.nominal += rtcp_XR_voip_metrics_get_jb_nominal(block);
			metrics->jitter_buffer.max += rtcp_XR_voip_metrics_get_jb_maximum(block);
			metrics->jitter_buffer.abs_max = rtcp_XR_voip_metrics_get_jb_abs_max(block);
			metrics->jitter_buffer.adaptive = (config >> 4) & 0x3;
			metrics->packet_loss.network_packet_loss_rate = rtcp_XR_voip_metrics_get_loss_rate(block);
			metrics->packet_loss.jitter_buffer_discard_rate = rtcp_XR_voip_metrics_get_discard_rate(block);
656

657 658 659
			metrics->session_description.packet_loss_concealment = (config >> 6) & 0x3;

			metrics->delay.round_trip_delay += rtcp_XR_voip_metrics_get_round_trip_delay(block);
660
		}else if (rtcp_is_SR(block)){
661 662 663
			MediaStream *ms = (stats_type == 0)
				? L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeAudio)
				: L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeVideo);
664 665 666 667
			float rtt = rtp_session_get_round_trip_propagation(ms->sessions.rtp_session);

			if (rtt > 1e-6){
				metrics->rtcp_sr_count++;
668
				metrics->delay.round_trip_delay += (int)(1000*rtt);
669
			}
670
		}
671
	}while(rtcp_next_packet(block));
672

673 674
	/* check if we should send an interval report - use a random sending time to
	dispatch reports and avoid sending them too close from each other */
675
	if ((report_interval > 0) && ((float)(ms_time(NULL) - report->last_report_date) > reporting_rand((float)report_interval))) {
676 677
		linphone_reporting_update_media_info(call, stats_type);
		send_report(call, report, "VQIntervalReport");
678 679 680
	}
}

681 682
static int publish_report(LinphoneCall *call, const char *event_type){
	int ret = 0;
683
	int i;
684
	for (i = 0; i < SAL_MEDIA_DESCRIPTION_MAX_STREAMS; i++){
685
		int stream_index = i == _linphone_call_get_main_audio_stream_index(call) ? LINPHONE_CALL_STATS_AUDIO : _linphone_call_get_main_video_stream_index(call) ? LINPHONE_CALL_STATS_VIDEO : LINPHONE_CALL_STATS_TEXT;
686
		if (media_report_enabled(call, stream_index)) {
687
			int sndret;
688
			linphone_reporting_update_media_info(call, stream_index);
689
			sndret=send_report(call, L_GET_CPP_PTR_FROM_C_OBJECT(call)->getLog()->reporting.reports[stream_index], event_type);
690 691 692 693 694
			if (sndret>0){
				ret += 10+(i+1)*sndret;
			}
		} else{
			ret += i+1;
695
		}
696
	}
697
	return ret;
698
}
699 700

int linphone_reporting_publish_session_report(LinphoneCall* call, bool_t call_term) {
701
	const char * session_type = call_term?"VQSessionReport: CallTerm":"VQSessionReport";
702
	return publish_report(call, session_type);
703
}
704

705 706
int linphone_reporting_publish_interval_report(LinphoneCall* call) {
	return publish_report(call, "VQIntervalReport");
707 708
}

709 710 711 712 713 714 715 716 717 718 719 720 721
static bool_t set_on_action_suggested_cb(MediaStream *stream,void (*on_action_suggested)(void*,int,const char**),void* u) {
	if (stream&&stream->rc){
		MSQosAnalyzer *analyzer=ms_bitrate_controller_get_qos_analyzer(stream->rc);
		if (analyzer){
			ms_qos_analyzer_set_on_action_suggested(analyzer,
													on_action_suggested,
													u);
			return TRUE;
		}
	}
	return FALSE;
}

722 723
void linphone_reporting_call_state_updated(LinphoneCall *call){
	LinphoneCallState state=linphone_call_get_state(call);
724
	LinphoneCallLog *log = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getLog();
725
	if (state == LinphoneCallReleased||!quality_reporting_enabled(call)){
726 727
		return;
	}
728 729
	switch (state){
		case LinphoneCallStreamsRunning:{
730
			int i = 0;
731 732 733 734 735
			MediaStream *streams[3] = {
				L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeAudio),
				L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeVideo),
				L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeText)
			};
736
			for (i = 0; i < SAL_MEDIA_DESCRIPTION_MAX_STREAMS; i++) {
737
				int stream_index = i == _linphone_call_get_main_audio_stream_index(call) ? LINPHONE_CALL_STATS_AUDIO : _linphone_call_get_main_video_stream_index(call) ? LINPHONE_CALL_STATS_VIDEO : LINPHONE_CALL_STATS_TEXT;
738
				bool_t enabled = media_report_enabled(call, stream_index);
739 740 741
				if (enabled && set_on_action_suggested_cb(streams[stream_index], qos_analyzer_on_action_suggested, log->reporting.reports[stream_index])) {
					log->reporting.reports[stream_index]->call=call;
					STR_REASSIGN(log->reporting.reports[stream_index]->qos_analyzer.name, ms_strdup(ms_qos_analyzer_get_name(ms_bitrate_controller_get_qos_analyzer(streams[stream_index]->rc))));
742 743 744
				}
			}
			linphone_reporting_update_ip(call);
745 746
			if (!media_report_enabled(call, LINPHONE_CALL_STATS_VIDEO) && log->reporting.was_video_running){
				send_report(call, log->reporting.reports[LINPHONE_CALL_STATS_VIDEO], "VQSessionReport");
747
			}
748
			log->reporting.was_video_running=media_report_enabled(call, LINPHONE_CALL_STATS_VIDEO);
749 750 751
			break;
		}
		case LinphoneCallEnd:{
752 753 754
			set_on_action_suggested_cb(L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeAudio), NULL, NULL);
			set_on_action_suggested_cb(L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeVideo), NULL, NULL);
			if (log->status==LinphoneCallSuccess || log->status==LinphoneCallAborted){
755
				linphone_reporting_publish_session_report(call, TRUE);
756 757 758 759 760 761 762 763
			}
			break;
		}
		default:{
			break;
		}
	}
}
764

765 766 767 768
reporting_session_report_t * linphone_reporting_new() {
	int i;
	reporting_session_report_t * rm = ms_new0(reporting_session_report_t,1);
	reporting_content_metrics_t * metrics[2] = {&rm->local_metrics, &rm->remote_metrics};
769 770 771

	memset(rm, 0, sizeof(reporting_session_report_t));

772 773 774 775
	for (i = 0; i < 2; i++) {
		metrics[i]->session_description.payload_type = -1;
		metrics[i]->session_description.sample_rate = -1;
		metrics[i]->session_description.frame_duration = -1;
776
		metrics[i]->session_description.packet_loss_concealment = -1;
777 778 779 780 781 782 783 784 785 786 787 788 789 790

		metrics[i]->packet_loss.network_packet_loss_rate = -1;
		metrics[i]->packet_loss.jitter_buffer_discard_rate = -1;


		metrics[i]->jitter_buffer.adaptive = -1;
		metrics[i]->jitter_buffer.abs_max = -1;

		metrics[i]->delay.end_system_delay = -1;
		metrics[i]->delay.interarrival_jitter = -1;
		metrics[i]->delay.mean_abs_jitter = -1;

		metrics[i]->signal.level = 127;
		metrics[i]->signal.noise_level = 127;
791
	}
792 793

	reset_avg_metrics(rm);
794
	return rm;
795
}
796 797

void linphone_reporting_destroy(reporting_session_report_t * report) {
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
	STR_REASSIGN(report->info.call_id, NULL);
	STR_REASSIGN(report->info.local_addr.id, NULL);
	STR_REASSIGN(report->info.remote_addr.id, NULL);
	STR_REASSIGN(report->info.orig_id, NULL);
	STR_REASSIGN(report->info.local_addr.ip, NULL);
	STR_REASSIGN(report->info.remote_addr.ip, NULL);
	STR_REASSIGN(report->info.local_addr.group, NULL);
	STR_REASSIGN(report->info.remote_addr.group, NULL);
	STR_REASSIGN(report->info.local_addr.mac, NULL);
	STR_REASSIGN(report->info.remote_addr.mac, NULL);
	STR_REASSIGN(report->dialog_id, NULL);
	STR_REASSIGN(report->local_metrics.session_description.fmtp, NULL);
	STR_REASSIGN(report->local_metrics.session_description.payload_desc, NULL);
	STR_REASSIGN(report->local_metrics.user_agent, NULL);
	STR_REASSIGN(report->remote_metrics.session_description.fmtp, NULL);
	STR_REASSIGN(report->remote_metrics.session_description.payload_desc, NULL);
	STR_REASSIGN(report->remote_metrics.user_agent, NULL);
	STR_REASSIGN(report->qos_analyzer.name, NULL);
	STR_REASSIGN(report->qos_analyzer.timestamp, NULL);
	STR_REASSIGN(report->qos_analyzer.input_leg, NULL);
	STR_REASSIGN(report->qos_analyzer.input, NULL);
	STR_REASSIGN(report->qos_analyzer.output_leg, NULL);
	STR_REASSIGN(report->qos_analyzer.output, NULL);
821 822 823

	ms_free(report);
}
824

825

826
void linphone_reporting_set_on_report_send(LinphoneCall *call, LinphoneQualityReportingReportSendCb cb){
827
	linphone_call_get_log(call)->reporting.on_report_sent = cb;
828
}