[vlc-devel] [RFC 3/3] rtp: option to assume Vorbis for unknown dynamic payloads

Pierre Ynard linkfanel at yahoo.fr
Thu Nov 18 06:07:41 CET 2010


Vorbis support is enabled. An option is added to manually select the
payload format of unknown dynamic payload types, in pre-arranged
streaming setups, without needing SDP. The only choice for now is
Vorbis.


diff --git a/modules/access/rtp/Modules.am b/modules/access/rtp/Modules.am
index 849c8e4..57b39ce 100644
--- a/modules/access/rtp/Modules.am
+++ b/modules/access/rtp/Modules.am
@@ -5,7 +5,8 @@ librtp_plugin_la_SOURCES = \
 	rtp.c \
 	rtp.h \
 	input.c \
-	session.c
+	session.c \
+	xiph.c
 librtp_plugin_la_CFLAGS = $(AM_CFLAGS)
 librtp_plugin_la_LIBADD = $(AM_LIBADD)
 librtp_plugin_la_DEPENDENCIES =
diff --git a/modules/access/rtp/rtp.c b/modules/access/rtp/rtp.c
index 3cf48eb..6030624 100644
--- a/modules/access/rtp/rtp.c
+++ b/modules/access/rtp/rtp.c
@@ -75,6 +75,15 @@
     "RTP packets will be discarded if they are too far behind (i.e. in the " \
     "past) by this many packets from the last received packet." )
 
+#define RTP_DYNAMIC_PT_TEXT N_("RTP payload format assumed for dynamic payloads")
+#define RTP_DYNAMIC_PT_LONGTEXT N_( \
+    "This payload format will be assumed for dynamic payload types " \
+    "(between 96 and 127) if it can't be determined otherwise with " \
+    "out-of-band mappings (SDP)" )
+
+static const char *const dynamic_pt_list[] = { "vorbis" };
+static const char *const dynamic_pt_list_text[] = { "Vorbis Encoded Audio" };
+
 static int  Open (vlc_object_t *);
 static void Close (vlc_object_t *);
 
@@ -114,6 +123,9 @@ vlc_module_begin ()
     add_integer ("rtp-max-misorder", 100, RTP_MAX_MISORDER_TEXT,
                  RTP_MAX_MISORDER_LONGTEXT, true)
         change_integer_range (0, 32767)
+    add_string ("rtp-dynamic-pt", NULL, RTP_DYNAMIC_PT_TEXT,
+                RTP_DYNAMIC_PT_LONGTEXT, true)
+        change_string_list (dynamic_pt_list, dynamic_pt_list_text, NULL)
 
     /*add_shortcut ("sctp")*/
     add_shortcut ("dccp", "rtptcp", /* "tcp" is already taken :( */
@@ -407,19 +419,19 @@ static int Control (demux_t *demux, int i_query, va_list args)
  * Generic packet handlers
  */
 
-static void *codec_init (demux_t *demux, es_format_t *fmt)
+void *codec_init (demux_t *demux, es_format_t *fmt)
 {
     return es_out_Add (demux->out, fmt);
 }
 
-static void codec_destroy (demux_t *demux, void *data)
+void codec_destroy (demux_t *demux, void *data)
 {
     if (data)
         es_out_Del (demux->out, (es_out_id_t *)data);
 }
 
 /* Send a packet to decoder */
-static uint32_t codec_decode (demux_t *demux, void *data, block_t *block)
+uint32_t codec_decode (demux_t *demux, void *data, block_t *block)
 {
     if (data)
     {
@@ -699,6 +711,21 @@ int rtp_autodetect (demux_t *demux, rtp_session_t *session,
           pt.frequency = 90000;
           break;
         }
+        else if (ptype >= 96)
+        {
+            char *dynamic = var_InheritString(demux, "rtp-dynamic-pt");
+            if (dynamic == NULL)
+                ;
+            else if (!strcmp(dynamic, "vorbis"))
+            {
+                pt.init = vorbis_init;
+                pt.destroy = vorbis_destroy;
+                pt.decode = vorbis_decode;
+                /* frequency is the sampling rate, and is unknown until
+                 * we parse it from vorbis configuration headers */
+            }
+            free(dynamic);
+        }
         else
         {
           return -1;
diff --git a/modules/access/rtp/rtp.h b/modules/access/rtp/rtp.h
index c90b010..04598af 100644
--- a/modules/access/rtp/rtp.h
+++ b/modules/access/rtp/rtp.h
@@ -73,3 +73,10 @@ struct demux_sys_t
 #endif
 };
 
+void *codec_init (demux_t *demux, es_format_t *fmt);
+void codec_destroy (demux_t *demux, void *data);
+uint32_t codec_decode (demux_t *demux, void *data, block_t *block);
+
+void *vorbis_init (demux_t *demux);
+void vorbis_destroy (demux_t *demux, void *data);
+uint32_t vorbis_decode (demux_t *demux, void *data, block_t *block);
diff --git a/modules/access/rtp/xiph.c b/modules/access/rtp/xiph.c
index 03ef83a..7a27e79 100644
--- a/modules/access/rtp/xiph.c
+++ b/modules/access/rtp/xiph.c
@@ -49,7 +49,7 @@ typedef struct rtp_vorbis_t
     uint32_t     ident;
 } rtp_vorbis_t;
 
-static void *vorbis_init (demux_t *demux)
+void *vorbis_init (demux_t *demux)
 {
     rtp_vorbis_t *self = malloc (sizeof (*self));
 
@@ -63,7 +63,7 @@ static void *vorbis_init (demux_t *demux)
     return self;
 }
 
-static void vorbis_destroy (demux_t *demux, void *data)
+void vorbis_destroy (demux_t *demux, void *data)
 {
     rtp_vorbis_t *self = data;
 
@@ -137,7 +137,7 @@ static ssize_t vorbis_header (void **pextra, const uint8_t *buf, size_t len)
 }
 
 
-static uint32_t vorbis_decode (demux_t *demux, void *data, block_t *block)
+uint32_t vorbis_decode (demux_t *demux, void *data, block_t *block)
 {
     uint32_t frequency = 0;
     rtp_vorbis_t *self = data;
@@ -231,7 +231,11 @@ static void vorbis_decode (demux_t *demux, void *data, block_t *block)
             case 0: /* Raw audio frame */
             {
                 if (self->ident != ident)
-                    break; /* Ignore raw without configuration */
+                {
+                    msg_Warn (demux, "ignoring raw Vorbis payload "
+                                     "without configuration");
+                    break;
+                }
                 block_t *raw = block_Alloc (len);
                 memcpy (raw->p_buffer, block->p_buffer, len);
                 raw->i_pts = block->i_pts; /* FIXME: what about pkts > 1 */


-- 
Pierre Ynard
"Une âme dans un corps, c'est comme un dessin sur une feuille de papier."



More information about the vlc-devel mailing list