52 #define MAX_DWT_LEVELS 5
57 #define MAX_REFERENCE_FRAMES 8
59 #define MAX_FRAMES (MAX_REFERENCE_FRAMES + MAX_DELAY + 1)
61 #define MAX_BLOCKSIZE 32
66 #define DIRAC_REF_MASK_REF1 1
67 #define DIRAC_REF_MASK_REF2 2
68 #define DIRAC_REF_MASK_GLOBAL 4
74 #define DELAYED_PIC_REF 4
76 #define CALC_PADDING(size, depth) \
77 (((size + (1 << depth) - 1) >> depth) << depth)
79 #define DIVRNDUP(a, b) (((a) + (b) - 1) / (b))
242 { { 5, 3, 3, 0}, { 0, 4, 4, 1}, { 0, 5, 5, 2}, { 0, 6, 6, 3} },
243 { { 4, 2, 2, 0}, { 0, 4, 4, 2}, { 0, 5, 5, 3}, { 0, 7, 7, 5} },
244 { { 5, 3, 3, 0}, { 0, 4, 4, 1}, { 0, 5, 5, 2}, { 0, 6, 6, 3} },
245 { { 8, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0} },
246 { { 8, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0} },
247 { { 0, 4, 4, 8}, { 0, 8, 8, 12}, { 0, 13, 13, 17}, { 0, 17, 17, 21} },
248 { { 3, 1, 1, 0}, { 0, 4, 4, 2}, { 0, 6, 6, 5}, { 0, 9, 9, 7} },
252 4, 5, 6, 7, 8, 10, 11, 13,
253 16, 19, 23, 27, 32, 38, 45, 54,
254 64, 76, 91, 108, 128, 152, 181, 215,
255 256, 304, 362, 431, 512, 609, 724, 861,
256 1024, 1218, 1448, 1722, 2048, 2435, 2896, 3444,
257 4096, 4871, 5793, 6889, 8192, 9742, 11585, 13777,
258 16384, 19484, 23170, 27554, 32768, 38968, 46341, 55109,
263 1, 2, 3, 4, 4, 5, 6, 7,
264 8, 10, 12, 14, 16, 19, 23, 27,
265 32, 38, 46, 54, 64, 76, 91, 108,
266 128, 152, 181, 216, 256, 305, 362, 431,
267 512, 609, 724, 861, 1024, 1218, 1448, 1722,
268 2048, 2436, 2897, 3445, 4096, 4871, 5793, 6889,
269 8192, 9742, 11585, 13777, 16384, 19484, 23171, 27555,
274 1, 2, 2, 3, 3, 4, 4, 5,
275 6, 7, 9, 10, 12, 14, 17, 20,
276 24, 29, 34, 41, 48, 57, 68, 81,
277 96, 114, 136, 162, 192, 228, 272, 323,
278 384, 457, 543, 646, 768, 913, 1086, 1292,
279 1536, 1827, 2172, 2583, 3072, 3653, 4344, 5166,
280 6144, 7307, 8689, 10333, 12288, 14613, 17378, 20666,
287 return ((x+1)*21845 + 10922) >> 16;
293 int i, remove_idx = -1;
295 for (i = 0; framelist[i]; i++)
296 if (framelist[i]->avframe->display_picture_number == picnum) {
297 remove_pic = framelist[i];
302 for (i = remove_idx; framelist[i]; i++)
303 framelist[i] = framelist[i+1];
311 for (i = 0; i < maxframes; i++)
313 framelist[i] =
frame;
323 int i, w, h, top_padding;
326 for (i = 0; i < 3; i++) {
396 for (j = 0; j < 3; j++)
397 for (k = 1; k < 4; k++)
404 for (i = 0; i < 3; i++) {
462 #define SIGN_CTX(x) (CTX_SIGN_ZERO + ((x) > 0) - ((x) < 0))
476 sign_pred = buf[-b->
stride];
480 pred_ctx += !(buf[-1] | buf[-b->
stride] | buf[-1-b->
stride]);
484 pred_ctx += !buf[-b->
stride];
489 coeff = (coeff * qfactor + qoffset + 2) >> 2;
491 coeff = (coeff ^ -sign) + sign;
502 coeff = (coeff * qfactor + qoffset + 2) >> 2;
504 coeff = (coeff ^ -sign) + sign;
515 int left,
int right,
int top,
int bottom,
516 int blockcnt_one,
int is_arith)
518 int x,
y, zero_block;
519 int qoffset, qfactor;
556 for (y = top; y < bottom; y++) {
557 for (x = left; x < right; x++) {
577 for (x = 1; x < b->
width; x++)
581 for (y = 1; y < b->
height; y++) {
582 buf[0] += buf[-b->
stride];
584 for (x = 1; x < b->
width; x++) {
598 int cb_x, cb_y, left, right, top, bottom;
603 int blockcnt_one = (cb_width + cb_height) == 2;
614 for (cb_y = 0; cb_y < cb_height; cb_y++) {
615 bottom = (b->
height * (cb_y+1LL)) / cb_height;
617 for (cb_x = 0; cb_x < cb_width; cb_x++) {
618 right = (b->
width * (cb_x+1LL)) / cb_width;
619 codeblock(s, b, &gb, &c, left, right, top, bottom, blockcnt_one, is_arith);
653 int level, num_bands = 0;
657 for (orientation = !!level; orientation < 4; orientation++) {
659 bands[num_bands++] =
b;
685 int slice_x,
int slice_y,
int bits_end,
704 for (y = top; y < bottom; y++) {
705 for (x = left; x < right; x++) {
748 for (orientation = !!level; orientation < 4; orientation++) {
757 chroma_bits = 8*slice->
bytes - 7 - length_bits - luma_bits;
761 for (orientation = !!level; orientation < 4; orientation++) {
792 for (slice_y = 0; bufsize > 0 && slice_y < s->
lowdelay.
num_y; slice_y++)
793 for (slice_x = 0; bufsize > 0 && slice_x < s->
lowdelay.
num_x; slice_x++) {
797 slices[slice_num].
bytes = bytes;
798 slices[slice_num].
slice_x = slice_x;
799 slices[slice_num].
slice_y = slice_y;
804 if (bufsize/8 >= bytes)
821 int i, w, h,
level, orientation;
823 for (i = 0; i < 3; i++) {
835 for (orientation = !!level; orientation < 4; orientation++) {
874 static const uint8_t default_blen[] = { 4, 12, 16, 24 };
875 static const uint8_t default_bsep[] = { 4, 8, 12, 16 };
909 "invalid x/y block length (%d/%d) for x/y chroma shift (%d/%d)\n",
940 for (ref = 0; ref < s->
num_refs; ref++) {
998 #define CHECKEDREAD(dst, cond, errmsg) \
999 tmp = svq3_get_ue_golomb(gb); \
1001 av_log(s->avctx, AV_LOG_ERROR, errmsg); \
1059 for (i = 0; i < 4; i++) {
1072 static const uint8_t avgsplit[7] = { 0, 0, 1, 1, 1, 2, 2 };
1079 return sbsplit[-stride];
1081 return avgsplit[sbsplit[-1] + sbsplit[-stride] + sbsplit[-stride-1]];
1091 return block[-1].
ref & refmask;
1093 return block[-stride].
ref & refmask;
1096 pred = (block[-1].
ref & refmask) + (block[-stride].ref & refmask) + (block[-stride-1].
ref & refmask);
1097 return (pred >> 1) & refmask;
1104 memset(block->
u.
dc, 0,
sizeof(block->
u.
dc));
1106 if (x && !(block[-1].ref & 3)) {
1107 for (i = 0; i < 3; i++)
1108 block->
u.
dc[i] += block[-1].
u.
dc[i];
1112 if (y && !(block[-stride].ref & 3)) {
1113 for (i = 0; i < 3; i++)
1114 block->
u.
dc[i] += block[-stride].
u.
dc[i];
1118 if (x && y && !(block[-1-stride].ref & 3)) {
1119 for (i = 0; i < 3; i++)
1120 block->
u.
dc[i] += block[-1-stride].
u.
dc[i];
1125 for (i = 0; i < 3; i++)
1126 block->
u.
dc[i] = (block->
u.
dc[i]+1)>>1;
1127 }
else if (n == 3) {
1128 for (i = 0; i < 3; i++)
1136 int refmask = ref+1;
1140 if (x && (block[-1].ref & mask) == refmask)
1141 pred[n++] = block[-1].
u.
mv[ref];
1143 if (y && (block[-stride].ref & mask) == refmask)
1144 pred[n++] = block[-stride].
u.
mv[ref];
1146 if (x && y && (block[-stride-1].ref & mask) == refmask)
1147 pred[n++] = block[-stride-1].
u.
mv[ref];
1151 block->
u.
mv[ref][0] = 0;
1152 block->
u.
mv[ref][1] = 0;
1155 block->
u.
mv[ref][0] = pred[0][0];
1156 block->
u.
mv[ref][1] = pred[0][1];
1159 block->
u.
mv[ref][0] = (pred[0][0] + pred[1][0] + 1) >> 1;
1160 block->
u.
mv[ref][1] = (pred[0][1] + pred[1][1] + 1) >> 1;
1163 block->
u.
mv[ref][0] =
mid_pred(pred[0][0], pred[1][0], pred[2][0]);
1164 block->
u.
mv[ref][1] =
mid_pred(pred[0][1], pred[1][1], pred[2][1]);
1177 int m = (1<<ep) - (c[0]*x + c[1]*y);
1178 int mx = m * ((
A[0][0] * x +
A[0][1]*
y) + (1<<ez) * b[0]);
1179 int my = m * ((
A[1][0] * x +
A[1][1]*
y) + (1<<ez) * b[1]);
1181 block->
u.
mv[ref][0] = (mx + (1<<(ez+ep))) >> (ez+ep);
1182 block->
u.
mv[ref][1] = (my + (1<<(ez+ep))) >> (ez+ep);
1200 for (i = 0; i < 3; i++)
1211 if (block->
ref & (i+1)) {
1215 pred_mv(block, stride, x, y, i);
1230 for (x = 1; x <
size; x++)
1233 for (y = 1; y <
size; y++) {
1235 for (x = 0; x <
size; x++)
1262 for (y = 0; y < s->
sbheight; y++) {
1263 for (x = 0; x < s->
sbwidth; x++) {
1274 for (i = 0; i < s->
num_refs; i++) {
1278 for (i = 0; i < 3; i++)
1282 for (x = 0; x < s->
sbwidth; x++) {
1286 for (q = 0; q < blkcnt; q++)
1287 for (p = 0; p < blkcnt; p++) {
1288 int bx = 4 * x + p*step;
1289 int by = 4 * y + q*step;
1301 #define ROLLOFF(i) offset == 1 ? ((i) ? 5 : 3) : \
1302 (1 + (6*(i) + offset - 1) / (2*offset - 1))
1306 else if (i > blen-1 - 2*offset)
1312 int left,
int right,
int wy)
1315 for (x = 0; left && x < p->
xblen >> 1; x++)
1316 obmc_weight[x] = wy*8;
1317 for (; x < p->
xblen >> right; x++)
1319 for (; x < p->
xblen; x++)
1320 obmc_weight[x] = wy*8;
1321 for (; x < stride; x++)
1326 int left,
int right,
int top,
int bottom)
1329 for (y = 0; top && y < p->
yblen >> 1; y++) {
1331 obmc_weight += stride;
1333 for (; y < p->
yblen >> bottom; y++) {
1336 obmc_weight += stride;
1338 for (; y < p->
yblen; y++) {
1340 obmc_weight += stride;
1350 if (top || bottom || by == 1) {
1385 int x,
int y,
int ref,
int plane)
1389 int motion_x = block->
u.
mv[ref][0];
1390 int motion_y = block->
u.
mv[ref][1];
1391 int mx, my, i, epel, nplanes = 0;
1414 src[0] = ref_hpel[(my>>1)+(mx>>2)] + y*p->
stride + x;
1418 for (i = 0; i < 4; i++)
1419 src[i] = ref_hpel[i] + y*p->
stride + x;
1443 src[!mx] = src[2 + !!mx];
1445 }
else if (!(my&3)) {
1446 src[0] = src[(my>>1) ];
1447 src[1] = src[(my>>1)+1];
1468 for (i = 0; i < nplanes; i++) {
1476 return (nplanes>>1) + epel;
1480 uint8_t *obmc_weight,
int xblen,
int yblen)
1485 for (y = 0; y < yblen; y++) {
1486 for (x = 0; x < xblen; x += 2) {
1487 dst[x ] += dc * obmc_weight[x ];
1488 dst[x+1] += dc * obmc_weight[x+1];
1496 uint16_t *mctmp,
uint8_t *obmc_weight,
1497 int plane,
int dstx,
int dsty)
1503 switch (block->
ref&3) {
1509 idx =
mc_subpel(s, block, src, dstx, dsty, (block->
ref&3)-1, plane);
1516 idx =
mc_subpel(s, block, src, dstx, dsty, 0, plane);
1518 idx =
mc_subpel(s, block, src, dstx, dsty, 1, plane);
1539 for (x = 1; x < s->
blwidth-1; x++) {
1581 for (i = 1; i < 4; i++) {
1593 ref->
hpel[plane][3], ref->
hpel[plane][0],
1611 int y, i,
comp, dsty;
1616 for (comp = 0; comp < 3; comp++) {
1626 for (comp = 0; comp < 3; comp++) {
1631 for (i = 0; i < 4; i++)
1644 for (y = 0; y < p->
height; y += 16) {
1654 for (i = 0; i < s->
num_refs; i++) {
1663 for (y = 0; y < s->
blheight; y++) {
1666 uint16_t *mctmp = s->
mctmp + y*rowheight;
1679 mc_row(s, blocks, mctmp, comp, dsty);
1698 int chroma_x_shift, chroma_y_shift;
1707 for (i = 0; f->
data[i]; i++) {
1725 int i, j, refnum, refdist;
1740 for (i = 0; i < s->
num_refs; i++) {
1775 if (retire != picnum) {
1835 #define DATA_UNIT_HEADER_SIZE 13
1843 int ret, i, parse_code = buf[4];
1865 }
else if (parse_code ==
pc_eos) {
1873 if (sscanf(buf+14,
"Schroedinger %d.%d.%d", ver, ver+1, ver+2) == 3)
1874 if (ver[0] == 1 && ver[1] == 0 && ver[2] <= 7)
1877 }
else if (parse_code & 0x8) {
1895 tmp = parse_code & 0x03;
1901 s->
is_arith = (parse_code & 0x48) == 0x08;
1902 s->
low_delay = (parse_code & 0x88) == 0x88;
1933 int buf_size = pkt->
size;
1934 int i, data_unit_size, buf_idx = 0;
1956 if (buf[buf_idx ] ==
'B' && buf[buf_idx+1] ==
'B' &&
1957 buf[buf_idx+2] ==
'C' && buf[buf_idx+3] ==
'D')
1964 data_unit_size =
AV_RB32(buf+buf_idx+5);
1965 if (data_unit_size > buf_size - buf_idx || !data_unit_size) {
1966 if(data_unit_size > buf_size - buf_idx)
1968 "Data unit with size %d is larger than input buffer, discarding\n",
1979 buf_idx += data_unit_size;
2003 if (delayed_frame) {