27 #define BITSTREAM_READER_LE 42 #define MAX_INDEX (64 - 1) 48 #define ALPHA_VLC_BITS 5 64 {0x0001, 2}, {0x0003, 3}, {0x000E, 4}, {0x0007, 5},
65 {0x0017, 5}, {0x0028, 6}, {0x0008, 6}, {0x006F, 7},
66 {0x001F, 7}, {0x00C4, 8}, {0x0044, 8}, {0x005F, 8},
67 {0x00DF, 8}, {0x007F, 8}, {0x00FF, 8}, {0x3E00, 14},
68 {0x1E00, 14}, {0x2E00, 14}, {0x0E00, 14}, {0x3600, 14},
69 {0x1600, 14}, {0x2600, 14}, {0x0600, 14}, {0x3A00, 14},
70 {0x1A00, 14}, {0x2A00, 14}, {0x0A00, 14}, {0x3200, 14},
71 {0x1200, 14}, {0x2200, 14}, {0x0200, 14}, {0x0C00, 15},
72 {0x7400, 15}, {0x3400, 15}, {0x5400, 15}, {0x1400, 15},
73 {0x6400, 15}, {0x2400, 15}, {0x4400, 15}, {0x0400, 15},
74 {0x0002, 3}, {0x000C, 5}, {0x004F, 7}, {0x00E4, 8},
75 {0x0004, 8}, {0x0D00, 13}, {0x1500, 13}, {0x7C00, 15},
76 {0x3C00, 15}, {0x5C00, 15}, {0x1C00, 15}, {0x6C00, 15},
77 {0x2C00, 15}, {0x4C00, 15}, {0xC800, 16}, {0x4800, 16},
78 {0x8800, 16}, {0x0800, 16}, {0x0300, 13}, {0x1D00, 13},
79 {0x0014, 5}, {0x0070, 7}, {0x003F, 8}, {0x00C0, 10},
80 {0x0500, 13}, {0x0180, 12}, {0x0280, 12}, {0x0C80, 12},
81 {0x0080, 12}, {0x0B00, 13}, {0x1300, 13}, {0x001C, 5},
82 {0x0064, 8}, {0x0380, 12}, {0x1900, 13}, {0x0D80, 12},
83 {0x0018, 6}, {0x00BF, 8}, {0x0480, 12}, {0x0B80, 12},
84 {0x0038, 6}, {0x0040, 9}, {0x0900, 13}, {0x0030, 7},
85 {0x0780, 12}, {0x2800, 16}, {0x0010, 7}, {0x0A80, 12},
86 {0x0050, 7}, {0x0880, 12}, {0x000F, 7}, {0x1100, 13},
87 {0x002F, 7}, {0x0100, 13}, {0x0084, 8}, {0x5800, 16},
88 {0x00A4, 8}, {0x9800, 16}, {0x0024, 8}, {0x1800, 16},
89 {0x0140, 9}, {0xE800, 16}, {0x01C0, 9}, {0x6800, 16},
90 {0x02C0, 10}, {0xA800, 16}, {0x0F80, 12}, {0x0580, 12},
91 {0x0980, 12}, {0x0E80, 12}, {0x0680, 12}, {0x1F00, 13},
92 {0x0F00, 13}, {0x1700, 13}, {0x0700, 13}, {0x1B00, 13},
93 {0xF800, 16}, {0x7800, 16}, {0xB800, 16}, {0x3800, 16},
100 1, 2, 3, 4, 5, 6, 7, 8,
101 9, 10, 11, 12, 13, 14, 15, 16,
102 17, 18, 19, 20, 21, 22, 23, 24,
103 25, 26, 27, 28, 29, 30, 31, 32,
104 33, 34, 35, 36, 37, 38, 39, 40,
105 1, 2, 3, 4, 5, 6, 7, 8,
106 9, 10, 11, 12, 13, 14, 15, 16,
107 17, 18, 19, 20, 1, 2, 3, 4,
108 5, 6, 7, 8, 9, 10, 11, 1,
109 2, 3, 4, 5, 1, 2, 3, 4,
110 1, 2, 3, 1, 2, 3, 1, 2,
111 1, 2, 1, 2, 1, 2, 1, 2,
112 1, 2, 1, 2, 1, 2, 1, 2,
113 1, 2, 1, 1, 1, 1, 1, 1,
114 1, 1, 1, 1, 1, 1, 1, 1,
119 0, 0, 0, 0, 0, 0, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 0,
121 0, 0, 0, 0, 0, 0, 0, 0,
122 0, 0, 0, 0, 0, 0, 0, 0,
123 0, 0, 0, 0, 0, 0, 0, 0,
124 1, 1, 1, 1, 1, 1, 1, 1,
125 1, 1, 1, 1, 1, 1, 1, 1,
126 1, 1, 1, 1, 2, 2, 2, 2,
127 2, 2, 2, 2, 2, 2, 2, 3,
128 3, 3, 3, 3, 4, 4, 4, 4,
129 5, 5, 5, 6, 6, 6, 7, 7,
130 8, 8, 9, 9, 10, 10, 11, 11,
131 12, 12, 13, 13, 14, 14, 15, 15,
132 16, 16, 17, 18, 19, 20, 21, 22,
133 23, 24, 25, 26, 27, 28, 29, 30,
145 #if CONFIG_SPEEDHQ_DECODER 147 static const uint8_t unscaled_quant_matrix[64] = {
148 16, 16, 19, 22, 26, 27, 29, 34,
149 16, 16, 22, 24, 27, 29, 34, 37,
150 19, 22, 26, 27, 29, 34, 34, 38,
151 22, 22, 26, 27, 29, 34, 37, 40,
152 22, 26, 27, 29, 32, 35, 40, 48,
153 26, 27, 29, 32, 35, 40, 48, 58,
154 26, 27, 29, 34, 38, 46, 56, 69,
155 27, 29, 35, 38, 46, 56, 69, 83
160 static VLC dc_lum_vlc_le;
161 static VLC dc_chroma_vlc_le;
162 static VLC dc_alpha_run_vlc_le;
163 static VLC dc_alpha_level_vlc_le;
165 static inline int decode_dc_le(
GetBitContext *gb,
int component)
169 if (component == 0 || component == 3) {
187 memset(block, 0,
sizeof(block));
211 for (y = 0; y < 8; y++) {
212 for (x = 0; x < 16; x++) {
213 last_alpha[x] -= block[y * 16 + x];
215 memcpy(dest, last_alpha, 16);
231 dc_offset = decode_dc_le(gb, component);
232 last_dc[component] -= dc_offset;
233 block[scantable[0]] = last_dc[component];
256 #if MIN_CACHE_BITS < 6 + 6 + 12 257 #error MIN_CACHE_BITS is too small for the escape code, add UPDATE_CACHE 269 block[scantable[
i]] = (level * quant_matrix[
i]) >> 4;
279 static int decode_speedhq_field(
const SHQContext *s,
const uint8_t *buf,
int buf_size,
AVFrame *
frame,
int field_number,
int start,
int end,
int line_stride)
281 int ret, slice_number, slice_offsets[5];
282 int linesize_y = frame->
linesize[0] * line_stride;
283 int linesize_cb = frame->
linesize[1] * line_stride;
284 int linesize_cr = frame->
linesize[2] * line_stride;
288 linesize_a = frame->
linesize[3] * line_stride;
290 if (
end < start ||
end - start < 3 || end > buf_size)
293 slice_offsets[0] = start;
294 slice_offsets[4] =
end;
295 for (slice_number = 1; slice_number < 4; slice_number++) {
296 uint32_t last_offset, slice_len;
298 last_offset = slice_offsets[slice_number - 1];
299 slice_len =
AV_RL24(buf + last_offset);
300 slice_offsets[slice_number] = last_offset + slice_len;
302 if (slice_len < 3 || slice_offsets[slice_number] >
end - 3)
306 for (slice_number = 0; slice_number < 4; slice_number++) {
311 slice_begin = slice_offsets[slice_number];
312 slice_end = slice_offsets[slice_number + 1];
314 if ((ret =
init_get_bits8(&gb, buf + slice_begin + 3, slice_end - slice_begin - 3)) < 0)
317 for (y = slice_number * 16 * line_stride; y < frame->
height; y += line_stride * 64) {
318 uint8_t *dest_y, *dest_cb, *dest_cr, *dest_a;
319 int last_dc[4] = { 1024, 1024, 1024, 1024 };
322 memset(last_alpha, 255,
sizeof(last_alpha));
324 dest_y = frame->
data[0] + frame->
linesize[0] * (y + field_number);
326 dest_cb = frame->
data[1] + frame->
linesize[1] * (y/2 + field_number);
327 dest_cr = frame->
data[2] + frame->
linesize[2] * (y/2 + field_number);
329 dest_cb = frame->
data[1] + frame->
linesize[1] * (y + field_number);
330 dest_cr = frame->
data[2] + frame->
linesize[2] * (y + field_number);
333 dest_a = frame->
data[3] + frame->
linesize[3] * (y + field_number);
336 for (x = 0; x < frame->
width; x += 16) {
340 if ((ret =
decode_dct_block(s, &gb, last_dc, 0, dest_y + 8, linesize_y)) < 0)
342 if ((ret =
decode_dct_block(s, &gb, last_dc, 0, dest_y + 8 * linesize_y, linesize_y)) < 0)
344 if ((ret =
decode_dct_block(s, &gb, last_dc, 0, dest_y + 8 * linesize_y + 8, linesize_y)) < 0)
358 if ((ret =
decode_dct_block(s, &gb, last_dc, 1, dest_cb + 8 * linesize_cb, linesize_cb)) < 0)
360 if ((ret =
decode_dct_block(s, &gb, last_dc, 2, dest_cr + 8 * linesize_cr, linesize_cr)) < 0)
365 if ((ret =
decode_dct_block(s, &gb, last_dc, 1, dest_cb + 8, linesize_cb)) < 0)
367 if ((ret =
decode_dct_block(s, &gb, last_dc, 2, dest_cr + 8, linesize_cr)) < 0)
369 if ((ret =
decode_dct_block(s, &gb, last_dc, 1, dest_cb + 8 * linesize_cb + 8, linesize_cb)) < 0)
371 if ((ret =
decode_dct_block(s, &gb, last_dc, 2, dest_cr + 8 * linesize_cr + 8, linesize_cr)) < 0)
384 if ((ret = decode_alpha_block(s, &gb, last_alpha, dest_a, linesize_a)) < 0)
386 if ((ret = decode_alpha_block(s, &gb, last_alpha, dest_a + 8 * linesize_a, linesize_a)) < 0)
393 if ((ret =
decode_dct_block(s, &gb, last_dc, 3, dest_a + 8, linesize_a)) < 0)
395 if ((ret =
decode_dct_block(s, &gb, last_dc, 3, dest_a + 8 * linesize_a, linesize_a)) < 0)
397 if ((ret =
decode_dct_block(s, &gb, last_dc, 3, dest_a + 8 * linesize_a + 8, linesize_a)) < 0)
415 void *
data,
int *got_frame,
420 int buf_size = avpkt->
size;
423 uint32_t second_field_offset;
430 if (quality >= 100) {
436 second_field_offset =
AV_RL24(buf + 1);
437 if (second_field_offset >= buf_size - 3) {
449 if (second_field_offset == 4 || second_field_offset == (buf_size-4)) {
459 if ((ret = decode_speedhq_field(s, buf, buf_size, frame, 0, 4, buf_size, 1)) < 0)
462 if ((ret = decode_speedhq_field(s, buf, buf_size, frame, 0, 4, second_field_offset, 2)) < 0)
464 if ((ret = decode_speedhq_field(s, buf, buf_size, frame, 1, second_field_offset, buf_size, 2)) < 0)
477 static av_cold void compute_alpha_vlcs(
void)
479 uint16_t run_code[134], level_code[266];
481 int16_t run_symbols[134], level_symbols[266];
490 run_symbols[entry] = 0;
494 for (i = 0; i < 4; ++
i) {
495 run_code[entry] = (i << 2) | 1;
497 run_symbols[entry] = i + 1;
502 for (i = 0; i < 128; ++
i) {
503 run_code[entry] = (i << 3) | 7;
504 run_bits[entry] = 10;
505 run_symbols[entry] =
i;
512 run_symbols[entry] = -1;
521 run_symbols, 2, 2, 160);
526 for (sign = 0; sign <= 1; ++sign) {
528 level_code[entry] = (sign << 1) | 1;
529 level_bits[entry] = 2;
530 level_symbols[entry] = sign ? -1 : 1;
534 for (i = 0; i < 4; ++
i) {
535 level_code[entry] = (i << 3) | (sign << 2) | 2;
536 level_bits[entry] = 5;
537 level_symbols[entry] = sign ? -(i + 2) : (i + 2);
548 for (i = 0; i < 256; ++
i) {
549 level_code[entry] = i << 2;
550 level_bits[entry] = 10;
551 level_symbols[entry] =
i;
561 level_symbols, 2, 2, 288);
564 static av_cold void speedhq_static_init(
void)
579 compute_alpha_vlcs();
599 case MKTAG(
'S',
'H',
'Q',
'0'):
604 case MKTAG(
'S',
'H',
'Q',
'1'):
609 case MKTAG(
'S',
'H',
'Q',
'2'):
614 case MKTAG(
'S',
'H',
'Q',
'3'):
619 case MKTAG(
'S',
'H',
'Q',
'4'):
624 case MKTAG(
'S',
'H',
'Q',
'5'):
629 case MKTAG(
'S',
'H',
'Q',
'7'):
634 case MKTAG(
'S',
'H',
'Q',
'9'):
658 .
init = speedhq_decode_init,
659 .
decode = speedhq_decode_frame,
static int get_xbits_le(GetBitContext *s, int n)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
int coded_width
Bitstream width / height, may be different from width/height e.g.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static av_cold int init(AVCodecContext *avctx)
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
void(* clear_block)(int16_t *block)
const unsigned char ff_mpeg12_vlc_dc_lum_bits[12]
av_cold void ff_blockdsp_init(BlockDSPContext *c, AVCodecContext *avctx)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define INIT_LE_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g, h, i, j, static_size)
const uint16_t ff_mpeg12_vlc_dc_lum_code[12]
AVCodec ff_speedhq_decoder
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Macro definitions for various function/variable attributes.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
The exact code depends on how similar the blocks are and how related they are to the block
#define INIT_2D_VLC_RL(rl, static_size, flags)
static av_cold int end(AVCodecContext *avctx)
#define LOCAL_ALIGNED_32(t, v,...)
enum SHQContext::@138 subsampling
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
static const uint8_t run_bits[7][16]
bitstream reader API header.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
static const uint16_t speedhq_vlc[123][2]
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const uint16_t ff_mpeg12_vlc_dc_chroma_code[12]
static const uint8_t speedhq_run[121]
const char * name
Name of the codec implementation.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
#define CLOSE_READER(name, gb)
#define GET_RL_VLC(level, run, name, gb, table, bits,max_depth, need_update)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define SKIP_BITS(name, gb, num)
int width
picture width / height.
static void decode_dct_block(RangeCoder *c, DCTBlockCoder *bc, uint8_t *dst, ptrdiff_t stride, int block_size, int *block, int mb_x, int mb_y)
const unsigned char ff_mpeg12_vlc_dc_chroma_bits[12]
static uint8_t speedhq_static_rl_table_store[2][2 *MAX_RUN+MAX_LEVEL+3]
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define LAST_SKIP_BITS(name, gb, num)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define GET_VLC(code, name, gb, table, bits, max_depth)
If the vlc code is invalid and max_depth=1, then no bits will be removed.
uint8_t idct_permutation[64]
IDCT input permutation.
void(* idct_put)(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
block -> idct -> clip to unsigned 8 bit -> dest.
RL_VLC_ELEM * rl_vlc[32]
decoding only
av_cold void ff_rl_init(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
#define SHOW_UBITS(name, gb, num)
#define FF_ARRAY_ELEMS(a)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
main external API structure.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
static const uint8_t speedhq_level[121]
#define OPEN_READER(name, gb)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
enum AVColorSpace colorspace
YUV colorspace type.
#define UPDATE_CACHE_LE(name, gb)
const uint8_t ff_zigzag_direct[64]
static void compute_quant_matrix(AGMContext *s, double qscale)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define INIT_CUSTOM_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, flags, static_size)
#define SHOW_SBITS(name, gb, num)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
ScanTable intra_scantable
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
static av_always_inline int diff(const uint32_t a, const uint32_t b)
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
enum SHQContext::@139 alpha_type
static int ff_thread_once(char *control, void(*routine)(void))
VLC_TYPE(* table)[2]
code, bits
int key_frame
1 -> keyframe, 0-> not
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
#define MKTAG(a, b, c, d)
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define INIT_VLC_OUTPUT_LE