47#define HAP_MAX_CHUNKS 64
60 if (
ctx->tex_size > out_length)
63 ctx->enc.tex_data.out =
out;
64 ctx->enc.frame_data.in =
f->data[0];
65 ctx->enc.stride =
f->linesize[0];
83 bytestream2_put_le24(pbc, header_length ==
HAP_HDR_LONG ? 0 : section_length);
84 bytestream2_put_byte(pbc, section_type);
87 bytestream2_put_le32(pbc, section_length);
94 int i, final_size = 0;
96 for (
i = 0;
i <
ctx->chunk_count;
i++) {
98 uint8_t *chunk_src, *chunk_dst;
105 +
ctx->chunks[
i-1].compressed_size;
116 if (ret != SNAPPY_OK) {
124 "Snappy buffer bigger than uncompressed (%zu >= %zu bytes).\n",
145 return (5 *
ctx->chunk_count) + 8;
153 if (
ctx->chunk_count > 1) {
167 if (
ctx->chunk_count == 1) {
170 ctx->chunks[0].compressor |
ctx->opt_tex_fmt);
180 for (
i = 0;
i <
ctx->chunk_count;
i++) {
181 bytestream2_put_byte(&pbc,
ctx->chunks[
i].compressor >> 4);
187 for (
i = 0;
i <
ctx->chunk_count;
i++) {
188 bytestream2_put_le32(&pbc,
ctx->chunks[
i].compressed_size);
198 int final_data_size, ret;
199 int pktsize =
FFMAX(
ctx->tex_size,
ctx->max_snappy *
ctx->chunk_count) + header_length;
213 final_data_size =
ctx->tex_size;
222 if (final_data_size < 0)
223 return final_data_size;
238 int corrected_chunk_count;
255 switch (
ctx->opt_tex_fmt) {
257 ctx->enc.tex_ratio = 8;
263 ctx->enc.tex_ratio = 16;
269 ctx->enc.tex_ratio = 16;
278 ctx->enc.raw_ratio = 16;
286 switch (
ctx->opt_compressor) {
289 corrected_chunk_count = 1;
291 ctx->max_snappy =
ctx->tex_size;
297 while ((
ctx->tex_size /
ctx->enc.tex_ratio) % corrected_chunk_count != 0) {
298 corrected_chunk_count--;
301 ctx->max_snappy = snappy_max_compressed_length(
ctx->tex_size / corrected_chunk_count);
311 if (corrected_chunk_count !=
ctx->opt_chunk_count) {
313 ctx->opt_chunk_count, corrected_chunk_count);
331#define OFFSET(x) offsetof(HapContext, x)
332#define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
346 .class_name =
"Hap encoder",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_hap_encoder
static AVFormatContext * ctx
Libavcodec external API header.
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
#define i(width, name, range_min, range_max)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
reference-counted frame API
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
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...
#define LIBAVUTIL_VERSION_INT
av_cold void ff_hap_free_context(HapContext *ctx)
int ff_hap_set_chunk_count(HapContext *ctx, int count, int first_in_frame)
@ HAP_ST_DECODE_INSTRUCTIONS
@ HAP_ST_COMPRESSOR_TABLE
static av_cold int hap_init(AVCodecContext *avctx)
static av_cold int hap_close(AVCodecContext *avctx)
static int hap_header_length(HapContext *ctx)
static int hap_decode_instructions_length(HapContext *ctx)
static int hap_compress_frame(AVCodecContext *avctx, uint8_t *dst)
static void hap_write_section_header(PutByteContext *pbc, enum HapHeaderLength header_length, int section_length, enum HapSectionType section_type)
static av_cold int hap_init(AVCodecContext *avctx)
static int compress_texture(AVCodecContext *avctx, uint8_t *out, int out_length, const AVFrame *f)
static av_cold int hap_close(AVCodecContext *avctx)
static int hap_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static const AVClass hapenc_class
static void hap_write_frame_header(HapContext *ctx, uint8_t *dst, int frame_length)
#define MKTAG(a, b, c, d)
Memory handling functions.
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Describe the class of an AVClass context structure.
main external API structure.
int width
picture width / height.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
uint32_t compressed_offset
enum HapCompressor compressor
int(* dxt1_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
int(* dxt5ys_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
int(* dxt5_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Texture block (4x4) module.
void ff_texturedspenc_init(TextureDSPEncContext *c)
int ff_texturedsp_exec_compress_threads(struct AVCodecContext *avctx, TextureDSPThreadContext *ctx)