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 } },
124 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
125 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
126 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
127 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
131 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
132 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
133 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
134 61694, 68745, 77615, 89113,100253,109366,126635,141533
142 static const uint8_t x_offset[4]={0, 1*
stride, 4*
stride, 5*stride};
145 const int z0 = 13*(input[4*i+0] + input[4*i+2]);
146 const int z1 = 13*(input[4*i+0] - input[4*i+2]);
147 const int z2 = 7* input[4*i+1] - 17*input[4*i+3];
148 const int z3 = 17* input[4*i+1] + 7*input[4*i+3];
157 const int offset= x_offset[i];
158 const int z0= 13*(temp[4*0+i] + temp[4*2+i]);
159 const int z1= 13*(temp[4*0+i] - temp[4*2+i]);
160 const int z2= 7* temp[4*1+i] - 17*temp[4*3+i];
161 const int z3= 17* temp[4*1+i] + 7*temp[4*3+i];
163 output[
stride* 0+offset] = ((z0 + z3)*qmul + 0x80000) >> 20;
164 output[
stride* 2+offset] = ((z1 + z2)*qmul + 0x80000) >> 20;
165 output[
stride* 8+offset] = ((z1 - z2)*qmul + 0x80000) >> 20;
166 output[
stride*10+offset] = ((z0 - z3)*qmul + 0x80000) >> 20;
178 dc = 13*13*((dc == 1) ? 1538*block[0] : ((qmul*(block[0] >> 3)) / 2));
182 for (i = 0; i < 4; i++) {
183 const int z0 = 13*(block[0 + 4*i] + block[2 + 4*i]);
184 const int z1 = 13*(block[0 + 4*i] - block[2 + 4*i]);
185 const int z2 = 7* block[1 + 4*i] - 17*block[3 + 4*i];
186 const int z3 = 17* block[1 + 4*i] + 7*block[3 + 4*i];
188 block[0 + 4*i] = z0 + z3;
189 block[1 + 4*i] = z1 + z2;
190 block[2 + 4*i] = z1 - z2;
191 block[3 + 4*i] = z0 - z3;
194 for (i = 0; i < 4; i++) {
195 const int z0 = 13*(block[i + 4*0] + block[i + 4*2]);
196 const int z1 = 13*(block[i + 4*0] - block[i + 4*2]);
197 const int z2 = 7* block[i + 4*1] - 17*block[i + 4*3];
198 const int z3 = 17* block[i + 4*1] + 7*block[i + 4*3];
199 const int rr = (dc + 0x80000);
201 dst[i + stride*0] = av_clip_uint8( dst[i + stride*0] + (((z0 + z3)*qmul + rr) >> 20) );
202 dst[i + stride*1] = av_clip_uint8( dst[i + stride*1] + (((z1 + z2)*qmul + rr) >> 20) );
203 dst[i + stride*2] = av_clip_uint8( dst[i + stride*2] + (((z1 - z2)*qmul + rr) >> 20) );
204 dst[i + stride*3] = av_clip_uint8( dst[i + stride*3] + (((z0 - z3)*qmul + rr) >> 20) );
209 int index,
const int type)
211 static const uint8_t *
const scan_patterns[4] =
215 const int intra = (3 * type) >> 2;
216 const uint8_t *
const scan = scan_patterns[type];
218 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
224 sign = (vlc & 0x1) - 1;
225 vlc = (vlc + 1) >> 1;
231 }
else if (vlc < 4) {
236 level = ((vlc + 9) >> 2) -
run;
244 level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
247 level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
251 if ((index += run) >= limit)
254 block[scan[
index]] = (level ^ sign) - sign;
267 int mx,
int my,
int dxy,
268 int thirdpel,
int dir,
int avg)
273 int blocksize = 2 - (width>>3);
278 if (mx < 0 || mx >= (s->
h_edge_pos - width - 1) ||
279 my < 0 || my >= (s->
v_edge_pos - height - 1)) {
285 mx = av_clip (mx, -16, (s->
h_edge_pos - width + 15));
286 my = av_clip (my, -16, (s->
v_edge_pos - height + 15));
304 mx = (mx + (mx < (int) x)) >> 1;
305 my = (my + (my < (int) y)) >> 1;
306 width = (width >> 1);
307 height = (height >> 1);
310 for (i = 1; i < 3; i++) {
330 int i, j, k, mx, my, dx, dy, x, y;
332 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
333 const int part_height = 16 >> ((unsigned) (size + 1) / 3);
334 const int extra_width = (mode ==
PREDICT_MODE) ? -16*6 : 0;
335 const int h_edge_pos = 6*(s->
h_edge_pos - part_width ) - extra_width;
336 const int v_edge_pos = 6*(s->
v_edge_pos - part_height) - extra_width;
338 for (i = 0; i < 16; i += part_height) {
339 for (j = 0; j < 16; j += part_width) {
340 const int b_xy = (4*s->
mb_x + (j >> 2)) + (4*s->
mb_y + (i >> 2))*h->
b_stride;
344 k = ((j >> 2) & 1) + ((i >> 1) & 2) + ((j >> 1) & 4) + (i & 8);
347 pred_motion(h, k, (part_width >> 2), dir, 1, &mx, &my);
362 mx = av_clip(mx, extra_width - 6*x, h_edge_pos - 6*x);
363 my = av_clip(my, extra_width - 6*y, v_edge_pos - 6*y);
381 mx = ((mx + 1)>>1) + dx;
382 my = ((my + 1)>>1) + dy;
383 fx = ((unsigned)(mx + 0x3000))/3 - 0x1000;
384 fy = ((unsigned)(my + 0x3000))/3 - 0x1000;
385 dxy = (mx - 3*fx) + 4*(my - 3*fy);
387 svq3_mc_dir_part(s, x, y, part_width, part_height, fx, fy, dxy, 1, dir, avg);
391 mx = ((unsigned)(mx + 1 + 0x3000))/3 + dx - 0x1000;
392 my = ((unsigned)(my + 1 + 0x3000))/3 + dy - 0x1000;
393 dxy = (mx&1) + 2*(my&1);
395 svq3_mc_dir_part(s, x, y, part_width, part_height, mx>>1, my>>1, dxy, 0, dir, avg);
399 mx = ((unsigned)(mx + 3 + 0x6000))/6 + dx - 0x1000;
400 my = ((unsigned)(my + 3 + 0x6000))/6 + dy - 0x1000;
402 svq3_mc_dir_part(s, x, y, part_width, part_height, mx, my, 0, 0, dir, avg);
411 if (part_height == 8 && i < 8) {
414 if (part_width == 8 && j < 8) {
418 if (part_width == 8 && j < 8) {
421 if (part_width == 4 || part_height == 4) {
428 part_width >> 2, part_height >> 2, h->
b_stride,
439 int i, j, k, m, dir, mode;
444 const int mb_xy = h->
mb_xy;
453 svq3_mc_dir_part(s, 16*s->
mb_x, 16*s->
mb_y, 16, 16, 0, 0, 0, 0, 0, 0);
456 svq3_mc_dir_part(s, 16*s->
mb_x, 16*s->
mb_y, 16, 16, 0, 0, 0, 0, 1, 1);
469 }
else if (mb_type < 8) {
487 for (m = 0; m < 2; m++) {
489 for (i = 0; i < 4; i++) {
493 for (i = 0; i < 4; i++) {
529 for (i = 0; i < 4; i++) {
534 if (
svq3_mc_dir(h, 0, mode, 1, (mb_type == 3)) < 0)
537 for (i = 0; i < 4; i++) {
544 }
else if (mb_type == 8 || mb_type == 33) {
549 for (i = 0; i < 4; i++) {
568 for (i = 0; i < 16; i+=2) {
580 left[2] =
svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
582 if (left[1] == -1 || left[2] == -1){
588 for (i = 0; i < 4; i++) {
601 for (i = 0; i < 4; i++) {
612 dir = (dir >> 1) ^ 3*(dir & 1) ^ 1;
624 for (i = 0; i < 4; i++) {
628 for (i = 0; i < 4; i++) {
671 for (i = 0; i < 4; i++) {
672 if ((cbp & (1 << i))) {
673 for (j = 0; j < 4; j++) {
674 k = index ? ((j&1) + 2*(i&1) + 2*(j&2) + 4*(i&2)) : (4*i + j);
686 for (i = 1; i < 3; ++i) {
694 for (i = 1; i < 3; i++) {
695 for (j = 0; j < 4; j++) {
724 const int mb_xy = h->
mb_xy;
729 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
734 int length = (header >> 5) & 3;
764 if ((header & 0x9F) == 2) {
765 i = (s->
mb_num < 64) ? 6 : (1 + av_log2 (s->
mb_num - 1));
812 unsigned char *extradata;
813 unsigned char *extradata_end;
815 int marker_found = 0;
834 extradata = (
unsigned char *)avctx->
extradata;
838 if (!memcmp(extradata,
"SEQH", 4)) {
853 if (size > extradata_end - extradata - 8)
859 switch (frame_size_code) {
860 case 0: avctx->
width = 160; avctx->
height = 120;
break;
861 case 1: avctx->
width = 128; avctx->
height = 96;
break;
862 case 2: avctx->
width = 176; avctx->
height = 144;
break;
863 case 3: avctx->
width = 352; avctx->
height = 288;
break;
864 case 4: avctx->
width = 704; avctx->
height = 576;
break;
865 case 5: avctx->
width = 240; avctx->
height = 180;
break;
866 case 6: avctx->
width = 320; avctx->
height = 240;
break;
901 unsigned long buf_len = watermark_width*watermark_height*4;
905 if (watermark_height > 0 &&
906 (uint64_t)watermark_width * 4 > UINT_MAX / watermark_height)
910 av_log(avctx,
AV_LOG_DEBUG,
"watermark size: %dx%d\n", watermark_width, watermark_height);
911 av_log(avctx,
AV_LOG_DEBUG,
"u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n", u1, u2, u3, u4, offset);
912 if (uncompress(buf, &buf_len, extradata + 8 + offset, size - offset) != Z_OK) {
922 av_log(avctx,
AV_LOG_ERROR,
"this svq3 file contains watermark which need zlib support compiled in\n");
946 void *
data,
int *data_size,
949 const uint8_t *buf = avpkt->
data;
953 int buf_size = avpkt->
size;
1024 for (m = 0; m < 2; m++){
1026 for (i = 0; i < 4; i++){
1028 for (j = -1; j < 4; j++)
static int svq3_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
void(* emulated_edge_mc)(uint8_t *buf, const uint8_t *src, int linesize, int block_w, int block_h, int src_x, int src_y, int w, int h)
Motion estimation with emulated edge values.
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
op_pixels_func put_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
unsigned int top_samples_available
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AV_WL32 AV_WL24 AV_WL16 AV_RB32
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)
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]
static const struct @45 svq3_dct_tables[2][16]
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
#define FF_DEBUG_PICT_INFO
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.
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
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 MPV_common_end(MpegEncContext *s)
static int init(AVCodecParserContext *s)
#define CODEC_FLAG_GRAY
Only decode/encode grayscale.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
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)
#define MB_TYPE_INTRA16x16
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. ...
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
Sorenson Vector Quantizer #1 (SVQ1) video codec.
#define CODEC_FLAG_EMU_EDGE
Don't draw edges.
void MPV_frame_end(MpegEncContext *s)
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 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
static int svq3_decode_end(AVCodecContext *avctx)
int width
picture width / height.
struct AVFrame AVFrame
Audio Video 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]
av_cold int MPV_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
#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)
static int svq3_get_ue_golomb(GetBitContext *gb)
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)
discard all non reference
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
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int16_t(*[2] motion_val)[2]
motion vector table
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void skip_bits(GetBitContext *s, int n)
void ff_draw_horiz_band(MpegEncContext *s, int y, int h)
#define CODEC_CAP_DRAW_HORIZ_BAND
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
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.
enum PixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
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
common internal api header.
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int adaptive_quant
use adaptive quantization
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]
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
discard all frames except keyframes
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int uvlinesize
line size, for chroma in bytes, may be different from width
int8_t ref_cache[2][5 *8]