diff 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
line wrap: on
line diff
--- a/sip-manual-out/main.c	Fri Mar 17 12:07:17 2023 -0800
+++ b/sip-manual-out/main.c	Fri Mar 17 13:45:31 2023 -0800
@@ -22,6 +22,7 @@
 extern char sip_dest_domain[];
 extern struct sockaddr_in rtp_local_addr;
 extern int rtp_udp_fd, rtcp_udp_fd;
+extern int rtp_out_enable;
 
 struct sockaddr_in sip_dest_sin;
 char from_uri[128], to_uri[128], call_id[128];
@@ -130,7 +131,8 @@
 	char **argv;
 {
 	fd_set fds;
-	int rc, max_fd;
+	struct timeval next_rtp_out, timeout;
+	int rc, max_fd, rtp_out_running;
 
 	preliminary_proc(argc, argv);
 	gettimeofday(&cur_event_time, 0);
@@ -144,13 +146,39 @@
 		max_fd = rtp_udp_fd;
 	if (rtcp_udp_fd > max_fd)
 		max_fd = rtcp_udp_fd;
+	rtp_out_running = 0;
 	for (;;) {
 		FD_ZERO(&fds);
 		FD_SET(0, &fds);
 		FD_SET(sip_socket, &fds);
 		FD_SET(rtp_udp_fd, &fds);
 		FD_SET(rtcp_udp_fd, &fds);
-		rc = select(max_fd+1, &fds, 0, 0, 0);
+		if (rtp_out_enable) {
+			if (!rtp_out_running) {
+				printf("Starting RTP output\n");
+				bcopy(&cur_event_time, &next_rtp_out,
+					sizeof(struct timeval));
+				rtp_out_running = 1;
+			} else {
+				next_rtp_out.tv_usec += 20000;
+				if (next_rtp_out.tv_usec >= 1000000) {
+					next_rtp_out.tv_sec++;
+					next_rtp_out.tv_usec -= 1000000;
+				}
+			}
+			if (timercmp(&cur_event_time, &next_rtp_out, <))
+				timersub(&next_rtp_out, &cur_event_time,
+					 &timeout);
+			else
+				timerclear(&timeout);
+			rc = select(max_fd+1, &fds, 0, 0, &timeout);
+		} else {
+			if (rtp_out_running) {
+				printf("Stopping RTP output\n");
+				rtp_out_running = 0;
+			}
+			rc = select(max_fd+1, &fds, 0, 0, 0);
+		}
 		if (rc < 0) {
 			if (errno == EINTR)
 				continue;
@@ -166,5 +194,7 @@
 			rtp_rx_select();
 		if (FD_ISSET(rtcp_udp_fd, &fds))
 			rtcp_rx_select();
+		if (rtp_out_running && (rc == 0))
+			generate_rtp_packet();
 	}
 }