[Pkg-voip-commits] [janus] 93/282: Added some checks/fixes already made in master

Jonas Smedegaard dr at jones.dk
Wed Dec 20 21:53:31 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/0.2.6-1
in repository janus.

commit ea08ce7eddd8ecad2626ad7eb2cef2b5c6edea7b
Author: Lorenzo Miniero <lminiero at gmail.com>
Date:   Wed Jul 26 18:45:05 2017 +0200

    Added some checks/fixes already made in master
---
 plugins/janus_sipre.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/plugins/janus_sipre.c b/plugins/janus_sipre.c
index 6194a85..48d42b5 100644
--- a/plugins/janus_sipre.c
+++ b/plugins/janus_sipre.c
@@ -1235,11 +1235,25 @@ void janus_sipre_incoming_rtp(janus_plugin_session *handle, int video, char *buf
 						video ? "Video" : "Audio", janus_srtp_error_str(res), len, protected, timestamp, seq);
 				} else {
 					/* Forward the frame to the peer */
-					send((video ? session->media.video_rtp_fd : session->media.audio_rtp_fd), sbuf, protected, 0);
+					if(send((video ? session->media.video_rtp_fd : session->media.audio_rtp_fd), sbuf, protected, 0) < 0) {
+						rtp_header *header = (rtp_header *)&sbuf;
+						guint32 timestamp = ntohl(header->timestamp);
+						guint16 seq = ntohs(header->seq_number);
+						JANUS_LOG(LOG_HUGE, "[SIPre-%s] Error sending %s SRTP packet... %s (len=%d, ts=%"SCNu32", seq=%"SCNu16")...\n",
+							session->account.username ? session->account.username : "unknown",
+							video ? "Video" : "Audio", strerror(errno), protected, timestamp, seq);
+					}
 				}
 			} else {
 				/* Forward the frame to the peer */
-				send((video ? session->media.video_rtp_fd : session->media.audio_rtp_fd), buf, len, 0);
+				if(send((video ? session->media.video_rtp_fd : session->media.audio_rtp_fd), buf, len, 0) < 0) {
+					rtp_header *header = (rtp_header *)&buf;
+					guint32 timestamp = ntohl(header->timestamp);
+					guint16 seq = ntohs(header->seq_number);
+					JANUS_LOG(LOG_HUGE, "[SIPre-%s] Error sending %s RTP packet... %s (len=%d, ts=%"SCNu32", seq=%"SCNu16")...\n",
+						session->account.username ? session->account.username : "unknown",
+						video ? "Video" : "Audio", strerror(errno), len, timestamp, seq);
+				}
 			}
 		}
 	}
@@ -1281,11 +1295,19 @@ void janus_sipre_incoming_rtcp(janus_plugin_session *handle, int video, char *bu
 						janus_srtp_error_str(res), len, protected);
 				} else {
 					/* Forward the message to the peer */
-					send((video ? session->media.video_rtcp_fd : session->media.audio_rtcp_fd), sbuf, protected, 0);
+					if(send((video ? session->media.video_rtcp_fd : session->media.audio_rtcp_fd), sbuf, protected, 0) < 0) {
+						JANUS_LOG(LOG_HUGE, "[SIPre-%s] Error sending %s SRTCP packet... %s (len=%d)...\n",
+							session->account.username ? session->account.username : "unknown",
+							video ? "Video" : "Audio", strerror(errno), protected);
+					}
 				}
 			} else {
 				/* Forward the message to the peer */
-				send((video ? session->media.video_rtcp_fd : session->media.audio_rtcp_fd), buf, len, 0);
+				if(send((video ? session->media.video_rtcp_fd : session->media.audio_rtcp_fd), buf, len, 0) < 0) {
+					JANUS_LOG(LOG_HUGE, "[SIPre-%s] Error sending %s RTCP packet... %s (len=%d)...\n",
+						session->account.username ? session->account.username : "unknown",
+						video ? "Video" : "Audio", strerror(errno), len);
+				}
 			}
 		}
 	}
