call_multicast_tester.c 11.7 KB
Newer Older
jehan's avatar
jehan committed
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) 2014  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 "liblinphone_tester.h"
Benjamin REIS's avatar
Benjamin REIS committed
21
#include "tester_utils.h"
22
#include "linphone/core.h"
jehan's avatar
jehan committed
23 24
#include "belle-sip/belle-sip.h"

25

jehan's avatar
jehan committed
26
static void call_multicast_base(bool_t video) {
27
	LinphoneCoreManager *marie, *pauline;
jehan's avatar
jehan committed
28 29
	LinphoneVideoPolicy marie_policy, pauline_policy;

30
	marie = linphone_core_manager_new( "marie_rc");
31
	pauline = linphone_core_manager_new( "pauline_tcp_rc");
jehan's avatar
jehan committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

	if (video) {
		linphone_core_enable_video_capture(marie->lc, TRUE);
		linphone_core_enable_video_display(marie->lc, TRUE);
		linphone_core_enable_video_capture(pauline->lc, TRUE);
		linphone_core_enable_video_display(pauline->lc, FALSE);

		marie_policy.automatically_initiate=TRUE;
		marie_policy.automatically_accept=TRUE;
		pauline_policy.automatically_initiate=TRUE;
		pauline_policy.automatically_accept=TRUE;

		linphone_core_set_video_policy(marie->lc,&marie_policy);
		linphone_core_set_video_policy(pauline->lc,&pauline_policy);
		linphone_core_set_video_multicast_addr(pauline->lc,"224.1.2.3");
		linphone_core_enable_video_multicast(pauline->lc,TRUE);
	}
	linphone_core_set_audio_multicast_addr(pauline->lc,"224.1.2.3");
	linphone_core_enable_audio_multicast(pauline->lc,TRUE);

52
	BC_ASSERT_TRUE(call(pauline,marie));
53
	wait_for_until(marie->lc, pauline->lc, NULL, 1, 6000);
jehan's avatar
jehan committed
54
	if (linphone_core_get_current_call(marie->lc)) {
55
		BC_ASSERT_GREATER(linphone_core_manager_get_max_audio_down_bw(marie),70,int,"%d");
jehan's avatar
jehan committed
56 57
		if (video) {
			/*check video path*/
Simon Morlat's avatar
Simon Morlat committed
58
			liblinphone_tester_set_next_video_frame_decoded_cb(linphone_core_get_current_call(marie->lc));
jehan's avatar
jehan committed
59
			linphone_call_send_vfu_request(linphone_core_get_current_call(marie->lc));
60
			BC_ASSERT_TRUE( wait_for(marie->lc,pauline->lc,&marie->stat.number_of_IframeDecoded,1));
jehan's avatar
jehan committed
61 62 63 64 65 66 67
		}

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

jehan's avatar
jehan committed
69 70 71
static void call_multicast(void)  {
	call_multicast_base(FALSE);
}
72
static void multicast_audio_with_pause_resume(void) {
73
	call_paused_resumed_base(TRUE,FALSE);
jehan's avatar
jehan committed
74 75 76 77 78 79 80
}
#ifdef VIDEO_ENABLED
static void call_multicast_video(void)  {
	call_multicast_base(TRUE);
}
#endif
static void early_media_with_multicast_base(bool_t video) {
81
	LinphoneCoreManager *marie, *pauline, *pauline2;
82
	bctbx_list_t* lcs = NULL;
jehan's avatar
jehan committed
83 84
	int dummy=0;
	LinphoneVideoPolicy marie_policy, pauline_policy;
85
	LpConfig *marie_lp;
86
	LinphoneCallParams *params;
87
	LinphoneCallStats *stats = NULL;
jehan's avatar
jehan committed
88

89
	marie   = linphone_core_manager_new("marie_rc");
90 91
	pauline = linphone_core_manager_new("pauline_tcp_rc");
	pauline2 = linphone_core_manager_new("pauline_tcp_rc");
92 93 94

	marie_lp=linphone_core_get_config(marie->lc);
	lp_config_set_int(marie_lp,"misc","real_early_media",1);
jehan's avatar
jehan committed
95 96

	if (video) {
97
		linphone_core_enable_video_capture(pauline->lc, FALSE);
jehan's avatar
jehan committed
98
		linphone_core_enable_video_display(pauline->lc, TRUE);
99 100
		linphone_core_enable_video_capture(pauline2->lc, FALSE);
		linphone_core_enable_video_display(pauline2->lc, TRUE);
jehan's avatar
jehan committed
101 102
		linphone_core_enable_video_capture(marie->lc, TRUE);
		linphone_core_enable_video_display(marie->lc, FALSE);
103 104 105 106 107 108 109 110 111

		// important: VP8 has really poor performances with the mire camera, at least
		// on iOS - so when ever h264 is available, let's use it instead
		if (linphone_core_find_payload_type(pauline->lc,"h264", -1, -1)!=NULL) {
			disable_all_video_codecs_except_one(pauline->lc,"h264");
			disable_all_video_codecs_except_one(pauline2->lc,"h264");
			disable_all_video_codecs_except_one(marie->lc,"h264");
		}

112 113 114
		linphone_core_set_video_device(pauline->lc, liblinphone_tester_mire_id);
		linphone_core_set_video_device(pauline2->lc, liblinphone_tester_mire_id);
		linphone_core_set_video_device(marie->lc, liblinphone_tester_mire_id);
115

116 117 118
		linphone_core_set_avpf_mode(pauline->lc, LinphoneAVPFEnabled);
		linphone_core_set_avpf_mode(pauline2->lc, LinphoneAVPFEnabled);
		linphone_core_set_avpf_mode(marie->lc, LinphoneAVPFEnabled);
jehan's avatar
jehan committed
119 120 121 122 123 124 125 126

		marie_policy.automatically_initiate=TRUE;
		marie_policy.automatically_accept=TRUE;
		pauline_policy.automatically_initiate=TRUE;
		pauline_policy.automatically_accept=TRUE;

		linphone_core_set_video_policy(marie->lc,&marie_policy);
		linphone_core_set_video_policy(pauline->lc,&pauline_policy);
127
		linphone_core_set_video_policy(pauline2->lc,&pauline_policy);
jehan's avatar
jehan committed
128 129 130 131 132 133 134
		linphone_core_set_video_multicast_addr(marie->lc,"224.1.2.3");
		linphone_core_enable_video_multicast(marie->lc,TRUE);
	}
	linphone_core_set_audio_multicast_addr(marie->lc,"224.1.2.3");
	linphone_core_enable_audio_multicast(marie->lc,TRUE);


135 136 137
	lcs = bctbx_list_append(lcs,marie->lc);
	lcs = bctbx_list_append(lcs,pauline->lc);
	lcs = bctbx_list_append(lcs,pauline2->lc);
jehan's avatar
jehan committed
138 139 140 141
	/*
		Marie calls Pauline, and after the call has rung, transitions to an early_media session
	*/

142
	linphone_core_invite_address(marie->lc, pauline->identity);
jehan's avatar
jehan committed
143

144 145
	BC_ASSERT_TRUE(wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallIncomingReceived,1,3000));
	BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallOutgoingRinging,1,1000));
