[vlc-devel] commit: RTP: add Framed RTP over TCP support ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat Jun 7 17:32:31 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sat Jun  7 18:33:47 2008 +0300| [51a5b2bedc0dd99f556c3fb64ffa8450c5401a44]

RTP: add Framed RTP over TCP support

(untested as I have no software capable of sending this)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=51a5b2bedc0dd99f556c3fb64ffa8450c5401a44
---

 modules/demux/rtp.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 modules/demux/rtp.h |    1 +
 2 files changed, 53 insertions(+), 1 deletions(-)

diff --git a/modules/demux/rtp.c b/modules/demux/rtp.c
index a48834d..6dcc186 100644
--- a/modules/demux/rtp.c
+++ b/modules/demux/rtp.c
@@ -92,6 +92,8 @@ vlc_module_begin ();
         change_integer_range (0, 32767);
 
     add_shortcut ("dccp");
+    /*add_shortcut ("sctp");*/
+    add_shortcut ("rtptcp"); /* "tcp" is already taken :( */
     add_shortcut ("rtp");
     add_shortcut ("udplite");
 vlc_module_end ();
@@ -131,6 +133,9 @@ static int Open (vlc_object_t *obj)
     if (!strcmp (demux->psz_access, "dccp"))
         tp = IPPROTO_DCCP;
     else
+    if (!strcmp (demux->psz_access, "rtptcp"))
+        tp = IPPROTO_TCP;
+    else
     if (!strcmp (demux->psz_access, "rtp"))
         tp = IPPROTO_UDP;
     else
@@ -181,6 +186,10 @@ static int Open (vlc_object_t *obj)
             msg_Err (obj, "DCCP support not included");
 #endif
             break;
+
+        case IPPROTO_TCP:
+            fd = net_Connect (obj, shost, sport, SOCK_STREAM, tp);
+            break;
     }
 
     free (tmp);
@@ -199,6 +208,7 @@ static int Open (vlc_object_t *obj)
     p_sys->max_dropout  = var_CreateGetInteger (obj, "rtp-max-dropout");
     p_sys->max_misorder = var_CreateGetInteger (obj, "rtp-max-misorder");
     p_sys->autodetect   = true;
+    p_sys->framed_rtp   = (tp == IPPROTO_TCP);
 
     demux->pf_demux   = Demux;
     demux->pf_control = Control;
@@ -331,6 +341,45 @@ static block_t *rtp_dgram_recv (demux_t *demux, int fd)
     return block_Realloc (block, 0, len);
 }
 
+/**
+ * Gets a framed RTP packet, or NULL in case of fatal error.
+ */
+static block_t *rtp_stream_recv (demux_t *demux, int fd)
+{
+    ssize_t len = 0;
+    uint8_t hdr[2]; /* frame header */
+
+    /* Receives the RTP frame header */
+    do
+    {
+        ssize_t val = net_Read (VLC_OBJECT (demux), fd, NULL,
+                                hdr + len, 2 - len, false);
+        if (val <= 0)
+            return NULL;
+        len += val;
+    }
+    while (len < 2);
+
+    block_t *block = block_Alloc (GetWBE (hdr));
+
+    /* Receives the RTP packet */
+    for (ssize_t i = 0; i < len;)
+    {
+        ssize_t val;
+
+        val = net_Read (VLC_OBJECT (demux), fd, NULL,
+                        block->p_buffer + i, block->i_buffer - i, false);
+        if (val <= 0)
+        {
+            block_Release (block);
+            return NULL;
+        }
+        i += val;
+    }
+
+    return block;
+}
+
 
 /*
  * Generic packet handlers
@@ -518,7 +567,9 @@ static int Demux (demux_t *demux)
     demux_sys_t *p_sys = demux->p_sys;
     block_t     *block;
 
-    block = rtp_dgram_recv (demux, p_sys->fd);
+    block = p_sys->framed_rtp
+        ? rtp_dgram_recv (demux, p_sys->fd)
+        : rtp_stream_recv (demux, p_sys->fd);
     if (!block)
         return 0;
 
diff --git a/modules/demux/rtp.h b/modules/demux/rtp.h
index 04e6869..f18a998 100644
--- a/modules/demux/rtp.h
+++ b/modules/demux/rtp.h
@@ -51,5 +51,6 @@ struct demux_sys_t
     uint16_t      max_dropout;
     uint16_t      max_misorder;
     bool          autodetect;
+    bool          framed_rtp;
 };
 




More information about the vlc-devel mailing list