From patchwork Wed Dec 30 23:31:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 24697 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 39DEA44A7BE for ; Thu, 31 Dec 2020 01:32:48 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 22D5368A84E; Thu, 31 Dec 2020 01:32:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3593568A6B6 for ; Thu, 31 Dec 2020 01:32:38 +0200 (EET) Received: by mail-ej1-f45.google.com with SMTP id ce23so23672594ejb.8 for ; Wed, 30 Dec 2020 15:32:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=cN73UNNfBx0N+odfT8rDmAxyjTELaLRX/gW7AGEnXQA=; b=nu7WNjMFQHT7ZHgmfoW+fBuTYTL5fglMo3gCMBlJ4B1u9sWNrmK/ckwq4NrvRElJ7C b50PXHwI1Fyr/bGRKsE8cXbdfr8hejq6w2zqt/z+lZ5+11aC7zFhXC4Zl84DwXRvZUhm Txx9wtBaaUPaAdwwlXA2KyI28pKX/Hw6i887TG0UmGk+C7Z8jelh/xCCW+DrnO4bQK6V DhdGruQDhXoKYnfD23N367jYK30/5sPnb38V0MAgT6dZ4/Qh2JgDm5pp6JQK2O1DIDPQ pyDbJw6oVqfrNwaSaBskrwpfZlU73MPt/eCr4jfgsT6I2EdPhGpbxEkXRZ15BrqmPLCK WFFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=cN73UNNfBx0N+odfT8rDmAxyjTELaLRX/gW7AGEnXQA=; b=GYoj5VZ8EymYGWo3gKSqaobf43hff+BMvZaDjUyNmKfUgMZEXDl1yeyfPOeKtESSiK +LidWZBjDYuFkuuLTyPbDAVdu1hJcb1JZsPIyOEqUDEK7wZ3JgLWq4eId10XMqzc23UE 39YkarkikerWY/HcfmmOrjQske/MZRnCWNz03BZPMkM9DxEJeCFUQcgtE1/y1DG97qch JFuFXFzEA4Bm25oQbc/JHBbnWAwIEIKQnROtICoBz7J6lSfSg0sHBEPLekHdedZuXRfl e3lwNofJz6Twm/M3IOu2un3cqjgNAEbdfBmhg3nvn+LnKapoIOUMkt6eriZcrmPNiXXB GZFQ== X-Gm-Message-State: AOAM532go1lPhg6THyOQK2olLqynMPOnp1+6BU4ZK/8vz/LEJPNkhhEr r5w0fP4EHifYf+2wLohtfG2h9dIDIR0= X-Google-Smtp-Source: ABdhPJzg9Cx+4YQolO2E+MQqX6UOTEMHmAYilw6CAdz1zJ8pSCOg4V2bYLmZv8PVoWoLnqZD7MrLcA== X-Received: by 2002:a17:906:578e:: with SMTP id k14mr10120728ejq.90.1609371157464; Wed, 30 Dec 2020 15:32:37 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id u19sm19630409ejg.16.2020.12.30.15.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 15:32:36 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 31 Dec 2020 00:31:31 +0100 Message-Id: <20201230233157.1055287-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201230233157.1055287-1-andreas.rheinhardt@gmail.com> References: <20201230233157.1055287-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/30] avcodec/mlpenc: Simplify finding best codebook 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" Finding the best codebook involves comparing different paths, where each path is a sequence of several decisions (namely which codebook to use). Up until now, these sequence was encoded in a NUL-terminated string and the actual decisions were encoded as ’\0'..'\3' (which encoded 0..3). This commit modifies this to actually encode it via 0..3 by switching away from a C-string to a simple array with an explicit length field. Signed-off-by: Andreas Rheinhardt --- libavcodec/mlpenc.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index f6159d39c8..9782cb8261 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -1947,24 +1947,16 @@ static void rematrix_channels(MLPEncodeContext *ctx) ****************************************************************************/ typedef struct { - char path[MAJOR_HEADER_INTERVAL + 3]; + char path[MAJOR_HEADER_INTERVAL + 2]; + int cur_idx; int bitcount; } PathCounter; -static const char *path_counter_codebook[] = { "0", "1", "2", "3", }; - -#define ZERO_PATH '0' #define CODEBOOK_CHANGE_BITS 21 static void clear_path_counter(PathCounter *path_counter) { - unsigned int i; - - for (i = 0; i < NUM_CODEBOOKS + 1; i++) { - path_counter[i].path[0] = ZERO_PATH; - path_counter[i].path[1] = 0x00; - path_counter[i].bitcount = 0; - } + memset(path_counter, 0, (NUM_CODEBOOKS + 1) * sizeof(*path_counter)); } static int compare_best_offset(BestOffset *prev, BestOffset *cur) @@ -1978,18 +1970,11 @@ static int compare_best_offset(BestOffset *prev, BestOffset *cur) static int best_codebook_path_cost(MLPEncodeContext *ctx, unsigned int channel, PathCounter *src, int cur_codebook) { - BestOffset *cur_bo, *prev_bo = restart_best_offset; + int idx = src->cur_idx; + BestOffset *cur_bo = ctx->best_offset[idx][channel], + *prev_bo = idx ? ctx->best_offset[idx - 1][channel] : restart_best_offset; int bitcount = src->bitcount; - char *path = src->path + 1; - int prev_codebook; - int i; - - for (i = 0; path[i]; i++) - prev_bo = ctx->best_offset[i][channel]; - - prev_codebook = path[i - 1] - ZERO_PATH; - - cur_bo = ctx->best_offset[i][channel]; + int prev_codebook = src->path[idx]; bitcount += cur_bo[cur_codebook].bitcount; @@ -2052,7 +2037,8 @@ static void set_best_codebook(MLPEncodeContext *ctx) prev_best_bitcount = temp_bitcount; if (src_path != dst_path) memcpy(dst_path, src_path, sizeof(PathCounter)); - av_strlcat(dst_path->path, path_counter_codebook[codebook], sizeof(dst_path->path)); + if (dst_path->cur_idx < FF_ARRAY_ELEMS(dst_path->path) - 1) + dst_path->path[++dst_path->cur_idx] = codebook; dst_path->bitcount = temp_bitcount; } } @@ -2069,7 +2055,7 @@ static void set_best_codebook(MLPEncodeContext *ctx) for (index = 0; index < ctx->number_of_subblocks; index++) { ChannelParams *cp = ctx->seq_channel_params + index*(ctx->avctx->channels) + channel; - best_codebook = *best_path++ - ZERO_PATH; + best_codebook = *best_path++; cur_bo = &ctx->best_offset[index][channel][best_codebook]; cp->huff_offset = cur_bo->offset;