offeranswer_tester.c 24.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
	liblinphone_tester - liblinphone test suite
	Copyright (C) 2013  Belledonne Communications SARL

	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, see <http://www.gnu.org/licenses/>.
*/

#include <sys/types.h>
#include <sys/stat.h>
21 22
#include "linphone/core.h"
#include "linphone/lpconfig.h"
23
#include "liblinphone_tester.h"
Benjamin REIS's avatar
Benjamin REIS committed
24
#include "tester_utils.h"
25 26 27 28 29 30 31 32 33 34 35 36 37

static int get_codec_position(const MSList *l, const char *mime_type, int rate){
	const MSList *elem;
	int i;
	for (elem=l, i=0; elem!=NULL; elem=elem->next,i++){
		PayloadType *pt=(PayloadType*)elem->data;
		if (strcasecmp(pt->mime_type, mime_type)==0 && pt->clock_rate==rate) return i;
	}
	return -1;
}

/*check basic things about codecs at startup: order and enablement*/
static void start_with_no_config(void){
38
	LinphoneCore *lc=linphone_factory_create_core_3(linphone_factory_get(), NULL, liblinphone_tester_get_empty_rc(), system_context);
39
	const MSList *codecs=linphone_core_get_audio_codecs(lc);
40 41 42 43 44
	int opus_codec_pos;
	int speex_codec_pos=get_codec_position(codecs, "speex", 8000);
	int speex16_codec_pos=get_codec_position(codecs, "speex", 16000);
	PayloadType *pt;
	opus_codec_pos=get_codec_position(codecs, "opus", 48000);
45 46
	if (opus_codec_pos!=-1) BC_ASSERT_EQUAL(opus_codec_pos,0,int, "%d");
	BC_ASSERT_LOWER(speex16_codec_pos,speex_codec_pos,int,"%d");
47

48
	pt=linphone_core_find_payload_type(lc, "speex", 16000, 1);
49
	BC_ASSERT_PTR_NOT_NULL(pt);
50
	if (pt) {
51
		BC_ASSERT_TRUE(linphone_core_payload_type_enabled(lc, pt));
52
	}
53
	linphone_core_unref(lc);
54 55 56 57 58
}

static void check_payload_type_numbers(LinphoneCall *call1, LinphoneCall *call2, int expected_number){
	const LinphoneCallParams *params=linphone_call_get_current_params(call1);
	const PayloadType *pt=linphone_call_params_get_used_audio_codec(params);
59
	BC_ASSERT_PTR_NOT_NULL(pt);
60
	if (pt){
61
		BC_ASSERT_EQUAL(payload_type_get_number(pt),expected_number, int, "%d");
62 63 64
	}
	params=linphone_call_get_current_params(call2);
	pt=linphone_call_params_get_used_audio_codec(params);
65
	BC_ASSERT_PTR_NOT_NULL(pt);
66
	if (pt){
67
		BC_ASSERT_EQUAL(payload_type_get_number(pt),expected_number, int, "%d");
68 69 70 71 72 73 74 75 76
	}
}

static void simple_call_with_different_codec_mappings(void) {
	LinphoneCoreManager* marie;
	LinphoneCoreManager* pauline;
	LinphoneCall *pauline_call;

	marie = linphone_core_manager_new( "marie_rc");
77
	pauline = linphone_core_manager_new( "pauline_tcp_rc");
78

79 80
	disable_all_audio_codecs_except_one(marie->lc,"pcmu",-1);
	disable_all_audio_codecs_except_one(pauline->lc,"pcmu",-1);
81

82
	/*marie set a fantasy number to PCMU*/
83
	payload_type_set_number(linphone_core_find_payload_type(marie->lc, "PCMU", 8000, -1), 104);
84 85

	BC_ASSERT_TRUE(call(marie,pauline));
86
	pauline_call=linphone_core_get_current_call(pauline->lc);
87
	BC_ASSERT_PTR_NOT_NULL(pauline_call);
88 89 90 91
	if (pauline_call){
		LinphoneCallParams *params;
		check_payload_type_numbers(linphone_core_get_current_call(marie->lc), pauline_call, 104);
		/*make a reinvite in the other direction*/
92
		linphone_call_update(pauline_call,
93 94
			params=linphone_core_create_call_params(pauline->lc, pauline_call));
		linphone_call_params_unref(params);
95 96 97 98
		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallUpdating,1));
		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallUpdatedByRemote,1));
		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallStreamsRunning,2));
		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallStreamsRunning,2));
