From patchwork Mon Feb 12 00:15:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Connor Worley X-Patchwork-Id: 46214 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9002:b0:19e:cdac:8cce with SMTP id d2csp407215pzc; Sun, 11 Feb 2024 16:16:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlD59kdtxtvxO7U9mhWJ4rSgt4o1VfLHOc7+r5yDjpFrDLDo+HLR8MlGgj63fEdKiUuKA0 X-Received: by 2002:a17:906:c78d:b0:a38:5b3c:7c9b with SMTP id cw13-20020a170906c78d00b00a385b3c7c9bmr5193619ejb.18.1707696970344; Sun, 11 Feb 2024 16:16:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707696970; cv=none; d=google.com; s=arc-20160816; b=iV++6YUmBO3MUjYmsTEwf7XWJX+ifcj9kuhviMyl/cK5v8STnc4xEoV/aqvoqSCijH kuWCYKDaFp6JVdQ4M7C99hCuD5GQxtRXUE1PjC90CSvJ36yYBOcJO4Y+YYUKYIaA7OZq I1bqwEcqVkLCjdptttCvhSq+nK3ZP+rdNisItH14Rm57NLpM6O/1NhGRARwZEFe0HM0T 6en7b5mLOcY0h+tDgxlVatmB7wXJ6mTn8U9/DmR8Y7NZbMCX4DM30Zmlj/0voWNdVr98 6TpHWw8TybXnPnH8dK07mhyApzUxiOU4oskcDwwP2BtWHDa7X2kB6/15T+jpSw2qnOOp cOxg== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=aNsbd/1/tbzNAg4vEHy9/xopQePz3FvzDrxktJ9BQMo=; fh=B2tGMhdFjlHVD4IcVt60tgGQOUxV/H7V6n1Fzf2T508=; b=aEy9+Y7/26PqzRHtnHWHs+SAyVL5CUZhw8Vjd4/L8wA/t73Y+8x8LFfAG8OV9sj+/2 +//Hf1DKYlt7hY1hgdJT8fuE8zWy0rHCJPyEAtVVeW3ItGpwVYQQF1nMlmQY2b7K/aBv bhA5/Gk+iGT7PbwcKnVcFKwjrVXCz/Zb6Igsop0xk0rtC0xr0zft/vr1zf+HXwSWLT+k U37GOwSP5Q01sfWh9mdX2o5S/B0qJydAaQb03fxTfZlG8KUSLiPm+2YDHe62+/mXVEB/ +23/iYdHwHasrLIsqEsUX9sT8IRqkByNd7Zyo0fUf9xFVMrN1CBWAjksUPRUEe46rgff tOtg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=l70Ob0uZ; 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=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCXtbd61VNCvEs93zlKTdStxL6TPRMDqvfPvfpCP4EZtStdRCC83oOx0APc5Eh26QxdJY8eesB7hCj3SIvgVVQ1pqWbFbitl45RluY10ibQZ33xzBEIQe5Tiil+XyP+oIYvXTrhO9+fM/LGB5wSuEqT/qfZx7LPCH/dotPCWfgiLw2EVZhS08XkX7vkMSSa6OUDQjqbNyh8SYlWbHCtwZmgHdQvDehW27pqFvha/R8cJZt4XL487nX2FE0IJCUMpWV86gPLvSYX3we5nbGal6VeXDQsPsE/t0ue/t4Ug05evjq1oWtxLLSU1qJ+EArJMqV7n9H1NK7jDk+s6hepFAA8lGDFJ12XfEUFnr+jqU5aWul9EpGrfY986HNw5Pc37l3S419tNpraJ6CtA4bqtJ7WHQdsffwSs+NFGLvCJU9L7KClCRsdW1aC3MllxgPjgxzjFTa/334ygaHDn0OWcmMQ96kMlkSeC65lo7fLSlkpCb6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kpfs250XKX9h27JO54= Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id rh23-20020a17090720f700b00a38328246edsi3279130ejb.793.2024.02.11.16.16.09; Sun, 11 Feb 2024 16:16:10 -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=@gmail.com header.s=20230601 header.b=l70Ob0uZ; 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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4DD3268CA05; Mon, 12 Feb 2024 02:16:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E23DF68CA05 for ; Mon, 12 Feb 2024 02:15:59 +0200 (EET) Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6e09ea155c5so1046544b3a.2 for ; Sun, 11 Feb 2024 16:15:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707696957; x=1708301757; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nY136ZP+7xUPgoLigkySVcMucrQy/7Pry0n6+1eqmV0=; b=l70Ob0uZ3PXugu8fx4PfdOV2j9w0BEE9TUKXA4zEXCYW/TsCRgqUHJghz/78HMlcS2 AUT9gSAWgDE6b8OFvVTe2GBSQq1fntJrp7dSnrakZ5rwZEZW3rBnmb40iE1Aw5KaHgZz dLAbRtSZqsUKY32FEAcBEIx2bQxsEYnBt+Pid93GHp8o2l+kFhL3Pdh/oPPvXuZpBdWW z3YvHqmlbB9uEIRo2N07uiAkjKmY7a49VUj0oSrnsvLvwnMPFzdLQo/h4KWJDt2UCuAT IfH17OtL8USTmqjKIQFoVB2/wokAyTvqs8ga6hO1bpDC/8y1EvtpKJO5zkBqzzx2G1qx 0l0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707696957; x=1708301757; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nY136ZP+7xUPgoLigkySVcMucrQy/7Pry0n6+1eqmV0=; b=tdYiuIev6IDPhIHIgk6mzeI6xCOscAy/N1h3l/7WYaxJf0AZsi7lE8J1s30CzM1hnU ETeTUOyjT7/SVAnd0EQdQYM5Mz88CIDiVTRQBVpKrre11OGRmJ+KP4E3wpSnOveBVKm4 lF5YzMqpM7DS2B48wbgJz2IhGuC9oktw5jcciFyKKuFItJ6Yj8RQrg/oULGi6jWIcJLH inePQ/xaYWP0UcCsQ7+aGVG1AE5AezrNg5LdWtyNuhJqIBd9SjDkUArW2+QYo/yvmHDK K649HZMc5FHb/KRUMsIWOqdSdeh62ryW1beLraDzGWjAiiSknD2Ow86hr3WVJyRm/vdf nLRA== X-Gm-Message-State: AOJu0YxX9vDLPkmd4Vt4FyBtAZ2i7YqADQuHgWyYXFWt+m+F579UEIcL TG5BKKjolq+ct/b+TMuOM2uKRmYTUGNcpZ+L60tbi1SQq6mbFK7KUD6h7AxtruA= X-Received: by 2002:a05:6a20:d707:b0:19e:3c4e:d0f8 with SMTP id iz7-20020a056a20d70700b0019e3c4ed0f8mr4138854pzb.32.1707696957450; Sun, 11 Feb 2024 16:15:57 -0800 (PST) Received: from localhost ([2601:647:4600:84e0:8bf:933e:340c:2dec]) by smtp.gmail.com with UTF8SMTPSA id q1-20020a17090a68c100b002964f55de20sm5383994pjj.30.2024.02.11.16.15.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Feb 2024 16:15:56 -0800 (PST) From: Connor Worley To: ffmpeg-devel@ffmpeg.org Date: Sun, 11 Feb 2024 16:15:52 -0800 Message-ID: <20240212001552.3162-1-connorbworley@gmail.com> X-Mailer: git-send-email 2.43.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/texturedsp: require explicitly-set frame dimensions 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: Connor Worley Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: yQnQQSXdiZWf This change decouples the frame dimensions from avctx, which is useful for DXV decoding, and fixes incorrect behavior in the existing implementation. Tested with `make fate THREADS=7` and `make fate THREADS=7 THREAD_TYPE=slice`. Signed-off-by: Connor Worley --- libavcodec/dds.c | 3 +++ libavcodec/dxv.c | 19 ++++++++++--------- libavcodec/dxvenc.c | 3 +++ libavcodec/hapdec.c | 5 +++++ libavcodec/hapenc.c | 3 +++ libavcodec/texturedsp.h | 1 + libavcodec/texturedsp_template.c | 4 ++-- libavcodec/vbndec.c | 3 +++ libavcodec/vbnenc.c | 3 +++ 9 files changed, 33 insertions(+), 11 deletions(-) diff --git a/libavcodec/dds.c b/libavcodec/dds.c index 67e2325a2a..83f51be802 100644 --- a/libavcodec/dds.c +++ b/libavcodec/dds.c @@ -339,6 +339,9 @@ static int parse_pixel_format(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "Unsupported %s fourcc.\n", av_fourcc2str(fourcc)); return AVERROR_INVALIDDATA; } + + ctx->dec.width = avctx->coded_width; + ctx->dec.height = avctx->coded_height; } else if (ctx->paletted) { if (bpp == 8) { avctx->pix_fmt = AV_PIX_FMT_PAL8; diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c index 2eca14c129..4eaa6dc224 100644 --- a/libavcodec/dxv.c +++ b/libavcodec/dxv.c @@ -843,7 +843,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, { DXVContext *ctx = avctx->priv_data; GetByteContext *gbc = &ctx->gbc; - AVCodecContext cavctx = *avctx; TextureDSPThreadContext texdsp_ctx, ctexdsp_ctx; int (*decompress_tex)(AVCodecContext *avctx); const char *msgcomp, *msgtext; @@ -854,9 +853,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, bytestream2_init(gbc, avpkt->data, avpkt->size); - cavctx.coded_height = avctx->coded_height / 2; - cavctx.coded_width = avctx->coded_width / 2; - avctx->pix_fmt = AV_PIX_FMT_RGBA; avctx->colorspace = AVCOL_SPC_RGB; @@ -943,7 +939,12 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, texdsp_ctx.slice_count = av_clip(avctx->thread_count, 1, avctx->coded_height / TEXTURE_BLOCK_H); ctexdsp_ctx.slice_count = av_clip(avctx->thread_count, 1, - cavctx.coded_height / TEXTURE_BLOCK_H); + avctx->coded_height / 2 / TEXTURE_BLOCK_H); + texdsp_ctx.width = avctx->coded_width; + texdsp_ctx.height = avctx->coded_height; + ctexdsp_ctx.width = avctx->coded_width / 2; + ctexdsp_ctx.height = avctx->coded_height / 2; + /* New header is 12 bytes long. */ if (!old_type) { version_major = bytestream2_get_byte(gbc) - 1; @@ -979,8 +980,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, if (avctx->pix_fmt != AV_PIX_FMT_RGBA) { int i; - ctx->ctex_size = cavctx.coded_width / ctexdsp_ctx.raw_ratio * - cavctx.coded_height / TEXTURE_BLOCK_H * + ctx->ctex_size = avctx->coded_width / 2 / ctexdsp_ctx.raw_ratio * + avctx->coded_height / 2 / TEXTURE_BLOCK_H * ctexdsp_ctx.tex_ratio; ctx->op_size[0] = avctx->coded_width * avctx->coded_height / 16; @@ -1022,13 +1023,13 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, ctexdsp_ctx.tex_data.in = ctx->ctex_data; ctexdsp_ctx.frame_data.out = frame->data[2]; ctexdsp_ctx.stride = frame->linesize[2]; - ret = ff_texturedsp_exec_decompress_threads(&cavctx, &ctexdsp_ctx); + ret = ff_texturedsp_exec_decompress_threads(avctx, &ctexdsp_ctx); if (ret < 0) return ret; ctexdsp_ctx.tex_data.in = ctx->ctex_data + ctexdsp_ctx.tex_ratio / 2; ctexdsp_ctx.frame_data.out = frame->data[1]; ctexdsp_ctx.stride = frame->linesize[1]; - ret = ff_texturedsp_exec_decompress_threads(&cavctx, &ctexdsp_ctx); + ret = ff_texturedsp_exec_decompress_threads(avctx, &ctexdsp_ctx); if (ret < 0) return ret; /* fallthrough */ diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c index bb2c2f8526..62ac812226 100644 --- a/libavcodec/dxvenc.c +++ b/libavcodec/dxvenc.c @@ -298,6 +298,9 @@ static av_cold int dxv_init(AVCodecContext *avctx) ctx->enc.tex_ratio; ctx->enc.slice_count = av_clip(avctx->thread_count, 1, avctx->height / TEXTURE_BLOCK_H); + ctx->enc.width = avctx->width; + ctx->enc.height = avctx->height; + ctx->tex_data = av_malloc(ctx->tex_size); if (!ctx->tex_data) { return AVERROR(ENOMEM); diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c index 3a848e9f67..cca15afa15 100644 --- a/libavcodec/hapdec.c +++ b/libavcodec/hapdec.c @@ -399,6 +399,11 @@ static av_cold int hap_init(AVCodecContext *avctx) return AVERROR_DECODER_NOT_FOUND; } + ctx->dec[0].width = avctx->coded_width; + ctx->dec[0].height = avctx->coded_height; + ctx->dec[1].width = avctx->coded_width; + ctx->dec[1].height = avctx->coded_height; + av_log(avctx, AV_LOG_DEBUG, "%s texture\n", texture_name); return 0; diff --git a/libavcodec/hapenc.c b/libavcodec/hapenc.c index 1464f743d6..ce537c67c9 100644 --- a/libavcodec/hapenc.c +++ b/libavcodec/hapenc.c @@ -276,6 +276,9 @@ static av_cold int hap_init(AVCodecContext *avctx) ctx->enc.raw_ratio = 16; ctx->enc.slice_count = av_clip(avctx->thread_count, 1, avctx->height / TEXTURE_BLOCK_H); + ctx->enc.width = avctx->width; + ctx->enc.height = avctx->height; + /* Texture compression ratio is constant, so can we computer * beforehand the final size of the uncompressed buffer. */ ctx->tex_size = avctx->width / TEXTURE_BLOCK_W * diff --git a/libavcodec/texturedsp.h b/libavcodec/texturedsp.h index 86c8eea02d..0bf49e8729 100644 --- a/libavcodec/texturedsp.h +++ b/libavcodec/texturedsp.h @@ -72,6 +72,7 @@ typedef struct TextureDSPThreadContext { uint8_t *out; // Output frame data } frame_data; ptrdiff_t stride; // Frame linesize + int width, height; // Frame width / height union { const uint8_t *in; // Compressed texture for decompression uint8_t *out; // Compressed texture of compression diff --git a/libavcodec/texturedsp_template.c b/libavcodec/texturedsp_template.c index 9589cc4187..b9caf494cc 100644 --- a/libavcodec/texturedsp_template.c +++ b/libavcodec/texturedsp_template.c @@ -27,8 +27,8 @@ static int exec_func(AVCodecContext *avctx, void *arg, { const TextureDSPThreadContext *ctx = arg; uint8_t *d = ctx->tex_data.out; - int w_block = avctx->coded_width / TEXTURE_BLOCK_W; - int h_block = avctx->coded_height / TEXTURE_BLOCK_H; + int w_block = ctx->width / TEXTURE_BLOCK_W; + int h_block = ctx->height / TEXTURE_BLOCK_H; int x, y; int start_slice, end_slice; int base_blocks_per_slice = h_block / ctx->slice_count; diff --git a/libavcodec/vbndec.c b/libavcodec/vbndec.c index 83ce9e994b..a044c9be3c 100644 --- a/libavcodec/vbndec.c +++ b/libavcodec/vbndec.c @@ -131,6 +131,9 @@ static int vbn_decode_frame(AVCodecContext *avctx, ctx->dec.tex_ratio = 16; linesize = avctx->coded_width; } + + ctx->dec.width = avctx->coded_width; + ctx->dec.height = avctx->coded_height; } else { av_log(avctx, AV_LOG_ERROR, "Unsupported VBN format: 0x%02x\n", format); return AVERROR_PATCHWELCOME; diff --git a/libavcodec/vbnenc.c b/libavcodec/vbnenc.c index abdc33c2c9..ce413e028b 100644 --- a/libavcodec/vbnenc.c +++ b/libavcodec/vbnenc.c @@ -88,6 +88,9 @@ static int vbn_encode(AVCodecContext *avctx, AVPacket *pkt, return AVERROR(EINVAL); } + ctx->enc.width = avctx->width; + ctx->enc.height = avctx->height; + pkt_size = VBN_HEADER_SIZE + linesize * frame->height; if (pkt_size > INT_MAX) return AVERROR(EINVAL);