@@ -2727,6 +2749,10 @@ static int janus_sipre_allocate_local_ports(janus_sipre_session *session) {
 			if(session->media.audio_rtcp_fd == -1) {
 				session->media.audio_rtcp_fd = socket(AF_INET, SOCK_DGRAM, 0);
 			}
+			if(session->media.audio_rtp_fd == -1 || session->media.audio_rtcp_fd == -1) {
+				JANUS_LOG(LOG_ERR, "Error creating audio sockets...\n");
+				return -1;
+			}
 			int rtp_port = g_random_int_range(10000, 60000);	/* FIXME Should this be configurable? */
 			if(rtp_port % 2)
 				rtp_port++;	/* Pick an even port for RTP */
@@ -2735,6 +2761,8 @@ static int janus_sipre_allocate_local_ports(janus_sipre_session *session) {
 			inet_pton(AF_INET, local_ip, &audio_rtp_address.sin_addr.s_addr);
 			if(bind(session->media.audio_rtp_fd, (struct sockaddr *)(&audio_rtp_address), sizeof(struct sockaddr)) < 0) {
 				JANUS_LOG(LOG_ERR, "Bind failed for audio RTP (port %d), trying a different one...\n", rtp_port);
+				close(session->media.audio_rtp_fd);
+				session->media.audio_rtp_fd = -1;
 				attempts--;
 				continue;
 			}
@@ -2748,6 +2776,8 @@ static int janus_sipre_allocate_local_ports(janus_sipre_session *session) {
 				/* RTP socket is not valid anymore, reset it */
 				close(session->media.audio_rtp_fd);
 				session->media.audio_rtp_fd = -1;
+				close(session->media.audio_rtcp_fd);
+				session->media.audio_rtcp_fd = -1;
 				attempts--;
 				continue;
 			}
@@ -2768,6 +2798,10 @@ static int janus_sipre_allocate_local_ports(janus_sipre_session *session) {
 			if(session->media.video_rtcp_fd == -1) {
 				session->media.video_rtcp_fd = socket(AF_INET, SOCK_DGRAM, 0);
 			}
+			if(session->media.video_rtp_fd == -1 || session->media.video_rtcp_fd == -1) {
+				JANUS_LOG(LOG_ERR, "Error creating video sockets...\n");
+				return -1;
+			}
 			int rtp_port = g_random_int_range(10000, 60000);	/* FIXME Should this be configurable? */
 			if(rtp_port % 2)
 				rtp_port++;	/* Pick an even port for RTP */
@@ -2776,6 +2810,8 @@ static int janus_sipre_allocate_local_ports(janus_sipre_session *session) {
 			inet_pton(AF_INET, local_ip, &video_rtp_address.sin_addr.s_addr);
 			if(bind(session->media.video_rtp_fd, (struct sockaddr *)(&video_rtp_address), sizeof(struct sockaddr)) < 0) {
 				JANUS_LOG(LOG_ERR, "Bind failed for video RTP (port %d), trying a different one...\n", rtp_port);
+				close(session->media.video_rtp_fd);
+				session->media.video_rtp_fd = -1;
 				attempts--;
 				continue;
 			}
@@ -2789,6 +2825,8 @@ static int janus_sipre_allocate_local_ports(janus_sipre_session *session) {
 				/* RTP socket is not valid anymore, reset it */
 				close(session->media.video_rtp_fd);
 				session->media.video_rtp_fd = -1;
+				close(session->media.video_rtp_fd);
+				session->media.video_rtp_fd = -1;
 				attempts--;
 				continue;
 			}
@@ -2992,12 +3030,16 @@ static void *janus_sipre_relay_thread(void *data) {
 				if(pipe_fd != -1 && fds[i].fd == pipe_fd) {
 					/* Poll interrupted for a reason, go on */
 					int code = 0;
-					bytes = read(pipe_fd, &code, sizeof(int));
+					(void)read(pipe_fd, &code, sizeof(int));
 					break;
 				}
 				/* Got an RTP/RTCP packet */
 				addrlen = sizeof(remote);
 				bytes = recvfrom(fds[i].fd, buffer, 1500, 0, (struct sockaddr*)&remote, &addrlen);
+				if(bytes < 0) {
+					/* Failed to read? */
+					continue;
+				}
 				/* Let's check what this is */
 				gboolean video = fds[i].fd == session->media.video_rtp_fd || fds[i].fd == session->media.video_rtcp_fd;
 				gboolean rtcp = fds[i].fd == session->media.audio_rtcp_fd || fds[i].fd == session->media.video_rtcp_fd;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git



More information about the Pkg-voip-commits mailing list