99 100 101 102 103 104 105 106 107
		/*payload type numbers shall remain the same*/
		check_payload_type_numbers(linphone_core_get_current_call(marie->lc), pauline_call, 104);
	}

	end_call(marie,pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
static void simple_call_with_fmtps(void){
	LinphoneCoreManager* marie;
	LinphoneCoreManager* pauline;
	LinphoneCall *pauline_call;

	marie = linphone_core_manager_new( "marie_rc");
	pauline = linphone_core_manager_new( "pauline_tcp_rc");

	disable_all_audio_codecs_except_one(marie->lc,"pcmu",-1);
	disable_all_audio_codecs_except_one(pauline->lc,"pcmu",-1);

	/*marie set a fantasy fmtp to PCMU*/
	linphone_payload_type_set_recv_fmtp(linphone_core_get_payload_type(marie->lc, "PCMU", 8000, -1), "parles-plus-fort=1");

	BC_ASSERT_TRUE(call(marie,pauline));
	pauline_call=linphone_core_get_current_call(pauline->lc);
	BC_ASSERT_PTR_NOT_NULL(pauline_call);
	if (pauline_call){
		LinphonePayloadType *pt = linphone_call_params_get_used_audio_payload_type(linphone_call_get_current_params(pauline_call));
		BC_ASSERT_PTR_NOT_NULL(pt);
		if (pt){
			BC_ASSERT_STRING_EQUAL(linphone_payload_type_get_send_fmtp(pt),"parles-plus-fort=1");
		}
		pt = linphone_call_params_get_used_audio_payload_type(linphone_call_get_current_params(linphone_core_get_current_call(marie->lc)));
		BC_ASSERT_PTR_NOT_NULL(pt);
		if (pt){
			ms_message("send_fmtp=%s, recv_fmtp=%s", linphone_payload_type_get_send_fmtp(pt), linphone_payload_type_get_recv_fmtp(pt));
			BC_ASSERT_STRING_EQUAL(linphone_payload_type_get_recv_fmtp(pt),"parles-plus-fort=1");
		}
	}

	end_call(marie,pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

144
static void call_failed_because_of_codecs(void) {
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
	LinphoneCall* out_call;

	disable_all_audio_codecs_except_one(marie->lc,"pcmu",-1);
	disable_all_audio_codecs_except_one(pauline->lc,"pcma",-1);
	out_call = linphone_core_invite_address(pauline->lc,marie->identity);
	linphone_call_ref(out_call);
	BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallOutgoingInit,1));

	/*flexisip will retain the 488 until the "urgent reply" timeout (I.E 5s) arrives.*/
	BC_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallError,1,7000));
	BC_ASSERT_EQUAL(linphone_call_get_reason(out_call),LinphoneReasonNotAcceptable, int, "%d");
	BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallIncomingReceived,0, int, "%d");
	BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallReleased,0, int, "%d");

	linphone_call_unref(out_call);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
164 165 166
}


