aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorTom Butterworth <bangnoise@gmail.com>2015-07-23 00:01:01 +0100
committerLuca Barbato <lu_zero@gentoo.org>2015-07-23 10:46:19 +0200
commitae5a8dca675ee544178225256893e679b750cb63 (patch)
treee51970085cd34f09bec5fab07173fcc0fe6be3cc /libavcodec
parentebe8b5d947c41449c684f17c6826fe6bc46c0360 (diff)
downloadffmpeg-ae5a8dca675ee544178225256893e679b750cb63.tar.gz
hap: Fix slice size computation
A bug was introduced in 977105407cae55876041dddbf4ce0934cdd4cd6c whereby when frame height wasn't divisible by the number of threads, pixels would be omitted from the bottom rows during decode. Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/hap.h2
-rw-r--r--libavcodec/hapdec.c26
2 files changed, 18 insertions, 10 deletions
diff --git a/libavcodec/hap.h b/libavcodec/hap.h
index 75299fda74..e06f933ba8 100644
--- a/libavcodec/hap.h
+++ b/libavcodec/hap.h
@@ -46,7 +46,7 @@ typedef struct HapContext {
uint8_t *snappied; /* Buffer interacting with snappy */
size_t max_snappy; /* Maximum compressed size for snappy buffer */
- int slice_size; /* Optimal slice size */
+ int slice_count; /* Number of slices for threaded operations */
/* Pointer to the selected compress or decompress function */
int (*tex_fun)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c
index 5133a51323..a4880cd3e7 100644
--- a/libavcodec/hapdec.c
+++ b/libavcodec/hapdec.c
@@ -143,14 +143,23 @@ static int decompress_texture_thread(AVCodecContext *avctx, void *arg,
AVFrame *frame = arg;
const uint8_t *d = ctx->tex_data;
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;
- start_slice = slice * ctx->slice_size;
- end_slice = FFMIN(start_slice + ctx->slice_size, avctx->coded_height);
+ /* 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);
- start_slice /= TEXTURE_BLOCK_H;
- end_slice /= TEXTURE_BLOCK_H;
+ 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++;
for (y = start_slice; y < end_slice; y++) {
uint8_t *p = frame->data[0] + y * frame->linesize[0] * TEXTURE_BLOCK_H;
@@ -170,10 +179,6 @@ static int hap_decode(AVCodecContext *avctx, void *data,
HapContext *ctx = avctx->priv_data;
ThreadFrame tframe;
int ret, length;
- int slices = FFMIN(avctx->thread_count,
- avctx->coded_height / TEXTURE_BLOCK_H);
-
- ctx->slice_size = avctx->coded_height / slices;
bytestream2_init(&ctx->gbc, avpkt->data, avpkt->size);
@@ -197,7 +202,7 @@ static int hap_decode(AVCodecContext *avctx, void *data,
ff_thread_finish_setup(avctx);
/* Use the decompress function on the texture, one block per thread */
- avctx->execute2(avctx, decompress_texture_thread, tframe.f, NULL, slices);
+ avctx->execute2(avctx, decompress_texture_thread, tframe.f, NULL, ctx->slice_count);
/* Frame is ready to be output */
tframe.f->pict_type = AV_PICTURE_TYPE_I;
@@ -227,6 +232,9 @@ static av_cold int hap_init(AVCodecContext *avctx)
ff_texturedsp_init(&ctx->dxtc);
+ ctx->slice_count = av_clip(avctx->thread_count, 1,
+ avctx->coded_height / TEXTURE_BLOCK_H);
+
return 0;
}