FFmpeg
Data Structures | Macros | Functions | Variables
vqavideo.c File Reference
#include <stdio.h>
#include <string.h>
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "decode.h"

Go to the source code of this file.

Data Structures

struct  VqaContext
 

Macros

#define PALETTE_COUNT   256
 
#define VQA_HEADER_SIZE   0x2A
 
#define MAX_CODEBOOK_VECTORS   0xFF00
 
#define SOLID_PIXEL_VECTORS   0x100
 
#define MAX_VECTORS   (MAX_CODEBOOK_VECTORS + SOLID_PIXEL_VECTORS)
 
#define MAX_CODEBOOK_SIZE   (MAX_VECTORS * 4 * 4 * sizeof(uint16_t))
 
#define CBF0_TAG   MKBETAG('C', 'B', 'F', '0')
 
#define CBFZ_TAG   MKBETAG('C', 'B', 'F', 'Z')
 
#define CBP0_TAG   MKBETAG('C', 'B', 'P', '0')
 
#define CBPZ_TAG   MKBETAG('C', 'B', 'P', 'Z')
 
#define CPL0_TAG   MKBETAG('C', 'P', 'L', '0')
 
#define CPLZ_TAG   MKBETAG('C', 'P', 'L', 'Z')
 
#define VPTZ_TAG   MKBETAG('V', 'P', 'T', 'Z')
 
#define VPTR_TAG   MKBETAG('V', 'P', 'T', 'R')
 
#define VPRZ_TAG   MKBETAG('V', 'P', 'R', 'Z')
 
#define CHECK_COUNT()
 
#define CHECK_COPY(idx)
 

Functions

static av_cold int vqa_decode_init (AVCodecContext *avctx)
 
static int decode_format80 (VqaContext *s, int src_size, unsigned char *dest, int dest_size, int check_size)
 
static int vqa_decode_frame_pal8 (VqaContext *s, AVFrame *frame)
 
static int vqa_decode_frame_hicolor (VqaContext *s, AVFrame *frame)
 
