]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtpenc_xiph.c
bktr: Use memset(0) instead of zero initialization for struct sigaction
[ffmpeg] / libavformat / rtpenc_xiph.c
index ef31c048deac81c7d478d95d6347ffc9297ae3b5..f6ab77f55e6fa9a94d0fdece02166df2bd5ca95e 100644 (file)
 void ff_rtp_send_xiph(AVFormatContext *s1, const uint8_t *buff, int size)
 {
     RTPMuxContext *s = s1->priv_data;
+    AVStream *st = s1->streams[0];
     int max_pkt_size, xdt, frag;
     uint8_t *q;
 
-    max_pkt_size = s->max_payload_size;
+    max_pkt_size = s->max_payload_size - 6; // ident+frag+tdt/vdt+pkt_num+pkt_length
 
     // set xiph data type
     switch (*buff) {
@@ -66,7 +67,7 @@ void ff_rtp_send_xiph(AVFormatContext *s1, const uint8_t *buff, int size)
     // 0 - whole frame (possibly multiple frames)
     // 1 - first fragment
     // 2 - fragment continuation
-    // 3 - last fragmement
+    // 3 - last fragment
     frag = size <= max_pkt_size ? 0 : 1;
 
     if (!frag && !xdt) { // do we have a whole frame of raw data?
@@ -75,9 +76,12 @@ void ff_rtp_send_xiph(AVFormatContext *s1, const uint8_t *buff, int size)
         int remaining    = end_ptr - ptr;
 
         assert(s->num_frames <= s->max_frames_per_packet);
-        if ((s->num_frames > 0 && remaining < 0) ||
-            s->num_frames == s->max_frames_per_packet) {
-            // send previous packets now; no room for new data
+        if (s->num_frames > 0 &&
+            (remaining < 0 ||
+             s->num_frames == s->max_frames_per_packet ||
+             av_compare_ts(s->cur_timestamp - s->timestamp, st->time_base,
+                           s1->max_delay, AV_TIME_BASE_Q) >= 0)) {
+            // send previous packets now; no room for new data, or too much delay
             ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
             s->num_frames = 0;
         }