multicast_call_tester.c 11.2 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 21 22 23
/*
	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"
#include "linphonecore.h"
#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) {
jehan's avatar
jehan committed
72 73 74 75 76 77 78 79
	call_paused_resumed_base(TRUE);
}
#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;
jehan's avatar
jehan committed
81 82 83
	MSList* lcs = NULL;
	int dummy=0;
	LinphoneVideoPolicy marie_policy, pauline_policy;
84
	LpConfig *marie_lp;
85
	LinphoneCallParams *params;
jehan's avatar
jehan committed
86

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

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

	if (video) {
95
		linphone_core_enable_video_capture(pauline->lc, FALSE);
jehan's avatar
jehan committed
96
		linphone_core_enable_video_display(pauline->lc, TRUE);
97 98
		linphone_core_enable_video_capture(pauline2->lc, FALSE);
		linphone_core_enable_video_display(pauline2->lc, TRUE);
jehan's avatar
jehan committed
99 100
		linphone_core_enable_video_capture(marie->lc, TRUE);
		linphone_core_enable_video_display(marie->lc, FALSE);
101 102 103 104 105 106 107 108
		
		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);
		
		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
109 110 111 112 113 114 115 116

		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);
117
		linphone_core_set_video_policy(pauline2->lc,&pauline_policy);
jehan's avatar
jehan committed
118 119 120 121 122 123 124 125 126
		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);


	lcs = ms_list_append(lcs,marie->lc);
	lcs = ms_list_append(lcs,pauline->lc);
127
	lcs = ms_list_append(lcs,pauline2->lc);
jehan's avatar
jehan committed
128 129 130 131
	/*
		Marie calls Pauline, and after the call has rung, transitions to an early_media session
	*/

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

134 135
	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
136 137 138 139 140 141


	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
142
			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
143 144 145
		}
		linphone_core_accept_early_media(pauline->lc, linphone_core_get_current_call(pauline->lc));

146 147
		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
148

149 150 151 152
		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
153
					linphone_call_set_next_video_frame_decoded_callback(linphone_core_get_current_call(pauline2->lc),linphone_call_iframe_decoded_cb,pauline2->lc);
154 155 156
				}
				linphone_core_accept_early_media(pauline2->lc, linphone_core_get_current_call(pauline2->lc));

157
				BC_ASSERT_TRUE( wait_for_list(lcs, &pauline2->stat.number_of_LinphoneCallIncomingEarlyMedia,1,2000) );
158 159
		}

jehan's avatar
jehan committed
160 161
		wait_for_list(lcs, &dummy, 1, 3000);

162
		BC_ASSERT_GREATER(linphone_core_manager_get_max_audio_down_bw(pauline),70,int,"%i");
163
		BC_ASSERT_TRUE(linphone_call_get_audio_stats(linphone_core_get_current_call(pauline->lc))->download_bandwidth<90);
164

165
		BC_ASSERT_GREATER(linphone_core_manager_get_max_audio_down_bw(pauline2),70,int,"%i");
166
		BC_ASSERT_TRUE(linphone_call_get_audio_stats(linphone_core_get_current_call(pauline2->lc))->download_bandwidth<90);
167

168 169
		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))));
170
		if (video) {
171 172
			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))));
173
		}
jehan's avatar
jehan committed
174 175

		if (video) {
176 177
			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
178 179 180 181
		}

		linphone_core_accept_call(pauline->lc, linphone_core_get_current_call(pauline->lc));

182 183 184
		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));
185

186 187
		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))));
188
		if (video) {
189 190
			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))));
191
		}
192
		params = linphone_core_create_call_params(pauline->lc, linphone_core_get_current_call(pauline->lc));
193 194 195 196 197 198 199

		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
200

201 202
		linphone_core_update_call(	pauline->lc
									, linphone_core_get_current_call(pauline->lc)
203 204 205
									, params);
		linphone_call_params_destroy(params);

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

208 209
		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))));
210

211 212 213 214 215 216 217 218 219 220 221 222
		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) {
223 224
			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))));
225
		}
jehan's avatar
jehan committed
226 227 228 229 230
		end_call(marie,pauline);
	}
	ms_free(lcs);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
231
	linphone_core_manager_destroy(pauline2);
jehan's avatar
jehan committed
232 233
}

234
static void early_media_with_multicast_audio(void) {
jehan's avatar
jehan committed
235 236
	early_media_with_multicast_base(FALSE);
}
237
static void unicast_incoming_with_multicast_audio_on(void) {
jehan's avatar
jehan committed
238 239 240
	simple_call_base(TRUE);
}
#ifdef VIDEO_ENABLED
241
static void early_media_with_multicast_video(void) {
jehan's avatar
jehan committed
242 243 244 245 246
	early_media_with_multicast_base(TRUE);
}
#endif

test_t multicast_call_tests[] = {
247 248 249 250
	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
251
#ifdef VIDEO_ENABLED
252 253
	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
254 255 256
#endif
};

257
test_suite_t multicast_call_test_suite = {"Multicast Call", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
258 259
										  sizeof(multicast_call_tests) / sizeof(multicast_call_tests[0]),
										  multicast_call_tests};