From patchwork Wed Jul 21 15:30:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaun Simpson X-Patchwork-Id: 28997 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp6327723ios; Wed, 21 Jul 2021 09:02:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpbOfLC2DEyXH1uZmQIKCztkIEEQTLB6oc/rb/iYyLBOxZmZ7pnzywPrlyYiF7qjVxGgfE X-Received: by 2002:a05:6402:64e:: with SMTP id u14mr48800006edx.122.1626883363823; Wed, 21 Jul 2021 09:02:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626883363; cv=none; d=google.com; s=arc-20160816; b=PqOeuGfSMHWWczWp1xnauRu9Wyzz9tc4Je7v/ZZOSWCsyoaXFj+G0+CezdDYUWGU4j FINy0UVkmMo9sjdZ/R/z5HR4KzKOfpK9u3+ERKszHBeqbALtIP6SnsiWfjl3FMRQTxEw 9TljSEu/tyWvoFCbSvA7b5aDZay/XopY/6ojYw2hNZKbT3pJKFWEeLjnz8AB73ve1RS7 v/4ly47Di0hIaRKzBGAA9qO/T2xIbPZR7itEzknSUwyd5D1XdnsUO76RxEhxm/342Vey Xih/Gv9Hz/Y1O3glxd7Y3N2T3a1h+HdCaK8ewmQzhfDtLYzZ32JWYZkTCBTASq6dHi5i burA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=eRVgf2E/Yco4UOumKUyHaTlPFpEsCVzW+CBo+d65iHM=; b=uj/dZVu7lQz2g85jSl9uFzkqK22C/PtGMlJdk270g5DdjOFektXNEYRqrRvf4Ij6ot kiPLRbkQ0hGHCPX5iSb8ga+8Z0arpFDtKI83SyK0EPLKBF62x2Ge7qruqMEs8CGp0Cbm 5Jh1vePnfQ02P++2VKtOlSm4ZRX/f6l6F02J4mP74n9eRPKSxrvatI708cwKmYSApmmX LuGDumnAF8k783ou2H7dMLpV0NMrGZh5LwuOCZ7xifI+gMA4Mek0UlHaACgcVbpGfnVN 0H8nxh5tXAhd1QeaIGggFrz+Ruuaj9niw6n6u87HuXVbHGBTpRxIbhWzLfRx4/VsQqji 4I9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=SKPmQVcd; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dh3si26712140edb.260.2021.07.21.09.02.39; Wed, 21 Jul 2021 09:02:43 -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=@gmail.com header.s=20161025 header.b=SKPmQVcd; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4201F68A998; Wed, 21 Jul 2021 19:02:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0858268A302 for ; Wed, 21 Jul 2021 19:02:30 +0300 (EEST) Received: by mail-lj1-f173.google.com with SMTP id j1so3620696ljo.10 for ; Wed, 21 Jul 2021 09:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=3PgoCkOlPwHGRdhOiiSqDxHO1WQrZFq1Say5mkCdXgQ=; b=SKPmQVcdOou2mMQauhw+E89J26rgIlmNbo5rNNzYMw0sn4vdhGV+GT1GLuki30IHxy +/NshO4jwEKgGyWnw16r45FM9s3ksf03G9539cdLWrgscvU9HwcDX3bh3ns0W2pvAZSy 8c2RqK6GvTfyP3/FaPP5slG80uqEWFTEDOsaqc46hNcXAJyYOVD7yASCHj3/IL9S7DJz KXF6EvW3qSEIpasjG5CMv9kJ9XW3Vtt7H/4E6Vce/RUDKD7W/ErjV1SFLTQTTUeGSGxx 0b3bA6E5WhTzxP8+lnQkoRUcw6Z+y/ZkcetY7JCtTL0b4UOQoVxFjQVST6i4/Y5TLxn6 q83g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=3PgoCkOlPwHGRdhOiiSqDxHO1WQrZFq1Say5mkCdXgQ=; b=To74j+wipUuFrpdiHIpzzPAW/y0MRn+deTP00ESWvFq66lMAKWpgWj6NUfm9HR2M94 0mz17L0ZpKO/Joe/DPE2kTuzdSRB3ErRlJ/HekV9sDNopdXktwK0Iw2u+7tCk5kTnBfB /Zprc+AY9LzaOT4qyjAU/tMzPuWE3BhO/16C6GAQBElh6wcmFD++ocZ1VZYeBbqanyZ1 xPnPUGfaP2aLuKQNYJ1SoocFcRa+d4ggTULCxc5IkwOBg+ttHTSOxwFsqOJ82NDbIYxg bfUUdXcK4d4WOaA42D/fN5ygqbgB39pC6Z+AtJRzAbTCfzO6ofTCtvI4yWjzdIVIohnX 8xvQ== X-Gm-Message-State: AOAM53081h5fXeu1NRaXuzFKY5xVVZsyhyAGQcodMpBtEQJLwp3bP8TE ov9m1cSw2h1rnJU6rNVBli4hMr42AV/mkIp5Kd0LrUAblRvz9Q== X-Received: by 2002:ac2:5042:: with SMTP id a2mr26307633lfm.569.1626881420542; Wed, 21 Jul 2021 08:30:20 -0700 (PDT) MIME-Version: 1.0 From: Shaun Simpson Date: Wed, 21 Jul 2021 16:30:09 +0100 Message-ID: To: ffmpeg-devel@ffmpeg.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] Patch JPEG2000 Parser: Fix parsing of tile-part header 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: 6gVMshR8Y/eY Please find my patch attached. libavcodec/jpeg2000_parser: Fix parsing of tile-part header, and frames where the end of frame marker is at the end of the buffer. Fixes playback of Sol Levante MXF JPEG2000 file: VIDEO_e4da5fcd-5ffc-4713-bcdd-95ea579d790b.mxf http://download.opencontent.netflix.com.s3.amazonaws.com/SolLevante/imf/SolLevante_IMF_DolbyVision_PQP3D65_UHD_24fps.zip Bug Summary: When playing back VIDEO_e4da5fcd-5ffc-4713-bcdd-95ea579d790b.mxf, I noticed a regression between release 4.2.4 and release 4.3.2. Release 4.3.2 skips some frames. This can be seen in the first 15 seconds of the video. The Netflix logo should fade out. This regression is in the master branch and was introduced by commit d09c356 which adds a JPEG2000 parser. I have also tested this patch against my 3 other JPEG2000 samples. The patches are against master branch 13ec662 and fix playback of this file. 1. Fixed a off by one error when calculating the number of bytes to skip. 2. Added a 'continue' to the Tile part header reading, to skip the reaming paring code during a header read. 3. To deal with the end of frame tag being at the very end of the buffer, return the frame size during the current loop iteration. Is the PARSER_FLAG_COMPLETE_FRAMES flag supposed to be set for the Netflix sample? The files playback correctly if the flag is set, as each buffer contains a complete frame, but it is not set for the test case above. Thank you, Shaun Simpson Subject: [PATCH 1/2] libavcodec/jpeg2000_parser: Fix parsing of tile-part header, and frames were the end of frame marker is at the end of the buffer. Fixes playback of Sol Levante MXF JPEG2000 file: VIDEO_e4da5fcd-5ffc-4713-bcdd-95ea579d790b.mxf http://download.opencontent.netflix.com.s3.amazonaws.com/SolLevante/imf/SolLevante_IMF_DolbyVision_PQP3D65_UHD_24fps.zip Signed-off-by: Shaun Simpson --- libavcodec/jpeg2000_parser.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/libavcodec/jpeg2000_parser.c b/libavcodec/jpeg2000_parser.c index 123197fdca..b332a067e5 100644 --- a/libavcodec/jpeg2000_parser.c +++ b/libavcodec/jpeg2000_parser.c @@ -23,7 +23,6 @@ * @file * JPEG2000 parser. */ - #include "parser.h" /* Whether frame is jp2 file or codestream @@ -42,7 +41,6 @@ typedef struct JPEG2000ParserContext { uint8_t fheader_read; // are we reading uint8_t reading_file_header; uint8_t skipped_codestream; - uint8_t codestream_frame_end; uint8_t read_tp; uint8_t in_codestream; } JPEG2000ParserContext; @@ -57,7 +55,6 @@ static inline void reset_context(JPEG2000ParserContext *m) m->ft = 0; m->skipped_codestream = 0; m->fheader_read = 0; - m->codestream_frame_end = 0; m->skip_bytes = 0; m->read_tp = 0; m->in_codestream = 0; @@ -100,16 +97,13 @@ static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int buf_ m->skip_bytes--; continue; } - if (m->codestream_frame_end) { - reset_context(m); - return i; - } if (m->read_tp) { // Find out how many bytes inside Tile part codestream to skip. if (m->read_tp == 1) { - m->skip_bytes = (state64 & 0xFFFFFFFF) - 10 > 0? - (state64 & 0xFFFFFFFF) - 10 : 0; + m->skip_bytes = (state64 & 0xFFFFFFFF) - 9 > 0? + (state64 & 0xFFFFFFFF) - 9 : 0; } m->read_tp--; + continue; } if (m->fheader_read) { if (m->fheader_read == 1) { @@ -141,7 +135,8 @@ static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int buf_ if (pc->frame_start_found && m->ft == jp2_file) { m->skipped_codestream = 1; } else if (pc->frame_start_found && m->ft == j2k_cstream) { - m->codestream_frame_end = 1; + reset_context(m); + return i + 1; // End of frame detected, return frame size. } m->in_codestream = 0; } else if (m->in_codestream && (state & 0xFFFF) == 0xFF90) { // Are we in tile part header?