167 168 169 170 171 172 173
static void profile_call_base(bool_t avpf1
							  , LinphoneMediaEncryption srtp1
							  , bool_t avpf2
							  , LinphoneMediaEncryption srtp2
							  , bool_t encryption_mandatory
							  , const char *expected_profile
							  , bool_t enable_video) {
174
	LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc");
175
	LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_tcp_rc");
176 177 178 179
	LinphoneProxyConfig *lpc;
	const LinphoneCallParams *params;

	if (avpf1) {
180
		lpc = linphone_core_get_default_proxy_config(marie->lc);
181 182 183 184
		linphone_proxy_config_enable_avpf(lpc, TRUE);
		linphone_proxy_config_set_avpf_rr_interval(lpc, 3);
	}
	if (avpf2) {
185
		lpc = linphone_core_get_default_proxy_config(pauline->lc);
186 187 188
		linphone_proxy_config_enable_avpf(lpc, TRUE);
		linphone_proxy_config_set_avpf_rr_interval(lpc, 3);
	}
189 190 191 192 193

	if (encryption_mandatory) {
		linphone_core_set_media_encryption_mandatory(marie->lc,TRUE);
		linphone_core_set_media_encryption_mandatory(pauline->lc,TRUE);
	}
194

195 196 197 198 199 200 201 202 203 204 205
	if (enable_video && linphone_core_video_supported(marie->lc)) {
		LinphoneVideoPolicy policy;
		policy.automatically_accept = TRUE;
		policy.automatically_initiate = TRUE;
		linphone_core_enable_video_capture(marie->lc, TRUE);
		linphone_core_enable_video_display(marie->lc, TRUE);
		linphone_core_set_video_policy(marie->lc,&policy);
		linphone_core_enable_video_capture(pauline->lc, TRUE);
		linphone_core_enable_video_display(pauline->lc, TRUE);
		linphone_core_set_video_policy(pauline->lc,&policy);
	}
206

jehan's avatar
jehan committed
207 208 209 210 211 212
	if (linphone_core_media_encryption_supported(marie->lc, srtp1)) {
		linphone_core_set_media_encryption(marie->lc, srtp1);
	} else {
		ms_message("Unsupported [%s] encryption type, cannot test",linphone_media_encryption_to_string(srtp1));
		goto end;

213
	}
jehan's avatar
jehan committed
214 215 216 217 218
	if (linphone_core_media_encryption_supported(pauline->lc, srtp2)) {
		linphone_core_set_media_encryption(pauline->lc, srtp2);
	}else {
		ms_message("Unsupported [%s] encryption type, cannot test",linphone_media_encryption_to_string(srtp2));
		goto end;
219 220
	}

221 222 223
	BC_ASSERT_TRUE(call(marie, pauline));
	BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallStreamsRunning, 1));
	BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallStreamsRunning, 1));
224
	wait_for_until(marie->lc, pauline->lc, NULL, 0, 1000); /*wait 1 second for streams to start flowing*/
225 226
	if (linphone_core_get_current_call(marie->lc)) {
		params = linphone_call_get_current_params(linphone_core_get_current_call(marie->lc));
227
		BC_ASSERT_STRING_EQUAL(linphone_call_params_get_rtp_profile(params), expected_profile);
228 229 230
	}
	if (linphone_core_get_current_call(pauline->lc)) {
		params = linphone_call_get_current_params(linphone_core_get_current_call(pauline->lc));
231
		BC_ASSERT_STRING_EQUAL(linphone_call_params_get_rtp_profile(params), expected_profile);
232
	}
233 234

	linphone_core_terminate_all_calls(marie->lc);
235 236
	BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallEnd, 1));
	BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallEnd, 1));
237 238
	BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallReleased, 1));
	BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallReleased, 1));
239 240
	BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallConnected, 1, int, "%d");
	BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallConnected, 1, int, "%d");
jehan's avatar
jehan committed
241
end:
242 243 244 245
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
}

246 247
static void profile_call(bool_t avpf1, LinphoneMediaEncryption srtp1, bool_t avpf2, LinphoneMediaEncryption srtp2, const char *expected_profile, bool_t enable_video) {
	profile_call_base(avpf1, srtp1, avpf2,srtp2,FALSE,expected_profile,enable_video);
248
}
249

250
static void avp_to_avp_call(void) {
251
	profile_call(FALSE, LinphoneMediaEncryptionNone, FALSE, LinphoneMediaEncryptionNone, "RTP/AVP", FALSE);
252
}
253 254 255 256 257
#ifdef VIDEO_ENABLED
static void avp_to_avp_video_call(void) {
	profile_call(FALSE, LinphoneMediaEncryptionNone, FALSE, LinphoneMediaEncryptionNone, "RTP/AVP", TRUE);
}
#endif
258 259

static void avp_to_avpf_call(void) {
260
	profile_call(FALSE, LinphoneMediaEncryptionNone, TRUE, LinphoneMediaEncryptionNone, "RTP/AVP",FALSE);
261
}
262 263 264 265 266
#ifdef VIDEO_ENABLED
static void avp_to_avpf_video_call(void) {
	profile_call(FALSE, LinphoneMediaEncryptionNone, TRUE, LinphoneMediaEncryptionNone, "RTP/AVP",TRUE);
}
#endif
267 268

