75 #define FULLPEL_MODE 1
76 #define HALFPEL_MODE 2
77 #define THIRDPEL_MODE 3
78 #define PREDICT_MODE 4
90 0 + 0 * 4, 1 + 0 * 4, 2 + 0 * 4, 2 + 1 * 4,
91 2 + 2 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4,
92 0 + 1 * 4, 0 + 2 * 4, 1 + 1 * 4, 1 + 2 * 4,
93 0 + 3 * 4, 1 + 3 * 4, 2 + 3 * 4, 3 + 3 * 4,
99 { 0, 2 }, { 1, 1 }, { 2, 0 },
100 { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
101 { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
102 { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
103 { 2, 4 }, { 3, 3 }, { 4, 2 },
109 { { 2, -1, -1, -1, -1 }, { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 },
110 { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 }, { 1, 2, -1, -1, -1 } },
111 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
112 { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
113 { { 2, 0, -1, -1, -1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
114 { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
115 { { 2, 0, -1, -1, -1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
116 { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
117 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
118 { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
119 { { 0, 2, -1, -1, -1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
120 { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
123 static const struct {
127 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
128 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
129 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
130 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
134 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
135 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
136 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
137 61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533
148 for (i = 0; i < 4; i++) {
149 const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]);
150 const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]);
151 const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3];
152 const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3];
154 temp[4 * i + 0] = z0 + z3;
155 temp[4 * i + 1] = z1 + z2;
156 temp[4 * i + 2] = z1 - z2;
157 temp[4 * i + 3] = z0 - z3;
160 for (i = 0; i < 4; i++) {
161 const int offset = x_offset[i];
162 const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]);
163 const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]);
164 const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];
165 const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];
167 output[
stride * 0 + offset] = (z0 + z3) * qmul + 0x80000 >> 20;
168 output[
stride * 2 + offset] = (z1 + z2) * qmul + 0x80000 >> 20;
169 output[
stride * 8 + offset] = (z1 - z2) * qmul + 0x80000 >> 20;
170 output[
stride * 10 + offset] = (z0 - z3) * qmul + 0x80000 >> 20;
176 int stride,
int qp,
int dc)
182 dc = 13 * 13 * (dc == 1 ? 1538 * block[0]
183 : qmul * (block[0] >> 3) / 2);
187 for (i = 0; i < 4; i++) {
188 const int z0 = 13 * (block[0 + 4 * i] + block[2 + 4 * i]);
189 const int z1 = 13 * (block[0 + 4 * i] - block[2 + 4 * i]);
190 const int z2 = 7 * block[1 + 4 * i] - 17 * block[3 + 4 * i];
191 const int z3 = 17 * block[1 + 4 * i] + 7 * block[3 + 4 * i];
193 block[0 + 4 * i] = z0 + z3;
194 block[1 + 4 * i] = z1 + z2;
195 block[2 + 4 * i] = z1 - z2;
196 block[3 + 4 * i] = z0 - z3;
199 for (i = 0; i < 4; i++) {
200 const int z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);
201 const int z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);
202 const int z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];
203 const int z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];
204 const int rr = (dc + 0x80000);
206 dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((z0 + z3) * qmul + rr >> 20));
207 dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((z1 + z2) * qmul + rr >> 20));
208 dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((z1 - z2) * qmul + rr >> 20));
209 dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((z0 - z3) * qmul + rr >> 20));
214 int index,
const int type)
216 static const uint8_t *
const scan_patterns[4] =
221 const int intra = 3 * type >> 2;
222 const uint8_t *
const scan = scan_patterns[type];
224 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
226 int sign = (vlc & 1) ? 0 : -1;
233 }
else if (vlc < 4) {
238 level = (vlc + 9 >> 2) - run;
247 ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
251 ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
255 if ((index += run) >= limit)
258 block[scan[
index]] = (level ^ sign) - sign;
271 int mx,
int my,
int dxy,
272 int thirdpel,
int dir,
int avg)
277 int blocksize = 2 - (width >> 3);
282 if (mx < 0 || mx >= s->
h_edge_pos - width - 1 ||
287 mx = av_clip(mx, -16, s->
h_edge_pos - width + 15);
288 my = av_clip(my, -16, s->
v_edge_pos - height + 15);
297 width + 1, height + 1,
311 mx = mx + (mx < (int) x) >> 1;
312 my = my + (my < (int) y) >> 1;
314 height = height >> 1;
317 for (i = 1; i < 3; i++) {
323 width + 1, height + 1,
345 int i, j, k, mx, my, dx, dy, x, y;
347 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
348 const int part_height = 16 >> ((unsigned)(size + 1) / 3);
349 const int extra_width = (mode ==
PREDICT_MODE) ? -16 * 6 : 0;
350 const int h_edge_pos = 6 * (s->
h_edge_pos - part_width) - extra_width;
351 const int v_edge_pos = 6 * (s->
v_edge_pos - part_height) - extra_width;
353 for (i = 0; i < 16; i += part_height)
354 for (j = 0; j < 16; j += part_width) {
355 const int b_xy = (4 * s->
mb_x + (j >> 2)) +
358 x = 16 * s->
mb_x + j;
359 y = 16 * s->
mb_y + i;
360 k = (j >> 2 & 1) + (i >> 1 & 2) +
361 (j >> 1 & 4) + (i & 8);
364 pred_motion(h, k, part_width >> 2, dir, 1, &mx, &my);
383 mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);
384 my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);
402 mx = (mx + 1 >> 1) + dx;
403 my = (my + 1 >> 1) + dy;
404 fx = (unsigned)(mx + 0x3000) / 3 - 0x1000;
405 fy = (unsigned)(my + 0x3000) / 3 - 0x1000;
406 dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);
409 fx, fy, dxy, 1, dir, avg);
413 mx = (unsigned)(mx + 1 + 0x3000) / 3 + dx - 0x1000;
414 my = (unsigned)(my + 1 + 0x3000) / 3 + dy - 0x1000;
415 dxy = (mx & 1) + 2 * (my & 1);
418 mx >> 1, my >> 1, dxy, 0, dir, avg);
422 mx = (unsigned)(mx + 3 + 0x6000) / 6 + dx - 0x1000;
423 my = (unsigned)(my + 3 + 0x6000) / 6 + dy - 0x1000;
426 mx, my, 0, 0, dir, avg);
435 if (part_height == 8 && i < 8) {
438 if (part_width == 8 && j < 8)
441 if (part_width == 8 && j < 8)
443 if (part_width == 4 || part_height == 4)
449 part_width >> 2, part_height >> 2, h->
b_stride,
459 int i, j, k, m, dir, mode;
464 const int mb_xy = h->
mb_xy;
491 }
else if (mb_type < 8) {
509 for (m = 0; m < 2; m++) {
511 for (i = 0; i < 4; i++)
515 for (i = 0; i < 4; i++)
521 4 * 2 *
sizeof(int16_t));
557 for (i = 0; i < 4; i++)
559 0, 4 * 2 *
sizeof(int16_t));
565 for (i = 0; i < 4; i++)
567 0, 4 * 2 *
sizeof(int16_t));
572 }
else if (mb_type == 8 || mb_type == 33) {
577 for (i = 0; i < 4; i++)
593 for (i = 0; i < 16; i += 2) {
605 left[2] =
svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
607 if (left[1] == -1 || left[2] == -1) {
613 for (i = 0; i < 4; i++)
625 for (i = 0; i < 4; i++)
635 dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
647 for (i = 0; i < 4; i++)
649 0, 4 * 2 *
sizeof(int16_t));
651 for (i = 0; i < 4; i++)
653 0, 4 * 2 *
sizeof(int16_t));
689 "error while decoding intra luma dc\n");
698 for (i = 0; i < 4; i++)
699 if ((cbp & (1 << i))) {
700 for (j = 0; j < 4; j++) {
701 k = index ? (1 * (j & 1) + 2 * (i & 1) +
702 2 * (j & 2) + 4 * (i & 2))
708 "error while decoding block\n");
715 for (i = 1; i < 3; ++i)
718 "error while decoding chroma dc block\n");
723 for (i = 1; i < 3; i++) {
724 for (j = 0; j < 4; j++) {
730 "error while decoding chroma ac block\n");
753 const int mb_xy = h->
mb_xy;
759 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
764 int length = header >> 5 & 3;
797 if ((header & 0x9F) == 2) {
825 -1, 4 *
sizeof(int8_t));
827 -1, 8 *
sizeof(int8_t) * s->
mb_x);
846 unsigned char *extradata;
847 unsigned char *extradata_end;
849 int marker_found = 0;
868 extradata = (
unsigned char *)avctx->
extradata;
872 if (!memcmp(extradata,
"SEQH", 4)) {
886 if (size > extradata_end - extradata - 8)
892 switch (frame_size_code) {
954 unsigned long buf_len = watermark_width *
955 watermark_height * 4;
959 if (watermark_height > 0 &&
960 (uint64_t)watermark_width * 4 > UINT_MAX / watermark_height)
965 watermark_width, watermark_height);
967 "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
968 u1, u2, u3, u4, offset);
969 if (uncompress(buf, &buf_len, extradata + 8 + offset,
970 size - offset) != Z_OK) {
972 "could not uncompress watermark logo\n");
984 "this svq3 file contains watermark which need zlib support compiled in\n");
1014 int buf_size = avpkt->
size;
1018 if (buf_size == 0) {
1039 "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
1085 for (m = 0; m < 2; m++) {
1087 for (i = 0; i < 4; i++) {
1089 for (j = -1; j < 4; j++)
1121 "error while decoding MB %d %d\n", s->
mb_x, s->
mb_y);
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
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.
av_cold int ff_MPV_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
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)
int v_edge_pos
horizontal / vertical position of the right/bottom edge (pixel replication)
void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc)
static unsigned svq3_get_ue_golomb(GetBitContext *gb)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
int mb_num
number of MBs of a picture
static av_always_inline uint32_t pack16to32(int a, int b)
static const uint8_t zigzag_scan[16]
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]
int prev_frame_num_offset
for POC type 2
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 * extradata
some codecs need / can use extradata like Huffman tables.
Picture current_picture
copy of the current picture structure.
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.
int flags2
AVCodecContext.flags2.
int mb_height
number of MBs horizontally & vertically
static int svq3_mc_dir(H264Context *h, int size, int mode, int dir, int avg)
void ff_MPV_frame_end(MpegEncContext *s)
static int init(AVCodecParserContext *s)
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 unrestricted_mv
mv can point outside of the coded picture
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define FF_DEBUG_PICT_INFO
uint8_t * edge_emu_buffer
temporary buffer for if MVs point to out-of-frame data
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
int low_delay
no reordering needed / has no b-frames
#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
int next_p_frame_damaged
set if the next p frame is damaged, to avoid showing trashed b frames
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.
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]
#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 ff_h264_frame_start(H264Context *h)
int prev_frame_num
frame_num of the last pic for POC type 1/2
static void svq3_mc_dir_part(MpegEncContext *s, int x, int y, int width, int height, int mx, int my, int dxy, int thirdpel, int dir, int avg)
static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
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.
int height
picture size. must be a multiple of 16
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)
void ff_draw_horiz_band(MpegEncContext *s, int y, int h)
static const uint8_t chroma_dc_scan[4]
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]
DSPContext dsp
pointers for accelerated dsp functions
#define MB_TYPE_INTRA16x16
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
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)
Picture * next_picture_ptr
pointer to the next picture (for bidir pred)
tpel_mc_func put_tpel_pixels_tab[11]
Thirdpel motion compensation with rounding (a+b+1)>>1.
struct AVCodecContext * avctx
discard all non reference
common internal api header.
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
int adaptive_quant
use adaptive quantization
#define AVERROR_INVALIDDATA
H.264 / AVC / MPEG4 part10 motion vector predicion.
Picture last_picture
copy of the previous picture structure.
Picture * last_picture_ptr
pointer to the previous picture.
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]
void ff_MPV_common_end(MpegEncContext *s)
uint8_t non_zero_count_cache[15 *8]
non zero coeff count cache.
static int svq3_decode_slice_header(AVCodecContext *avctx)
Picture next_picture
copy of the next picture structure.
int key_frame
1 -> keyframe, 0-> not
void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qp)
int linesize
line size, in bytes, may be different from width
static const uint8_t svq3_scan[16]
static const int8_t svq3_pred_1[6][6][5]
int flags
AVCodecContext.flags (HQ, MV4, ...)
int8_t * intra4x4_pred_mode
int uvlinesize
line size, for chroma in bytes, may be different from width
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
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)