83 #define FULLPEL_MODE 1
84 #define HALFPEL_MODE 2
85 #define THIRDPEL_MODE 3
86 #define PREDICT_MODE 4
98 0 + 0 * 4, 1 + 0 * 4, 2 + 0 * 4, 2 + 1 * 4,
99 2 + 2 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4,
100 0 + 1 * 4, 0 + 2 * 4, 1 + 1 * 4, 1 + 2 * 4,
101 0 + 3 * 4, 1 + 3 * 4, 2 + 3 * 4, 3 + 3 * 4,
107 { 0, 2 }, { 1, 1 }, { 2, 0 },
108 { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
109 { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
110 { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
111 { 2, 4 }, { 3, 3 }, { 4, 2 },
117 { { 2, -1, -1, -1, -1 }, { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 },
118 { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 }, { 1, 2, -1, -1, -1 } },
119 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
120 { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
121 { { 2, 0, -1, -1, -1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
122 { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
123 { { 2, 0, -1, -1, -1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
124 { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
125 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
126 { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
127 { { 0, 2, -1, -1, -1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
128 { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
131 static const struct {
135 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
136 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
137 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
138 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
142 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
143 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
144 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
145 61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533
156 for (i = 0; i < 4; i++) {
157 const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]);
158 const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]);
159 const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3];
160 const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3];
162 temp[4 * i + 0] = z0 + z3;
163 temp[4 * i + 1] = z1 + z2;
164 temp[4 * i + 2] = z1 - z2;
165 temp[4 * i + 3] = z0 - z3;
168 for (i = 0; i < 4; i++) {
169 const int offset = x_offset[i];
170 const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]);
171 const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]);
172 const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];
173 const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];
175 output[
stride * 0 + offset] = (z0 + z3) * qmul + 0x80000 >> 20;
176 output[
stride * 2 + offset] = (z1 + z2) * qmul + 0x80000 >> 20;
177 output[
stride * 8 + offset] = (z1 - z2) * qmul + 0x80000 >> 20;
178 output[
stride * 10 + offset] = (z0 - z3) * qmul + 0x80000 >> 20;
184 int stride,
int qp,
int dc)
190 dc = 13 * 13 * (dc == 1 ? 1538 * block[0]
191 : qmul * (block[0] >> 3) / 2);
195 for (i = 0; i < 4; i++) {
196 const int z0 = 13 * (block[0 + 4 * i] + block[2 + 4 * i]);
197 const int z1 = 13 * (block[0 + 4 * i] - block[2 + 4 * i]);
198 const int z2 = 7 * block[1 + 4 * i] - 17 * block[3 + 4 * i];
199 const int z3 = 17 * block[1 + 4 * i] + 7 * block[3 + 4 * i];
201 block[0 + 4 * i] = z0 + z3;
202 block[1 + 4 * i] = z1 + z2;
203 block[2 + 4 * i] = z1 - z2;
204 block[3 + 4 * i] = z0 - z3;
207 for (i = 0; i < 4; i++) {
208 const int z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);
209 const int z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);
210 const int z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];
211 const int z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];
212 const int rr = (dc + 0x80000);
214 dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((z0 + z3) * qmul + rr >> 20));
215 dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((z1 + z2) * qmul + rr >> 20));
216 dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((z1 - z2) * qmul + rr >> 20));
217 dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((z0 - z3) * qmul + rr >> 20));
222 int index,
const int type)
224 static const uint8_t *
const scan_patterns[4] =
229 const int intra = 3 * type >> 2;
230 const uint8_t *
const scan = scan_patterns[type];
232 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
234 int sign = (vlc & 1) ? 0 : -1;
241 }
else if (vlc < 4) {
246 level = (vlc + 9 >> 2) - run;
255 ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
259 ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
263 if ((index += run) >= limit)
266 block[scan[
index]] = (level ^ sign) - sign;
279 int mx,
int my,
int dxy,
280 int thirdpel,
int dir,
int avg)
286 int blocksize = 2 - (width >> 3);
291 if (mx < 0 || mx >= s->
h_edge_pos - width - 1 ||
296 mx = av_clip(mx, -16, s->
h_edge_pos - width + 15);
297 my = av_clip(my, -16, s->
v_edge_pos - height + 15);
306 width + 1, height + 1,
320 mx = mx + (mx < (int) x) >> 1;
321 my = my + (my < (int) y) >> 1;
323 height = height >> 1;
326 for (i = 1; i < 3; i++) {
332 width + 1, height + 1,
354 int i, j, k, mx, my, dx, dy, x, y;
356 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
357 const int part_height = 16 >> ((unsigned)(size + 1) / 3);
358 const int extra_width = (mode ==
PREDICT_MODE) ? -16 * 6 : 0;
359 const int h_edge_pos = 6 * (s->
h_edge_pos - part_width) - extra_width;
360 const int v_edge_pos = 6 * (s->
v_edge_pos - part_height) - extra_width;
362 for (i = 0; i < 16; i += part_height)
363 for (j = 0; j < 16; j += part_width) {
364 const int b_xy = (4 * h->
mb_x + (j >> 2)) +
367 x = 16 * h->
mb_x + j;
368 y = 16 * h->
mb_y + i;
369 k = (j >> 2 & 1) + (i >> 1 & 2) +
370 (j >> 1 & 4) + (i & 8);
373 pred_motion(h, k, part_width >> 2, dir, 1, &mx, &my);
392 mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);
393 my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);
411 mx = (mx + 1 >> 1) + dx;
412 my = (my + 1 >> 1) + dy;
413 fx = (unsigned)(mx + 0x3000) / 3 - 0x1000;
414 fy = (unsigned)(my + 0x3000) / 3 - 0x1000;
415 dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);
418 fx, fy, dxy, 1, dir, avg);
422 mx = (unsigned)(mx + 1 + 0x3000) / 3 + dx - 0x1000;
423 my = (unsigned)(my + 1 + 0x3000) / 3 + dy - 0x1000;
424 dxy = (mx & 1) + 2 * (my & 1);
427 mx >> 1, my >> 1, dxy, 0, dir, avg);
431 mx = (unsigned)(mx + 3 + 0x6000) / 6 + dx - 0x1000;
432 my = (unsigned)(my + 3 + 0x6000) / 6 + dy - 0x1000;
435 mx, my, 0, 0, dir, avg);
444 if (part_height == 8 && i < 8) {
447 if (part_width == 8 && j < 8)
450 if (part_width == 8 && j < 8)
452 if (part_width == 4 || part_height == 4)
458 part_width >> 2, part_height >> 2, h->
b_stride,
468 int i, j, k, m, dir, mode;
472 const int mb_xy = h->
mb_xy;
499 }
else if (mb_type < 8) {
517 for (m = 0; m < 2; m++) {
519 for (i = 0; i < 4; i++)
523 for (i = 0; i < 4; i++)
529 4 * 2 *
sizeof(int16_t));
565 for (i = 0; i < 4; i++)
567 0, 4 * 2 *
sizeof(int16_t));
573 for (i = 0; i < 4; i++)
575 0, 4 * 2 *
sizeof(int16_t));
580 }
else if (mb_type == 8 || mb_type == 33) {
585 for (i = 0; i < 4; i++)
601 for (i = 0; i < 16; i += 2) {
613 left[2] =
svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
615 if (left[1] == -1 || left[2] == -1) {
621 for (i = 0; i < 4; i++)
633 for (i = 0; i < 4; i++)
643 dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
655 for (i = 0; i < 4; i++)
657 0, 4 * 2 *
sizeof(int16_t));
659 for (i = 0; i < 4; i++)
661 0, 4 * 2 *
sizeof(int16_t));
697 "error while decoding intra luma dc\n");
706 for (i = 0; i < 4; i++)
707 if ((cbp & (1 << i))) {
708 for (j = 0; j < 4; j++) {
709 k = index ? (1 * (j & 1) + 2 * (i & 1) +
710 2 * (j & 2) + 4 * (i & 2))
716 "error while decoding block\n");
723 for (i = 1; i < 3; ++i)
726 "error while decoding chroma dc block\n");
731 for (i = 1; i < 3; i++) {
732 for (j = 0; j < 4; j++) {
738 "error while decoding chroma ac block\n");
760 const int mb_xy = h->
mb_xy;
766 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
771 int length = header >> 5 & 3;
804 if ((header & 0x9F) == 2) {
832 -1, 4 *
sizeof(int8_t));
834 -1, 8 *
sizeof(int8_t) * h->
mb_x);
852 unsigned char *extradata;
853 unsigned char *extradata_end;
855 int marker_found = 0;
884 extradata = (
unsigned char *)avctx->
extradata;
888 if (!memcmp(extradata,
"SEQH", 4)) {
902 if (size > extradata_end - extradata - 8)
908 switch (frame_size_code) {
970 unsigned long buf_len = watermark_width *
971 watermark_height * 4;
975 if (watermark_height > 0 &&
976 (uint64_t)watermark_width * 4 > UINT_MAX / watermark_height)
981 watermark_width, watermark_height);
983 "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
984 u1, u2, u3, u4, offset);
985 if (uncompress(buf, &buf_len, extradata + 8 + offset,
986 size - offset) != Z_OK) {
988 "could not uncompress watermark logo\n");
999 "this svq3 file contains watermark which need zlib support compiled in\n");
1030 const int b4_stride = h->
mb_width * 4 + 1;
1031 const int b4_array_size = b4_stride * h->
mb_height * 4;
1042 for (i = 0; i < 2; i++) {
1068 int buf_size = avpkt->
size;
1072 if (buf_size == 0) {
1107 for (i = 0; i < 16; i++) {
1111 for (i = 0; i < 16; i++) {
1146 "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
1182 for (m = 0; m < 2; m++) {
1184 for (i = 0; i < 4; i++) {
1186 for (j = -1; j < 4; j++)
1218 "error while decoding MB %d %d\n", h->
mb_x, h->
mb_y);
1254 for (i = 0; i < 2; i++) {
const struct AVCodec * codec
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
discard all frames except keyframes
uint8_t * edge_emu_buffer
op_pixels_func put_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
unsigned int top_samples_available
This structure describes decoded (raw) audio or video data.
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
uint16_t ff_svq1_packet_checksum(const uint8_t *data, const int length, int value)
static void skip_bits_long(GetBitContext *s, int n)
av_cold int ff_h264_decode_init(AVCodecContext *avctx)
void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc)
int16_t(*[2] motion_val_base)[2]
static unsigned svq3_get_ue_golomb(GetBitContext *gb)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static void free_picture(AVCodecContext *avctx, Picture *pic)
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
static av_always_inline uint32_t pack16to32(int a, int b)
static const uint8_t zigzag_scan[16]
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int svq3_mc_dir(SVQ3Context *s, int size, int mode, int dir, int avg)
static int svq3_decode_block(GetBitContext *gb, DCTELEM *block, int index, const int type)
enum AVDiscard skip_frame
static const uint8_t golomb_to_pict_type[5]
void(* emulated_edge_mc)(uint8_t *buf, const uint8_t *src, ptrdiff_t linesize, int block_w, int block_h, int src_x, int src_y, int w, int h)
Copy a rectangular area of samples to a temporary buffer and replicate the border samples...
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
DCTELEM mb_luma_dc[3][16 *2]
#define FFSWAP(type, a, b)
int prev_frame_num_offset
for POC type 2
static int get_buffer(AVCodecContext *avctx, Picture *pic)
DCTELEM mb[16 *48 *2]
as a dct coeffecient is int32_t in high depth, we need to reserve twice the space.
static const uint8_t luma_dc_zigzag_scan[16]
uint8_t motion_subsample_log2
log2 of the size of the block which a single vector in motion_val represents: (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
op_pixels_func avg_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
static const IMbInfo i_mb_type_info[26]
static int get_bits_count(const GetBitContext *s)
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
static int init(AVCodecParserContext *s)
static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
H.264 / AVC / MPEG4 part10 codec.
int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma)
Check if the top & left blocks are available if needed and change the dc mode so it only uses the ava...
int has_b_frames
Size of the frame reordering buffer in the decoder.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
tpel_mc_func avg_tpel_pixels_tab[11]
void ff_h264_hl_decode_mb(H264Context *h)
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define FF_DEBUG_PICT_INFO
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
#define CODEC_FLAG_EMU_EDGE
Sorenson Vector Quantizer #1 (SVQ1) video codec.
static const uint8_t scan8[16 *3+3]
static av_always_inline void pred_motion(H264Context *const h, int n, int part_width, int list, int ref, int *const mx, int *const my)
Get the predicted MV.
static int svq3_get_se_golomb(GetBitContext *gb)
useful rectangle filling function
unsigned int left_samples_available
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
int frame_num_offset
for POC type 2
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
static int svq3_decode_end(AVCodecContext *avctx)
int width
picture width / height.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
static av_cold int svq3_decode_init(AVCodecContext *avctx)
static void fill_rectangle(SDL_Surface *screen, int x, int y, int w, int h, int color)
int8_t intra4x4_pred_mode_cache[5 *8]
unsigned int topright_samples_available
static const uint8_t golomb_to_intra4x4_cbp[48]
void ff_draw_horiz_band(AVCodecContext *avctx, DSPContext *dsp, Picture *cur, Picture *last, int y, int h, int picture_structure, int first_field, int draw_edges, int low_delay, int v_edge_pos, int h_edge_pos)
#define PART_NOT_AVAILABLE
static const int8_t mv[256][2]
uint32_t * mb_type
macroblock type table mb_type_base + mb_width + 2
H264 / AVC / MPEG4 part10 codec data table
int prev_frame_num
frame_num of the last pic for POC type 1/2
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
int ff_h264_check_intra4x4_pred_mode(H264Context *h)
Check if the top & left blocks are available if needed and change the dc mode so it only uses the ava...
int ff_h264_alloc_tables(H264Context *h)
Allocate tables.
int16_t(*[2] motion_val)[2]
motion vector table
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static const uint8_t chroma_dc_scan[4]
static void svq3_mc_dir_part(SVQ3Context *s, int x, int y, int width, int height, int mx, int my, int dxy, int thirdpel, int dir, int avg)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static const uint8_t svq3_pred_0[25][2]
int8_t * ref_index[2]
motion reference frame index the order in which these are stored can depend on the codec...
#define MB_TYPE_INTRA16x16
int block_offset[2 *(16 *3)]
block_offset[ 0..23] for frame macroblocks block_offset[24..47] for field macroblocks ...
av_cold void ff_h264_free_context(H264Context *h)
Free any data that may have been allocated in the H264 context like SPS, PPS etc. ...
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void(* clear_blocks)(DCTELEM *blocks)
tpel_mc_func put_tpel_pixels_tab[11]
Thirdpel motion compensation with rounding (a+b+1)>>1.
discard all non reference
common internal api header.
#define AVERROR_INVALIDDATA
H.264 / AVC / MPEG4 part10 motion vector predicion.
static const uint8_t golomb_to_inter_cbp[48]
static av_always_inline void write_back_intra_pred_mode(H264Context *h)
static const uint32_t svq3_dequant_coeff[32]
uint8_t non_zero_count_cache[15 *8]
non zero coeff count cache.
static int svq3_decode_slice_header(AVCodecContext *avctx)
int key_frame
1 -> keyframe, 0-> not
void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qp)
enum AVPictureType pict_type
static const uint8_t svq3_scan[16]
static const int8_t svq3_pred_1[6][6][5]
int8_t * intra4x4_pred_mode
AVPixelFormat
Pixel format.
This structure stores compressed data.
static int svq3_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define CODEC_CAP_DRAW_HORIZ_BAND
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static const struct @54 svq3_dct_tables[2][16]
int8_t ref_cache[2][5 *8]
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)