static void avp_to_savp_call(void) {
269 270 271 272 273
	profile_call(FALSE, LinphoneMediaEncryptionNone, FALSE, LinphoneMediaEncryptionSRTP, "RTP/AVP", FALSE);
}
#ifdef VIDEO_ENABLED
static void avp_to_savp_video_call(void) {
	profile_call(FALSE, LinphoneMediaEncryptionNone, FALSE, LinphoneMediaEncryptionSRTP, "RTP/AVP", TRUE);
274
}
275
#endif
276 277

static void avp_to_savpf_call(void) {
278
	profile_call(FALSE, LinphoneMediaEncryptionNone, TRUE, LinphoneMediaEncryptionSRTP, "RTP/AVP", FALSE);
279
}
280 281 282 283 284
#ifdef VIDEO_ENABLED
static void avp_to_savpf_video_call(void) {
	profile_call(FALSE, LinphoneMediaEncryptionNone, TRUE, LinphoneMediaEncryptionSRTP, "RTP/AVP", TRUE);
}
#endif
285 286

static void avpf_to_avp_call(void) {
287
	profile_call(TRUE, LinphoneMediaEncryptionNone, FALSE, LinphoneMediaEncryptionNone, "RTP/AVPF", FALSE);
288
}
289 290 291 292 293
#ifdef VIDEO_ENABLED
static void avpf_to_avp_video_call(void) {
	profile_call(TRUE, LinphoneMediaEncryptionNone, FALSE, LinphoneMediaEncryptionNone, "RTP/AVPF", TRUE);
}
#endif
294 295

static void avpf_to_avpf_call(void) {
296
	profile_call(TRUE, LinphoneMediaEncryptionNone, TRUE, LinphoneMediaEncryptionNone, "RTP/AVPF", FALSE);
297
}
298 299 300 301 302
#ifdef VIDEO_ENABLED
static void avpf_to_avpf_video_call(void) {
	profile_call(TRUE, LinphoneMediaEncryptionNone, TRUE, LinphoneMediaEncryptionNone, "RTP/AVPF", TRUE);
}
#endif
303 304

static void avpf_to_savp_call(void) {
305
	profile_call(TRUE, LinphoneMediaEncryptionNone, FALSE, LinphoneMediaEncryptionSRTP, "RTP/AVPF", FALSE);
306
}
307 308 309 310 311
#ifdef VIDEO_ENABLED
static void avpf_to_savp_video_call(void) {
	profile_call(TRUE, LinphoneMediaEncryptionNone, FALSE, LinphoneMediaEncryptionSRTP, "RTP/AVPF", TRUE);
}
#endif
312 313

static void avpf_to_savpf_call(void) {
314
	profile_call(TRUE, LinphoneMediaEncryptionNone, TRUE, LinphoneMediaEncryptionSRTP, "RTP/AVPF", FALSE);
315
}
316 317 318 319 320
#ifdef VIDEO_ENABLED
static void avpf_to_savpf_video_call(void) {
	profile_call(TRUE, LinphoneMediaEncryptionNone, TRUE, LinphoneMediaEncryptionSRTP, "RTP/AVPF", TRUE);
}
#endif
321 322

static void savp_to_avp_call(void) {
323
	profile_call(FALSE, LinphoneMediaEncryptionSRTP, FALSE, LinphoneMediaEncryptionNone, "RTP/SAVP", FALSE);
324
}
325 326 327 328 329
#ifdef VIDEO_ENABLED
static void savp_to_avp_video_call(void) {
	profile_call(FALSE, LinphoneMediaEncryptionSRTP, FALSE, LinphoneMediaEncryptionNone, "RTP/SAVP", TRUE);
}
#endif
330 331

static void savp_to_avpf_call(void) {
332 333 334 335 336
	profile_call(FALSE, LinphoneMediaEncryptionSRTP, TRUE, LinphoneMediaEncryptionNone, "RTP/SAVP", FALSE);
}
#ifdef VIDEO_ENABLED
static void savp_to_avpf_video_call(void) {
	profile_call(FALSE, LinphoneMediaEncryptionSRTP, TRUE, LinphoneMediaEncryptionNone, "RTP/SAVP", TRUE);
337
}
338
#endif
339 340

