multicast_call_tester.c 11.3 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 29 30 31 32
	int begin;
	int leaked_objects;
	LinphoneVideoPolicy marie_policy, pauline_policy;

	belle_sip_object_enable_leak_detector(TRUE);
	begin=belle_sip_object_get_object_count();
33
	marie = linphone_core_manager_new( "marie_rc");
34
	pauline = linphone_core_manager_new( "pauline_tcp_rc");
jehan's avatar
jehan committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

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

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

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

	leaked_objects=belle_sip_object_get_object_count()-begin;
72
	BC_ASSERT_EQUAL(leaked_objects, 0, int, "%d");
jehan's avatar
jehan committed
73 74 75
	if (leaked_objects>0){
		belle_sip_object_dump_active_objects();
	}
76
	belle_sip_object_enable_leak_detector(FALSE);
jehan's avatar
jehan committed
77 78

}
79

jehan's avatar
jehan committed
80 81 82 83 84 85 86 87 88 89 90 91
static void call_multicast(void)  {
	call_multicast_base(FALSE);
}
static void multicast_audio_with_pause_resume() {
	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) {
92
	LinphoneCoreManager *marie, *pauline, *pauline2;
jehan's avatar
jehan committed
93 94 95 96 97
	MSList* lcs = NULL;
	int dummy=0;
	int leaked_objects;
	int begin;
	LinphoneVideoPolicy marie_policy, pauline_policy;
98
	LpConfig *marie_lp;
99
	LinphoneCallParams *params;
jehan's avatar
jehan committed
100 101 102

	belle_sip_object_enable_leak_detector(TRUE);
	begin=belle_sip_object_get_object_count();
103
	marie   = linphone_core_manager_new("marie_rc");
104 105
	pauline = linphone_core_manager_new("pauline_tcp_rc");
	pauline2 = linphone_core_manager_new("pauline_tcp_rc");
106 107 108

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

	if (video) {
111
		linphone_core_enable_video_capture(pauline->lc, FALSE);
jehan's avatar
jehan committed
112
		linphone_core_enable_video_display(pauline->lc, TRUE);
113 114
		linphone_core_enable_video_capture(pauline2->lc, FALSE);
		linphone_core_enable_video_display(pauline2->lc, TRUE);
jehan's avatar
jehan committed
115 116 117 118 119 120 121 122 123 124
		linphone_core_enable_video_capture(marie->lc, TRUE);
		linphone_core_enable_video_display(marie->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);
125
		linphone_core_set_video_policy(pauline2->lc,&pauline_policy);
jehan's avatar
jehan committed
126 127 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);


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

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

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


	if (linphone_core_inc_invite_pending(pauline->lc)) {
		/* send a 183 to initiate the early media */
		if (video) {
			/*check video path*/
			linphone_call_set_next_video_frame_decoded_callback(linphone_core_get_current_call(pauline->lc),linphone_call_cb,pauline->lc);
		}
		linphone_core_accept_early_media(pauline->lc, linphone_core_get_current_call(pauline->lc));

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

157 158 159 160 161 162 163 164
		if (linphone_core_inc_invite_pending(pauline2->lc)) {
				/* send a 183 to initiate the early media */
				if (video) {
					/*check video path*/
					linphone_call_set_next_video_frame_decoded_callback(linphone_core_get_current_call(pauline2->lc),linphone_call_cb,pauline2->lc);
				}
				linphone_core_accept_early_media(pauline2->lc, linphone_core_get_current_call(pauline2->lc));

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

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

170
		BC_ASSERT_GREATER(linphone_core_manager_get_max_audio_down_bw(pauline),70,int,"%i");
171
		BC_ASSERT_TRUE(linphone_call_get_audio_stats(linphone_core_get_current_call(pauline->lc))->download_bandwidth<90);
172

173
		BC_ASSERT_GREATER(linphone_core_manager_get_max_audio_down_bw(pauline2),70,int,"%i");
174
		BC_ASSERT_TRUE(linphone_call_get_audio_stats(linphone_core_get_current_call(pauline2->lc))->download_bandwidth<90);
175

176 177
		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))));
178
		if (video) {
179 180
			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))));
181
		}
jehan's avatar
jehan committed
182 183

		if (video) {
184 185
			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
186 187 188 189
		}

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

190 191 192
		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));
193

194 195
		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))));
196
		if (video) {
197 198
			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))));
199 200 201 202 203 204 205 206 207
		}
		params=linphone_call_params_copy(linphone_call_get_current_params(linphone_core_get_current_call(pauline->lc)));

		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
208

209 210
		linphone_core_update_call(	pauline->lc
									, linphone_core_get_current_call(pauline->lc)
211 212 213
									, params);
		linphone_call_params_destroy(params);

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

216 217
		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))));
218

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

	leaked_objects=belle_sip_object_get_object_count()-begin;
242
	BC_ASSERT_EQUAL(leaked_objects,0, int, "%d");
243
	if (leaked_objects>0){
jehan's avatar
jehan committed
244 245
		belle_sip_object_dump_active_objects();
	}
246
	belle_sip_object_enable_leak_detector(FALSE);
jehan's avatar
jehan committed
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
}

static void early_media_with_multicast_audio() {
	early_media_with_multicast_base(FALSE);
}
static void unicast_incoming_with_multicast_audio_on() {
	simple_call_base(TRUE);
}
#ifdef VIDEO_ENABLED
static void early_media_with_multicast_video() {
	early_media_with_multicast_base(TRUE);
}
#endif

test_t multicast_call_tests[] = {
	{ "Multicast audio call",call_multicast},
	{ "Multicast call with pause/resume",multicast_audio_with_pause_resume},
	{ "Early media multicast audio call",early_media_with_multicast_audio},
	{ "Unicast incoming call with multicast activated",unicast_incoming_with_multicast_audio_on},
#ifdef VIDEO_ENABLED
	{ "Multicast video call",call_multicast_video},
	{ "Early media multicast video call",early_media_with_multicast_video},
#endif
};

test_suite_t multicast_call_test_suite = {
	"Multicast Call",
274
	liblinphone_tester_setup,
jehan's avatar
jehan committed
275 276 277 278
	NULL,
	sizeof(multicast_call_tests) / sizeof(multicast_call_tests[0]),
	multicast_call_tests
};