annotate mtctest/main.c @ 11:aa2ba9b432af

mtctest: implement play and play-stop commands
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 09 Jun 2024 04:32:57 +0000
parents 395c56969bc4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Main module for ThemWi test MT call generator.
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/time.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/errno.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
10
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
11 #include <string.h>
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
12 #include <strings.h>
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <syslog.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <unistd.h>
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
15 #include <themwi/rtp/rtp_alloc_simple.h>
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern int mtc_socket;
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
18 extern struct rtp_alloc_simple rtp_info;
10
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
19 extern int rtp_play_active;
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 struct timeval cur_event_time;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 main(argc, argv)
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 char **argv;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 extern int optind;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 extern char *optarg;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 char *from;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 fd_set fds;
10
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
30 struct timeval next_rtp_out, timeout;
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
31 int c, max_fd, rtp_out_running;
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 from = 0;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 while ((c = getopt(argc, argv, "f:")) != EOF) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 switch (c) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 case 'f':
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 from = optarg;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 continue;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 default:
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 usage:
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 fprintf(stderr,
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 "usage: %s [-f from-number] to-number\n",
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 argv[0]);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 exit(1);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (argc != optind + 1)
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 goto usage;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 openlog("themwi-test-mtc", 0, LOG_LOCAL5);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 init_setup_msg(from, argv[optind]);
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
51 obtain_rtp_endp();
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 connect_mtc_socket();
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 send_setup_msg();
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 /* main select loop */
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
55 max_fd = mtc_socket;
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
56 if (rtp_info.gsm_rtp_fd > mtc_socket)
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
57 max_fd = rtp_info.gsm_rtp_fd;
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
58 if (rtp_info.gsm_rtcp_fd > mtc_socket)
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
59 max_fd = rtp_info.gsm_rtcp_fd;
10
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
60 rtp_out_running = 0;
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 for (;;) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 FD_ZERO(&fds);
8
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
63 FD_SET(0, &fds);
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 FD_SET(mtc_socket, &fds);
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
65 FD_SET(rtp_info.gsm_rtp_fd, &fds);
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
66 FD_SET(rtp_info.gsm_rtcp_fd, &fds);
10
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
67 if (rtp_play_active) {
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
68 if (!rtp_out_running) {
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
69 printf("Starting RTP output\n");
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
70 bcopy(&cur_event_time, &next_rtp_out,
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
71 sizeof(struct timeval));
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
72 rtp_out_running = 1;
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
73 }
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
74 if (timercmp(&cur_event_time, &next_rtp_out, <))
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
75 timersub(&next_rtp_out, &cur_event_time,
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
76 &timeout);
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
77 else
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
78 timerclear(&timeout);
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
79 c = select(max_fd+1, &fds, 0, 0, &timeout);
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
80 } else {
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
81 if (rtp_out_running) {
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
82 printf("Stopping RTP output\n");
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
83 rtp_out_running = 0;
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
84 }
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
85 c = select(max_fd+1, &fds, 0, 0, 0);
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
86 }
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (c < 0) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (errno == EINTR)
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 continue;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 perror("select");
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 exit(1);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 gettimeofday(&cur_event_time, 0);
8
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
94 if (FD_ISSET(0, &fds))
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
95 select_stdin();
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (FD_ISSET(mtc_socket, &fds))
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 mtc_socket_select();
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
98 if (FD_ISSET(rtp_info.gsm_rtp_fd, &fds))
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
99 rtp_rx_select();
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
100 if (FD_ISSET(rtp_info.gsm_rtcp_fd, &fds))
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
101 rtcp_rx_select();
10
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
102 if (rtp_out_running && (c == 0)) {
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
103 generate_rtp_packet();
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
104 next_rtp_out.tv_usec += 20000;
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
105 if (next_rtp_out.tv_usec >= 1000000) {
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
106 next_rtp_out.tv_sec++;
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
107 next_rtp_out.tv_usec -= 1000000;
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
108 }
395c56969bc4 mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
109 }
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 }
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }