[FFmpeg-devel] libavformat/rtpdec_jpeg.c patch to allow fragmentation offset to include q header and table data
Hayden Myers
haydenm315 at gmail.com
Fri Sep 10 21:48:22 EEST 2021
>From fb2b280e44b785b99b27c24503c61574168701b9 Mon Sep 17 00:00:00 2001
From: Hayden Myers <hmyers at skylinenet.net>
Date: Fri, 10 Sep 2021 14:35:28 -0400
Subject: [PATCH] libavformat/rtpdec_jpeg.c: Allow fragmentation offset to
include q header and data
Some jpeg over rtp streams include the quantization header and table data
in the
reported fragmentation offset value of the jpeg header. ffmpeg stores q
table
data separate from the jpeg stream data. When the fragmentation offset is
compared
against the current position in the jpeg frame, it's off by q header + q
data bytes.
This results in all packets being dropped. It thinks there's data loss,
but there
really isn't. Added a conditional to check if the offset differs by q
header +
q data bytes, before dropping the packet.
Signed-off-by: Hayden Myers <hmyers at skylinenet.net>
---
libavformat/rtpdec_jpeg.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index b32d074136..4ec9fc8bd9 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -211,6 +211,7 @@ static void create_default_qtables(uint8_t *qtables,
uint8_t q)
}
}
+
static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
AVStream *st, AVPacket *pkt, uint32_t
*timestamp,
const uint8_t *buf, int len, uint16_t seq,
@@ -350,10 +351,27 @@ static int jpeg_parse_packet(AVFormatContext *ctx,
PayloadContext *jpeg,
return AVERROR_INVALIDDATA;
}
- if (off != avio_tell(jpeg->frame) - jpeg->hdr_size) {
- av_log(ctx, AV_LOG_ERROR,
- "Missing packets; dropping frame.\n");
- return AVERROR(EAGAIN);
+ if (off != (avio_tell(jpeg->frame) - jpeg->hdr_size)) {
+
+ /* Take into account that the fragment offset may include the quant
+ * table data. Allow the offset to differ by the size of the
+ * q header and table.
+ */
+
+ //Default to 2 * 64 byte tables for 8 bit precision.
+ uint8_t qtable_len = 128;
+
+ // Use the q table len value stored in the ctx
+ if (q >= 127 && q < 255)
+ qtable_len = jpeg->qtables_len[q-128];
+
+ // account for MBZ, Precision, and Length bytes.
+ qtable_len += 4;
+
+ if (off != (avio_tell(jpeg->frame) - (jpeg->hdr_size -
qtable_len))) {
+ av_log(ctx, AV_LOG_ERROR, "Missing packets; dropping
frame.\n");
+ return AVERROR(EAGAIN);
+ }
}
/* Copy data to frame buffer. */
--
2.25.1
More information about the ffmpeg-devel
mailing list