aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/hqx.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2015-04-20 04:57:06 +0200
committerMichael Niedermayer <michaelni@gmx.at>2015-04-20 04:57:06 +0200
commit55b866f618582350bcc5489d4e96afd40c9c8c44 (patch)
tree9e6705e10fb3104b82e65f421a438f7eec355f9a /libavcodec/hqx.c
parentd8b4e9adbb93211b511e3864d8230789186ef4ed (diff)
parent453642f8afe9f979fcc813a246b1ec656ec36a93 (diff)
downloadffmpeg-55b866f618582350bcc5489d4e96afd40c9c8c44.tar.gz
Merge commit '453642f8afe9f979fcc813a246b1ec656ec36a93'
* commit '453642f8afe9f979fcc813a246b1ec656ec36a93': hqx: Store shareable data in main decoder context Conflicts: libavcodec/hqx.c libavcodec/hqx.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/hqx.c')
-rw-r--r--libavcodec/hqx.c121
1 files changed, 52 insertions, 69 deletions
diff --git a/libavcodec/hqx.c b/libavcodec/hqx.c
index 8c568f2439..96c246b36b 100644
--- a/libavcodec/hqx.c
+++ b/libavcodec/hqx.c
@@ -40,9 +40,6 @@ enum HQXFormat {
#define HQX_HEADER_SIZE 59
-typedef int (*mb_decode_func)(HQXContext *ctx, HQXSliceData * slice_data, AVFrame *pic,
- GetBitContext *gb, int x, int y);
-
/* macroblock selects a group of 4 possible quants and
* a block can use any of those four quantisers
* one column is powers of 2, the other one is powers of 2 * 3,
@@ -82,14 +79,14 @@ static const uint8_t hqx_quant_chroma[64] = {
44, 91, 96, 197, 203, 209, 232, 246,
};
-static inline void put_blocks(HQXContext *ctx, AVFrame *pic, int plane,
+static inline void put_blocks(HQXContext *ctx, int plane,
int x, int y, int ilace,
int16_t *block0, int16_t *block1,
const uint8_t *quant)
{
int fields = ilace ? 2 : 1;
- int lsize = pic->linesize[plane];
- uint8_t *p = pic->data[plane] + x * 2;
+ int lsize = ctx->pic->linesize[plane];
+ uint8_t *p = ctx->pic->data[plane] + x * 2;
ctx->hqxdsp.idct_put((uint16_t *)(p + y * lsize),
lsize * fields, block0, quant);
@@ -154,7 +151,7 @@ static int decode_block(GetBitContext *gb, VLC *vlc,
return 0;
}
-static int hqx_decode_422(HQXContext *ctx, HQXSliceData * slice_data, AVFrame *pic,
+static int hqx_decode_422(HQXContext *ctx, HQXSliceData * slice_data,
GetBitContext *gb, int x, int y)
{
const int *quants;
@@ -179,15 +176,15 @@ static int hqx_decode_422(HQXContext *ctx, HQXSliceData * slice_data, AVFrame *p
return ret;
}
- put_blocks(ctx, pic, 0, x , y, flag, slice_data->block[0], slice_data->block[2], hqx_quant_luma);
- put_blocks(ctx, pic, 0, x + 8 , y, flag, slice_data->block[1], slice_data->block[3], hqx_quant_luma);
- put_blocks(ctx, pic, 2, x >> 1, y, flag, slice_data->block[4], slice_data->block[5], hqx_quant_chroma);
- put_blocks(ctx, pic, 1, x >> 1, y, flag, slice_data->block[6], slice_data->block[7], hqx_quant_chroma);
+ put_blocks(ctx, 0, x , y, flag, slice_data->block[0], slice_data->block[2], hqx_quant_luma);
+ put_blocks(ctx, 0, x + 8 , y, flag, slice_data->block[1], slice_data->block[3], hqx_quant_luma);
+ put_blocks(ctx, 2, x >> 1, y, flag, slice_data->block[4], slice_data->block[5], hqx_quant_chroma);
+ put_blocks(ctx, 1, x >> 1, y, flag, slice_data->block[6], slice_data->block[7], hqx_quant_chroma);
return 0;
}
-static int hqx_decode_422a(HQXContext *ctx, HQXSliceData * slice_data, AVFrame *pic,
+static int hqx_decode_422a(HQXContext *ctx, HQXSliceData * slice_data,
GetBitContext *gb, int x, int y)
{
const int *quants;
@@ -226,17 +223,17 @@ static int hqx_decode_422a(HQXContext *ctx, HQXSliceData * slice_data, AVFrame *
}
}
- put_blocks(ctx, pic, 3, x, y, flag, slice_data->block[ 0], slice_data->block[ 2], hqx_quant_luma);
- put_blocks(ctx, pic, 3, x + 8, y, flag, slice_data->block[ 1], slice_data->block[ 3], hqx_quant_luma);
- put_blocks(ctx, pic, 0, x, y, flag, slice_data->block[ 4], slice_data->block[ 6], hqx_quant_luma);
- put_blocks(ctx, pic, 0, x + 8, y, flag, slice_data->block[ 5], slice_data->block[ 7], hqx_quant_luma);
- put_blocks(ctx, pic, 2, x >> 1, y, flag, slice_data->block[ 8], slice_data->block[ 9], hqx_quant_chroma);
- put_blocks(ctx, pic, 1, x >> 1, y, flag, slice_data->block[10], slice_data->block[11], hqx_quant_chroma);
+ put_blocks(ctx, 3, x, y, flag, slice_data->block[ 0], slice_data->block[ 2], hqx_quant_luma);
+ put_blocks(ctx, 3, x + 8, y, flag, slice_data->block[ 1], slice_data->block[ 3], hqx_quant_luma);
+ put_blocks(ctx, 0, x, y, flag, slice_data->block[ 4], slice_data->block[ 6], hqx_quant_luma);
+ put_blocks(ctx, 0, x + 8, y, flag, slice_data->block[ 5], slice_data->block[ 7], hqx_quant_luma);
+ put_blocks(ctx, 2, x >> 1, y, flag, slice_data->block[ 8], slice_data->block[ 9], hqx_quant_chroma);
+ put_blocks(ctx, 1, x >> 1, y, flag, slice_data->block[10], slice_data->block[11], hqx_quant_chroma);
return 0;
}
-static int hqx_decode_444(HQXContext *ctx, HQXSliceData * slice_data, AVFrame *pic,
+static int hqx_decode_444(HQXContext *ctx, HQXSliceData * slice_data,
GetBitContext *gb, int x, int y)
{
const int *quants;
@@ -261,17 +258,18 @@ static int hqx_decode_444(HQXContext *ctx, HQXSliceData * slice_data, AVFrame *p
return ret;
}
- put_blocks(ctx, pic, 0, x, y, flag, slice_data->block[0], slice_data->block[ 2], hqx_quant_luma);
- put_blocks(ctx, pic, 0, x + 8, y, flag, slice_data->block[1], slice_data->block[ 3], hqx_quant_luma);
- put_blocks(ctx, pic, 2, x, y, flag, slice_data->block[4], slice_data->block[ 6], hqx_quant_chroma);
- put_blocks(ctx, pic, 2, x + 8, y, flag, slice_data->block[5], slice_data->block[ 7], hqx_quant_chroma);
- put_blocks(ctx, pic, 1, x, y, flag, slice_data->block[8], slice_data->block[10], hqx_quant_chroma);
- put_blocks(ctx, pic, 1, x + 8, y, flag, slice_data->block[9], slice_data->block[11], hqx_quant_chroma);
+ put_blocks(ctx, 0, x, y, flag, slice_data->block[0], slice_data->block[ 2], hqx_quant_luma);
+ put_blocks(ctx, 0, x + 8, y, flag, slice_data->block[1], slice_data->block[ 3], hqx_quant_luma);
+ put_blocks(ctx, 2, x, y, flag, slice_data->block[4], slice_data->block[ 6], hqx_quant_chroma);
+ put_blocks(ctx, 2, x + 8, y, flag, slice_data->block[5], slice_data->block[ 7], hqx_quant_chroma);
+ put_blocks(ctx, 1, x, y, flag, slice_data->block[8], slice_data->block[10], hqx_quant_chroma);
+ put_blocks(ctx, 1, x + 8, y, flag, slice_data->block[9], slice_data->block[11], hqx_quant_chroma);
return 0;
}
-static int hqx_decode_444a(HQXContext *ctx, HQXSliceData * slice_data, AVFrame *pic,
+
+static int hqx_decode_444a(HQXContext *ctx, HQXSliceData * slice_data,
GetBitContext *gb, int x, int y)
{
const int *quants;
@@ -307,14 +305,14 @@ static int hqx_decode_444a(HQXContext *ctx, HQXSliceData * slice_data, AVFrame *
}
}
- put_blocks(ctx, pic, 3, x, y, flag, slice_data->block[ 0], slice_data->block[ 2], hqx_quant_luma);
- put_blocks(ctx, pic, 3, x + 8, y, flag, slice_data->block[ 1], slice_data->block[ 3], hqx_quant_luma);
- put_blocks(ctx, pic, 0, x, y, flag, slice_data->block[ 4], slice_data->block[ 6], hqx_quant_luma);
- put_blocks(ctx, pic, 0, x + 8, y, flag, slice_data->block[ 5], slice_data->block[ 7], hqx_quant_luma);
- put_blocks(ctx, pic, 2, x, y, flag, slice_data->block[ 8], slice_data->block[10], hqx_quant_chroma);
- put_blocks(ctx, pic, 2, x + 8, y, flag, slice_data->block[ 9], slice_data->block[11], hqx_quant_chroma);
- put_blocks(ctx, pic, 1, x, y, flag, slice_data->block[12], slice_data->block[14], hqx_quant_chroma);
- put_blocks(ctx, pic, 1, x + 8, y, flag, slice_data->block[13], slice_data->block[15], hqx_quant_chroma);
+ put_blocks(ctx, 3, x, y, flag, slice_data->block[ 0], slice_data->block[ 2], hqx_quant_luma);
+ put_blocks(ctx, 3, x + 8, y, flag, slice_data->block[ 1], slice_data->block[ 3], hqx_quant_luma);
+ put_blocks(ctx, 0, x, y, flag, slice_data->block[ 4], slice_data->block[ 6], hqx_quant_luma);
+ put_blocks(ctx, 0, x + 8, y, flag, slice_data->block[ 5], slice_data->block[ 7], hqx_quant_luma);
+ put_blocks(ctx, 2, x, y, flag, slice_data->block[ 8], slice_data->block[10], hqx_quant_chroma);
+ put_blocks(ctx, 2, x + 8, y, flag, slice_data->block[ 9], slice_data->block[11], hqx_quant_chroma);
+ put_blocks(ctx, 1, x, y, flag, slice_data->block[12], slice_data->block[14], hqx_quant_chroma);
+ put_blocks(ctx, 1, x + 8, y, flag, slice_data->block[13], slice_data->block[15], hqx_quant_chroma);
return 0;
}
@@ -323,8 +321,7 @@ static const int shuffle_16[16] = {
0, 5, 11, 14, 2, 7, 9, 13, 1, 4, 10, 15, 3, 6, 8, 12
};
-static int decode_slice(HQXContext *ctx, AVFrame *pic, GetBitContext *gb,
- int slice_no, mb_decode_func decode_func)
+static int decode_slice(HQXContext *ctx, GetBitContext *gb, int slice_no)
{
int mb_w = (ctx->width + 15) >> 4;
int mb_h = (ctx->height + 15) >> 4;
@@ -370,28 +367,18 @@ static int decode_slice(HQXContext *ctx, AVFrame *pic, GetBitContext *gb,
mb_x += pos % grp_w;
mb_y = loc_row + (pos / grp_w);
}
- decode_func(ctx, &ctx->slice[slice_no], pic, gb, mb_x * 16, mb_y * 16);
+ ctx->decode_func(ctx, &ctx->slice[slice_no], gb, mb_x * 16, mb_y * 16);
}
}
return 0;
}
-typedef struct {
- AVFrame *pic;
- uint8_t *src;
- GetBitContext gb[17];
- unsigned data_size;
- mb_decode_func decode_func;
- uint32_t slice_off[17];
-} Data;
-
static int decode_slice_thread(AVCodecContext *avctx, void *arg, int slice, int threadnr)
{
- Data * data = (Data*) arg;
- uint32_t * slice_off = data->slice_off;
- unsigned data_size = data->data_size;
HQXContext *ctx = avctx->priv_data;
+ uint32_t * slice_off = ctx->slice_off;
+ unsigned data_size = ctx->data_size;
int ret;
if (slice_off[slice] < HQX_HEADER_SIZE ||
@@ -401,11 +388,11 @@ static int decode_slice_thread(AVCodecContext *avctx, void *arg, int slice, int
return AVERROR_INVALIDDATA;
}
- ret = init_get_bits8(&data->gb[slice], data->src + slice_off[slice], slice_off[slice + 1] - slice_off[slice]);
+ ret = init_get_bits8(&ctx->slice[slice].gb, ctx->src + slice_off[slice], slice_off[slice + 1] - slice_off[slice]);
if (ret < 0)
return ret;
- ret = decode_slice(ctx, data->pic, &data->gb[slice], slice, data->decode_func);
+ ret = decode_slice(ctx, &ctx->slice[slice].gb, slice);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error decoding slice %d.\n", slice);
}
@@ -416,13 +403,10 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data,
int *got_picture_ptr, AVPacket *avpkt)
{
HQXContext *ctx = avctx->priv_data;
- AVFrame *pic = data;
uint8_t *src = avpkt->data;
uint32_t info_tag, info_offset;
int data_start;
int i, ret;
- Data arg_data;
- arg_data.decode_func = 0;
if (avpkt->size < 8)
return AVERROR_INVALIDDATA;
@@ -445,12 +429,12 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data,
av_log(avctx, AV_LOG_DEBUG, "Skipping INFO chunk.\n");
}
- data_start = src - avpkt->data;
- arg_data.src = src;
- arg_data.pic = data;
- arg_data.data_size = avpkt->size - data_start;
+ data_start = src - avpkt->data;
+ ctx->data_size = avpkt->size - data_start;
+ ctx->src = src;
+ ctx->pic = data;
- if (arg_data.data_size < HQX_HEADER_SIZE) {
+ if (ctx->data_size < HQX_HEADER_SIZE) {
av_log(avctx, AV_LOG_ERROR, "Frame too small.\n");
return AVERROR_INVALIDDATA;
}
@@ -465,7 +449,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++)
- arg_data.slice_off[i] = AV_RB24(src + 8 + i * 3);
+ ctx->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);
@@ -487,34 +471,33 @@ static int hqx_decode_frame(AVCodecContext *avctx, void *data,
switch (ctx->format) {
case HQX_422:
avctx->pix_fmt = AV_PIX_FMT_YUV422P16;
- arg_data.decode_func = hqx_decode_422;
+ ctx->decode_func = hqx_decode_422;
break;
case HQX_444:
avctx->pix_fmt = AV_PIX_FMT_YUV444P16;
- arg_data.decode_func = hqx_decode_444;
+ ctx->decode_func = hqx_decode_444;
break;
case HQX_422A:
avctx->pix_fmt = AV_PIX_FMT_YUVA422P16;
- arg_data.decode_func = hqx_decode_422a;
+ ctx->decode_func = hqx_decode_422a;
break;
case HQX_444A:
avctx->pix_fmt = AV_PIX_FMT_YUVA444P16;
- arg_data.decode_func = hqx_decode_444a;
+ ctx->decode_func = hqx_decode_444a;
break;
default:
av_log(avctx, AV_LOG_ERROR, "Invalid format: %d.\n", ctx->format);
return AVERROR_INVALIDDATA;
}
- ret = ff_get_buffer(avctx, pic, 0);
+ ret = ff_get_buffer(avctx, ctx->pic, 0);
if (ret < 0)
return ret;
+ avctx->execute2(avctx, decode_slice_thread, NULL, NULL, 16);
- avctx->execute2(avctx, decode_slice_thread, &arg_data, NULL, 16);
-
- pic->key_frame = 1;
- pic->pict_type = AV_PICTURE_TYPE_I;
+ ctx->pic->key_frame = 1;
+ ctx->pic->pict_type = AV_PICTURE_TYPE_I;
*got_picture_ptr = 1;