]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/rtpfmt.c
Fix [10fcb9f9c3c73d13340c0bd4153fc4c9c87b7186] (win doesn't have setenv).
[vlc] / modules / stream_out / rtpfmt.c
index 1ccc24fff01eadefd818a19add82f1fdde1193a5..a9d0aee6df0b1b9c78afc8a731fed57b9df2cc96 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * rtp.c: rtp stream output module
+ * rtpfmt.c: RTP payload formats
  *****************************************************************************
  * Copyright (C) 2003-2004 the VideoLAN team
  * Copyright © 2007 Rémi Denis-Courmont
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_sout.h>
 #include <vlc_block.h>
 
 #include "rtp.h"
 
-int rtp_packetize_mpa( sout_stream_t *p_stream, sout_stream_id_t *id,
+int
+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_mpa( sout_stream_id_t *id,
                        block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 4; /* payload max in one packet */
@@ -45,7 +50,7 @@ int rtp_packetize_mpa( sout_stream_t *p_stream, sout_stream_id_t *id,
     for( i = 0; i < i_count; i++ )
     {
         int           i_payload = __MIN( i_max, i_data );
-        block_t *out = block_New( p_stream, 16 + i_payload );
+        block_t *out = block_Alloc( 16 + i_payload );
 
         /* rtp common header */
         rtp_packetize_common( id, out, (i == i_count - 1)?1:0, in->i_pts );
@@ -71,8 +76,7 @@ int rtp_packetize_mpa( sout_stream_t *p_stream, sout_stream_id_t *id,
 }
 
 /* rfc2250 */
-int rtp_packetize_mpv( sout_stream_t *p_stream, sout_stream_id_t *id,
-                       block_t *in )
+int rtp_packetize_mpv( sout_stream_id_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 4; /* payload max in one packet */
     int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
@@ -140,8 +144,7 @@ int rtp_packetize_mpv( sout_stream_t *p_stream, sout_stream_id_t *id,
     for( i = 0; i < i_count; i++ )
     {
         int           i_payload = __MIN( i_max, i_data );
-        block_t *out = block_New( p_stream,
-                                             16 + i_payload );
+        block_t *out = block_Alloc( 16 + i_payload );
         uint32_t      h = ( i_temporal_ref << 16 )|
                           ( b_sequence_start << 13 )|
                           ( b_start_slice << 12 )|
@@ -174,8 +177,7 @@ int rtp_packetize_mpv( sout_stream_t *p_stream, sout_stream_id_t *id,
     return VLC_SUCCESS;
 }
 
-int rtp_packetize_ac3( sout_stream_t *p_stream, sout_stream_id_t *id,
-                       block_t *in )
+int rtp_packetize_ac3( sout_stream_id_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 2; /* payload max in one packet */
     int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
@@ -187,7 +189,7 @@ int rtp_packetize_ac3( sout_stream_t *p_stream, sout_stream_id_t *id,
     for( i = 0; i < i_count; i++ )
     {
         int           i_payload = __MIN( i_max, i_data );
-        block_t *out = block_New( p_stream, 14 + i_payload );
+        block_t *out = block_Alloc( 14 + i_payload );
 
         /* rtp common header */
         rtp_packetize_common( id, out, (i == i_count - 1)?1:0, in->i_pts );
@@ -211,8 +213,7 @@ int rtp_packetize_ac3( sout_stream_t *p_stream, sout_stream_id_t *id,
     return VLC_SUCCESS;
 }
 
-int rtp_packetize_split( sout_stream_t *p_stream, sout_stream_id_t *id,
-                         block_t *in )
+int rtp_packetize_split( sout_stream_id_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id); /* payload max in one packet */
     int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
@@ -224,7 +225,7 @@ int rtp_packetize_split( sout_stream_t *p_stream, sout_stream_id_t *id,
     for( i = 0; i < i_count; i++ )
     {
         int           i_payload = __MIN( i_max, i_data );
-        block_t *out = block_New( p_stream, 12 + i_payload );
+        block_t *out = block_Alloc( 12 + i_payload );
 
         /* rtp common header */
         rtp_packetize_common( id, out, (i == i_count - 1),
@@ -245,8 +246,7 @@ int rtp_packetize_split( sout_stream_t *p_stream, sout_stream_id_t *id,
 }
 
 /* rfc3016 */
-int rtp_packetize_mp4a_latm( sout_stream_t *p_stream, sout_stream_id_t *id,
-                             block_t *in )
+int rtp_packetize_mp4a_latm( sout_stream_id_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 2;              /* payload max in one packet */
     int     latmhdrsize = in->i_buffer / 0xff + 1;
@@ -263,7 +263,7 @@ int rtp_packetize_mp4a_latm( sout_stream_t *p_stream, sout_stream_id_t *id,
 
         if( i != 0 )
             latmhdrsize = 0;
-        out = block_New( p_stream, 12 + latmhdrsize + i_payload );
+        out = block_Alloc( 12 + latmhdrsize + i_payload );
 
         /* rtp common header */
         rtp_packetize_common( id, out, ((i == i_count - 1) ? 1 : 0),
@@ -298,68 +298,7 @@ int rtp_packetize_mp4a_latm( sout_stream_t *p_stream, sout_stream_id_t *id,
     return VLC_SUCCESS;
 }
 
-int rtp_packetize_l16( sout_stream_t *p_stream, sout_stream_id_t *id,
-                       block_t *in )
-{
-    const uint8_t *p_data = in->p_buffer;
-    size_t i_data  = in->i_buffer;
-    size_t i_plen = 2 * rtp_plen (id, 20);
-
-    for( unsigned i_packet = 0; i_data > 0; i_packet++ )
-    {
-        int           i_payload = __MIN( i_plen, i_data );
-        block_t *out = block_New( p_stream, 12 + i_payload );
-
-        /* rtp common header */
-        rtp_packetize_common( id, out, 0,
-                              (in->i_pts > 0 ? in->i_pts : in->i_dts) );
-        memcpy( &out->p_buffer[12], p_data, i_payload );
-
-        out->i_buffer = 12 + i_payload;
-        out->i_dts    = in->i_dts + i_packet * 20000;
-        out->i_length = i_payload * 20000 / i_plen;
-
-        rtp_packetize_send( id, out );
-
-        p_data += i_payload;
-        i_data -= i_payload;
-    }
-
-    return VLC_SUCCESS;
-}
-
-int rtp_packetize_l8( sout_stream_t *p_stream, sout_stream_id_t *id,
-                      block_t *in )
-{
-    const uint8_t *p_data = in->p_buffer;
-    size_t i_data  = in->i_buffer;
-    size_t i_plen = rtp_plen (id, 20);
-
-    for( unsigned i_packet = 0; i_data > 0; i_packet++ )
-    {
-        int           i_payload = __MIN( i_plen, i_data );
-        block_t *out = block_New( p_stream, 12 + i_payload );
-
-        /* rtp common header */
-        rtp_packetize_common( id, out, 0,
-                              (in->i_pts > 0 ? in->i_pts : in->i_dts) );
-        memcpy( &out->p_buffer[12], p_data, i_payload );
-
-        out->i_buffer = 12 + i_payload;
-        out->i_dts    = in->i_dts + i_packet * 20000;
-        out->i_length = i_payload * 20000 / i_plen;
-
-        rtp_packetize_send( id, out );
-
-        p_data += i_payload;
-        i_data -= i_payload;
-    }
-
-    return VLC_SUCCESS;
-}
-
-int rtp_packetize_mp4a( sout_stream_t *p_stream, sout_stream_id_t *id,
-                        block_t *in )
+int rtp_packetize_mp4a( sout_stream_id_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 4; /* payload max in one packet */
     int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
@@ -371,7 +310,7 @@ int rtp_packetize_mp4a( sout_stream_t *p_stream, sout_stream_id_t *id,
     for( i = 0; i < i_count; i++ )
     {
         int           i_payload = __MIN( i_max, i_data );
-        block_t *out = block_New( p_stream, 16 + i_payload );
+        block_t *out = block_Alloc( 16 + i_payload );
 
         /* rtp common header */
         rtp_packetize_common( id, out, ((i == i_count - 1)?1:0),
@@ -403,8 +342,7 @@ int rtp_packetize_mp4a( sout_stream_t *p_stream, sout_stream_id_t *id,
 /* rfc2429 */
 #define RTP_H263_HEADER_SIZE (2)  // plen = 0
 #define RTP_H263_PAYLOAD_START (14)  // plen = 0
-int rtp_packetize_h263( sout_stream_t *p_stream, sout_stream_id_t *id,
-                        block_t *in )
+int rtp_packetize_h263( sout_stream_id_t *id, block_t *in )
 {
     uint8_t *p_data = in->p_buffer;
     int     i_data  = in->i_buffer;
@@ -433,8 +371,7 @@ int rtp_packetize_h263( sout_stream_t *p_stream, sout_stream_id_t *id,
     for( i = 0; i < i_count; i++ )
     {
         int      i_payload = __MIN( i_max, i_data );
-        block_t *out = block_New( p_stream,
-                                  RTP_H263_PAYLOAD_START + i_payload );
+        block_t *out = block_Alloc( RTP_H263_PAYLOAD_START + i_payload );
         b_p_bit = (i == 0) ? 1 : 0;
         h = ( b_p_bit << 10 )|
             ( b_v_bit << 9  )|
@@ -466,9 +403,9 @@ int rtp_packetize_h263( sout_stream_t *p_stream, sout_stream_id_t *id,
 
 /* rfc3984 */
 int
-rtp_packetize_h264_nal( sout_stream_t *p_stream, sout_stream_id_t *id,
+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, vlc_bool_t b_last, int64_t i_length )
+                        int64_t i_dts, bool b_last, int64_t i_length )
 {
     const int i_max = rtp_mtu (id); /* payload max in one packet */
     int i_nal_hdr;
@@ -488,7 +425,7 @@ rtp_packetize_h264_nal( sout_stream_t *p_stream, sout_stream_id_t *id,
     if( i_data <= i_max )
     {
         /* Single NAL unit packet */
-        block_t *out = block_New( p_stream, 12 + i_data );
+        block_t *out = block_Alloc( 12 + i_data );
         out->i_dts    = i_dts;
         out->i_length = i_length;
 
@@ -512,7 +449,7 @@ rtp_packetize_h264_nal( sout_stream_t *p_stream, sout_stream_id_t *id,
         for( i = 0; i < i_count; i++ )
         {
             const int i_payload = __MIN( i_data, i_max-2 );
-            block_t *out = block_New( p_stream, 12 + 2 + i_payload );
+            block_t *out = block_Alloc( 12 + 2 + i_payload );
             out->i_dts    = i_dts + i * i_length / i_count;
             out->i_length = i_length / i_count;
 
@@ -535,8 +472,7 @@ rtp_packetize_h264_nal( sout_stream_t *p_stream, sout_stream_id_t *id,
     return VLC_SUCCESS;
 }
 
-int rtp_packetize_h264( sout_stream_t *p_stream, sout_stream_id_t *id,
-                        block_t *in )
+int rtp_packetize_h264( sout_stream_id_t *id, block_t *in )
 {
     const uint8_t *p_buffer = in->p_buffer;
     int i_buffer = in->i_buffer;
@@ -566,7 +502,7 @@ int rtp_packetize_h264( sout_stream_t *p_stream, sout_stream_id_t *id,
             }
         }
         /* TODO add STAP-A to remove a lot of overhead with small slice/sei/... */
-        rtp_packetize_h264_nal( p_stream, id, p_buffer, i_size,
+        rtp_packetize_h264_nal( id, p_buffer, i_size,
                                 (in->i_pts > 0 ? in->i_pts : in->i_dts), in->i_dts,
                                 (i_size >= i_buffer), in->i_length * i_size / in->i_buffer );
 
@@ -576,8 +512,7 @@ int rtp_packetize_h264( sout_stream_t *p_stream, sout_stream_id_t *id,
     return VLC_SUCCESS;
 }
 
-int rtp_packetize_amr( sout_stream_t *p_stream, sout_stream_id_t *id,
-                       block_t *in )
+int rtp_packetize_amr( sout_stream_id_t *id, block_t *in )
 {
     int     i_max   = rtp_mtu (id) - 2; /* payload max in one packet */
     int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
@@ -590,7 +525,7 @@ int rtp_packetize_amr( sout_stream_t *p_stream, sout_stream_id_t *id,
     for( i = 0; i < i_count; i++ )
     {
         int           i_payload = __MIN( i_max, i_data );
-        block_t *out = block_New( p_stream, 14 + i_payload );
+        block_t *out = block_Alloc( 14 + i_payload );
 
         /* rtp common header */
         rtp_packetize_common( id, out, ((i == i_count - 1)?1:0),
@@ -615,8 +550,7 @@ int rtp_packetize_amr( sout_stream_t *p_stream, sout_stream_id_t *id,
     return VLC_SUCCESS;
 }
 
-int rtp_packetize_t140( sout_stream_t *p_stream, sout_stream_id_t *id,
-                        block_t *in )
+int rtp_packetize_t140( sout_stream_id_t *id, block_t *in )
 {
     const size_t   i_max  = rtp_mtu (id);
     const uint8_t *p_data = in->p_buffer;
@@ -641,7 +575,7 @@ int rtp_packetize_t140( sout_stream_t *p_stream, sout_stream_id_t *id,
             }
         }
 
-        block_t *out = block_New( p_stream, 12 + i_payload );
+        block_t *out = block_Alloc( 12 + i_payload );
         if( out == NULL )
             return VLC_SUCCESS;
 
@@ -662,8 +596,7 @@ int rtp_packetize_t140( sout_stream_t *p_stream, sout_stream_id_t *id,
 }
 
 
-int rtp_packetize_spx( sout_stream_t *p_stream, sout_stream_id_t *id,
-                       block_t *in )
+int rtp_packetize_spx( sout_stream_id_t *id, block_t *in )
 {
     uint8_t *p_buffer = in->p_buffer;
     int i_data_size, i_payload_size, i_payload_padding;
@@ -672,10 +605,7 @@ int rtp_packetize_spx( sout_stream_t *p_stream, sout_stream_id_t *id,
     block_t *p_out;
 
     if ( in->i_buffer > rtp_mtu (id) )
-    {
-        msg_Warn( p_stream, "Cannot send packet larger than output MTU" );
         return VLC_SUCCESS;
-    }
 
     /*
       RFC for Speex in RTP says that each packet must end on an octet 
@@ -696,7 +626,7 @@ int rtp_packetize_spx( sout_stream_t *p_stream, sout_stream_id_t *id,
       Allocate a new RTP p_output block of the appropriate size. 
       Allow for 12 extra bytes of RTP header. 
     */
-    p_out = block_New( p_stream, 12 + i_payload_size );
+    p_out = block_Alloc( 12 + i_payload_size );
 
     if ( i_payload_padding )
     {