rtspenc: Write the interleaving header in the same buffer as the packet data

Originally committed as revision 23465 to svn://svn.ffmpeg.org/ffmpeg/trunk
oldabi
Martin Storsjö 15 years ago
parent dd798dcd11
commit 35d8ecc54e
  1. 11
      libavformat/rtspenc.c

@ -69,13 +69,19 @@ static int tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st)
AVFormatContext *rtpctx = rtsp_st->transport_priv; AVFormatContext *rtpctx = rtsp_st->transport_priv;
uint8_t *buf, *ptr; uint8_t *buf, *ptr;
int size; int size;
uint8_t interleave_header[4]; uint8_t *interleave_header, *interleaved_packet;
size = url_close_dyn_buf(rtpctx->pb, &buf); size = url_close_dyn_buf(rtpctx->pb, &buf);
ptr = buf; ptr = buf;
while (size > 4) { while (size > 4) {
uint32_t packet_len = AV_RB32(ptr); uint32_t packet_len = AV_RB32(ptr);
int id; 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; ptr += 4;
size -= 4; size -= 4;
if (packet_len > size || packet_len < 2) if (packet_len > size || packet_len < 2)
@ -87,8 +93,7 @@ static int tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st)
interleave_header[0] = '$'; interleave_header[0] = '$';
interleave_header[1] = id; interleave_header[1] = id;
AV_WB16(interleave_header + 2, packet_len); AV_WB16(interleave_header + 2, packet_len);
url_write(rt->rtsp_hd, interleave_header, 4); url_write(rt->rtsp_hd, interleaved_packet, 4 + packet_len);
url_write(rt->rtsp_hd, ptr, packet_len);
ptr += packet_len; ptr += packet_len;
size -= packet_len; size -= packet_len;
} }

Loading…
Cancel
Save