51 #define MAX_DWT_LEVELS 5
56 #define MAX_REFERENCE_FRAMES 8
58 #define MAX_FRAMES (MAX_REFERENCE_FRAMES + MAX_DELAY + 1)
60 #define MAX_BLOCKSIZE 32
65 #define DIRAC_REF_MASK_REF1 1
66 #define DIRAC_REF_MASK_REF2 2
67 #define DIRAC_REF_MASK_GLOBAL 4
73 #define DELAYED_PIC_REF 4
75 #define ff_emulated_edge_mc ff_emulated_edge_mc_8
77 #define CALC_PADDING(size, depth) \
78 (((size + (1 << depth) - 1) >> depth) << depth)
80 #define DIVRNDUP(a, b) (((a) + (b) - 1) / (b))
241 { { 5, 3, 3, 0}, { 0, 4, 4, 1}, { 0, 5, 5, 2}, { 0, 6, 6, 3} },
242 { { 4, 2, 2, 0}, { 0, 4, 4, 2}, { 0, 5, 5, 3}, { 0, 7, 7, 5} },
243 { { 5, 3, 3, 0}, { 0, 4, 4, 1}, { 0, 5, 5, 2}, { 0, 6, 6, 3} },
244 { { 8, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0} },
245 { { 8, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0} },
246 { { 0, 4, 4, 8}, { 0, 8, 8, 12}, { 0, 13, 13, 17}, { 0, 17, 17, 21} },
247 { { 3, 1, 1, 0}, { 0, 4, 4, 2}, { 0, 6, 6, 5}, { 0, 9, 9, 7} },
251 4, 5, 6, 7, 8, 10, 11, 13,
252 16, 19, 23, 27, 32, 38, 45, 54,
253 64, 76, 91, 108, 128, 152, 181, 215,
254 256, 304, 362, 431, 512, 609, 724, 861,
255 1024, 1218, 1448, 1722, 2048, 2435, 2896, 3444,
256 4096, 4871, 5793, 6889, 8192, 9742, 11585, 13777,
257 16384, 19484, 23170, 27554, 32768, 38968, 46341, 55109,
262 1, 2, 3, 4, 4, 5, 6, 7,
263 8, 10, 12, 14, 16, 19, 23, 27,
264 32, 38, 46, 54, 64, 76, 91, 108,
265 128, 152, 181, 216, 256, 305, 362, 431,
266 512, 609, 724, 861, 1024, 1218, 1448, 1722,
267 2048, 2436, 2897, 3445, 4096, 4871, 5793, 6889,
268 8192, 9742, 11585, 13777, 16384, 19484, 23171, 27555,
273 1, 2, 2, 3, 3, 4, 4, 5,
274 6, 7, 9, 10, 12, 14, 17, 20,
275 24, 29, 34, 41, 48, 57, 68, 81,
276 96, 114, 136, 162, 192, 228, 272, 323,
277 384, 457, 543, 646, 768, 913, 1086, 1292,
278 1536, 1827, 2172, 2583, 3072, 3653, 4344, 5166,
279 6144, 7307, 8689, 10333, 12288, 14613, 17378, 20666,
286 return ((x+1)*21845 + 10922) >> 16;
292 int i, remove_idx = -1;
294 for (i = 0; framelist[i]; i++)
295 if (framelist[i]->avframe.display_picture_number == picnum) {
296 remove_pic = framelist[i];
301 for (i = remove_idx; framelist[i]; i++)
302 framelist[i] = framelist[i+1];
310 for (i = 0; i < maxframes; i++)
312 framelist[i] =
frame;
322 int i, w, h, top_padding;
325 for (i = 0; i < 3; i++) {
395 for (j = 0; j < 3; j++)
396 for (k = 1; k < 4; k++)
403 for (i = 0; i < 3; i++) {
448 #define SIGN_CTX(x) (CTX_SIGN_ZERO + ((x) > 0) - ((x) < 0))
462 sign_pred = buf[-b->
stride];
466 pred_ctx += !(buf[-1] | buf[-b->
stride] | buf[-1-b->
stride]);
470 pred_ctx += !buf[-b->
stride];
475 coeff = (coeff * qfactor + qoffset + 2) >> 2;
477 coeff = (coeff ^ -sign) + sign;
488 coeff = (coeff * qfactor + qoffset + 2) >> 2;
490 coeff = (coeff ^ -sign) + sign;
501 int left,
int right,
int top,
int bottom,
502 int blockcnt_one,
int is_arith)
504 int x,
y, zero_block;
505 int qoffset, qfactor;
542 for (y = top; y < bottom; y++) {
543 for (x = left; x < right; x++) {
563 for (x = 1; x < b->
width; x++)
567 for (y = 1; y < b->
height; y++) {
568 buf[0] += buf[-b->
stride];
570 for (x = 1; x < b->
width; x++) {
584 int cb_x, cb_y, left, right, top, bottom;
589 int blockcnt_one = (cb_width + cb_height) == 2;
600 for (cb_y = 0; cb_y < cb_height; cb_y++) {
601 bottom = (b->
height * (cb_y+1LL)) / cb_height;
603 for (cb_x = 0; cb_x < cb_width; cb_x++) {
604 right = (b->
width * (cb_x+1LL)) / cb_width;
605 codeblock(s, b, &gb, &c, left, right, top, bottom, blockcnt_one, is_arith);
639 int level, num_bands = 0;
643 for (orientation = !!level; orientation < 4; orientation++) {
645 bands[num_bands++] =
b;
671 int slice_x,
int slice_y,
int bits_end,
690 for (y = top; y < bottom; y++) {
691 for (x = left; x < right; x++) {
734 for (orientation = !!level; orientation < 4; orientation++) {
743 chroma_bits = 8*slice->
bytes - 7 - length_bits - luma_bits;
747 for (orientation = !!level; orientation < 4; orientation++) {
776 for (slice_y = 0; bufsize > 0 && slice_y < s->
lowdelay.
num_y; slice_y++)
777 for (slice_x = 0; bufsize > 0 && slice_x < s->
lowdelay.
num_x; slice_x++) {
781 slices[slice_num].
bytes = bytes;
782 slices[slice_num].
slice_x = slice_x;
783 slices[slice_num].
slice_y = slice_y;
801 int i, w, h,
level, orientation;
803 for (i = 0; i < 3; i++) {
815 for (orientation = !!level; orientation < 4; orientation++) {
854 static const uint8_t default_blen[] = { 4, 12, 16, 24 };
855 static const uint8_t default_bsep[] = { 4, 8, 12, 16 };
912 for (ref = 0; ref < s->
num_refs; ref++) {
970 #define CHECKEDREAD(dst, cond, errmsg) \
971 tmp = svq3_get_ue_golomb(gb); \
973 av_log(s->avctx, AV_LOG_ERROR, errmsg); \
1031 for (i = 0; i < 4; i++) {
1044 static const uint8_t avgsplit[7] = { 0, 0, 1, 1, 1, 2, 2 };
1053 return avgsplit[sbsplit[-1] + sbsplit[-
stride] + sbsplit[-stride-1]];
1063 return block[-1].
ref & refmask;
1068 pred = (block[-1].
ref & refmask) + (block[-stride].ref & refmask) + (block[-stride-1].
ref & refmask);
1069 return (pred >> 1) & refmask;
1076 memset(block->
u.
dc, 0,
sizeof(block->
u.
dc));
1078 if (x && !(block[-1].ref & 3)) {
1079 for (i = 0; i < 3; i++)
1080 block->
u.
dc[i] += block[-1].
u.
dc[i];
1084 if (y && !(block[-stride].ref & 3)) {
1085 for (i = 0; i < 3; i++)
1086 block->
u.
dc[i] += block[-stride].
u.
dc[i];
1090 if (x && y && !(block[-1-stride].ref & 3)) {
1091 for (i = 0; i < 3; i++)
1092 block->
u.
dc[i] += block[-1-stride].
u.
dc[i];
1097 for (i = 0; i < 3; i++)
1098 block->
u.
dc[i] = (block->
u.
dc[i]+1)>>1;
1099 }
else if (n == 3) {
1100 for (i = 0; i < 3; i++)
1108 int refmask = ref+1;
1112 if (x && (block[-1].ref & mask) == refmask)
1113 pred[n++] = block[-1].
u.
mv[ref];
1115 if (y && (block[-stride].ref & mask) == refmask)
1118 if (x && y && (block[-stride-1].ref & mask) == refmask)
1119 pred[n++] = block[-stride-1].
u.
mv[ref];
1123 block->
u.
mv[ref][0] = 0;
1124 block->
u.
mv[ref][1] = 0;
1127 block->
u.
mv[ref][0] = pred[0][0];
1128 block->
u.
mv[ref][1] = pred[0][1];
1131 block->
u.
mv[ref][0] = (pred[0][0] + pred[1][0] + 1) >> 1;
1132 block->
u.
mv[ref][1] = (pred[0][1] + pred[1][1] + 1) >> 1;
1135 block->
u.
mv[ref][0] =
mid_pred(pred[0][0], pred[1][0], pred[2][0]);
1136 block->
u.
mv[ref][1] =
mid_pred(pred[0][1], pred[1][1], pred[2][1]);
1149 int m = (1<<ep) - (c[0]*x + c[1]*y);
1150 int mx = m * ((
A[0][0] * x +
A[0][1]*
y) + (1<<ez) * b[0]);
1151 int my = m * ((
A[1][0] * x +
A[1][1]*
y) + (1<<ez) * b[1]);
1153 block->
u.
mv[ref][0] = (mx + (1<<(ez+ep))) >> (ez+ep);
1154 block->
u.
mv[ref][1] = (my + (1<<(ez+ep))) >> (ez+ep);
1172 for (i = 0; i < 3; i++)
1183 if (block->
ref & (i+1)) {
1187 pred_mv(block, stride, x, y, i);
1202 for (x = 1; x <
size; x++)
1205 for (y = 1; y <
size; y++) {
1207 for (x = 0; x <
size; x++)
1234 for (y = 0; y < s->
sbheight; y++) {
1235 for (x = 0; x < s->
sbwidth; x++) {
1246 for (i = 0; i < s->
num_refs; i++) {
1250 for (i = 0; i < 3; i++)
1254 for (x = 0; x < s->
sbwidth; x++) {
1258 for (q = 0; q < blkcnt; q++)
1259 for (p = 0; p < blkcnt; p++) {
1260 int bx = 4 * x + p*step;
1261 int by = 4 * y + q*step;
1273 #define ROLLOFF(i) offset == 1 ? ((i) ? 5 : 3) : \
1274 (1 + (6*(i) + offset - 1) / (2*offset - 1))
1278 else if (i > blen-1 - 2*offset)
1284 int left,
int right,
int wy)
1287 for (x = 0; left && x < p->
xblen >> 1; x++)
1288 obmc_weight[x] = wy*8;
1289 for (; x < p->
xblen >> right; x++)
1291 for (; x < p->
xblen; x++)
1292 obmc_weight[x] = wy*8;
1298 int left,
int right,
int top,
int bottom)
1301 for (y = 0; top && y < p->
yblen >> 1; y++) {
1305 for (; y < p->
yblen >> bottom; y++) {
1310 for (; y < p->
yblen; y++) {
1322 if (top || bottom || by == 1) {
1357 int x,
int y,
int ref,
int plane)
1361 int motion_x = block->
u.
mv[ref][0];
1362 int motion_y = block->
u.
mv[ref][1];
1363 int mx, my, i, epel, nplanes = 0;
1386 src[0] = ref_hpel[(my>>1)+(mx>>2)] + y*p->
stride + x;
1390 for (i = 0; i < 4; i++)
1391 src[i] = ref_hpel[i] + y*p->
stride + x;
1415 src[!mx] = src[2 + !!mx];
1417 }
else if (!(my&3)) {
1418 src[0] = src[(my>>1) ];
1419 src[1] = src[(my>>1)+1];
1440 for (i = 0; i < nplanes; i++) {
1447 return (nplanes>>1) + epel;
1451 uint8_t *obmc_weight,
int xblen,
int yblen)
1456 for (y = 0; y < yblen; y++) {
1457 for (x = 0; x < xblen; x += 2) {
1458 dst[x ] += dc * obmc_weight[x ];
1459 dst[x+1] += dc * obmc_weight[x+1];
1467 uint16_t *mctmp,
uint8_t *obmc_weight,
1468 int plane,
int dstx,
int dsty)
1474 switch (block->
ref&3) {
1480 idx =
mc_subpel(s, block, src, dstx, dsty, (block->
ref&3)-1, plane);
1487 idx =
mc_subpel(s, block, src, dstx, dsty, 0, plane);
1489 idx =
mc_subpel(s, block, src, dstx, dsty, 1, plane);
1510 for (x = 1; x < s->
blwidth-1; x++) {
1552 for (i = 1; i < 4; i++) {
1561 ref->
hpel[plane][3], ref->
hpel[plane][0],
1577 int y, i,
comp, dsty;
1581 for (comp = 0; comp < 3; comp++) {
1589 for (comp = 0; comp < 3; comp++) {
1594 for (i = 0; i < 4; i++)
1607 for (y = 0; y < p->
height; y += 16) {
1623 for (y = 0; y < s->
blheight; y++) {
1625 start =
FFMAX(dsty, 0);
1626 uint16_t *mctmp = s->
mctmp + y*rowheight;
1634 h = p->
ybsep - (start - dsty);
1639 mc_row(s, blocks, mctmp, comp, dsty);
1662 int i, j, refnum, refdist;
1677 for (i = 0; i < s->
num_refs; i++) {
1706 if (retire != picnum) {
1764 #define DATA_UNIT_HEADER_SIZE 13
1772 int i, parse_code = buf[4];
1794 }
else if (parse_code ==
pc_eos) {
1802 if (sscanf(buf+14,
"Schroedinger %d.%d.%d", ver, ver+1, ver+2) == 3)
1803 if (ver[0] == 1 && ver[1] == 0 && ver[2] <= 7)
1806 }
else if (parse_code & 0x8) {
1824 tmp = parse_code & 0x03;
1830 s->
is_arith = (parse_code & 0x48) == 0x08;
1831 s->
low_delay = (parse_code & 0x88) == 0x88;
1864 int buf_size = pkt->
size;
1865 int i, data_unit_size, buf_idx = 0;
1886 if (buf[buf_idx ] ==
'B' && buf[buf_idx+1] ==
'B' &&
1887 buf[buf_idx+2] ==
'C' && buf[buf_idx+3] ==
'D')
1894 data_unit_size =
AV_RB32(buf+buf_idx+5);
1895 if (buf_idx + data_unit_size > buf_size || !data_unit_size) {
1896 if(buf_idx + data_unit_size > buf_size)
1898 "Data unit with size %d is larger than input buffer, discarding\n",
1909 buf_idx += data_unit_size;
1934 if (delayed_frame) {