]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/rtpfmt.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / modules / stream_out / rtpfmt.c
index a9d0aee6df0b1b9c78afc8a731fed57b9df2cc96..482db7d4fc4708eb3416ce7b49e18ddc40d94b9c 100644 (file)
@@ -55,11 +55,9 @@ int rtp_packetize_mpa( sout_stream_id_t *id,
         /* rtp common header */
         rtp_packetize_common( id, out, (i == i_count - 1)?1:0, in->i_pts );
         /* mbz set to 0 */
-        out->p_buffer[12] = 0;
-        out->p_buffer[13] = 0;
+        SetWBE( out->p_buffer + 12, 0 );
         /* fragment offset in the current frame */
-        out->p_buffer[14] = ( (i*i_max) >> 8 )&0xff;
-        out->p_buffer[15] = ( (i*i_max)      )&0xff;
+        SetWBE( out->p_buffer + 14, i * i_max );
         memcpy( &out->p_buffer[16], p_data, i_payload );
 
         out->i_buffer   = 16 + i_payload;
@@ -145,6 +143,7 @@ int rtp_packetize_mpv( sout_stream_id_t *id, block_t *in )
     {
         int           i_payload = __MIN( i_max, i_data );
         block_t *out = block_Alloc( 16 + i_payload );
+        /* MBZ:5 T:1 TR:10 AN:1 N:1 S:1 B:1 E:1 P:3 FBV:1 BFC:3 FFV:1 FFC:3 */
         uint32_t      h = ( i_temporal_ref << 16 )|
                           ( b_sequence_start << 13 )|
                           ( b_start_slice << 12 )|
@@ -154,13 +153,9 @@ int rtp_packetize_mpv( sout_stream_id_t *id, block_t *in )
 
         /* rtp common header */
         rtp_packetize_common( id, out, (i == i_count - 1)?1:0,
-                              in->i_pts > 0 ? in->i_pts : in->i_dts );
+                          in->i_pts > VLC_TS_INVALID ? in->i_pts : in->i_dts );
 
-        /* MBZ:5 T:1 TR:10 AN:1 N:1 S:1 B:1 E:1 P:3 FBV:1 BFC:3 FFV:1 FFC:3 */
-        out->p_buffer[12] = ( h >> 24 )&0xff;
-        out->p_buffer[13] = ( h >> 16 )&0xff;
-        out->p_buffer[14] = ( h >>  8 )&0xff;
-        out->p_buffer[15] = ( h       )&0xff;
+        SetDWBE( out->p_buffer + 12, h );
 
         memcpy( &out->p_buffer[16], p_data, i_payload );
 
@@ -229,7 +224,7 @@ int rtp_packetize_split( sout_stream_id_t *id, block_t *in )
 
         /* rtp common header */
         rtp_packetize_common( id, out, (i == i_count - 1),
-                              (in->i_pts > 0 ? in->i_pts : in->i_dts) );
+                      (in->i_pts > VLC_TS_INVALID ? in->i_pts : in->i_dts) );
         memcpy( &out->p_buffer[12], p_data, i_payload );
 
         out->i_buffer   = 12 + i_payload;
@@ -245,6 +240,39 @@ int rtp_packetize_split( sout_stream_id_t *id, block_t *in )
     return VLC_SUCCESS;
 }
 
+/* split and convert from little endian to network byte order */
+int rtp_packetize_swab( 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;
+
+    uint8_t *p_data = in->p_buffer;
+    int     i_data  = in->i_buffer;
+    int     i;
+
+    for( i = 0; i < i_count; i++ )
+    {
+        int           i_payload = __MIN( i_max, i_data );
+        block_t *out = block_Alloc( 12 + i_payload );
+
+        /* rtp common header */
+        rtp_packetize_common( id, out, (i == i_count - 1),
+                      (in->i_pts > VLC_TS_INVALID ? in->i_pts : in->i_dts) );
+        swab( p_data, out->p_buffer + 12, i_payload );
+
+        out->i_buffer = 12 + i_payload;
+        out->i_dts    = in->i_dts + i * in->i_length / i_count;
+        out->i_length = in->i_length / i_count;
+
+        rtp_packetize_send( id, out );
+
+        p_data += i_payload;
+        i_data -= i_payload;
+    }
+
+    return VLC_SUCCESS;
+}
+
 /* rfc3016 */
 int rtp_packetize_mp4a_latm( sout_stream_id_t *id, block_t *in )
 {
@@ -267,7 +295,7 @@ int rtp_packetize_mp4a_latm( sout_stream_id_t *id, block_t *in )
 
         /* rtp common header */
         rtp_packetize_common( id, out, ((i == i_count - 1) ? 1 : 0),
-                              (in->i_pts > 0 ? in->i_pts : in->i_dts) );
+                      (in->i_pts > VLC_TS_INVALID ? in->i_pts : in->i_dts) );
 
         if( i == 0 )
         {
@@ -314,14 +342,13 @@ int rtp_packetize_mp4a( sout_stream_id_t *id, block_t *in )
 
         /* rtp common header */
         rtp_packetize_common( id, out, ((i == i_count - 1)?1:0),
-                              (in->i_pts > 0 ? in->i_pts : in->i_dts) );
+                      (in->i_pts > VLC_TS_INVALID ? in->i_pts : in->i_dts) );
         /* AU headers */
         /* AU headers length (bits) */
         out->p_buffer[12] = 0;
         out->p_buffer[13] = 2*8;
         /* for each AU length 13 bits + idx 3bits, */
