summaryrefslogtreecommitdiff
path: root/libavcodec/hapdec.c
diff options
context:
space:
mode:
authorMartin Vignali <martin.vignali@gmail.com>2017-11-21 11:55:37 +0100
committerMartin Vignali <martin.vignali@gmail.com>2017-11-21 12:05:06 +0100
commit518b9ee3d16fa0a04c2c11bc86a64fb46fc25702 (patch)
tree625212c4ec0f2049cc8e93de7307931304d28802 /libavcodec/hapdec.c
parentba98f8463fd1345fab173fa405ac98aefd92ed06 (diff)
avcodec/hapdec : reorganize code before adding multi-texture decoding
Diffstat (limited to 'libavcodec/hapdec.c')
-rw-r--r--libavcodec/hapdec.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c
index fc9dff10f1..e5b448112a 100644
--- a/libavcodec/hapdec.c
+++ b/libavcodec/hapdec.c
@@ -266,8 +266,8 @@ static int decompress_chunks_thread(AVCodecContext *avctx, void *arg,
return 0;
}
-static int decompress_texture_thread(AVCodecContext *avctx, void *arg,
- int slice, int thread_nb)
+static int decompress_texture_thread_internal(AVCodecContext *avctx, void *arg,
+ int slice, int thread_nb, int texture_num)
{
HapContext *ctx = avctx->priv_data;
AVFrame *frame = 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;
int off = y * w_block;
for (x = 0; x < w_block; x++) {
- ctx->tex_fun(p + x * 16, frame->linesize[0],
- d + (off + x) * ctx->tex_rat);
+ if (texture_num == 0) {
+ ctx->tex_fun(p + x * 16, frame->linesize[0],
+ d + (off + x) * ctx->tex_rat);
+ }
}
}
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,
int *got_frame, AVPacket *avpkt)
{
HapContext *ctx = avctx->priv_data;
ThreadFrame tframe;
- int ret, i;
+ int ret, i, t;
int tex_size;
+ int start_texture_section = 0;
+ int tex_rat[2] = {0, 0};
bytestream2_init(&ctx->gbc, avpkt->data, avpkt->size);
- /* Check for section header */
- ret = hap_parse_frame_header(avctx);
- if (ret < 0)
- return ret;
+ tex_rat[0] = ctx->tex_rat;
/* Get the output frame ready to receive data */
tframe.f = data;
ret = ff_thread_get_buffer(avctx, &tframe, 0);
if (ret < 0)
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)
ff_thread_finish_setup(avctx);
@@ -357,7 +373,10 @@ static int hap_decode(AVCodecContext *avctx, void *data,
}
/* 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);
+ }
+ }
/* Frame is ready to be output */
tframe.f->pict_type = AV_PICTURE_TYPE_I;
@@ -385,6 +404,8 @@ static av_cold int hap_init(AVCodecContext *avctx)
ff_texturedsp_init(&ctx->dxtc);
+ ctx->texture_count = 1;
+
switch (avctx->codec_tag) {
case MKTAG('H','a','p','1'):
texture_name = "DXT1";