changeset 6081:d21ccbea3294 libavformat

rtspenc: Write the interleaving header in the same buffer as the packet data
author mstorsjo
date Fri, 04 Jun 2010 06:42:39 +0000
parents c7ddd67739a6
children 140e0b5fcea2
files rtspenc.c
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/rtspenc.c	Fri Jun 04 06:35:12 2010 +0000
+++ b/rtspenc.c	Fri Jun 04 06:42:39 2010 +0000
@@ -69,13 +69,19 @@
     AVFormatContext *rtpctx = rtsp_st->transport_priv;
     uint8_t *buf, *ptr;
     int size;
-    uint8_t interleave_header[4];
+    uint8_t *interleave_header, *interleaved_packet;
 
     size = url_close_dyn_buf(rtpctx->pb, &buf);
     ptr = buf;
     while (size > 4) {
         uint32_t packet_len = AV_RB32(ptr);
         int id;
+        /* The interleaving header is exactly 4 bytes, which happens to be
+         * the same size as the packet length header from
+         * url_open_dyn_packet_buf. So by writing the interleaving header
+         * over these bytes, we get a consecutive interleaved packet
+         * that can be written in one call. */
+        interleaved_packet = interleave_header = ptr;
         ptr += 4;
         size -= 4;
         if (packet_len > size || packet_len < 2)
@@ -87,8 +93,7 @@
         interleave_header[0] = '$';
         interleave_header[1] = id;
         AV_WB16(interleave_header + 2, packet_len);
-        url_write(rt->rtsp_hd, interleave_header, 4);
-        url_write(rt->rtsp_hd, ptr, packet_len);
+        url_write(rt->rtsp_hd, interleaved_packet, 4 + packet_len);
         ptr += packet_len;
         size -= packet_len;
     }