From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 3EDF4427DC for ; Wed, 30 Mar 2022 20:33:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C52BC68B26D; Wed, 30 Mar 2022 23:32:28 +0300 (EEST) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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, -- 2.31.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".