From patchwork Fri Jan 22 21:51:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 25119 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 B31CB44B343 for ; Fri, 22 Jan 2021 23:51:31 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 88DEE68A2BB; Fri, 22 Jan 2021 23:51:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8066F68065D for ; Fri, 22 Jan 2021 23:51:24 +0200 (EET) Received: by mail-wm1-f43.google.com with SMTP id c128so5572130wme.2 for ; Fri, 22 Jan 2021 13:51:24 -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:mime-version :content-transfer-encoding; bh=YW8WIgWT7XkEhlFEZkhG8RqtnCGzUk2+qhIgJq78q94=; b=RoaqJC5/OBYq02V4mggR1OIZ2aB/OgOxsg+ddO6mB2053v2MrHG9zvAqLPExGICWmj 8SW4vMQP1sOnz48tzsZ6KeEoL6TcGwzPG1J86bdko+oDM8oTVGX0SYpqNE55i1WWAjUV r7/n2SKdaQCcCq2/5ttRoAiGd0dCE6q+Jp7kP9s6oByzVyZpHBocC9aMJjTGHM3pYnpQ HvEAhWaQuhnoO7A0tZdevEqqqVJnnpw7+medlZ8AmXY6sGLtplWO/zER9+6J3ip9idqn omxaR9s7vNmaXYiZufbTRBwp/qjTjK91M5uYNV/VrcDI9E9P3WQCLp7r40DCdVWTOzju G3Pw== 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=YW8WIgWT7XkEhlFEZkhG8RqtnCGzUk2+qhIgJq78q94=; b=qp/c497bd/9HgcOlzVRbhdvGVfCHtgihGZxf1AapxgViaGHg0RaSn6oc2SYlkBR4E5 NuIDzNxkscDN8DV4TNcFSW9zRfHt7ruEaltawtL7eOJ6RevbBWtKf6hlq4K0UY+gNP0X YVKYb8VY31oDUYjI0yc9dsIuKX19i09QB5Dg8pQnAx5tceLOczofaX/22iYRpqjM9VbE nY9hheP7v+jIzFMAMdGbR8qY4hk/fOUUiM3X6lGoNeX+JltTAYx77J8jw4qSbMZgkqB3 Aj20D0GQtfImgqoHNOrYh+wBRFhtbH1vbvCOLDs60p122J6J7hhSg6bK6wgUmUtLCMVN zl2g== X-Gm-Message-State: AOAM531g5S6N4+yn0Lv41N5V7asHoD3AtJUmAYd4ykGDQ1JiJfpdw8WV +hIcygx9Emaeig5TD0CT5jbSsDuZX30= X-Google-Smtp-Source: ABdhPJzf3OxA6d74dlISeMXPAopWrB0yi2na9DwGBCgOV/u4Wtld68dq4u4PCV4i/BYWYOXF/3smjA== X-Received: by 2002:a7b:c415:: with SMTP id k21mr5752732wmi.96.1611352283469; Fri, 22 Jan 2021 13:51:23 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id z63sm13128821wme.8.2021.01.22.13.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 13:51:22 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 22 Jan 2021 22:51:16 +0100 Message-Id: <20210122215116.520936-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/dnxhd: Make ff_dxnhd_get_cid_table return a pointer, not index 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" All callers only use the index into ff_dnxhd_cid_table to get a pointer to the desired entry. Signed-off-by: Andreas Rheinhardt --- libavcodec/dnxhddata.c | 46 +++++++++++++++++++++--------------------- libavcodec/dnxhddata.h | 4 +--- libavcodec/dnxhddec.c | 13 ++++++------ libavcodec/dnxhdenc.c | 8 +++----- 4 files changed, 34 insertions(+), 37 deletions(-) diff --git a/libavcodec/dnxhddata.c b/libavcodec/dnxhddata.c index 154be89860..3a69a0f501 100644 --- a/libavcodec/dnxhddata.c +++ b/libavcodec/dnxhddata.c @@ -932,7 +932,7 @@ static const uint8_t dnxhd_1250_run[62] = { 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, }; -const CIDEntry ff_dnxhd_cid_table[] = { +static const CIDEntry dnxhd_cid_table[] = { { 1235, 1920, 1080, 917504, 917504, 0, 6, 10, 4, dnxhd_1235_luma_weight, dnxhd_1235_chroma_weight, @@ -1075,31 +1075,31 @@ const CIDEntry ff_dnxhd_cid_table[] = { { 0 }, { 5888, 255} }, }; -int ff_dnxhd_get_cid_table(int cid) +const CIDEntry *ff_dnxhd_get_cid_table(int cid) { - int i; - for (i = 0; i < FF_ARRAY_ELEMS(ff_dnxhd_cid_table); i++) - if (ff_dnxhd_cid_table[i].cid == cid) - return i; - return -1; + for (int i = 0; i < FF_ARRAY_ELEMS(dnxhd_cid_table); i++) + if (dnxhd_cid_table[i].cid == cid) + return &dnxhd_cid_table[i]; + return NULL; } int avpriv_dnxhd_get_frame_size(int cid) { - int i = ff_dnxhd_get_cid_table(cid); - if (i<0) - return i; - return ff_dnxhd_cid_table[i].frame_size; + const CIDEntry *entry = ff_dnxhd_get_cid_table(cid); + if (!entry) + return -1; + return entry->frame_size; } int avpriv_dnxhd_get_hr_frame_size(int cid, int w, int h) { - int result, i = ff_dnxhd_get_cid_table(cid); + const CIDEntry *entry = ff_dnxhd_get_cid_table(cid); + int result; - if (i < 0) - return i; + if (!entry) + return -1; - result = ((h + 15) / 16) * ((w + 15) / 16) * (int64_t)ff_dnxhd_cid_table[i].packet_scale.num / ff_dnxhd_cid_table[i].packet_scale.den; + result = ((h + 15) / 16) * ((w + 15) / 16) * (int64_t)entry->packet_scale.num / entry->packet_scale.den; result = (result + 2048) / 4096 * 4096; return FFMAX(result, 8192); @@ -1107,10 +1107,10 @@ int avpriv_dnxhd_get_hr_frame_size(int cid, int w, int h) int avpriv_dnxhd_get_interlaced(int cid) { - int i = ff_dnxhd_get_cid_table(cid); - if (i < 0) - return i; - return ff_dnxhd_cid_table[i].flags & DNXHD_INTERLACED ? 1 : 0; + const CIDEntry *entry = ff_dnxhd_get_cid_table(cid); + if (!entry) + return -1; + return entry->flags & DNXHD_INTERLACED ? 1 : 0; } static int dnxhd_find_hr_cid(AVCodecContext *avctx) @@ -1140,8 +1140,8 @@ int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth) if (!mbs) return 0; - for (i = 0; i < FF_ARRAY_ELEMS(ff_dnxhd_cid_table); i++) { - const CIDEntry *cid = &ff_dnxhd_cid_table[i]; + for (i = 0; i < FF_ARRAY_ELEMS(dnxhd_cid_table); i++) { + const CIDEntry *cid = &dnxhd_cid_table[i]; int interlaced = cid->flags & DNXHD_INTERLACED ? 1 : 0; if (cid->width == avctx->width && cid->height == avctx->height && interlaced == !!(avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) && @@ -1163,8 +1163,8 @@ int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth) void ff_dnxhd_print_profiles(AVCodecContext *avctx, int loglevel) { int i, j; - for (i = 0; i < FF_ARRAY_ELEMS(ff_dnxhd_cid_table); i++) { - const CIDEntry *cid = &ff_dnxhd_cid_table[i]; + for (i = 0; i < FF_ARRAY_ELEMS(dnxhd_cid_table); i++) { + const CIDEntry *cid = &dnxhd_cid_table[i]; for (j = 0; j < FF_ARRAY_ELEMS(cid->bit_rates); j++) { if (!cid->bit_rates[j]) break; diff --git a/libavcodec/dnxhddata.h b/libavcodec/dnxhddata.h index cfa6b0c99d..898079cffc 100644 --- a/libavcodec/dnxhddata.h +++ b/libavcodec/dnxhddata.h @@ -58,9 +58,7 @@ typedef struct CIDEntry { AVRational packet_scale; } CIDEntry; -extern const CIDEntry ff_dnxhd_cid_table[]; - -int ff_dnxhd_get_cid_table(int cid); +const CIDEntry *ff_dnxhd_get_cid_table(int cid); int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth); void ff_dnxhd_print_profiles(AVCodecContext *avctx, int loglevel); diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c index 09bc6f9b59..c78d55aee5 100644 --- a/libavcodec/dnxhddec.c +++ b/libavcodec/dnxhddec.c @@ -113,18 +113,19 @@ static av_cold int dnxhd_decode_init(AVCodecContext *avctx) static int dnxhd_init_vlc(DNXHDContext *ctx, uint32_t cid, int bitdepth) { if (cid != ctx->cid) { - int index; + const CIDEntry *cid_table = ff_dnxhd_get_cid_table(cid); - if ((index = ff_dnxhd_get_cid_table(cid)) < 0) { + if (!cid_table) { av_log(ctx->avctx, AV_LOG_ERROR, "unsupported cid %"PRIu32"\n", cid); return AVERROR(ENOSYS); } - if (ff_dnxhd_cid_table[index].bit_depth != bitdepth && - ff_dnxhd_cid_table[index].bit_depth != DNXHD_VARIABLE) { - av_log(ctx->avctx, AV_LOG_ERROR, "bit depth mismatches %d %d\n", ff_dnxhd_cid_table[index].bit_depth, bitdepth); + if (cid_table->bit_depth != bitdepth && + cid_table->bit_depth != DNXHD_VARIABLE) { + av_log(ctx->avctx, AV_LOG_ERROR, "bit depth mismatches %d %d\n", + cid_table->bit_depth, bitdepth); return AVERROR_INVALIDDATA; } - ctx->cid_table = &ff_dnxhd_cid_table[index]; + ctx->cid_table = cid_table; av_log(ctx->avctx, AV_LOG_VERBOSE, "Profile cid %"PRIu32".\n", cid); ff_free_vlc(&ctx->ac_vlc); diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c index 0144797d1b..2461c51727 100644 --- a/libavcodec/dnxhdenc.c +++ b/libavcodec/dnxhdenc.c @@ -351,7 +351,7 @@ static av_cold int dnxhd_init_rc(DNXHDEncContext *ctx) static av_cold int dnxhd_encode_init(AVCodecContext *avctx) { DNXHDEncContext *ctx = avctx->priv_data; - int i, index, ret; + int i, ret; switch (avctx->pix_fmt) { case AV_PIX_FMT_YUV422P: @@ -411,10 +411,8 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - index = ff_dnxhd_get_cid_table(ctx->cid); - av_assert0(index >= 0); - - ctx->cid_table = &ff_dnxhd_cid_table[index]; + ctx->cid_table = ff_dnxhd_get_cid_table(ctx->cid); + av_assert0(ctx->cid_table); ctx->m.avctx = avctx; ctx->m.mb_intra = 1;