[vlc-devel] commit: rtp: g726 packetization ( Rafaël Carré )

git version control git at videolan.org
Thu Sep 4 17:25:37 CEST 2008


vlc | branch: master | Rafaël Carré <rcarre at m2x.nl> | Thu Sep  4 17:26:19 2008 +0200| [c32cb1d118ba028be1df6b98a11811a27b04d782] | committer: Rafaël Carré 

rtp: g726 packetization

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c32cb1d118ba028be1df6b98a11811a27b04d782
---

 modules/stream_out/rtp.c    |   22 ++++++++++++++++++
 modules/stream_out/rtp.h    |    4 +++
 modules/stream_out/rtpfmt.c |   52 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c
index 6407aaf..5c611ca 100644
--- a/modules/stream_out/rtp.c
+++ b/modules/stream_out/rtp.c
@@ -1064,6 +1064,28 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
             id->psz_enc = "MPV";
             id->pf_packetize = rtp_packetize_mpv;
             break;
+        case VLC_FOURCC( 'G', '7', '2', '6' ):
+        case VLC_FOURCC( 'g', '7', '2', '6' ):
+            switch( p_fmt->i_bitrate / 1000 )
+            {
+            case 16:
+                id->psz_enc = "G726-16";
+                id->pf_packetize = rtp_packetize_g726_16;
+                break;
+            case 24:
+                id->psz_enc = "G726-24";
+                id->pf_packetize = rtp_packetize_g726_24;
+                break;
+            case 32:
+                id->psz_enc = "G726-32";
+                id->pf_packetize = rtp_packetize_g726_32;
+                break;
+            case 40:
+                id->psz_enc = "G726-40";
+                id->pf_packetize = rtp_packetize_g726_40;
+                break;
+            }
+            break;
         case VLC_FOURCC( 'a', '5', '2', ' ' ):
             id->psz_enc = "ac3";
             id->pf_packetize = rtp_packetize_ac3;
diff --git a/modules/stream_out/rtp.h b/modules/stream_out/rtp.h
index 8788dc8..4af86ce 100644
--- a/modules/stream_out/rtp.h
+++ b/modules/stream_out/rtp.h
@@ -58,6 +58,10 @@ int rtp_packetize_h264 (sout_stream_id_t *, block_t *);
 int rtp_packetize_amr  (sout_stream_id_t *, block_t *);
 int rtp_packetize_spx  (sout_stream_id_t *, block_t *);
 int rtp_packetize_t140 (sout_stream_id_t *, block_t *);
+int rtp_packetize_g726_16 (sout_stream_id_t *, block_t *);
+int rtp_packetize_g726_24 (sout_stream_id_t *, block_t *);
+int rtp_packetize_g726_32 (sout_stream_id_t *, block_t *);
+int rtp_packetize_g726_40 (sout_stream_id_t *, block_t *);
 
 /* RTCP */
 typedef struct rtcp_sender_t rtcp_sender_t;
diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c
index a9d0aee..0b8b488 100644
--- a/modules/stream_out/rtpfmt.c
+++ b/modules/stream_out/rtpfmt.c
@@ -668,3 +668,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 > 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++ * 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, 16 );
+}
+
+int rtp_packetize_g726_24( sout_stream_id_t *id, block_t *in )
+{
+    return rtp_packetize_g726( id, in, 24 );
+}
+
+int rtp_packetize_g726_32( sout_stream_id_t *id, block_t *in )
+{
+    return rtp_packetize_g726( id, in, 32 );
+}
+
+int rtp_packetize_g726_40( sout_stream_id_t *id, block_t *in )
+{
+    return rtp_packetize_g726( id, in, 40 );
+}




More information about the vlc-devel mailing list