]> git.sesse.net Git - vlc/blobdiff - modules/access/rtp/rtp.c
decode an RTP/H264 elementary stream without using SDP
[vlc] / modules / access / rtp / rtp.c
old mode 100644 (file)
new mode 100755 (executable)
index 27b9138..c896270
@@ -8,7 +8,7 @@
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2.0
+ * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
@@ -16,7 +16,7 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU Lesser General Public
+ * You should have received a copy of the GNU General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  ****************************************************************************/
 #include <vlc_network.h>
 #include <vlc_plugin.h>
 
-#include <vlc_codecs.h>
-
 #include "rtp.h"
-#include <srtp.h>
+#ifdef HAVE_SRTP
+# include <srtp.h>
+#endif
 
 #define RTP_CACHING_TEXT N_("RTP de-jitter buffer length (msec)")
 #define RTP_CACHING_LONGTEXT N_( \
@@ -97,10 +97,12 @@ vlc_module_begin ()
                  RTCP_PORT_LONGTEXT, false)
         change_integer_range (0, 65535)
         change_safe ()
+#ifdef HAVE_SRTP
     add_string ("srtp-key", "", NULL,
                 SRTP_KEY_TEXT, SRTP_KEY_LONGTEXT, false)
     add_string ("srtp-salt", "", NULL,
                 SRTP_SALT_TEXT, SRTP_SALT_LONGTEXT, false)
+#endif
     add_integer ("rtp-max-src", 1, NULL, RTP_MAX_SRC_TEXT,
                  RTP_MAX_SRC_LONGTEXT, true)
         change_integer_range (1, 255)
@@ -113,11 +115,9 @@ vlc_module_begin ()
                  RTP_MAX_MISORDER_LONGTEXT, true)
         change_integer_range (0, 32767)
 
-    add_shortcut ("dccp")
     /*add_shortcut ("sctp")*/
-    add_shortcut ("rtptcp") /* "tcp" is already taken :( */
-    add_shortcut ("rtp")
-    add_shortcut ("udplite")
+    add_shortcut ("dccp", "rtptcp", /* "tcp" is already taken :( */
+                  "rtp", "udplite")
 vlc_module_end ()
 
 /*
@@ -165,18 +165,27 @@ static int Open (vlc_object_t *obj)
     else
         return VLC_EGENERIC;
 
-    char *tmp = strdup (demux->psz_path);
-    char *shost = tmp;
-    if (shost == NULL)
+    char *tmp = strdup (demux->psz_location);
+    if (tmp == NULL)
         return VLC_ENOMEM;
 
-    char *dhost = strchr (shost, '@');
-    if (dhost)
-        *dhost++ = '\0';
+    char *shost;
+    char *dhost = strchr (tmp, '@');
+    if (dhost != NULL)
+    {
+        *(dhost++) = '\0';
+        shost = tmp;
+    }
+    else
+    {
+        dhost = tmp;
+        shost = NULL;
+    }
 
     /* Parses the port numbers */
     int sport = 0, dport = 0;
-    sport = extract_port (&shost);
+    if (shost != NULL)
+        sport = extract_port (&shost);
     if (dhost != NULL)
         dport = extract_port (&dhost);
     if (dport == 0)
@@ -209,14 +218,14 @@ static int Open (vlc_object_t *obj)
 #ifdef SOCK_DCCP
             var_Create (obj, "dccp-service", VLC_VAR_STRING);
             var_SetString (obj, "dccp-service", "RTPV"); /* FIXME: RTPA? */
-            fd = net_Connect (obj, shost, sport, SOCK_DCCP, tp);
+            fd = net_Connect (obj, dhost, dport, SOCK_DCCP, tp);
 #else
             msg_Err (obj, "DCCP support not included");
 #endif
             break;
 
         case IPPROTO_TCP:
-            fd = net_Connect (obj, shost, sport, SOCK_STREAM, tp);
+            fd = net_Connect (obj, dhost, dport, SOCK_STREAM, tp);
             break;
     }
 
@@ -236,12 +245,15 @@ static int Open (vlc_object_t *obj)
     }
 
     vlc_mutex_init (&p_sys->lock);
+#ifdef HAVE_SRTP
     p_sys->srtp         = NULL;
+#endif
     p_sys->fd           = fd;
     p_sys->rtcp_fd      = rtcp_fd;
     p_sys->caching      = var_CreateGetInteger (obj, "rtp-caching");
     p_sys->max_src      = var_CreateGetInteger (obj, "rtp-max-src");
-    p_sys->timeout      = var_CreateGetInteger (obj, "rtp-timeout");
+    p_sys->timeout      = var_CreateGetInteger (obj, "rtp-timeout")
+                        * CLOCK_FREQ;
     p_sys->max_dropout  = var_CreateGetInteger (obj, "rtp-max-dropout");
     p_sys->max_misorder = var_CreateGetInteger (obj, "rtp-max-misorder");
     p_sys->framed_rtp   = (tp == IPPROTO_TCP);
@@ -254,6 +266,7 @@ static int Open (vlc_object_t *obj)
     if (p_sys->session == NULL)
         goto error;
 
+#ifdef HAVE_SRTP
     char *key = var_CreateGetNonEmptyString (demux, "srtp-key");
     if (key)
     {
@@ -275,6 +288,7 @@ static int Open (vlc_object_t *obj)
             goto error;
         }
     }
+#endif
 
     if (vlc_clone (&p_sys->thread, rtp_thread, demux,
                    VLC_THREAD_PRIORITY_INPUT))
@@ -303,8 +317,10 @@ static void Close (vlc_object_t *obj)
     }
     vlc_mutex_destroy (&p_sys->lock);
 
+#ifdef HAVE_SRTP
     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)
@@ -415,7 +431,6 @@ static void codec_decode (demux_t *demux, void *data, block_t *block)
         block_Release (block);
 }
 
-
 static void *stream_init (demux_t *demux, const char *name)
 {
     return stream_DemuxNew (demux, name, demux->out);
@@ -438,6 +453,11 @@ static void stream_decode (demux_t *demux, void *data, block_t *block)
     (void)demux;
 }
 
+static void *demux_init (demux_t *demux)
+{
+    return stream_init (demux, demux->psz_demux);
+}
+
 /*
  * Static payload types handler
  */
@@ -663,7 +683,22 @@ int rtp_autodetect (demux_t *demux, rtp_session_t *session,
         break;
 
       default:
-        return -1;
+        /*
+         * If the rtp payload type is unknown then check demux if it is specified
+         */
+        if ((strcmp(demux->psz_demux, "h264") == 0) || (strcmp(demux->psz_demux, "ts") == 0))
+        {
+          msg_Dbg (demux, "rtp autodetect specified demux=%s", demux->psz_demux);
+          pt.init = demux_init;
+          pt.destroy = stream_destroy;
+          pt.decode = stream_decode;
+          pt.frequency = 90000;
+          break;
+        }
+        else
+        {
+          return -1;
+        }
     }
     rtp_add_type (demux, session, &pt);
     return 0;