From patchwork Wed Mar 30 20:32:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 35090 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp1011353pzb; Wed, 30 Mar 2022 13:33:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzG/WQCXn587cGPiyAiF4nW19HUz5tDNoejRlaO5be0Ke0DjDv81HKBO7fMJ+ou7T99VxA X-Received: by 2002:a17:907:7f04:b0:6e1:39b8:d1a5 with SMTP id qf4-20020a1709077f0400b006e139b8d1a5mr1529029ejc.83.1648672400325; Wed, 30 Mar 2022 13:33:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648672400; cv=none; d=google.com; s=arc-20160816; b=o9vt5ahrHzJwbn7/q0FWfBrjXzXLb8RJs7f9pJxt4RSrRMBagQ793KQg+wNeUeLXKu /PCrc/PjNLjJFfuzbq1kfskqWSNd86mfvOW3LJjbv3fBjCg2RKW3OAquqY7N6z4OUU7f SCMqfLmej0xInqvYrAP3GztNSUUhicsE8YlpowAamQtomjvysG8HaSViGKRj6pZSa68M zqonfEOD+OJPQwvDPageIc1S+O86QDOkDP31wyxlIIO2B92niOCp1fTbk+6O5+GDPcQ0 G1BkM9Wq9V9yKhCNN7inn92Pgd+o6oBH/mHYZRBYTSrFKcNSZHmOD0QaKeo70YKdAz5L GtJQ== 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:delivered-to; bh=lll/B82ScRUant/YplStZhhe8b0NgiuYNBVU+2xRrHg=; b=cjZ0GZp8HZeBexZK/hiOr63VlZvl9+TsUKCKHsA4MU87SqdZTPiEzswIceL80y672j z20nrYLx6Lwrb57TDKFYMIoNisRHO/9i569XE3SMzu/3be4QtjLufNer4OWe6x7AMMZI xhY3OhLkJkxiMdFAGdNj0lzZKoXoU1l3NBJVFqT4I1PnIvqncIy0OxDPSf49kbzPwHTI IEdeNCbkRF0Jqz4Cy1BfNrFrNvvJpFKxWDXfodqYQNcP//5Q5k0wv0rP233vyanprEbd 22uZQIKF72VF0QLkGq3FjI9BLUIhUA5ix4EVzIAU6dEHzkH9prQf+wAFWGlDEwZ/wVxi PWEw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t20-20020a056402525400b0041b539e9ceesi7014609edd.491.2022.03.30.13.33.19; Wed, 30 Mar 2022 13:33:20 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1232768B285; Wed, 30 Mar 2022 23:32:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BFEA568B284 for ; Wed, 30 Mar 2022 23:32:20 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 5F161E67E5; Wed, 30 Mar 2022 22:32:21 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kG9OI8Jp5tsb; Wed, 30 Mar 2022 22:32:19 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id F1048E6BB6; Wed, 30 Mar 2022 22:32:18 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 22:32:02 +0200 Message-Id: <20220330203205.25937-5-cus@passwd.hu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220330203205.25937-1-cus@passwd.hu> References: <20220330203205.25937-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/8] avcodec/hapenc: use the common texturedsp encode function 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: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: OUbeMw2lI9+/ And add slice thread capabilities. Signed-off-by: Marton Balint --- libavcodec/hap.h | 4 +--- libavcodec/hapenc.c | 34 ++++++++++++++++------------------ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/libavcodec/hap.h b/libavcodec/hap.h index 7e065e4838..fb5a4c4123 100644 --- a/libavcodec/hap.h +++ b/libavcodec/hap.h @@ -80,9 +80,7 @@ typedef struct HapContext { int texture_count; /* 2 for HAQA, 1 for other version */ int texture_section_size; /* size of the part of the texture section (for HAPQA) */ - /* Pointer to the selected compress function (encoder only) */ - int (*tex_fun)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block); - + TextureDSPThreadContext enc; TextureDSPThreadContext dec[2]; } HapContext; diff --git a/libavcodec/hapenc.c b/libavcodec/hapenc.c index ee03fef449..148331a3dd 100644 --- a/libavcodec/hapenc.c +++ b/libavcodec/hapenc.c @@ -56,18 +56,14 @@ enum HapHeaderLength { static int compress_texture(AVCodecContext *avctx, uint8_t *out, int out_length, const AVFrame *f) { HapContext *ctx = avctx->priv_data; - int i, j; if (ctx->tex_size > out_length) return AVERROR_BUFFER_TOO_SMALL; - for (j = 0; j < avctx->height; j += 4) { - for (i = 0; i < avctx->width; i += 4) { - uint8_t *p = f->data[0] + i * 4 + j * f->linesize[0]; - const int step = ctx->tex_fun(out, f->linesize[0], p); - out += step; - } - } + ctx->enc.tex_data.out = out; + ctx->enc.frame_data.in = f->data[0]; + ctx->enc.stride = f->linesize[0]; + avctx->execute2(avctx, ff_texturedsp_compress_thread, &ctx->enc, NULL, ctx->enc.slice_count); return 0; } @@ -236,7 +232,6 @@ static int hap_encode(AVCodecContext *avctx, AVPacket *pkt, static av_cold int hap_init(AVCodecContext *avctx) { HapContext *ctx = avctx->priv_data; - int ratio; int corrected_chunk_count; int ret = av_image_check_size(avctx->width, avctx->height, 0, avctx); @@ -256,32 +251,34 @@ static av_cold int hap_init(AVCodecContext *avctx) switch (ctx->opt_tex_fmt) { case HAP_FMT_RGBDXT1: - ratio = 8; + ctx->enc.tex_ratio = 8; avctx->codec_tag = MKTAG('H', 'a', 'p', '1'); avctx->bits_per_coded_sample = 24; - ctx->tex_fun = ctx->dxtc.dxt1_block; + ctx->enc.tex_funct = ctx->dxtc.dxt1_block; break; case HAP_FMT_RGBADXT5: - ratio = 4; + ctx->enc.tex_ratio = 16; avctx->codec_tag = MKTAG('H', 'a', 'p', '5'); avctx->bits_per_coded_sample = 32; - ctx->tex_fun = ctx->dxtc.dxt5_block; + ctx->enc.tex_funct = ctx->dxtc.dxt5_block; break; case HAP_FMT_YCOCGDXT5: - ratio = 4; + ctx->enc.tex_ratio = 16; avctx->codec_tag = MKTAG('H', 'a', 'p', 'Y'); avctx->bits_per_coded_sample = 24; - ctx->tex_fun = ctx->dxtc.dxt5ys_block; + ctx->enc.tex_funct = ctx->dxtc.dxt5ys_block; break; default: av_log(avctx, AV_LOG_ERROR, "Invalid format %02X\n", ctx->opt_tex_fmt); return AVERROR_INVALIDDATA; } + ctx->enc.raw_ratio = 16; + ctx->enc.slice_count = av_clip(avctx->thread_count, 1, avctx->height / TEXTURE_BLOCK_H); /* Texture compression ratio is constant, so can we computer * beforehand the final size of the uncompressed buffer. */ - ctx->tex_size = FFALIGN(avctx->width, TEXTURE_BLOCK_W) * - FFALIGN(avctx->height, TEXTURE_BLOCK_H) * 4 / ratio; + ctx->tex_size = avctx->width / TEXTURE_BLOCK_W * + avctx->height / TEXTURE_BLOCK_H * ctx->enc.tex_ratio; switch (ctx->opt_compressor) { case HAP_COMP_NONE: @@ -294,7 +291,7 @@ static av_cold int hap_init(AVCodecContext *avctx) case HAP_COMP_SNAPPY: /* Round the chunk count to divide evenly on DXT block edges */ corrected_chunk_count = av_clip(ctx->opt_chunk_count, 1, HAP_MAX_CHUNKS); - while ((ctx->tex_size / (64 / ratio)) % corrected_chunk_count != 0) { + while ((ctx->tex_size / ctx->enc.tex_ratio) % corrected_chunk_count != 0) { corrected_chunk_count--; } @@ -356,6 +353,7 @@ const FFCodec ff_hap_encoder = { .p.id = AV_CODEC_ID_HAP, .priv_data_size = sizeof(HapContext), .p.priv_class = &hapenc_class, + .p.capabilities = AV_CODEC_CAP_SLICE_THREADS, .init = hap_init, .encode2 = hap_encode, .close = hap_close,