test_ecc.c 2.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
linphone
Copyright (C) 2011 Belledonne Communications SARL
Author: Simon MORLAT (simon.morlat@linphone.org)

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, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 20
*/

21 22
#include "linphone/core.h"
#include "linphone/core_utils.h"
23 24 25
#if _MSC_VER
#include <io.h>
#endif
26
static int done = 0;
27

28 29 30 31
static void calibration_finished(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay, void *data) {
	ms_message("echo calibration finished %s.", status == LinphoneEcCalibratorDone ? "successfully" : "with faillure");
	if (status == LinphoneEcCalibratorDone)
		ms_message("Measured delay is %i", delay);
32
	done = 1;
33 34
}

35
static char config_file[1024] = {0};
36
void parse_args(int argc, char *argv[]) {
37 38 39
#ifndef F_OK
#define F_OK 4
#endif
40
	if (argc != 3 || strncmp("-c", argv[1], 2) || access(argv[2], F_OK) != 0) {
41 42 43
		printf("Usage: test_ecc [-c config_file] where config_file will be written with the detected value\n");
		exit(-1);
	}
44
	strncpy(config_file, argv[2], 1024);
45
	config_file[sizeof(config_file) - 1] = '\0';
46 47
}

48 49
int main(int argc, char *argv[]) {
	LinphoneCoreVTable vtable = {0};
50
	LinphoneCore *lc;
51 52
	if (argc > 1)
		parse_args(argc, argv);
53
	lc = linphone_core_new(&vtable, config_file[0] ?  config_file  : NULL, NULL, NULL);
54

55 56
	linphone_core_enable_logs(NULL);

57 58
	linphone_core_start_echo_calibration(lc, calibration_finished, NULL, NULL, NULL);

59
	while (!done) {
60
		linphone_core_iterate(lc);
61
		ms_usleep(20000);
62 63 64 65
	}
	linphone_core_destroy(lc);
	return 0;
}