FreeCalypso > hg > themwi-interim
annotate mtctest/main.c @ 14:44c1d4d787e9 default tip
themwi-test-mtc: add option to set bearer cap
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 28 Nov 2024 20:37:23 +0000 |
parents | 395c56969bc4 |
children |
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; |
14
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
28 char *from, *bc_extra; |
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
29 int include_bc; |
5
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 fd_set fds; |
10
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
31 struct timeval next_rtp_out, timeout; |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
32 int c, max_fd, rtp_out_running; |
5
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 from = 0; |
14
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
35 include_bc = 0; |
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
36 bc_extra = 0; |
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
37 while ((c = getopt(argc, argv, "f:sS:")) != EOF) { |
5
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 switch (c) { |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 case 'f': |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 from = optarg; |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 continue; |
14
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
42 case 's': |
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
43 include_bc = 1; |
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
44 continue; |
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
45 case 'S': |
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
46 include_bc = 1; |
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
47 bc_extra = optarg; |
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
48 continue; |
5
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 default: |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 usage: |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 fprintf(stderr, |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 "usage: %s [-f from-number] to-number\n", |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 argv[0]); |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 exit(1); |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (argc != optind + 1) |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 goto usage; |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 openlog("themwi-test-mtc", 0, LOG_LOCAL5); |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 init_setup_msg(from, argv[optind]); |
14
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
61 if (include_bc) |
44c1d4d787e9
themwi-test-mtc: add option to set bearer cap
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
62 set_bearer_cap(bc_extra); |
6
33d8b3177540
mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
63 obtain_rtp_endp(); |
5
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 connect_mtc_socket(); |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 send_setup_msg(); |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 /* main select loop */ |
6
33d8b3177540
mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
67 max_fd = mtc_socket; |
33d8b3177540
mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
68 if (rtp_info.gsm_rtp_fd > mtc_socket) |
33d8b3177540
mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
69 max_fd = rtp_info.gsm_rtp_fd; |
33d8b3177540
mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
70 if (rtp_info.gsm_rtcp_fd > mtc_socket) |
33d8b3177540
mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
71 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
|
72 rtp_out_running = 0; |
5
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 for (;;) { |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 FD_ZERO(&fds); |
8
a902ccbf6bbc
mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
75 FD_SET(0, &fds); |
5
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 FD_SET(mtc_socket, &fds); |
6
33d8b3177540
mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
77 FD_SET(rtp_info.gsm_rtp_fd, &fds); |
33d8b3177540
mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
78 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
|
79 if (rtp_play_active) { |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
80 if (!rtp_out_running) { |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
81 printf("Starting RTP output\n"); |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
82 bcopy(&cur_event_time, &next_rtp_out, |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
83 sizeof(struct timeval)); |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
84 rtp_out_running = 1; |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
85 } |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
86 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
|
87 timersub(&next_rtp_out, &cur_event_time, |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
88 &timeout); |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
89 else |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
90 timerclear(&timeout); |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
91 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
|
92 } else { |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
93 if (rtp_out_running) { |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
94 printf("Stopping RTP output\n"); |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
95 rtp_out_running = 0; |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
96 } |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
97 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
|
98 } |
5
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 if (c < 0) { |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 if (errno == EINTR) |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 continue; |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 perror("select"); |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 exit(1); |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 } |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 gettimeofday(&cur_event_time, 0); |
8
a902ccbf6bbc
mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
106 if (FD_ISSET(0, &fds)) |
a902ccbf6bbc
mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
107 select_stdin(); |
5
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 if (FD_ISSET(mtc_socket, &fds)) |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 mtc_socket_select(); |
6
33d8b3177540
mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
110 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
|
111 rtp_rx_select(); |
33d8b3177540
mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
112 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
|
113 rtcp_rx_select(); |
10
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
114 if (rtp_out_running && (c == 0)) { |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
115 generate_rtp_packet(); |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
116 next_rtp_out.tv_usec += 20000; |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
117 if (next_rtp_out.tv_usec >= 1000000) { |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
118 next_rtp_out.tv_sec++; |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
119 next_rtp_out.tv_usec -= 1000000; |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
120 } |
395c56969bc4
mtctest: implement guts of RTP play mechanism
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
121 } |
5
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 } |
e7b192a5dee5
mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 } |