static void savp_to_savp_call(void) {
341 342 343 344 345
	profile_call(FALSE, LinphoneMediaEncryptionSRTP, FALSE, LinphoneMediaEncryptionSRTP, "RTP/SAVP", FALSE);
}
#ifdef VIDEO_ENABLED
static void savp_to_savp_video_call(void) {
	profile_call(FALSE, LinphoneMediaEncryptionSRTP, FALSE, LinphoneMediaEncryptionSRTP, "RTP/SAVP", TRUE);
346
}
347
#endif
348 349

static void savp_to_savpf_call(void) {
350
	profile_call(FALSE, LinphoneMediaEncryptionSRTP, TRUE, LinphoneMediaEncryptionSRTP, "RTP/SAVP", FALSE);
351
}
352 353 354 355 356
#ifdef VIDEO_ENABLED
static void savp_to_savpf_video_call(void) {
	profile_call(FALSE, LinphoneMediaEncryptionSRTP, TRUE, LinphoneMediaEncryptionSRTP, "RTP/SAVP", TRUE);
}
#endif
357 358

static void savpf_to_avp_call(void) {
359 360 361 362 363
	profile_call(TRUE, LinphoneMediaEncryptionSRTP, FALSE, LinphoneMediaEncryptionNone, "RTP/SAVPF", FALSE);
}
#ifdef VIDEO_ENABLED
static void savpf_to_avp_video_call(void) {
	profile_call(TRUE, LinphoneMediaEncryptionSRTP, FALSE, LinphoneMediaEncryptionNone, "RTP/SAVPF", TRUE);
364
}
365
#endif
366 367

static void savpf_to_avpf_call(void) {
368 369 370 371 372
	profile_call(TRUE, LinphoneMediaEncryptionSRTP, TRUE, LinphoneMediaEncryptionNone, "RTP/SAVPF", FALSE);
}
#ifdef VIDEO_ENABLED
static void savpf_to_avpf_video_call(void) {
	profile_call(TRUE, LinphoneMediaEncryptionSRTP, TRUE, LinphoneMediaEncryptionNone, "RTP/SAVPF", TRUE);
373
}
374
#endif
375 376

static void savpf_to_savp_call(void) {
377
	profile_call(TRUE, LinphoneMediaEncryptionSRTP, FALSE, LinphoneMediaEncryptionSRTP, "RTP/SAVPF", FALSE);
378
}
379 380 381 382 383
#ifdef VIDEO_ENABLED
static void savpf_to_savp_video_call(void) {
	profile_call(TRUE, LinphoneMediaEncryptionSRTP, FALSE, LinphoneMediaEncryptionSRTP, "RTP/SAVPF", TRUE);
}
#endif
384
static void savpf_to_savpf_call(void) {
385
	profile_call(TRUE, LinphoneMediaEncryptionSRTP, TRUE, LinphoneMediaEncryptionSRTP, "RTP/SAVPF", FALSE);
jehan's avatar
jehan committed
386
}
387 388 389 390 391
#ifdef VIDEO_ENABLED
static void savpf_to_savpf_video_call(void) {
	profile_call(TRUE, LinphoneMediaEncryptionSRTP, TRUE, LinphoneMediaEncryptionSRTP, "RTP/SAVPF", TRUE);
}
#endif
jehan's avatar
jehan committed
392 393

static void savpf_dtls_to_savpf_dtls_call(void) {
394 395 396 397 398
	profile_call(TRUE, LinphoneMediaEncryptionDTLS, TRUE, LinphoneMediaEncryptionDTLS, "UDP/TLS/RTP/SAVPF", FALSE);
}
#ifdef VIDEO_ENABLED
static void savpf_dtls_to_savpf_dtls_video_call(void) {
	profile_call(TRUE, LinphoneMediaEncryptionDTLS, TRUE, LinphoneMediaEncryptionDTLS, "UDP/TLS/RTP/SAVPF", TRUE);
jehan's avatar
jehan committed
399
}
400 401
#endif

