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;