[FFmpeg-devel] [PATCH] libavformat/rtpenc_jpeg.c: Added support for DRI frames in MJPEG RTP packetization

rayjay 526528945 at qq.com
Mon Feb 19 10:31:16 EET 2024


Signed-off-by: rayjay <526528945 at qq.com>
---
 libavformat/rtpenc_jpeg.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/libavformat/rtpenc_jpeg.c b/libavformat/rtpenc_jpeg.c
index e4e95931f4..721c02ff76 100644
--- a/libavformat/rtpenc_jpeg.c
+++ b/libavformat/rtpenc_jpeg.c
@@ -37,6 +37,7 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size)
     int len;
     int i;
     int default_huffman_tables = 0;
+    uint16_t restart_interval = 0;
 
     s->buf_ptr   = s->buf;
     s->timestamp = s->cur_timestamp;
@@ -164,6 +165,9 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size)
                 return;
             }
             break;
+        } else if (buf[i + 1] == DRI) {
+            type |= 0x40;
+            restart_interval = AV_RB16(&buf[i + 4]);
         }
     }
 
@@ -203,6 +207,9 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size)
         if (off == 0 && nb_qtables)
             hdr_size += 4 + 64 * nb_qtables;
 
+        if (type & 0x40)
+            hdr_size += 4;
+
         /* payload max in one packet */
         len = FFMIN(size, s->max_payload_size - hdr_size);
 
@@ -214,6 +221,13 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size)
         bytestream_put_byte(&p, w);
         bytestream_put_byte(&p, h);
 
+        /* set dri */
+        if (type & 0x40) {
+            bytestream_put_be16(&p, restart_interval);
+            bytestream_put_byte(&p, 0xff);
+            bytestream_put_byte(&p, 0xff);
+        }
+
         if (off == 0 && nb_qtables) {
             /* set quantization tables header */
             bytestream_put_byte(&p, 0);
-- 
2.40.0.windows.1



More information about the ffmpeg-devel mailing list