FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hapdec.c
Go to the documentation of this file.
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 
38 #include "avcodec.h"
39 #include "bytestream.h"
40 #include "hap.h"
41 #include "internal.h"
42 #include "snappy.h"
43 #include "texturedsp.h"
44 #include "thread.h"
45 
46 /* The first three bytes are the size of the section past the header, or zero
47  * if the length is stored in the next long word. The fourth byte in the first
48  * long word indicates the type of the current section. */
49 static int parse_section_header(GetByteContext *gbc, int *section_size,
50  enum HapSectionType *section_type)
51 {
52  if (bytestream2_get_bytes_left(gbc) < 4)
53  return AVERROR_INVALIDDATA;
54 
55  *section_size = bytestream2_get_le24(gbc);
56  *section_type = bytestream2_get_byte(gbc);
57 
58  if (*section_size == 0) {
59  if (bytestream2_get_bytes_left(gbc) < 4)
60  return AVERROR_INVALIDDATA;
61 
62  *section_size = bytestream2_get_le32(gbc);
63  }
64 
65  if (*section_size > bytestream2_get_bytes_left(gbc) || *section_size < 0)
66  return AVERROR_INVALIDDATA;
67  else
68  return 0;
69 }
70 
72 {
73  GetByteContext *gbc = &ctx->gbc;
74  int section_size;
75  enum HapSectionType section_type;
76  int is_first_table = 1, had_offsets = 0, had_compressors = 0, had_sizes = 0;
77  int i, ret;
78 
79  while (size > 0) {
80  int stream_remaining = bytestream2_get_bytes_left(gbc);
81  ret = parse_section_header(gbc, &section_size, &section_type);
82  if (ret != 0)
83  return ret;
84 
85  size -= stream_remaining - bytestream2_get_bytes_left(gbc);
86 
87  switch (section_type) {
89  ret = ff_hap_set_chunk_count(ctx, section_size, is_first_table);
90  if (ret != 0)
91  return ret;
92  for (i = 0; i < section_size; i++) {
93  ctx->chunks[i].compressor = bytestream2_get_byte(gbc) << 4;
94  }
95  had_compressors = 1;
96  is_first_table = 0;
97  break;
98  case HAP_ST_SIZE_TABLE:
99  ret = ff_hap_set_chunk_count(ctx, section_size / 4, is_first_table);
100  if (ret != 0)
101  return ret;
102  for (i = 0; i < section_size / 4; i++) {
103  ctx->chunks[i].compressed_size = bytestream2_get_le32(gbc);
104  }
105  had_sizes = 1;
106  is_first_table = 0;
107  break;
108  case HAP_ST_OFFSET_TABLE:
109  ret = ff_hap_set_chunk_count(ctx, section_size / 4, is_first_table);
110  if (ret != 0)
111  return ret;
112  for (i = 0; i < section_size / 4; i++) {
113  ctx->chunks[i].compressed_offset = bytestream2_get_le32(gbc);
114  }
115  had_offsets = 1;
116  is_first_table = 0;
117  break;
118  default:
119  break;
120  }
121  size -= section_size;
122  }
123 
124  if (!had_sizes || !had_compressors)
125  return AVERROR_INVALIDDATA;
126 
127  /* The offsets table is optional. If not present than calculate offsets by
128  * summing the sizes of preceding chunks. */
129  if (!had_offsets) {
130  size_t running_size = 0;
131  for (i = 0; i < ctx->chunk_count; i++) {
132  ctx->chunks[i].compressed_offset = running_size;
133  running_size += ctx->chunks[i].compressed_size;
134  }
135  }
136 
137  return 0;
138 }
139 
141 {
142  int i;
143  size_t running_offset = 0;
144  for (i = 0; i < ctx->chunk_count; i++) {
145  if (ctx->chunks[i].compressed_offset != running_offset
146  || ctx->chunks[i].compressor != HAP_COMP_NONE)
147  return 0;
148  running_offset += ctx->chunks[i].compressed_size;
149  }
150  return 1;
151 }
152 
154 {
155  HapContext *ctx = avctx->priv_data;
156  GetByteContext *gbc = &ctx->gbc;
157  int section_size;
158  enum HapSectionType section_type;
159  const char *compressorstr;
160  int i, ret;
161 
162  ret = parse_section_header(gbc, &ctx->texture_section_size, &section_type);
163  if (ret != 0)
164  return ret;
165 
166  if ((avctx->codec_tag == MKTAG('H','a','p','1') && (section_type & 0x0F) != HAP_FMT_RGBDXT1) ||
167  (avctx->codec_tag == MKTAG('H','a','p','5') && (section_type & 0x0F) != HAP_FMT_RGBADXT5) ||
168  (avctx->codec_tag == MKTAG('H','a','p','Y') && (section_type & 0x0F) != HAP_FMT_YCOCGDXT5) ||
169  (avctx->codec_tag == MKTAG('H','a','p','A') && (section_type & 0x0F) != HAP_FMT_RGTC1) ||
170  ((avctx->codec_tag == MKTAG('H','a','p','M') && (section_type & 0x0F) != HAP_FMT_RGTC1) &&
171  (section_type & 0x0F) != HAP_FMT_YCOCGDXT5)) {
172  av_log(avctx, AV_LOG_ERROR,
173  "Invalid texture format %#04x.\n", section_type & 0x0F);
174  return AVERROR_INVALIDDATA;
175  }
176 
177  switch (section_type & 0xF0) {
178  case HAP_COMP_NONE:
179  case HAP_COMP_SNAPPY:
180  ret = ff_hap_set_chunk_count(ctx, 1, 1);
181  if (ret == 0) {
182  ctx->chunks[0].compressor = section_type & 0xF0;
183  ctx->chunks[0].compressed_offset = 0;
185  }
186  if (ctx->chunks[0].compressor == HAP_COMP_NONE) {
187  compressorstr = "none";
188  } else {
189  compressorstr = "snappy";
190  }
191  break;
192  case HAP_COMP_COMPLEX:
193  ret = parse_section_header(gbc, &section_size, &section_type);
194  if (ret == 0 && section_type != HAP_ST_DECODE_INSTRUCTIONS)
195  ret = AVERROR_INVALIDDATA;
196  if (ret == 0)
197  ret = hap_parse_decode_instructions(ctx, section_size);
198  compressorstr = "complex";
199  break;
200  default:
201  ret = AVERROR_INVALIDDATA;
202  break;
203  }
204 
205  if (ret != 0)
206  return ret;
207 
208  /* Check the frame is valid and read the uncompressed chunk sizes */
209  ctx->tex_size = 0;
210  for (i = 0; i < ctx->chunk_count; i++) {
211  HapChunk *chunk = &ctx->chunks[i];
212 
213  /* Check the compressed buffer is valid */
215  return AVERROR_INVALIDDATA;
216 
217  /* Chunks are unpacked sequentially, ctx->tex_size is the uncompressed
218  * size thus far */
219  chunk->uncompressed_offset = ctx->tex_size;
220 
221  /* Fill out uncompressed size */
222  if (chunk->compressor == HAP_COMP_SNAPPY) {
223  GetByteContext gbc_tmp;
224  int64_t uncompressed_size;
225  bytestream2_init(&gbc_tmp, gbc->buffer + chunk->compressed_offset,
226  chunk->compressed_size);
227  uncompressed_size = ff_snappy_peek_uncompressed_length(&gbc_tmp);
228  if (uncompressed_size < 0) {
229  return uncompressed_size;
230  }
231  chunk->uncompressed_size = uncompressed_size;
232  } else if (chunk->compressor == HAP_COMP_NONE) {
233  chunk->uncompressed_size = chunk->compressed_size;
234  } else {
235  return AVERROR_INVALIDDATA;
236  }
237  ctx->tex_size += chunk->uncompressed_size;
238  }
239 
240  av_log(avctx, AV_LOG_DEBUG, "%s compressor\n", compressorstr);
241 
242  return ret;
243 }
244 
245 static int decompress_chunks_thread(AVCodecContext *avctx, void *arg,
246  int chunk_nb, int thread_nb)
247 {
248  HapContext *ctx = avctx->priv_data;
249 
250  HapChunk *chunk = &ctx->chunks[chunk_nb];
251  GetByteContext gbc;
252  uint8_t *dst = ctx->tex_buf + chunk->uncompressed_offset;
253 
254  bytestream2_init(&gbc, ctx->gbc.buffer + chunk->compressed_offset, chunk->compressed_size);
255 
256  if (chunk->compressor == HAP_COMP_SNAPPY) {
257  int ret;
258  int64_t uncompressed_size = ctx->tex_size;
259 
260  /* Uncompress the frame */
261  ret = ff_snappy_uncompress(&gbc, dst, &uncompressed_size);
262  if (ret < 0) {
263  av_log(avctx, AV_LOG_ERROR, "Snappy uncompress error\n");
264  return ret;
265  }
266  } else if (chunk->compressor == HAP_COMP_NONE) {
267  bytestream2_get_buffer(&gbc, dst, chunk->compressed_size);
268  }
269 
270  return 0;
271 }
272 
274  int slice, int thread_nb, int texture_num)
275 {
276  HapContext *ctx = avctx->priv_data;
277  AVFrame *frame = arg;
278  const uint8_t *d = ctx->tex_data;
279  int w_block = avctx->coded_width / TEXTURE_BLOCK_W;
280  int h_block = avctx->coded_height / TEXTURE_BLOCK_H;
281  int x, y;
282  int start_slice, end_slice;
283  int base_blocks_per_slice = h_block / ctx->slice_count;
284  int remainder_blocks = h_block % ctx->slice_count;
285 
286  /* When the frame height (in blocks) doesn't divide evenly between the
287  * number of slices, spread the remaining blocks evenly between the first
288  * operations */
289  start_slice = slice * base_blocks_per_slice;
290  /* Add any extra blocks (one per slice) that have been added before this slice */
291  start_slice += FFMIN(slice, remainder_blocks);
292 
293  end_slice = start_slice + base_blocks_per_slice;
294  /* Add an extra block if there are still remainder blocks to be accounted for */
295  if (slice < remainder_blocks)
296  end_slice++;
297 
298  for (y = start_slice; y < end_slice; y++) {
299  uint8_t *p = frame->data[0] + y * frame->linesize[0] * TEXTURE_BLOCK_H;
300  int off = y * w_block;
301  for (x = 0; x < w_block; x++) {
302  if (texture_num == 0) {
303  ctx->tex_fun(p + x * 4 * ctx->uncompress_pix_size, frame->linesize[0],
304  d + (off + x) * ctx->tex_rat);
305  } else {
306  ctx->tex_fun2(p + x * 4 * ctx->uncompress_pix_size, frame->linesize[0],
307  d + (off + x) * ctx->tex_rat2);
308  }
309  }
310  }
311 
312  return 0;
313 }
314 
316  int slice, int thread_nb)
317 {
318  return decompress_texture_thread_internal(avctx, arg, slice, thread_nb, 0);
319 }
320 
322  int slice, int thread_nb)
323 {
324  return decompress_texture_thread_internal(avctx, arg, slice, thread_nb, 1);
325 }
326 
327 static int hap_decode(AVCodecContext *avctx, void *data,
328  int *got_frame, AVPacket *avpkt)
329 {
330  HapContext *ctx = avctx->priv_data;
331  ThreadFrame tframe;
332  int ret, i, t;
333  int tex_size;
334  int section_size;
335  enum HapSectionType section_type;
336  int start_texture_section = 0;
337  int tex_rat[2] = {0, 0};
338 
339  bytestream2_init(&ctx->gbc, avpkt->data, avpkt->size);
340 
341  tex_rat[0] = ctx->tex_rat;
342 
343  /* check for multi texture header */
344  if (ctx->texture_count == 2) {
345  ret = parse_section_header(&ctx->gbc, &section_size, &section_type);
346  if (ret != 0)
347  return ret;
348  if ((section_type & 0x0F) != 0x0D) {
349  av_log(avctx, AV_LOG_ERROR, "Invalid section type in 2 textures mode %#04x.\n", section_type);
350  return AVERROR_INVALIDDATA;
351  }
352  start_texture_section = 4;
353  tex_rat[1] = ctx->tex_rat2;
354  }
355 
356  /* Get the output frame ready to receive data */
357  tframe.f = data;
358  ret = ff_thread_get_buffer(avctx, &tframe, 0);
359  if (ret < 0)
360  return ret;
361 
362  for (t = 0; t < ctx->texture_count; t++) {
363  bytestream2_seek(&ctx->gbc, start_texture_section, SEEK_SET);
364 
365  /* Check for section header */
366  ret = hap_parse_frame_header(avctx);
367  if (ret < 0)
368  return ret;
369 
370  start_texture_section += ctx->texture_section_size + 4;
371 
372  if (avctx->codec->update_thread_context)
373  ff_thread_finish_setup(avctx);
374 
375  /* Unpack the DXT texture */
376  if (hap_can_use_tex_in_place(ctx)) {
377  /* Only DXTC texture compression in a contiguous block */
378  ctx->tex_data = ctx->gbc.buffer;
379  tex_size = FFMIN(ctx->texture_section_size, bytestream2_get_bytes_left(&ctx->gbc));
380  } else {
381  /* Perform the second-stage decompression */
382  ret = av_reallocp(&ctx->tex_buf, ctx->tex_size);
383  if (ret < 0)
384  return ret;
385 
386  avctx->execute2(avctx, decompress_chunks_thread, NULL,
387  ctx->chunk_results, ctx->chunk_count);
388 
389  for (i = 0; i < ctx->chunk_count; i++) {
390  if (ctx->chunk_results[i] < 0)
391  return ctx->chunk_results[i];
392  }
393 
394  ctx->tex_data = ctx->tex_buf;
395  tex_size = ctx->tex_size;
396  }
397 
398  if (tex_size < (avctx->coded_width / TEXTURE_BLOCK_W)
399  *(avctx->coded_height / TEXTURE_BLOCK_H)
400  *tex_rat[t]) {
401  av_log(avctx, AV_LOG_ERROR, "Insufficient data\n");
402  return AVERROR_INVALIDDATA;
403  }
404 
405  /* Use the decompress function on the texture, one block per thread */
406  if (t == 0){
407  avctx->execute2(avctx, decompress_texture_thread, tframe.f, NULL, ctx->slice_count);
408  } else{
409  tframe.f = data;
410  avctx->execute2(avctx, decompress_texture2_thread, tframe.f, NULL, ctx->slice_count);
411  }
412  }
413 
414  /* Frame is ready to be output */
415  tframe.f->pict_type = AV_PICTURE_TYPE_I;
416  tframe.f->key_frame = 1;
417  *got_frame = 1;
418 
419  return avpkt->size;
420 }
421 
422 static av_cold int hap_init(AVCodecContext *avctx)
423 {
424  HapContext *ctx = avctx->priv_data;
425  const char *texture_name;
426  int ret = av_image_check_size(avctx->width, avctx->height, 0, avctx);
427 
428  if (ret < 0) {
429  av_log(avctx, AV_LOG_ERROR, "Invalid video size %dx%d.\n",
430  avctx->width, avctx->height);
431  return ret;
432  }
433 
434  /* Since codec is based on 4x4 blocks, size is aligned to 4 */
435  avctx->coded_width = FFALIGN(avctx->width, TEXTURE_BLOCK_W);
436  avctx->coded_height = FFALIGN(avctx->height, TEXTURE_BLOCK_H);
437 
438  ff_texturedsp_init(&ctx->dxtc);
439 
440  ctx->texture_count = 1;
441  ctx->uncompress_pix_size = 4;
442 
443  switch (avctx->codec_tag) {
444  case MKTAG('H','a','p','1'):
445  texture_name = "DXT1";
446  ctx->tex_rat = 8;
447  ctx->tex_fun = ctx->dxtc.dxt1_block;
448  avctx->pix_fmt = AV_PIX_FMT_RGB0;
449  break;
450  case MKTAG('H','a','p','5'):
451  texture_name = "DXT5";
452  ctx->tex_rat = 16;
453  ctx->tex_fun = ctx->dxtc.dxt5_block;
454  avctx->pix_fmt = AV_PIX_FMT_RGBA;
455  break;
456  case MKTAG('H','a','p','Y'):
457  texture_name = "DXT5-YCoCg-scaled";
458  ctx->tex_rat = 16;
459  ctx->tex_fun = ctx->dxtc.dxt5ys_block;
460  avctx->pix_fmt = AV_PIX_FMT_RGB0;
461  break;
462  case MKTAG('H','a','p','A'):
463  texture_name = "RGTC1";
464  ctx->tex_rat = 8;
465  ctx->tex_fun = ctx->dxtc.rgtc1u_gray_block;
466  avctx->pix_fmt = AV_PIX_FMT_GRAY8;
467  ctx->uncompress_pix_size = 1;
468  break;
469  case MKTAG('H','a','p','M'):
470  texture_name = "DXT5-YCoCg-scaled / RGTC1";
471  ctx->tex_rat = 16;
472  ctx->tex_rat2 = 8;
473  ctx->tex_fun = ctx->dxtc.dxt5ys_block;
474  ctx->tex_fun2 = ctx->dxtc.rgtc1u_alpha_block;
475  avctx->pix_fmt = AV_PIX_FMT_RGBA;
476  ctx->texture_count = 2;
477  break;
478  default:
480  }
481 
482  av_log(avctx, AV_LOG_DEBUG, "%s texture\n", texture_name);
483 
484  ctx->slice_count = av_clip(avctx->thread_count, 1,
485  avctx->coded_height / TEXTURE_BLOCK_H);
486 
487  return 0;
488 }
489 
490 static av_cold int hap_close(AVCodecContext *avctx)
491 {
492  HapContext *ctx = avctx->priv_data;
493 
494  ff_hap_free_context(ctx);
495 
496  return 0;
497 }
498 
500  .name = "hap",
501  .long_name = NULL_IF_CONFIG_SMALL("Vidvox Hap"),
502  .type = AVMEDIA_TYPE_VIDEO,
503  .id = AV_CODEC_ID_HAP,
504  .init = hap_init,
505  .decode = hap_decode,
506  .close = hap_close,
507  .priv_data_size = sizeof(HapContext),
510  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
512 };
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
Definition: hap.h:61
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:1511
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
HapChunk * chunks
Definition: hap.h:72
static int hap_can_use_tex_in_place(HapContext *ctx)
Definition: hapdec.c:140
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1689
HapSectionType
Definition: hap.h:46
int(* dxt1_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:46
misc image utilities
AVFrame * f
Definition: thread.h:36
int(* tex_fun)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: hap.h:90
int tex_rat2
Definition: hap.h:76
Texture block (4x4) module.
int size
Definition: avcodec.h:1415
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1711
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:133
size_t compressed_size
Definition: hap.h:56
int compressed_offset
Definition: hap.h:55
AVCodec.
Definition: avcodec.h:3365
size_t uncompressed_size
Definition: hap.h:58
int64_t ff_snappy_peek_uncompressed_length(GetByteContext *gb)
Get the uncompressed length of an input buffer compressed using the Snappy algorithm.
Definition: snappy.c:131
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
int(* rgtc1u_gray_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:56
uint8_t
#define av_cold
Definition: attributes.h:82
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:234
static int hap_parse_decode_instructions(HapContext *ctx, int size)
Definition: hapdec.c:71
Multithreading support functions.
AVCodec ff_hap_decoder
Definition: hapdec.c:499
int ff_hap_set_chunk_count(HapContext *ctx, int count, int first_in_frame)
Definition: hap.c:28
static AVFrame * frame
#define TEXTURE_BLOCK_H
Definition: texturedsp.h:43
TextureDSPContext dxtc
Definition: hap.h:64
uint8_t * data
Definition: avcodec.h:1414
const uint8_t * buffer
Definition: bytestream.h:34
static av_cold int hap_init(AVCodecContext *avctx)
Definition: hapdec.c:422
ptrdiff_t size
Definition: opengl_enc.c:101
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
#define FFALIGN(x, a)
Definition: macros.h:48
GetByteContext gbc
Definition: hap.h:65
#define av_log(a,...)
static int hap_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: hapdec.c:327
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int * chunk_results
Definition: hap.h:73
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:263
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:154
const char * arg
Definition: jacosubdec.c:66
const char * name
Name of the codec implementation.
Definition: avcodec.h:3372
int(* dxt5_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:51
int(* tex_fun2)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: hap.h:91
static int decompress_texture_thread_internal(AVCodecContext *avctx, void *arg, int slice, int thread_nb, int texture_num)
Definition: hapdec.c:273
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:1012
int ff_snappy_uncompress(GetByteContext *gb, uint8_t *buf, int64_t *size)
Decompress an input buffer using Snappy algorithm.
Definition: snappy.c:141
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:89
static av_cold int hap_close(AVCodecContext *avctx)
Definition: hapdec.c:490
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:282
av_cold void ff_texturedsp_init(TextureDSPContext *c)
Definition: texturedsp.c:637
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:284
int uncompressed_offset
Definition: hap.h:57
#define FFMIN(a, b)
Definition: common.h:96
int width
picture width / height.
Definition: avcodec.h:1674
static int parse_section_header(GetByteContext *gbc, int *section_size, enum HapSectionType *section_type)
Definition: hapdec.c:49
AVFormatContext * ctx
Definition: movenc.c:48
int tex_rat
Definition: hap.h:75
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:2753
Snappy decompression.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:1016
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:163
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:232
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
av_cold void ff_hap_free_context(HapContext *ctx)
Definition: hap.c:50
main external API structure.
Definition: avcodec.h:1502
const uint8_t * tex_data
Definition: hap.h:77
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1527
int chunk_count
Definition: hap.h:71
int coded_height
Definition: avcodec.h:1689
int slice_count
Definition: hap.h:83
static int decompress_texture2_thread(AVCodecContext *avctx, void *arg, int slice, int thread_nb)
Definition: hapdec.c:321
static int decompress_chunks_thread(AVCodecContext *avctx, void *arg, int chunk_nb, int thread_nb)
Definition: hapdec.c:245
static int hap_parse_frame_header(AVCodecContext *avctx)
Definition: hapdec.c:153
static int decompress_texture_thread(AVCodecContext *avctx, void *arg, int slice, int thread_nb)
Definition: hapdec.c:315
uint8_t * tex_buf
Definition: hap.h:78
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
Y , 8bpp.
Definition: pixfmt.h:70
common internal api header.
size_t tex_size
Definition: hap.h:79
Definition: hap.h:53
void * priv_data
Definition: avcodec.h:1529
int(* update_thread_context)(AVCodecContext *dst, const AVCodecContext *src)
Copy necessary context variables from a previous thread context to the current one.
Definition: avcodec.h:3432
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:52
int texture_section_size
Definition: hap.h:86
int(* rgtc1u_alpha_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:57
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
Definition: avcodec.h:2813
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:279
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
Definition: bytestream.h:208
int uncompress_pix_size
Definition: hap.h:87
enum HapCompressor compressor
Definition: hap.h:54
#define MKTAG(a, b, c, d)
Definition: common.h:366
#define TEXTURE_BLOCK_W
Definition: texturedsp.h:42
int texture_count
Definition: hap.h:85
This structure stores compressed data.
Definition: avcodec.h:1391
int(* dxt5ys_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:53
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:956