-        out->p_buffer[14] = ( in->i_buffer >> 5 )&0xff;
-        out->p_buffer[15] = ( (in->i_buffer&0xff)<<3 )|0;
+        SetWBE( out->p_buffer + 14, (in->i_buffer << 3) | 0 );
 
         memcpy( &out->p_buffer[16], p_data, i_payload );
 
@@ -381,11 +408,10 @@ int rtp_packetize_h263( sout_stream_id_t *id, block_t *in )
         /* rtp common header */
         //b_m_bit = 1; // always contains end of frame
         rtp_packetize_common( id, out, (i == i_count - 1)?1:0,
-                              in->i_pts > 0 ? in->i_pts : in->i_dts );
+                          in->i_pts > VLC_TS_INVALID ? in->i_pts : in->i_dts );
 
         /* h263 header */
-        out->p_buffer[12] = ( h >>  8 )&0xff;
-        out->p_buffer[13] = ( h       )&0xff;
+        SetWBE( out->p_buffer + 12, h );
         memcpy( &out->p_buffer[RTP_H263_PAYLOAD_START], p_data, i_payload );
 
         out->i_buffer = RTP_H263_PAYLOAD_START + i_payload;
@@ -454,7 +480,8 @@ rtp_packetize_h264_nal( sout_stream_id_t *id,
             out->i_length = i_length / i_count;
 
             /* */
-            rtp_packetize_common( id, out, (b_last && i_payload == i_data), i_pts );
+            rtp_packetize_common( id, out, (b_last && i_payload == i_data),
+                                    i_pts );
             out->i_buffer = 14 + i_payload;
 
             /* FU indicator */
@@ -503,8 +530,8 @@ int rtp_packetize_h264( sout_stream_id_t *id, block_t *in )
         }
         /* TODO add STAP-A to remove a lot of overhead with small slice/sei/... */
         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 );
+                (in->i_pts > VLC_TS_INVALID ? in->i_pts : in->i_dts), in->i_dts,
+                (i_size >= i_buffer), in->i_length * i_size / in->i_buffer );
 
         i_buffer -= i_skip;
         p_buffer += i_skip;
@@ -529,7 +556,7 @@ int rtp_packetize_amr( sout_stream_id_t *id, block_t *in )
 
         /* rtp common header */
         rtp_packetize_common( id, out, ((i == i_count - 1)?1:0),
-                              (in->i_pts > 0 ? in->i_pts : in->i_dts) );
+                      (in->i_pts > VLC_TS_INVALID ? in->i_pts : in->i_dts) );
         /* Payload header */
         out->p_buffer[12] = 0xF0; /* CMR */
         out->p_buffer[13] = p_data[0]&0x7C; /* ToC */ /* FIXME: frame type */
@@ -656,7 +683,8 @@ int rtp_packetize_spx( sout_stream_id_t *id, block_t *in )
     }
 
     /* Add the RTP header to our p_output buffer. */
-    rtp_packetize_common( id, p_out, 0, (in->i_pts > 0 ? in->i_pts : in->i_dts) );
+    rtp_packetize_common( id, p_out, 0,
+                        (in->i_pts > VLC_TS_INVALID ? in->i_pts : in->i_dts) );
     /* Copy the Speex payload to the p_output buffer */
     memcpy( &p_out->p_buffer[12], p_buffer, i_data_size );
 
@@ -668,3 +696,55 @@ int rtp_packetize_spx( sout_stream_id_t *id, block_t *in )
     rtp_packetize_send( id, p_out );
     return VLC_SUCCESS;
 }
+
+static int rtp_packetize_g726( sout_stream_id_t *id, block_t *in, int i_pad )
+{
+    int     i_max   = (rtp_mtu( id )- 12 + i_pad - 1) & ~i_pad;
+    int     i_count = ( in->i_buffer + i_max - 1 ) / i_max;
+
+    uint8_t *p_data = in->p_buffer;
+    int     i_data  = in->i_buffer;
+    int     i_packet = 0;
+
+    while( i_data > 0 )
+    {
+        int           i_payload = __MIN( i_max, i_data );
+        block_t *out = block_New( p_stream, 12 + i_payload );
+
+        /* rtp common header */
+        rtp_packetize_common( id, out, 0,
+                      (in->i_pts > VLC_TS_INVALID ? 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++ * in->i_length / i_count;
+        out->i_length = in->i_length / i_count;
+
+        rtp_packetize_send( id, out );
+
+        p_data += i_payload;
+        i_data -= i_payload;
+    }
+    return VLC_SUCCESS;
+}
+
+int rtp_packetize_g726_16( sout_stream_id_t *id, block_t *in )
+{
+    return rtp_packetize_g726( id, in, 4 );
+}
+
+int rtp_packetize_g726_24( sout_stream_id_t *id, block_t *in )
+{
+    return rtp_packetize_g726( id, in, 8 );
+}
+
+int rtp_packetize_g726_32( sout_stream_id_t *id, block_t *in )
+{
+    return rtp_packetize_g726( id, in, 2 );
+}
+
+int rtp_packetize_g726_40( sout_stream_id_t *id, block_t *in )
+{
+    return rtp_packetize_g726( id, in, 8 );
+}