jehan's avatar
jehan committed
146 147 148 149 150 151


	if (linphone_core_inc_invite_pending(pauline->lc)) {
		/* send a 183 to initiate the early media */
		if (video) {
			/*check video path*/
Simon Morlat's avatar
Simon Morlat committed
152
			liblinphone_tester_set_next_video_frame_decoded_cb(linphone_core_get_current_call(pauline->lc));
jehan's avatar
jehan committed
153
		}
154
		linphone_call_accept_early_media(linphone_core_get_current_call(pauline->lc));
jehan's avatar
jehan committed
155

156 157
		BC_ASSERT_TRUE( wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallIncomingEarlyMedia,1,2000) );
		BC_ASSERT_TRUE( wait_for_list(lcs, &marie->stat.number_of_LinphoneCallOutgoingEarlyMedia,1,2000) );
jehan's avatar
jehan committed
158

159 160 161 162
		if (linphone_core_inc_invite_pending(pauline2->lc)) {
				/* send a 183 to initiate the early media */
				if (video) {
					/*check video path*/
Simon Morlat's avatar
Simon Morlat committed
163
					liblinphone_tester_set_next_video_frame_decoded_cb(linphone_core_get_current_call(pauline2->lc));
164
				}
165
				linphone_call_accept_early_media(linphone_core_get_current_call(pauline2->lc));
166

167
				BC_ASSERT_TRUE( wait_for_list(lcs, &pauline2->stat.number_of_LinphoneCallIncomingEarlyMedia,1,2000) );
168 169
		}

