From 6c5b98d40b8eeec14174fb9602acbf4b0c924981 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 21 Oct 2016 13:29:46 +0200 Subject: [PATCH] avcodec/dnxhdenc: Move allocation out of radix_sort() Its slow, its not checked, FPU state is not clean either currently there Signed-off-by: Michael Niedermayer --- libavcodec/dnxhdenc.c | 12 +++++++----- libavcodec/dnxhdenc.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c index 88edd6b20f..60bea83c1f 100644 --- a/libavcodec/dnxhdenc.c +++ b/libavcodec/dnxhdenc.c @@ -288,9 +288,12 @@ static av_cold int dnxhd_init_rc(DNXHDEncContext *ctx) { FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->mb_rc, (ctx->m.avctx->qmax + 1), ctx->m.mb_num * sizeof(RCEntry), fail); - if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD) + if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD) { FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->mb_cmp, ctx->m.mb_num, sizeof(RCCMPEntry), fail); + FF_ALLOCZ_ARRAY_OR_GOTO(ctx->m.avctx, ctx->mb_cmp_tmp, + ctx->m.mb_num, sizeof(RCCMPEntry), fail); + } ctx->frame_bits = (ctx->coding_unit_size - ctx->data_offset - 4 - ctx->min_padding) * 8; ctx->qscale = 1; @@ -1072,10 +1075,9 @@ static void radix_sort_pass(RCCMPEntry *dst, const RCCMPEntry *data, } } -static void radix_sort(RCCMPEntry *data, int size) +static void radix_sort(RCCMPEntry *data, RCCMPEntry *tmp, int size) { int buckets[RADIX_PASSES][NBUCKETS]; - RCCMPEntry *tmp = av_malloc_array(size, sizeof(*tmp)); radix_count(data, size, buckets); radix_sort_pass(tmp, data, size, buckets[0], 0); radix_sort_pass(data, tmp, size, buckets[1], 1); @@ -1083,7 +1085,6 @@ static void radix_sort(RCCMPEntry *data, int size) radix_sort_pass(tmp, data, size, buckets[2], 2); radix_sort_pass(data, tmp, size, buckets[3], 3); } - av_free(tmp); } static int dnxhd_encode_fast(AVCodecContext *avctx, DNXHDEncContext *ctx) @@ -1117,7 +1118,7 @@ static int dnxhd_encode_fast(AVCodecContext *avctx, DNXHDEncContext *ctx) if (RC_VARIANCE) avctx->execute2(avctx, dnxhd_mb_var_thread, NULL, NULL, ctx->m.mb_height); - radix_sort(ctx->mb_cmp, ctx->m.mb_num); + radix_sort(ctx->mb_cmp, ctx->mb_cmp_tmp, ctx->m.mb_num); for (x = 0; x < ctx->m.mb_num && max_bits > ctx->frame_bits; x++) { int mb = ctx->mb_cmp[x].mb; int rc = (ctx->qscale * ctx->m.mb_num ) + mb; @@ -1234,6 +1235,7 @@ static av_cold int dnxhd_encode_end(AVCodecContext *avctx) av_freep(&ctx->mb_qscale); av_freep(&ctx->mb_rc); av_freep(&ctx->mb_cmp); + av_freep(&ctx->mb_cmp_tmp); av_freep(&ctx->slice_size); av_freep(&ctx->slice_offs); diff --git a/libavcodec/dnxhdenc.h b/libavcodec/dnxhdenc.h index 96a79aa424..91ef6d0602 100644 --- a/libavcodec/dnxhdenc.h +++ b/libavcodec/dnxhdenc.h @@ -96,6 +96,7 @@ typedef struct DNXHDEncContext { uint8_t *mb_qscale; RCCMPEntry *mb_cmp; + RCCMPEntry *mb_cmp_tmp; RCEntry *mb_rc; void (*get_pixels_8x4_sym)(int16_t * /* align 16 */,