402
static void savpf_dtls_to_savpf_dtls_encryption_mandatory_call(void) {
403 404 405 406 407
	profile_call_base(TRUE, LinphoneMediaEncryptionDTLS, TRUE, LinphoneMediaEncryptionDTLS, TRUE, "UDP/TLS/RTP/SAVPF", FALSE);
}
#ifdef VIDEO_ENABLED
static void savpf_dtls_to_savpf_dtls_encryption_mandatory_video_call(void) {
	profile_call_base(TRUE, LinphoneMediaEncryptionDTLS, TRUE, LinphoneMediaEncryptionDTLS, TRUE, "UDP/TLS/RTP/SAVPF", TRUE);
408
}
409 410
#endif

411
static void savpf_dtls_to_savpf_encryption_mandatory_call(void) {
412 413 414 415 416
	/*profile_call_base(TRUE, LinphoneMediaEncryptionDTLS, TRUE, LinphoneMediaEncryptionSRTP, TRUE, "UDP/TLS/RTP/SAVPF",FALSE); not sure of result*/
}
#ifdef VIDEO_ENABLED
static void savpf_dtls_to_savpf_encryption_mandatory_video_call(void) {
	/*profile_call_base(TRUE, LinphoneMediaEncryptionDTLS, TRUE, LinphoneMediaEncryptionSRTP, TRUE, "UDP/TLS/RTP/SAVPF",TRUE); not sure of result*/
417
}
418
#endif
jehan's avatar
jehan committed
419 420

static void savpf_dtls_to_savpf_call(void) {
421 422 423 424 425
	profile_call(TRUE, LinphoneMediaEncryptionDTLS, TRUE, LinphoneMediaEncryptionSRTP, "UDP/TLS/RTP/SAVPF", FALSE);
}
#ifdef VIDEO_ENABLED
static void savpf_dtls_to_savpf_video_call(void) {
	profile_call(TRUE, LinphoneMediaEncryptionDTLS, TRUE, LinphoneMediaEncryptionSRTP, "UDP/TLS/RTP/SAVPF", TRUE);
jehan's avatar
jehan committed
426
}
427
#endif
jehan's avatar
jehan committed
428 429

static void savpf_dtls_to_avpf_call(void) {
430
	profile_call(TRUE, LinphoneMediaEncryptionDTLS, TRUE, LinphoneMediaEncryptionNone, "UDP/TLS/RTP/SAVPF", FALSE);
431
}
432 433 434 435 436
#ifdef VIDEO_ENABLED
static void savpf_dtls_to_avpf_video_call(void) {
	profile_call(TRUE, LinphoneMediaEncryptionDTLS, TRUE, LinphoneMediaEncryptionNone, "UDP/TLS/RTP/SAVPF", TRUE);
}
#endif
437

438
#ifdef VIDEO_ENABLED
439
static OrtpPayloadType * configure_core_for_avpf_and_video(LinphoneCore *lc) {
440
	LinphoneProxyConfig *lpc;
441
	OrtpPayloadType *pt;
442 443 444 445
	LinphoneVideoPolicy policy = { 0 };

	policy.automatically_initiate = TRUE;
	policy.automatically_accept = TRUE;
446
	lpc = linphone_core_get_default_proxy_config(lc);
447 448 449 450 451 452
	linphone_proxy_config_enable_avpf(lpc, TRUE);
	linphone_proxy_config_set_avpf_rr_interval(lpc, 3);
	linphone_core_set_video_device(lc, "StaticImage: Static picture");
	linphone_core_enable_video_capture(lc, TRUE);
	linphone_core_enable_video_display(lc, TRUE);
	linphone_core_set_video_policy(lc, &policy);
453 454
	pt = linphone_core_find_payload_type(lc, "VP8", 90000, -1);
	if (pt == NULL) {
455 456 457 458
		ms_warning("VP8 codec not available.");
	} else {
		disable_all_video_codecs_except_one(lc, "VP8");
	}
459
	return pt;
460 461 462 463 464 465
}

static void check_avpf_features(LinphoneCore *lc, unsigned char expected_features) {
	LinphoneCall *lcall = linphone_core_get_current_call(lc);
	BC_ASSERT_PTR_NOT_NULL(lcall);
	if (lcall != NULL) {
466 467
		SalMediaDescription *resultDesc = _linphone_call_get_result_desc(lcall);
		SalStreamDescription *desc = sal_media_description_find_stream(resultDesc, SalProtoRtpAvpf, SalVideo);
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
		BC_ASSERT_PTR_NOT_NULL(desc);
		if (desc != NULL) {
			BC_ASSERT_PTR_NOT_NULL(desc->payloads);
			if (desc->payloads) {
				PayloadType *pt = (PayloadType *)desc->payloads->data;
				BC_ASSERT_STRING_EQUAL(pt->mime_type, "VP8");
				BC_ASSERT_EQUAL(pt->avpf.features, expected_features, int, "%d");
			}
		}
	}
}

