Commit 518b9ee3 authored by Martin Vignali's avatar Martin Vignali

avcodec/hapdec : reorganize code before adding multi-texture decoding

parent ba98f846
...@@ -81,6 +81,8 @@ typedef struct HapContext { ...@@ -81,6 +81,8 @@ typedef struct HapContext {
int slice_count; /* Number of slices for threaded operations */ int slice_count; /* Number of slices for threaded operations */
int texture_count; /* 2 for HAQA, 1 for other version */
/* Pointer to the selected compress or decompress function */ /* Pointer to the selected compress or decompress function */
int (*tex_fun)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block); int (*tex_fun)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
} HapContext; } HapContext;
......
...@@ -266,8 +266,8 @@ static int decompress_chunks_thread(AVCodecContext *avctx, void *arg, ...@@ -266,8 +266,8 @@ static int decompress_chunks_thread(AVCodecContext *avctx, void *arg,
return 0; return 0;
} }
static int decompress_texture_thread(AVCodecContext *avctx, void *arg, static int decompress_texture_thread_internal(AVCodecContext *avctx, void *arg,
int slice, int thread_nb) int slice, int thread_nb, int texture_num)
{ {
HapContext *ctx = avctx->priv_data; HapContext *ctx = avctx->priv_data;
AVFrame *frame = arg; AVFrame *frame = arg;
...@@ -295,34 +295,50 @@ static int decompress_texture_thread(AVCodecContext *avctx, void *arg, ...@@ -295,34 +295,50 @@ static int decompress_texture_thread(AVCodecContext *avctx, void *arg,
uint8_t *p = frame->data[0] + y * frame->linesize[0] * TEXTURE_BLOCK_H; uint8_t *p = frame->data[0] + y * frame->linesize[0] * TEXTURE_BLOCK_H;
int off = y * w_block; int off = y * w_block;
for (x = 0; x < w_block; x++) { for (x = 0; x < w_block; x++) {
if (texture_num == 0) {
ctx->tex_fun(p + x * 16, frame->linesize[0], ctx->tex_fun(p + x * 16, frame->linesize[0],
d + (off + x) * ctx->tex_rat); d + (off + x) * ctx->tex_rat);
} }
} }
}
return 0; return 0;
} }
static int decompress_texture_thread(AVCodecContext *avctx, void *arg,
int slice, int thread_nb)
{
return decompress_texture_thread_internal(avctx, arg, slice, thread_nb, 0);
}
static int hap_decode(AVCodecContext *avctx, void *data, static int hap_decode(AVCodecContext *avctx, void *data,
int *got_frame, AVPacket *avpkt) int *got_frame, AVPacket *avpkt)
{ {
HapContext *ctx = avctx->priv_data; HapContext *ctx = avctx->priv_data;
ThreadFrame tframe; ThreadFrame tframe;
int ret, i; int ret, i, t;
int tex_size; int tex_size;
int start_texture_section = 0;
int tex_rat[2] = {0, 0};
bytestream2_init(&ctx->gbc, avpkt->data, avpkt->size); bytestream2_init(&ctx->gbc, avpkt->data, avpkt->size);
/* Check for section header */ tex_rat[0] = ctx->tex_rat;
ret = hap_parse_frame_header(avctx);
if (ret < 0)
return ret;
/* Get the output frame ready to receive data */ /* Get the output frame ready to receive data */
tframe.f = data; tframe.f = data;
ret = ff_thread_get_buffer(avctx, &tframe, 0); ret = ff_thread_get_buffer(avctx, &tframe, 0);
if (ret < 0) if (ret < 0)
return ret; return ret;
for (t = 0; t < ctx->texture_count; t++) {
bytestream2_seek(&ctx->gbc, start_texture_section, SEEK_SET);
/* Check for section header */
ret = hap_parse_frame_header(avctx);
if (ret < 0)
return ret;
if (avctx->codec->update_thread_context) if (avctx->codec->update_thread_context)
ff_thread_finish_setup(avctx); ff_thread_finish_setup(avctx);
...@@ -357,7 +373,10 @@ static int hap_decode(AVCodecContext *avctx, void *data, ...@@ -357,7 +373,10 @@ static int hap_decode(AVCodecContext *avctx, void *data,
} }
/* Use the decompress function on the texture, one block per thread */ /* Use the decompress function on the texture, one block per thread */
if (t == 0){
avctx->execute2(avctx, decompress_texture_thread, tframe.f, NULL, ctx->slice_count); avctx->execute2(avctx, decompress_texture_thread, tframe.f, NULL, ctx->slice_count);
}
}
/* Frame is ready to be output */ /* Frame is ready to be output */
tframe.f->pict_type = AV_PICTURE_TYPE_I; tframe.f->pict_type = AV_PICTURE_TYPE_I;
...@@ -385,6 +404,8 @@ static av_cold int hap_init(AVCodecContext *avctx) ...@@ -385,6 +404,8 @@ static av_cold int hap_init(AVCodecContext *avctx)
ff_texturedsp_init(&ctx->dxtc); ff_texturedsp_init(&ctx->dxtc);
ctx->texture_count = 1;
switch (avctx->codec_tag) { switch (avctx->codec_tag) {
case MKTAG('H','a','p','1'): case MKTAG('H','a','p','1'):
texture_name = "DXT1"; texture_name = "DXT1";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment