]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtpenc_xiph.c
avformat: Do not use AVFMT_RAWPICTURE
[ffmpeg] / libavformat / rtpenc_xiph.c
index 07086b1a12a952cd2a138c08e253e7e8a59e85c0..5b171c36a2a5258c7a2679298dc7f0127e27c4e8 100644 (file)
@@ -19,6 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intreadwrite.h"
+
 #include "avformat.h"
 #include "rtpenc.h"
 
 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) {
@@ -73,24 +76,29 @@ 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;
         }
 
         // buffer current frame to send later
-        if (0 == s->num_frames) s->timestamp = s->cur_timestamp;
+        if (0 == s->num_frames)
+            s->timestamp = s->cur_timestamp;
         s->num_frames++;
 
         // Set packet header. Normally, this is OR'd with frag and xdt,
         // but those are zero, so omitted here
         *q++ = s->num_frames;
 
-        if (s->num_frames > 1) q = s->buf_ptr; // jump ahead if needed
-        *q++ = (size >> 8) & 0xff;
-        *q++ = size & 0xff;
+        if (s->num_frames > 1)
+            q = s->buf_ptr; // jump ahead if needed
+        AV_WB16(q, size);
+        q += 2;
         memcpy(q, buff, size);
         q += size;
         s->buf_ptr = q;
@@ -111,8 +119,8 @@ void ff_rtp_send_xiph(AVFormatContext *s1, const uint8_t *buff, int size)
 
         // set packet headers
         *q++ = (frag << 6) | (xdt << 4); // num_frames = 0
-        *q++ = (len >> 8) & 0xff;
-        *q++ = len & 0xff;
+        AV_WB16(q, len);
+        q += 2;
         // set packet body
         memcpy(q, buff, len);
         q += len;