view mtctest/main.c @ 9:0ec938ed530b

mtctest: capture MSC RTP info for play command
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 09 Jun 2024 03:37:44 +0000
parents a902ccbf6bbc
children 395c56969bc4
line wrap: on
line source

/*
 * Main module for ThemWi test MT call generator.
 */

#include <sys/types.h>
#include <sys/time.h>
#include <sys/errno.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <syslog.h>
#include <unistd.h>
#include <themwi/rtp/rtp_alloc_simple.h>

extern int mtc_socket;
extern struct rtp_alloc_simple rtp_info;

struct timeval cur_event_time;

main(argc, argv)
	char **argv;
{
	extern int optind;
	extern char *optarg;
	char *from;
	fd_set fds;
	int c, max_fd;

	from = 0;
	while ((c = getopt(argc, argv, "f:")) != EOF) {
		switch (c) {
		case 'f':
			from = optarg;
			continue;
		default:
		usage:
			fprintf(stderr,
				"usage: %s [-f from-number] to-number\n",
				argv[0]);
			exit(1);
		}
	}
	if (argc != optind + 1)
		goto usage;
	openlog("themwi-test-mtc", 0, LOG_LOCAL5);
	init_setup_msg(from, argv[optind]);
	obtain_rtp_endp();
	connect_mtc_socket();
	send_setup_msg();
	/* main select loop */
	max_fd = mtc_socket;
	if (rtp_info.gsm_rtp_fd > mtc_socket)
		max_fd = rtp_info.gsm_rtp_fd;
	if (rtp_info.gsm_rtcp_fd > mtc_socket)
		max_fd = rtp_info.gsm_rtcp_fd;
	for (;;) {
		FD_ZERO(&fds);
		FD_SET(0, &fds);
		FD_SET(mtc_socket, &fds);
		FD_SET(rtp_info.gsm_rtp_fd, &fds);
		FD_SET(rtp_info.gsm_rtcp_fd, &fds);
		c = select(max_fd+1, &fds, 0, 0, 0);
		if (c < 0) {
			if (errno == EINTR)
				continue;
			perror("select");
			exit(1);
		}
		gettimeofday(&cur_event_time, 0);
		if (FD_ISSET(0, &fds))
			select_stdin();
		if (FD_ISSET(mtc_socket, &fds))
			mtc_socket_select();
		if (FD_ISSET(rtp_info.gsm_rtp_fd, &fds))
			rtp_rx_select();
		if (FD_ISSET(rtp_info.gsm_rtcp_fd, &fds))
			rtcp_rx_select();
	}
}