[vlc-commits] rtp: improve S16L to L16 packetization

Rémi Denis-Courmont git at videolan.org
Thu Sep 25 21:31:27 CEST 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Sep 25 22:30:49 2014 +0300| [f490a08f5ee62d6bb9fa5bc06fd399213c7b4de4] | committer: Rémi Denis-Courmont

rtp: improve S16L to L16 packetization

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

 modules/stream_out/rtpfmt.c |   40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c
index acdfe17..8119a36 100644
--- a/modules/stream_out/rtpfmt.c
+++ b/modules/stream_out/rtpfmt.c
@@ -926,32 +926,32 @@ static int rtp_packetize_pcm(sout_stream_id_sys_t *id, block_t *in)
 }
 
 /* split and convert from little endian to network byte order */
-static int rtp_packetize_swab( sout_stream_id_sys_t *id, block_t *in )
+static int rtp_packetize_swab(sout_stream_id_sys_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;
+    unsigned max = rtp_mtu(id);
 
-    for( i = 0; i < i_count; i++ )
+    while (in->i_buffer > 0)
     {
-        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 );
+        unsigned payload = (max < in->i_buffer) ? max : in->i_buffer;
+        unsigned duration = (in->i_length * payload) / in->i_buffer;
+        bool marker = (in->i_flags & BLOCK_FLAG_DISCONTINUITY) != 0;
 
-        out->i_dts    = in->i_dts + i * in->i_length / i_count;
-        out->i_length = in->i_length / i_count;
+        block_t *out = block_Alloc(12 + payload);
+        if (unlikely(out == NULL))
+        {
+            block_Release(in);
+            return VLC_ENOMEM;
+        }
 
-        rtp_packetize_send( id, out );
+        rtp_packetize_common(id, out, marker, in->i_pts);
+        swab(in->p_buffer, out->p_buffer + 12, payload);
+        rtp_packetize_send(id, out);
 
-        p_data += i_payload;
-        i_data -= i_payload;
+        in->p_buffer += payload;
+        in->i_buffer -= payload;
+        in->i_pts += duration;
+        in->i_length -= duration;
+        in->i_flags &= ~BLOCK_FLAG_DISCONTINUITY;
     }
 
     block_Release(in);



More information about the vlc-commits mailing list