From: Marton Balint <cus@passwd.hu> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH] lavc/texturedsp: require explicitly-set frame dimensions Date: Wed, 14 Feb 2024 23:30:23 +0100 (CET) Message-ID: <523f9058-9533-2de8-a8a1-be80a9dc3fef@passwd.hu> (raw) In-Reply-To: <20240212001552.3162-1-connorbworley@gmail.com> On Sun, 11 Feb 2024, Connor Worley wrote: > This change decouples the frame dimensions from avctx, which is useful > for DXV decoding, and fixes incorrect behavior in the existing > implementation. Keep in mind that avctx->coded_width/height can change on a per-frame basis. So most likely it is better to assign width/height right before the call to ff_texturedsp_exec* Regards, Marton > > Tested with `make fate THREADS=7` and > `make fate THREADS=7 THREAD_TYPE=slice`. > > Signed-off-by: Connor Worley <connorbworley@gmail.com> > --- > 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); > -- > 2.43.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". > _______________________________________________ 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".
prev parent reply other threads:[~2024-02-14 22:30 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-12 0:15 Connor Worley 2024-02-14 22:30 ` Marton Balint [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=523f9058-9533-2de8-a8a1-be80a9dc3fef@passwd.hu \ --to=cus@passwd.hu \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git