call_multicast_tester.c 11.8 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"
21
#include "linphone/core.h"
jehan's avatar
jehan committed
22 23
#include "belle-sip/belle-sip.h"

24

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

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

	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);

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

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

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

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

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

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

		// 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");
		}

111 112 113
		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);
114

115 116 117
		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
118 119 120 121 122 123 124 125

		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);
126
		linphone_core_set_video_policy(pauline2->lc,&pauline_policy);
jehan's avatar
jehan committed
127 128 129 130 131 132 133
		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);


134 135 136
	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
137 138 139 140
	/*
		Marie calls Pauline, and after the call has rung, transitions to an early_media session
	*/

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

143 144
	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
145 146 147 148 149 150


	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
151
			linphone_call_set_next_video_frame_decoded_callback(linphone_core_get_current_call(pauline->lc),linphone_call_iframe_decoded_cb,pauline->lc);
jehan's avatar
jehan committed
152
		}
153
		linphone_call_accept_early_media(linphone_core_get_current_call(pauline->lc));
jehan's avatar
jehan committed
154

155 156
		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
157

158 159 160 161
		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
162
					linphone_call_set_next_video_frame_decoded_callback(linphone_core_get_current_call(pauline2->lc),linphone_call_iframe_decoded_cb,pauline2->lc);
163
				}
164
				linphone_call_accept_early_media(linphone_core_get_current_call(pauline2->lc));
165

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

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

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

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

181 182
		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))));
183
		if (video) {
184 185
			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))));
186
		}
jehan's avatar
jehan committed
187 188

		if (video) {
189 190
			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
191 192
		}

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

195 196 197
		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));
198

199 200
		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))));
201
		if (video) {
202 203
			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))));
204
		}
205
		params = linphone_core_create_call_params(pauline->lc, linphone_core_get_current_call(pauline->lc));
206 207 208 209 210 211 212

		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
213

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

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

219 220
		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))));
221

222 223 224 225 226 227 228 229 230 231 232 233
		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) {
234 235
			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))));
236
		}
jehan's avatar
jehan committed
237 238 239 240 241
		end_call(marie,pauline);
	}
	ms_free(lcs);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
242
	linphone_core_manager_destroy(pauline2);
jehan's avatar
jehan committed
243 244
}

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

test_t multicast_call_tests[] = {
258 259 260 261
	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
262
#ifdef VIDEO_ENABLED
263 264
	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
265 266 267
#endif
};

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