[FFmpeg-devel] [PATCH 1/2] avcodec/hap: fix for missing pixels at the bottom of frames

Tom Butterworth bangnoise at gmail.com
Wed Jul 22 22:46:24 CEST 2015


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.
---
 libavcodec/hap.h    |  1 +
 libavcodec/hapdec.c | 17 +++++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/libavcodec/hap.h b/libavcodec/hap.h
index 893b4c5..a46738e 100644
--- a/libavcodec/hap.h
+++ b/libavcodec/hap.h
@@ -77,6 +77,7 @@ typedef struct HapContext {
 
     size_t max_snappy;       /* Maximum compressed size for snappy buffer */
 
+    int slice_count;         /* Number of slices for threaded operations */
     int slice_size;          /* Optimal slice size */
 
     /* Pointer to the selected compress or decompress function */
diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c
index c05d4c0..69a925d 100644
--- a/libavcodec/hapdec.c
+++ b/libavcodec/hapdec.c
@@ -275,7 +275,12 @@ static int decompress_texture_thread(AVCodecContext *avctx, void *arg,
     int start_slice, end_slice;
 
     start_slice = slice * ctx->slice_size;
-    end_slice   = FFMIN(start_slice + ctx->slice_size, avctx->coded_height);
+    /* If the frame height isn't divisible by the number of slices then the
+     * last slice must cover more rows than ctx->slice_size */
+    if (slice == ctx->slice_count - 1)
+        end_slice = avctx->coded_height;
+    else
+        end_slice = FFMIN(start_slice + ctx->slice_size, avctx->coded_height);
 
     start_slice /= TEXTURE_BLOCK_H;
     end_slice   /= TEXTURE_BLOCK_H;
@@ -298,10 +303,6 @@ static int hap_decode(AVCodecContext *avctx, void *data,
     HapContext *ctx = avctx->priv_data;
     ThreadFrame tframe;
     int ret, i;
-    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);
 
@@ -340,7 +341,7 @@ static int hap_decode(AVCodecContext *avctx, void *data,
     }
 
     /* 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;
@@ -391,6 +392,10 @@ static av_cold int hap_init(AVCodecContext *avctx)
         return AVERROR_DECODER_NOT_FOUND;
     }
 
+    ctx->slice_count = av_clip(avctx->thread_count, 1,
+                               avctx->coded_height / TEXTURE_BLOCK_H);
+    ctx->slice_size = avctx->coded_height / ctx->slice_count;
+
     av_log(avctx, AV_LOG_DEBUG, "%s texture\n", texture_name);
 
     return 0;
-- 
2.3.2 (Apple Git-55)



More information about the ffmpeg-devel mailing list