[vlc-commits] rtp: use struct vlc_dtls
Rémi Denis-Courmont
git at videolan.org
Sat Jun 6 08:07:50 CEST 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun May 10 15:11:08 2020 +0300| [ced9254b63271c36bddd15c01adabb88d3a3f1bb] | committer: Rémi Denis-Courmont
rtp: use struct vlc_dtls
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ced9254b63271c36bddd15c01adabb88d3a3f1bb
---
modules/access/rtp/input.c | 65 ++++++++++++++----------------------------
modules/access/rtp/rtp.c | 70 +++++++++++++++++++++++++++++++++-------------
modules/access/rtp/rtp.h | 4 +--
3 files changed, 73 insertions(+), 66 deletions(-)
diff --git a/modules/access/rtp/input.c b/modules/access/rtp/input.c
index 1548609196..d1d0f72bf5 100644
--- a/modules/access/rtp/input.c
+++ b/modules/access/rtp/input.c
@@ -27,11 +27,9 @@
#include <vlc_common.h>
#include <vlc_demux.h>
#include <vlc_block.h>
-#include <vlc_network.h>
#include <limits.h>
#include <errno.h>
-#include <unistd.h>
#ifdef HAVE_POLL
# include <poll.h>
#endif
@@ -39,6 +37,8 @@
# include <sys/uio.h>
#endif
+#include <vlc_dtls.h>
+
#include "rtp.h"
#ifdef HAVE_SRTP
# include "srtp.h"
@@ -108,29 +108,15 @@ void *rtp_dgram_thread (void *opaque)
demux_t *demux = opaque;
demux_sys_t *sys = demux->p_sys;
vlc_tick_t deadline = VLC_TICK_INVALID;
- int rtp_fd = sys->fd;
-#ifdef __linux__
- const int trunc_flag = MSG_TRUNC;
-#else
- const int trunc_flag = 0;
-#endif
+ struct vlc_dtls *rtp_sock = sys->rtp_sock;
- struct iovec iov =
- {
- .iov_len = DEFAULT_MRU,
- };
- struct msghdr msg =
+ for (;;)
{
- .msg_iov = &iov,
- .msg_iovlen = 1,
- };
+ struct pollfd ufd[1];
- struct pollfd ufd[1];
- ufd[0].fd = rtp_fd;
- ufd[0].events = POLLIN;
+ ufd[0].events = POLLIN;
+ ufd[0].fd = vlc_dtls_GetPollFD(rtp_sock, &ufd[0].events);
- for (;;)
- {
int n = poll (ufd, 1, rtp_timeout (deadline));
if (n == -1)
continue;
@@ -141,31 +127,18 @@ void *rtp_dgram_thread (void *opaque)
if (ufd[0].revents)
{
- n--;
- if (unlikely(ufd[0].revents & POLLHUP))
- break; /* RTP socket dead (DCCP only) */
-
- block_t *block = block_Alloc (iov.iov_len);
+ block_t *block = block_Alloc(DEFAULT_MRU);
if (unlikely(block == NULL))
- {
- if (iov.iov_len == DEFAULT_MRU)
- break; /* we are totallly screwed */
- iov.iov_len = DEFAULT_MRU;
- continue; /* retry with shrunk MRU */
- }
-
- iov.iov_base = block->p_buffer;
- msg.msg_flags = trunc_flag;
-
- ssize_t len = recvmsg (rtp_fd, &msg, trunc_flag);
- if (len != -1)
- {
- if (msg.msg_flags & trunc_flag)
- {
- msg_Err(demux, "%zd bytes packet truncated (MRU was %zu)",
- len, iov.iov_len);
+ break; /* we are totallly screwed */
+
+ bool truncated;
+ ssize_t len = vlc_dtls_Recv(rtp_sock, block->p_buffer,
+ block->i_buffer, &truncated);
+ if (len >= 0) {
+ if (truncated) {
+ msg_Err(demux, "packet truncated (MRU was %zu)",
+ block->i_buffer);
block->i_flags |= BLOCK_FLAG_CORRUPTED;
- iov.iov_len = len;
}
else
block->i_buffer = len;
@@ -174,10 +147,14 @@ void *rtp_dgram_thread (void *opaque)
}
else
{
+ if (errno == EPIPE)
+ break; /* connection terminated */
msg_Warn (demux, "RTP network error: %s",
vlc_strerror_c(errno));
block_Release (block);
}
+
+ n--;
}
dequeue:
diff --git a/modules/access/rtp/rtp.c b/modules/access/rtp/rtp.c
index 4cbbd3c4ba..04f3f3f65c 100644
--- a/modules/access/rtp/rtp.c
+++ b/modules/access/rtp/rtp.c
@@ -31,6 +31,7 @@
#include <vlc_demux.h>
#include <vlc_network.h>
#include <vlc_plugin.h>
+#include <vlc_dtls.h>
#include "rtp.h"
#ifdef HAVE_SRTP
@@ -150,11 +151,10 @@ static void Close (vlc_object_t *obj)
if (p_sys->srtp)
srtp_destroy (p_sys->srtp);
#endif
- if (p_sys->session)
- rtp_session_destroy (demux, p_sys->session);
- if (p_sys->rtcp_fd != -1)
- net_Close (p_sys->rtcp_fd);
- net_Close (p_sys->fd);
+ rtp_session_destroy (demux, p_sys->session);
+ if (p_sys->rtcp_sock != NULL)
+ vlc_dtls_Close(p_sys->rtcp_sock);
+ vlc_dtls_Close(p_sys->rtp_sock);
}
static int OpenSDP(vlc_object_t *obj)
@@ -184,8 +184,8 @@ static int OpenSDP(vlc_object_t *obj)
if (unlikely(sys == NULL))
return VLC_ENOMEM;
- sys->fd = -1;
- sys->rtcp_fd = -1;
+ sys->rtp_sock = NULL;
+ sys->rtcp_sock = NULL;
sys->session = NULL;
#ifdef HAVE_SRTP
sys->srtp = NULL;
@@ -281,19 +281,28 @@ static int OpenSDP(vlc_object_t *obj)
if (fd == -1)
goto error;
- int rtcp_fd = -1;
+ sys->rtp_sock = vlc_datagram_CreateFD(fd);
+ if (unlikely(sys->rtp_sock == NULL)) {
+ net_Close(fd);
+ goto error;
+ }
+
if (rtcp_port > 0) {
- rtcp_fd = net_OpenDgram(obj, conn->addr, rtcp_port, src, 0,
- IPPROTO_UDP);
- if (rtcp_fd == -1)
+ fd = net_OpenDgram(obj, conn->addr, rtcp_port, src, 0, IPPROTO_UDP);
+ if (fd == -1)
+ goto error;
+
+ sys->rtcp_sock = vlc_datagram_CreateFD(fd);
+ if (unlikely(sys->rtcp_sock == NULL)) {
+ net_Close(fd);
goto error;
+ }
}
vlc_sdp_free(sdp);
+ sdp = NULL;
sys->chained_demux = NULL;
- sys->fd = fd;
- sys->rtcp_fd = rtcp_fd;
sys->max_src = var_InheritInteger(obj, "rtp-max-src");
sys->timeout = vlc_tick_from_sec(var_InheritInteger(obj, "rtp-timeout"));
sys->max_dropout = var_InheritInteger(obj, "rtp-max-dropout");
@@ -309,14 +318,21 @@ static int OpenSDP(vlc_object_t *obj)
goto error;
if (vlc_clone(&sys->thread, rtp_dgram_thread, demux,
- VLC_THREAD_PRIORITY_INPUT))
+ VLC_THREAD_PRIORITY_INPUT)) {
+ rtp_session_destroy(demux, sys->session);
goto error;
+ }
+
sys->thread_ready = true;
return VLC_SUCCESS;
error:
- Close (obj);
- vlc_sdp_free(sdp);
+ if (sys->rtcp_sock != NULL)
+ vlc_dtls_Close(sys->rtcp_sock);
+ if (sys->rtp_sock != NULL)
+ vlc_dtls_Close(sys->rtp_sock);
+ if (sdp != NULL)
+ vlc_sdp_free(sdp);
return VLC_EGENERIC;
}
@@ -376,6 +392,7 @@ static int OpenURL(vlc_object_t *obj)
/* Try to connect */
int fd = -1, rtcp_fd = -1;
+ bool co = false;
switch (tp)
{
@@ -398,6 +415,7 @@ static int OpenURL(vlc_object_t *obj)
var_Create (obj, "dccp-service", VLC_VAR_STRING);
var_SetString (obj, "dccp-service", "RTPV"); /* FIXME: RTPA? */
fd = net_Connect (obj, dhost, dport, SOCK_DCCP, tp);
+ co = true;
#else
msg_Err (obj, "DCCP support not included");
#endif
@@ -405,20 +423,26 @@ static int OpenURL(vlc_object_t *obj)
}
free (tmp);
- if (fd == -1) {
+ p_sys->rtp_sock = (co ? vlc_dccp_CreateFD : vlc_datagram_CreateFD)(fd);
+ if (p_sys->rtcp_sock == NULL) {
if (rtcp_fd != -1)
net_Close(rtcp_fd);
return VLC_EGENERIC;
}
net_SetCSCov (fd, -1, 12);
+ if (rtcp_fd != -1) {
+ p_sys->rtcp_sock = vlc_datagram_CreateFD(rtcp_fd);
+ if (p_sys->rtcp_sock == NULL)
+ net_Close (rtcp_fd);
+ } else
+ p_sys->rtcp_sock = NULL;
+
/* Initializes demux */
p_sys->chained_demux = NULL;
#ifdef HAVE_SRTP
p_sys->srtp = NULL;
#endif
- p_sys->fd = fd;
- p_sys->rtcp_fd = rtcp_fd;
p_sys->max_src = var_CreateGetInteger (obj, "rtp-max-src");
p_sys->timeout = vlc_tick_from_sec( var_CreateGetInteger (obj, "rtp-timeout") );
p_sys->max_dropout = var_CreateGetInteger (obj, "rtp-max-dropout");
@@ -467,7 +491,13 @@ static int OpenURL(vlc_object_t *obj)
return VLC_SUCCESS;
error:
- Close (obj);
+ if (p_sys->srtp != NULL)
+ srtp_destroy(p_sys->srtp);
+ if (p_sys->session != NULL)
+ rtp_session_destroy(demux, p_sys->session);
+ if (p_sys->rtcp_sock != NULL)
+ vlc_dtls_Close(p_sys->rtcp_sock);
+ vlc_dtls_Close(p_sys->rtp_sock);
return VLC_EGENERIC;
}
diff --git a/modules/access/rtp/rtp.h b/modules/access/rtp/rtp.h
index 01a50c8427..84f78bc2fe 100644
--- a/modules/access/rtp/rtp.h
+++ b/modules/access/rtp/rtp.h
@@ -67,8 +67,8 @@ typedef struct
#ifdef HAVE_SRTP
struct srtp_session_t *srtp;
#endif
- int fd;
- int rtcp_fd;
+ struct vlc_dtls *rtp_sock;
+ struct vlc_dtls *rtcp_sock;
vlc_thread_t thread;
vlc_tick_t timeout;
More information about the vlc-commits
mailing list