../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
192 / 239
80.3%
Branches:
82 / 127
64.6%
Functions:
7 / 7
100.0%

libavcodec/hapdec.c
Line Branch Exec Source
1 /*
2 * Vidvox Hap decoder
3 * Copyright (C) 2015 Vittorio Giovara <vittorio.giovara@gmail.com>
4 * Copyright (C) 2015 Tom Butterworth <bangnoise@gmail.com>
5 *
6 * HapQA and HAPAlphaOnly added by Jokyo Images
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 /**
26 * @file
27 * Hap decoder
28 *
29 * Fourcc: Hap1, Hap5, HapY, HapA, HapM
30 *
31 * https://github.com/Vidvox/hap/blob/master/documentation/HapVideoDRAFT.md
32 */
33
34 #include <stdint.h>
35
36 #include "libavutil/imgutils.h"
37 #include "libavutil/mem.h"
38
39 #include "avcodec.h"
40 #include "bytestream.h"
41 #include "codec_internal.h"
42 #include "hap.h"
43 #include "snappy.h"
44 #include "texturedsp.h"
45 #include "thread.h"
46
47 6 static int hap_parse_decode_instructions(HapContext *ctx, int size)
48 {
49 6 GetByteContext *gbc = &ctx->gbc;
50 int section_size;
51 enum HapSectionType section_type;
52 6 int is_first_table = 1, had_offsets = 0, had_compressors = 0, had_sizes = 0;
53 int i, ret;
54
55
2/2
✓ Branch 35 → 3 taken 12 times.
✓ Branch 35 → 36 taken 6 times.
18 while (size > 0) {
56 12 int stream_remaining = bytestream2_get_bytes_left(gbc);
57 12 ret = ff_hap_parse_section_header(gbc, &section_size, &section_type);
58
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 12 times.
12 if (ret != 0)
59 ✗ return ret;
60
61 12 size -= stream_remaining - bytestream2_get_bytes_left(gbc);
62
63
2/4
✓ Branch 8 → 9 taken 6 times.
✓ Branch 8 → 17 taken 6 times.
✗ Branch 8 → 25 not taken.
✗ Branch 8 → 33 not taken.
12 switch (section_type) {
64 6 case HAP_ST_COMPRESSOR_TABLE:
65 6 ret = ff_hap_set_chunk_count(ctx, section_size, is_first_table);
66
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 6 times.
6 if (ret != 0)
67 ✗ return ret;
68
2/2
✓ Branch 15 → 13 taken 47 times.
✓ Branch 15 → 16 taken 6 times.
53 for (i = 0; i < section_size; i++) {
69 47 ctx->chunks[i].compressor = bytestream2_get_byte(gbc) << 4;
70 }
71 6 had_compressors = 1;
72 6 is_first_table = 0;
73 6 break;
74 6 case HAP_ST_SIZE_TABLE:
75 6 ret = ff_hap_set_chunk_count(ctx, section_size / 4, is_first_table);
76
1/2
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 6 times.
6 if (ret != 0)
77 ✗ return ret;
78
2/2
✓ Branch 23 → 21 taken 47 times.
✓ Branch 23 → 24 taken 6 times.
53 for (i = 0; i < section_size / 4; i++) {
79 47 ctx->chunks[i].compressed_size = bytestream2_get_le32(gbc);
80 }
81 6 had_sizes = 1;
82 6 is_first_table = 0;
83 6 break;
84 ✗ case HAP_ST_OFFSET_TABLE:
85 ✗ ret = ff_hap_set_chunk_count(ctx, section_size / 4, is_first_table);
86
0/2
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
✗ if (ret != 0)
87 ✗ return ret;
88
0/2
✗ Branch 31 → 29 not taken.
✗ Branch 31 → 32 not taken.
✗ for (i = 0; i < section_size / 4; i++) {
89 ✗ ctx->chunks[i].compressed_offset = bytestream2_get_le32(gbc);
90 }
91 ✗ had_offsets = 1;
92 ✗ is_first_table = 0;
93 ✗ break;
94 ✗ default:
95 ✗ break;
96 }
97 12 size -= section_size;
98 }
99
100
2/4
✓ Branch 36 → 37 taken 6 times.
✗ Branch 36 → 38 not taken.
✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 6 times.
6 if (!had_sizes || !had_compressors)
101 ✗ return AVERROR_INVALIDDATA;
102
103 /* The offsets table is optional. If not present than calculate offsets by
104 * summing the sizes of preceding chunks. */
105
1/2
✓ Branch 39 → 40 taken 6 times.
✗ Branch 39 → 45 not taken.
6 if (!had_offsets) {
106 6 size_t running_size = 0;
107
2/2
✓ Branch 44 → 41 taken 47 times.
✓ Branch 44 → 45 taken 6 times.
53 for (i = 0; i < ctx->chunk_count; i++) {
108 47 ctx->chunks[i].compressed_offset = running_size;
109
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 43 taken 47 times.
47 if (ctx->chunks[i].compressed_size > UINT32_MAX - running_size)
110 ✗ return AVERROR_INVALIDDATA;
111 47 running_size += ctx->chunks[i].compressed_size;
112 }
113 }
114
115 6 return 0;
116 }
117
118 12 static int hap_can_use_tex_in_place(HapContext *ctx)
119 {
120 int i;
121 12 size_t running_offset = 0;
122
2/2
✓ Branch 7 → 3 taken 12 times.
✓ Branch 7 → 8 taken 3 times.
15 for (i = 0; i < ctx->chunk_count; i++) {
123
1/2
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 5 not taken.
12 if (ctx->chunks[i].compressed_offset != running_offset
124
2/2
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 6 taken 3 times.
12 || ctx->chunks[i].compressor != HAP_COMP_NONE)
125 9 return 0;
126 3 running_offset += ctx->chunks[i].compressed_size;
127 }
128 3 return 1;
129 }
130
131 12 static int hap_parse_frame_header(AVCodecContext *avctx)
132 {
133 12 HapContext *ctx = avctx->priv_data;
134 12 GetByteContext *gbc = &ctx->gbc;
135 int section_size;
136 enum HapSectionType section_type;
137 const char *compressorstr;
138 int i, ret;
139
140 12 ret = ff_hap_parse_section_header(gbc, &ctx->texture_section_size, &section_type);
141
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 12 times.
12 if (ret != 0)
142 ✗ return ret;
143
144
3/4
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 7 taken 11 times.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 16 not taken.
12 if ((avctx->codec_tag == MKTAG('H','a','p','1') && (section_type & 0x0F) != HAP_FMT_RGBDXT1) ||
145
3/4
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 9 taken 11 times.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 16 not taken.
12 (avctx->codec_tag == MKTAG('H','a','p','5') && (section_type & 0x0F) != HAP_FMT_RGBADXT5) ||
146
3/4
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 11 taken 10 times.
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 16 not taken.
12 (avctx->codec_tag == MKTAG('H','a','p','Y') && (section_type & 0x0F) != HAP_FMT_YCOCGDXT5) ||
147
3/4
✓ Branch 11 → 12 taken 2 times.
✓ Branch 11 → 13 taken 10 times.
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 16 not taken.
12 (avctx->codec_tag == MKTAG('H','a','p','A') && (section_type & 0x0F) != HAP_FMT_RGTC1) ||
148
4/4
✓ Branch 13 → 14 taken 6 times.
✓ Branch 13 → 18 taken 6 times.
✓ Branch 14 → 15 taken 3 times.
✓ Branch 14 → 18 taken 3 times.
12 ((avctx->codec_tag == MKTAG('H','a','p','M') && (section_type & 0x0F) != HAP_FMT_RGTC1) &&
149
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 18 taken 3 times.
3 (section_type & 0x0F) != HAP_FMT_YCOCGDXT5)) {
150 ✗ av_log(avctx, AV_LOG_ERROR,
151 "Invalid texture format %#04x.\n", section_type & 0x0F);
152 ✗ return AVERROR_INVALIDDATA;
153 }
154
155
2/3
✓ Branch 18 → 19 taken 6 times.
✓ Branch 18 → 26 taken 6 times.
✗ Branch 18 → 33 not taken.
12 switch (section_type & 0xF0) {
156 6 case HAP_COMP_NONE:
157 case HAP_COMP_SNAPPY:
158 6 ret = ff_hap_set_chunk_count(ctx, 1, 1);
159
1/2
✓ Branch 20 → 21 taken 6 times.
✗ Branch 20 → 22 not taken.
6 if (ret == 0) {
160 6 ctx->chunks[0].compressor = section_type & 0xF0;
161 6 ctx->chunks[0].compressed_offset = 0;
162 6 ctx->chunks[0].compressed_size = ctx->texture_section_size;
163 }
164
2/2
✓ Branch 22 → 23 taken 3 times.
✓ Branch 22 → 24 taken 3 times.
6 if (ctx->chunks[0].compressor == HAP_COMP_NONE) {
165 3 compressorstr = "none";
166 } else {
167 3 compressorstr = "snappy";
168 }
169 6 break;
170 6 case HAP_COMP_COMPLEX:
171 6 ret = ff_hap_parse_section_header(gbc, &section_size, &section_type);
172
2/4
✓ Branch 27 → 28 taken 6 times.
✗ Branch 27 → 30 not taken.
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 6 times.
6 if (ret == 0 && section_type != HAP_ST_DECODE_INSTRUCTIONS)
173 ✗ ret = AVERROR_INVALIDDATA;
174
1/2
✓ Branch 30 → 31 taken 6 times.
✗ Branch 30 → 32 not taken.
6 if (ret == 0)
175 6 ret = hap_parse_decode_instructions(ctx, section_size);
176 6 compressorstr = "complex";
177 6 break;
178 ✗ default:
179 ✗ ret = AVERROR_INVALIDDATA;
180 ✗ break;
181 }
182
183
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 12 times.
12 if (ret != 0)
184 ✗ return ret;
185
186 /* Check the frame is valid and read the uncompressed chunk sizes */
187 12 ctx->tex_size = 0;
188
2/2
✓ Branch 52 → 37 taken 53 times.
✓ Branch 52 → 53 taken 12 times.
65 for (i = 0; i < ctx->chunk_count; i++) {
189 53 HapChunk *chunk = &ctx->chunks[i];
190 int64_t uncompressed_size;
191
192 /* Check the compressed buffer is valid */
193
1/2
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 53 times.
53 if (chunk->compressed_offset + (uint64_t)chunk->compressed_size > bytestream2_get_bytes_left(gbc))
194 ✗ return AVERROR_INVALIDDATA;
195
196 /* Chunks are unpacked sequentially, ctx->tex_size is the uncompressed
197 * size thus far */
198 53 chunk->uncompressed_offset = ctx->tex_size;
199
200 /* Fill out uncompressed size */
201
2/2
✓ Branch 40 → 41 taken 50 times.
✓ Branch 40 → 46 taken 3 times.
53 if (chunk->compressor == HAP_COMP_SNAPPY) {
202 GetByteContext gbc_tmp;
203 50 bytestream2_init(&gbc_tmp, gbc->buffer + chunk->compressed_offset,
204 50 chunk->compressed_size);
205 50 uncompressed_size = ff_snappy_peek_uncompressed_length(&gbc_tmp);
206
1/2
✗ Branch 43 → 44 not taken.
✓ Branch 43 → 45 taken 50 times.
50 if (uncompressed_size < 0) {
207 ✗ return uncompressed_size;
208 }
209
1/2
✓ Branch 46 → 47 taken 3 times.
✗ Branch 46 → 48 not taken.
3 } else if (chunk->compressor == HAP_COMP_NONE) {
210 3 uncompressed_size = chunk->compressed_size;
211 } else {
212 ✗ return AVERROR_INVALIDDATA;
213 }
214
1/2
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 53 times.
53 if (uncompressed_size > INT_MAX - ctx->tex_size)
215 ✗ return AVERROR_INVALIDDATA;
216 53 chunk->uncompressed_size = uncompressed_size;
217 53 ctx->tex_size += uncompressed_size;
218 }
219
220 12 av_log(avctx, AV_LOG_DEBUG, "%s compressor\n", compressorstr);
221
222 12 return ret;
223 }
224
225 50 static int decompress_chunks_thread(AVCodecContext *avctx, void *arg,
226 int chunk_nb, int thread_nb)
227 {
228 50 HapContext *ctx = avctx->priv_data;
229
230 50 HapChunk *chunk = &ctx->chunks[chunk_nb];
231 GetByteContext gbc;
232 50 uint8_t *dst = ctx->tex_buf + chunk->uncompressed_offset;
233
234 50 bytestream2_init(&gbc, ctx->gbc.buffer + chunk->compressed_offset, chunk->compressed_size);
235
236
1/2
✓ Branch 3 → 4 taken 50 times.
✗ Branch 3 → 9 not taken.
50 if (chunk->compressor == HAP_COMP_SNAPPY) {
237 int ret;
238 50 int64_t uncompressed_size = ctx->tex_size;
239
240 /* Uncompress the frame */
241 50 ret = ff_snappy_uncompress(&gbc, dst, &uncompressed_size);
242
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 50 times.
50 if (ret < 0) {
243 ✗ av_log(avctx, AV_LOG_ERROR, "Snappy uncompress error\n");
244 ✗ return ret;
245 }
246
0/2
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
✗ } else if (chunk->compressor == HAP_COMP_NONE) {
247 ✗ bytestream2_get_buffer(&gbc, dst, chunk->compressed_size);
248 }
249
250 50 return 0;
251 }
252
253 9 static int hap_decode(AVCodecContext *avctx, AVFrame *frame,
254 int *got_frame, AVPacket *avpkt)
255 {
256 9 HapContext *ctx = avctx->priv_data;
257 int ret, i, t;
258 int section_size;
259 enum HapSectionType section_type;
260 9 int start_texture_section = 0;
261
262 9 bytestream2_init(&ctx->gbc, avpkt->data, avpkt->size);
263
264 /* check for multi texture header */
265
2/2
✓ Branch 3 → 4 taken 3 times.
✓ Branch 3 → 11 taken 6 times.
9 if (ctx->texture_count == 2) {
266 3 ret = ff_hap_parse_section_header(&ctx->gbc, &section_size, &section_type);
267
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 3 times.
3 if (ret != 0)
268 ✗ return ret;
269
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 10 taken 3 times.
3 if ((section_type & 0x0F) != 0x0D) {
270 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid section type in 2 textures mode %#04x.\n", section_type);
271 ✗ return AVERROR_INVALIDDATA;
272 }
273 3 start_texture_section = 4;
274 }
275
276 /* Get the output frame ready to receive data */
277 9 ret = ff_thread_get_buffer(avctx, frame, 0);
278
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 9 times.
9 if (ret < 0)
279 ✗ return ret;
280
281
2/2
✓ Branch 43 → 15 taken 12 times.
✓ Branch 43 → 44 taken 9 times.
21 for (t = 0; t < ctx->texture_count; t++) {
282 12 bytestream2_seek(&ctx->gbc, start_texture_section, SEEK_SET);
283
284 /* Check for section header */
285 12 ret = hap_parse_frame_header(avctx);
286
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 12 times.
12 if (ret < 0)
287 ✗ return ret;
288
289 12 if (ctx->tex_size != (avctx->coded_width / TEXTURE_BLOCK_W)
290 12 *(avctx->coded_height / TEXTURE_BLOCK_H)
291
1/2
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 22 taken 12 times.
12 *ctx->dec[t].tex_ratio) {
292 ✗ av_log(avctx, AV_LOG_ERROR, "uncompressed size mismatches\n");
293 ✗ return AVERROR_INVALIDDATA;
294 }
295
296 12 start_texture_section += ctx->texture_section_size + 4;
297
298 /* Unpack the DXT texture */
299
2/2
✓ Branch 23 → 24 taken 3 times.
✓ Branch 23 → 31 taken 9 times.
12 if (hap_can_use_tex_in_place(ctx)) {
300 int tex_size;
301 /* Only DXTC texture compression in a contiguous block */
302 3 ctx->dec[t].tex_data.in = ctx->gbc.buffer;
303
1/2
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 3 times.
3 tex_size = FFMIN(ctx->texture_section_size, bytestream2_get_bytes_left(&ctx->gbc));
304 3 if (tex_size < (avctx->coded_width / TEXTURE_BLOCK_W)
305 3 *(avctx->coded_height / TEXTURE_BLOCK_H)
306
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 41 taken 3 times.
3 *ctx->dec[t].tex_ratio) {
307 ✗ av_log(avctx, AV_LOG_ERROR, "Insufficient data\n");
308 ✗ return AVERROR_INVALIDDATA;
309 }
310 } else {
311 /* Perform the second-stage decompression */
312 9 ret = av_reallocp(&ctx->tex_buf, ctx->tex_size);
313
1/2
✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 9 times.
9 if (ret < 0)
314 ✗ return ret;
315 9 memset(ctx->tex_buf, 0, ctx->tex_size);
316
317 9 avctx->execute2(avctx, decompress_chunks_thread, NULL,
318 ctx->chunk_results, ctx->chunk_count);
319
320
2/2
✓ Branch 39 → 36 taken 50 times.
✓ Branch 39 → 40 taken 9 times.
59 for (i = 0; i < ctx->chunk_count; i++) {
321
1/2
✗ Branch 36 → 37 not taken.
✓ Branch 36 → 38 taken 50 times.
50 if (ctx->chunk_results[i] < 0)
322 ✗ return ctx->chunk_results[i];
323 }
324
325 9 ctx->dec[t].tex_data.in = ctx->tex_buf;
326 }
327
328 12 ctx->dec[t].frame_data.out = frame->data[0];
329 12 ctx->dec[t].stride = frame->linesize[0];
330 12 ctx->dec[t].width = avctx->coded_width;
331 12 ctx->dec[t].height = avctx->coded_height;
332 12 ff_texturedsp_exec_decompress_threads(avctx, &ctx->dec[t]);
333 }
334
335 /* Frame is ready to be output */
336 9 *got_frame = 1;
337
338 9 return avpkt->size;
339 }
340
341 28 static av_cold int hap_init(AVCodecContext *avctx)
342 {
343 28 HapContext *ctx = avctx->priv_data;
344 TextureDSPContext dxtc;
345 const char *texture_name;
346 28 int ret = av_image_check_size(avctx->width, avctx->height, 0, avctx);
347
348
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 28 times.
28 if (ret < 0) {
349 ✗ av_log(avctx, AV_LOG_ERROR, "Invalid video size %dx%d.\n",
350 avctx->width, avctx->height);
351 ✗ return ret;
352 }
353
354 /* Since codec is based on 4x4 blocks, size is aligned to 4 */
355 28 avctx->coded_width = FFALIGN(avctx->width, TEXTURE_BLOCK_W);
356 28 avctx->coded_height = FFALIGN(avctx->height, TEXTURE_BLOCK_H);
357
358 28 ff_texturedsp_init(&dxtc);
359
360 28 ctx->texture_count = 1;
361 28 ctx->dec[0].raw_ratio = 16;
362 28 ctx->dec[0].slice_count = av_clip(avctx->thread_count, 1,
363 28 avctx->coded_height / TEXTURE_BLOCK_H);
364
365
5/6
✓ Branch 7 → 8 taken 2 times.
✓ Branch 7 → 9 taken 2 times.
✓ Branch 7 → 10 taken 6 times.
✓ Branch 7 → 11 taken 6 times.
✓ Branch 7 → 12 taken 12 times.
✗ Branch 7 → 13 not taken.
28 switch (avctx->codec_tag) {
366 2 case MKTAG('H','a','p','1'):
367 2 texture_name = "DXT1";
368 2 ctx->dec[0].tex_ratio = 8;
369 2 ctx->dec[0].tex_funct = dxtc.dxt1_block;
370 2 avctx->pix_fmt = AV_PIX_FMT_RGB0;
371 2 break;
372 2 case MKTAG('H','a','p','5'):
373 2 texture_name = "DXT5";
374 2 ctx->dec[0].tex_ratio = 16;
375 2 ctx->dec[0].tex_funct = dxtc.dxt5_block;
376 2 avctx->pix_fmt = AV_PIX_FMT_RGBA;
377 2 break;
378 6 case MKTAG('H','a','p','Y'):
379 6 texture_name = "DXT5-YCoCg-scaled";
380 6 ctx->dec[0].tex_ratio = 16;
381 6 ctx->dec[0].tex_funct = dxtc.dxt5ys_block;
382 6 avctx->pix_fmt = AV_PIX_FMT_RGB0;
383 6 break;
384 6 case MKTAG('H','a','p','A'):
385 6 texture_name = "RGTC1";
386 6 ctx->dec[0].tex_ratio = 8;
387 6 ctx->dec[0].tex_funct = dxtc.rgtc1u_gray_block;
388 6 ctx->dec[0].raw_ratio = 4;
389 6 avctx->pix_fmt = AV_PIX_FMT_GRAY8;
390 6 break;
391 12 case MKTAG('H','a','p','M'):
392 12 texture_name = "DXT5-YCoCg-scaled / RGTC1";
393 12 ctx->dec[0].tex_ratio = 16;
394 12 ctx->dec[1].tex_ratio = 8;
395 12 ctx->dec[0].tex_funct = dxtc.dxt5ys_block;
396 12 ctx->dec[1].tex_funct = dxtc.rgtc1u_alpha_block;
397 12 ctx->dec[1].raw_ratio = 16;
398 12 ctx->dec[1].slice_count = ctx->dec[0].slice_count;
399 12 avctx->pix_fmt = AV_PIX_FMT_RGBA;
400 12 ctx->texture_count = 2;
401 12 break;
402 ✗ default:
403 ✗ return AVERROR_DECODER_NOT_FOUND;
404 }
405
406 28 av_log(avctx, AV_LOG_DEBUG, "%s texture\n", texture_name);
407
408 28 return 0;
409 }
410
411 28 static av_cold int hap_close(AVCodecContext *avctx)
412 {
413 28 HapContext *ctx = avctx->priv_data;
414
415 28 ff_hap_free_context(ctx);
416
417 28 return 0;
418 }
419
420 const FFCodec ff_hap_decoder = {
421 .p.name = "hap",
422 CODEC_LONG_NAME("Vidvox Hap"),
423 .p.type = AVMEDIA_TYPE_VIDEO,
424 .p.id = AV_CODEC_ID_HAP,
425 .init = hap_init,
426 FF_CODEC_DECODE_CB(hap_decode),
427 .close = hap_close,
428 .priv_data_size = sizeof(HapContext),
429 .p.capabilities = AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS |
430 AV_CODEC_CAP_DR1,
431 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
432 .codec_tags = (const uint32_t []){
433 MKTAG('H','a','p','1'),
434 MKTAG('H','a','p','5'),
435 MKTAG('H','a','p','Y'),
436 MKTAG('H','a','p','A'),
437 MKTAG('H','a','p','M'),
438 FF_CODEC_TAGS_END,
439 },
440 };
441