From patchwork Mon Mar 4 12:43:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 46745 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a919:b0:19e:cdac:8cce with SMTP id cd25csp2774109pzb; Mon, 4 Mar 2024 04:41:37 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVS5ggyQDIX0ZQ8zwJK9K2LoAID6tpRXGCzAfe44gaUdAxBCETfYYKNVWD0A2qPJrMiHYWHvax6atvrJv92SI80gE4e+sIOf7SZUg== X-Google-Smtp-Source: AGHT+IHG64MmbUuJUx+/xso4ltrxqSB65xwsaS1Fp2WW/irAthWayqw4wqrL3536lduyjZo8qW9A X-Received: by 2002:a50:f60d:0:b0:566:902e:65e4 with SMTP id c13-20020a50f60d000000b00566902e65e4mr8666629edn.18.1709556097280; Mon, 04 Mar 2024 04:41:37 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q18-20020a056402519200b00566a2345727si4029351edd.0.2024.03.04.04.41.36; Mon, 04 Mar 2024 04:41:37 -0800 (PST) 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=@outlook.com header.s=selector1 header.b=FiN9ijsZ; arc=fail (body hash mismatch); 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 265E768D3BC; Mon, 4 Mar 2024 14:41:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04olkn2082.outbound.protection.outlook.com [40.92.73.82]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 05B2068CFE3 for ; Mon, 4 Mar 2024 14:41:26 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cmNAVJmSSU+ySNu2ofhn4GShiA1OM0EkNNJ70/cFkoSK0l9pLAHhavEX+SuPJoE2DwbE3dVoptm2YGo0Z2dZResOJm79ohqrdkw3F7JqR5xdoYalhjfndibzYeh0UjwVJ4B4qG1gFRGxt1dbKfUf0zXq9+S/NU5i9Ag69OkPLIG63WVKRvoJXmzQTk08mMzTlDz+H9Tyk3xzOZtFubY6/4izKzKyAcXrWr8xL5MrdBTr6f/w16PUWMGr9pVx6A2Ol0kIthN9k1oxJDBtHVbxGmxfISWATq/VQVLeKbRgH2DAPcoTmIz//8HlJSlwhjZhDa5chn+EALSzm2k/0lhHOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=x/nnx44vUPP7g39BC+yrR9AyhAZCDH8TBr2JYuViXTQ=; b=fz/eCqTgCk7F8f1v5PnOSz9Mb7pDmIAnD2H/SwN5ddeM4PqRQ+/NN7VAohbcfO7sX3HZe7xdl6vjLkIOLSD1vBPyH2pCKASgL5sI6esAbVfp+0dGqq1yPCg2oYJVfIIEdA4IMIHiSshQb4vzCm5WstTOLy1877qBMGVK20u012R1wXcXpQ62Nmy0zYZzirxkm3+R4S2fWahYR4mcDasbgOyWDviWXtdstQCfzgiK81U88R6Jipvxdei9Oz9nTxR0yoQSLZADpxAixOeAcEKVa2q2PWx6YH+kW8ftpSRpPwSN953hJxThQuyUhtJkqQhzN7t9ES0rFzNGlS9CSRv3dQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=x/nnx44vUPP7g39BC+yrR9AyhAZCDH8TBr2JYuViXTQ=; b=FiN9ijsZnFmp87uubyVuVGIHFJjOPv7blee+md87iYrmZvZcazs5sH8LJzFGoJXAM1vXSRZ29DG+9ugh+VVVvJYElt/waedP5aH3ql25rb/g1NpXPRBd/UuQr9+2TKX51CYZmsyv/T4tIkvs7LePyECysX/uC8IzlPzi1Ka+lTxtfE/rnAWc25NxEX2elDmN2UOhrXpKVKplz9PzOGeshgqx+Z+QkDg5e+d3Xop4gmWp9PFjeHAMEki55B/h16nHVbA8Wv2nD4fJOzN73oNpbGsFugD4nsK3JKJxq03YiKOibnVn2Za9ehEZ5jFQr8CYKvHfFkLHEbz1G0Wi1meYDQ== Received: from DU0P250MB0747.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:3cb::16) by DB9P250MB0523.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:338::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.37; Mon, 4 Mar 2024 12:41:24 +0000 Received: from DU0P250MB0747.EURP250.PROD.OUTLOOK.COM ([fe80::db07:87f6:7c75:38cc]) by DU0P250MB0747.EURP250.PROD.OUTLOOK.COM ([fe80::db07:87f6:7c75:38cc%3]) with mapi id 15.20.7292.036; Mon, 4 Mar 2024 12:41:24 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Mar 2024 13:43:15 +0100 Message-ID: X-Mailer: git-send-email 2.40.1 X-TMN: [CkItFQ0bWp95XqzN8E4Rlvg+/2WwBSGWqRl0WYzS99o=] X-ClientProxiedBy: ZR0P278CA0005.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::15) To DU0P250MB0747.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:3cb::16) X-Microsoft-Original-Message-ID: <20240304124316.1276127-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0P250MB0747:EE_|DB9P250MB0523:EE_ X-MS-Office365-Filtering-Correlation-Id: a7e1b545-097d-4c23-355f-08dc3c4866bc X-MS-Exchange-SLBlob-MailProps: quCBMN2EvO9jQf2BBpFaKEGBeEuTTpzwlmXPasmCjU+odXYPilw1Bzut65ThH3jI7avwTim8xwCeUTYaVHttVIxdhY2V8swhNf3FpMFHzP1AP4ilwdcMGekWD/JIAyFHxVjpFLUeUuBHWhInlLxsJfgRH2+c0+4WV0PsBPv8uBOellnceDd+MwxSImXQy9Yuf4r5eOX/pQ1gsNs2lGDd5xIBSUylRGFuc+MEu3txVUzu3WDS5kOOsBMB3q1Yqg8/1L8PE/jXEPFuCfSFhmN8LdJA7II1skMkBHweidsPszQ+o+B4EiNJVhGd+Wonhmvz+PwtlMj63E12X0Asjmh7E5LNI45pOVRrTYsvDXOfnle55mCCoWwCOuxBF8+X/lE/hNs2TA5r3+cvahzXcKWuht/ti1XzpXb0pXj0acZp1DAhRsyh1jhQ3GC6RoXn93GBSkD/79r2/4dP1EscQawFL5Inr9Y8blryD6W9HSUwkVtOusC3sVl1ARb7NdhvxIT/h/3Clbzb3fw7bo/Ecaml8o5eXqPa+aZDO/2COjWvV+yK8xM35ZvKE5JSKTDfhaSEEhNKG/+xi2mfmrCMzOCJbZplKZr/fw7uJVdZciWgV8+qyVD+UUY8wzxB8HEN1Co0xoeRQISQD19Fj1CieNEU4Rl5KxOMLDlvxuRM+Mtfgm6iVrW+1M4FqON0iz/0lfBhXcDJSS8lJqR8a3Dz69XCVA== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oELub6vTv6kq/6oyeNzKJBSbIyuN06Ho+KANAYEvTa9/bXmM9WVENPkFuGuOiF3A5v13/5iemASumat12h3XhkutB81b1aDJb+vDbfl8MPQs4YcwG91byfc8Xdpgno9t5AkUcNxlLjRhtRaatA3ype3rCJG9TuDVYI6RTfpA2TJT88kryKUao7uuUJxVzx7BCvBJg4ZHiRGpvgOlKwHnQ5GpTgy+gZZ1l20UdQlF8nyskzuKF25w1/JBU6/7vikgF7dwaD4apADlNX3hOL9jYAXypC0P2ph1sIOHSF1SQ3T9iX+g5oBSYbF8k1JiQZUnRGYVDI0CxyBDH4fPEcTa9XTUdyeHPsIH2hTXCeeSfdQ9VSoF2vW5Wct4qG17Gyo6+Vh9helbMwWmxVH+qsuz1S5UjO1hgZLzsxhKNVyn2xY/RdDYhDSz4OdHBTds+jc63kOQJmrlKORtRtC28bIMNc8b63ctSRfg0jisZvr4Ugu+vNkg4siAZpifaHbmnKpZxPX96Pl5OyJAZ8R5bgkULWJ2OF6IK4SRhUAKoS+Sc6GjYXxalwVs4/37pwO+mTPn72BX7nVS64lyE2UsPsgCt2s2Q26n+qDiaF8f8QIpM7HBulMRrRhNx8Up7NgUtVhI X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6HuCgf900lC0NxnboEK7rEw9lBFj41RnLaUQ7bC7RJAAs5eEjkd8qIVQ6rsF3i3D7UqAD7zarxdqkKOQHqziidnVa/kXdWLqKmRs5q02Qf4n+1fP6Tk4jJiERL4+b1rQm0jWuIlYzysvrlDDdfjHQTS31jCk+/m+LEXvKgN/BJmF9X+gpFURmjzd33n8dDn2enJXjC4YnG4Oik67I6PownbXodCCb1/E/+JOPatUGBT9Mkiq4cEAyh8p3pLl8i1fsk5FNeKI7owNSwdqKkQRedaSuC+nGVawb6KMOsZBGN1qu9W8QBQFYgVtmQ0E2iWeaoPZDAW8gjKHo3txJ3uu1pW5BOzNB2SbYsvSOVFlTTBcjRER1VABxnCMJT+QcIXL4oiF915IKWFIfWwgmQSFJgKcpeoSmjy2uOqJMy2DtpcgQHvA+GD5m4o/mwZvVFz+rbidm83CMfe4d6hzYpAO8iab/oY8vJBxIdGXDhknjN63OLxeeW/sv/wfv4xm2XuxNja1AnYR2BbQJWFiEndQD1PgmXtus93cJFNLqTga1J3sofxg68Amur8ke8KaJ1SQFyKi9QEZOd8whIVOnNCk5pRxU0DkTtybO1jBfLdf+LyRNsmRDnDWuxoWkots48CuDeDW2VQ8P2kcwtm6JFJMyjqNZvydwetuPnR02HmJZbN3g+M1gIPxWj5fck3zbgzErWrArbGG9/7taSOc9V1ib3W3z727dDy7tel4rrVq/1uUyl0RuNHrtj1jlm3u5PgMScYufIkkVn7dqofumCyrzACIP3yKQLK39QUolPfGBDXesjle9TD6hHeuqrQQk0osoGTMFih5ECo/DUljzdqd8lSEd8i7II+grqvT0BTkEJWWACBFjbzv2uriow3nAbeJzQPQ9P6w/zazrukczZQGAjiuhpljgFvEh8YP6ScPHp0wZBQ929R24v1KxztSUdHHkAlTGzFWTxEaCyAods9Sk7HeqyL9C+wqlYP5I07PdYMC0Ag3RoRCN8TGz8yHi8iGMVz2lCzblNyQTPkgEXIXObUqbdIB1vbdasktZNi20bfz7JiDcPOxZWM+ilaL9x0fScZLaF6qeMtzfuM9l066/O45VCgZqkazayqI4Az9RXpkA33inX5kiQqM7/yRO2ez3G+870PsfgEgT7W8hqMij5pUfpfDNA1VxO2ljM+RQipgeE+udoBnQSpa0Wa2xTG7/ikZOGeq+D4uMdazDyVcUXzrJ2AiLKRJzm1hfy/9DsrvpzKO8LZsQlA/7TziSuQ+lcdXtcJEasjNtDk+mWk7KQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a7e1b545-097d-4c23-355f-08dc3c4866bc X-MS-Exchange-CrossTenant-AuthSource: DU0P250MB0747.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2024 12:41:24.0834 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9P250MB0523 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/hq_hqadata: Move data in a header X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: bToNxJEn6ZZh It is only used by hq_hqa.c, so said header can simply be included there. Also move the code to initialize the VLCs to hq_hqa.c. Signed-off-by: Andreas Rheinhardt --- libavcodec/Makefile | 3 +- libavcodec/hq_hqa.c | 39 +++++++++++---- libavcodec/hq_hqa.h | 60 ----------------------- libavcodec/{hq_hqadata.c => hq_hqadata.h} | 34 ++++++------- 4 files changed, 48 insertions(+), 88 deletions(-) delete mode 100644 libavcodec/hq_hqa.h rename libavcodec/{hq_hqadata.c => hq_hqadata.h} (99%) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index eadaab5ec4..cf81a55edb 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -451,8 +451,7 @@ OBJS-$(CONFIG_HEVC_V4L2M2M_DECODER) += v4l2_m2m_dec.o OBJS-$(CONFIG_HEVC_V4L2M2M_ENCODER) += v4l2_m2m_enc.o OBJS-$(CONFIG_HEVC_VIDEOTOOLBOX_ENCODER) += videotoolboxenc.o OBJS-$(CONFIG_HNM4_VIDEO_DECODER) += hnm4video.o -OBJS-$(CONFIG_HQ_HQA_DECODER) += hq_hqa.o hq_hqadata.o hq_hqadsp.o \ - canopus.o +OBJS-$(CONFIG_HQ_HQA_DECODER) += hq_hqa.o hq_hqadsp.o canopus.o OBJS-$(CONFIG_HQX_DECODER) += hqx.o hqxvlc.o hqxdsp.o canopus.o OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o huffyuvdec.o OBJS-$(CONFIG_HUFFYUV_ENCODER) += huffyuv.o huffyuvenc.o diff --git a/libavcodec/hq_hqa.c b/libavcodec/hq_hqa.c index 0df7995f84..510a66fd91 100644 --- a/libavcodec/hq_hqa.c +++ b/libavcodec/hq_hqa.c @@ -21,6 +21,7 @@ #include #include "libavutil/attributes.h" +#include "libavutil/mem_internal.h" #include "avcodec.h" #include "bytestream.h" @@ -28,9 +29,9 @@ #include "codec_internal.h" #include "decode.h" #include "get_bits.h" - -#include "hq_hqa.h" +#include "hq_hqadata.h" #include "hq_hqadsp.h" +#include "vlc.h" /* HQ/HQA slices are a set of macroblocks belonging to a frame, and * they usually form a pseudorandom pattern (probably because it is @@ -48,6 +49,15 @@ * while lavc simply aligns coded_width and coded_height. */ +typedef struct HQContext { + AVCodecContext *avctx; + HQDSPContext hqhqadsp; + + VLC hq_ac_vlc; + VLC hqa_cbp_vlc; + DECLARE_ALIGNED(16, int16_t, block)[12][64]; +} HQContext; + static inline void put_blocks(HQContext *c, AVFrame *pic, int plane, int x, int y, int ilace, int16_t *block0, int16_t *block1) @@ -70,9 +80,9 @@ static int hq_decode_block(HQContext *c, GetBitContext *gb, int16_t block[64], if (!is_hqa) { block[0] = get_sbits(gb, 9) * 64; - q = ff_hq_quants[qsel][is_chroma][get_bits(gb, 2)]; + q = hq_quants[qsel][is_chroma][get_bits(gb, 2)]; } else { - q = ff_hq_quants[qsel][is_chroma][get_bits(gb, 2)]; + q = hq_quants[qsel][is_chroma][get_bits(gb, 2)]; block[0] = get_sbits(gb, 9) * 64; } @@ -81,10 +91,10 @@ static int hq_decode_block(HQContext *c, GetBitContext *gb, int16_t block[64], if (val < 0) return AVERROR_INVALIDDATA; - pos += ff_hq_ac_skips[val]; + pos += hq_ac_skips[val]; if (pos >= 64) break; - block[ff_zigzag_direct[pos]] = (int)(ff_hq_ac_syms[val] * (unsigned)q[pos]) >> 12; + block[ff_zigzag_direct[pos]] = (int)(hq_ac_syms[val] * (unsigned)q[pos]) >> 12; pos++; } @@ -124,10 +134,10 @@ static int hq_decode_frame(HQContext *ctx, AVFrame *pic, GetByteContext *gbc, int slice, start_off, next_off, i, ret; if ((unsigned)prof_num >= NUM_HQ_PROFILES) { - profile = &ff_hq_profile[0]; + profile = &hq_profile[0]; avpriv_request_sample(ctx->avctx, "HQ Profile %d", prof_num); } else { - profile = &ff_hq_profile[prof_num]; + profile = &hq_profile[prof_num]; av_log(ctx->avctx, AV_LOG_VERBOSE, "HQ Profile %d\n", prof_num); } @@ -362,6 +372,17 @@ static int hq_hqa_decode_frame(AVCodecContext *avctx, AVFrame *pic, return avpkt->size; } +static av_cold int hq_init_vlcs(HQContext *c) +{ + int ret = vlc_init(&c->hqa_cbp_vlc, 5, FF_ARRAY_ELEMS(cbp_vlc_lens), + cbp_vlc_lens, 1, 1, cbp_vlc_bits, 1, 1, 0); + if (ret < 0) + return ret; + + return vlc_init(&c->hq_ac_vlc, 9, NUM_HQ_AC_ENTRIES, + hq_ac_bits, 1, 1, hq_ac_codes, 2, 2, 0); +} + static av_cold int hq_hqa_decode_init(AVCodecContext *avctx) { HQContext *ctx = avctx->priv_data; @@ -369,7 +390,7 @@ static av_cold int hq_hqa_decode_init(AVCodecContext *avctx) ff_hqdsp_init(&ctx->hqhqadsp); - return ff_hq_init_vlcs(ctx); + return hq_init_vlcs(ctx); } static av_cold int hq_hqa_decode_close(AVCodecContext *avctx) diff --git a/libavcodec/hq_hqa.h b/libavcodec/hq_hqa.h deleted file mode 100644 index 71aa36706c..0000000000 --- a/libavcodec/hq_hqa.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Canopus HQ/HQA decoder - * - * 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 - */ - -#ifndef AVCODEC_HQ_HQA_H -#define AVCODEC_HQ_HQA_H - -#include - -#include "libavutil/mem_internal.h" - -#include "avcodec.h" -#include "hq_hqadsp.h" -#include "vlc.h" - -#define NUM_HQ_AC_ENTRIES 746 -#define NUM_HQ_PROFILES 22 -#define NUM_HQ_QUANTS 16 - -typedef struct HQContext { - AVCodecContext *avctx; - HQDSPContext hqhqadsp; - - VLC hq_ac_vlc; - VLC hqa_cbp_vlc; - DECLARE_ALIGNED(16, int16_t, block)[12][64]; -} HQContext; - -typedef struct HQProfile { - const uint8_t *perm_tab; - int width, height; - int num_slices; - int tab_w, tab_h; -} HQProfile; - -extern const int32_t * const ff_hq_quants[16][2][4]; -extern const HQProfile ff_hq_profile[NUM_HQ_PROFILES]; - -extern const uint8_t ff_hq_ac_skips[NUM_HQ_AC_ENTRIES]; -extern const int16_t ff_hq_ac_syms [NUM_HQ_AC_ENTRIES]; - -int ff_hq_init_vlcs(HQContext *c); - -#endif /* AVCODEC_HQ_HQA_H */ diff --git a/libavcodec/hq_hqadata.c b/libavcodec/hq_hqadata.h similarity index 99% rename from libavcodec/hq_hqadata.c rename to libavcodec/hq_hqadata.h index 438bdf093a..f71d8bd4fa 100644 --- a/libavcodec/hq_hqadata.c +++ b/libavcodec/hq_hqadata.h @@ -1,5 +1,5 @@ /* - * Canopus HQ/HQA decoder + * Canopus HQ/HQA data * * This file is part of FFmpeg. * @@ -18,7 +18,18 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "hq_hqa.h" +#include + +#define NUM_HQ_AC_ENTRIES 746 +#define NUM_HQ_PROFILES 22 +#define NUM_HQ_QUANTS 16 + +typedef struct HQProfile { + const uint8_t *perm_tab; + int width, height; + int num_slices; + int tab_w, tab_h; +} HQProfile; #define MAT_SIZE 64 @@ -1123,7 +1134,7 @@ static const int32_t qmat4D[MAT_SIZE] = { 0x24CF8B9, 0x384AC0F, 0x709581F, 0x3CDBBA7, }; -const int32_t *const ff_hq_quants[NUM_HQ_QUANTS][2][4] = { +static const int32_t *const hq_quants[NUM_HQ_QUANTS][2][4] = { { { qmat00, qmat02, qmat06, qmat0E }, { qmat01, qmat03, qmat07, qmat0F } }, { { qmat02, qmat06, qmat0E, qmat16 }, { qmat03, qmat07, qmat0F, qmat17 } }, { { qmat04, qmat0A, qmat12, qmat1E }, { qmat05, qmat0B, qmat13, qmat1F } }, @@ -1289,7 +1300,7 @@ static const uint16_t hq_ac_codes[NUM_HQ_AC_ENTRIES] = { 0xFFFE, 0xFFFF, }; -const uint8_t ff_hq_ac_skips[NUM_HQ_AC_ENTRIES] = { +static const uint8_t hq_ac_skips[NUM_HQ_AC_ENTRIES] = { 0, 0, 0, 0, 64, 1, 1, 0, 0, 0, 0, 2, 2, 1, 1, 0, 0, 0, 0, 3, 3, 4, 4, 0, 0, 0, 0, 5, 5, 6, 6, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 7, 7, 8, 8, 9, @@ -1339,7 +1350,7 @@ const uint8_t ff_hq_ac_skips[NUM_HQ_AC_ENTRIES] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -const int16_t ff_hq_ac_syms[NUM_HQ_AC_ENTRIES] = { +static const int16_t hq_ac_syms[NUM_HQ_AC_ENTRIES] = { 1, -1, 2, -2, 0, 1, -1, 3, -3, 4, -4, 1, -1, 2, -2, 5, -5, 6, -6, 1, -1, 1, -1, 7, @@ -8340,7 +8351,7 @@ static const uint8_t hq_tab_21[] = { }; /* List of profiles, order is important */ -const HQProfile ff_hq_profile[NUM_HQ_PROFILES] = { +static const HQProfile hq_profile[NUM_HQ_PROFILES] = { { hq_tab_11, 160, 120, 8, 10, 8 }, // case 0 (default) = case 11 { hq_tab_01, 720, 480, 8, 25, 54 }, { hq_tab_02, 720, 486, 8, 15, 93 }, @@ -8364,14 +8375,3 @@ const HQProfile ff_hq_profile[NUM_HQ_PROFILES] = { { hq_tab_20, 704, 480, 8, 20, 66 }, { hq_tab_21, 704, 576, 8, 24, 66 }, }; - -av_cold int ff_hq_init_vlcs(HQContext *c) -{ - int ret = vlc_init(&c->hqa_cbp_vlc, 5, FF_ARRAY_ELEMS(cbp_vlc_lens), - cbp_vlc_lens, 1, 1, cbp_vlc_bits, 1, 1, 0); - if (ret < 0) - return ret; - - return vlc_init(&c->hq_ac_vlc, 9, NUM_HQ_AC_ENTRIES, - hq_ac_bits, 1, 1, hq_ac_codes, 2, 2, 0); -} From patchwork Mon Mar 4 12:46:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 46746 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a919:b0:19e:cdac:8cce with SMTP id cd25csp2775565pzb; Mon, 4 Mar 2024 04:44:31 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUEr1mpsrNzrqH1CC1+bzvF8b0k7e7eOfIUwRwzIHj5o4OjeaYuo4YjDO0Aa6bO2+x28bI28us+IlHRXgk4rYkhxnGKyOEUtsJInw== X-Google-Smtp-Source: AGHT+IF+QWN28vybB/2shpdb6wEKwBlWpgHa2/VhAA5kR0G9FCsmWLzAPEyPyZ+HbzWGmdwfc9sj X-Received: by 2002:a17:906:f8d6:b0:a45:2e21:c78c with SMTP id lh22-20020a170906f8d600b00a452e21c78cmr2331239ejb.13.1709556270885; Mon, 04 Mar 2024 04:44:30 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id bh6-20020a170906a0c600b00a45464679bbsi805192ejb.76.2024.03.04.04.44.30; Mon, 04 Mar 2024 04:44:30 -0800 (PST) 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=@outlook.com header.s=selector1 header.b=kxgdVwoa; arc=fail (body hash mismatch); 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A26DB68CFFE; Mon, 4 Mar 2024 14:44:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03olkn2054.outbound.protection.outlook.com [40.92.58.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5BF6C68CFFE for ; Mon, 4 Mar 2024 14:44:21 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NZ/dPlKoQNrxpCXKkkzr0N+eye1NeJsIgMVbRV4KHswNBayv6VdFfaUZZS9E83kdfpzv3VOzGVTsVmm52l0CHGjdTkbY7SmIyynm9pcok3VvpacNqSBrgbEAFuB7v2PWdbMHe7fQouffCJUvfd0UN0UDLaP46v/cNL2wlwnvEo0X54ZRKq8geHEOnKz0yAkQsOA33trC/B5AvgQl4dyeL/jTVt1DSBV4AG8WIt33krsET765t+Nmh3091+FDCuXq42p7Y/BTaTYA9SB3gBO7kVunOPsXP+rHDVi2JFsDhsqe6PjmFDvZFTH2zEWFHZHgPHtM7FGAiw1tQ15RC7WlEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OkTHPezX38agQwpY3NJN2dtVFQtpsVKWzYyWYq7fDDs=; b=eFr+ANPVFr0KbsMLccVi4s0X1hXTjzUvM+7AI4ed3IWqLMqOxQSDKdiT0zyQ4mVy1YSF4b8w8FzmC1fR26ngJ2TUKVZnn0yuWBjbQjqocwbiLWbA0AhuH/8q34CGo1AJhjpzK/54OCpZ3wDDRGxkdk3mQh+ZKI6n0meQfFewW81nFPw4seFD+bGm7ABprzU0hrVKE/DsCSBP0P+P76kpQHnnMDbxorBZvQGzTUk0J9vuknJtwhPIIHx9/lLOVJc8kjK0tRPCMatD8KUqXiM3pEOXsT8y5/z4MnXcsx4rbsHAv3izZgGRIlIxeY+DnfMVKUEA4nHuWZNUe9nxzAwaLA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OkTHPezX38agQwpY3NJN2dtVFQtpsVKWzYyWYq7fDDs=; b=kxgdVwoar+OLXdfn8PPCffKf39Kptjom2oi4nTWsnEb6KajFcXEnHVJ5jWcBFwrAIvNVf+JMc/G46pwh3/uuoVQTX8ZR/IQMfERsHFszr5nhdCBBh0Vwtet7tk9KI7trY4tmW1gygfI5J1/UX8sc0aDaD0b+xrL2ARKC2knTzR+2l6b2W5B9/t/qOnom4TZ4Tp2iWk7Qrq5l52+sqwaLFrLS0UVXdTnS5W8uHl77sz2gWgNPaTWCB7gwR7WhqaDuZwYSewKTTjHvqWqphycOX5ZZSbeBWiCbKi/xQ/aaz2UvR0WH7DP+4uk7RMr0CxvW7LaOdvkOedw9DgKBn2GXfA== Received: from DU0P250MB0747.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:3cb::16) by PRAP250MB0490.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:290::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.37; Mon, 4 Mar 2024 12:44:19 +0000 Received: from DU0P250MB0747.EURP250.PROD.OUTLOOK.COM ([fe80::db07:87f6:7c75:38cc]) by DU0P250MB0747.EURP250.PROD.OUTLOOK.COM ([fe80::db07:87f6:7c75:38cc%3]) with mapi id 15.20.7292.036; Mon, 4 Mar 2024 12:44:19 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Mar 2024 13:46:01 +0100 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [KgMLj7D4X2tCVYt/mUgozJwiTn+GiMrcavp2I7txtuE=] X-ClientProxiedBy: ZR0P278CA0074.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::7) To DU0P250MB0747.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:3cb::16) X-Microsoft-Original-Message-ID: <20240304124601.1276245-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0P250MB0747:EE_|PRAP250MB0490:EE_ X-MS-Office365-Filtering-Correlation-Id: 449faac5-1b1a-453b-338b-08dc3c48cf2d X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dkm2Up4K95wi5qBvh6R/ceGc8LEzHgrApiRcmdmo7+RQxz1NOpxXLDGdDxEUHf46LzMXs4qo9oWoZY76O9noGApvT7hLAKg9W2DgIchYBhnLfF6iva8IsL4HN74rJyn12kAXGwfdySMPWmjJsZQyW55lXbTr+wEuYxe4bPuYUbaM6pJucg63v9IGupAhOJgdLhuScSVq2dTECYtymeCse8iQ9xDwUr/1HtleKApqhg8o8VBEH2fs+4wiQB1KWmgHQvFfJ1K1fMCUF/JeA5jvigKopoNqhfrzHRLmJC6ajsQTVn3Rl5oIRxiVkYXG+SLwX+O0cESW6vCtXTNIuVWiCppH4+N5gla07QgfBY86JL5Pe5wIlOxa6AG7RVgPYV9QWpF8cwjyX6GARGo8iSfvhCCVUeMtLhA309g+ErqDbgQ5OZfz4QCUhpjJkgHN1Mm5ZW/sfjwnw9M2kRYbuOlVLfu7Q3BQQdLfrxRtGOxJIDCIQMCXrpi4kHWXwTJxLtGzANBwMnpywkmJ90o/Kej6FSwLugMUNFItHttVE/2Ryp+dxxPqpD/m1l9bUQxW4v2AddBKe9ORbpFPKJcHoqRO7iOl8weYvFX3XPnhIFEdz/VbY/6lmx08ZMYjxZHpPrLO X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GueIPRmUIciUyWwbWUNnBabG9H/qnmsaLF/2icTOqnuwm0v4RlfVX9yPG5xBlMO0YRWmyOwLvFGhgn2WQEcb5e8bqKUJuI6b6miJHpgqch5VngsSNuU83A5/GBYi906/WoAfqtSXHds2VRn5KBmffpMh4u9RHI+M8G7RwMNRaIi9Z2n3nA4+e5CyzaPvuo71pvK7FpcDMesTGtk74F4yM/07DAozJtPb6h7s/rK4rB7TTawev/GzjLeTwrwgODmGa20OowUteFOUvan/1MNW66J/C4jL64bi7UKVzzYmlBUBnD5g1lUIcGTehhJkkJTUwE6lyt3xr8KWbdUMdMa5m4fKjaixFHYd9npnMS92KE5hCIuLt5GFW4ZR7UPf3X+qxefNGsrOhNOTilqZiynCCJYPEim4XM4PRBkhA//wKH3k1z3TAkiZ+AlWmziKuFeDDPlcMUmrdwWExApGLWYcp5tE6lHkDO3EeVBpNKNpLQqZgtnLs4vPcs4J4BfY+jOA5d0mjW/w0gBCSxxYquMkbd4moSyMkSQ3O/dhz7Y0kHUyF/jYRPcY1h45+vn0jdbcXugvnt8LU3HUn8UM45V2/vsKJiAuuFFD3ko4guGwcjuUecDPiN5z3K5R+El0zoXAlULU+onfywIqtvkrXWS/4dNQDcLl2d98cDTtyGnLilDWYi2QsjOQHDoBd/iDCpSvOfNEG29yn6v1C1gsDUWZXZcO8RVtH6a0gkVaEqQotkko/QRTzjDmevazbmPmHW5sfxhnuyV760J0mmCkjkj87NyNeP2yISmLJw7GTCRMihi9NF3tVk1/jzmnAYyucbtQZ4+keNbaYh8AouJJYW6x+A1FMRiIhV1vzIgDHEGjqCATzGSRrgWfm9Faev9K5zsKXbpPdYEFwBQes1TXSj5IC4Kx9mOnN7HDnEgKkyCTXadYj3NxeqICcVW+qHR7uxbdmXmZoO9Bsj7TDlK7JpLogahnDQ4PDuTD6EdlphKfJ6+iw8M4WgmdqYlBOc6N3wf4FmJyQNmlY0jHeMZQq4P7r8YDZJkgUmy2xW+/DUvqHGFW/zKDIkYdkPlq0CD+tfnisgMc1rI+8XViSk5n96lQD4Rj7RZ+lrq4KN1KgHl3Hz8AM/GrE/QMQr9Ufq2Iq5V+DAXkkBZ1gTkAFbQaKR/bKLvCOFrHCnXMToQfscHNwRLkfmXFekt/qlXXiuXn1pj9v/Yg/KFtLzOhvSKJGRv+DWeotDtRvOCnLqmVfn1Xf6Y/A/W949MEiY2RV2pF4OlWrL8/KNdNHFkDOzwptdIKtQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 449faac5-1b1a-453b-338b-08dc3c48cf2d X-MS-Exchange-CrossTenant-AuthSource: DU0P250MB0747.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2024 12:44:19.3094 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PRAP250MB0490 Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/hq_hqa: Make VLC tables static X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: a30WwzORVjRA Signed-off-by: Andreas Rheinhardt --- libavcodec/hq_hqa.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/libavcodec/hq_hqa.c b/libavcodec/hq_hqa.c index 510a66fd91..096fb65dc7 100644 --- a/libavcodec/hq_hqa.c +++ b/libavcodec/hq_hqa.c @@ -22,6 +22,7 @@ #include "libavutil/attributes.h" #include "libavutil/mem_internal.h" +#include "libavutil/thread.h" #include "avcodec.h" #include "bytestream.h" @@ -53,11 +54,12 @@ typedef struct HQContext { AVCodecContext *avctx; HQDSPContext hqhqadsp; - VLC hq_ac_vlc; - VLC hqa_cbp_vlc; DECLARE_ALIGNED(16, int16_t, block)[12][64]; } HQContext; +static VLCElem hq_ac_vlc[1184]; +static VLCElem hqa_cbp_vlc[32]; + static inline void put_blocks(HQContext *c, AVFrame *pic, int plane, int x, int y, int ilace, int16_t *block0, int16_t *block1) @@ -87,7 +89,7 @@ static int hq_decode_block(HQContext *c, GetBitContext *gb, int16_t block[64], } for (;;) { - val = get_vlc2(gb, c->hq_ac_vlc.table, 9, 2); + val = get_vlc2(gb, hq_ac_vlc, 9, 2); if (val < 0) return AVERROR_INVALIDDATA; @@ -195,7 +197,7 @@ static int hqa_decode_mb(HQContext *c, AVFrame *pic, int qgroup, if (get_bits_left(gb) < 1) return AVERROR_INVALIDDATA; - cbp = get_vlc2(gb, c->hqa_cbp_vlc.table, 5, 1); + cbp = get_vlc2(gb, hqa_cbp_vlc, 5, 1); for (i = 0; i < 12; i++) memset(c->block[i], 0, sizeof(*c->block)); @@ -372,33 +374,24 @@ static int hq_hqa_decode_frame(AVCodecContext *avctx, AVFrame *pic, return avpkt->size; } -static av_cold int hq_init_vlcs(HQContext *c) +static av_cold void hq_init_vlcs(void) { - int ret = vlc_init(&c->hqa_cbp_vlc, 5, FF_ARRAY_ELEMS(cbp_vlc_lens), - cbp_vlc_lens, 1, 1, cbp_vlc_bits, 1, 1, 0); - if (ret < 0) - return ret; + VLC_INIT_STATIC_TABLE(hqa_cbp_vlc, 5, FF_ARRAY_ELEMS(cbp_vlc_lens), + cbp_vlc_lens, 1, 1, cbp_vlc_bits, 1, 1, 0); - return vlc_init(&c->hq_ac_vlc, 9, NUM_HQ_AC_ENTRIES, - hq_ac_bits, 1, 1, hq_ac_codes, 2, 2, 0); + VLC_INIT_STATIC_TABLE(hq_ac_vlc, 9, NUM_HQ_AC_ENTRIES, + hq_ac_bits, 1, 1, hq_ac_codes, 2, 2, 0); } static av_cold int hq_hqa_decode_init(AVCodecContext *avctx) { + static AVOnce init_static_once = AV_ONCE_INIT; HQContext *ctx = avctx->priv_data; ctx->avctx = avctx; ff_hqdsp_init(&ctx->hqhqadsp); - return hq_init_vlcs(ctx); -} - -static av_cold int hq_hqa_decode_close(AVCodecContext *avctx) -{ - HQContext *ctx = avctx->priv_data; - - ff_vlc_free(&ctx->hq_ac_vlc); - ff_vlc_free(&ctx->hqa_cbp_vlc); + ff_thread_once(&init_static_once, hq_init_vlcs); return 0; } @@ -411,7 +404,5 @@ const FFCodec ff_hq_hqa_decoder = { .priv_data_size = sizeof(HQContext), .init = hq_hqa_decode_init, FF_CODEC_DECODE_CB(hq_hqa_decode_frame), - .close = hq_hqa_decode_close, .p.capabilities = AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, };