diff mbox series

[FFmpeg-devel,04/11] lavc/jpeg2000dec: Thread init_tile()

Message ID f9ab86da06ffe7a259cbcd104b5783b0baf628cb.camel@haerdin.se
State New
Headers show
Series [FFmpeg-devel,01/11] lavc/jpeg2000dec: Finer granularity threading | expand

Checks

Context Check Description
andriy/configure_x86 warning Failed to apply patch

Commit Message

Tomas Härdin Sept. 28, 2022, 10:06 a.m. UTC
This is the one that needs the new execute2()

Comments

Tomas Härdin Sept. 28, 2022, 2:14 p.m. UTC | #1
ons 2022-09-28 klockan 12:06 +0200 skrev Tomas Härdin:
> This is the one that needs the new execute2()

A data race snuck into this one, updated patch attached.

/Tomas
diff mbox series

Patch

From 4e7c65a7a3e049396ce5e3c01db335a532889115 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Mon, 13 Jun 2022 15:09:17 +0200
Subject: [PATCH 04/11] lavc/jpeg2000dec: Thread init_tile()

---
 libavcodec/jpeg2000dec.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 273346538f..00aa73e261 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -1019,12 +1019,19 @@  static int get_ppt(Jpeg2000DecoderContext *s, int n)
     return 0;
 }
 
-static int init_tile(Jpeg2000DecoderContext *s, int tileno)
+static int init_tile(AVCodecContext *avctx, void *td,
+                     int jobnr, int threadnr)
 {
-    int compno;
-    int tilex = tileno % s->numXtiles;
-    int tiley = tileno / s->numXtiles;
-    Jpeg2000Tile *tile = s->tile + tileno;
+    const Jpeg2000DecoderContext *s = avctx->priv_data;
+    int tileno                      = jobnr / s->ncomponents;
+    int tilex                       = tileno % s->numXtiles;
+    int tiley                       = tileno / s->numXtiles;
+    int compno                      = jobnr % s->ncomponents;
+    Jpeg2000Tile *tile              = s->tile + tileno;
+    Jpeg2000Component *comp         = tile->comp + compno;
+    Jpeg2000CodingStyle *codsty     = tile->codsty + compno;
+    Jpeg2000QuantStyle  *qntsty     = tile->qntsty + compno;
+    int ret; // global bandno
 
     if (!tile->comp)
         return AVERROR(ENOMEM);
@@ -1034,12 +1041,6 @@  static int init_tile(Jpeg2000DecoderContext *s, int tileno)
     tile->coord[1][0] = av_clip(tiley       * (int64_t)s->tile_height + s->tile_offset_y, s->image_offset_y, s->height);
     tile->coord[1][1] = av_clip((tiley + 1) * (int64_t)s->tile_height + s->tile_offset_y, s->image_offset_y, s->height);
 
-    for (compno = 0; compno < s->ncomponents; compno++) {
-        Jpeg2000Component *comp = tile->comp + compno;
-        Jpeg2000CodingStyle *codsty = tile->codsty + compno;
-        Jpeg2000QuantStyle  *qntsty = tile->qntsty + compno;
-        int ret; // global bandno
-
         comp->coord_o[0][0] = tile->coord[0][0];
         comp->coord_o[0][1] = tile->coord[0][1];
         comp->coord_o[1][0] = tile->coord[1][0];
@@ -1063,7 +1064,7 @@  static int init_tile(Jpeg2000DecoderContext *s, int tileno)
                                              s->cbps[compno], s->cdx[compno],
                                              s->cdy[compno], s->avctx, s->slices))
             return ret;
-    }
+
     return 0;
 }
 
@@ -2371,9 +2372,6 @@  static int jpeg2000_read_bitstream_packets(Jpeg2000DecoderContext *s)
     for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) {
         Jpeg2000Tile *tile = s->tile + tileno;
 
-        if ((ret = init_tile(s, tileno)) < 0)
-            return ret;
-
         if ((ret = jpeg2000_decode_packets(s, tile)) < 0)
             return ret;
     }
@@ -2668,6 +2666,9 @@  static int jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture,
     picture->key_frame = 1;
     s->slices = avctx->active_thread_type == FF_THREAD_SLICE ? avctx->thread_count : 1;
 
+    if ((ret = avctx->execute2(avctx, init_tile, NULL, NULL, s->numXtiles * s->numYtiles * s->ncomponents)) < 0)
+        goto end;
+
     if (ret = jpeg2000_read_bitstream_packets(s))
         goto end;
 
-- 
2.30.2