static void compatible_avpf_features(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc");
	LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_tcp_rc");
483
	OrtpPayloadType *pt;
Simon Morlat's avatar
Simon Morlat committed
484
	bool_t call_ok;
485 486

	if (configure_core_for_avpf_and_video(marie->lc) == NULL) goto end;
Benjamin REIS's avatar
Benjamin REIS committed
487

488
	pt = configure_core_for_avpf_and_video(pauline->lc);
489

Simon Morlat's avatar
Simon Morlat committed
490 491
	BC_ASSERT_TRUE((call_ok=call(marie, pauline)));
	if (!call_ok) goto end;
492

493 494
	BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallStreamsRunning, 1));
	BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallStreamsRunning, 1));
495
	wait_for_until(marie->lc, pauline->lc, NULL, 0, 1000); /*wait 1 second for streams to start flowing*/
496 497
	check_avpf_features(marie->lc, pt->avpf.features);
	check_avpf_features(pauline->lc, pt->avpf.features);
498

Simon Morlat's avatar
Simon Morlat committed
499
	end_call(marie,pauline);
500 501 502 503 504 505 506 507
end:
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
}

static void incompatible_avpf_features(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc");
	LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_tcp_rc");
508
	OrtpPayloadType *pt;
Simon Morlat's avatar
Simon Morlat committed
509
	bool_t call_ok;
510 511

	if (configure_core_for_avpf_and_video(marie->lc) == NULL) goto end;
Benjamin REIS's avatar
Benjamin REIS committed
512

513 514
	pt = configure_core_for_avpf_and_video(pauline->lc);
	pt->avpf.features = PAYLOAD_TYPE_AVPF_NONE;
515

Simon Morlat's avatar
Simon Morlat committed
516 517
	BC_ASSERT_TRUE(call_ok=call(marie, pauline));
	if (!call_ok) goto end;
518 519
	BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallStreamsRunning, 1));
	BC_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallStreamsRunning, 1));
520
	wait_for_until(marie->lc, pauline->lc, NULL, 0, 1000); /*wait 1 second for streams to start flowing*/
521 522 523
	check_avpf_features(marie->lc, PAYLOAD_TYPE_AVPF_NONE);
	check_avpf_features(pauline->lc, PAYLOAD_TYPE_AVPF_NONE);

Simon Morlat's avatar
Simon Morlat committed
524
	end_call(marie,pauline);
525 526 527 528 529 530
end:
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
}
#endif

