From patchwork Sat Sep 26 10:27:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22621 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 8BB6B44AF23 for ; Sat, 26 Sep 2020 13:36:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 68DFD68B825; Sat, 26 Sep 2020 13:36:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3247668B765 for ; Sat, 26 Sep 2020 13:36:23 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id k15so6591058wrn.10 for ; Sat, 26 Sep 2020 03:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HOAMOCocwFGbsW4hHsu6G3Vw3nEnkHBoTejpdtmziDg=; b=CGgGZQZP80lTk80B9lctVhaHj7sTRvKNzJtoVWPquQeJ8EmPqLieRrcyj7IHtABcyS eFLCYLXxrGBaamaIRZmUkmlwV/TVJY3FsMhxJd0W7wYULiSw3KBX5CeEmMANfbUz4UUt gwvYSicYQHWDv3BFSBzLh7Q/SnlcmQjViR16cdfT76Fad3sCkxG7Z0O05UKWRSnt3hCl lHt9ZAF76x+tdhHzpoTOke6jRcvYalotXNdqxD9mFedoALzyETHSJh00aBVJiJPW/e0a f330746VwD8ondJWz354X7j5c4GyGg5Z0PYr0acsJFFsFf641rwUMqrq6fZv71I90qtA hsHw== 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:mime-version :content-transfer-encoding; bh=HOAMOCocwFGbsW4hHsu6G3Vw3nEnkHBoTejpdtmziDg=; b=iglk6gVB+/RkY6QfdyTg8GeZeFENmtMpOtZa+e3PZ+oFMjloxBYjEVf3siWkWxyHb9 gejh6s1DAJzkBC4ROZLBTzhLaHUN06rFlRSBwtznCe33pKHpehWrP/Vbm5AcWiZaNh9b jRKGYtGkIa4vq5pRIyMPz7p83wne5bUAUN65LLykmWSo7uxrteXO05AlkTqDkQn6k+7s yilOAG/z3bHgQU8atG0TfmDhJ+f5roeBKM4hvLl1aravOdb4e8OE1moyQz1DVQllPeZ0 Q2Eu0cLj3VI6SzgblBKWxXlG2Lla7BQHrEv1KQHsOCcTWtrudAbsyiLGOCzPu3b+nI2c HnuA== X-Gm-Message-State: AOAM531ZJi3Jts0b3Tv3gbrK0Pu3TlsaeRhpcMgy9rrGzL4fvlcuyeuV /79Im939l20fRzgS+ZnUC+/R37WTuFg= X-Google-Smtp-Source: ABdhPJyDRIb3Y/eIn7IPONK2X77pPBWwO9LVMHOCnWq/R1JYutviZBXPVU62OOc+nYkD+azZFnUBnw== X-Received: by 2002:adf:c5c3:: with SMTP id v3mr9214567wrg.205.1601116093109; Sat, 26 Sep 2020 03:28:13 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:28:12 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:40 +0200 Message-Id: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/25] avcodec/photocd: Simplify parsing Huffman tables a bit 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/photocd.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libavcodec/photocd.c b/libavcodec/photocd.c index 057c9d33d4..8fd4536a65 100644 --- a/libavcodec/photocd.c +++ b/libavcodec/photocd.c @@ -245,21 +245,20 @@ static av_noinline int decode_huff(AVCodecContext *avctx, AVFrame *frame, int x2, idx; for (; get_bits_left(&g) > 0;) { - if ((show_bits(&g, 24) & 0xfff000) == 0xfff000) + if (show_bits(&g, 12) == 0xfff) break; skip_bits(&g, 8); } - shiftreg = show_bits_long(&g, 32) & 0xffffff00; - while (shiftreg != 0xfffffe00) { + shiftreg = show_bits(&g, 24); + while (shiftreg != 0xfffffe) { if (get_bits_left(&g) <= 0) return AVERROR_INVALIDDATA; skip_bits(&g, 1); - shiftreg = show_bits_long(&g, 32) & 0xffffff00; + shiftreg = show_bits(&g, 24); } - skip_bits(&g, 16); - y = show_bits_long(&g, 23) & 0x1fff; - skip_bits(&g, 8); + skip_bits(&g, 24); + y = show_bits(&g, 15) & 0x1fff; if (y >= height) break; type = get_bits(&g, 2); From patchwork Sat Sep 26 10:27:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22626 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:c650:0:0:0:0:0 with SMTP id k77csp1722509ybf; Sat, 26 Sep 2020 03:36:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0ApwiK3GLnISlQJ52McvE5CMebMQUnvrPKtZfYQm2tTA7lIgKrYUeTnNFv7iZpYE+ByDq X-Received: by 2002:adf:f88d:: with SMTP id u13mr9593133wrp.213.1601116572372; Sat, 26 Sep 2020 03:36:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601116572; cv=none; d=google.com; s=arc-20160816; b=z0hnap1Pl/vCF6ZtOiStCmvYtu5Esag8hUNoQQmXengMEHtpr+1edCLola4aNdDn52 xDV6vczCAVosG4POVEcqhEe0tQVJDOu1uGLph8P+jRmEA77WkUDRsTmxq7xk4Ekx0bDm 7W2Im93m+hFhyXQ73O4NQQLvdfaS/92wqslD+4xIsv/RH6LYQ5BG8zb0iCuW55MB/i9T o5s/ea4VX9gRa0eEhUR3CVVeLQ/tt09TKJIpSKfytSqOkQqouCigwhKgj29b/l3L/XMQ 6NYM1Bh4N2GbPyKMW31o5YAXqF75msy4k71yq9qNdjG2lKPoxkVze9TsNmnFADkyXBXf fV7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=zOaOEgLynrQLAhnytKviDTh1vttlGolN3rWpTqfDty4=; b=aBYY1ZgKFGOYIQ/1rjXKfDxqMlI1CGblL602urUF6oWnLd25vanmMrH9PL6rf1rBPA jAMvSv4m8IXB8E5JyZcse2ZAp3ozgOpJmJaydFpWxtw7+58nDFDhyRaW55EPM8exxiCP 7EhKKy81g+rZ/wuONj+TT0ZsEjicP90M+RPqbIMUkv5l0c0r+I6vgTAW8tN7p5ZLPhXg O7TtOi+XMxTKn73vjHV7TtAzjtUxcLFhXwD+EWuBSJN6Vwph1GsMY2zLdt4L3czwbTIN VENNrP0kvPoUgssoUxOw/Bi9VcOYEZYHL8znkkUVPtQawSvWhp8bGDvj3oqyJN7UeZ+x /xfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=JxxhEoBI; 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 s8si5063360wrn.325.2020.09.26.03.36.12; Sat, 26 Sep 2020 03:36:12 -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=JxxhEoBI; 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 CD81668B773; Sat, 26 Sep 2020 13:36:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 09ABA68B76C for ; Sat, 26 Sep 2020 13:35:56 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id w2so1738297wmi.1 for ; Sat, 26 Sep 2020 03:35:56 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=d8P0qbWSO4yudPweHUYIG1bNvk+mceRmrQ1f2kQCMuQ=; b=JxxhEoBIxLzg1AMObtqdQBF9svHUISILp7epE6avqQVt+B8ukgxvk4hzsUfcyRYD2e nbxFjBfulUSqhf7e+gbVXld4uAA/f4ihVk+DC7z2839f7Sr5mgAB6CmShoHf1Yv4xVp7 wMFJVRonsCg4lpG2srYaXLONeIQ23aItGCrmdc9A2IkefBgyEVtztlLqKpM5zvnDsCjR 9NcMUBsmROg3vTk5hFAMcocUB4+C6lG3Ephmoyn1hi6j8qJIwoJwNFs8/vAF3c5SYi8m UojJo+yFmNwYc1/F9z8bYEg9gllVi+Dk/yCUhGZeJ3rN0brn0UBS8OX5vROj9XuzhB/Y TwoQ== 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:mime-version:content-transfer-encoding; bh=d8P0qbWSO4yudPweHUYIG1bNvk+mceRmrQ1f2kQCMuQ=; b=HqrJ/vOkSMs15h7sNcxEaVbw8p5VjR5TuHjGdtyHhSjiPU/pklWcOi3eaHL50TuCFX Zt7J/AKlHn1ykhuFMSfjlzL62njUpaRt5VPzh8KImaYaoupxzZ9LhHoNDPYAiboCvcsr tmVmRxbesBsmWchnjIN6h8v8i7SoYIATEQwRuguXWkKu1g+1XZBdni1+eXPrZdzlTxkv MT1RiqrEvIwM9iSsd6PUimXEp06L4F2v/3ePs2Ekp2uyvgKPl/v5oxrYrTTKfiTDYuOs VmaOZGzgLKSMrcDh+YRTaRxCmweR4+vdsOLSOCS2LBFdRNbN48ckVqK+Q8qgZvTlgJkR TZ5Q== X-Gm-Message-State: AOAM530yrz+9XQBQmNZaBBsDKg5UHP9QQub1mM62XTNCgkSk7Ghvge/T nUvC7PibeOhtLInzjIsjbL6kJBbJerc= X-Received: by 2002:a05:600c:283:: with SMTP id 3mr2094147wmk.110.1601116192929; Sat, 26 Sep 2020 03:29:52 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:29:52 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:41 +0200 Message-Id: <20200926102804.228089-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/25] avcodec/bytestream: Add unchecked bytestream2 peek functions 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" X-TUID: cPfJvNbf4S7o Content-Length: 2424 Signed-off-by: Andreas Rheinhardt --- libavcodec/bytestream.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h index 0516a6e3dc..d0033f14f3 100644 --- a/libavcodec/bytestream.h +++ b/libavcodec/bytestream.h @@ -77,11 +77,15 @@ static av_always_inline type bytestream2_get_ ## name(GetByteContext *g) \ } \ return bytestream2_get_ ## name ## u(g); \ } \ +static av_always_inline type bytestream2_peek_ ## name ## u(GetByteContext *g) \ +{ \ + return read(g->buffer); \ +} \ static av_always_inline type bytestream2_peek_ ## name(GetByteContext *g) \ { \ if (g->buffer_end - g->buffer < bytes) \ return 0; \ - return read(g->buffer); \ + return bytestream2_peek_ ## name ## u(g); \ } DEF(uint64_t, le64, 8, AV_RL64, AV_WL64) From patchwork Sat Sep 26 10:27:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22600 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 CF14644A10F for ; Sat, 26 Sep 2020 13:30:01 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9C74D6882F0; Sat, 26 Sep 2020 13:30:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 454E5688291 for ; Sat, 26 Sep 2020 13:29:55 +0300 (EEST) Received: by mail-wm1-f46.google.com with SMTP id l15so1071628wmh.1 for ; Sat, 26 Sep 2020 03:29:55 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=bK0EC+GXViaFH33M/4LeX2M1YHVQCvF9jd2em1v4OGs=; b=PcNWnVcFoZ0rN3Kv8uwKwVbhSkzgYHdzQxmN+w1+4INW1xcNnuXgGnXx7sBMq81brs 4QXJIN8HWDpGVSsJOhueD/3Z58FUsbLnyzKdln87XeBuBZKT+gskejhpSEaDdDRORxo8 SreIqjvdq9In6zGpq25atU0OdBvJafB7PjdqBg1vnLmy/UMEgGzI2nlrvdywsQfP3/qw wDjzpGfFzfkkQVM9QhzqWbVemKYPyeT+BHauLeEAr2NrNY5BuIPQwQsVX/yclfSFtXCD AbFTsKXPmeBtHzDZhXyDfYFC6JEryk82Z8r4VnxmSWcVzOoXdAAHUL5MnVGPvQW4ANEX mAEw== 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:mime-version:content-transfer-encoding; bh=bK0EC+GXViaFH33M/4LeX2M1YHVQCvF9jd2em1v4OGs=; b=A0dySW70fwpOL1hMpXNuP7wOp+uD0RUNvY6hrssZeN7LI8IgeLfF2yCKhcQJ+is0Wu d1xgRAQlwi7/zRz8cMeOL8UQQEg9UCiWwY/b05OTc/dpRnmAbI861Kk3+LlIItO9pdHv v/l3VngkSLmJXNwKcFJvPcpUnovk4zprLbzPFjxoOu/pzR6r0bvDUKgRXVhb+SScnL17 XbgqLiTN0KucrZjFw3+wgBtuvjA2uO+mYjjGOaGXJUyU0840yIw3/5plDM8YLEQcuT80 v5PD7n1oQdL62JOQLjVPXgAJlAhWlc/+6I7QNDll+1YBzUEWthW2a8Q97Do892ZqsdOg kBag== X-Gm-Message-State: AOAM532I7S6zEwJAakaP7Sm4CLmDYjEMpn/zjurDduV6cTiu2Zpg4kuw /WBb6oBaCfn/9gaGJRhgeaunWEM2Ud8= X-Google-Smtp-Source: ABdhPJxKYT/sJXOL9XXLIrB3HWJjp5umZ5rsXWSKYZHQUkWkht7WxIyEgzF2XqOaAdrzBX3vgvyBZQ== X-Received: by 2002:a1c:f214:: with SMTP id s20mr2012440wmc.84.1601116194396; Sat, 26 Sep 2020 03:29:54 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:29:53 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:42 +0200 Message-Id: <20200926102804.228089-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/25] avcodec/magicyuv: Improve overread check when parsing Huffman tables 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/magicyuv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index b56d3e9d32..d2f6a9b01e 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -394,8 +394,13 @@ static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max) while (get_bits_left(gbit) >= 8) { int b = get_bits(gbit, 1); int x = get_bits(gbit, 7); - int l = get_bitsz(gbit, b * 8) + 1; + int l = 1; + if (b) { + if (get_bits_left(gbit) < 8) + break; + l += get_bits(gbit, 8); + } k = j + l; if (k > max || x == 0 || x > 32) { av_log(avctx, AV_LOG_ERROR, "Invalid Huffman codes\n"); From patchwork Sat Sep 26 10:27:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22601 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 E4B0D44A10F for ; Sat, 26 Sep 2020 13:30:03 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CD45D68B6A3; Sat, 26 Sep 2020 13:30:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5C3B3688291 for ; Sat, 26 Sep 2020 13:29:56 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id k10so3504744wru.6 for ; Sat, 26 Sep 2020 03:29:56 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=+jN7Q071KKHKtbC+UBvVZKje+7rDgsPvOk+FHcjpujQ=; b=EUbr8MhZMpRUMMr76CLqIjDouBxHLtyAbE8GPC5j4mkhqkVltuvXGD02yKP3vd7zlz T0qTTMLzGX0Vy6403Mu0y4mqFTZrLs01i14CG7Os8+ZSHTSj07/gDiBbiA+Xl0FEOkp7 7i3EIbsHDVOLWZmnqAXJdPA/9N6zQMRZS2Jbw9Ln++uT9EURPdukOnFjg55NUWZLneWv AxZ6W1TjNqTq6gWd9jmsKsjJ9wveE+GfQ4ntTl53T5XF7Rni/L1DGHGdooI34j2o+KgL K1dcX1nNjSj92bbTgQYMvT7aZd2wI3EAOlZCmNasxcfcEZBADZLAQeVEralETIfJi454 1Hew== 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:mime-version:content-transfer-encoding; bh=+jN7Q071KKHKtbC+UBvVZKje+7rDgsPvOk+FHcjpujQ=; b=C4BkUTp6xAgUx3zRTwcAP9zBAI8zMOKxTfEGPfL4Eh+yhlTcoJv/Juqf6ihEuaN31p YaqqoTlxF5Hf37c+GPiTLY38IHMg2m5oWbhFv8J25BOtlSCrWY02wrcL+eYP03JGbuP7 Y3fEDqFWiwYCzLam3+PctXQRbWcZQAJsnkqwPibMovg0qI9KnP0qiWV+GTA24wNXZOY9 M9oQpackTQ5VsWVjBwTQnW7sQLCJEi6m3EdsfgcJkloblWXwaW4+Va+kfY1U46edx/MP pueGKRFtAwBCEqymfSXfiRVXaHhJlY1Ra/Wl956aqd+OCtVaf53N0XNJYpyKyyTObt6f f1eQ== X-Gm-Message-State: AOAM533FA1isThOZm/jJ520P3o7WtZDk3DRMXqwynVAOKCxQKJj6Ss+q tYx0g5aY0dlnj+OUjYcyhRTzOajEe4U= X-Google-Smtp-Source: ABdhPJzLZ0wjQQzylMgkKenGifXvHMAqf/U7Zwbk30bcbD9XNT9QBVVe0c7RaeaPDiCk0xAcXj/uxw== X-Received: by 2002:adf:fed1:: with SMTP id q17mr8627496wrs.85.1601116195543; Sat, 26 Sep 2020 03:29:55 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:29:54 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:43 +0200 Message-Id: <20200926102804.228089-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/25] avcodec/diracdsp: Remove unused variable 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" Forgotten in ca3c6c981aa5b0af8a5576020b79fdd3cdf9ae9e. Signed-off-by: Andreas Rheinhardt --- libavcodec/diracdsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/diracdsp.c b/libavcodec/diracdsp.c index 4e08d3817e..80dfafd78b 100644 --- a/libavcodec/diracdsp.c +++ b/libavcodec/diracdsp.c @@ -195,7 +195,7 @@ static void dequant_subband_ ## PX ## _c(uint8_t *src, uint8_t *dst, ptrdiff_t s { \ int i, y; \ for (y = 0; y < tot_v; y++) { \ - PX c, sign, *src_r = (PX *)src, *dst_r = (PX *)dst; \ + PX c, *src_r = (PX *)src, *dst_r = (PX *)dst; \ for (i = 0; i < tot_h; i++) { \ c = *src_r++; \ if (c < 0) c = -((-(unsigned)c*qf + qs) >> 2); \ From patchwork Sat Sep 26 10:27:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22602 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 A945F44A10F for ; Sat, 26 Sep 2020 13:30:04 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 94A6468B6BF; Sat, 26 Sep 2020 13:30:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5A7E468B629 for ; Sat, 26 Sep 2020 13:29:57 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id q9so1720152wmj.2 for ; Sat, 26 Sep 2020 03:29:57 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=0rX9LFhMdqL15kYIN/NZgOFNmajDZeC8MsUbOpHJI30=; b=izohGwS+ayQiwGBx2GVUOP9amXp5dFuvsn4PR9mZIDGieeDONGsMhaUcpQ8Cz4BE8v 4qYU6mXE6rst1yPj52N/XuZTEDwFYqpeX5fkFpKAhGVHWoiH0Ejfmg96MXnY/VN0AQ1s 5jsk9/j6L9AyJMS8QeNicYJuI7VxHPurXxt0AQvrvTZO1B0QFfcnf9Z49yJicyxUwN+n 9vAhp3EPVRBEsUixNI1QUKSQJ7MLIqSjf6xmpUwzoghegtO3/LQIBnBoVIWV/d0v4xO2 gzKMEc4usuXXeonaLOH6vBXwys6g+hWOylLPLew85wxqR9ErTqij75QyEFd6SccSxrQD I6hg== 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:mime-version:content-transfer-encoding; bh=0rX9LFhMdqL15kYIN/NZgOFNmajDZeC8MsUbOpHJI30=; b=TYYPnpCR2WBKkHGEpWTmt+RxX/dwqb39hyZmmKxj2BhiNcQZMDsL3XKzjSXSOrUj/P xBiWwrLtcPKkwfN+nrbslyefhmFTNF09cPrWxL4g+9Hrjfj8ayI0Z/8Z25u2D16FUtMr TMOf7Nk26l6zC9odpFZnzBZVcStzGiVZAILeZh0zgWVWJdtJYn4J2bJB4SmEIw5tZwgf Za5C7p50XuJ17UC3A9OitwwJHuIE7BTuuCZ3L7Dg4DIz/gG9UHXf6QIUAY5bPHoZ2pfZ Ay7ekaNFHU6piwr0XtP3R02zhMVo9XGbWunqVYAFbzgyBblZGW5vmv7RLAgx4yd1jpcj Bqnw== X-Gm-Message-State: AOAM531bKQucG/eBleTLND/OCziKBCxDxLffn/ohwp6514LU0H+8Zu31 23/gUUCW6gX9VJSSeZ6dAGm/A/wGlQs= X-Google-Smtp-Source: ABdhPJxJuL9J1p2274FW+XfhzkP7MJre7G8K/bxjDLwb4nrZ/O14nP6oRH76RNUbNsHeRh1c3iI8aQ== X-Received: by 2002:a1c:3d44:: with SMTP id k65mr1987909wma.132.1601116196493; Sat, 26 Sep 2020 03:29:56 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:29:55 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:44 +0200 Message-Id: <20200926102804.228089-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/25] avcodec/magicyuv: Check early for invalid slices 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" Every plane of each slice has to contain at least two bytes for flags and the type of prediction used. Signed-off-by: Andreas Rheinhardt --- libavcodec/magicyuv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index d2f6a9b01e..6c29efc9f4 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -614,6 +614,8 @@ static int magy_decode_frame(AVCodecContext *avctx, void *data, return AVERROR_INVALIDDATA; s->slices[i][j].size = next_offset - offset; + if (s->slices[i][j].size < 2) + return AVERROR_INVALIDDATA; offset = next_offset; } From patchwork Sat Sep 26 10:27:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22622 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 EB37A44B03F for ; Sat, 26 Sep 2020 13:37:04 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D6C3568B79A; Sat, 26 Sep 2020 13:37:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9BE1B68B765 for ; Sat, 26 Sep 2020 13:36:58 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id b79so1877587wmb.4 for ; Sat, 26 Sep 2020 03:36:58 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=NGgsqxhRCPzn77KHdLUZlaCdXizQ8MZ5HxUMdbd8Y5w=; b=kV/00cGVPZXN2gM0Th8lOZ3qgfrPULxCPtKoWwDhStGr6PsDAOmGEm2gC4AY6KvgOt TZ275Eq9LLzb42w6tILqQenHgkafotrAn4/eUfHn/ogKmVKg36aqD6+WbT8H007PMGKn +J/K6jMPU+C9O+ezF8O3l8hHMWx3zFSU7lFB5hPVgIza0YZbtOFcDZ8c8Zatm/wwMYKC jEA2+c/Xp09mrfnM/DFn56Sh9ZxPdcczMM7R5j/Pxvx8UbTT5sg1tX1wbO5krEZlFj4v N6YhF0EKyNqTw1WozqwBDjeK2hVG2QSK3GHm5AgDm6tY786x5j4ORRfyBRL25gBot9ZO FfIQ== 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:mime-version:content-transfer-encoding; bh=NGgsqxhRCPzn77KHdLUZlaCdXizQ8MZ5HxUMdbd8Y5w=; b=haSp6cwHJ9we7K/7G5oL26nA8eKp8XtHIklUztko9/Kl7tsXoDZw9/2Ymn6bbJKM3B kQmboplp/B1D5jJH5FgoUDhkhryLEVRSG2EKsUEIzP4URsW84GXb4D0/AA4yU+RhOgJa Vq3fyV8pYYs/R5ef5wdLYGgebH69ISBnyF6wAmXTEQ82KDcq0yYAt8f7VaueQrUZOviM hZzWyG0Q326UIvXx8KA1tpcVg4mXBJCOI0J2vMpc0VWcESI5nT5BT5v8bc/c+9fLKnhz m9QmaMTQei4/AfsY0JAbrPSz6gdo8bFYapzJnOeIHyKRFbYjxb6ugRS4Sq0DKmYD02OG qNDg== X-Gm-Message-State: AOAM533KsYU00Nc4lpV4oano6ExAjR+8aNbDuRfGxa7Ra4TnF+LdaNZ7 MRIMII3PkO4chLQ26AjM0NpaJvuL/vY= X-Google-Smtp-Source: ABdhPJwR/lBQZOTmVqK5dQCR+uuUmq6qIr8ETUqO7iRmS+dMcAUj8YLu6kkiq74+mffcfvb/7+Qs0w== X-Received: by 2002:a1c:62c2:: with SMTP id w185mr1993484wmb.109.1601116197772; Sat, 26 Sep 2020 03:29:57 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:29:56 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:45 +0200 Message-Id: <20200926102804.228089-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/25] avcodec/magicyuv: Don't use GetBit API for byte-aligned reads 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/magicyuv.c | 45 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index 6c29efc9f4..f7dfef0eb8 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -270,27 +270,26 @@ static int magy_decode_slice(AVCodecContext *avctx, void *tdata, int sheight = AV_CEIL_RSHIFT(s->slice_height, s->vshift[i]); ptrdiff_t fake_stride = p->linesize[i] * (1 + interlaced); ptrdiff_t stride = p->linesize[i]; + const uint8_t *slice = s->buf + s->slices[i][j].start; int flags, pred; - int ret = init_get_bits8(&gb, s->buf + s->slices[i][j].start, - s->slices[i][j].size); - - if (ret < 0) - return ret; - flags = get_bits(&gb, 8); - pred = get_bits(&gb, 8); + flags = bytestream_get_byte(&slice); + pred = bytestream_get_byte(&slice); dst = p->data[i] + j * sheight * stride; if (flags & 1) { - if (get_bits_left(&gb) < 8* width * height) + if (s->slices[i][j].size - 2 < width * height) return AVERROR_INVALIDDATA; for (k = 0; k < height; k++) { - for (x = 0; x < width; x++) - dst[x] = get_bits(&gb, 8); - + bytestream_get_buffer(&slice, dst, width); dst += stride; } } else { + int ret = init_get_bits8(&gb, slice, s->slices[i][j].size - 2); + + if (ret < 0) + return ret; + for (k = 0; k < height; k++) { for (x = 0; x < width; x++) { int pix; @@ -385,21 +384,25 @@ static int magy_decode_slice(AVCodecContext *avctx, void *tdata, return 0; } -static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max) +static int build_huffman(AVCodecContext *avctx, const uint8_t *table, + int table_size, int max) { MagicYUVContext *s = avctx->priv_data; + GetByteContext gb; HuffEntry he[4096]; int i = 0, j = 0, k; - while (get_bits_left(gbit) >= 8) { - int b = get_bits(gbit, 1); - int x = get_bits(gbit, 7); + bytestream2_init(&gb, table, table_size); + + while (bytestream2_get_bytes_left(&gb) > 0) { + int b = bytestream2_peek_byteu(&gb) & 0x80; + int x = bytestream2_get_byteu(&gb) & ~0x80; int l = 1; if (b) { - if (get_bits_left(gbit) < 8) + if (bytestream2_get_bytes_left(&gb) <= 0) break; - l += get_bits(gbit, 8); + l += bytestream2_get_byteu(&gb); } k = j + l; if (k > max || x == 0 || x > 32) { @@ -440,7 +443,6 @@ static int magy_decode_frame(AVCodecContext *avctx, void *data, ThreadFrame frame = { .f = data }; AVFrame *p = data; GetByteContext gbyte; - GetBitContext gbit; uint32_t first_offset, offset, next_offset, header_size, slice_width; int width, height, format, version, table_size; int ret, i, j; @@ -632,11 +634,8 @@ static int magy_decode_frame(AVCodecContext *avctx, void *data, if (table_size < 2) return AVERROR_INVALIDDATA; - ret = init_get_bits8(&gbit, avpkt->data + bytestream2_tell(&gbyte), table_size); - if (ret < 0) - return ret; - - ret = build_huffman(avctx, &gbit, s->max); + ret = build_huffman(avctx, avpkt->data + bytestream2_tell(&gbyte), + table_size, s->max); if (ret < 0) return ret; From patchwork Sat Sep 26 10:27:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22603 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 8586044A10F for ; Sat, 26 Sep 2020 13:30:07 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 68AD268B5C6; Sat, 26 Sep 2020 13:30:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BA1FC68B6C2 for ; Sat, 26 Sep 2020 13:29:59 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id m6so6671500wrn.0 for ; Sat, 26 Sep 2020 03:29:59 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=y2UdPqqAJ/oar1DF4H9UCbS0I4d+1VA2SLRscs1oP9I=; b=dJfS1ga/lDlajG/0o2QBHa2gnxDUTrxWG/Td1gbIAD07YALKjYAg4DE4A8zxw+tP64 2PwrOF8TPib4Muafo8UfW6QvlRjn8L/FrPoqMD4wjsQo+ae08KU7YgLv7uFAG8xZZ7HF ldpxiURFTnZHZtisIss2L0iEKE8vEZNSOG2C7RfixDYoOSH4bzrGLUms5+ZzE/uQSqbs Ts+Fr2hKnh/HxpYeEfvx0MSFJ1rgBqXOY4IusvvoK4xy+vp8cVtCxetpofWAu/GtQ9wV G10de6D2hm709DcIkxYYKD5BjpTrsOZ6uN/OzWE2Zd/Y+Dpwb0pQovDgxsqos7J1D91Z L3tg== 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:mime-version:content-transfer-encoding; bh=y2UdPqqAJ/oar1DF4H9UCbS0I4d+1VA2SLRscs1oP9I=; b=DDoPwQiTTnndWvyhC4uSFX8FrsvrTArzOc8Iewjn6BDRe3XWe2WNGnB+xYHBNLV9vv 5FWC+GAobEuHprr77A7FQpkgOiA6ck0X0UNkb9Z8tugjPfQ07aJ8vB495r5ChRroFaIv SQxpLyv3Q6Rs7KeEUSD6obykwWL9mrzR1+WDh/wOyYuBWMIpfjNiRcE7SMSzsLN74KPR m3r9JW5j4K4eh1pqDgzpUc8nHUrropftNVqwvqeNUB+7EYvECyPf5rzAmwK/DaXJ34Sb xMu9+rWuLARaSo8YKrk1v/+GDijtUxbifnZUhZm98im7Q2iDDSLNxluCe3GacTb9IPHz 8ouw== X-Gm-Message-State: AOAM533++5TI7Z25WUYY0pya24NLZp4F+mIDGdNRwAksGNbno+zS/6ng lYbkZ14YcRUBj3oYfPhO7dDVHjm19B0= X-Google-Smtp-Source: ABdhPJwXj+WjO5Lg3tM4d8376VWvoou3Rww2SgBVlqquKLYkEG6mYyuVq+yOyIS3+1nzqK4LNenR3w== X-Received: by 2002:adf:94e3:: with SMTP id 90mr3742641wrr.380.1601116199004; Sat, 26 Sep 2020 03:29:59 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:29:58 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:46 +0200 Message-Id: <20200926102804.228089-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/25] avcodec/magicyuv: Use const uint8_t* for pointer to immutable data 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/magicyuv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index f7dfef0eb8..3413d8f298 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -63,7 +63,7 @@ typedef struct MagicYUVContext { int color_matrix; // video color matrix int flags; int interlaced; // video is interlaced - uint8_t *buf; // pointer to AVPacket->data + const uint8_t *buf; // pointer to AVPacket->data int hshift[4]; int vshift[4]; Slice *slices[4]; // slice bitstream positions for each plane From patchwork Sat Sep 26 10:27:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22604 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 B783C44A10F for ; Sat, 26 Sep 2020 13:30:08 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A192168B705; Sat, 26 Sep 2020 13:30:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4FC3968AB33 for ; Sat, 26 Sep 2020 13:30:01 +0300 (EEST) Received: by mail-wm1-f45.google.com with SMTP id e2so1887491wme.1 for ; Sat, 26 Sep 2020 03:30:01 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=9ei7XVcuYhTjW+ZgiXvg5Y5L+xrYqtR4VWV/XRYFhMM=; b=LtR9lCSD0hekITYoIhr7uEEqG4ClVjxJa7XllfokjMUb2rznBZEaYzxkY5PRAiD7XP xEI9NM1RRwAxWyyYxRbnpU4e9BErCPGC55YqnQhvqPdgggIVtSUFRKf24D8Yj6l4YPnF UOjxqSycLvauDFRfDvIw4rMFjsVDExt/wt0MH9DuLMePungw+b0SHs80Z1q0CrvSI/Tt xJqgw5Vw61R6eEM31gnDNTEW9OXqCPt9CBOaSZQlK4zI24P3Q8vCCQ7uDRUqMvk8zlQ7 QACrI/fGCRagcxvL3tJmBoflnUdsuJp4Tff1fztmLSJl+vknvLaC/dPGmVprz5INZBoA 6meA== 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:mime-version:content-transfer-encoding; bh=9ei7XVcuYhTjW+ZgiXvg5Y5L+xrYqtR4VWV/XRYFhMM=; b=eU/hGKktU4FhllyGU9XiyKfHTnxLfBQbfiIsITT7HMIWrY6ceFy9c3+r8lXWD26R54 D39fxiVqgwC3tT7+pUvMFqaafFPsqNOk7Gi0CbDixldz+PtPNZ+MG4Gy+vsnYYzn1HXt wY4vXliMUkeYjwA/HiTRetWArcQnnMI6hPuY1b+gWslh4V0wwf3Htrxg6k87WvYYJHQX 2HtiIaLAtpcJv+8qUvj1wVlsNP/4pYaNcWCuWil06BDgm5nU/DbaxvQtqnvulq+DLfAb UoBLA7f6o6NlDyrlD4cPllefULOTSqgxrElknGonhy7Vpg5IRhK/zBqxeqUF3vguK76G 4Olw== X-Gm-Message-State: AOAM530mluztF9w+ASdoGNgFXRyZumch9tooulnQT4oUvTZzp35gkzfG NkXCBGyxmd3T46hnD3XovvEVwuNpm/Y= X-Google-Smtp-Source: ABdhPJxdeLd/nFv6HiQVTWcOSX5lWbX5Do668Fov18Rwgi0zhSblJ01auOC0RhlNYQLu9g6ndl+D+Q== X-Received: by 2002:a1c:c256:: with SMTP id s83mr2041319wmf.93.1601116200127; Sat, 26 Sep 2020 03:30:00 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:29:59 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:47 +0200 Message-Id: <20200926102804.228089-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/25] avcodec/magicyuv: Replace implicit checks for overread by explicit ones 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/magicyuv.c | 49 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index 3413d8f298..93ee739093 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -442,23 +442,26 @@ static int magy_decode_frame(AVCodecContext *avctx, void *data, MagicYUVContext *s = avctx->priv_data; ThreadFrame frame = { .f = data }; AVFrame *p = data; - GetByteContext gbyte; + GetByteContext gb; uint32_t first_offset, offset, next_offset, header_size, slice_width; int width, height, format, version, table_size; int ret, i, j; - bytestream2_init(&gbyte, avpkt->data, avpkt->size); - if (bytestream2_get_le32(&gbyte) != MKTAG('M', 'A', 'G', 'Y')) + if (avpkt->size < 36) + return AVERROR_INVALIDDATA; + + bytestream2_init(&gb, avpkt->data, avpkt->size); + if (bytestream2_get_le32u(&gb) != MKTAG('M', 'A', 'G', 'Y')) return AVERROR_INVALIDDATA; - header_size = bytestream2_get_le32(&gbyte); + header_size = bytestream2_get_le32u(&gb); if (header_size < 32 || header_size >= avpkt->size) { av_log(avctx, AV_LOG_ERROR, "header or packet too small %"PRIu32"\n", header_size); return AVERROR_INVALIDDATA; } - version = bytestream2_get_byte(&gbyte); + version = bytestream2_get_byteu(&gb); if (version != 7) { avpriv_request_sample(avctx, "Version %d", version); return AVERROR_PATCHWELCOME; @@ -471,7 +474,7 @@ static int magy_decode_frame(AVCodecContext *avctx, void *data, s->decorrelate = 0; s->bps = 8; - format = bytestream2_get_byte(&gbyte); + format = bytestream2_get_byteu(&gb); switch (format) { case 0x65: avctx->pix_fmt = AV_PIX_FMT_GBRP; @@ -552,34 +555,34 @@ static int magy_decode_frame(AVCodecContext *avctx, void *data, s->magy_decode_slice = s->bps == 8 ? magy_decode_slice : magy_decode_slice10; s->planes = av_pix_fmt_count_planes(avctx->pix_fmt); - bytestream2_skip(&gbyte, 1); - s->color_matrix = bytestream2_get_byte(&gbyte); - s->flags = bytestream2_get_byte(&gbyte); + bytestream2_skipu(&gb, 1); + s->color_matrix = bytestream2_get_byteu(&gb); + s->flags = bytestream2_get_byteu(&gb); s->interlaced = !!(s->flags & 2); - bytestream2_skip(&gbyte, 3); + bytestream2_skipu(&gb, 3); - width = bytestream2_get_le32(&gbyte); - height = bytestream2_get_le32(&gbyte); + width = bytestream2_get_le32u(&gb); + height = bytestream2_get_le32u(&gb); ret = ff_set_dimensions(avctx, width, height); if (ret < 0) return ret; - slice_width = bytestream2_get_le32(&gbyte); + slice_width = bytestream2_get_le32u(&gb); if (slice_width != avctx->coded_width) { avpriv_request_sample(avctx, "Slice width %"PRIu32, slice_width); return AVERROR_PATCHWELCOME; } - s->slice_height = bytestream2_get_le32(&gbyte); + s->slice_height = bytestream2_get_le32u(&gb); if (s->slice_height <= 0 || s->slice_height > INT_MAX - avctx->coded_height) { av_log(avctx, AV_LOG_ERROR, "invalid slice height: %d\n", s->slice_height); return AVERROR_INVALIDDATA; } - bytestream2_skip(&gbyte, 4); + bytestream2_skipu(&gb, 4); s->nb_slices = (avctx->coded_height + s->slice_height - 1) / s->slice_height; - if (s->nb_slices > INT_MAX / sizeof(Slice)) { + if (s->nb_slices > INT_MAX / FFMAX(sizeof(Slice), 4 * 5)) { av_log(avctx, AV_LOG_ERROR, "invalid number of slices: %d\n", s->nb_slices); return AVERROR_INVALIDDATA; @@ -596,12 +599,14 @@ static int magy_decode_frame(AVCodecContext *avctx, void *data, } } + if (bytestream2_get_bytes_left(&gb) <= s->nb_slices * s->planes * 5) + return AVERROR_INVALIDDATA; for (i = 0; i < s->planes; i++) { av_fast_malloc(&s->slices[i], &s->slices_size[i], s->nb_slices * sizeof(Slice)); if (!s->slices[i]) return AVERROR(ENOMEM); - offset = bytestream2_get_le32(&gbyte); + offset = bytestream2_get_le32u(&gb); if (offset >= avpkt->size - header_size) return AVERROR_INVALIDDATA; @@ -611,7 +616,7 @@ static int magy_decode_frame(AVCodecContext *avctx, void *data, for (j = 0; j < s->nb_slices - 1; j++) { s->slices[i][j].start = offset + header_size; - next_offset = bytestream2_get_le32(&gbyte); + next_offset = bytestream2_get_le32u(&gb); if (next_offset <= offset || next_offset >= avpkt->size - header_size) return AVERROR_INVALIDDATA; @@ -625,16 +630,16 @@ static int magy_decode_frame(AVCodecContext *avctx, void *data, s->slices[i][j].size = avpkt->size - s->slices[i][j].start; } - if (bytestream2_get_byte(&gbyte) != s->planes) + if (bytestream2_get_byteu(&gb) != s->planes) return AVERROR_INVALIDDATA; - bytestream2_skip(&gbyte, s->nb_slices * s->planes); + bytestream2_skipu(&gb, s->nb_slices * s->planes); - table_size = header_size + first_offset - bytestream2_tell(&gbyte); + table_size = header_size + first_offset - bytestream2_tell(&gb); if (table_size < 2) return AVERROR_INVALIDDATA; - ret = build_huffman(avctx, avpkt->data + bytestream2_tell(&gbyte), + ret = build_huffman(avctx, avpkt->data + bytestream2_tell(&gb), table_size, s->max); if (ret < 0) return ret; From patchwork Sat Sep 26 10:27:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22605 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 863B944A10F for ; Sat, 26 Sep 2020 13:30:09 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6C27B68B729; Sat, 26 Sep 2020 13:30:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2036068AB33 for ; Sat, 26 Sep 2020 13:30:02 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id z4so6653009wrr.4 for ; Sat, 26 Sep 2020 03:30:02 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=r0I3+MMfdZvyJvZSbafZYem75Ej9Hix/EOrX3Y2a02g=; b=Qxcbe3kRrr+8tUAWs6YmA2iGRFRxXRQN5gDBMnoT5s0PbzGC4hPmsROpemT+q1DBe9 cSmhlwU0onRwQMeCTtbe125GFj5cjH+iWsj6v7yA6MqJMtpsDtEX59p9MFpLSaTkabZb OTFK0fbcFWsL6kMOJEYqS7aTd/gKBX0zE2pyAQuWz3Audssl4cbQUZOMbKSsOq2tIs+a 7yENdtBucPIlFs7FSOI3pmOa5zJd6ogbcHIjbkoNcDpay6eZjRiwOalmKZ3A1j7gWRR4 ClQa/1aE4cUyDYdFaOdW+xPqfcNELh4gcw1u1KE1SSRF6Rjwu5VG17O7kiSxyDRkpjFq NReA== 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:mime-version:content-transfer-encoding; bh=r0I3+MMfdZvyJvZSbafZYem75Ej9Hix/EOrX3Y2a02g=; b=rxHwsNy3oiTtcCidh+8wqaJAEMbIFR7dfNLZ1XjHYi41nv81fX+Wn85ohB4Jtbkfft QA4KqXJCbK9GYUucQc8LM1KKLTczCLUPFjU148FMKJXGKJQ5RvT/vwxBPuTW61Ks/jl+ 2QjXMhotqZmDhAVDeU5fltow3zMhKus3pYNKdZQ56McwvdaPVfZRm02k7JMorkdkmz3p saaN9AH3LL3bmIwKagadg7MvlsoM1bMv6Igbhkrt5Cyjn8N9BXX+pr3mtb1qQBvSdU9G qJQIpIcs1+TU8gdoKdti5PIQKbqdufl1We42U2iBZfM8eVCgtN0kGkoMwR3paFhxeKeI gfUw== X-Gm-Message-State: AOAM531uPueuopoLLBjFijkkf/HMNnmqQuJg7NsmxpPGK/6iecDCKwph A9XTUUY7YCkXt93Rd0zQYZ1G61Fq1Us= X-Google-Smtp-Source: ABdhPJxEsEUgOdbLhK3YYnvNeSPntqa77jn4FJUnr9hRE2HApK2A/iDYjpsyzfk9/eZzoUJNTOUscw== X-Received: by 2002:adf:d845:: with SMTP id k5mr8323902wrl.285.1601116201209; Sat, 26 Sep 2020 03:30:01 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:00 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:48 +0200 Message-Id: <20200926102804.228089-9-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/25] avcodec/magicyuv: Don't invert order unnecessarily 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" The MagicYUV decoder currently sets both the length and the symbol field of an array of HuffEntries; hereby the symbol of the ith entry (0-based) is just i. Then said array gets sorted so that entries with greater length are at the end and entries with the same length are ordered so that those with smaller symbols are at the end. Afterwards the newly sorted array is traversed in reverse order. This commit instead inverts the ordering and traverses the array in its ordinary order in order to simplify understanding. Signed-off-by: Andreas Rheinhardt --- This commit actually only exists to simplify understanding of the next two commits; apart from that, it is unnecessary. libavcodec/magicyuv.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index 93ee739093..1b3f4cfc6b 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -77,24 +77,23 @@ typedef struct MagicYUVContext { static int huff_cmp_len(const void *a, const void *b) { const HuffEntry *aa = a, *bb = b; - return (aa->len - bb->len) * 4096 + bb->sym - aa->sym; + return (bb->len - aa->len) * 4096 + aa->sym - bb->sym; } static int huff_build(HuffEntry he[], VLC *vlc, int nb_elems) { uint32_t code; - int i; AV_QSORT(he, nb_elems, HuffEntry, huff_cmp_len); code = 1; - for (i = nb_elems - 1; i >= 0; i--) { + for (unsigned i = 0; i < nb_elems; i++) { he[i].code = code >> (32 - he[i].len); code += 0x80000000u >> (he[i].len - 1); } ff_free_vlc(vlc); - return ff_init_vlc_sparse(vlc, FFMIN(he[nb_elems - 1].len, 12), nb_elems, + return ff_init_vlc_sparse(vlc, FFMIN(he[0].len, 12), nb_elems, &he[0].len, sizeof(he[0]), sizeof(he[0].len), &he[0].code, sizeof(he[0]), sizeof(he[0].code), &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0); From patchwork Sat Sep 26 10:27:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22630 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:c650:0:0:0:0:0 with SMTP id k77csp1723257ybf; Sat, 26 Sep 2020 03:38:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjLS2oskjEc4CABxR1vL0XTo29wWkvQmBD2BtJRBPFhyECZ37J5JomPFL/EXQiMaaikpHC X-Received: by 2002:adf:e852:: with SMTP id d18mr9535179wrn.40.1601116686599; Sat, 26 Sep 2020 03:38:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601116686; cv=none; d=google.com; s=arc-20160816; b=pxOBy5PRVOHyDceTHft+hzk5xSyzy4AqSTZ9kN33WZgU+IPZ4OPROKKkjhuZH9xDPf mkUazpVlXjs7aQSJ2SU6GR/qpr0iZ9f4YMGxbrDCe4ss+H8Uhrkl+NZU7Xm3MUdrotwQ AQQAnM2xFVez5JbUnqTZCa4U9HFswl1TiuhwJv3zZc8WpDng0kxtSDw7EmX9XCYIlRag NjadOmt3J4ZOL0ne96K5nOi35JQ2wxzwxYcJ0yOqclmInTG37lnfEWZQCvUAMgSUA5g1 uW1f66+BN2tCNrTfv/dJw4Skgx3EvqM9c26YeMWBXtQTsduNL8LDFurAeEGfVxzQ+f44 D2CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=EzDLyKtJJhLWR+tHu8WAvc0RI83G0VOIRgVEE+VVAqQ=; b=wdqQ8P3aUa/T+fFHRiYH1sH2SV8CdrOjrsGQv/20MHKMigTnUm49CJhG6H/7IvC6zB voofeVq6SAZrRth6paVwFJjRr4vrhSJ0PpviH5RaktkW350Da5VhuG7SxXJqvjuPlH+v TshkfFhLeSbh4c5QVCfH8J5gHUgyZnpdAIAUa24mD3dH6g69I0DqYvivYhgNyTAeHWtj GuCmRzJ7nznTFdSv0DLp+XF4ZaytxdwhPRaZxwOEehE5EdyUy0NHzzfxL1Gu28NjjRd2 kqUPNJZbFGhi6JReHuzUVtXK16BbPTocIjGatMrs3WFMagE3TUKOjg3mxaIkKvhlw2Lx rYDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=KW+ljCR+; 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 o17si5598641wrp.82.2020.09.26.03.38.06; Sat, 26 Sep 2020 03:38:06 -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=KW+ljCR+; 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 2D3FB68B86F; Sat, 26 Sep 2020 13:38:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A73A6883D0 for ; Sat, 26 Sep 2020 13:37:57 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id b79so1879023wmb.4 for ; Sat, 26 Sep 2020 03:37:57 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=HFoY4yfagmhajYWQNftN4u96sYQAzJO88WGqAq/APOY=; b=KW+ljCR+7fqZljGIwVjmFgZNd5KrFGH/GkIJRbmSdld+LapEnnS4Dzta/KduRUfrNF 6fWItXU6loTskxpj0mHiF/mguNJmnVuVdA+GnoxiXJnoWwDA7IGZlN96eIocL7mUBKku xecuWZ8nFE4c9EDuAgFwZEru6i/9awPDudQWECLdyWkPvz8UOJOgpua4gIv68TqpUEoj nZfyY/j0GB+CMj68cBnt+oG7hcH/Mibo4ugj14hiiKvdKcerHthJLp0Bbr5ndsERWhKg Hx2jELEI8yzc2Zx9S8R24XnwSR/UwGkD0fsu3mnvl+ZDFglURuys7getTiGGhlk7g+uh TX1g== 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:mime-version:content-transfer-encoding; bh=HFoY4yfagmhajYWQNftN4u96sYQAzJO88WGqAq/APOY=; b=F6RQ6MnOxMYmEQchoUDHmoAj3ykrOYhwUPdspPQslmCXFDugq43BAKHwem0NMBVGou TwNLesfSkY9vPshsu39g71NUzF3UslMyBTdxonYZKhUMysnTqpBrh360xqqiqh/QUNM5 PmMUhwSqh0+SF4hOqhzlLZoGhRlYjm7zA93JfdUNX9NSn4TStfKnzHllppkT+2NeyeDJ 0INFKMXfD9zp86mpMvB5VPXESXwMTs5DN6LAMfS/LocUfA/lNOw/11P5AEqF1V1ugWkQ ZR184uhce4qIxkhH/xBTXZO1UjglEBKOi+jeZZm0GNTR4RZ/VU5F2EFG5elAb5V6DJ3F DgIA== X-Gm-Message-State: AOAM533KzBtD9PObteMqqwS12CAfcNhtD/knjSbxDLzIdNkyyySvjXIJ gZS5NOaitNmU3x8uFI2hYeQ+6r6OPgc= X-Received: by 2002:a1c:9894:: with SMTP id a142mr1943852wme.167.1601116202251; Sat, 26 Sep 2020 03:30:02 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:01 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:49 +0200 Message-Id: <20200926102804.228089-10-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/25] avcodec/magicyuv: Fix building Huffman table 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" X-TUID: SuoPcKXXSjLK Content-Length: 2379 The MagicYUV format stores Huffman tables in its bitstream by coding the length of a given symbol; it does not code the actual code directly, instead this is to be inferred by the rule that a symbol is to the left of every shorter symbol in the Huffman tree and that for symbols of the same length the symbol is ascending from left to right. With one exception, this is also what our decoder did. The exception only matters when there are codes of length 32, because in this case the first symbol of this length did not get the code 0, but 1; e.g. if there were exactly two nodes of length 32, then they would get assigned the codes 1 and 2 and a node of length 31 will get the 31-bit code 1 which is a prefix of the 32 bit code 2, making the Huffman table invalid. On the other hand, if there were only one symbol with the length 32, the earlier code would accept this un-Huffman-tree. Signed-off-by: Andreas Rheinhardt --- libavcodec/magicyuv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index 1b3f4cfc6b..17dea69d76 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -86,7 +86,7 @@ static int huff_build(HuffEntry he[], VLC *vlc, int nb_elems) AV_QSORT(he, nb_elems, HuffEntry, huff_cmp_len); - code = 1; + code = 0; for (unsigned i = 0; i < nb_elems; i++) { he[i].code = code >> (32 - he[i].len); code += 0x80000000u >> (he[i].len - 1); From patchwork Sat Sep 26 10:27:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22607 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 2E3FD44A10F for ; Sat, 26 Sep 2020 13:30:12 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 17C4B68B75A; Sat, 26 Sep 2020 13:30:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 524C968B71E for ; Sat, 26 Sep 2020 13:30:04 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id s13so1705180wmh.4 for ; Sat, 26 Sep 2020 03:30:04 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=VqAFODf/gGeYQyAKcFpb2YFN/8JuXzgnWP2opuuL+3A=; b=RtlRPjUpUKu++vr/YPw+PUTbOrjwBHrghT0Fzm167iNPqtbiDo0vEDyN6ZGeFSnPZU 1RqEmgbgBzkb9e/oLSjX/JMaq7LwQe8OLEr6/TViErylXgtbYHEt7ukbHBCPIFzA8BKj dy6ZW4R1MGAP5XsJ+3w1KE2++VQovehZ0BqkptCozyOO6BYjM4Oed7/XnjCVMSlmYWIh vx9G/JzqJntX86Q4hfrE7JTFDszT6QEsXvGTT6Er648ouB8K8S9mTUwKfXkGRQz/s+mb KDmXfLYZ79XwzI1gUSakLXMCsSL8iLL1YHt895ZZ/7UDTHiHFQToqRhnlOe7ytFiptoE HxfQ== 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:mime-version:content-transfer-encoding; bh=VqAFODf/gGeYQyAKcFpb2YFN/8JuXzgnWP2opuuL+3A=; b=i4zfmlS3DabViO1EEJ3wRYqd+ySdQ04gZlI0EDtIiJRbIm2LFDJ2VAVVzBbCiK/GDU R0z0KxDY9zV+/Zx+bV7A+9hMn+lBDZ5P5ykzl4hPj50Y7x7OAkyVI10kLtdFyZPwfrGY Ne1Y82juasZFiRcBfapcA29TtHj7m/r78IuvMteArDXNfjOTOdC/5a3tllXu/S8PcrZI EKFoDv/j2zWnL7UcO1i39TkJfRPSOv7m43YjUfitUjt/Nh57p86QOWUXi366a/Aq7NT2 s5F2zOaCWJYlPKx/c8kQzOpVaNzUobzf4gDl7UThXTuYONHcGCs0k1bx2qmO6yvnx4zY IBQA== X-Gm-Message-State: AOAM531qCPdosnzcAt3kY02t6QHiyNuS9e4z+L0soy3PlI27i3Hey0hI Od5yBgraEoEVng3V775F7+Pbxfxpd/I= X-Google-Smtp-Source: ABdhPJzR7GpirCPrshPK0gqfYjhwBi4meyYcjoD/IwR4XaQuregaMfbWUtrPhBTOrG3ZMGd9FX+imQ== X-Received: by 2002:a1c:7215:: with SMTP id n21mr2175280wmc.154.1601116203462; Sat, 26 Sep 2020 03:30:03 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:02 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:50 +0200 Message-Id: <20200926102804.228089-11-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/25] avcodec/magicyuv: Avoid AV_QSORT when creating Huffman table 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" The MagicYUV format stores Huffman tables in its bitstream by coding the length of a given symbol; it does not code the actual code directly, instead this is to be inferred by the rule that a symbol is to the left of every shorter symbol in the Huffman tree and that for symbols of the same length the symbol is ascending from left to right. Our decoder implemented this by first sorting the array containing length and symbol of each element according to descending length and for equal length, according to ascending symbol. Afterwards, the current state in the tree got encoded in a variable code; if the next array entry had length len, then the len most significant bits of code contained the code of this entry. Whenever an entry of the array of length len was processed, code was incremented by 1U << (32 - len). So two entries of length len have the same effect as incrementing code by 1U << (32 - (len - 1)), which corresponds to the parent node of length len - 1 of the two nodes of length len etc. This commit modifies this to avoid sorting the entries before calculating the codes. This is done by calculating how many non-leaf nodes there are on each level of the tree before calculating the codes. Afterwards every leaf node on this level gets assigned the number of nodes already on this level as code. This of course works only because the entries are already sorted by their symbol initially, so that this algorithm indeed gives ascending symbols from left to right on every level. This offers both speed- as well as (obvious) codesize advantages. With Clang 10 the number of decicycles for build_huffman decreased from 1561987 to 1228405; for GCC 9 it went from 1825096 decicyles to 1429921. These tests were carried out with a sample with 150 frames that was looped 13 times; and this was iterated 10 times. The earlier reference point here is from the point when the loop generating the codes was traversed in reverse order (as the patch reversing the order led to performance penalties). Signed-off-by: Andreas Rheinhardt --- libavcodec/magicyuv.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index 17dea69d76..7dded9b457 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -25,7 +25,6 @@ #define CACHED_BITSTREAM_READER !ARCH_X86_32 #include "libavutil/pixdesc.h" -#include "libavutil/qsort.h" #include "avcodec.h" #include "bytestream.h" @@ -74,26 +73,24 @@ typedef struct MagicYUVContext { LLVidDSPContext llviddsp; } MagicYUVContext; -static int huff_cmp_len(const void *a, const void *b) +static int huff_build(HuffEntry he[], uint16_t codes_count[33], + VLC *vlc, int nb_elems) { - const HuffEntry *aa = a, *bb = b; - return (bb->len - aa->len) * 4096 + aa->sym - bb->sym; -} - -static int huff_build(HuffEntry he[], VLC *vlc, int nb_elems) -{ - uint32_t code; - - AV_QSORT(he, nb_elems, HuffEntry, huff_cmp_len); + unsigned nb_codes = 0, max = 0; + + for (int i = 32; i > 0; i--) { + uint16_t curr = codes_count[i]; // # of leafs of length i + codes_count[i] = nb_codes / 2; // # of non-leaf nodes on level i + nb_codes = codes_count[i] + curr; // # of nodes on level i + if (curr && !max) + max = i; + } - code = 0; for (unsigned i = 0; i < nb_elems; i++) { - he[i].code = code >> (32 - he[i].len); - code += 0x80000000u >> (he[i].len - 1); + he[i].code = codes_count[he[i].len]; + codes_count[he[i].len]++; } - - ff_free_vlc(vlc); - return ff_init_vlc_sparse(vlc, FFMIN(he[0].len, 12), nb_elems, + return ff_init_vlc_sparse(vlc, FFMIN(max, 12), nb_elems, &he[0].len, sizeof(he[0]), sizeof(he[0].len), &he[0].code, sizeof(he[0]), sizeof(he[0].code), &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0); @@ -389,6 +386,7 @@ static int build_huffman(AVCodecContext *avctx, const uint8_t *table, MagicYUVContext *s = avctx->priv_data; GetByteContext gb; HuffEntry he[4096]; + uint16_t length_count[33] = { 0 }; int i = 0, j = 0, k; bytestream2_init(&gb, table, table_size); @@ -409,6 +407,7 @@ static int build_huffman(AVCodecContext *avctx, const uint8_t *table, return AVERROR_INVALIDDATA; } + length_count[x] += l; for (; j < k; j++) { he[j].sym = j; he[j].len = x; @@ -416,7 +415,7 @@ static int build_huffman(AVCodecContext *avctx, const uint8_t *table, if (j == max) { j = 0; - if (huff_build(he, &s->vlc[i], max)) { + if (huff_build(he, length_count, &s->vlc[i], max)) { av_log(avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n"); return AVERROR_INVALIDDATA; } @@ -424,6 +423,7 @@ static int build_huffman(AVCodecContext *avctx, const uint8_t *table, if (i == s->planes) { break; } + memset(length_count, 0, sizeof(length_count)); } } From patchwork Sat Sep 26 10:27:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22619 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 3DC78449EC5 for ; Sat, 26 Sep 2020 13:35:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0EF7B68B74B; Sat, 26 Sep 2020 13:35:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2089268ABC3 for ; Sat, 26 Sep 2020 13:35:23 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id y15so1899334wmi.0 for ; Sat, 26 Sep 2020 03:35:23 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=2kwlJjX3GTKiQCwksTLcTXlPbNAoCGXVulz/yXmAa7Y=; b=i126gzRqO/wRQC92BHH5L/UmmICWM/sLBfHSdtpH03eAEYAATVuxlluzReUytSsBB6 YrA3ZTDzTO77XJ+AZQOxk+V2fvfXxYvgNOjtyI9TUEDgNu3tOwTAEVcStpYkuFGWqZDN 6UJTefwg1cBCOHayT6EJMPVHKZRT2CQ5Zdq9t+ZifB2k/54oA7whYJAjz0Xw0QiFsgLS IoKjmmEGXbji56wnGiet6laVTElVdz9iRZn1kJ11wZcENyJZVnp+MAJLnMFiuDK9Glsa wZnzw9kdw42oY++XqVaojUzRYBSlL+hYr41IX0F1GeS2H2/T+xJi7FwojXqBZOJ06myS DyGw== 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:mime-version:content-transfer-encoding; bh=2kwlJjX3GTKiQCwksTLcTXlPbNAoCGXVulz/yXmAa7Y=; b=W03TBpZwSBMxetnUgBuGXLVxpziLqnAHrk5ruwyCnnuzD6dIxbxmg58Tw/3AJyovGp eHzrEN8/5tOAaTWqWXJJSLlQY9zuXg+4DFFzayklGf5uiXzLHbtqh/yZU+6y/igJqMhx FQToVLdcIY3HEZOjb8LZq6fib/LSh0SSVkXfPMwDw8WbwR4tDIOts3AofVG0kHyOAipF 8MBtO/rKrmOEvSY0X815OjIMJmRJNO4LKNaqzHhNrkUzF92ne7hxjiwyxQJsNY9vWJDG xwdU3z8BlXfkHVFSltvBzmFyjhhFB4NFWaNiFxi2BwZVRBXChtDjYLqGR4vtpKcGSOIF Syog== X-Gm-Message-State: AOAM530X6a1iAb6asFEC9S8xy7HRT9lLApcR13ZvVA/hnZJR0GklbDkZ qjPJJ7yxh9zyfvLgbsL5It0yvP6NB4M= X-Google-Smtp-Source: ABdhPJxunzqDLu6RHB1FJS5F3YJeDISwrHHWInmiphJ5Xw01elJsuGi8+jsmd704zAFVSZdLycTh2A== X-Received: by 2002:a7b:c085:: with SMTP id r5mr2159497wmh.52.1601116204603; Sat, 26 Sep 2020 03:30:04 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:03 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:51 +0200 Message-Id: <20200926102804.228089-12-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/25] avcodec/magicyuv: Don't waste stack space 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" Now that the HuffEntries are no longer sorted by the MagicYUV decoder, their symbols are trivial: The symbol of the element with index i is i. They can therefore be removed. Furthermore, despite the length of the codes being in the range 1..32 bits, the actual value of the codes is <= 4096 (for 12 bit content). The reason for this is that the longer codes are on the left side of the tree, so that the higher bits of these codes are simply zero. By using an uint16_t for the codes and removing the symbols entry, the size of each HuffEntry is decreased from eight to four, saving 16KB of stack space. Signed-off-by: Andreas Rheinhardt --- libavcodec/magicyuv.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index 7dded9b457..ea1f727e5c 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -46,9 +46,8 @@ typedef enum Prediction { } Prediction; typedef struct HuffEntry { - uint16_t sym; uint8_t len; - uint32_t code; + uint16_t code; } HuffEntry; typedef struct MagicYUVContext { @@ -90,10 +89,9 @@ static int huff_build(HuffEntry he[], uint16_t codes_count[33], he[i].code = codes_count[he[i].len]; codes_count[he[i].len]++; } - return ff_init_vlc_sparse(vlc, FFMIN(max, 12), nb_elems, - &he[0].len, sizeof(he[0]), sizeof(he[0].len), - &he[0].code, sizeof(he[0]), sizeof(he[0].code), - &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0); + return init_vlc(vlc, FFMIN(max, 12), nb_elems, + &he[0].len, sizeof(he[0]), sizeof(he[0].len), + &he[0].code, sizeof(he[0]), sizeof(he[0].code), 0); } static void magicyuv_median_pred16(uint16_t *dst, const uint16_t *src1, @@ -408,10 +406,8 @@ static int build_huffman(AVCodecContext *avctx, const uint8_t *table, } length_count[x] += l; - for (; j < k; j++) { - he[j].sym = j; + for (; j < k; j++) he[j].len = x; - } if (j == max) { j = 0; From patchwork Sat Sep 26 10:27:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22606 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 59F3B44A10F for ; Sat, 26 Sep 2020 13:30:11 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4A58F68B748; Sat, 26 Sep 2020 13:30:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4570968B655 for ; Sat, 26 Sep 2020 13:30:07 +0300 (EEST) Received: by mail-wm1-f41.google.com with SMTP id y15so1890963wmi.0 for ; Sat, 26 Sep 2020 03:30:07 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=Y/7j4TMsCUwVSYY05oCy3LdtyzeWCCAkMZC7h6pJPvM=; b=qkK09rsdpGY45I7JJ/HgBzwZ2mRLcJLAuiwsgWp91glGHQzdVg2Vex+K7sh6qvrsh+ xYfWGJIUr7y5PiMbZdeChW+0Bhe9FJsL6gFn0d7nKIzjc6sT0+Mu8eQNBSLFgpPsdaKM 3i17Hsz8BXWUYnXJXhfhAv88S2/a7UzwhLgkqJlTMtEIGXIokKRvzC4hmr0+MM50pCv3 7p4OMx1HNUWxATbhjonTH7m005T6zqeT7SiMRjRtZv+i6ycPITkor7TpGqzJhdf9lzdc mw30ZYhN6ikh4a9MxH+PZ5XWZlt1peIfub3dBiBWewQiEA+CLVq6+N089I4wfI4OD7c1 dUtA== 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:mime-version:content-transfer-encoding; bh=Y/7j4TMsCUwVSYY05oCy3LdtyzeWCCAkMZC7h6pJPvM=; b=fDu7LBIhhCouAKqbzxuLLgw0Q34cvXKBVT9AifD994iddTBSPuMr2HQqJGkpSts1QN d1xy5t+rAJCngxFZ1ZVQOP6cU254iXHCyJcVhrqePfJ5inyh3mRqeb8/uQRDsUilKFKk Yttd+jDdT6YgfY3ELBugDAe+9k+egr/RSDMBsC+NU3cBHhnvstxegYbycjaWouO1e1YV YNQURG3bBip5Z70mecu3waDfQRYgQ4xqIaeD0NnnInv1+8fTdDU4lOIWD9cdqjqUlhVc Y25U3NMRIvjE5hQV4mBRbzIGs5Hbz9TBKpA+c1XZ9yppR5vx/+ldOInYHZMnBKYsvQX6 weNw== X-Gm-Message-State: AOAM530rQmvZZ+hZu//22quu2BAHbKuG9pxPlf73mhVnDrdtTuwS3rSI t0DOS+C3cjOxJsFuq4f85/Y1OvFhjEk= X-Google-Smtp-Source: ABdhPJzDLJGYmgUUCPAjV/hJZ+75ok4rFYP72M4N542EvYcf+Ax56qZIjAK96N3rx8+b/nQzzBRJBw== X-Received: by 2002:a1c:4187:: with SMTP id o129mr2000288wma.113.1601116206157; Sat, 26 Sep 2020 03:30:06 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:05 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:52 +0200 Message-Id: <20200926102804.228089-13-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/25] avcodec/utvideodec/enc: Fix building Huffman table 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" The Ut Video format stores Huffman tables in its bitstream by coding the length of a given symbol; it does not code the actual code directly, instead this is to be inferred by the rule that a symbol is to the left of every shorter symbol in the Huffman tree and that for symbols of the same length the symbol is descending from left to right. With one exception, this is also what our de- and encoder did. The exception only matters when there are codes of length 32, because in this case the first symbol of this length did not get the code 0, but 1; this is tantamount to pretending that there is a (nonexistent) leaf of length 32. This is simply false. The reference software agrees with this [1]. [1]: https://github.com/umezawatakeshi/utvideo/blob/2700a471a78402e5c340150b38e8a793ef3676f1/utv_core/HuffmanCode.cpp#L280 Signed-off-by: Andreas Rheinhardt --- libavcodec/utvideodec.c | 4 ++-- libavcodec/utvideoenc.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c index c07636d435..b3c4c3519b 100644 --- a/libavcodec/utvideodec.c +++ b/libavcodec/utvideodec.c @@ -70,7 +70,7 @@ static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym) return -1; } - code = 1; + code = 0; for (i = last; i >= 0; i--) { codes[i] = code >> (32 - he[i].len); bits[i] = he[i].len; @@ -113,7 +113,7 @@ static int build_huff(const uint8_t *src, VLC *vlc, int *fsym) if (he[last].len > 32) return -1; - code = 1; + code = 0; for (i = last; i >= 0; i--) { codes[i] = code >> (32 - he[i].len); bits[i] = he[i].len; diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c index f1b9d11c96..05a9614036 100644 --- a/libavcodec/utvideoenc.c +++ b/libavcodec/utvideoenc.c @@ -346,7 +346,7 @@ static void calculate_codes(HuffEntry *he) while (he[last].len == 255 && last) last--; - code = 1; + code = 0; for (i = last; i >= 0; i--) { he[i].code = code >> (32 - he[i].len); code += 0x80000000u >> (he[i].len - 1); From patchwork Sat Sep 26 10:27:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22620 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 8892D449EC5 for ; Sat, 26 Sep 2020 13:36:01 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6E11468B790; Sat, 26 Sep 2020 13:36:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 140A868AE72 for ; Sat, 26 Sep 2020 13:35:55 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id y15so1900130wmi.0 for ; Sat, 26 Sep 2020 03:35:55 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=OaDUQ0EvQt7SOSF7Cl9gm6A0dFbsfj1x5kZNoIXkJwU=; b=D7nbKZhEWfpjet5MmG7r0EypuO7+yo8kTUfn5huNJapDpSKKY11+pLXXy0g7o1G1uc uBPmY5LwSli6muaw0gaD6Etjq0/yTth9igTdkbiHJoE4dfYmB8Y4fziFsx3wCztw9Fl3 4Ze3KN7EOtC09FmCmhR1/rxeK4jegJ2rq4UCBtMcOTCS6+S++pPUE3yP4SEPXdYH36xu aLBDWLqQruSku9fyHQfaAVWR+xmfICA/F+ZUh2bOe8XGf1L/3Ps1PWSS2WhEwtyCYbb+ wTPxwMoAKLrlHr6AD/ObQ8Ip5imUH9ZYJxN+zZDdv5hfVuBOaBCeW2eaD7c8oJGWJlFt lipw== 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:mime-version:content-transfer-encoding; bh=OaDUQ0EvQt7SOSF7Cl9gm6A0dFbsfj1x5kZNoIXkJwU=; b=ahbTU6P0fvSm5z+Hz1IupVOWgJRO4ubPL8o6hdPT+DV4q6mqkCDkUKG3wpp4YeJ13Q HwgIUorGjutDrq22M7N2prPu5722rydHov15AyW82D7zhAXNJ5fY4sr76lwL5ke3DOmh 7WZHDld1K6d6W9RrKgVfZuMfs+GzgH1pVUwW6sl5/fLuEaYN3wdM8eFc7j1/O3Si1KkD 5uWYyjx2SUZ+aNKXGD4/w/D+PLKC8Hym/htb/bH5LmtITfMyAUg2Yz5fbCkMwG+KBnBb RgvG9BF3e3pVkTzdGA6wjjGLjGyYZ7DJao9g9i88MKOOzD0dKHo70BXSB7FQmXkRSZqK PzMA== X-Gm-Message-State: AOAM53331T9Py5kDlaYtUQHTXH6N1KQl/BHbjO4rRQuTSCt5a8O8wUzY ERadCOkV8J06y6mET7I6v4FWFYW4PuQ= X-Google-Smtp-Source: ABdhPJzN2CqbYp802MgdCH4+/N/J7iYgtVd2GCxcwPjPbZeuATo90E2WTxjFgvnfW+YALb/abiH1tw== X-Received: by 2002:a05:600c:283:: with SMTP id 3mr2095048wmk.110.1601116207187; Sat, 26 Sep 2020 03:30:07 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:06 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:53 +0200 Message-Id: <20200926102804.228089-14-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/25] avcodec/utvideodec: Remove code duplication when creating Huffman tables 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/utvideodec.c | 55 +++++------------------------------------ 1 file changed, 6 insertions(+), 49 deletions(-) diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c index b3c4c3519b..f014e90606 100644 --- a/libavcodec/utvideodec.c +++ b/libavcodec/utvideodec.c @@ -40,7 +40,7 @@ #include "thread.h" #include "utvideo.h" -static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym) +static int build_huff(const uint8_t *src, VLC *vlc, int *fsym, unsigned nb_elems) { int i; HuffEntry he[1024]; @@ -51,18 +51,18 @@ static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym) uint32_t code; *fsym = -1; - for (i = 0; i < 1024; i++) { + for (i = 0; i < nb_elems; i++) { he[i].sym = i; he[i].len = *src++; } - qsort(he, 1024, sizeof(*he), ff_ut10_huff_cmp_len); + qsort(he, nb_elems, sizeof(*he), ff_ut10_huff_cmp_len); if (!he[0].len) { *fsym = he[0].sym; return 0; } - last = 1023; + last = nb_elems - 1; while (he[last].len == 255 && last) last--; @@ -84,49 +84,6 @@ static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym) syms, sizeof(*syms), sizeof(*syms), 0); } -static int build_huff(const uint8_t *src, VLC *vlc, int *fsym) -{ - int i; - HuffEntry he[256]; - int last; - uint32_t codes[256]; - uint8_t bits[256]; - uint8_t syms[256]; - uint32_t code; - - *fsym = -1; - for (i = 0; i < 256; i++) { - he[i].sym = i; - he[i].len = *src++; - } - qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len); - - if (!he[0].len) { - *fsym = he[0].sym; - return 0; - } - - last = 255; - while (he[last].len == 255 && last) - last--; - - if (he[last].len > 32) - return -1; - - code = 0; - for (i = last; i >= 0; i--) { - codes[i] = code >> (32 - he[i].len); - bits[i] = he[i].len; - syms[i] = he[i].sym; - code += 0x80000000u >> (he[i].len - 1); - } - - return ff_init_vlc_sparse(vlc, VLC_BITS, last + 1, - bits, sizeof(*bits), sizeof(*bits), - codes, sizeof(*codes), sizeof(*codes), - syms, sizeof(*syms), sizeof(*syms), 0); -} - static int decode_plane10(UtvideoContext *c, int plane_no, uint16_t *dst, ptrdiff_t stride, int width, int height, @@ -139,7 +96,7 @@ static int decode_plane10(UtvideoContext *c, int plane_no, GetBitContext gb; int prev, fsym; - if ((ret = build_huff10(huff, &vlc, &fsym)) < 0) { + if ((ret = build_huff(huff, &vlc, &fsym, 1024)) < 0) { av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n"); return ret; } @@ -299,7 +256,7 @@ static int decode_plane(UtvideoContext *c, int plane_no, return 0; } - if (build_huff(src, &vlc, &fsym)) { + if (build_huff(src, &vlc, &fsym, 256)) { av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n"); return AVERROR_INVALIDDATA; } From patchwork Sat Sep 26 10:27:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22608 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 E8C1544A10F for ; Sat, 26 Sep 2020 13:30:12 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D217968B750; Sat, 26 Sep 2020 13:30:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 55C4C68B6F8 for ; Sat, 26 Sep 2020 13:30:09 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id d4so1703203wmd.5 for ; Sat, 26 Sep 2020 03:30:09 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=jfPiX9v5V3SZASD+YHCtWGgcMZITuBF7kpqZixMOLic=; b=LCKoXDckfteZ6943KrU1GQlky6VETIjy6AqRt504awC0CzeKnU21XDKt89nZ+M/9W4 oBuPolXdWwUeREhY6A4ztEOx1fA1GqO/W9W1JgsyVNrunf6r6eDtX9lsXLkA8OhbJDpc qTEFllXEcQoH4flv0EhIXnKcGZb6bwmGhihRYDxomL2J4/LDpWc7IXbKZ7A+OSF81Tym uKkaA92P4d0XTVTNR74W5V+iqTJpgymxMkZ+NzNZWmSyGiWAwT/J/YesEReqOv1r9HaV sUMV0HYUV8HoNkw9MbW242tSADyDl3T3o7Fum1GaYOc3LJtGoRkUljrFRJSEothccsHT xVow== 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:mime-version:content-transfer-encoding; bh=jfPiX9v5V3SZASD+YHCtWGgcMZITuBF7kpqZixMOLic=; b=iVJen1PD6RLM7n7WfoB0CZAcjDaEsmwxgyT7iURZmOlOntO0LeAuw+qtmIdyfaprpQ MnSwIMSpMjLUZYMt7kPGuIyNQBa7rA0QQqZUL3pW4vylcw6t+s/tcrt2NouzL0oPDOeZ 7N4y1a8r3x8KlcC+RkbE5qWuprPboGUM0kilRA62GXMwR1Y0B8Xd+FY5kgXW0l+xdL+S CyJIe0zPbPq2dKJT6nf+EsXr9HWYgcKVeC+5XB9NN9ksvLhp/uTOg4DsiMGQ43ezjDlg KypeZUhz5bwGn33ulajlJ+k+tbsnOXiJ1WkFNUAfJmF9Z0rnBTEgfJh2GMcUN/Xtjick 8sng== X-Gm-Message-State: AOAM5317lcPzcZS4gbImeGrFJke861uqLyChJO+k7ffXUWB52VMtP97t 1bgNU9Ul+2GD9n2JRP72bES3+AMuJaw= X-Google-Smtp-Source: ABdhPJy5p9CfJKfMqlyWDud1pO2S2DqgvgKwyvq8OTQ43h+V5DF6ncDzYZktOYBDLMnbi9ukWukA/Q== X-Received: by 2002:a7b:cf30:: with SMTP id m16mr2058524wmg.0.1601116208493; Sat, 26 Sep 2020 03:30:08 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:07 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:54 +0200 Message-Id: <20200926102804.228089-15-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/25] avcodec/utvideodec: Avoid qsort when creating Huffman tables 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" The Ut video format uses Huffman trees which are only implicitly coded in the bitstream: Only the lengths of the codes are coded, the rest has to be inferred by the decoder according to the rule that the longer codes are to the left of shorter codes in the tree and on each level the symbols are descending from left to right. Because longer codes are to the left of shorter codes, one needs to know how many non-leaf nodes there are on each level in order to know the code of the next left-most leaf (which belongs to the highest symbol on that level). The current code does this by sorting the entries to be ascending according to length and (for entries with the same length) ascending according to their symbols. This array is then traversed in reverse order, so that the lowest level is dealt with first, so that the number of non-leaf nodes of the next higher level is known when processing said level. But this can also be calculated without sorting: Simply count how many leaf nodes there are on each level. Then one can calculate the number of non-leaf nodes on each level iteratively from the lowest level upwards: It is just half the number of nodes of the level below. This improves performance: For the sample from ticket #4044 the amount of decicycles for one call to build_huff() decreased from 1055489 to 446310 for Clang 10 and from 1080306 to 535155 for GCC 9. Signed-off-by: Andreas Rheinhardt --- libavcodec/utvideo.c | 6 ----- libavcodec/utvideo.h | 1 - libavcodec/utvideodec.c | 53 ++++++++++++++++++++--------------------- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/libavcodec/utvideo.c b/libavcodec/utvideo.c index 5828d5ec0d..b14e56e0d8 100644 --- a/libavcodec/utvideo.c +++ b/libavcodec/utvideo.c @@ -39,9 +39,3 @@ int ff_ut_huff_cmp_len(const void *a, const void *b) const HuffEntry *aa = a, *bb = b; return (aa->len - bb->len)*256 + aa->sym - bb->sym; } - -int ff_ut10_huff_cmp_len(const void *a, const void *b) -{ - const HuffEntry *aa = a, *bb = b; - return (aa->len - bb->len)*1024 + aa->sym - bb->sym; -} diff --git a/libavcodec/utvideo.h b/libavcodec/utvideo.h index cf0bb28c44..2975f287a7 100644 --- a/libavcodec/utvideo.h +++ b/libavcodec/utvideo.h @@ -99,6 +99,5 @@ typedef struct HuffEntry { /* Compare huffman tree nodes */ int ff_ut_huff_cmp_len(const void *a, const void *b); -int ff_ut10_huff_cmp_len(const void *a, const void *b); #endif /* AVCODEC_UTVIDEO_H */ diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c index f014e90606..8b47c14d98 100644 --- a/libavcodec/utvideodec.c +++ b/libavcodec/utvideodec.c @@ -43,45 +43,44 @@ static int build_huff(const uint8_t *src, VLC *vlc, int *fsym, unsigned nb_elems) { int i; - HuffEntry he[1024]; - int last; uint32_t codes[1024]; uint8_t bits[1024]; - uint16_t syms[1024]; - uint32_t code; + uint16_t codes_count[33] = { 0 }; *fsym = -1; for (i = 0; i < nb_elems; i++) { - he[i].sym = i; - he[i].len = *src++; - } - qsort(he, nb_elems, sizeof(*he), ff_ut10_huff_cmp_len); + if (src[i] == 0) { + *fsym = i; + return 0; + } else if (src[i] == 255) { + bits[i] = 0; + } else if (src[i] <= 32) { + bits[i] = src[i]; + } else + return AVERROR_INVALIDDATA; - if (!he[0].len) { - *fsym = he[0].sym; - return 0; + codes_count[bits[i]]++; } + if (codes_count[0] == nb_elems) + return AVERROR_INVALIDDATA; - last = nb_elems - 1; - while (he[last].len == 255 && last) - last--; - - if (he[last].len > 32) { - return -1; + for (unsigned i = 32, nb_codes = 0; i > 0; i--) { + uint16_t curr = codes_count[i]; // # of leafs of length i + codes_count[i] = nb_codes / 2; // # of non-leaf nodes on level i + nb_codes = codes_count[i] + curr; // # of nodes on level i } - code = 0; - for (i = last; i >= 0; i--) { - codes[i] = code >> (32 - he[i].len); - bits[i] = he[i].len; - syms[i] = he[i].sym; - code += 0x80000000u >> (he[i].len - 1); + for (unsigned i = nb_elems; i-- > 0;) { + if (!bits[i]) { + codes[i] = 0; + continue; + } + codes[i] = codes_count[bits[i]]++; } #define VLC_BITS 11 - return ff_init_vlc_sparse(vlc, VLC_BITS, last + 1, - bits, sizeof(*bits), sizeof(*bits), - codes, sizeof(*codes), sizeof(*codes), - syms, sizeof(*syms), sizeof(*syms), 0); + return init_vlc(vlc, VLC_BITS, nb_elems, + bits, sizeof(*bits), sizeof(*bits), + codes, sizeof(*codes), sizeof(*codes), 0); } static int decode_plane10(UtvideoContext *c, int plane_no, From patchwork Sat Sep 26 10:27:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22609 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 E7EF544A10F for ; Sat, 26 Sep 2020 13:30:13 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D257A68B777; Sat, 26 Sep 2020 13:30:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9EB0768AB33 for ; Sat, 26 Sep 2020 13:30:10 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id w2so1729740wmi.1 for ; Sat, 26 Sep 2020 03:30:10 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=oRXsGksnk1er8KpRXPeBNAFLTin8MBH3Y94fZsCEjQU=; b=nt8i/3BstaZ0UC49SmTHkNSeborg2fhurm9qIHX3G5kDEEjbN+CMeaxH7RBJILhF1Q yQxi3COBPTSe85sbn33R0jq0Wl6iAUE9PiHJpTobQeB+I6GSjlP1Yg7e0sspkHDbGm4Z tB5iNwMRRoF/TZLxNRWhhW0vgfKTPVLWRAPYQFs0rpiFv1N/rK9bfw34lm9ifkf+m/6c lyTBKX7ClTqdJ+NuOPwH6OGXWRYnYaJBkz3IjXcozmdgKeuavIMIaV0JkKASyM0LWupg RmpeLgCy6ii0PjnhspyRVjNWxKy4l25uXhIZBxepLg1imwEqnJRrV/j2XElIdeb+ilmj 4GRw== 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:mime-version:content-transfer-encoding; bh=oRXsGksnk1er8KpRXPeBNAFLTin8MBH3Y94fZsCEjQU=; b=oRtKjTVkNNjrc2t8PZkEDGBYmmJ07g7FkThduxJbFrJ6Lb+esAkNb6PfaGwLtxUoP/ 2sZTD4ZBX8inlUAwnEIWmbFhRMWFOVYNd97vMqRnGoHIAhZejQRvT23Jh4IPrhkuPihI 2niUOuuYEnH5cCSLaUFmX9D48M0+IBppwFazgL/3BGMAPy2hi0AKOQtBsq5tn08Lupra MMv/Fv6VD4GPXhSx1K8O75HEXU7zYO4gu67AmvkZLyUCc6ThKSOu1pHEhkmK5UT7m6Vf HffVaq4Qsw+qIWFVR4jgOD1b0pE0Gw1ChS74FRmYK0rxZumbWhIxWU/A8Om1nLb0x4E4 Smbg== X-Gm-Message-State: AOAM532Mk6gPBcu509DXlid4CUTC4huVkGUYg1/k6ZRVF1u9reVG2Tf9 nJW53KeueEwZUyrUfIongCPOGVJp/sw= X-Google-Smtp-Source: ABdhPJxnHxi4Gbuw6N0JnLnzRDHzP09VRVr8hTUZLDtItFZuSOECZF/woqwvK9uptIPER+km1gKp+A== X-Received: by 2002:a7b:c1c3:: with SMTP id a3mr2211116wmj.68.1601116209550; Sat, 26 Sep 2020 03:30:09 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:08 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:55 +0200 Message-Id: <20200926102804.228089-16-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/25] avcodec/utvideo: Remove unused array 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" Unused since 3594788b713e76449eda0bc9d64b38258c86a594. Signed-off-by: Andreas Rheinhardt --- libavcodec/utvideo.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavcodec/utvideo.c b/libavcodec/utvideo.c index b14e56e0d8..0cf0cbcd8b 100644 --- a/libavcodec/utvideo.c +++ b/libavcodec/utvideo.c @@ -32,8 +32,6 @@ const int ff_ut_pred_order[5] = { }; #endif -const int ff_ut_rgb_order[4] = { 1, 2, 0, 3 }; // G, B, R, A - int ff_ut_huff_cmp_len(const void *a, const void *b) { const HuffEntry *aa = a, *bb = b; From patchwork Sat Sep 26 10:27:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22610 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 D713A44A10F for ; Sat, 26 Sep 2020 13:30:15 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C4BC368B790; Sat, 26 Sep 2020 13:30:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 11FAC68B73E for ; Sat, 26 Sep 2020 13:30:12 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id y15so1891105wmi.0 for ; Sat, 26 Sep 2020 03:30:12 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=h2zqsiK0iAUCr5aQcZrZ16/QULZ1nfQ2jPaUUsli8XM=; b=mwpEsl4waRJq23VmFI4FiXDNBeAW8vu5a9QLcgmVh0b/PRtxK/5unQxKphTm7k75ic yjVBUt0PXVI2T++01TUECtMmPHK4/2zvNAjFBlU/ccA983uFZGu21WBw3Qq8HzaFjGEF fUojUgE1MedYuZ0y3uI87c4MSPUfEBetF6bHwe9kCXu5EWd0KJIJxEeFFH/BD+xDi14/ FRlFaNOzJVjw24veY4LNM9b8Nu4KgQ5MYgSU1UnjMfu98p2j4XIlz3oL2GH2/G+S8L9G dHcSCNs+DK3GWVc2TnYSMIdPEfqXwYVGjtEoM0h947h5B4ZVDvaN8W0T0IqtJuhY6ZEZ x89Q== 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:mime-version:content-transfer-encoding; bh=h2zqsiK0iAUCr5aQcZrZ16/QULZ1nfQ2jPaUUsli8XM=; b=cCAVdbzrvPRKLwIWQut6ex1iqN3ww8UleExx26CSQMf+xhwtBOzNoYxoA4DTVs3yI5 2iBoY/O76vkcQIGODpnWglvUfjmoVxe80+1QdFP+10WrYrNXBjH94D+D7/ObC9zEFE7I GWDv5nKe78q+QGNhzn/loLRJL3wkVjUymQN/iciiq/7mfkVInl5SwRUz/Lu5tZM1W4Ep 4PLO2iwzv758oPupuK349WLGMujNDe+nNFwdFRBYrSG78dSvVDKPt36GK5A/ooFPWAgE 558N4cCdIObB6ekNxdZ3LCCqd5VtiTD2mjH0sG02Y80Ty4UfQO/HpXm/5rZ6UtFDH+yD r2yg== X-Gm-Message-State: AOAM5305vRot91ZhukdJYNWgdvOZeWkkzLYv1nsSRdXYwbwgRkXLAGUm r3bQDDSS3mwdU68PAngwUCillZFBOlE= X-Google-Smtp-Source: ABdhPJxUb/19Z3lnkHrm9y1tfshA8Txx5kcj8puKbOPsdfJWr2ctqMIri7Yhmh8acV9PwEPEWQNL5Q== X-Received: by 2002:a1c:62c2:: with SMTP id w185mr1994317wmb.109.1601116210962; Sat, 26 Sep 2020 03:30:10 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:10 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:56 +0200 Message-Id: <20200926102804.228089-17-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/25] avcodec/utvideo: Move stuff only used by Ut encoder to Ut encoder 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/Makefile | 4 ++-- libavcodec/utvideo.c | 39 --------------------------------------- libavcodec/utvideo.h | 12 ------------ libavcodec/utvideoenc.c | 23 +++++++++++++++++++++-- 4 files changed, 23 insertions(+), 55 deletions(-) delete mode 100644 libavcodec/utvideo.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 9b120a6f64..bee2335a5a 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -664,8 +664,8 @@ OBJS-$(CONFIG_TTA_ENCODER) += ttaenc.o ttaencdsp.o ttadata.o OBJS-$(CONFIG_TWINVQ_DECODER) += twinvqdec.o twinvq.o OBJS-$(CONFIG_TXD_DECODER) += txd.o OBJS-$(CONFIG_ULTI_DECODER) += ulti.o -OBJS-$(CONFIG_UTVIDEO_DECODER) += utvideodec.o utvideo.o utvideodsp.o -OBJS-$(CONFIG_UTVIDEO_ENCODER) += utvideoenc.o utvideo.o +OBJS-$(CONFIG_UTVIDEO_DECODER) += utvideodec.o utvideodsp.o +OBJS-$(CONFIG_UTVIDEO_ENCODER) += utvideoenc.o OBJS-$(CONFIG_V210_DECODER) += v210dec.o OBJS-$(CONFIG_V210_ENCODER) += v210enc.o OBJS-$(CONFIG_V210X_DECODER) += v210x.o diff --git a/libavcodec/utvideo.c b/libavcodec/utvideo.c deleted file mode 100644 index 0cf0cbcd8b..0000000000 --- a/libavcodec/utvideo.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Common Ut Video code - * Copyright (c) 2011 Konstantin Shishkov - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * Common Ut Video code - */ - -#include "utvideo.h" - -#if FF_API_PRIVATE_OPT -const int ff_ut_pred_order[5] = { - PRED_LEFT, PRED_MEDIAN, PRED_MEDIAN, PRED_NONE, PRED_GRADIENT -}; -#endif - -int ff_ut_huff_cmp_len(const void *a, const void *b) -{ - const HuffEntry *aa = a, *bb = b; - return (aa->len - bb->len)*256 + aa->sym - bb->sym; -} diff --git a/libavcodec/utvideo.h b/libavcodec/utvideo.h index 2975f287a7..9da9329ff3 100644 --- a/libavcodec/utvideo.h +++ b/libavcodec/utvideo.h @@ -61,9 +61,6 @@ enum { UTVIDEO_444 = MKTAG('Y', 'V', '2', '4'), }; -/* Mapping of libavcodec prediction modes to Ut Video's */ -extern const int ff_ut_pred_order[5]; - typedef struct UtvideoContext { const AVClass *class; AVCodecContext *avctx; @@ -91,13 +88,4 @@ typedef struct UtvideoContext { size_t control_stream_size[4][256]; } UtvideoContext; -typedef struct HuffEntry { - uint16_t sym; - uint8_t len; - uint32_t code; -} HuffEntry; - -/* Compare huffman tree nodes */ -int ff_ut_huff_cmp_len(const void *a, const void *b); - #endif /* AVCODEC_UTVIDEO_H */ diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c index 05a9614036..5c87eb50ac 100644 --- a/libavcodec/utvideoenc.c +++ b/libavcodec/utvideoenc.c @@ -37,6 +37,25 @@ #include "utvideo.h" #include "huffman.h" +typedef struct HuffEntry { + uint16_t sym; + uint8_t len; + uint32_t code; +} HuffEntry; + +#if FF_API_PRIVATE_OPT +static const int ut_pred_order[5] = { + PRED_LEFT, PRED_MEDIAN, PRED_MEDIAN, PRED_NONE, PRED_GRADIENT +}; +#endif + +/* Compare huffman tree nodes */ +static int ut_huff_cmp_len(const void *a, const void *b) +{ + const HuffEntry *aa = a, *bb = b; + return (aa->len - bb->len)*256 + aa->sym - bb->sym; +} + /* Compare huffentry symbols */ static int huff_cmp_sym(const void *a, const void *b) { @@ -139,7 +158,7 @@ FF_DISABLE_DEPRECATION_WARNINGS /* Convert from libavcodec prediction type to Ut Video's */ if (avctx->prediction_method) - c->frame_pred = ff_ut_pred_order[avctx->prediction_method]; + c->frame_pred = ut_pred_order[avctx->prediction_method]; FF_ENABLE_DEPRECATION_WARNINGS #endif @@ -340,7 +359,7 @@ static void calculate_codes(HuffEntry *he) int last, i; uint32_t code; - qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len); + qsort(he, 256, sizeof(*he), ut_huff_cmp_len); last = 255; while (he[last].len == 255 && last) From patchwork Sat Sep 26 10:27:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22611 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 C3BA044A10F for ; Sat, 26 Sep 2020 13:30:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A879E68B787; Sat, 26 Sep 2020 13:30:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E7EB68AB33 for ; Sat, 26 Sep 2020 13:30:13 +0300 (EEST) Received: by mail-wr1-f43.google.com with SMTP id j2so6616912wrx.7 for ; Sat, 26 Sep 2020 03:30:13 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=OVVkx/gkygNT3WN4x71Cr9rZS9in+Vaz6lsMjUvp+iw=; b=RSFMmeOCR/u5c0yFmLwD2XdZztDjrmcbhwo0O4EM0WNHr69PUf2WvUV+y48fTPrBEp CkhALru2TR/aPcWEgBz4qOKTz9QeN+tzDGJv7WYy3c6KHmt4VB7xcxn0w9yIWsh8+Rqr fUzDkLc+K+U9moG/fUiMCmyxi5I/l/01gPQIT3xZfNR5O9tdhDUkyAmc6PRc5qpHIoR/ NkAHLx0/CPfIryjVwi6RAf4Bv8H9PfwbxSwcI3SHAOy3gZnkXaXzAG99C3E1eiZepaSI ZRPaHe0bR5OM5BAQSN7+eHUH/FB/i7gueG83fwTH7frqfxVMrpBasLyB3SpLAkcM1YT6 aGqg== 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:mime-version:content-transfer-encoding; bh=OVVkx/gkygNT3WN4x71Cr9rZS9in+Vaz6lsMjUvp+iw=; b=Eht2DVIFrLfa0muOfv06RS/AT306tnNvC4tAJe+OKApAUufjR6rWsfVIJspRNq+psE m52Cqet6Fb0ShAAmX59tsCw71ddlhpxUBu8DvVeHQ5RvTbI4rw7W4hMVoHqr1OoSC6NV LSvRpa25tCLij/V/EEdYKrojb4Liojsx2ImVDKqMfJSZG+FGmASyGJbivFzAZ5QU3tvz GpH3ZRkbJqxgmW9bIfIsOE2SwC1G/6RJAI4XYMpnZe/ok5bjvV3bJeke1U8YjK5LRJFi 3uhHlN22mNTrNrDPBVIUM+/oolRri2f0yihOaQfPskoAi0lP+HO9lLV3cL+OJN9jOz58 mgog== X-Gm-Message-State: AOAM533TbjMPzkyQvZYNbw1cohW16TG1/w63nEVfUShAfyhqWQOw9ol0 mk0FHm+ug4mC+o7LDPyIJnuMjxrrtYg= X-Google-Smtp-Source: ABdhPJzQAxSDYEunh/qZdW1S8zcYWYbdnvqq/b3gJpMMOwKsYwZwNc2a1bwW36RxwqHzh+3Cwh/ZDQ== X-Received: by 2002:adf:9f10:: with SMTP id l16mr9628387wrf.77.1601116212485; Sat, 26 Sep 2020 03:30:12 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:11 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:57 +0200 Message-Id: <20200926102804.228089-18-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/25] avcodec/utils: Only call codec->close if init has been called 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" avcodec_open2() also called the AVCodec's close function if an error happened before init had ever been called if the AVCodec has the FF_CODEC_CAP_INIT_CLEANUP flag set. This is against the documentation of said flag: "The codec allows calling the close function for deallocation even if the init function returned a failure." E.g. the SVQ3 decoder is not ready to be closed if init has never been called. Fixes: NULL dereference Fixes: 25762/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SVQ3_fuzzer-5716279070294016 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Andreas Rheinhardt --- If someone were to call avcodec_alloc_context3(NULL) and manually fill in avctx->codec, then the close function might even be called before avctx->priv_data has been allocated. libavcodec/utils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index cf0a55f26d..94b9e94584 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -931,6 +931,7 @@ FF_ENABLE_DEPRECATION_WARNINGS || avci->frame_thread_encoder)) { ret = avctx->codec->init(avctx); if (ret < 0) { + codec_init_ok = -1; goto free_and_end; } codec_init_ok = 1; @@ -1022,8 +1023,8 @@ end: return ret; free_and_end: if (avctx->codec && avctx->codec->close && - (codec_init_ok || - (avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP))) + (codec_init_ok > 0 || (codec_init_ok < 0 && + avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP))) avctx->codec->close(avctx); if (HAVE_THREADS && avci->thread_ctx) From patchwork Sat Sep 26 10:27:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22612 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 EC53E44A10F for ; Sat, 26 Sep 2020 13:30:17 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D093068B7CB; Sat, 26 Sep 2020 13:30:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C439968B751 for ; Sat, 26 Sep 2020 13:30:14 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id s12so6595313wrw.11 for ; Sat, 26 Sep 2020 03:30:14 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=smVFEK2cY57DuFqiSXq42jt+GsOuT0W66WFyDxYQX5k=; b=VfxqwdhW33i2Qb8QGw8O7rwYdDVfuHpQN8ZvDkNnJ03qhfgV7jHacTUc3Mcjxo4RlN sQ1UZpbzd86XzI7oYYa6r676qRcozzyEiiFrykzYUt+T97Ksc86E/GdagpwMPDBCOiux QUbBmVyl3Y8L3CyNdR+sEVgUpVp0OKMLKX3zHOZEcYrsBHc8xVB9FjYDl/7q2Hlt8p76 tZfPKZ9sqpWNYlve8b04gVYByyJnX7sR1rJwf33i3E6S4U5W8LPYZoAYi0s+6uEuapQv 9veENpDdsx3GDQmDUbIcJvy3tvwp5wzll2oV+TMxcXGjZlzyh7QRfuCitvLmfNoGLHF0 gTLA== 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:mime-version:content-transfer-encoding; bh=smVFEK2cY57DuFqiSXq42jt+GsOuT0W66WFyDxYQX5k=; b=Z5r8GdrkNgJG8k9dr577LN6gvybAWydsK4gpRUxLLMQ2QzfJnzoNFbpX2nfd7XM7NW ZCgLyq0joEOqk7lYJoaFYb0OPwnTnKB8T8oyQmYHvPghc2aV+/dijfhut/24NNUM0ABy HAIdWF9ktRYlKUYzqa2gsaz+TUBWsqNzUOLYv5T3pgWz3GY8BGGF91DGQHL7+35GwzWI 0dCtZqcm+Ul8UkediGHf/22/TthrEkrurPHskhLfdMpKolbFZbHOlhA/stzqET+DQVae tdkohMUhnRVA/suHLa874ceh/gseH1T3m21uz7S2e0shjFnUq/Z1Lo5CKsq5QrctqSvL oNqg== X-Gm-Message-State: AOAM533wEjjG5w9+rz0eqUQ+MxZigMPbSUkaOKmZbH3jB3YSjnbfh1WI jYVCvFoo6xM3ltPnQ7AqsJbq6Gy8D6k= X-Google-Smtp-Source: ABdhPJyNbE/1Ddliy0xnoLS/Ml6G5GxaBXuCmcpwrhr2Gh30wl0vRUurcHKo8mPCaNMQr4Mq//EFRw== X-Received: by 2002:adf:c5c3:: with SMTP id v3mr9221613wrg.205.1601116213752; Sat, 26 Sep 2020 03:30:13 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:12 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:58 +0200 Message-Id: <20200926102804.228089-19-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/25] avcodec/utils: Remove always-true check 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" The first thing avcodec_open2() allocates is the AVCodecInternal. If allocating it fails, a jump to end occurs; but if an error happens after its allocation, a jump to free_and_end happens which frees all allocations performed so far and then jumps to end. Yet free_and_end contained a check for AVCodecInternal (after having already dereferenced it to check whether ff_thread_free() needs to be called) which is of course always true. So remove it. Signed-off-by: Andreas Rheinhardt --- libavcodec/utils.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 94b9e94584..8e7c3125aa 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1043,7 +1043,7 @@ FF_ENABLE_DEPRECATION_WARNINGS av_dict_free(&tmp); av_freep(&avctx->priv_data); av_freep(&avctx->subtitle_header); - if (avci) { + av_frame_free(&avci->to_free); av_frame_free(&avci->compat_decode_frame); av_frame_free(&avci->buffer_frame); @@ -1056,7 +1056,6 @@ FF_ENABLE_DEPRECATION_WARNINGS av_bsf_free(&avci->bsf); av_buffer_unref(&avci->pool); - } av_freep(&avci); avctx->internal = NULL; avctx->codec = NULL; From patchwork Sat Sep 26 10:27:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22613 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 8020144A10F for ; Sat, 26 Sep 2020 13:30:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 69D6268B826; Sat, 26 Sep 2020 13:30:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BC58668B767 for ; Sat, 26 Sep 2020 13:30:15 +0300 (EEST) Received: by mail-wr1-f51.google.com with SMTP id k10so3505299wru.6 for ; Sat, 26 Sep 2020 03:30:15 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=/PfddM8Hcw3k+Xppy7/ve7fY5wW4G/cYoIEV1Mb8f00=; b=a0Ls2UgB6U574jf/eFBNt9NfzUTWJx+xrp6iNlFX4Ou47BhR7BDQ25tL075gkRp0d3 t2hgvDxOk0GaXZIKBmMCdRkH6koXTT1fBmxdpC147WPELM6S0SLWtCScLewMZCTryFzj /hlY2ZkvyUnygZZVOAJzbI5jX9XEFQMORCHEUjv7QGgeitqcrEM0rxuGwBDRh3e6OQT1 fkCe1mUtx+bju0QYKaG4Xz59p1y2oa21TusRO8mPTOecWNxp2EQc2Pc1oSZEurfMFn0J 00GstrX4UTnK4VNsrUmMW6cKegYc97jyQgkf3i3ygVoMJzm2cNlI2sZ0Om9FDDgGbADn rGBg== 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:mime-version:content-transfer-encoding; bh=/PfddM8Hcw3k+Xppy7/ve7fY5wW4G/cYoIEV1Mb8f00=; b=MNgek13vGYKCLH3K/xuln+LTCSFSFv4DXF8Ox4fwY/bxQxbOqm01SPqleGySDXhnvx pWGEYfHekP6Tmyp9DeM9X/k21Eztlh2hJzp76KgsSJAuJnX+FmQOLSw1nMFVU3eKk5O2 0xTBLO86mpeoWUiF1mRJXnYOGsT6BfeUfzWhDwQg2y+D/vf1TX41NFCBeEjAqf2PxWG3 Cv02UdNZQ/B8FXFT/Wdr0p9gGeEetqPVzhA6F5yajBpTJZWsDQNi503Kha5nE3+Yg7Mn wA+gQV8JtmvRKqK94uHY/HIfJBDE2pQqRiqsV1Paq8OzGX7btdQI8b19nf7lMmiqAhzo xL1w== X-Gm-Message-State: AOAM530qWn/05Bo7UeWxVUXUr8nwWgK58ZSumao0UOtQNAhMwWgIG1tH I31lkgYy9AUYwEfesr1U4ob1+vcP0gI= X-Google-Smtp-Source: ABdhPJw3/mqBdbYQ70r5MwSM2eUbeqzCnwNsxw8vU3427kLYcCVFXI81Vq0/SWL/JiHVuKb+EDtCmg== X-Received: by 2002:adf:ed12:: with SMTP id a18mr9450062wro.178.1601116214708; Sat, 26 Sep 2020 03:30:14 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:14 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:59 +0200 Message-Id: <20200926102804.228089-20-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/25] avcodec/utils: Improve check for freeing codec private options 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" Don't check for AVCodec.priv_data_size (which is always true if AVCodec.priv_class is set). Instead check for AVCodecContext.priv_data to actually exist. (Note: av_opt_free(NULL) is a no-op.) Signed-off-by: Andreas Rheinhardt --- libavcodec/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 8e7c3125aa..a8af45d0c3 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1030,7 +1030,7 @@ free_and_end: if (HAVE_THREADS && avci->thread_ctx) ff_thread_free(avctx); - if (codec->priv_class && codec->priv_data_size) + if (codec->priv_class && avctx->priv_data) av_opt_free(avctx->priv_data); av_opt_free(avctx); From patchwork Sat Sep 26 10:28:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22617 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 7B8B444B313 for ; Sat, 26 Sep 2020 13:32:17 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2D6BB68B745; Sat, 26 Sep 2020 13:30:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D4D3268B7CA for ; Sat, 26 Sep 2020 13:30:16 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id x14so6585401wrl.12 for ; Sat, 26 Sep 2020 03:30:16 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=fEyjse7kLEuk/7KwJt+dhNvKw/TdeJzj1Hmwp6yfg34=; b=JLxw/Ld67tAM4RQG9HYzwe4vf50VlZlzwzZfn3ZWbxHtKeRKJ8iPzbdYyQr2fneEnn dem6wqCl3brpCbzJxjgk3NR/mFDey3Agh8WrQeRkj/+Dtdu6UalTqeAtb84ONTWuyI0a FThCaChjhfddf59DVXDG4F4a50SLOUJPVK+IiiCQiOpiE+dEiLx151uKEUfPQwd4Anci m9JSBSEh3GLRPnmH5bU/SrXDepiHc6YBQeUALbO6xNHmNWqGVh//tWl1Ha/+IiTwDfkP 5GVxrDOdVxwGUVIxWCzoHaCY6tqFZzhU5w3Ggca8vdmnx8uJffexuMB045eNP0Ngl6nO yaLw== 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:mime-version:content-transfer-encoding; bh=fEyjse7kLEuk/7KwJt+dhNvKw/TdeJzj1Hmwp6yfg34=; b=qarqdTP02kZSjLrc3EoQ/7qn62ghLwfSCGymNmsYBpHHecRtriZ47FF8OjM5yr0Q13 Ja81VARN1p3EenulDh8XG2GF21q9bV5Q+rO1AT+YliCJ5zHT6Ji7XbUK3aA7BvbNrroB FU9O4dxw7ePCNKd2cSp48VNxAv52iojgni+omhaWsEqK0afDcKl7koRIz+wWuTqTfEWf ecSK1wHHf+ZSjWnwkRi5j9MWrc+c49+WRAYn/7zjTPPuuHb3Zl4lEWR3x3qyZcoTWIKz 0eFlkvMnlaRv4MEZzXQ3/XCdcgtQIxdRhk0IT8iZpcVZc3ANjK99sh8JjykbjU1Ii10W gy6w== X-Gm-Message-State: AOAM531qqomcIKiRMTgOYoA0Fw7Tpdrjr5zcnU4HOsvaC4OoK7mnywL+ s/n3Wt5aFKid3grPxRMJ2tgvGiDFgWo= X-Google-Smtp-Source: ABdhPJzAN2Ju73qMd3uscOo1MyNuuAcb19MJypgmTJ2ralo1DQhJblyQPh7Ukgg8z1a5IvcYpPx+MQ== X-Received: by 2002:a5d:43cf:: with SMTP id v15mr9118268wrr.269.1601116215998; Sat, 26 Sep 2020 03:30:15 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:15 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:28:00 +0200 Message-Id: <20200926102804.228089-21-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/25] avcodec/utils: Don't forget cleaning up when allocating priv_data fails 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" Allocating an AVCodecContext's priv_data used to be the first object allocated in avcodec_open2(), so it was unnecessary to goto free_and_end (which does the cleanup) upon error here. But this is no longer so since f3a29b750a5979ae6847879fba758faf1fae88d0. Signed-off-by: Andreas Rheinhardt --- libavcodec/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index a8af45d0c3..05064b560f 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -608,7 +608,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avctx->priv_data = av_mallocz(codec->priv_data_size); if (!avctx->priv_data) { ret = AVERROR(ENOMEM); - goto end; + goto free_and_end; } if (codec->priv_class) { *(const AVClass **)avctx->priv_data = codec->priv_class; From patchwork Sat Sep 26 10:28:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22614 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 8E07544A10F for ; Sat, 26 Sep 2020 13:30:23 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 73A4D68B7A4; Sat, 26 Sep 2020 13:30:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B539768B736 for ; Sat, 26 Sep 2020 13:30:17 +0300 (EEST) Received: by mail-wm1-f52.google.com with SMTP id q9so1720699wmj.2 for ; Sat, 26 Sep 2020 03:30:17 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=KCr34Gr72yt3wMGh6lb+u+NLEQIqZ8I4hbDsGZ0Xe4U=; b=IsGNgQEiHJvh/QANSwNglwAgSSSZz4yxcirx140LfhHR+biJJ4ZPg9Jr2P3Sidkbap +0rqOeNwP7NEKF1bgO2pDhMUt1D/Uon+WINvMwnK3HxQinfKGtq7VCGWWxcdXvGCBoD4 6UqN2jTsdjsxjVvQBcNziiFOFe+/teEAS+dkhl2vB63LShJTAWdpP4+0rvy2ffbb9OBg eU5bQEfuQ+p7iNSHvsZcIO4wsEU1Mlx8MIjbxPCtPFroUoZfyodfk6X0eyOlDNenFiV1 0OTC5s+AFhDcnG8E1W4WWNct3tIsXFFaqU5ReLulCiL7jawODos4vr8+KGrdOj7blO3K MXpA== 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:mime-version:content-transfer-encoding; bh=KCr34Gr72yt3wMGh6lb+u+NLEQIqZ8I4hbDsGZ0Xe4U=; b=NCP9fEGB/n4XzhWe6qauqMMmevsqJ33GYsUB8E66IKktnXX7Ki0zVdphbCa5QfJNbo rmteBSO9NXkMHe5yUGbJVrRLQT8Iys3YIX6Ybimmx591cFTOupyqb0aJZGUYkwxn+/dN nbCWvaX7QYpiLPGvXyY58K/yDpa0H7yQJ5TV03quIEewtTkUdsV+egJGYXwi3pACkdYy HkpvTiGIukxJ77vKM2tU48/RiEtqFtblC54L/YkiQoDNoap7QzIvaLn9haiEQiRzOiQy plFyq0+lFVU5a+m3IHBhGLCrB3WAhlPfq2tbW5vnBrXnNeJC1hb99/nuB7LKNa3clooF mrSQ== X-Gm-Message-State: AOAM530BRV2xmgySxj1WxjQIH9NI4ZtbLKF3KzHumh5ZmxSeESunZ55t QhD813RxznfC/YUsjgapvbNApT0dIEM= X-Google-Smtp-Source: ABdhPJzo/tgQc1yc6aAJeM/Al9i7q/GsFMStKIp92vBORYVaalx4pe+5oM9E3al8YVuaDDx6NLyi4A== X-Received: by 2002:a1c:81c9:: with SMTP id c192mr1990221wmd.2.1601116217085; Sat, 26 Sep 2020 03:30:17 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:16 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:28:01 +0200 Message-Id: <20200926102804.228089-22-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/25] avcodec/utils: Also free encoder extradata on avcodec_open2() error 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" It is owned by libavcodec for encoders. Signed-off-by: Andreas Rheinhardt --- libavcodec/utils.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 05064b560f..a976ceb260 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1034,11 +1034,15 @@ free_and_end: av_opt_free(avctx->priv_data); av_opt_free(avctx); + if (av_codec_is_encoder(avctx->codec)) { #if FF_API_CODED_FRAME FF_DISABLE_DEPRECATION_WARNINGS av_frame_free(&avctx->coded_frame); FF_ENABLE_DEPRECATION_WARNINGS #endif + av_freep(&avctx->extradata); + avctx->extradata_size = 0; + } av_dict_free(&tmp); av_freep(&avctx->priv_data); From patchwork Sat Sep 26 10:28:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22615 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 89E3D44A10F for ; Sat, 26 Sep 2020 13:30:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6429A68B825; Sat, 26 Sep 2020 13:30:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2B1E168B79A for ; Sat, 26 Sep 2020 13:30:19 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id g4so6628082wrs.5 for ; Sat, 26 Sep 2020 03:30:19 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=ycM8hxX8wfr/0DxfwcgMPgYto11tYSaDU7qaE+bK8RQ=; b=mLKPTOlz3U0bm45XUkcsvitjIWgGG9wRTxkVxQxTFJr6wDzD2nYEj9SPY66CgfYUg0 YN9PR8v12OM2Ztep/j2Y9hFGxUAV9YzsZquNa1WiwVjfv4Qxq/epAzz9xWQ0S1bkaIMd Ip7PrfUnQLRXc8gBR6IpoKv8OP54rf4n8I9Ltofeih9TzmyVKcVHmvoBvpY1CwJrJRUc fvGqCQFUEN1TTr9BhFi0ndm0uYsoDnST36XMLqL0Y+yHaDMCqjzzN++7cBoiaCdwbdrO CuqQF7giKkQ9qdyMNoKsgInuXLfpppH3S3AUkTwslu6RsyU1/Ud0Nwk7vaY4JcLMIM3e Sl+g== 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:mime-version:content-transfer-encoding; bh=ycM8hxX8wfr/0DxfwcgMPgYto11tYSaDU7qaE+bK8RQ=; b=k225/+Z40qFxb/Uqq0TtC7ha7pU/Gm3/ZXObzNJ/Zx57Eng/gaGMshrp0ApCBkDXKv MtAa/uh28a34VyGCuZriuvbKPXwFgg80/Zb7onmHcVaR2a/2Bjpo3pX3E9kPqK36YA6k vTtud6lqlwEUA6LLd7W+7aa40BqoarEJO6KRAFitYDyDn7MqQsLZzodpttAP2A/tA3aI RZWYB7sjhrR9rx69Y7r1p1XEz9M/Pku76d4aB35Lakt/Mygo+BGaJ5cUy+VAYK4AUfQv HbZPtUq44OrqLWbxyENwNxOeuYPqmRYC8x+qvhMaHp0EAMqWFswhMHngI0Yr2ZZhDaU2 tPew== X-Gm-Message-State: AOAM533942LrrPVwtGES/7zyhuUGYukBu0ENbzkGZcGtffLRmfnWokA3 mouDKNPJgoznVK3cKkrIvDWaSjOyBWg= X-Google-Smtp-Source: ABdhPJx5Ph94G2wvFp2HuZNwoz/SZ4qs20sFK368xQVOrdVHJORdR5BuLlpfEFIqAY0tgfyBrwSf2Q== X-Received: by 2002:adf:dd82:: with SMTP id x2mr9500815wrl.419.1601116218331; Sat, 26 Sep 2020 03:30:18 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:17 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:28:02 +0200 Message-Id: <20200926102804.228089-23-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 23/25] avcodec/utils: Reindentation 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/utils.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index a976ceb260..af2a4c2a88 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1037,7 +1037,7 @@ free_and_end: if (av_codec_is_encoder(avctx->codec)) { #if FF_API_CODED_FRAME FF_DISABLE_DEPRECATION_WARNINGS - av_frame_free(&avctx->coded_frame); + av_frame_free(&avctx->coded_frame); FF_ENABLE_DEPRECATION_WARNINGS #endif av_freep(&avctx->extradata); @@ -1048,18 +1048,18 @@ FF_ENABLE_DEPRECATION_WARNINGS av_freep(&avctx->priv_data); av_freep(&avctx->subtitle_header); - av_frame_free(&avci->to_free); - av_frame_free(&avci->compat_decode_frame); - av_frame_free(&avci->buffer_frame); - av_packet_free(&avci->compat_encode_packet); - av_packet_free(&avci->buffer_pkt); - av_packet_free(&avci->last_pkt_props); + av_frame_free(&avci->to_free); + av_frame_free(&avci->compat_decode_frame); + av_frame_free(&avci->buffer_frame); + av_packet_free(&avci->compat_encode_packet); + av_packet_free(&avci->buffer_pkt); + av_packet_free(&avci->last_pkt_props); - av_packet_free(&avci->ds.in_pkt); - av_frame_free(&avci->es.in_frame); - av_bsf_free(&avci->bsf); + av_packet_free(&avci->ds.in_pkt); + av_frame_free(&avci->es.in_frame); + av_bsf_free(&avci->bsf); - av_buffer_unref(&avci->pool); + av_buffer_unref(&avci->pool); av_freep(&avci); avctx->internal = NULL; avctx->codec = NULL; From patchwork Sat Sep 26 10:28:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22618 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 553B944B313 for ; Sat, 26 Sep 2020 13:32:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BE17568B832; Sat, 26 Sep 2020 13:30:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5E5DF68B78A for ; Sat, 26 Sep 2020 13:30:20 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id g4so6628114wrs.5 for ; Sat, 26 Sep 2020 03:30:20 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=MxAQcCZXRlmLDsmjzWU+fXCThcTmSOLKftW4jzb2l+Q=; b=FA5E5TNRapRYutStVGC+04uZfeQLrvImQ0a7JQw2r2Oqg9OQ5f1c8mlP2ajVTAo40J p6EWYv1OYKVnfzhUwz7bRGpQ5Gabcs5rZ4tVE0rYwJkampidNpcJrJB/r+LIoQYjix4O nWleblJWKh8fo92qqyLaLJUhW8hC/E0p74bzU/befqfwTyzkjT1rj2/rnWyKI0EteK5x 3+ROpFKOQAonCilLo/WLvngDjdW9r6zBqxNMUGRywobp4mrHxMIIthCxE3NSMUwFUGyQ HKBdvQ3moprzqJWvGvXGQo24BVR1OmkCoGgGhXyf1eeBMLgPWkTRhlznUjIX32jtJbKn kYVg== 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:mime-version:content-transfer-encoding; bh=MxAQcCZXRlmLDsmjzWU+fXCThcTmSOLKftW4jzb2l+Q=; b=J/p43v+LVw+ox7glIt2nKQGjz6ICyy3Dqi0WP6BPwX8OodeBSsVnkr+RMSwUJhvyW5 w+sonoonwUTeyCurS0RNrJEHa97T0yKnJ+s8rw8e82ZrxXkhY5f+kBhZZ6R9b5UEOPB/ g9YzJ9wkFSQZZy8Lqk0PdwGcb9vrB0jbEMh+n+1W3YUYl11vyt+9j9lb6my0Zsl63LS4 TyCTZh7AVZ6ll7dLMTAdffz8pZYk4fHJHBgvyHKxSAb8qhlPkBXE0OwxoEcVFPpm8plT STD/N1rIB91xuar6wGYH+EvJqg1+e25s03yYyvhMncc9LOS0qIcBVmrioY1SRV3HE7T9 iHWw== X-Gm-Message-State: AOAM531XnNtALQjhg+2SWYdxNmn3Whq5egxHIsOL6zy43SJHfxKfPI/V nWBBFNlzIXEyR0T0JvRugxKpaMc86RE= X-Google-Smtp-Source: ABdhPJx2VLYkhx7X2r+qCRh4ZPjPBXF4REZUhoS/pEheiWd+hpLMfV9qoMJaXf3HDwsP/9GtJ4HQyQ== X-Received: by 2002:adf:cd05:: with SMTP id w5mr8966728wrm.62.1601116219416; Sat, 26 Sep 2020 03:30:19 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:18 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:28:03 +0200 Message-Id: <20200926102804.228089-24-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 24/25] avcodec/fraps: Use unchecked bitstream reader 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" The fraps decoder already checked for overreads manually (and errored out in this scenario), yet it still enabled implicit checks, leading to worse performance and more code size. This commit disables the implicit bitstream reader checks. For the sample [1] this improves performance from 195105896 to 155851561 decicycles for Clang 10 and from 222801887 to 168270467 decicycles when compiled with GCC 9.3. These values are the average of 10 runs each looping ten times over the input. [1]: samples.ffmpeg.org/ffmpeg-bugs/trac/ticket2593/fraps_flv1_decoding_errors.avi Signed-off-by: Andreas Rheinhardt --- libavcodec/fraps.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/fraps.c b/libavcodec/fraps.c index 7a7673f73f..00fd63ffec 100644 --- a/libavcodec/fraps.c +++ b/libavcodec/fraps.c @@ -31,6 +31,7 @@ * Version 2 files support by Konstantin Shishkov */ +#define UNCHECKED_BITSTREAM_READER 1 #include "avcodec.h" #include "get_bits.h" #include "huffman.h" From patchwork Sat Sep 26 10:28:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22616 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 21FFD44A10F for ; Sat, 26 Sep 2020 13:30:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0ABA868B83C; Sat, 26 Sep 2020 13:30:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6DE9E68B7A4 for ; Sat, 26 Sep 2020 13:30:22 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id a9so1881230wmm.2 for ; Sat, 26 Sep 2020 03:30:22 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=ZzDsxeXDB+Tk6R6kDjozQCnugVBhKcZ+aHLwkzyFS/A=; b=BKWIZFfdYgUjP1gcpm+b8Od33lImhICSa/ULolMESyW3zHZ0IhneeE5t566zN719cV z3WcWPUYlLh7cYkWvvdkeKw5NxHbeLork2FS9Hbyh35uUxuzCdXe7470QKyTvsbpItWs DgWmlTdomfv9KoqBcXVXN0M3suLS6xmCN+NCe4Zam++FIl3YPxRgJTky4pT97ShxHdyR idVZ4SXOi/SLJexOaNQ7y1UyBfTX4sQgbwsZaOV0v92gtY0LwXRr1XQppN6ZASUKX2cL VsH8AzWi5Iq3UbZnzA6NabRA91noN2UIBPnGYMAuhpcG8rwsnuyLwGMkzyGs2WqOXHW9 ikVw== 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:mime-version:content-transfer-encoding; bh=ZzDsxeXDB+Tk6R6kDjozQCnugVBhKcZ+aHLwkzyFS/A=; b=VlZC36chglut6QiJI/WfqU5yh6Kq5qtFwmOEjQuMe9eWOc8x6rgaSPrt5Ew0AJYrNF ZuwkNHgOMT9iAxpRDz992AZpPm+H26crYXv3LDTYtS/xpMLKHebBUnJdvbcR/FdTSdVE mPCWzarnFcWsK50V4voNBrAA+I6bj7wXdiaiTr+XXEXA4AQNh0DUG6sgb9/XMalehwBV 2aHoLIdCZsQW9sxLy4yL7W0mTcWjuhh5kWS5ouCRMTLcoUlUHIf8x73o+MsS0eATgvTC YjZzkNwEpV1yqW8+jEKBj9SUCnu8vVku1xoKXuEm1P8pDZPs83tko1P90TySmK76Ppaa TiOg== X-Gm-Message-State: AOAM532jQNS0cE05Mp410Jxpgq6qIWhYHafPMpsyui5NaMTo11MgHMj8 4IQryVr+cBJfBkUse/HoC00qdOpOkzM= X-Google-Smtp-Source: ABdhPJySATI5ExrE6fThQH5uNLqT8OLEiEPlzVEAPvC2Dr0UUxJIioqHSpZ8s0cnQxElQx/x9A9bNA== X-Received: by 2002:a1c:e1d6:: with SMTP id y205mr2040082wmg.92.1601116221460; Sat, 26 Sep 2020 03:30:21 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:20 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:28:04 +0200 Message-Id: <20200926102804.228089-25-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 25/25] avcodec/fraps: Use cached bitstream reader 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" This proved beneficial for performance: For the sample [1] the number of decicycles in one decode call decreased from 155851561 to 108158037 for Clang 10 and from 168270467 to 128847479 for GCC 9.3. For x86-32 compiled with GCC 9.3 and run on an x64 Haswell the number increased from 158405517 to 202215769, so that the cached bitstream reader is only enabled if HAVE_FAST_64BIT is set. These values are the average of 10 runs each looping five times over the input. [1]: samples.ffmpeg.org/ffmpeg-bugs/trac/ticket2593/fraps_flv1_decoding_errors.avi Signed-off-by: Andreas Rheinhardt --- libavcodec/fraps.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/fraps.c b/libavcodec/fraps.c index 00fd63ffec..8d01b44f11 100644 --- a/libavcodec/fraps.c +++ b/libavcodec/fraps.c @@ -31,6 +31,9 @@ * Version 2 files support by Konstantin Shishkov */ +#include "config.h" + +#define CACHED_BITSTREAM_READER HAVE_FAST_64BIT #define UNCHECKED_BITSTREAM_READER 1 #include "avcodec.h" #include "get_bits.h"