jehan's avatar
jehan committed
170 171
		wait_for_list(lcs, &dummy, 1, 3000);

172
		stats = linphone_call_get_audio_stats(linphone_core_get_current_call(pauline->lc));
173
		BC_ASSERT_GREATER(linphone_core_manager_get_max_audio_down_bw(pauline),70,int,"%i");
174 175
		BC_ASSERT_LOWER((int)linphone_call_stats_get_download_bandwidth(stats), 90, int, "%i");
		linphone_call_stats_unref(stats);
176

177
		stats = linphone_call_get_audio_stats(linphone_core_get_current_call(pauline2->lc));
178
		BC_ASSERT_GREATER(linphone_core_manager_get_max_audio_down_bw(pauline2),70,int,"%i");
179 180
		BC_ASSERT_LOWER((int)linphone_call_stats_get_download_bandwidth(stats),90, int, "%i");
		linphone_call_stats_unref(stats);
181

182 183
		BC_ASSERT_TRUE(linphone_call_params_audio_multicast_enabled(linphone_call_get_current_params(linphone_core_get_current_call(pauline->lc))));
		BC_ASSERT_TRUE(linphone_call_params_audio_multicast_enabled(linphone_call_get_current_params(linphone_core_get_current_call(marie->lc))));
184
		if (video) {
185 186
			BC_ASSERT_TRUE(linphone_call_params_video_multicast_enabled(linphone_call_get_current_params(linphone_core_get_current_call(pauline->lc))));
			BC_ASSERT_TRUE(linphone_call_params_video_multicast_enabled(linphone_call_get_current_params(linphone_core_get_current_call(marie->lc))));
187
		}
jehan's avatar
jehan committed
188 189

		if (video) {
190 191
			BC_ASSERT_TRUE( wait_for_list(lcs,&pauline->stat.number_of_IframeDecoded,1,2000));
			BC_ASSERT_TRUE( wait_for_list(lcs,&pauline2->stat.number_of_IframeDecoded,1,2000));
jehan's avatar
jehan committed
192 193
		}

194
		linphone_call_accept(linphone_core_get_current_call(pauline->lc));
jehan's avatar
jehan committed
195

196 197 198
		BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallConnected, 1,1000));
		BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallStreamsRunning, 1,1000));
		BC_ASSERT_TRUE(wait_for_list(lcs, &pauline2->stat.number_of_LinphoneCallEnd, 1,1000));
199

200 201
		BC_ASSERT_TRUE(linphone_call_params_audio_multicast_enabled(linphone_call_get_current_params(linphone_core_get_current_call(pauline->lc))));
		BC_ASSERT_TRUE(linphone_call_params_audio_multicast_enabled(linphone_call_get_current_params(linphone_core_get_current_call(marie->lc))));
202
		if (video) {
203 204
			BC_ASSERT_TRUE(linphone_call_params_video_multicast_enabled(linphone_call_get_current_params(linphone_core_get_current_call(pauline->lc))));
			BC_ASSERT_TRUE(linphone_call_params_video_multicast_enabled(linphone_call_get_current_params(linphone_core_get_current_call(marie->lc))));
205
		}