531
static test_t offeranswer_tests[] = {
532 533 534
	TEST_NO_TAG("Start with no config", start_with_no_config),
	TEST_NO_TAG("Call failed because of codecs", call_failed_because_of_codecs),
	TEST_NO_TAG("Simple call with different codec mappings", simple_call_with_different_codec_mappings),
535
	TEST_NO_TAG("Simple call with fmtps", simple_call_with_fmtps),
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
	TEST_NO_TAG("AVP to AVP call", avp_to_avp_call),
	TEST_NO_TAG("AVP to AVPF call", avp_to_avpf_call),
	TEST_NO_TAG("AVP to SAVP call", avp_to_savp_call),
	TEST_NO_TAG("AVP to SAVPF call", avp_to_savpf_call),
	TEST_NO_TAG("AVPF to AVP call", avpf_to_avp_call),
	TEST_NO_TAG("AVPF to AVPF call", avpf_to_avpf_call),
	TEST_NO_TAG("AVPF to SAVP call", avpf_to_savp_call),
	TEST_NO_TAG("AVPF to SAVPF call", avpf_to_savpf_call),
	TEST_NO_TAG("SAVP to AVP call", savp_to_avp_call),
	TEST_NO_TAG("SAVP to AVPF call", savp_to_avpf_call),
	TEST_NO_TAG("SAVP to SAVP call", savp_to_savp_call),
	TEST_NO_TAG("SAVP to SAVPF call", savp_to_savpf_call),
	TEST_NO_TAG("SAVPF to AVP call", savpf_to_avp_call),
	TEST_NO_TAG("SAVPF to AVPF call", savpf_to_avpf_call),
	TEST_NO_TAG("SAVPF to SAVP call", savpf_to_savp_call),
	TEST_NO_TAG("SAVPF to SAVPF call", savpf_to_savpf_call),
johan's avatar
johan committed
552 553 554 555 556
	TEST_ONE_TAG("SAVPF/DTLS to SAVPF/DTLS call", savpf_dtls_to_savpf_dtls_call, "DTLS"),
	TEST_ONE_TAG("SAVPF/DTLS to SAVPF/DTLS encryption mandatory call", savpf_dtls_to_savpf_dtls_encryption_mandatory_call, "DTLS"),
	TEST_ONE_TAG("SAVPF/DTLS to SAVPF call", savpf_dtls_to_savpf_call, "DTLS"),
	TEST_ONE_TAG("SAVPF/DTLS to SAVPF encryption mandatory call", savpf_dtls_to_savpf_encryption_mandatory_call, "DTLS"),
	TEST_ONE_TAG("SAVPF/DTLS to AVPF call", savpf_dtls_to_avpf_call, "DTLS"),
557
#ifdef VIDEO_ENABLED
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
	TEST_NO_TAG("AVP to AVP video call", avp_to_avp_video_call),
	TEST_NO_TAG("AVP to AVPF video call", avp_to_avpf_video_call),
	TEST_NO_TAG("AVP to SAVP video call", avp_to_savp_video_call),
	TEST_NO_TAG("AVP to SAVPF video call", avp_to_savpf_video_call),
	TEST_NO_TAG("AVPF to AVP video call", avpf_to_avp_video_call),
	TEST_NO_TAG("AVPF to AVPF video call", avpf_to_avpf_video_call),
	TEST_NO_TAG("AVPF to SAVP video call", avpf_to_savp_video_call),
	TEST_NO_TAG("AVPF to SAVPF video call", avpf_to_savpf_video_call),
	TEST_NO_TAG("SAVP to AVP video call", savp_to_avp_video_call),
	TEST_NO_TAG("SAVP to AVPF video call", savp_to_avpf_video_call),
	TEST_NO_TAG("SAVP to SAVP video call", savp_to_savp_video_call),
	TEST_NO_TAG("SAVP to SAVPF video call", savp_to_savpf_video_call),
	TEST_NO_TAG("SAVPF to AVP video call", savpf_to_avp_video_call),
	TEST_NO_TAG("SAVPF to AVPF video call", savpf_to_avpf_video_call),
	TEST_NO_TAG("SAVPF to SAVP video call", savpf_to_savp_video_call),
	TEST_NO_TAG("SAVPF to SAVPF video call", savpf_to_savpf_video_call),
johan's avatar
johan committed
574 575 576 577 578
	TEST_ONE_TAG("SAVPF/DTLS to SAVPF/DTLS video call", savpf_dtls_to_savpf_dtls_video_call, "DTLS"),
	TEST_ONE_TAG("SAVPF/DTLS to SAVPF/DTLS encryption mandatory video call", savpf_dtls_to_savpf_dtls_encryption_mandatory_video_call, "DTLS"),
	TEST_ONE_TAG("SAVPF/DTLS to SAVPF video call", savpf_dtls_to_savpf_video_call, "DTLS"),
	TEST_ONE_TAG("SAVPF/DTLS to SAVPF encryption mandatory video call", savpf_dtls_to_savpf_encryption_mandatory_video_call, "DTLS"),
	TEST_ONE_TAG("SAVPF/DTLS to AVPF video call", savpf_dtls_to_avpf_video_call, "DTLS"),
579 580 581

	TEST_NO_TAG("Compatible AVPF features", compatible_avpf_features),
	TEST_NO_TAG("Incompatible AVPF features", incompatible_avpf_features)
582
#endif
583 584
};

585
test_suite_t offeranswer_test_suite = {"Offer-answer", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
586
									   sizeof(offeranswer_tests) / sizeof(offeranswer_tests[0]), offeranswer_tests};