static int vqa_decode_frame (AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
 
static av_cold int vqa_decode_end (AVCodecContext *avctx)
 

Variables

static const FFCodecDefault vqa_defaults []
 
const FFCodec ff_vqa_decoder
 

Detailed Description

VQA Video Decoder

Author
Mike Melanson (melan.nosp@m.son@.nosp@m.pcisy.nosp@m.s.ne.nosp@m.t)
See also
http://wiki.multimedia.cx/index.php?title=VQA

The VQA video decoder outputs PAL8 or RGB555 colorspace data, depending on the type of data in the file.

This decoder needs the 42-byte VQHD header from the beginning of the VQA file passed through the extradata field. The VQHD header is laid out as:

bytes 0-3 chunk fourcc: 'VQHD' bytes 4-7 chunk size in big-endian format, should be 0x0000002A bytes 8-49 VQHD chunk data

Bytes 8-49 are what this decoder expects to see.

Briefly, VQA is a vector quantized animation format that operates in a VGA palettized colorspace. It operates on pixel vectors (blocks) of either 4x2 or 4x4 in size. Compressed VQA chunks can contain vector codebooks, palette information, and code maps for rendering vectors onto frames. Any of these components can also be compressed with a run-length encoding (RLE) algorithm commonly referred to as "format80".

VQA takes a novel approach to rate control. Each group of n frames (usually, n = 8) relies on a different vector codebook. Rather than transporting an entire codebook every 8th frame, the new codebook is broken up into 8 pieces and sent along with the compressed video chunks for each of the 8 frames preceding the 8 frames which require the codebook. A full codebook is also sent on the very first frame of a file. This is an interesting technique, although it makes random file seeking difficult despite the fact that the frames are all intracoded.

V1,2 VQA uses 12-bit codebook indexes. If the 12-bit indexes were packed into bytes and then RLE compressed, bytewise, the results would be poor. That is why the coding method divides each index into 2 parts, the top 4 bits and the bottom 8 bits, then RL encodes the 4-bit pieces together and the 8-bit pieces together. If most of the vectors are clustered into one group of 256 vectors, most of the 4-bit index pieces should be the same.

VQA3 introduces a 15-bit high color codebook, delta coding, replaces the above "split byte" scheme with RLE compression, and extends the "format80" compression with relative references. In VQA3 the whole codebook is always updated as a whole without splitting it into pieces.

Definition in file vqavideo.c.

Macro Definition Documentation

◆ PALETTE_COUNT

#define PALETTE_COUNT   256

Definition at line 82 of file vqavideo.c.

◆ VQA_HEADER_SIZE

#define VQA_HEADER_SIZE   0x2A

Definition at line 83 of file vqavideo.c.

◆ MAX_CODEBOOK_VECTORS

#define MAX_CODEBOOK_VECTORS   0xFF00

Definition at line 87 of file vqavideo.c.

◆ SOLID_PIXEL_VECTORS

#define SOLID_PIXEL_VECTORS   0x100

Definition at line 88 of file vqavideo.c.

◆ MAX_VECTORS

#define MAX_VECTORS   (MAX_CODEBOOK_VECTORS + SOLID_PIXEL_VECTORS)

Definition at line 89 of file vqavideo.c.

◆ MAX_CODEBOOK_SIZE

#define MAX_CODEBOOK_SIZE   (MAX_VECTORS * 4 * 4 * sizeof(uint16_t))

Definition at line 90 of file vqavideo.c.

◆ CBF0_TAG

#define CBF0_TAG   MKBETAG('C', 'B', 'F', '0')

Definition at line 92 of file vqavideo.c.

◆ CBFZ_TAG

#define CBFZ_TAG   MKBETAG('C', 'B', 'F', 'Z')

Definition at line 93 of file vqavideo.c.

◆ CBP0_TAG

#define CBP0_TAG   MKBETAG('C', 'B', 'P', '0')

Definition at line 94 of file vqavideo.c.

◆ CBPZ_TAG

#define CBPZ_TAG   MKBETAG('C', 'B', 'P', 'Z')

Definition at line 95 of file vqavideo.c.

◆ CPL0_TAG

#define CPL0_TAG   MKBETAG('C', 'P', 'L', '0')

Definition at line 96 of file vqavideo.c.

◆ CPLZ_TAG

#define CPLZ_TAG   MKBETAG('C', 'P', 'L', 'Z')

Definition at line 97 of file vqavideo.c.

◆ VPTZ_TAG

#define VPTZ_TAG   MKBETAG('V', 'P', 'T', 'Z')

Definition at line 98 of file vqavideo.c.

◆ VPTR_TAG

#define VPTR_TAG   MKBETAG('V', 'P', 'T', 'R')

Definition at line 99 of file vqavideo.c.

◆ VPRZ_TAG

#define VPRZ_TAG   MKBETAG('V', 'P', 'R', 'Z')

Definition at line 100 of file vqavideo.c.

◆ CHECK_COUNT

#define CHECK_COUNT ( )
Value:
if (dest_index + count > dest_size) { \
av_log(s->avctx, AV_LOG_ERROR, "decode_format80 problem: next op would overflow dest_index\n"); \
av_log(s->avctx, AV_LOG_ERROR, "current dest_index = %d, count = %d, dest_size = %d\n", \
dest_index, count, dest_size); \
}

Definition at line 217 of file vqavideo.c.

◆ CHECK_COPY

#define CHECK_COPY (   idx)
Value:
if (idx < 0 || idx + count > dest_size) { \
av_log(s->avctx, AV_LOG_ERROR, "decode_format80 problem: next op would overflow dest_index\n"); \
av_log(s->avctx, AV_LOG_ERROR, "current src_pos = %d, count = %d, dest_size = %d\n", \
src_pos, count, dest_size); \
}

Definition at line 225 of file vqavideo.c.

Function Documentation

◆ vqa_decode_init()

static av_cold int vqa_decode_init ( AVCodecContext avctx)
static

Definition at line 128 of file vqavideo.c.

◆ decode_format80()

static int decode_format80 ( VqaContext s,
int  src_size,
unsigned char *  dest,
int  dest_size,
int  check_size 
)
static

Definition at line 234 of file vqavideo.c.

Referenced by vqa_decode_frame_hicolor(), and vqa_decode_frame_pal8().

◆ vqa_decode_frame_pal8()

static int vqa_decode_frame_pal8 ( VqaContext s,
AVFrame frame 
)
static

Definition at line 342 of file vqavideo.c.

Referenced by vqa_decode_frame().

◆ vqa_decode_frame_hicolor()

static int vqa_decode_frame_hicolor ( VqaContext s,
AVFrame frame 
)
static

Definition at line 625 of file vqavideo.c.

Referenced by vqa_decode_frame().

◆ vqa_decode_frame()

static int vqa_decode_frame ( AVCodecContext avctx,
AVFrame rframe,
int *  got_frame,
AVPacket avpkt 
)
static

Definition at line 796 of file vqavideo.c.

◆ vqa_decode_end()

static av_cold int vqa_decode_end ( AVCodecContext avctx)
static

Definition at line 835 of file vqavideo.c.

Variable Documentation

◆ vqa_defaults

const FFCodecDefault vqa_defaults[]
static
Initial value:
= {
{ "max_pixels", "640*480" },
{ NULL },
}

Definition at line 847 of file vqavideo.c.

◆ ff_vqa_decoder

const FFCodec ff_vqa_decoder
Initial value:
= {
.p.name = "vqavideo",
CODEC_LONG_NAME("Westwood Studios VQA (Vector Quantized Animation) video"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(VqaContext),
.close = vqa_decode_end,
.p.capabilities = AV_CODEC_CAP_DR1,
.defaults = vqa_defaults,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 852 of file vqavideo.c.

FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:43
VqaContext
Definition: vqavideo.c:102
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:311
s
#define s(width, name)
Definition: cbs_vp9.c:198
vqa_decode_init
static av_cold int vqa_decode_init(AVCodecContext *avctx)
Definition: vqavideo.c:128
AV_CODEC_ID_WS_VQA
@ AV_CODEC_ID_WS_VQA
Definition: codec_id.h:96
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
NULL
#define NULL
Definition: coverity.c:32
vqa_defaults
static const FFCodecDefault vqa_defaults[]
Definition: vqavideo.c:847
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
vqa_decode_frame
static int vqa_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
Definition: vqavideo.c:796
vqa_decode_end
static av_cold int vqa_decode_end(AVCodecContext *avctx)
Definition: vqavideo.c:835
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61