From patchwork Fri Nov 20 07:19:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23790 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 67ABC44B17A for ; Fri, 20 Nov 2020 09:31:36 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C43F768BA9C; Fri, 20 Nov 2020 09:25:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4ED9468BA7B for ; Fri, 20 Nov 2020 09:24:51 +0200 (EET) Received: by mail-ej1-f67.google.com with SMTP id s25so11496100ejy.6 for ; Thu, 19 Nov 2020 23:24:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=bpvjtuL0904bHagDoLTOGnC3g0rjuC8b7GCnYbcjLBA=; b=X22EoSDO7UNQq8X/ujZGCODPQs7Rpp1SUhZqxWZU5wSVYAjEttE0hBK93B+XXYFiUp /KQneIwGY4SIkU4SMMqVlAylP8KtU4LWtvrCu2c0OQYuAm2XRmd96Z1yF/DAHEUI4L1A Ka386Mp4ufPn7FnHLqMlhzCj2Kuk/+n82TqjHPpHhh+zl/oqLKPMCLF8FbU9Fqg5syQA YXqAMUu1xR0We+wIajKYGJ++2otlut8uqnKrsWACKcrErqA1fOO7ZtYOXYnEOfJbNiJR TBrFQF2yECn3Rxty/1/Uc5uQxDM9HyckvfmmY9/pNecPM43Km6QC3kwa/MxZd+iltIX5 0CsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=bpvjtuL0904bHagDoLTOGnC3g0rjuC8b7GCnYbcjLBA=; b=kV7WbB7mYeagVA8ID06QguMVt1XSGACccAwv3wRFC1JVwi8bjde/Mxk8t7uPOyZIM+ oHUwPuCl4xbeNavjoCCefkqSg/82cnPUoEq42HALXWxUcMzNtGwHPXZZG4D6OBM6YiBP X4NgBi4HpdBRkL0X0Rgy/Ff/rE3HaFbKTd1QuUs91c5m/mLGj9RG+yHvjf3j9mqXxm86 JPrpONgXVj134SCInxWJrCXxBdYTR4m4xp8RSX9S6e8QC/WYqq6eSw1JKXjPvW9a6bhh 56QLAoYC1FT4uuSbUNjJUuS5Vucx6d5OjkwDm84/p1ErrgCLS7c4YmMFPM6+U65Gwbsn +dQA== X-Gm-Message-State: AOAM5323KAg3Lws+JWOO+Hyl83tYiqxCdqNjunocwMzpe/FhtVfpH4Sd SjqMrnNCVwynXOLGQJaB8uH2GzwnKPdTxA== X-Google-Smtp-Source: ABdhPJwC+Ep1vUUMC7MfMSkIkK0+5TXAP6oeklGWYOW5YJNi8GNJvunLz4ybIQbya/3s+W4GVyCMPg== X-Received: by 2002:a17:906:79c4:: with SMTP id m4mr30647821ejo.26.1605857090431; Thu, 19 Nov 2020 23:24:50 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id lz27sm779419ejb.39.2020.11.19.23.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:24:49 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:19:13 +0100 Message-Id: <20201120072116.818090-41-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> References: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 040/162] avcodec/motionpixels: Only create VLC iff it is going to be used X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" If the Huffman tree consists of only one entry (which has length zero), no tree is used at all for parsing as the VLC API currently can't handle this. So it makes no sense to create a VLC in this case. Commit 41b7389cade702383e59343561776f83bb26e17f added a check for whether creating the VLC should be skipped, but it also skipped decoding the packet and it used the wrong check: It checked max_codes_bits, the maximum length of code; but this value is only updated iff there is more than one Huffman entry. So if there is only one Huffman entry, and there was a previous frame with more than one entry, then a VLC was created unnecessarily; yet if there was no previous frame with more than one entry, then this frame will be skipped which is probably spec-incompliant. I have no sample for the latter. This commit improves the check to create a VLC iff it is going to be used. Signed-off-by: Andreas Rheinhardt --- libavcodec/motionpixels.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c index b48200b017..0bf153f883 100644 --- a/libavcodec/motionpixels.c +++ b/libavcodec/motionpixels.c @@ -324,8 +324,7 @@ static int mp_decode_frame(AVCodecContext *avctx, if (sz == 0) goto end; - if (mp->max_codes_bits <= 0) - goto end; + if (mp->codes_count > 1) if (init_vlc(&mp->vlc, mp->max_codes_bits, mp->codes_count, &mp->codes[0].size, sizeof(HuffCode), 1, &mp->codes[0].code, sizeof(HuffCode), 4, 0)) goto end; mp_decode_frame_helper(mp, &gb);