From patchwork Mon Aug 23 23:23:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hayden Myers X-Patchwork-Id: 29747 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp2517747iov; Mon, 23 Aug 2021 16:23:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2NdqVLm477V+cr+fiTMRtp0bm50Hj6+ITtKWnZK0/8vX9ang7sKNJJsz2cgG93sizfOCG X-Received: by 2002:a17:906:6bc5:: with SMTP id t5mr11298281ejs.340.1629761017939; Mon, 23 Aug 2021 16:23:37 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id jt11si15923742ejb.125.2021.08.23.16.23.37; Mon, 23 Aug 2021 16:23:37 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@SkylineTechnologySolutions.onmicrosoft.com header.s=selector2-SkylineTechnologySolutions-onmicrosoft-com header.b=QiRwRZ2M; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D77EA689881; Tue, 24 Aug 2021 02:23:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (unknown [40.107.220.102]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D99F668021B for ; Tue, 24 Aug 2021 02:23:23 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YBJ0ICdmnP3WM+OAeF/yZzaRzpkZPSq4FFHab/qJQOPSdS1lmCZNePx++M/HFo1Rp541Vx/vVuAsAXCxwmQ3BRW5kEejZG0qrLc81yXcCibuutFdhIi39MOaqfDg3v7AmDSIENmGLfrJcdhfQiOrhqvW6YGzY4kObwMjVm8pN/L4izmyv9zSnN9o5UOhZY1b4EX2L4fL1Y1fTIlcSdZA1J8Xi51FvTh93wbP77maQ5lyX3eoYRBEtAq5OcOyaorjI/T2P6e6rFTMxIUuyJjgMLHrr4ChvQqSN1NTJbcyc+BZvdA0aVaNyAgvE5a+tDD+GjYVrrIz+WmKSVAMPOYiAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3B5XgPoV5DgcTOBzMIF2RI+LxtMuP2bRC6cE2HUOAzc=; b=Ab+04bTywk26YbaARBtXM000MXtl2W0AyrMi+VAYYie4LE6U2HOAbZ1WR+yayW08P2iFhvWKoN42lSAXmYsnH7yZrlN7KZsg00/icJzM35JL6VFOq5nuDKw12WdHXjCXHAkWl4CXgG7pIsOvzoOJtUD1iGNgT3xnU+TRF3x6IcqZOn72I5t0sAcZ7QdFHsU1hkxNGtavfW/DKNV/gdYc+UfbxIH7W2Sr/jg83a1DjfRlXiLiP0BhRa6EIxD7A3MI9TIaJpAAzIFkodU439rF+N9iaL8Pui6NT+oSCDGhOfsDBTmQ4EEVjJRT9JFsrLDR6yFP4BKyiUzmNH4jMXwdRQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 191.237.4.149) smtp.rcpttodomain=ffmpeg.org smtp.mailfrom=skylinenet.net; dmarc=bestguesspass action=none header.from=skylinenet.net; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=SkylineTechnologySolutions.onmicrosoft.com; s=selector2-SkylineTechnologySolutions-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3B5XgPoV5DgcTOBzMIF2RI+LxtMuP2bRC6cE2HUOAzc=; b=QiRwRZ2MttXiYqsauhD8qFmZfYGatj/Qxl1gYiDyIxf17JVznzExafM7mx/xJRDJVOFX0BsdjQXpGwTHjr8P70QeskVE0b6QVoLRWZccviaPQLwcnGmG0ksT+n8AVoSlzkGXTTgdjSE6KpJA/A4I7304E8FU5P34pE6DdsBvlLs= Received: from DM5PR1401CA0007.namprd14.prod.outlook.com (2603:10b6:4:4a::17) by CH0PR10MB4825.namprd10.prod.outlook.com (2603:10b6:610:da::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.21; Mon, 23 Aug 2021 23:23:18 +0000 Received: from DM6NAM04FT018.eop-NAM04.prod.protection.outlook.com (2603:10b6:4:4a:cafe::f4) by DM5PR1401CA0007.outlook.office365.com (2603:10b6:4:4a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Mon, 23 Aug 2021 23:23:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 191.237.4.149) smtp.mailfrom=skylinenet.net; ffmpeg.org; dkim=none (message not signed) header.d=none;ffmpeg.org; dmarc=bestguesspass action=none header.from=skylinenet.net; Received-SPF: Pass (protection.outlook.com: domain of skylinenet.net designates 191.237.4.149 as permitted sender) receiver=protection.outlook.com; client-ip=191.237.4.149; helo=us1.smtp.exclaimer.net; Received: from us1.smtp.exclaimer.net (191.237.4.149) by DM6NAM04FT018.mail.protection.outlook.com (10.13.158.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4436.19 via Frontend Transport; Mon, 23 Aug 2021 23:23:16 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.102) by us1.smtp.exclaimer.net (191.237.4.149) with Exclaimer Signature Manager ESMTP Proxy us1.smtp.exclaimer.net (tlsversion=TLS12, tlscipher=TLS_ECDHE_WITH_AES256_SHA384); Mon, 23 Aug 2021 23:23:17 +0000 X-ExclaimerHostedSignatures-MessageProcessed: true X-ExclaimerProxyLatency: 16028399 X-ExclaimerImprintLatency: 3120792 X-ExclaimerImprintAction: 9477614131a746999e662c7037f7ea37 Received: from BLAPR10MB5169.namprd10.prod.outlook.com (2603:10b6:208:331::15) by BLAPR10MB4834.namprd10.prod.outlook.com (2603:10b6:208:307::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.22; Mon, 23 Aug 2021 23:23:13 +0000 Received: from BLAPR10MB5169.namprd10.prod.outlook.com ([fe80::d002:d568:b8dd:3743]) by BLAPR10MB5169.namprd10.prod.outlook.com ([fe80::d002:d568:b8dd:3743%9]) with mapi id 15.20.4436.024; Mon, 23 Aug 2021 23:23:13 +0000 From: Hayden Myers To: FFmpeg development discussions and patches Thread-Topic: [PATCH] libavformat/rtpdec_jpeg.c: quantization table headers not sent in every frame packet Thread-Index: AQHXmHVgQwv8hGCnrUG4RUE7h69Zlw== Date: Mon, 23 Aug 2021 23:23:12 +0000 Message-ID: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Authentication-Results-Original: ffmpeg.org; dkim=none (message not signed) header.d=none;ffmpeg.org; dmarc=none action=none header.from=skylinenet.net; x-ms-publictraffictype: Email X-MS-Office365-Filtering-Correlation-Id: c4801055-5a59-43d0-6e9a-08d9668cfd04 x-ms-traffictypediagnostic: BLAPR10MB4834:|CH0PR10MB4825: X-Microsoft-Antispam-PRVS: x-ms-oob-tlc-oobclassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: ziw79/0KJcDNVFSd4rl5TvC9uprvpe/EKc70WRlEad50qefeu/bcCt2hXt2qSy3s0SDyOuFA77IPIdWuZuDf6QwLnOtZrU2UDAO94XzT0qXmdd2BY3iw7DNk3VEHjXX/5QL0ssqyj63OupNoO0n1GCIa6ItPV+oPhcpf5zmK4DHi0fAV2KdEf66KMfOo/2hguqZz/XshJ9oJO4qTcsbo2YTkFkFuR4vjq3ISW9ruFT3pMWc9QckZ9oYlfZ6jfNIVfjSDPVuyQH9ezWndoZSTeuEdUH73gUkTPRMWoivJFgaE7jGcX82dc8vg5uARkHbaEjGOXSKZf+yKRjpIUDbEFtJxRSSwcaxg7Kup+R/yrHM2vN9/YlTYmVMtr1cV1Id/wmqHnhBGhV4VaM4vp2nsNkMlp8C1C6QGXQ1j3EwmdU1DK3VmkXATRDGyC63rXVqfCfGIepPct3DffwoSUIBX0uCNs3aKYgA8W6QF3hKDvAUTPYCqAqKRLiKNCpzTxIiIDXEm+6hcZBzqjF9vihZmodXrL4D1FEIcVdLHpaQyKwUKP3PzbPUZ9D/XbHf0exUC01uvO7Grfw8eyE7fb5Fv3vegkfriGlSMbrNkBc2eA8Y4rZyb0UTGYY5MisKVaO4hLcUE62twNbscrZE3wrGEL2tAbPYUBRD2VRo2HoSEyP2g4YDe7jdx+9CwF+3K+Z7uMY97q1EV+4nWXOQg+AIRCA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BLAPR10MB5169.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(396003)(366004)(346002)(39850400004)(376002)(55016002)(52536014)(8676002)(8936002)(6916009)(86362001)(66556008)(71200400001)(9686003)(5660300002)(6506007)(38100700002)(33656002)(83380400001)(478600001)(76116006)(66476007)(66946007)(66446008)(64756008)(26005)(186003)(38070700005)(316002)(7696005)(2906002)(122000001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?5rwywRSuwPhtHk5JvbIqMjd?= =?iso-8859-1?q?EMBe1Z7Y0M+mVgg4M/BdR847FahgXMOP6nI4RvvXeWsBuk4lv+tHlcRRPQ8b?= =?iso-8859-1?q?/+TMAf2euwLZzRTqi0Stwehiu0BAHRU5bjAV+UANNdURVJelUJ9M5isFpPMi?= =?iso-8859-1?q?IgegSzbqIOEdbNAUR+vnjfGJWN4cO6LyLteYxxOlcwy/3q72Y08tvy2yvFtj?= =?iso-8859-1?q?1ScN14tYBbVYdGLLerGCLVlF/6i40YStJ/HJbEbU1MDWYwfm6/KQPw+UwXUx?= =?iso-8859-1?q?Vl9WIrWmOv4YUIuzv0+l2DK5hgA2YkQPG/m6Kn5PIdV9sN/9UYZTqGvgRZ5t?= =?iso-8859-1?q?uEjWEyFnI4o0PW8XkSz3nLuav/YAa2/69K50CmQvmKRQLgSQyLsf4VWtoQnz?= =?iso-8859-1?q?y8MUbN1sS2iP2hIdW9O4SivAMU+0FTTHaPR3Wqt1Qe/A0UVxM5NFxUUpI0oI?= =?iso-8859-1?q?2/Bwl2/LyF0+8YvsmBVpq0fOHG2tC5s899nGz9rCVP0n8KTazygrII/TqSYl?= =?iso-8859-1?q?CO8UtjlYnxDky1Ka/UZzT5eL4kdtQ8oNBhmDoIKD3XYkd2mBZLX4ILy3PuAA?= =?iso-8859-1?q?HXOih1ON959naZXfaTcMmovf3Y4lFyZZ32LAmXHWcx3uOPnR85Ybl56pdhO1?= =?iso-8859-1?q?G1gJqv8VssE62nGUh5+ihz06lDpGCh8nn4ForZ4uwT6Rq34kktb3nNhxfYN+?= =?iso-8859-1?q?HHH/zyZ06FSqUvUq3cNAEzj+YVEhQnyIsxNhBdGKAYYYaiMyAvKE2mesj6KD?= =?iso-8859-1?q?xbvurPFNvm/3Pk80XRk6r8OVnATRv5IxbZmtUQVyjYaMjcV2HlsRCoYMtuf7?= =?iso-8859-1?q?83yzsmRcyZFuG0WQ1o5M12raN3WhX0qPqJdtB5y6nA4AuyrmqElDc27gIY49?= =?iso-8859-1?q?0ePLF+zDzRNjl1Dq/8K34oKIc8W2Or9hv907PV9D4932wI+IHMOQwS2Uo4PD?= =?iso-8859-1?q?nuf9LAHXWnJbBHPs/oVSGyZ4nBZpRV3B+5VWlemETH6Gh0D4CX7LcC+UQKJF?= =?iso-8859-1?q?BQUoz4/7TYCYI7rU4dWtiEX0GwPG0FTgJ5DcZkiXH7wRTNi6v73MTp9J0BhK?= =?iso-8859-1?q?nbMdEMiWNHy1SLccNIeUPYqApKNxALiL5CeSUUeRNraBrpUzg6Lu5UQKfvr+?= =?iso-8859-1?q?PSCD+eGjB1npKTGk4JM0YMEhbVym9fS7yu4y5wAaq09lXJURtwXIVIAKsXxO?= =?iso-8859-1?q?56ffw2tWPtXhezGmYvvlOPyiaXWzJ8RCXuWcaGoeSZ7pLavgnBgIEZ5Oiole?= =?iso-8859-1?q?N+5qewKRypZgb9PPQnZxIbIB/NBCJv3ZmSpZRZO6LNFFuZMVSAF2M65FND87?= =?iso-8859-1?q?uEWH8loOlj2GI8zL4X9SJftxqHjWqnpqw74e96qY=3D?= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4834 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DM6NAM04FT018.eop-NAM04.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: e5457970-b2b8-449a-2774-08d9668cfa59 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DHM8FJMIzEu4253DvlT4vlPsaMQxobfIJoqNMu19njcO2/NgC3RuLzXP+2eRdNQpolTx9sDf5nZP3xJhgRmy+B5gLBpHFkn37jtFxdUG05kBfI1zeK/kj79itJKJcfmRyokqY3bka7Fnr3TJPfOUk/2bCtyJN+r0wtR9SONkSjqjBOhc8BOvOuyZKx5tNNbNXDY6v0I33R85bkA7fjMAXBFH2et8jxOTfHXF7GJnRdUSQVB3ZauyJk+rFf3i4FpNoI7+9Uo42nJVmtiQXje+PW9oF7It9Jk9J5eCmSmh1dyaxnh3z2hHWC0X87oNV2LtBQ6DQw6S0dKQqbz0UvoXctY+aFnEcUIA4S0t3CJYbI6dvb1N3dk8KMKhL2oqXFRPxoFwrarAGBqrnmsYym1aj2qL78h4E5MmToAy8DdPdEjdaYzCppnCnAA9ruLMyOV+4T/nLeu+UDsO08TSUuCWu2nXj+qFeXDeWItARgZitQ5yHl7k6t7FOZmt3uhOZZbVHbdSwVqM2/bfYQWJWju+HBqqhbSy0Us6T0UYulWraJTdvzkqNskqFglkwX1TN3i8RKxqTzNkgAiFtb2BCXKhPK9MqOIo/tvwVUWq+5zfhwtoLUN0YcUWN3BfYt/e18Tx0A3nap9g/d4JuKZIEWbrVhyXpgq6w1rnh7CCVDRPlJdepiPdMd9Txe9XJAxR6PiqbH10mMAF2Yxj0ySolyeUkVNYxuwzvkDrajqqwXEwkimEqXdTqzAa17TRocvAmd0AyC6nWUtlhP1s/UJAk9yEkZ8yMUpYEsvrC8/xNQW6q6DCW2owMBeu4wVqnFH5i8vIEO40lPEn1pDOlyFPNeu8tQ== X-Forefront-Antispam-Report: CIP:191.237.4.149; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:us1.smtp.exclaimer.net; PTR:us1.smtp.exclaimer.net; CAT:NONE; SFS:(4636009)(396003)(136003)(376002)(346002)(39850400004)(46966006)(36840700001)(8936002)(33964004)(356005)(8676002)(82740400003)(7636003)(336012)(55016002)(186003)(7596003)(5660300002)(82310400003)(33656002)(47076005)(2906002)(166002)(52536014)(7696005)(26005)(478600001)(6506007)(9686003)(70586007)(70206006)(66576008)(6916009)(36860700001)(83380400001)(86362001)(316002); DIR:OUT; SFP:1102; X-OriginatorOrg: Skylinenet.net X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2021 23:23:16.9939 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c4801055-5a59-43d0-6e9a-08d9668cfd04 X-MS-Exchange-CrossTenant-Id: 6d9102c7-bb77-4c07-b670-10ed3ffb09cd X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=6d9102c7-bb77-4c07-b670-10ed3ffb09cd; Ip=[191.237.4.149]; Helo=[us1.smtp.exclaimer.net] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM04FT018.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB4825 X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] [PATCH] libavformat/rtpdec_jpeg.c: quantization table headers not sent in every frame packet X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: vClKhA6gX+ER MJPEG streams coming from Genetec VMS provide a quantization table for each frame, but only in the first packet. Before the packet data is copied to the frame buffer, a check is done to compare the fragment offset against the frame - header. The header is computed at the beginning of each frame. The offset ends up with a value of -132 because the header size includes the quantization table data, but the packet buffer doesn't. Created a function to detect if a quantization header isn't present when it should be, and use this to offset the extra bytes reported in the jpeg header. Signed-off-by: Hayden Myers cleanup Signed-off-by: Hayden Myers --- libavformat/rtpdec_jpeg.c | 54 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) -- 2.20.1 Hayden Myers Principal Software Engineer t: (410) 590-2027 diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c index b32d074136..6e1c6d6b44 100644 --- a/libavformat/rtpdec_jpeg.c +++ b/libavformat/rtpdec_jpeg.c @@ -211,6 +211,52 @@ static void create_default_qtables(uint8_t *qtables, uint8_t q) } } +/* + * If the q header isn't present in th packet, subtract from the + * jpeg header. The first packet in the frame could contain the q header. + * + * Some implementation do not include the quanization header with each packet. + * I'm specifically calling out Genetec VMS, but it could be rooted in specific + * cameras. + * + * @param ctx - The context, just used for logging. + * @param buf - current packet buffer + * @param q - quantizer value + * + * @return the number of bytes to remove if q header isn't present in the packet + * ,or 0 if the header is detected, or q <=127. + * + */ +static int get_q_hdr_bytes_to_remove(AVFormatContext *ctx, const uint8_t *buf, + uint8_t q) +{ + int ret=0, mbz=0, precision=0; + + /* Use the first byte to detect if the quantization table header is + * present. If mbz isn't zero, and the precision byte isn't <= 1 quant + * table isn't present, and we're into jpeg image payload data already. + */ + mbz = AV_RB8(buf); /* reserved byte should always be 0 */ + precision = AV_RB8(buf + 1); /* size of coefficients */ + /* best attempt to determine if the q header is present. Dont remove + * anything if a qtable is detected or q < 128. + */ + if ((mbz == 0 && precision <= 1) || q < 128) { + ret = 0; + // no header detected in pkt, must remove q hdr bytes + } else { + //1 byte - reserved MBZ + //1 byte - precision + //2 bytes - length + ret += 4; + //128 bytes - 2 * 64 byte tables (8bit precision) + ret += 128; + av_log(ctx,AV_LOG_WARNING, + "Q header missing, reducing jpeg->hdr_size\n"); + } + return ret; +} + 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, @@ -220,7 +266,7 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg, const uint8_t *qtables = NULL; uint16_t qtable_len; uint32_t off; - int ret, dri = 0; + int ret, dri = 0, q_hdr_bytes_to_remove = 0; if (len < 8) { av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n"); @@ -235,6 +281,7 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg, height = AV_RB8(buf + 7); /* frame height in 8 pixel blocks */ buf += 8; len -= 8; + q_hdr_bytes_to_remove = get_q_hdr_bytes_to_remove(ctx, buf, q); if (type & 0x40) { if (len < 4) { @@ -350,9 +397,8 @@ 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"); + if (off != (avio_tell(jpeg->frame) - (jpeg->hdr_size - q_hdr_bytes_to_remove))) { + av_log(ctx, AV_LOG_ERROR, "Missing packets; dropping frame.\n"); return AVERROR(EAGAIN); }