[vlc-devel] [PATCH] rtp sout: send in-band vorbis configuration packets

Pierre Ynard linkfanel at yahoo.fr
Thu Nov 18 05:00:45 CET 2010


This is an alternative to SDP to convey the codec configuration
necessary to decode the stream. The configuration is sent only once at
the beginning of the stream; at least you won't be tempted to waste
bandwidth with retransmissions. This is a ad-hoc hack, but it's not too
bad or pervasive.

An alternative would be to extend existing structures and/or add private
data for packetizers, to store the configuration blob, timestamp,
(re)transmission parameters...

The same situation will arise with theora.


diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c
index d829974..b7fbf65 100644
--- a/modules/stream_out/rtp.c
+++ b/modules/stream_out/rtp.c
@@ -1253,6 +1253,14 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
     while( p_buffer != NULL )
     {
         p_next = p_buffer->p_next;
+
+        /* Send a Vorbis Packed Configuration packet (RFC 5215 §3.1)
+         * as the first packet of the stream */
+        if (!strcmp(id->rtp_fmt.ptname, "vorbis")
+            && id->i_sequence == id->i_seq_sent_next)
+                rtp_packetize_vorbis_config(id, id->rtp_fmt.fmtp,
+                                            p_buffer->i_pts);
+
         if( id->rtp_fmt.pf_packetize( id, p_buffer ) )
             break;
 
diff --git a/modules/stream_out/rtp.h b/modules/stream_out/rtp.h
index 67b6108..c6fcb8c 100644
--- a/modules/stream_out/rtp.h
+++ b/modules/stream_out/rtp.h
@@ -59,6 +59,9 @@ void rtp_packetize_common (sout_stream_id_t *id, block_t *out,
 void rtp_packetize_send (sout_stream_id_t *id, block_t *out);
 size_t rtp_mtu (const sout_stream_id_t *id);
 
+int rtp_packetize_vorbis_config( sout_stream_id_t *id, const char *fmtp,
+                                 int64_t i_pts );
+
 /* RTCP */
 typedef struct rtcp_sender_t rtcp_sender_t;
 rtcp_sender_t *OpenRTCP (vlc_object_t *obj, int rtp_fd, int proto,
diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c
index 20ae567..ecc536c 100644
--- a/modules/stream_out/rtpfmt.c
+++ b/modules/stream_out/rtpfmt.c
@@ -447,6 +447,70 @@ rtp_packetize_h264_nal( sout_stream_id_t *id,
                         const uint8_t *p_data, int i_data, int64_t i_pts,
                         int64_t i_dts, bool b_last, int64_t i_length );
 
+int rtp_packetize_vorbis_config( sout_stream_id_t *id, const char *fmtp,
+                                 int64_t i_pts )
+{
+    int     i_max   = rtp_mtu (id) - 6; /* payload max in one packet */
+
+    uint8_t *p_orig, *p_data;
+    int i_data;
+
+    i_data = vlc_b64_decode_binary(&p_orig,
+                                   fmtp + sizeof("configuration=") - 1 );
+    if (i_data == 0)
+        return VLC_EGENERIC;
+    assert(i_data > 9);
+    p_data = p_orig + 9;
+    i_data -= 9;
+
+    int i_count = ( i_data + i_max - 1 ) / i_max;
+
+    for( int i = 0; i < i_count; i++ )
+    {
+        int           i_payload = __MIN( i_max, i_data );
+        block_t *out = block_Alloc( 18 + i_payload );
+
+        unsigned fragtype, numpkts;
+        if (i_count == 1)
+        {
+            fragtype = 0;
+            numpkts = 1;
+        }
+        else
+        {
+            numpkts = 0;
+            if (i == 0)
+                fragtype = 1;
+            else if (i == i_count - 1)
+                fragtype = 3;
+            else
+                fragtype = 2;
+        }
+        /* Ident:24, Fragment type:2, Vorbis Data Type:2, # of packets:4 */
+        uint32_t header = ((VORBIS_IDENT & 0xffffff) << 8) |
+                          (fragtype << 6) | (1 << 4) | numpkts;
+
+        /* rtp common header */
+        rtp_packetize_common( id, out, 0, i_pts );
+
+        SetDWBE( out->p_buffer + 12, header);
+        SetWBE( out->p_buffer + 16, i_payload);
+        memcpy( &out->p_buffer[18], p_data, i_payload );
+
+        out->i_buffer   = 18 + i_payload;
+        out->i_dts    = i_pts;
+
+        rtp_packetize_send( id, out );
+
+        p_data += i_payload;
+        i_data -= i_payload;
+    }
+
+    free(p_orig);
+
+    return VLC_SUCCESS;
+}
+
 /* rfc5215 */
 static int rtp_packetize_vorbis( sout_stream_id_t *id, block_t *in )
 {


Regards,

-- 
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