> From e750ddd8b1b79cfad04f2cdd58b5ba438390adf1 Mon Sep 17 00:00:00 2001
> From: fo <[email protected]>
You should fix your Git configuration so that this contains your full name.
Also, which one is your preferred email address?
> Date: Mon, 6 Apr 2015 15:47:14 +0200
> Subject: [PATCH] libavcodec/hqx: made decoding multi threaded!
Just "hqx:" is enough as subject tag
> --- a/libavcodec/hqx.c
> +++ b/libavcodec/hqx.c
> @@ -39,7 +39,7 @@ enum HQXFormat {
>
> #define HQX_HEADER_SIZE 59
>
> -typedef int (*mb_decode_func)(HQXContext *ctx, AVFrame *pic,
> +typedef int (*mb_decode_func)(HQXContext *ctx, slice_data_t * slice_data,
> AVFrame *pic,
*slice_data
> @@ -260,7 +260,7 @@ static int decode_block(GetBitContext *gb, VLC *vlc,
>
> -static int hqx_decode_422(HQXContext *ctx, AVFrame *pic,
> +static int hqx_decode_422(HQXContext *ctx, slice_data_t * slice_data,
> AVFrame *pic,
same
> @@ -280,20 +280,20 @@ static int hqx_decode_422(HQXContext *ctx, AVFrame *pic,
>
> - put_blocks(pic, 0, x, y, flag, ctx->block[0], ctx->block[2],
> hqx_quant_luma);
> - put_blocks(pic, 0, x + 8, y, flag, ctx->block[1], ctx->block[3],
> hqx_quant_luma);
> - put_blocks(pic, 2, x >> 1, y, flag, ctx->block[4], ctx->block[5],
> hqx_quant_chroma);
> - put_blocks(pic, 1, x >> 1, y, flag, ctx->block[6], ctx->block[7],
> hqx_quant_chroma);
> + put_blocks(pic, 0, x, y, flag, slice_data->block[0],
> slice_data->block[2], hqx_quant_luma);
> + put_blocks(pic, 0, x + 8, y, flag, slice_data->block[1],
> slice_data->block[3], hqx_quant_luma);
> + put_blocks(pic, 2, x >> 1, y, flag, slice_data->block[4],
> slice_data->block[5], hqx_quant_chroma);
> + put_blocks(pic, 1, x >> 1, y, flag, slice_data->block[6],
> slice_data->block[7], hqx_quant_chroma);
Tabs are not allowed. Also, you're undoing the pretty vertical alignment.
> -static int hqx_decode_422a(HQXContext *ctx, AVFrame *pic,
> +static int hqx_decode_422a(HQXContext *ctx, slice_data_t * slice_data,
> AVFrame *pic,
*slice_data
> @@ -305,9 +305,9 @@ static int hqx_decode_422a(HQXContext *ctx, AVFrame *pic,
> for (i = 0; i < 12; i++)
> - memset(ctx->block[i], 0, sizeof(**ctx->block) * 64);
> + memset(slice_data->block[i], 0, sizeof(**slice_data->block) *
> 64);
> for (i = 0; i < 12; i++)
> - ctx->block[i][0] = -0x800;
> + slice_data->block[i][0] = -0x800;
tabs
> @@ -325,24 +325,24 @@ static int hqx_decode_422a(HQXContext *ctx, AVFrame
> *pic,
> if (cbp & (1 << i)) {
> int vlc_index = ctx->dcb - 9;
> ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
> - ctx->dcb, ctx->block[i], &last_dc);
> + ctx->dcb, slice_data->block[i],
> &last_dc);
same
> -static int hqx_decode_444(HQXContext *ctx, AVFrame *pic,
> +static int hqx_decode_444(HQXContext *ctx, slice_data_t * slice_data,
> AVFrame *pic,
*slice_data
> @@ -362,22 +362,22 @@ static int hqx_decode_444(HQXContext *ctx, AVFrame *pic,
> if (i == 0 || i == 4 || i == 8)
> last_dc = 0;
> ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
> - ctx->dcb, ctx->block[i], &last_dc);
> + ctx->dcb, slice_data->block[i], &last_dc);
tabs
> -static int hqx_decode_444a(HQXContext *ctx, AVFrame *pic,
> +static int hqx_decode_444a(HQXContext *ctx, slice_data_t * slice_data,
> AVFrame *pic,
*slice_data
> @@ -389,9 +389,9 @@ static int hqx_decode_444a(HQXContext *ctx, AVFrame *pic,
>
> for (i = 0; i < 16; i++)
> - memset(ctx->block[i], 0, sizeof(**ctx->block) * 64);
> + memset(slice_data->block[i], 0, sizeof(**slice_data->block) *
> 64);
> for (i = 0; i < 16; i++)
> - ctx->block[i][0] = -0x800;
> + slice_data->block[i][0] = -0x800;
tabs
> @@ -406,21 +406,21 @@ static int hqx_decode_444a(HQXContext *ctx, AVFrame
> *pic,
> if (cbp & (1 << i)) {
> int vlc_index = ctx->dcb - 9;
> ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,
> - ctx->dcb, ctx->block[i], &last_dc);
> + ctx->dcb, slice_data->block[i],
> &last_dc);
tabs
> @@ -476,13 +476,48 @@ static int decode_slice(HQXContext *ctx, AVFrame *pic,
> GetBitContext *gb,
>
> +typedef struct
> +{
> + AVFrame *pic;
> + uint8_t *src;
> + GetBitContext gb[17];
> + unsigned data_size;
> + mb_decode_func decode_func;
> + uint32_t slice_off[17];
> +} data_t;
The _t namespace is reserved for POSIX, please don't invade it.
Also, please don't anonymously typedef structs.
> +static int decode_slice_thread(AVCodecContext *avctx, void *arg, int slice,
> int threadnr)
> +{
> + DECLARE_ALIGNED(16, int16_t, block)[16][64];
> +
> + data_t * data = (data_t*) arg;
> + uint32_t * slice_off = data->slice_off;
> + unsigned data_size = data->data_size;
> + if (slice_off[slice] < HQX_HEADER_SIZE ||
> + slice_off[slice] >= slice_off[slice + 1] ||
> + slice_off[slice + 1] > data_size) {
> + av_log(avctx, AV_LOG_ERROR, "Invalid slice size.\n");
> + return AVERROR_INVALIDDATA;
> + }
> + int ret = init_get_bits8(&data->gb[slice], data->src + slice_off[slice],
> + slice_off[slice + 1] - slice_off[slice]);
> + if (ret < 0)
> + return ret;
> + HQXContext *ctx = avctx->priv_data;
> + ret = decode_slice(ctx, data->pic, &data->gb[slice], slice,
> data->decode_func);
> + if (ret < 0) {
> + av_log(avctx, AV_LOG_ERROR, "Error decoding slice %d.\n",
> slice);
> + }
> + return ret;
> +}
more tabs
> @@ -492,11 +527,10 @@ static int hqx_decode_frame(AVCodecContext *avctx, void
> *data,
> int slice;
> - uint32_t slice_off[17];
> - mb_decode_func decode_func = 0;
> + data_t arg_data;
> + arg_data.decode_func = 0;
tabs
> @@ -520,9 +554,11 @@ static int hqx_decode_frame(AVCodecContext *avctx, void
> *data,
>
> data_start = src - avpkt->data;
> - data_size = avpkt->size - data_start;
> + arg_data.src = src;
> + arg_data.pic = data;
> + arg_data.data_size = avpkt->size - data_start;
>
> - if (data_size < HQX_HEADER_SIZE) {
> + if (arg_data.data_size < HQX_HEADER_SIZE) {
same
> @@ -559,22 +595,22 @@ static int hqx_decode_frame(AVCodecContext *avctx, void
> *data,
> case HQX_444:
> avctx->pix_fmt = AV_PIX_FMT_YUV444P16;
> - decode_func = hqx_decode_444;
> + arg_data.decode_func = hqx_decode_444;
> break;
> case HQX_422A:
> avctx->pix_fmt = AV_PIX_FMT_YUVA422P16;
> - decode_func = hqx_decode_422a;
> + arg_data.decode_func = hqx_decode_422a;
> break;
> case HQX_444A:
> avctx->pix_fmt = AV_PIX_FMT_YUVA444P16;
> - decode_func = hqx_decode_444a;
> + arg_data.decode_func = hqx_decode_444a;
> break;
> }
> - if (!decode_func) {
> + if (!arg_data.decode_func) {
same
> @@ -583,6 +619,10 @@ static int hqx_decode_frame(AVCodecContext *avctx, void
> *data,
> if (ret < 0)
> return ret;
>
> +
> + avctx->execute2(avctx, decode_slice_thread, &arg_data, NULL, 16);
same
> +#if 0
> for (slice = 0; slice < 16; slice++) {
> if (slice_off[slice] < HQX_HEADER_SIZE ||
> slice_off[slice] >= slice_off[slice + 1] ||
Don't leave behind commented-out cruft. This code either has to stay
or be deleted.
> @@ -639,5 +679,5 @@ AVCodec ff_hqx_decoder = {
> .init = hqx_decode_init,
> .decode = hqx_decode_frame,
> .close = hqx_decode_close,
> - .capabilities = CODEC_CAP_DR1,
> + .capabilities = CODEC_CAP_DR1 | CODEC_CAP_SLICE_THREADS,
tabs and please keep the vertical alignment.
Diego
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel