diff rtpdec.c @ 5665:93b0d64bf0c9 libavformat

When using RTP-over-UDP, send dummy packets during stream setup, similar to what e.g. RealPlayer does. This allows proper port forwarding setup in NAT- based environments. Patch by Martin Storsj <$firstname at $firstname dot st>.
author rbultje
date Tue, 16 Feb 2010 22:50:50 +0000
parents 457efbf56d15
children 57ef8feb5745
line wrap: on
line diff
--- a/rtpdec.c	Tue Feb 16 19:26:49 2010 +0000
+++ b/rtpdec.c	Tue Feb 16 22:50:50 2010 +0000
@@ -273,6 +273,45 @@
     return 0;
 }
 
+void rtp_send_punch_packets(URLContext* rtp_handle)
+{
+    ByteIOContext *pb;
+    uint8_t *buf;
+    int len;
+
+    /* Send a small RTP packet */
+    if (url_open_dyn_buf(&pb) < 0)
+        return;
+
+    put_byte(pb, (RTP_VERSION << 6));
+    put_byte(pb, 0); /* Payload type */
+    put_be16(pb, 0); /* Seq */
+    put_be32(pb, 0); /* Timestamp */
+    put_be32(pb, 0); /* SSRC */
+
+    put_flush_packet(pb);
+    len = url_close_dyn_buf(pb, &buf);
+    if ((len > 0) && buf)
+        url_write(rtp_handle, buf, len);
+    av_free(buf);
+
+    /* Send a minimal RTCP RR */
+    if (url_open_dyn_buf(&pb) < 0)
+        return;
+
+    put_byte(pb, (RTP_VERSION << 6));
+    put_byte(pb, 201); /* receiver report */
+    put_be16(pb, 1); /* length in words - 1 */
+    put_be32(pb, 0); /* our own SSRC */
+
+    put_flush_packet(pb);
+    len = url_close_dyn_buf(pb, &buf);
+    if ((len > 0) && buf)
+        url_write(rtp_handle, buf, len);
+    av_free(buf);
+}
+
+
 /**
  * open a new RTP parse context for stream 'st'. 'st' can be NULL for
  * MPEG2TS streams to indicate that they should be demuxed inside the