From patchwork Wed Sep 28 10:10:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Tomas_H=C3=A4rdin?= X-Patchwork-Id: 38428 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp100927pzh; Wed, 28 Sep 2022 03:10:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5AZX9k/ys9qyo8eHFRV8Wn/kkXkhIT3VMJ5OaprfOvunduzDAH+iBRpNU47vFlPKBpiCKy X-Received: by 2002:aa7:cb87:0:b0:43b:e650:6036 with SMTP id r7-20020aa7cb87000000b0043be6506036mr32372634edt.350.1664359824786; Wed, 28 Sep 2022 03:10:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664359824; cv=none; d=google.com; s=arc-20160816; b=gRqsRld9JFxA4/IGnMpkzLKgijDulk6WOakYbHPGt4MD1HNdHw+3kLIftG9+4YUKM9 ztdQyN5yos1VABtZZTmS/LFIn4B95lY7EwY1ybJStyGAeLfkYDwkeB+/7AsX9ztxWQGl rNKAdAIU5SA0fXtRl/+NmmVkDqKRC32piH7ybo6OBf9ozE2E1M/mIJhwMVRi/R010Azl TAJo6Xf3qrC/No+jGpIOl9gNbgnyr/9aW++0GfWtWLEwBLuUzhCW2D33HNsN88eaF6x/ YNORI3kC4sSXzRBryn1/PdgG0sCYgPBrohnkBIL1vp6EoG4QMJukCU/r0TXEE/Sx2EpS Vq5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:user-agent:references:in-reply-to:date:to:from :message-id:delivered-to; bh=VgxAtXcsLb+6cmK6T8Yyc/KToq3I5xJHAjdAZ7ewNB4=; b=AfXdqXtUyeYWhO8yOYZojqH8ssTa2qJCNO49y4iD+a2VijMdaGIMhEvZnI4af0toar KDY/tWCXjPmLDWdiO8liTz72bh0Cx0/+FcjNs77QZQZ3O6S+04i+OeTFrNtgGgWOyz2c 0MWZHAiWALBdLWBvtg960zxtCA5crjbrFzBaCjHiGfL0m1zFhKc6DMFNW6v4yG7sg/nI iCpfCOt/aKPoHQpQ34sjirL9F42Sk2z2XrDgJ0xh7FMY1CoTT8doTZkyp0xmWpVwhBy2 xW++2EmKNiq8jck09NZajGKu74tUKl/s+oOJZLdOG9xHW8I7mutdVH3geHg8m3faQ6Ub ZU4w== 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 w19-20020a05640234d300b0044ee88a08b1si5541202edc.277.2022.09.28.03.10.24; Wed, 28 Sep 2022 03:10:24 -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 D7C4068BC6B; Wed, 28 Sep 2022 13:10:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.frobbit.se (mail.frobbit.se [85.30.129.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DF65668BA30 for ; Wed, 28 Sep 2022 13:10:15 +0300 (EEST) Received: from debian.lan (unknown [IPv6:2a00:66c0:a::72c]) by mail.frobbit.se (Postfix) with ESMTPSA id 69F4C1FD1A for ; Wed, 28 Sep 2022 12:10:15 +0200 (CEST) Message-ID: <8db44fd563d0a84d2799259e9a8a51fd930c90be.camel@haerdin.se> From: Tomas =?iso-8859-1?q?H=E4rdin?= To: FFmpeg development discussions and patches Date: Wed, 28 Sep 2022 12:10:14 +0200 In-Reply-To: <65e79fe701374868bb2f4b70ce8fd220938e2e86.camel@haerdin.se> References: <65e79fe701374868bb2f4b70ce8fd220938e2e86.camel@haerdin.se> User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/11] lavc/jpeg2000dec: Component-level threading of write_frame() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: td6aa/PqSNBM Ideally the clipping done by write_frame() and the MCT stuff would be done at the final IDWT stage From 34f055bb0732085d6f97d8f27890b47afb8ca868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= Date: Tue, 14 Jun 2022 15:45:32 +0200 Subject: [PATCH 11/11] lavc/jpeg2000dec: Component-level threading of write_frame() Split off MCT and don't bother with it unless the picture actually uses MCT. --- libavcodec/jpeg2000dec.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 71176d944d..8b984cfc27 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -156,6 +156,7 @@ typedef struct Jpeg2000DecoderContext { // used for idwt slicing int reslevel, dir, slices; int have_dwt97_int; // 1 if any coding style is FF_DWT97_INT + int have_mct; } Jpeg2000DecoderContext; /* get_bits functions for JPEG2000 packet bitstream @@ -604,6 +605,9 @@ static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, return AVERROR_INVALIDDATA; } + if (tmp.mct) + s->have_mct = 1; + if ((ret = get_cox(s, &tmp)) < 0) return ret; tmp.init = 1; @@ -2074,16 +2078,14 @@ static int jpeg2000_dwt97_int_postshift(AVCodecContext *avctx, void *td, #define WRITE_FRAME(D, PIXEL) \ static inline void write_frame_ ## D(const Jpeg2000DecoderContext * s, Jpeg2000Tile * tile, \ - AVFrame * picture, int precision) \ + AVFrame * picture, int precision, int compno) \ { \ const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(s->avctx->pix_fmt); \ int planar = !!(pixdesc->flags & AV_PIX_FMT_FLAG_PLANAR); \ int pixelsize = planar ? 1 : pixdesc->nb_components; \ \ - int compno; \ int x, y; \ \ - for (compno = 0; compno < s->ncomponents; compno++) { \ Jpeg2000Component *comp = tile->comp + compno; \ Jpeg2000CodingStyle *codsty = tile->codsty + compno; \ PIXEL *line; \ @@ -2130,8 +2132,6 @@ static int jpeg2000_dwt97_int_postshift(AVCodecContext *avctx, void *td, } \ line += picture->linesize[plane] / sizeof(PIXEL); \ } \ - } \ - \ } WRITE_FRAME(8, uint8_t) @@ -2139,26 +2139,36 @@ WRITE_FRAME(16, uint16_t) #undef WRITE_FRAME -static int jpeg2000_mct_write_frame(AVCodecContext *avctx, void *td, - int jobnr, int threadnr) +static int jpeg2000_mct(AVCodecContext *avctx, void *td, + int jobnr, int threadnr) { const Jpeg2000DecoderContext *s = avctx->priv_data; - AVFrame *picture = td; Jpeg2000Tile *tile = s->tile + jobnr; /* inverse MCT transformation */ if (tile->codsty[0].mct) mct_decode(s, tile); + return 0; +} + +static int jpeg2000_write_frame(AVCodecContext *avctx, void *td, + int jobnr, int threadnr) +{ + Jpeg2000DecoderContext *s = avctx->priv_data; + AVFrame *picture = td; + Jpeg2000Tile *tile = s->tile + jobnr / s->ncomponents; + int compno = jobnr % s->ncomponents; + if (s->precision <= 8) { - write_frame_8(s, tile, picture, 8); + write_frame_8(s, tile, picture, 8, compno); } else { int precision = picture->format == AV_PIX_FMT_XYZ12 || picture->format == AV_PIX_FMT_RGB48 || picture->format == AV_PIX_FMT_RGBA64 || picture->format == AV_PIX_FMT_GRAY16 ? 16 : s->precision; - write_frame_16(s, tile, picture, precision); + write_frame_16(s, tile, picture, precision, compno); } return 0; @@ -2694,7 +2704,12 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture, s->numXtiles * s->numYtiles * s->ncomponents * s->slices)) < 0) goto end; - if ((ret = avctx->execute2(avctx, jpeg2000_mct_write_frame, picture, NULL, s->numXtiles * s->numYtiles)) < 0) + if (s->have_mct && + (ret = avctx->execute2(avctx, jpeg2000_mct, NULL, NULL, s->numXtiles * s->numYtiles)) < 0) + goto end; + + if ((ret = avctx->execute2(avctx, jpeg2000_write_frame, picture, NULL, + s->numXtiles * s->numYtiles * s->ncomponents)) < 0) goto end; jpeg2000_dec_cleanup(s); -- 2.30.2