From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 517F147371 for ; Mon, 15 Dec 2025 22:33:01 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'CTKHN28xUQzyUM6UGKK3UiCKH8koa8H4uw6xB3knv30=', expected b'Ai2wxumWc6k3h9C/8VcQu807P29onuDpafizJIoX3DM=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1765837960; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=CTKHN28xUQzyUM6UGKK3UiCKH8koa8H4uw6xB3knv30=; b=j6vxyjMhyS9IA8uil/NrufV9JOK1/u+6ubadTBqEr76kUg2la0dJNIR7MGirdIxDQMYjs llssSlyjh4vbZwG8UHgbFlRB9QQgADMjFXpYLsKW67t0hmZzUid0Y7cEKztzFji2dceuZsj LAGWZQB/vbngeY9z+NxyEs+UUHzEGRcp5yBagDThydKHvX6vw0f7aeiIUnRAeAZVO2MOzCh KxmhsW4/ouwaMWvsETHLs/SuV5hR6nLmTuyoiS0+yDgbkpOkyQt+Ax5OrlXgVZgyqacDoMR qGAoNN7zerJM9QTB/yxYvIRMZXGDCDKK642AG/iPFpXX8dSMDTF0wJGrtclw== Received: from [172.20.0.2] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 2A00C69086C; Tue, 16 Dec 2025 00:32:40 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1765837950; b=XAOGbIDNwgY6jUC3Ce7VyACZtO2eDJzHkJCbj6yS7+hAyVWHKIAInH1rWJmsK2vaBLIGd ESOiWirZ/5IvTGAuEe9dnVnN4WjTQQ4WjUEm1NOR+1pB7dvryuSYH5zkEWS8uQDG2pBpBLJ 9/Z6Oiji0sGoOGpN7mOg97v8Zu+4nNsg2t1HJWDQyn9FuqTGU7X3hyVTEsaBqK5wNSme0Om 7cS7O/mojkBHQOeDtQ4/CUfBr5UGgxF014M1Y1ePPLrK9OXtchS6AY0fAannlFTXj9aslrk zCNLXfGbs1SiEz1F6GvwRAOOa8uPJdVh6reTofXwQIOTF0ij3ZosBzlFmAZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1765837950; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=r3ERbBMItMkDIhj58H8ZrR6IK0cLPCp+NyD3X0hVll8=; b=dZGrUszNwYiJQK6gYp54nkSYpcGFdZPS3SrZCNwZqBjJVK1atYlgzA6T8Np10A7S1Meq3 cvzHpIfYdN0tFyl1u3uBRqA7BY/laMsnMWGokWqLl5x9Vi8p434iYAKStF71y+kGnR0lj/B QHLfpUHqzZ/wV42/c/4hbLHUmA5W+H+ah7NIb7RQxQHCeKWefLglpeX00G7llK1vJ5mSoyb H05gGDOvCPi7a5ifDkzrCA51kyQim3QY9C3kj1pYqC3mBjVtWLNxoUxfBkWUA61x5+qDNUo 1gUAiy8fIFeaa64q+zNTkR5Q+WHXfCKnETJsMuFUXL6+Njxt3sF6qxN80mGw== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1765837941; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=Ai2wxumWc6k3h9C/8VcQu807P29onuDpafizJIoX3DM=; b=Zi3aNuI1dOGhPV2shYemvPuD4tGt0dAsi7lQ7S79rzAODVxoo4WeNW2qpPE/2INmT4Sr0 vYo5UIAZS0MSPblZ9m4UO+ln36SCyvQ/vt9ZQUxa0G6CN7CQT8KmxbjU7srBovjM5xsAaIu FzbKKCERK6cWgkZJLrpRO+vEIIPqEG4rws6+m483rhvnIMCgSU4Bwj+kuo2R4svky7jTxAR hkA/Qrzh/531CI10tek0yCufzJW+HOqOTGrvx6NVv4cvo/upZznVDg2ZHtbiXNgLNI76CLi M0I6C7olUlgJWeLBDn4kchL1pzlxJQy3lDeIOjl+DF8Gc7AibrtjB+yZ4gtg== Received: from 55ca25703178 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 0D1FD690869 for ; Tue, 16 Dec 2025 00:32:21 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Dec 2025 22:32:20 -0000 Message-ID: <176583794122.60.14602168267083783692@2cb04c0e5124> Message-ID-Hash: 3QW65NYTAGFS73AEYPKNENEJVSUJLKDB X-Message-ID-Hash: 3QW65NYTAGFS73AEYPKNENEJVSUJLKDB X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] avcodec/jpegxs_parser: fix bitstream assembly logic (PR #21210) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: James Almer via ffmpeg-devel Cc: James Almer Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #21210 opened by James Almer (jamrial) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21210 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21210.patch Fixes samples like the one shared in #21997 >>From b44ba0848cde7bc74c3132b27ea0f6f2e2fc0521 Mon Sep 17 00:00:00 2001 From: James Almer Date: Mon, 15 Dec 2025 19:13:02 -0300 Subject: [PATCH 1/2] avcodec/jpegxs_parser: fix bitstream assembly logic JPEG-XS streams can have the bytes corresponding to certain markers as part of slice data, and no considerations were made for it, so we need to add checks for false positives. This fixes assembling several samples. Signed-off-by: James Almer --- libavcodec/jpegxs_parser.c | 66 +++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/libavcodec/jpegxs_parser.c b/libavcodec/jpegxs_parser.c index a6a3d1fcce..a9750b0a02 100644 --- a/libavcodec/jpegxs_parser.c +++ b/libavcodec/jpegxs_parser.c @@ -16,19 +16,28 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mem.h" + #include "bytestream.h" #include "get_bits.h" #include "jpegxs.h" #include "parser.h" #include "parser_internal.h" +typedef struct JPEGXSParseContext { + ParseContext pc; + + int eoc_found; +} JPEGXSParseContext; + /** * Find the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or -1 */ -static int jpegxs_find_frame_end(ParseContext *pc, const uint8_t *buf, +static int jpegxs_find_frame_end(JPEGXSParseContext *jpegxs, const uint8_t *buf, int buf_size) { + ParseContext *pc = &jpegxs->pc; int pic_found, i = 0; uint32_t state; @@ -46,15 +55,41 @@ static int jpegxs_find_frame_end(ParseContext *pc, const uint8_t *buf, } } - if (pic_found) { - if (buf_size == 0) - return 0; + if (buf_size == 0) { + if (jpegxs->eoc_found) { + pc->frame_start_found = jpegxs->eoc_found = 0; + pc->state = -1; + } + return 0; + } + + while (pic_found && i < buf_size) { + if (jpegxs->eoc_found) { + for(; i < buf_size; i++) { + state = (state << 8) | buf[i]; + if ((state >> 16) == JPEGXS_MARKER_EOC) { + if ((uint16_t)state == JPEGXS_MARKER_SOC) { + // New image + pc->frame_start_found = jpegxs->eoc_found = 0; + pc->state = -1; + return i - 1; + } else { + // False positive + i++; + jpegxs->eoc_found = 0; + break; + } + } + } + } + for(; i < buf_size; i++) { state = (state << 8) | buf[i]; if ((uint16_t)state == JPEGXS_MARKER_EOC) { - pc->frame_start_found = 0; - pc->state = -1; - return i + 1; + // EOC candidate + i++; + jpegxs->eoc_found = 1; + break; } } } @@ -181,10 +216,11 @@ static int jpegxsvideo_parse(AVCodecParserContext *s, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { - ParseContext *pc = s->priv_data; + JPEGXSParseContext *jpegxs = s->priv_data; + ParseContext *pc = &jpegxs->pc; int next; - next = jpegxs_find_frame_end(pc, buf, buf_size); + next = jpegxs_find_frame_end(jpegxs, buf, buf_size); if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { *poutbuf = NULL; @@ -199,9 +235,17 @@ static int jpegxsvideo_parse(AVCodecParserContext *s, return next; } +static av_cold void jpegxsparse_close(AVCodecParserContext *s) +{ + JPEGXSParseContext *jpegxs = s->priv_data; + ParseContext *pc = &jpegxs->pc; + + av_freep(&pc->buffer); +} + const FFCodecParser ff_jpegxs_parser = { PARSER_CODEC_LIST(AV_CODEC_ID_JPEGXS), - .priv_data_size = sizeof(ParseContext), + .priv_data_size = sizeof(JPEGXSParseContext), .parse = jpegxsvideo_parse, - .close = ff_parse_close, + .close = jpegxsparse_close, }; -- 2.49.1 >>From 55fb11f3941e5a9cf5cbdd32b90a7d7b7cf65c44 Mon Sep 17 00:00:00 2001 From: James Almer Date: Mon, 15 Dec 2025 19:25:49 -0300 Subject: [PATCH 2/2] tests/fate/demux: add a raw JPEG-XS demux test Use the concat protocol, to test the parser's capabilities to differentiate between EOC maker before SOC marker, on top of false EOC marker positives and EOC maker on EOF. Signed-off-by: James Almer --- tests/fate/demux.mak | 3 +++ tests/ref/fate/jxs-concat-demux | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 tests/ref/fate/jxs-concat-demux diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak index ad1046a453..5ad576608e 100644 --- a/tests/fate/demux.mak +++ b/tests/fate/demux.mak @@ -169,6 +169,9 @@ fate-ts-demux: CMD = ffprobe_demux $(TARGET_SAMPLES)/ac3/mp3ac325-4864-small.ts FATE_FFPROBE_DEMUX-$(CONFIG_MPEGTS_DEMUXER) += fate-ts-timed-id3-demux fate-ts-timed-id3-demux: CMD = ffprobe_demux $(TARGET_SAMPLES)/mpegts/id3.ts +FATE_FFPROBE_DEMUX-$(call PARSERDEM, JPEGXS, IMAGE_JPEGXS_PIPE, CONCAT_PROTOCOL) += fate-jxs-concat-demux +fate-jxs-concat-demux: CMD = framecrc "-i concat:$(TARGET_SAMPLES)/jxs/lena.jxs|$(TARGET_SAMPLES)/jxs/lena.jxs -c:v copy" + FATE_SAMPLES_DEMUX += $(FATE_SAMPLES_DEMUX-yes) FATE_SAMPLES_FFMPEG += $(FATE_SAMPLES_DEMUX) FATE_FFPROBE_DEMUX += $(FATE_FFPROBE_DEMUX-yes) diff --git a/tests/ref/fate/jxs-concat-demux b/tests/ref/fate/jxs-concat-demux new file mode 100644 index 0000000000..bb2378043d --- /dev/null +++ b/tests/ref/fate/jxs-concat-demux @@ -0,0 +1,7 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: jpegxs +#dimensions 0: 256x256 +#sar 0: 0/1 +0, 0, 0, 1, 131072, 0x75165e30 +0, 1, 1, 1, 131072, 0x75165e30 -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org