50 #define MAX_DWT_LEVELS 5
55 #define MAX_REFERENCE_FRAMES 8
57 #define MAX_FRAMES (MAX_REFERENCE_FRAMES + MAX_DELAY + 1)
59 #define MAX_BLOCKSIZE 32
64 #define DIRAC_REF_MASK_REF1 1
65 #define DIRAC_REF_MASK_REF2 2
66 #define DIRAC_REF_MASK_GLOBAL 4
72 #define DELAYED_PIC_REF 4
74 #define ff_emulated_edge_mc ff_emulated_edge_mc_8
76 #define CALC_PADDING(size, depth) \
77 (((size + (1 << depth) - 1) >> depth) << depth)
79 #define DIVRNDUP(a, b) (((a) + (b) - 1) / (b))
239 { { 5, 3, 3, 0}, { 0, 4, 4, 1}, { 0, 5, 5, 2}, { 0, 6, 6, 3} },
240 { { 4, 2, 2, 0}, { 0, 4, 4, 2}, { 0, 5, 5, 3}, { 0, 7, 7, 5} },
241 { { 5, 3, 3, 0}, { 0, 4, 4, 1}, { 0, 5, 5, 2}, { 0, 6, 6, 3} },
242 { { 8, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0} },
243 { { 8, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0} },
244 { { 0, 4, 4, 8}, { 0, 8, 8, 12}, { 0, 13, 13, 17}, { 0, 17, 17, 21} },
245 { { 3, 1, 1, 0}, { 0, 4, 4, 2}, { 0, 6, 6, 5}, { 0, 9, 9, 7} },
249 4, 5, 6, 7, 8, 10, 11, 13,
250 16, 19, 23, 27, 32, 38, 45, 54,
251 64, 76, 91, 108, 128, 152, 181, 215,
252 256, 304, 362, 431, 512, 609, 724, 861,
253 1024, 1218, 1448, 1722, 2048, 2435, 2896, 3444,
254 4096, 4871, 5793, 6889, 8192, 9742, 11585, 13777,
255 16384, 19484, 23170, 27554, 32768, 38968, 46341, 55109,
260 1, 2, 3, 4, 4, 5, 6, 7,
261 8, 10, 12, 14, 16, 19, 23, 27,
262 32, 38, 46, 54, 64, 76, 91, 108,
263 128, 152, 181, 216, 256, 305, 362, 431,
264 512, 609, 724, 861, 1024, 1218, 1448, 1722,
265 2048, 2436, 2897, 3445, 4096, 4871, 5793, 6889,
266 8192, 9742, 11585, 13777, 16384, 19484, 23171, 27555,
271 1, 2, 2, 3, 3, 4, 4, 5,
272 6, 7, 9, 10, 12, 14, 17, 20,
273 24, 29, 34, 41, 48, 57, 68, 81,
274 96, 114, 136, 162, 192, 228, 272, 323,
275 384, 457, 543, 646, 768, 913, 1086, 1292,
276 1536, 1827, 2172, 2583, 3072, 3653, 4344, 5166,
277 6144, 7307, 8689, 10333, 12288, 14613, 17378, 20666,
284 return ((x+1)*21845 + 10922) >> 16;
290 int i, remove_idx = -1;
292 for (i = 0; framelist[i]; i++)
293 if (framelist[i]->avframe.display_picture_number == picnum) {
294 remove_pic = framelist[i];
299 for (i = remove_idx; framelist[i]; i++)
300 framelist[i] = framelist[i+1];
308 for (i = 0; i < maxframes; i++)
310 framelist[i] =
frame;
320 int i, w, h, top_padding;
323 for (i = 0; i < 3; i++) {
371 for (j = 0; j < 3; j++)
372 for (k = 1; k < 4; k++)
379 for (i = 0; i < 3; i++) {
423 #define SIGN_CTX(x) (CTX_SIGN_ZERO + ((x) > 0) - ((x) < 0))
437 sign_pred = buf[-b->
stride];
441 pred_ctx += !(buf[-1] | buf[-b->
stride] | buf[-1-b->
stride]);
445 pred_ctx += !buf[-b->
stride];
450 coeff = (coeff * qfactor + qoffset + 2) >> 2;
452 coeff = (coeff ^ -sign) + sign;
463 coeff = (coeff * qfactor + qoffset + 2) >> 2;
465 coeff = (coeff ^ -sign) + sign;
476 int left,
int right,
int top,
int bottom,
477 int blockcnt_one,
int is_arith)
479 int x, y, zero_block;
480 int qoffset, qfactor;
517 for (y = top; y < bottom; y++) {
518 for (x = left; x < right; x++) {
538 for (x = 1; x < b->
width; x++)
542 for (y = 1; y < b->
height; y++) {
543 buf[0] += buf[-b->
stride];
545 for (x = 1; x < b->
width; x++) {
559 int cb_x, cb_y, left, right, top, bottom;
564 int blockcnt_one = (cb_width + cb_height) == 2;
575 for (cb_y = 0; cb_y < cb_height; cb_y++) {
576 bottom = (b->
height * (cb_y+1)) / cb_height;
578 for (cb_x = 0; cb_x < cb_width; cb_x++) {
579 right = (b->
width * (cb_x+1)) / cb_width;
580 codeblock(s, b, &gb, &c, left, right, top, bottom, blockcnt_one, is_arith);
614 int level, num_bands = 0;
618 for (orientation = !!level; orientation < 4; orientation++) {
620 bands[num_bands++] =
b;
646 int slice_x,
int slice_y,
int bits_end,
665 for (y = top; y < bottom; y++) {
666 for (x = left; x < right; x++) {
709 for (orientation = !!level; orientation < 4; orientation++) {
718 chroma_bits = 8*slice->
bytes - 7 - length_bits - luma_bits;
722 for (orientation = !!level; orientation < 4; orientation++) {
751 for (slice_y = 0; bufsize > 0 && slice_y < s->
lowdelay.
num_y; slice_y++)
752 for (slice_x = 0; bufsize > 0 && slice_x < s->
lowdelay.
num_x; slice_x++) {
756 slices[slice_num].
bytes = bytes;
757 slices[slice_num].
slice_x = slice_x;
758 slices[slice_num].
slice_y = slice_y;
776 int i, w, h,
level, orientation;
778 for (i = 0; i < 3; i++) {
790 for (orientation = !!level; orientation < 4; orientation++) {
829 static const uint8_t default_blen[] = { 4, 12, 16, 24 };
830 static const uint8_t default_bsep[] = { 4, 8, 12, 16 };
887 for (ref = 0; ref < s->
num_refs; ref++) {
945 #define CHECKEDREAD(dst, cond, errmsg) \
946 tmp = svq3_get_ue_golomb(gb); \
948 av_log(s->avctx, AV_LOG_ERROR, errmsg); \
1006 for (i = 0; i < 4; i++) {
1019 static const uint8_t avgsplit[7] = { 0, 0, 1, 1, 1, 2, 2 };
1028 return avgsplit[sbsplit[-1] + sbsplit[-
stride] + sbsplit[-stride-1]];
1038 return block[-1].
ref & refmask;
1043 pred = (block[-1].
ref & refmask) + (block[-stride].ref & refmask) + (block[-stride-1].
ref & refmask);
1044 return (pred >> 1) & refmask;
1051 memset(block->
u.
dc, 0,
sizeof(block->
u.
dc));
1053 if (x && !(block[-1].ref & 3)) {
1054 for (i = 0; i < 3; i++)
1055 block->
u.
dc[i] += block[-1].
u.
dc[i];
1059 if (y && !(block[-stride].ref & 3)) {
1060 for (i = 0; i < 3; i++)
1061 block->
u.
dc[i] += block[-stride].
u.
dc[i];
1065 if (x && y && !(block[-1-stride].ref & 3)) {
1066 for (i = 0; i < 3; i++)
1067 block->
u.
dc[i] += block[-1-stride].
u.
dc[i];
1072 for (i = 0; i < 3; i++)
1073 block->
u.
dc[i] = (block->
u.
dc[i]+1)>>1;
1074 }
else if (n == 3) {
1075 for (i = 0; i < 3; i++)
1083 int refmask = ref+1;
1087 if (x && (block[-1].ref & mask) == refmask)
1088 pred[n++] = block[-1].
u.
mv[ref];
1090 if (y && (block[-stride].ref & mask) == refmask)
1093 if (x && y && (block[-stride-1].ref & mask) == refmask)
1094 pred[n++] = block[-stride-1].
u.
mv[ref];
1098 block->
u.
mv[ref][0] = 0;
1099 block->
u.
mv[ref][1] = 0;
1102 block->
u.
mv[ref][0] = pred[0][0];
1103 block->
u.
mv[ref][1] = pred[0][1];
1106 block->
u.
mv[ref][0] = (pred[0][0] + pred[1][0] + 1) >> 1;
1107 block->
u.
mv[ref][1] = (pred[0][1] + pred[1][1] + 1) >> 1;
1110 block->
u.
mv[ref][0] =
mid_pred(pred[0][0], pred[1][0], pred[2][0]);
1111 block->
u.
mv[ref][1] =
mid_pred(pred[0][1], pred[1][1], pred[2][1]);
1124 int m = (1<<ep) - (c[0]*x + c[1]*y);
1125 int mx = m * ((
A[0][0] * x +
A[0][1]*y) + (1<<ez) * b[0]);
1126 int my = m * ((
A[1][0] * x +
A[1][1]*y) + (1<<ez) * b[1]);
1128 block->
u.
mv[ref][0] = (mx + (1<<(ez+ep))) >> (ez+ep);
1129 block->
u.
mv[ref][1] = (my + (1<<(ez+ep))) >> (ez+ep);
1133 int stride,
int x,
int y)
1147 for (i = 0; i < 3; i++)
1158 if (block->
ref & (i+1)) {
1162 pred_mv(block, stride, x, y, i);
1177 for (x = 1; x <
size; x++)
1180 for (y = 1; y <
size; y++) {
1182 for (x = 0; x <
size; x++)
1209 for (y = 0; y < s->
sbheight; y++) {
1210 for (x = 0; x < s->
sbwidth; x++) {
1221 for (i = 0; i < s->
num_refs; i++) {
1225 for (i = 0; i < 3; i++)
1229 for (x = 0; x < s->
sbwidth; x++) {
1233 for (q = 0; q < blkcnt; q++)
1234 for (p = 0; p < blkcnt; p++) {
1235 int bx = 4 * x + p*step;
1236 int by = 4 * y + q*step;
1248 #define ROLLOFF(i) offset == 1 ? ((i) ? 5 : 3) : \
1249 (1 + (6*(i) + offset - 1) / (2*offset - 1))
1253 else if (i > blen-1 - 2*offset)
1259 int left,
int right,
int wy)
1262 for (x = 0; left && x < p->
xblen >> 1; x++)
1263 obmc_weight[x] = wy*8;
1264 for (; x < p->
xblen >> right; x++)
1266 for (; x < p->
xblen; x++)
1267 obmc_weight[x] = wy*8;
1273 int left,
int right,
int top,
int bottom)
1276 for (y = 0; top && y < p->
yblen >> 1; y++) {
1280 for (; y < p->
yblen >> bottom; y++) {
1285 for (; y < p->
yblen; y++) {
1297 if (top || bottom || by == 1) {
1332 int x,
int y,
int ref,
int plane)
1336 int motion_x = block->
u.
mv[ref][0];
1337 int motion_y = block->
u.
mv[ref][1];
1338 int mx, my, i, epel, nplanes = 0;
1361 src[0] = ref_hpel[(my>>1)+(mx>>2)] + y*p->
stride + x;
1365 for (i = 0; i < 4; i++)
1366 src[i] = ref_hpel[i] + y*p->
stride + x;
1390 src[!mx] = src[2 + !!mx];
1392 }
else if (!(my&3)) {
1393 src[0] = src[(my>>1) ];
1394 src[1] = src[(my>>1)+1];
1415 for (i = 0; i < nplanes; i++) {
1422 return (nplanes>>1) + epel;
1426 uint8_t *obmc_weight,
int xblen,
int yblen)
1431 for (y = 0; y < yblen; y++) {
1432 for (x = 0; x < xblen; x += 2) {
1433 dst[x ] += dc * obmc_weight[x ];
1434 dst[x+1] += dc * obmc_weight[x+1];
1442 uint16_t *mctmp,
uint8_t *obmc_weight,
1443 int plane,
int dstx,
int dsty)
1449 switch (block->
ref&3) {
1455 idx =
mc_subpel(s, block, src, dstx, dsty, (block->
ref&3)-1, plane);
1462 idx =
mc_subpel(s, block, src, dstx, dsty, 0, plane);
1464 idx =
mc_subpel(s, block, src, dstx, dsty, 1, plane);
1485 for (x = 1; x < s->
blwidth-1; x++) {
1527 for (i = 1; i < 4; i++) {
1536 ref->
hpel[plane][3], ref->
hpel[plane][0],
1552 int y, i,
comp, dsty;
1556 for (comp = 0; comp < 3; comp++) {
1564 for (comp = 0; comp < 3; comp++) {
1569 for (i = 0; i < 4; i++)
1582 for (y = 0; y < p->
height; y += 16) {
1598 for (y = 0; y < s->
blheight; y++) {
1600 start =
FFMAX(dsty, 0);
1601 uint16_t *mctmp = s->
mctmp + y*rowheight;
1609 h = p->
ybsep - (start - dsty);
1614 mc_row(s, blocks, mctmp, comp, dsty);
1637 int i, j, refnum, refdist;
1652 for (i = 0; i < s->
num_refs; i++) {
1681 if (retire != picnum) {
1739 #define DATA_UNIT_HEADER_SIZE 13
1747 int i, parse_code = buf[4];
1769 }
else if (parse_code ==
pc_eos) {
1777 if (sscanf(buf+14,
"Schroedinger %d.%d.%d", ver, ver+1, ver+2) == 3)
1778 if (ver[0] == 1 && ver[1] == 0 && ver[2] <= 7)
1781 }
else if (parse_code & 0x8) {
1799 tmp = parse_code & 0x03;
1805 s->
is_arith = (parse_code & 0x48) == 0x08;
1806 s->
low_delay = (parse_code & 0x88) == 0x88;
1836 int buf_size = pkt->
size;
1837 int i, data_unit_size, buf_idx = 0;
1858 if (buf[buf_idx ] ==
'B' && buf[buf_idx+1] ==
'B' &&
1859 buf[buf_idx+2] ==
'C' && buf[buf_idx+3] ==
'D')
1866 data_unit_size =
AV_RB32(buf+buf_idx+5);
1867 if (buf_idx + data_unit_size > buf_size || !data_unit_size) {
1868 if(buf_idx + data_unit_size > buf_size)
1870 "Data unit with size %d is larger than input buffer, discarding\n",
1881 buf_idx += data_unit_size;
1906 if (delayed_frame) {