72 if (prefer_delayed_free) {
80 }
else if (can_direct_free) {
92 int prefer_delayed_free,
int can_direct_free,
int free_mem)
98 for (i = 0; i < 5; i++)
171 for (i = 0; i < 4; i++)
174 for (i = 0; i < 4; i++)
178 for (i = 0; i < 3; i++)
187 for (i = 0; i < 4; i++) {
220 if (buf_size - size < 0)
244 for (i = 0; i < 4; i++) {
308 int header_size, hscale, vscale, i, j, k, l,
m, ret;
315 header_size =
AV_RL24(buf) >> 5;
327 if (header_size > buf_size - 7*s->
keyframe) {
333 if (
AV_RL24(buf) != 0x2a019d) {
337 width =
AV_RL16(buf+3) & 0x3fff;
338 height =
AV_RL16(buf+5) & 0x3fff;
339 hscale = buf[4] >> 6;
340 vscale = buf[6] >> 6;
344 if (hscale || vscale)
348 for (i = 0; i < 4; i++)
349 for (j = 0; j < 16; j++)
361 buf_size -= header_size;
408 for (i = 0; i < 4; i++)
409 for (j = 0; j < 8; j++)
410 for (k = 0; k < 3; k++)
427 for (i = 0; i < 4; i++)
430 for (i = 0; i < 3; i++)
434 for (i = 0; i < 2; i++)
435 for (j = 0; j < 19; j++)
459 for (i = 0; i < 3; i++)
461 for (i = 9; i > 3; i--)
503 *mbsplits_cur, *firstidx;
513 top_mv = top_mb->
bmv;
530 for (n = 0; n < num; n++) {
532 uint32_t left, above;
536 left =
AV_RN32A(&left_mv[mbsplits_left[k + 3]]);
538 left =
AV_RN32A(&cur_mv[mbsplits_cur[k - 1]]);
540 above =
AV_RN32A(&top_mv[mbsplits_top[k + 12]]);
542 above =
AV_RN32A(&cur_mv[mbsplits_cur[k - 4]]);
571 enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV };
572 enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT };
594 #define MV_EDGE_CHECK(n)\
596 VP8Macroblock *edge = mb_edge[n];\
597 int edge_ref = edge->ref_frame;\
598 if (edge_ref != VP56_FRAME_CURRENT) {\
599 uint32_t mv = AV_RN32A(&edge->mv);\
601 if (cur_sign_bias != sign_bias[edge_ref]) {\
604 mv = ((mv&0x7fff7fff) + 0x00010001) ^ (mv&0x80008000);\
606 if (!n || mv != AV_RN32A(&near_mv[idx]))\
607 AV_WN32A(&near_mv[++idx], mv);\
608 cnt[idx] += 1 + (n != 2);\
610 cnt[CNT_ZERO] += 1 + (n != 2);\
623 if (cnt[CNT_SPLITMV] &&
AV_RN32A(&near_mv[1 + VP8_EDGE_TOP]) ==
AV_RN32A(&near_mv[1 + VP8_EDGE_TOPLEFT]))
624 cnt[CNT_NEAREST] += 1;
627 if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) {
629 FFSWAP(
VP56mv, near_mv[CNT_NEAREST], near_mv[CNT_NEAR]);
636 clamp_mv(s, &mb->
mv, &near_mv[CNT_ZERO + (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])]);
666 int mb_x,
int keyframe,
int layout)
682 for (y = 0; y < 4; y++) {
683 for (x = 0; x < 4; x++) {
687 left[
y] = top[x] = *intra4x4;
693 for (i = 0; i < 16; i++)
708 *segment = ref ? *ref : *segment;
754 #ifndef decode_block_coeffs_internal
766 int i,
uint8_t *token_prob, int16_t qmul[2])
779 token_prob = probs[i][0];
785 token_prob = probs[i+1][1];
805 int cat = (a<<1) + b;
806 coeff = 3 + (8<<cat);
810 token_prob = probs[i+1][2];
834 int i,
int zero_nhood, int16_t qmul[2])
836 uint8_t *token_prob = probs[i][zero_nhood];
846 int i, x,
y, luma_start = 0, luma_ctx = 3;
847 int nnz_pred, nnz, nnz_total = 0;
852 nnz_pred = t_nnz[8] + l_nnz[8];
857 l_nnz[8] = t_nnz[8] = !!nnz;
871 for (y = 0; y < 4; y++)
872 for (x = 0; x < 4; x++) {
873 nnz_pred = l_nnz[
y] + t_nnz[x];
878 t_nnz[x] = l_nnz[
y] = !!nnz;
885 for (i = 4; i < 6; i++)
886 for (y = 0; y < 2; y++)
887 for (x = 0; x < 2; x++) {
888 nnz_pred = l_nnz[i+2*
y] + t_nnz[i+2*x];
892 t_nnz[i+2*x] = l_nnz[i+2*
y] = !!nnz;
905 int linesize,
int uvlinesize,
int simple)
909 AV_COPY64(top_border+16, src_cb + 7*uvlinesize);
910 AV_COPY64(top_border+24, src_cr + 7*uvlinesize);
916 int linesize,
int uvlinesize,
int mb_x,
int mb_y,
int mb_width,
917 int simple,
int xchg)
919 uint8_t *top_border_m1 = top_border-32;
921 src_cb -= uvlinesize;
922 src_cr -= uvlinesize;
924 #define XCHG(a,b,xchg) do { \
925 if (xchg) AV_SWAP64(b,a); \
926 else AV_COPY64(b,a); \
929 XCHG(top_border_m1+8, src_y-8, xchg);
930 XCHG(top_border, src_y, xchg);
931 XCHG(top_border+8, src_y+8, 1);
932 if (mb_x < mb_width-1)
933 XCHG(top_border+32, src_y+16, 1);
937 if (!simple || !mb_y) {
938 XCHG(top_border_m1+16, src_cb-8, xchg);
939 XCHG(top_border_m1+24, src_cr-8, xchg);
940 XCHG(top_border+16, src_cb, 1);
941 XCHG(top_border+24, src_cr, 1);
1006 if (!mb_x && mb_y) {
1040 int x,
y,
mode, nnz;
1060 uint8_t tr_top[4] = { 127, 127, 127, 127 };
1070 tr = tr_right[-1]*0x01010101
u;
1077 for (y = 0; y < 4; y++) {
1079 for (x = 0; x < 4; x++) {
1087 topright = tr_right;
1092 dst = copy_dst + 12;
1096 AV_WN32A(copy_dst+4, 127
U * 0x01010101U);
1102 copy_dst[3] = ptr[4*x-s->
linesize-1];
1109 copy_dst[35] = 129
U;
1111 copy_dst[11] = ptr[4*x -1];
1112 copy_dst[19] = ptr[4*x+s->
linesize -1];
1113 copy_dst[27] = ptr[4*x+s->
linesize*2-1];
1114 copy_dst[35] = ptr[4*x+s->
linesize*3-1];
1158 { 0, 1, 2, 1, 2, 1, 2, 1 },
1160 { 0, 3, 5, 3, 5, 3, 5, 3 },
1161 { 0, 2, 3, 2, 3, 2, 3, 2 },
1183 int x_off,
int y_off,
int block_w,
int block_h,
1191 int mx = (mv->
x << 1)&7, mx_idx =
subpel_idx[0][mx];
1192 int my = (mv->
y << 1)&7, my_idx =
subpel_idx[0][my];
1194 x_off += mv->
x >> 2;
1195 y_off += mv->
y >> 2;
1199 src += y_off * linesize + x_off;
1200 if (x_off < mx_idx || x_off >= width - block_w -
subpel_idx[2][mx] ||
1201 y_off < my_idx || y_off >= height - block_h -
subpel_idx[2][my]) {
1204 x_off - mx_idx, y_off - my_idx, width, height);
1207 mc_func[my_idx][mx_idx](
dst, linesize, src, linesize, block_h, mx, my);
1210 mc_func[0][0](
dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0);
1234 int block_w,
int block_h,
int width,
int height,
int linesize,
1243 x_off += mv->
x >> 3;
1244 y_off += mv->
y >> 3;
1247 src1 += y_off * linesize + x_off;
1248 src2 += y_off * linesize + x_off;
1250 if (x_off < mx_idx || x_off >= width - block_w -
subpel_idx[2][mx] ||
1251 y_off < my_idx || y_off >= height - block_h -
subpel_idx[2][my]) {
1254 x_off - mx_idx, y_off - my_idx, width, height);
1256 mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my);
1260 x_off - mx_idx, y_off - my_idx, width, height);
1262 mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my);
1264 mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my);
1265 mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my);
1269 mc_func[0][0](dst1, linesize, src1 + y_off * linesize + x_off, linesize, block_h, 0, 0);
1270 mc_func[0][0](dst2, linesize, src2 + y_off * linesize + x_off, linesize, block_h, 0, 0);
1276 AVFrame *ref_frame,
int x_off,
int y_off,
1277 int bx_off,
int by_off,
1278 int block_w,
int block_h,
1285 ref_frame, mv, x_off + bx_off, y_off + by_off,
1286 block_w, block_h, width, height, s->
linesize,
1294 x_off >>= 1; y_off >>= 1;
1295 bx_off >>= 1; by_off >>= 1;
1296 width >>= 1; height >>= 1;
1297 block_w >>= 1; block_h >>= 1;
1299 dst[2] + by_off * s->
uvlinesize + bx_off, ref_frame,
1300 &uvmv, x_off + bx_off, y_off + by_off,
1301 block_w, block_h, width, height, s->
uvlinesize,
1310 if (s->
ref_count[ref-1] > (mb_xy >> 5)) {
1311 int x_off = mb_x << 4, y_off = mb_y << 4;
1312 int mx = (mb->
mv.
x>>2) + x_off + 8;
1313 int my = (mb->
mv.
y>>2) + y_off;
1320 off= (mx>>1) + ((my>>1) + (mb_x&7))*s->
uvlinesize + 64;
1332 int x_off = mb_x << 4, y_off = mb_y << 4;
1340 0, 0, 16, 16, width,
height, &mb->
mv);
1347 for (y = 0; y < 4; y++) {
1348 for (x = 0; x < 4; x++) {
1351 4*x + x_off, 4*y + y_off, 4, 4,
1358 x_off >>= 1; y_off >>= 1; width >>= 1;
height >>= 1;
1359 for (y = 0; y < 2; y++) {
1360 for (x = 0; x < 2; x++) {
1361 uvmv.
x = mb->
bmv[ 2*y * 4 + 2*x ].
x +
1362 mb->
bmv[ 2*y * 4 + 2*x+1].
x +
1363 mb->
bmv[(2*y+1) * 4 + 2*x ].x +
1364 mb->
bmv[(2*y+1) * 4 + 2*x+1].
x;
1365 uvmv.
y = mb->
bmv[ 2*y * 4 + 2*x ].
y +
1366 mb->
bmv[ 2*y * 4 + 2*x+1].
y +
1367 mb->
bmv[(2*y+1) * 4 + 2*x ].y +
1368 mb->
bmv[(2*y+1) * 4 + 2*x+1].
y;
1369 uvmv.
x = (uvmv.
x + 2 + (uvmv.
x >> (
INT_BIT-1))) >> 2;
1370 uvmv.
y = (uvmv.
y + 2 + (uvmv.
y >> (
INT_BIT-1))) >> 2;
1376 dst[2] + 4*y*s->
uvlinesize + x*4, ref, &uvmv,
1377 4*x + x_off, 4*y + y_off, 4, 4,
1386 0, 0, 16, 8, width,
height, &bmv[0]);
1388 0, 8, 16, 8, width,
height, &bmv[1]);
1392 0, 0, 8, 16, width,
height, &bmv[0]);
1394 8, 0, 8, 16, width,
height, &bmv[1]);
1398 0, 0, 8, 8, width,
height, &bmv[0]);
1400 8, 0, 8, 8, width,
height, &bmv[1]);
1402 0, 8, 8, 8, width,
height, &bmv[2]);
1404 8, 8, 8, 8, width,
height, &bmv[3]);
1416 for (y = 0; y < 4; y++) {
1419 if (nnz4&~0x01010101) {
1420 for (x = 0; x < 4; x++) {
1437 for (ch = 0; ch < 2; ch++) {
1441 if (nnz4&~0x01010101) {
1442 for (y = 0; y < 2; y++) {
1443 for (x = 0; x < 2; x++) {
1450 goto chroma_idct_end;
1464 int interior_limit, filter_level;
1478 filter_level = av_clip_uintp2(filter_level, 6);
1480 interior_limit = filter_level;
1485 interior_limit =
FFMAX(interior_limit, 1);
1494 int mbedge_lim, bedge_lim, hev_thresh;
1500 static const uint8_t hev_thresh_lut[2][64] = {
1501 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1502 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1503 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
1505 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1506 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1507 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1514 bedge_lim = 2*filter_level + inner_limit;
1515 mbedge_lim = bedge_lim + 4;
1517 hev_thresh = hev_thresh_lut[s->
keyframe][filter_level];
1521 mbedge_lim, inner_limit, hev_thresh);
1523 mbedge_lim, inner_limit, hev_thresh);
1528 inner_limit, hev_thresh);
1530 inner_limit, hev_thresh);
1532 inner_limit, hev_thresh);
1534 uvlinesize, bedge_lim,
1535 inner_limit, hev_thresh);
1540 mbedge_lim, inner_limit, hev_thresh);
1542 mbedge_lim, inner_limit, hev_thresh);
1547 linesize, bedge_lim,
1548 inner_limit, hev_thresh);
1550 linesize, bedge_lim,
1551 inner_limit, hev_thresh);
1553 linesize, bedge_lim,
1554 inner_limit, hev_thresh);
1556 dst[2] + 4 * uvlinesize,
1557 uvlinesize, bedge_lim,
1558 inner_limit, hev_thresh);
1564 int mbedge_lim, bedge_lim;
1573 bedge_lim = 2*filter_level + inner_limit;
1574 mbedge_lim = bedge_lim + 4;
1601 #define MARGIN (16 << 2)
1610 for (mb_y = 0; mb_y < s->
mb_height; mb_y++) {
1618 for (mb_x = 0; mb_x < s->
mb_width; mb_x++, mb_xy++, mb++) {
1632 #define check_thread_pos(td, otd, mb_x_check, mb_y_check)\
1634 int tmp = (mb_y_check << 16) | (mb_x_check & 0xFFFF);\
1635 if (otd->thread_mb_pos < tmp) {\
1636 pthread_mutex_lock(&otd->lock);\
1637 td->wait_mb_pos = tmp;\
1639 if (otd->thread_mb_pos >= tmp)\
1641 pthread_cond_wait(&otd->cond, &otd->lock);\
1643 td->wait_mb_pos = INT_MAX;\
1644 pthread_mutex_unlock(&otd->lock);\
1648 #define update_pos(td, mb_y, mb_x)\
1650 int pos = (mb_y << 16) | (mb_x & 0xFFFF);\
1651 int sliced_threading = (avctx->active_thread_type == FF_THREAD_SLICE) && (num_jobs > 1);\
1652 int is_null = (next_td == NULL) || (prev_td == NULL);\
1653 int pos_check = (is_null) ? 1 :\
1654 (next_td != td && pos >= next_td->wait_mb_pos) ||\
1655 (prev_td != td && pos >= prev_td->wait_mb_pos);\
1656 td->thread_mb_pos = pos;\
1657 if (sliced_threading && pos_check) {\
1658 pthread_mutex_lock(&td->lock);\
1659 pthread_cond_broadcast(&td->cond);\
1660 pthread_mutex_unlock(&td->lock);\
1664 #define check_thread_pos(td, otd, mb_x_check, mb_y_check)
1665 #define update_pos(td, mb_y, mb_x)
1669 int jobnr,
int threadnr)
1674 int i,
y, mb_x, mb_xy = mb_y*s->
mb_width;
1684 if (mb_y == 0) prev_td = td;
1685 else prev_td = &s->
thread_data[(jobnr + num_jobs - 1)%num_jobs];
1686 if (mb_y == s->
mb_height-1) next_td = td;
1687 else next_td = &s->
thread_data[(jobnr + 1)%num_jobs];
1692 memset(mb - 1, 0,
sizeof(*mb));
1699 for (i = 0; i < 3; i++)
1700 for (y = 0; y < 16>>!!i; y++)
1701 dst[i][y*curframe->
linesize[i]-1] = 129;
1710 for (mb_x = 0; mb_x < s->
mb_width; mb_x++, mb_xy++, mb++) {
1712 if (prev_td != td) {
1713 if (threadnr != 0) {
1725 prev_frame && prev_frame->ref_index[0] ? prev_frame->ref_index[0] + mb_xy :
NULL, 0);
1755 if (s->
deblock_filter && num_jobs != 1 && threadnr == num_jobs-1) {
1779 int jobnr,
int threadnr)
1798 if (mb_y == 0) prev_td = td;
1799 else prev_td = &s->
thread_data[(jobnr + num_jobs - 1)%num_jobs];
1800 if (mb_y == s->
mb_height-1) next_td = td;
1801 else next_td = &s->
thread_data[(jobnr + 1)%num_jobs];
1803 for (mb_x = 0; mb_x < s->
mb_width; mb_x++, mb++) {
1805 if (prev_td != td) {
1813 if (num_jobs == 1) {
1833 int jobnr,
int threadnr)
1841 for (mb_y = jobnr; mb_y < s->
mb_height; mb_y += num_jobs) {
1863 int ret, i, referenced, num_jobs;
1888 for (i = 0; i < 5; i++)
1890 &s->
frames[i] != prev_frame &&
1897 for (i = 0; i < 5; i++)
1898 if (&s->
frames[i] != prev_frame &&
1909 if (curframe->data[0])
1925 curframe->reference = referenced ? 3 : 0;
1951 s->
linesize = curframe->linesize[0];
2047 #define REBASE(pic) \
2048 pic ? pic - &s_src->frames[0] + &s->frames[0] : NULL
2062 s->
prob[0] = s_src->
prob[!s_src->update_probabilities];