[FFmpeg-devel] HQX codec path: faster decode with multi threaded decoding of slices; fixed clipping bug
Michael Niedermayer
michaelni at gmx.at
Wed Apr 8 15:09:09 CEST 2015
On Wed, Apr 08, 2015 at 09:26:05AM +0200, Ferdinand Oeinck wrote:
[...]
> - 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 forbidden in ffmpeg git
[...]
> +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]);
please dont mix declarations and statements
> + 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;
> +}
> +
> static int hqx_decode_frame(AVCodecContext *avctx, void *data,
> int *got_picture_ptr, AVPacket *avpkt)
> {
> @@ -492,11 +527,10 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data,
> uint32_t info_tag, info_offset;
> int data_start;
> unsigned data_size;
> - GetBitContext gb;
> int i, ret;
> int slice;
> - uint32_t slice_off[17];
> - mb_decode_func decode_func = 0;
> + data_t arg_data;
> + arg_data.decode_func = 0;
some of the variables become unused, dont leave unused variables
>
> if (avpkt->size < 8)
> return AVERROR_INVALIDDATA;
> @@ -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) {
> av_log(avctx, AV_LOG_ERROR, "Frame too small.\n");
> return AVERROR_INVALIDDATA;
> }
> @@ -537,7 +573,7 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data,
> ctx->width = AV_RB16(src + 4);
> ctx->height = AV_RB16(src + 6);
> for (i = 0; i < 17; i++)
> - slice_off[i] = AV_RB24(src + 8 + i * 3);
> + arg_data.slice_off[i] = AV_RB24(src + 8 + i * 3);
>
> if (ctx->dcb == 8) {
> av_log(avctx, AV_LOG_ERROR, "Invalid DC precision %d.\n", ctx->dcb);
> @@ -559,22 +595,22 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data,
> switch (ctx->format) {
> case HQX_422:
> avctx->pix_fmt = AV_PIX_FMT_YUV422P16;
> - decode_func = hqx_decode_422;
> + arg_data.decode_func = hqx_decode_422;
> break;
> 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) {
> av_log(avctx, AV_LOG_ERROR, "Invalid format: %d.\n", ctx->format);
> return AVERROR_INVALIDDATA;
> }
> @@ -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);
> +
> +#if 0
> for (slice = 0; slice < 16; slice++) {
> if (slice_off[slice] < HQX_HEADER_SIZE ||
> slice_off[slice] >= slice_off[slice + 1] ||
> @@ -599,7 +639,7 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data,
> av_log(avctx, AV_LOG_ERROR, "Error decoding slice %d.\n", slice);
> }
> }
> -
> +#endif
please remove code that is not usefull anymore dont just comment it
out
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
In fact, the RIAA has been known to suggest that students drop out
of college or go to community college in order to be able to afford
settlements. -- The RIAA
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150408/81054903/attachment.asc>
More information about the ffmpeg-devel
mailing list