2015-04-26 00:58:57 +02:00
|
|
|
/*
|
|
|
|
* Vidvox Hap decoder
|
|
|
|
* Copyright (C) 2015 Vittorio Giovara <vittorio.giovara@gmail.com>
|
2015-07-21 02:12:12 +02:00
|
|
|
* Copyright (C) 2015 Tom Butterworth <bangnoise@gmail.com>
|
2015-04-26 00:58:57 +02:00
|
|
|
*
|
2017-11-21 12:59:02 +02:00
|
|
|
* HapQA and HAPAlphaOnly added by Jokyo Images
|
|
|
|
*
|
2015-06-22 22:33:46 +02:00
|
|
|
* This file is part of FFmpeg.
|
2015-04-26 00:58:57 +02:00
|
|
|
*
|
2015-06-22 22:33:46 +02:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2015-04-26 00:58:57 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2015-06-22 22:33:46 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2015-04-26 00:58:57 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2015-06-22 22:33:46 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2015-04-26 00:58:57 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Hap decoder
|
|
|
|
*
|
2017-09-23 21:50:54 +02:00
|
|
|
* Fourcc: Hap1, Hap5, HapY, HapA, HapM
|
2015-04-26 00:58:57 +02:00
|
|
|
*
|
|
|
|
* https://github.com/Vidvox/hap/blob/master/documentation/HapVideoDRAFT.md
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "libavutil/imgutils.h"
|
2024-03-25 02:30:37 +02:00
|
|
|
#include "libavutil/mem.h"
|
2015-04-26 00:58:57 +02:00
|
|
|
|
|
|
|
#include "avcodec.h"
|
|
|
|
#include "bytestream.h"
|
2022-03-16 19:18:28 +02:00
|
|
|
#include "codec_internal.h"
|
2015-04-26 00:58:57 +02:00
|
|
|
#include "hap.h"
|
|
|
|
#include "snappy.h"
|
|
|
|
#include "texturedsp.h"
|
|
|
|
#include "thread.h"
|
|
|
|
|
2015-07-21 02:12:12 +02:00
|
|
|
static int hap_parse_decode_instructions(HapContext *ctx, int size)
|
|
|
|
{
|
|
|
|
GetByteContext *gbc = &ctx->gbc;
|
|
|
|
int section_size;
|
|
|
|
enum HapSectionType section_type;
|
|
|
|
int is_first_table = 1, had_offsets = 0, had_compressors = 0, had_sizes = 0;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
while (size > 0) {
|
|
|
|
int stream_remaining = bytestream2_get_bytes_left(gbc);
|
2018-03-11 20:15:56 +02:00
|
|
|
ret = ff_hap_parse_section_header(gbc, §ion_size, §ion_type);
|
2015-07-21 02:12:12 +02:00
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
size -= stream_remaining - bytestream2_get_bytes_left(gbc);
|
|
|
|
|
|
|
|
switch (section_type) {
|
|
|
|
case HAP_ST_COMPRESSOR_TABLE:
|
|
|
|
ret = ff_hap_set_chunk_count(ctx, section_size, is_first_table);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
for (i = 0; i < section_size; i++) {
|
|
|
|
ctx->chunks[i].compressor = bytestream2_get_byte(gbc) << 4;
|
|
|
|
}
|
|
|
|
had_compressors = 1;
|
|
|
|
is_first_table = 0;
|
|
|
|
break;
|
|
|
|
case HAP_ST_SIZE_TABLE:
|
|
|
|
ret = ff_hap_set_chunk_count(ctx, section_size / 4, is_first_table);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
for (i = 0; i < section_size / 4; i++) {
|
|
|
|
ctx->chunks[i].compressed_size = bytestream2_get_le32(gbc);
|
|
|
|
}
|
|
|
|
had_sizes = 1;
|
|
|
|
is_first_table = 0;
|
|
|
|
break;
|
|
|
|
case HAP_ST_OFFSET_TABLE:
|
|
|
|
ret = ff_hap_set_chunk_count(ctx, section_size / 4, is_first_table);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
for (i = 0; i < section_size / 4; i++) {
|
|
|
|
ctx->chunks[i].compressed_offset = bytestream2_get_le32(gbc);
|
|
|
|
}
|
|
|
|
had_offsets = 1;
|
|
|
|
is_first_table = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
size -= section_size;
|
2015-04-26 00:58:57 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 02:12:12 +02:00
|
|
|
if (!had_sizes || !had_compressors)
|
2015-04-26 00:58:57 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2015-07-21 02:12:12 +02:00
|
|
|
/* The offsets table is optional. If not present than calculate offsets by
|
|
|
|
* summing the sizes of preceding chunks. */
|
|
|
|
if (!had_offsets) {
|
|
|
|
size_t running_size = 0;
|
|
|
|
for (i = 0; i < ctx->chunk_count; i++) {
|
|
|
|
ctx->chunks[i].compressed_offset = running_size;
|
2021-02-19 22:16:25 +02:00
|
|
|
if (ctx->chunks[i].compressed_size > UINT32_MAX - running_size)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2015-07-21 02:12:12 +02:00
|
|
|
running_size += ctx->chunks[i].compressed_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hap_can_use_tex_in_place(HapContext *ctx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
size_t running_offset = 0;
|
|
|
|
for (i = 0; i < ctx->chunk_count; i++) {
|
|
|
|
if (ctx->chunks[i].compressed_offset != running_offset
|
|
|
|
|| ctx->chunks[i].compressor != HAP_COMP_NONE)
|
|
|
|
return 0;
|
|
|
|
running_offset += ctx->chunks[i].compressed_size;
|
|
|
|
}
|
|
|
|
return 1;
|
2015-04-26 00:58:57 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 02:12:12 +02:00
|
|
|
static int hap_parse_frame_header(AVCodecContext *avctx)
|
2015-04-26 00:58:57 +02:00
|
|
|
{
|
|
|
|
HapContext *ctx = avctx->priv_data;
|
|
|
|
GetByteContext *gbc = &ctx->gbc;
|
2015-07-21 02:12:12 +02:00
|
|
|
int section_size;
|
|
|
|
enum HapSectionType section_type;
|
2015-04-26 00:58:57 +02:00
|
|
|
const char *compressorstr;
|
2015-07-21 02:12:12 +02:00
|
|
|
int i, ret;
|
|
|
|
|
2018-03-11 20:15:56 +02:00
|
|
|
ret = ff_hap_parse_section_header(gbc, &ctx->texture_section_size, §ion_type);
|
2015-07-21 02:12:12 +02:00
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2015-04-26 00:58:57 +02:00
|
|
|
|
2015-07-27 23:36:37 +02:00
|
|
|
if ((avctx->codec_tag == MKTAG('H','a','p','1') && (section_type & 0x0F) != HAP_FMT_RGBDXT1) ||
|
|
|
|
(avctx->codec_tag == MKTAG('H','a','p','5') && (section_type & 0x0F) != HAP_FMT_RGBADXT5) ||
|
2017-09-23 21:50:54 +02:00
|
|
|
(avctx->codec_tag == MKTAG('H','a','p','Y') && (section_type & 0x0F) != HAP_FMT_YCOCGDXT5) ||
|
2017-11-21 12:59:02 +02:00
|
|
|
(avctx->codec_tag == MKTAG('H','a','p','A') && (section_type & 0x0F) != HAP_FMT_RGTC1) ||
|
|
|
|
((avctx->codec_tag == MKTAG('H','a','p','M') && (section_type & 0x0F) != HAP_FMT_RGTC1) &&
|
|
|
|
(section_type & 0x0F) != HAP_FMT_YCOCGDXT5)) {
|
2015-04-26 00:58:57 +02:00
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
2015-07-27 23:36:37 +02:00
|
|
|
"Invalid texture format %#04x.\n", section_type & 0x0F);
|
2015-07-16 14:23:21 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2015-07-21 02:12:11 +02:00
|
|
|
}
|
2015-07-16 14:23:21 +02:00
|
|
|
|
2015-07-21 02:12:12 +02:00
|
|
|
switch (section_type & 0xF0) {
|
|
|
|
case HAP_COMP_NONE:
|
|
|
|
case HAP_COMP_SNAPPY:
|
|
|
|
ret = ff_hap_set_chunk_count(ctx, 1, 1);
|
|
|
|
if (ret == 0) {
|
|
|
|
ctx->chunks[0].compressor = section_type & 0xF0;
|
|
|
|
ctx->chunks[0].compressed_offset = 0;
|
2017-11-21 12:59:02 +02:00
|
|
|
ctx->chunks[0].compressed_size = ctx->texture_section_size;
|
2015-07-21 02:12:12 +02:00
|
|
|
}
|
|
|
|
if (ctx->chunks[0].compressor == HAP_COMP_NONE) {
|
|
|
|
compressorstr = "none";
|
|
|
|
} else {
|
|
|
|
compressorstr = "snappy";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HAP_COMP_COMPLEX:
|
2018-03-11 20:15:56 +02:00
|
|
|
ret = ff_hap_parse_section_header(gbc, §ion_size, §ion_type);
|
2015-07-21 02:12:12 +02:00
|
|
|
if (ret == 0 && section_type != HAP_ST_DECODE_INSTRUCTIONS)
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
if (ret == 0)
|
|
|
|
ret = hap_parse_decode_instructions(ctx, section_size);
|
|
|
|
compressorstr = "complex";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Check the frame is valid and read the uncompressed chunk sizes */
|
|
|
|
ctx->tex_size = 0;
|
|
|
|
for (i = 0; i < ctx->chunk_count; i++) {
|
|
|
|
HapChunk *chunk = &ctx->chunks[i];
|
|
|
|
|
|
|
|
/* Check the compressed buffer is valid */
|
2021-02-19 22:16:25 +02:00
|
|
|
if (chunk->compressed_offset + (uint64_t)chunk->compressed_size > bytestream2_get_bytes_left(gbc))
|
2015-07-21 02:12:12 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
/* Chunks are unpacked sequentially, ctx->tex_size is the uncompressed
|
|
|
|
* size thus far */
|
|
|
|
chunk->uncompressed_offset = ctx->tex_size;
|
|
|
|
|
|
|
|
/* Fill out uncompressed size */
|
|
|
|
if (chunk->compressor == HAP_COMP_SNAPPY) {
|
|
|
|
GetByteContext gbc_tmp;
|
|
|
|
int64_t uncompressed_size;
|
|
|
|
bytestream2_init(&gbc_tmp, gbc->buffer + chunk->compressed_offset,
|
|
|
|
chunk->compressed_size);
|
|
|
|
uncompressed_size = ff_snappy_peek_uncompressed_length(&gbc_tmp);
|
|
|
|
if (uncompressed_size < 0) {
|
|
|
|
return uncompressed_size;
|
|
|
|
}
|
|
|
|
chunk->uncompressed_size = uncompressed_size;
|
|
|
|
} else if (chunk->compressor == HAP_COMP_NONE) {
|
|
|
|
chunk->uncompressed_size = chunk->compressed_size;
|
|
|
|
} else {
|
|
|
|
return AVERROR_INVALIDDATA;
|
2015-07-16 14:23:22 +02:00
|
|
|
}
|
2015-07-21 02:12:12 +02:00
|
|
|
ctx->tex_size += chunk->uncompressed_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "%s compressor\n", compressorstr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int decompress_chunks_thread(AVCodecContext *avctx, void *arg,
|
|
|
|
int chunk_nb, int thread_nb)
|
|
|
|
{
|
|
|
|
HapContext *ctx = avctx->priv_data;
|
|
|
|
|
|
|
|
HapChunk *chunk = &ctx->chunks[chunk_nb];
|
|
|
|
GetByteContext gbc;
|
|
|
|
uint8_t *dst = ctx->tex_buf + chunk->uncompressed_offset;
|
|
|
|
|
|
|
|
bytestream2_init(&gbc, ctx->gbc.buffer + chunk->compressed_offset, chunk->compressed_size);
|
|
|
|
|
|
|
|
if (chunk->compressor == HAP_COMP_SNAPPY) {
|
|
|
|
int ret;
|
|
|
|
int64_t uncompressed_size = ctx->tex_size;
|
2015-07-23 20:39:29 +02:00
|
|
|
|
2015-04-26 00:58:57 +02:00
|
|
|
/* Uncompress the frame */
|
2015-07-21 02:12:12 +02:00
|
|
|
ret = ff_snappy_uncompress(&gbc, dst, &uncompressed_size);
|
2015-04-26 00:58:57 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Snappy uncompress error\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2015-07-21 02:12:12 +02:00
|
|
|
} else if (chunk->compressor == HAP_COMP_NONE) {
|
|
|
|
bytestream2_get_buffer(&gbc, dst, chunk->compressed_size);
|
2015-04-26 00:58:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-30 21:33:24 +02:00
|
|
|
static int hap_decode(AVCodecContext *avctx, AVFrame *frame,
|
2015-04-26 00:58:57 +02:00
|
|
|
int *got_frame, AVPacket *avpkt)
|
|
|
|
{
|
|
|
|
HapContext *ctx = avctx->priv_data;
|
2017-11-21 12:55:37 +02:00
|
|
|
int ret, i, t;
|
2017-11-21 12:59:02 +02:00
|
|
|
int section_size;
|
|
|
|
enum HapSectionType section_type;
|
2017-11-21 12:55:37 +02:00
|
|
|
int start_texture_section = 0;
|
2015-04-26 00:58:57 +02:00
|
|
|
|
|
|
|
bytestream2_init(&ctx->gbc, avpkt->data, avpkt->size);
|
|
|
|
|
2017-11-21 12:59:02 +02:00
|
|
|
/* check for multi texture header */
|
|
|
|
if (ctx->texture_count == 2) {
|
2018-03-11 20:15:56 +02:00
|
|
|
ret = ff_hap_parse_section_header(&ctx->gbc, §ion_size, §ion_type);
|
2017-11-21 12:59:02 +02:00
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
if ((section_type & 0x0F) != 0x0D) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid section type in 2 textures mode %#04x.\n", section_type);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
start_texture_section = 4;
|
|
|
|
}
|
|
|
|
|
2015-04-26 00:58:57 +02:00
|
|
|
/* Get the output frame ready to receive data */
|
2022-02-06 15:49:23 +02:00
|
|
|
ret = ff_thread_get_buffer(avctx, frame, 0);
|
2015-04-26 00:58:57 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-11-21 12:55:37 +02:00
|
|
|
|
|
|
|
for (t = 0; t < ctx->texture_count; t++) {
|
|
|
|
bytestream2_seek(&ctx->gbc, start_texture_section, SEEK_SET);
|
|
|
|
|
2017-11-21 12:55:56 +02:00
|
|
|
/* Check for section header */
|
|
|
|
ret = hap_parse_frame_header(avctx);
|
2015-07-21 02:12:12 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2020-03-28 21:36:00 +02:00
|
|
|
if (ctx->tex_size != (avctx->coded_width / TEXTURE_BLOCK_W)
|
|
|
|
*(avctx->coded_height / TEXTURE_BLOCK_H)
|
2022-03-19 22:01:41 +02:00
|
|
|
*ctx->dec[t].tex_ratio) {
|
2020-03-28 21:36:00 +02:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed size mismatches\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2017-11-21 12:59:02 +02:00
|
|
|
start_texture_section += ctx->texture_section_size + 4;
|
|
|
|
|
2017-11-21 12:55:56 +02:00
|
|
|
/* Unpack the DXT texture */
|
|
|
|
if (hap_can_use_tex_in_place(ctx)) {
|
2020-03-28 21:36:00 +02:00
|
|
|
int tex_size;
|
2017-11-21 12:55:56 +02:00
|
|
|
/* Only DXTC texture compression in a contiguous block */
|
2022-03-19 22:01:41 +02:00
|
|
|
ctx->dec[t].tex_data.in = ctx->gbc.buffer;
|
2017-11-21 12:59:02 +02:00
|
|
|
tex_size = FFMIN(ctx->texture_section_size, bytestream2_get_bytes_left(&ctx->gbc));
|
2020-03-28 21:36:00 +02:00
|
|
|
if (tex_size < (avctx->coded_width / TEXTURE_BLOCK_W)
|
|
|
|
*(avctx->coded_height / TEXTURE_BLOCK_H)
|
2022-03-19 22:01:41 +02:00
|
|
|
*ctx->dec[t].tex_ratio) {
|
2020-03-28 21:36:00 +02:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Insufficient data\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2017-11-21 12:55:56 +02:00
|
|
|
} else {
|
|
|
|
/* Perform the second-stage decompression */
|
|
|
|
ret = av_reallocp(&ctx->tex_buf, ctx->tex_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2015-07-21 02:12:12 +02:00
|
|
|
|
2017-11-21 12:55:56 +02:00
|
|
|
avctx->execute2(avctx, decompress_chunks_thread, NULL,
|
|
|
|
ctx->chunk_results, ctx->chunk_count);
|
2015-07-24 03:25:49 +02:00
|
|
|
|
2017-11-21 12:55:56 +02:00
|
|
|
for (i = 0; i < ctx->chunk_count; i++) {
|
|
|
|
if (ctx->chunk_results[i] < 0)
|
|
|
|
return ctx->chunk_results[i];
|
|
|
|
}
|
|
|
|
|
2022-03-19 22:01:41 +02:00
|
|
|
ctx->dec[t].tex_data.in = ctx->tex_buf;
|
2017-11-21 12:55:56 +02:00
|
|
|
}
|
2015-07-21 02:12:12 +02:00
|
|
|
|
2022-03-19 22:01:41 +02:00
|
|
|
ctx->dec[t].frame_data.out = frame->data[0];
|
|
|
|
ctx->dec[t].stride = frame->linesize[0];
|
2024-02-15 07:44:38 +02:00
|
|
|
ctx->dec[t].width = avctx->coded_width;
|
|
|
|
ctx->dec[t].height = avctx->coded_height;
|
2024-01-24 21:36:55 +02:00
|
|
|
ff_texturedsp_exec_decompress_threads(avctx, &ctx->dec[t]);
|
2017-11-21 12:55:37 +02:00
|
|
|
}
|
2015-04-26 00:58:57 +02:00
|
|
|
|
|
|
|
/* Frame is ready to be output */
|
2022-02-06 15:49:23 +02:00
|
|
|
frame->pict_type = AV_PICTURE_TYPE_I;
|
2023-04-12 18:58:54 +02:00
|
|
|
frame->flags |= AV_FRAME_FLAG_KEY;
|
2015-04-26 00:58:57 +02:00
|
|
|
*got_frame = 1;
|
|
|
|
|
|
|
|
return avpkt->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold int hap_init(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
HapContext *ctx = avctx->priv_data;
|
2024-01-24 19:55:26 +02:00
|
|
|
TextureDSPContext dxtc;
|
2015-07-21 02:12:10 +02:00
|
|
|
const char *texture_name;
|
2015-04-26 00:58:57 +02:00
|
|
|
int ret = av_image_check_size(avctx->width, avctx->height, 0, avctx);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid video size %dx%d.\n",
|
|
|
|
avctx->width, avctx->height);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Since codec is based on 4x4 blocks, size is aligned to 4 */
|
|
|
|
avctx->coded_width = FFALIGN(avctx->width, TEXTURE_BLOCK_W);
|
|
|
|
avctx->coded_height = FFALIGN(avctx->height, TEXTURE_BLOCK_H);
|
|
|
|
|
2024-01-24 19:55:26 +02:00
|
|
|
ff_texturedsp_init(&dxtc);
|
2015-04-26 00:58:57 +02:00
|
|
|
|
2017-11-21 12:55:37 +02:00
|
|
|
ctx->texture_count = 1;
|
2022-03-19 22:01:41 +02:00
|
|
|
ctx->dec[0].raw_ratio = 16;
|
|
|
|
ctx->dec[0].slice_count = av_clip(avctx->thread_count, 1,
|
|
|
|
avctx->coded_height / TEXTURE_BLOCK_H);
|
2017-11-21 12:55:37 +02:00
|
|
|
|
2015-07-16 14:23:21 +02:00
|
|
|
switch (avctx->codec_tag) {
|
|
|
|
case MKTAG('H','a','p','1'):
|
2015-07-21 02:12:10 +02:00
|
|
|
texture_name = "DXT1";
|
2022-03-19 22:01:41 +02:00
|
|
|
ctx->dec[0].tex_ratio = 8;
|
2024-01-24 19:55:26 +02:00
|
|
|
ctx->dec[0].tex_funct = dxtc.dxt1_block;
|
2015-10-24 13:09:58 +02:00
|
|
|
avctx->pix_fmt = AV_PIX_FMT_RGB0;
|
2015-07-16 14:23:21 +02:00
|
|
|
break;
|
|
|
|
case MKTAG('H','a','p','5'):
|
2015-07-21 02:12:10 +02:00
|
|
|
texture_name = "DXT5";
|
2022-03-19 22:01:41 +02:00
|
|
|
ctx->dec[0].tex_ratio = 16;
|
2024-01-24 19:55:26 +02:00
|
|
|
ctx->dec[0].tex_funct = dxtc.dxt5_block;
|
2015-10-24 13:09:58 +02:00
|
|
|
avctx->pix_fmt = AV_PIX_FMT_RGBA;
|
2015-07-16 14:23:21 +02:00
|
|
|
break;
|
|
|
|
case MKTAG('H','a','p','Y'):
|
2015-07-21 02:12:10 +02:00
|
|
|
texture_name = "DXT5-YCoCg-scaled";
|
2022-03-19 22:01:41 +02:00
|
|
|
ctx->dec[0].tex_ratio = 16;
|
2024-01-24 19:55:26 +02:00
|
|
|
ctx->dec[0].tex_funct = dxtc.dxt5ys_block;
|
2015-10-24 13:09:58 +02:00
|
|
|
avctx->pix_fmt = AV_PIX_FMT_RGB0;
|
2015-07-16 14:23:21 +02:00
|
|
|
break;
|
2017-09-23 21:50:54 +02:00
|
|
|
case MKTAG('H','a','p','A'):
|
|
|
|
texture_name = "RGTC1";
|
2022-03-19 22:01:41 +02:00
|
|
|
ctx->dec[0].tex_ratio = 8;
|
2024-01-24 19:55:26 +02:00
|
|
|
ctx->dec[0].tex_funct = dxtc.rgtc1u_gray_block;
|
2022-03-19 22:01:41 +02:00
|
|
|
ctx->dec[0].raw_ratio = 4;
|
2017-11-25 20:46:48 +02:00
|
|
|
avctx->pix_fmt = AV_PIX_FMT_GRAY8;
|
2017-09-23 21:50:54 +02:00
|
|
|
break;
|
|
|
|
case MKTAG('H','a','p','M'):
|
2017-11-21 12:59:02 +02:00
|
|
|
texture_name = "DXT5-YCoCg-scaled / RGTC1";
|
2022-03-19 22:01:41 +02:00
|
|
|
ctx->dec[0].tex_ratio = 16;
|
|
|
|
ctx->dec[1].tex_ratio = 8;
|
2024-01-24 19:55:26 +02:00
|
|
|
ctx->dec[0].tex_funct = dxtc.dxt5ys_block;
|
|
|
|
ctx->dec[1].tex_funct = dxtc.rgtc1u_alpha_block;
|
2022-03-19 22:01:41 +02:00
|
|
|
ctx->dec[1].raw_ratio = 16;
|
|
|
|
ctx->dec[1].slice_count = ctx->dec[0].slice_count;
|
2017-11-21 12:59:02 +02:00
|
|
|
avctx->pix_fmt = AV_PIX_FMT_RGBA;
|
|
|
|
ctx->texture_count = 2;
|
|
|
|
break;
|
2015-07-16 14:23:21 +02:00
|
|
|
default:
|
|
|
|
return AVERROR_DECODER_NOT_FOUND;
|
|
|
|
}
|
2015-07-21 02:12:10 +02:00
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "%s texture\n", texture_name);
|
|
|
|
|
2015-04-26 00:58:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold int hap_close(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
HapContext *ctx = avctx->priv_data;
|
|
|
|
|
2015-07-21 02:12:12 +02:00
|
|
|
ff_hap_free_context(ctx);
|
2015-04-26 00:58:57 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_hap_decoder = {
|
|
|
|
.p.name = "hap",
|
2022-08-29 13:38:02 +02:00
|
|
|
CODEC_LONG_NAME("Vidvox Hap"),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.p.id = AV_CODEC_ID_HAP,
|
2015-04-26 00:58:57 +02:00
|
|
|
.init = hap_init,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_DECODE_CB(hap_decode),
|
2015-04-26 00:58:57 +02:00
|
|
|
.close = hap_close,
|
|
|
|
.priv_data_size = sizeof(HapContext),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS |
|
2015-07-07 02:41:27 +02:00
|
|
|
AV_CODEC_CAP_DR1,
|
2022-07-10 00:05:45 +02:00
|
|
|
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
|
2019-12-29 22:24:01 +02:00
|
|
|
.codec_tags = (const uint32_t []){
|
|
|
|
MKTAG('H','a','p','1'),
|
|
|
|
MKTAG('H','a','p','5'),
|
|
|
|
MKTAG('H','a','p','Y'),
|
|
|
|
MKTAG('H','a','p','A'),
|
|
|
|
MKTAG('H','a','p','M'),
|
|
|
|
FF_CODEC_TAGS_END,
|
|
|
|
},
|
2015-04-26 00:58:57 +02:00
|
|
|
};
|