168 for (i = 0; i < 4; i++)
171 for (i = 0; i < 4; i++)
175 for (i = 0; i < 3; i++)
184 for (i = 0; i < 4; i++) {
217 if (buf_size - size < 0)
241 for (i = 0; i < 4; i++) {
305 int header_size, hscale, vscale, i, j, k, l,
m,
ret;
312 header_size =
AV_RL24(buf) >> 5;
324 if (header_size > buf_size - 7*s->
keyframe) {
330 if (
AV_RL24(buf) != 0x2a019d) {
334 width =
AV_RL16(buf+3) & 0x3fff;
335 height =
AV_RL16(buf+5) & 0x3fff;
336 hscale = buf[4] >> 6;
337 vscale = buf[6] >> 6;
341 if (hscale || vscale)
345 for (i = 0; i < 4; i++)
346 for (j = 0; j < 16; j++)
358 buf_size -= header_size;
405 for (i = 0; i < 4; i++)
406 for (j = 0; j < 8; j++)
407 for (k = 0; k < 3; k++)
424 for (i = 0; i < 4; i++)
427 for (i = 0; i < 3; i++)
431 for (i = 0; i < 2; i++)
432 for (j = 0; j < 19; j++)
456 for (i = 0; i < 3; i++)
458 for (i = 9; i > 3; i--)
500 *mbsplits_cur, *firstidx;
510 top_mv = top_mb->
bmv;
527 for (n = 0; n < num; n++) {
529 uint32_t left, above;
533 left =
AV_RN32A(&left_mv[mbsplits_left[k + 3]]);
535 left =
AV_RN32A(&cur_mv[mbsplits_cur[k - 1]]);
537 above =
AV_RN32A(&top_mv[mbsplits_top[k + 12]]);
539 above =
AV_RN32A(&cur_mv[mbsplits_cur[k - 4]]);
568 enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV };
569 enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT };
591 #define MV_EDGE_CHECK(n)\
593 VP8Macroblock *edge = mb_edge[n];\
594 int edge_ref = edge->ref_frame;\
595 if (edge_ref != VP56_FRAME_CURRENT) {\
596 uint32_t mv = AV_RN32A(&edge->mv);\
598 if (cur_sign_bias != sign_bias[edge_ref]) {\
601 mv = ((mv&0x7fff7fff) + 0x00010001) ^ (mv&0x80008000);\
603 if (!n || mv != AV_RN32A(&near_mv[idx]))\
604 AV_WN32A(&near_mv[++idx], mv);\
605 cnt[idx] += 1 + (n != 2);\
607 cnt[CNT_ZERO] += 1 + (n != 2);\
620 if (cnt[CNT_SPLITMV] &&
AV_RN32A(&near_mv[1 + VP8_EDGE_TOP]) ==
AV_RN32A(&near_mv[1 + VP8_EDGE_TOPLEFT]))
621 cnt[CNT_NEAREST] += 1;
624 if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) {
626 FFSWAP(
VP56mv, near_mv[CNT_NEAREST], near_mv[CNT_NEAR]);
633 clamp_mv(s, &mb->
mv, &near_mv[CNT_ZERO + (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])]);
663 int mb_x,
int keyframe,
int layout)
679 for (y = 0; y < 4; y++) {
680 for (x = 0; x < 4; x++) {
684 left[
y] = top[x] = *intra4x4;
690 for (i = 0; i < 16; i++)
705 *segment = ref ? *ref : *segment;
751 #ifndef decode_block_coeffs_internal
763 int i,
uint8_t *token_prob, int16_t qmul[2])
776 token_prob = probs[i][0];
782 token_prob = probs[i+1][1];
802 int cat = (a<<1) + b;
803 coeff = 3 + (8<<cat);
807 token_prob = probs[i+1][2];
831 int i,
int zero_nhood, int16_t qmul[2])
833 uint8_t *token_prob = probs[i][zero_nhood];
843 int i, x,
y, luma_start = 0, luma_ctx = 3;
844 int nnz_pred, nnz, nnz_total = 0;
849 nnz_pred = t_nnz[8] + l_nnz[8];
854 l_nnz[8] = t_nnz[8] = !!nnz;
868 for (y = 0; y < 4; y++)
869 for (x = 0; x < 4; x++) {
870 nnz_pred = l_nnz[
y] + t_nnz[x];
875 t_nnz[x] = l_nnz[
y] = !!nnz;
882 for (i = 4; i < 6; i++)
883 for (y = 0; y < 2; y++)
884 for (x = 0; x < 2; x++) {
885 nnz_pred = l_nnz[i+2*
y] + t_nnz[i+2*x];
889 t_nnz[i+2*x] = l_nnz[i+2*
y] = !!nnz;
902 int linesize,
int uvlinesize,
int simple)
906 AV_COPY64(top_border+16, src_cb + 7*uvlinesize);
907 AV_COPY64(top_border+24, src_cr + 7*uvlinesize);
913 int linesize,
int uvlinesize,
int mb_x,
int mb_y,
int mb_width,
914 int simple,
int xchg)
916 uint8_t *top_border_m1 = top_border-32;
918 src_cb -= uvlinesize;
919 src_cr -= uvlinesize;
921 #define XCHG(a,b,xchg) do { \
922 if (xchg) AV_SWAP64(b,a); \
923 else AV_COPY64(b,a); \
926 XCHG(top_border_m1+8, src_y-8, xchg);
927 XCHG(top_border, src_y, xchg);
928 XCHG(top_border+8, src_y+8, 1);
929 if (mb_x < mb_width-1)
930 XCHG(top_border+32, src_y+16, 1);
934 if (!simple || !mb_y) {
935 XCHG(top_border_m1+16, src_cb-8, xchg);
936 XCHG(top_border_m1+24, src_cr-8, xchg);
937 XCHG(top_border+16, src_cb, 1);
938 XCHG(top_border+24, src_cr, 1);
1026 int x,
y,
mode, nnz;
1042 uint8_t tr_top[4] = { 127, 127, 127, 127 };
1052 tr = tr_right[-1]*0x01010101
u;
1059 for (y = 0; y < 4; y++) {
1061 for (x = 0; x < 4; x++) {
1066 if ((y == 0 || x == 3) && mb_y == 0) {
1069 topright = tr_right;
1073 dst = copy_dst + 12;
1077 AV_WN32A(copy_dst+4, 127
U * 0x01010101U);
1083 copy_dst[3] = ptr[4*x-s->
linesize-1];
1090 copy_dst[35] = 129
U;
1092 copy_dst[11] = ptr[4*x -1];
1093 copy_dst[19] = ptr[4*x+s->
linesize -1];
1094 copy_dst[27] = ptr[4*x+s->
linesize*2-1];
1095 copy_dst[35] = ptr[4*x+s->
linesize*3-1];
1132 { 0, 1, 2, 1, 2, 1, 2, 1 },
1134 { 0, 3, 5, 3, 5, 3, 5, 3 },
1135 { 0, 2, 3, 2, 3, 2, 3, 2 },
1157 int x_off,
int y_off,
int block_w,
int block_h,
1164 int src_linesize = linesize;
1166 int mx = (mv->
x << 1)&7, mx_idx =
subpel_idx[0][mx];
1167 int my = (mv->
y << 1)&7, my_idx =
subpel_idx[0][my];
1169 x_off += mv->
x >> 2;
1170 y_off += mv->
y >> 2;
1174 src += y_off * linesize + x_off;
1175 if (x_off < mx_idx || x_off >= width - block_w -
subpel_idx[2][mx] ||
1176 y_off < my_idx || y_off >= height - block_h -
subpel_idx[2][my]) {
1178 src - my_idx * linesize - mx_idx,
1182 x_off - mx_idx, y_off - my_idx, width, height);
1186 mc_func[my_idx][mx_idx](dst, linesize,
src, src_linesize, block_h, mx, my);
1189 mc_func[0][0](dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0);
1213 int block_w,
int block_h,
int width,
int height, ptrdiff_t linesize,
1222 x_off += mv->
x >> 3;
1223 y_off += mv->
y >> 3;
1226 src1 += y_off * linesize + x_off;
1227 src2 += y_off * linesize + x_off;
1229 if (x_off < mx_idx || x_off >= width - block_w -
subpel_idx[2][mx] ||
1230 y_off < my_idx || y_off >= height - block_h -
subpel_idx[2][my]) {
1232 src1 - my_idx * linesize - mx_idx,
1236 x_off - mx_idx, y_off - my_idx, width, height);
1238 mc_func[my_idx][mx_idx](dst1, linesize, src1,
EDGE_EMU_LINESIZE, block_h, mx, my);
1241 src2 - my_idx * linesize - mx_idx,
1242 EDGE_EMU_LINESIZE, linesize,
1245 x_off - mx_idx, y_off - my_idx, width, height);
1247 mc_func[my_idx][mx_idx](dst2, linesize, src2,
EDGE_EMU_LINESIZE, block_h, mx, my);
1249 mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my);
1250 mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my);
1254 mc_func[0][0](dst1, linesize, src1 + y_off * linesize + x_off, linesize, block_h, 0, 0);
1255 mc_func[0][0](dst2, linesize, src2 + y_off * linesize + x_off, linesize, block_h, 0, 0);
1262 int bx_off,
int by_off,
1263 int block_w,
int block_h,
1270 ref_frame, mv, x_off + bx_off, y_off + by_off,
1271 block_w, block_h, width, height, s->
linesize,
1279 x_off >>= 1; y_off >>= 1;
1280 bx_off >>= 1; by_off >>= 1;
1281 width >>= 1; height >>= 1;
1282 block_w >>= 1; block_h >>= 1;
1284 dst[2] + by_off * s->
uvlinesize + bx_off, ref_frame,
1285 &uvmv, x_off + bx_off, y_off + by_off,
1286 block_w, block_h, width, height, s->
uvlinesize,
1295 if (s->
ref_count[ref-1] > (mb_xy >> 5)) {
1296 int x_off = mb_x << 4, y_off = mb_y << 4;
1297 int mx = (mb->
mv.
x>>2) + x_off + 8;
1298 int my = (mb->
mv.
y>>2) + y_off;
1305 off= (mx>>1) + ((my>>1) + (mb_x&7))*s->
uvlinesize + 64;
1317 int x_off = mb_x << 4, y_off = mb_y << 4;
1325 0, 0, 16, 16, width,
height, &mb->
mv);
1332 for (y = 0; y < 4; y++) {
1333 for (x = 0; x < 4; x++) {
1336 4*x + x_off, 4*y + y_off, 4, 4,
1343 x_off >>= 1; y_off >>= 1; width >>= 1;
height >>= 1;
1344 for (y = 0; y < 2; y++) {
1345 for (x = 0; x < 2; x++) {
1346 uvmv.
x = mb->
bmv[ 2*y * 4 + 2*x ].
x +
1347 mb->
bmv[ 2*y * 4 + 2*x+1].
x +
1348 mb->
bmv[(2*y+1) * 4 + 2*x ].x +
1349 mb->
bmv[(2*y+1) * 4 + 2*x+1].
x;
1350 uvmv.
y = mb->
bmv[ 2*y * 4 + 2*x ].
y +
1351 mb->
bmv[ 2*y * 4 + 2*x+1].
y +
1352 mb->
bmv[(2*y+1) * 4 + 2*x ].y +
1353 mb->
bmv[(2*y+1) * 4 + 2*x+1].
y;
1354 uvmv.
x = (uvmv.
x + 2 + (uvmv.
x >> (INT_BIT-1))) >> 2;
1355 uvmv.
y = (uvmv.
y + 2 + (uvmv.
y >> (INT_BIT-1))) >> 2;
1361 dst[2] + 4*y*s->
uvlinesize + x*4, ref, &uvmv,
1362 4*x + x_off, 4*y + y_off, 4, 4,
1371 0, 0, 16, 8, width,
height, &bmv[0]);
1373 0, 8, 16, 8, width,
height, &bmv[1]);
1377 0, 0, 8, 16, width,
height, &bmv[0]);
1379 8, 0, 8, 16, width,
height, &bmv[1]);
1383 0, 0, 8, 8, width,
height, &bmv[0]);
1385 8, 0, 8, 8, width,
height, &bmv[1]);
1387 0, 8, 8, 8, width,
height, &bmv[2]);
1389 8, 8, 8, 8, width,
height, &bmv[3]);
1401 for (y = 0; y < 4; y++) {
1404 if (nnz4&~0x01010101) {
1405 for (x = 0; x < 4; x++) {
1422 for (ch = 0; ch < 2; ch++) {
1426 if (nnz4&~0x01010101) {
1427 for (y = 0; y < 2; y++) {
1428 for (x = 0; x < 2; x++) {
1435 goto chroma_idct_end;
1449 int interior_limit, filter_level;
1463 filter_level = av_clip_uintp2(filter_level, 6);
1465 interior_limit = filter_level;
1470 interior_limit =
FFMAX(interior_limit, 1);
1479 int mbedge_lim, bedge_lim, hev_thresh;
1485 static const uint8_t hev_thresh_lut[2][64] = {
1486 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1487 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1488 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
1490 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1491 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1492 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1499 bedge_lim = 2*filter_level + inner_limit;
1500 mbedge_lim = bedge_lim + 4;
1502 hev_thresh = hev_thresh_lut[s->
keyframe][filter_level];
1506 mbedge_lim, inner_limit, hev_thresh);
1508 mbedge_lim, inner_limit, hev_thresh);
1513 inner_limit, hev_thresh);
1515 inner_limit, hev_thresh);
1517 inner_limit, hev_thresh);
1519 uvlinesize, bedge_lim,
1520 inner_limit, hev_thresh);
1525 mbedge_lim, inner_limit, hev_thresh);
1527 mbedge_lim, inner_limit, hev_thresh);
1532 linesize, bedge_lim,
1533 inner_limit, hev_thresh);
1535 linesize, bedge_lim,
1536 inner_limit, hev_thresh);
1538 linesize, bedge_lim,
1539 inner_limit, hev_thresh);
1541 dst[2] + 4 * uvlinesize,
1542 uvlinesize, bedge_lim,
1543 inner_limit, hev_thresh);
1549 int mbedge_lim, bedge_lim;
1558 bedge_lim = 2*filter_level + inner_limit;
1559 mbedge_lim = bedge_lim + 4;
1578 #define MARGIN (16 << 2)
1587 for (mb_y = 0; mb_y < s->
mb_height; mb_y++) {
1595 for (mb_x = 0; mb_x < s->
mb_width; mb_x++, mb_xy++, mb++) {
1599 prev_frame && prev_frame->
seg_map ?
1610 #define check_thread_pos(td, otd, mb_x_check, mb_y_check)\
1612 int tmp = (mb_y_check << 16) | (mb_x_check & 0xFFFF);\
1613 if (otd->thread_mb_pos < tmp) {\
1614 pthread_mutex_lock(&otd->lock);\
1615 td->wait_mb_pos = tmp;\
1617 if (otd->thread_mb_pos >= tmp)\
1619 pthread_cond_wait(&otd->cond, &otd->lock);\
1621 td->wait_mb_pos = INT_MAX;\
1622 pthread_mutex_unlock(&otd->lock);\
1626 #define update_pos(td, mb_y, mb_x)\
1628 int pos = (mb_y << 16) | (mb_x & 0xFFFF);\
1629 int sliced_threading = (avctx->active_thread_type == FF_THREAD_SLICE) && (num_jobs > 1);\
1630 int is_null = (next_td == NULL) || (prev_td == NULL);\
1631 int pos_check = (is_null) ? 1 :\
1632 (next_td != td && pos >= next_td->wait_mb_pos) ||\
1633 (prev_td != td && pos >= prev_td->wait_mb_pos);\
1634 td->thread_mb_pos = pos;\
1635 if (sliced_threading && pos_check) {\
1636 pthread_mutex_lock(&td->lock);\
1637 pthread_cond_broadcast(&td->cond);\
1638 pthread_mutex_unlock(&td->lock);\
1642 #define check_thread_pos(td, otd, mb_x_check, mb_y_check)
1643 #define update_pos(td, mb_y, mb_x)
1647 int jobnr,
int threadnr)
1652 int mb_x, mb_xy = mb_y*s->
mb_width;
1662 if (mb_y == 0) prev_td =
td;
1663 else prev_td = &s->
thread_data[(jobnr + num_jobs - 1)%num_jobs];
1665 else next_td = &s->
thread_data[(jobnr + 1)%num_jobs];
1675 memset(mb - 1, 0,
sizeof(*mb));
1684 for (mb_x = 0; mb_x < s->
mb_width; mb_x++, mb_xy++, mb++) {
1686 if (prev_td != td) {
1687 if (threadnr != 0) {
1699 prev_frame && prev_frame->seg_map ?
1700 prev_frame->seg_map->data + mb_xy : NULL, 0);
1730 if (s->
deblock_filter && num_jobs != 1 && threadnr == num_jobs-1) {
1754 int jobnr,
int threadnr)
1773 if (mb_y == 0) prev_td =
td;
1774 else prev_td = &s->
thread_data[(jobnr + num_jobs - 1)%num_jobs];
1776 else next_td = &s->
thread_data[(jobnr + 1)%num_jobs];
1778 for (mb_x = 0; mb_x < s->
mb_width; mb_x++, mb++) {
1780 if (prev_td != td) {
1788 if (num_jobs == 1) {
1808 int jobnr,
int threadnr)
1816 for (mb_y = jobnr; mb_y < s->
mb_height; mb_y += num_jobs) {
1838 int ret, i, referenced, num_jobs;
1861 for (i = 0; i < 5; i++)
1863 &s->
frames[i] != prev_frame &&
1870 for (i = 0; i < 5; i++)
1871 if (&s->
frames[i] != prev_frame &&
1882 if (curframe->tf.f->data[0])
1896 curframe->tf.f->key_frame = s->
keyframe;
1921 s->
linesize = curframe->tf.f->linesize[0];
2038 #define REBASE(pic) \
2039 pic ? pic - &s_src->frames[0] + &s->frames[0] : NULL
2053 s->
prob[0] = s_src->
prob[!s_src->update_probabilities];
2059 if (s_src->frames[i].tf.f->data[0]) {