diff mbox series

[FFmpeg-devel,v2,1/1] libavformat/rtpenc_jpeg.c: add support for the DRI marker

Message ID 20240127050944.26604-1-sebas642@gmail.com
State New
Headers show
Series [FFmpeg-devel,v2,1/1] libavformat/rtpenc_jpeg.c: add support for the DRI marker | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Sebastien Cote Jan. 27, 2024, 5:09 a.m. UTC
This patch adds support for the DRI marker in the JPEG RTP encoder.
Apologies for the bad line breaks in the previous patch. The production line for this patch is 100% Linux.

Signed-off-by: Sebastien Cote <sebas642@gmail.com>
---
 libavformat/rtpenc_jpeg.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
diff mbox series

Patch

diff --git a/libavformat/rtpenc_jpeg.c b/libavformat/rtpenc_jpeg.c
index e4e95931f4..de2148a29d 100644
--- a/libavformat/rtpenc_jpeg.c
+++ b/libavformat/rtpenc_jpeg.c
@@ -33,6 +33,7 @@  void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size)
     uint8_t type = 2; /* initialized non-0/1 value for RTP/JPEG type check*/
     uint8_t w, h;
     uint8_t *p;
+    uint16_t rst_marker_interval = 0;
     int off = 0; /* fragment offset of the current JPEG frame */
     int len;
     int i;
@@ -155,6 +156,22 @@  void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size)
                     dht_size = 0;
                     continue;
             }
+        } else if (buf[i + 1] == DRI) {
+            uint16_t dri_size = 0;
+            if (i + 5 > size) {
+                av_log(s1, AV_LOG_ERROR, "Too short JPEG header. Aborted!\n");
+                return;
+            }
+
+            dri_size = AV_RB16(&buf[i + 2]);
+            rst_marker_interval = AV_RB16(&buf[i + 4]);
+
+            if (i + 1 + dri_size > size) {
+                av_log(s1, AV_LOG_ERROR, "Too short JPEG header. Aborted!\n");
+                return;
+            }
+
+            i += 1 + dri_size;
         } else if (buf[i + 1] == SOS) {
             /* SOS is last marker in the header */
             i += AV_RB16(&buf[i + 2]) + 2;
@@ -196,10 +213,16 @@  void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size)
         }
     }
 
+    if (rst_marker_interval > 0)
+        type += 64;
+
     p = s->buf_ptr;
     while (size > 0) {
         int hdr_size = 8;
 
+        if (rst_marker_interval > 0)
+            hdr_size += 4;
+
         if (off == 0 && nb_qtables)
             hdr_size += 4 + 64 * nb_qtables;
 
@@ -214,6 +237,11 @@  void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buf, int size)
         bytestream_put_byte(&p, w);
         bytestream_put_byte(&p, h);
 
+        if (rst_marker_interval > 0) {
+            bytestream_put_be16(&p, rst_marker_interval);
+            bytestream_put_be16(&p, 0xFFFF);
+        }
+
         if (off == 0 && nb_qtables) {
             /* set quantization tables header */
             bytestream_put_byte(&p, 0);