[FFmpeg-devel,v1,2/2] avcodec/hapdec: simplify the calculation of slice start and end

Submitted by lance.lmwang@gmail.com on Oct. 21, 2019, 12:48 a.m.

Details

Message ID 20191021004814.13935-2-lance.lmwang@gmail.com
State New
Headers show

Commit Message

lance.lmwang@gmail.com Oct. 21, 2019, 12:48 a.m.
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavcodec/hapdec.c | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c
index 8c845770cf..dd325bb51a 100644
--- a/libavcodec/hapdec.c
+++ b/libavcodec/hapdec.c
@@ -246,7 +246,7 @@  static int decompress_chunks_thread(AVCodecContext *avctx, void *arg,
 }
 
 static int decompress_texture_thread_internal(AVCodecContext *avctx, void *arg,
-                                              int slice, int thread_nb, int texture_num)
+                                              int jobnr, int thread_nb, int texture_num)
 {
     HapContext *ctx = avctx->priv_data;
     AVFrame *frame = arg;
@@ -254,21 +254,8 @@  static int decompress_texture_thread_internal(AVCodecContext *avctx, void *arg,
     int w_block = avctx->coded_width / TEXTURE_BLOCK_W;
     int h_block = avctx->coded_height / TEXTURE_BLOCK_H;
     int x, y;
-    int start_slice, end_slice;
-    int base_blocks_per_slice = h_block / ctx->slice_count;
-    int remainder_blocks = h_block % ctx->slice_count;
-
-    /* When the frame height (in blocks) doesn't divide evenly between the
-     * number of slices, spread the remaining blocks evenly between the first
-     * operations */
-    start_slice = slice * base_blocks_per_slice;
-    /* Add any extra blocks (one per slice) that have been added before this slice */
-    start_slice += FFMIN(slice, remainder_blocks);
-
-    end_slice = start_slice + base_blocks_per_slice;
-    /* Add an extra block if there are still remainder blocks to be accounted for */
-    if (slice < remainder_blocks)
-        end_slice++;
+    int start_slice = (h_block * jobnr) / ctx->slice_count;
+    int end_slice = (h_block * (jobnr+1)) / ctx->slice_count;
 
     for (y = start_slice; y < end_slice; y++) {
         uint8_t *p = frame->data[0] + y * frame->linesize[0] * TEXTURE_BLOCK_H;