FreeCalypso > hg > themwi-system-sw
comparison sip-manual-out/main.c @ 192:f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 17 Mar 2023 13:45:31 -0800 |
parents | 258932879f8b |
children | eac3e0b6ce02 |
comparison
equal
deleted
inserted
replaced
191:6ac96217c442 | 192:f8a33603288f |
---|---|
20 extern struct in_addr sip_bind_ip, sip_dest_ip; | 20 extern struct in_addr sip_bind_ip, sip_dest_ip; |
21 extern unsigned sip_bind_port, sip_dest_port; | 21 extern unsigned sip_bind_port, sip_dest_port; |
22 extern char sip_dest_domain[]; | 22 extern char sip_dest_domain[]; |
23 extern struct sockaddr_in rtp_local_addr; | 23 extern struct sockaddr_in rtp_local_addr; |
24 extern int rtp_udp_fd, rtcp_udp_fd; | 24 extern int rtp_udp_fd, rtcp_udp_fd; |
25 extern int rtp_out_enable; | |
25 | 26 |
26 struct sockaddr_in sip_dest_sin; | 27 struct sockaddr_in sip_dest_sin; |
27 char from_uri[128], to_uri[128], call_id[128]; | 28 char from_uri[128], to_uri[128], call_id[128]; |
28 struct timeval cur_event_time; | 29 struct timeval cur_event_time; |
29 unsigned max_forwards = 70; | 30 unsigned max_forwards = 70; |
128 | 129 |
129 main(argc, argv) | 130 main(argc, argv) |
130 char **argv; | 131 char **argv; |
131 { | 132 { |
132 fd_set fds; | 133 fd_set fds; |
133 int rc, max_fd; | 134 struct timeval next_rtp_out, timeout; |
135 int rc, max_fd, rtp_out_running; | |
134 | 136 |
135 preliminary_proc(argc, argv); | 137 preliminary_proc(argc, argv); |
136 gettimeofday(&cur_event_time, 0); | 138 gettimeofday(&cur_event_time, 0); |
137 sprintf(call_id, "%08u_%u@%s", | 139 sprintf(call_id, "%08u_%u@%s", |
138 (unsigned)(cur_event_time.tv_sec % 100000000), | 140 (unsigned)(cur_event_time.tv_sec % 100000000), |
142 max_fd = sip_socket; | 144 max_fd = sip_socket; |
143 if (rtp_udp_fd > max_fd) | 145 if (rtp_udp_fd > max_fd) |
144 max_fd = rtp_udp_fd; | 146 max_fd = rtp_udp_fd; |
145 if (rtcp_udp_fd > max_fd) | 147 if (rtcp_udp_fd > max_fd) |
146 max_fd = rtcp_udp_fd; | 148 max_fd = rtcp_udp_fd; |
149 rtp_out_running = 0; | |
147 for (;;) { | 150 for (;;) { |
148 FD_ZERO(&fds); | 151 FD_ZERO(&fds); |
149 FD_SET(0, &fds); | 152 FD_SET(0, &fds); |
150 FD_SET(sip_socket, &fds); | 153 FD_SET(sip_socket, &fds); |
151 FD_SET(rtp_udp_fd, &fds); | 154 FD_SET(rtp_udp_fd, &fds); |
152 FD_SET(rtcp_udp_fd, &fds); | 155 FD_SET(rtcp_udp_fd, &fds); |
153 rc = select(max_fd+1, &fds, 0, 0, 0); | 156 if (rtp_out_enable) { |
157 if (!rtp_out_running) { | |
158 printf("Starting RTP output\n"); | |
159 bcopy(&cur_event_time, &next_rtp_out, | |
160 sizeof(struct timeval)); | |
161 rtp_out_running = 1; | |
162 } else { | |
163 next_rtp_out.tv_usec += 20000; | |
164 if (next_rtp_out.tv_usec >= 1000000) { | |
165 next_rtp_out.tv_sec++; | |
166 next_rtp_out.tv_usec -= 1000000; | |
167 } | |
168 } | |
169 if (timercmp(&cur_event_time, &next_rtp_out, <)) | |
170 timersub(&next_rtp_out, &cur_event_time, | |
171 &timeout); | |
172 else | |
173 timerclear(&timeout); | |
174 rc = select(max_fd+1, &fds, 0, 0, &timeout); | |
175 } else { | |
176 if (rtp_out_running) { | |
177 printf("Stopping RTP output\n"); | |
178 rtp_out_running = 0; | |
179 } | |
180 rc = select(max_fd+1, &fds, 0, 0, 0); | |
181 } | |
154 if (rc < 0) { | 182 if (rc < 0) { |
155 if (errno == EINTR) | 183 if (errno == EINTR) |
156 continue; | 184 continue; |
157 perror("select"); | 185 perror("select"); |
158 exit(1); | 186 exit(1); |
164 sip_socket_select(); | 192 sip_socket_select(); |
165 if (FD_ISSET(rtp_udp_fd, &fds)) | 193 if (FD_ISSET(rtp_udp_fd, &fds)) |
166 rtp_rx_select(); | 194 rtp_rx_select(); |
167 if (FD_ISSET(rtcp_udp_fd, &fds)) | 195 if (FD_ISSET(rtcp_udp_fd, &fds)) |
168 rtcp_rx_select(); | 196 rtcp_rx_select(); |
197 if (rtp_out_running && (rc == 0)) | |
198 generate_rtp_packet(); | |
169 } | 199 } |
170 } | 200 } |