206
		params = linphone_core_create_call_params(pauline->lc, linphone_core_get_current_call(pauline->lc));
207 208 209 210 211 212 213

		linphone_call_params_enable_audio_multicast(params,FALSE);
		linphone_call_params_enable_video_multicast(params,FALSE);
		linphone_core_enable_video_capture(pauline->lc, TRUE);
		linphone_core_enable_video_display(pauline->lc, TRUE);
		linphone_core_enable_video_capture(marie->lc, TRUE);
		linphone_core_enable_video_display(marie->lc, TRUE);
jehan's avatar
jehan committed
214

215
		linphone_call_update(linphone_core_get_current_call(pauline->lc), params);
Simon Morlat's avatar
Simon Morlat committed
216
		linphone_call_params_unref(params);
217

218
		BC_ASSERT_TRUE(wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallStreamsRunning, 2,1000));
219

220 221
		BC_ASSERT_FALSE(linphone_call_params_audio_multicast_enabled(linphone_call_get_current_params(linphone_core_get_current_call(pauline->lc))));
		BC_ASSERT_FALSE(linphone_call_params_audio_multicast_enabled(linphone_call_get_current_params(linphone_core_get_current_call(marie->lc))));
222

223 224 225 226 227 228 229 230 231 232 233 234
		check_media_direction(	pauline
								, linphone_core_get_current_call(pauline->lc)
								, lcs
								,LinphoneMediaDirectionSendRecv
								, video?LinphoneMediaDirectionSendRecv:LinphoneMediaDirectionInactive);
		check_media_direction(	marie
								, linphone_core_get_current_call(marie->lc)
								, lcs
								,LinphoneMediaDirectionSendRecv
								, video?LinphoneMediaDirectionSendRecv:LinphoneMediaDirectionInactive);

		if (video) {
235 236
			BC_ASSERT_FALSE(linphone_call_params_video_multicast_enabled(linphone_call_get_current_params(linphone_core_get_current_call(marie->lc))));
			BC_ASSERT_FALSE(linphone_call_params_video_multicast_enabled(linphone_call_get_current_params(linphone_core_get_current_call(pauline->lc))));
237
		}
jehan's avatar
jehan committed
238 239 240 241 242
		end_call(marie,pauline);
	}
	ms_free(lcs);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
243
	linphone_core_manager_destroy(pauline2);
jehan's avatar
jehan committed
244 245
}

246
static void early_media_with_multicast_audio(void) {
jehan's avatar
jehan committed
247 248
	early_media_with_multicast_base(FALSE);
}
249
static void unicast_incoming_with_multicast_audio_on(void) {
jehan's avatar
jehan committed
250 251 252
	simple_call_base(TRUE);
}
#ifdef VIDEO_ENABLED
253
static void early_media_with_multicast_video(void) {
jehan's avatar
jehan committed
254 255 256 257 258
	early_media_with_multicast_base(TRUE);
}
#endif

test_t multicast_call_tests[] = {
259 260 261 262
	TEST_NO_TAG("Multicast audio call",call_multicast),
	TEST_NO_TAG("Multicast call with pause/resume",multicast_audio_with_pause_resume),
	TEST_NO_TAG("Early media multicast audio call",early_media_with_multicast_audio),
	TEST_NO_TAG("Unicast incoming call with multicast activated",unicast_incoming_with_multicast_audio_on),
jehan's avatar
jehan committed
263
#ifdef VIDEO_ENABLED
264 265
	TEST_NO_TAG("Multicast video call",call_multicast_video),
	TEST_NO_TAG("Early media multicast video call",early_media_with_multicast_video),
jehan's avatar
jehan committed
266 267 268
#endif
};

269
test_suite_t multicast_call_test_suite = {"Multicast Call", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
270 271
										  sizeof(multicast_call_tests) / sizeof(multicast_call_tests[0]),
										  multicast_call_tests};