170 for (i = 0; i < 4; i++)
173 for (i = 0; i < 4; i++)
177 for (i = 0; i < 3; i++)
186 for (i = 0; i < 4; i++) {
219 if (buf_size - size < 0)
243 for (i = 0; i < 4; i++) {
307 int header_size, hscale, vscale, i, j, k, l,
m,
ret;
314 header_size =
AV_RL24(buf) >> 5;
326 if (header_size > buf_size - 7*s->
keyframe) {
332 if (
AV_RL24(buf) != 0x2a019d) {
336 width =
AV_RL16(buf+3) & 0x3fff;
337 height =
AV_RL16(buf+5) & 0x3fff;
338 hscale = buf[4] >> 6;
339 vscale = buf[6] >> 6;
343 if (hscale || vscale)
347 for (i = 0; i < 4; i++)
348 for (j = 0; j < 16; j++)
360 buf_size -= header_size;
407 for (i = 0; i < 4; i++)
408 for (j = 0; j < 8; j++)
409 for (k = 0; k < 3; k++)
426 for (i = 0; i < 4; i++)
429 for (i = 0; i < 3; i++)
433 for (i = 0; i < 2; i++)
434 for (j = 0; j < 19; j++)
458 for (i = 0; i < 3; i++)
460 for (i = 9; i > 3; i--)
502 *mbsplits_cur, *firstidx;
512 top_mv = top_mb->
bmv;
529 for (n = 0; n < num; n++) {
531 uint32_t left, above;
535 left =
AV_RN32A(&left_mv[mbsplits_left[k + 3]]);
537 left =
AV_RN32A(&cur_mv[mbsplits_cur[k - 1]]);
539 above =
AV_RN32A(&top_mv[mbsplits_top[k + 12]]);
541 above =
AV_RN32A(&cur_mv[mbsplits_cur[k - 4]]);
570 enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV };
571 enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT };
593 #define MV_EDGE_CHECK(n)\
595 VP8Macroblock *edge = mb_edge[n];\
596 int edge_ref = edge->ref_frame;\
597 if (edge_ref != VP56_FRAME_CURRENT) {\
598 uint32_t mv = AV_RN32A(&edge->mv);\
600 if (cur_sign_bias != sign_bias[edge_ref]) {\
603 mv = ((mv&0x7fff7fff) + 0x00010001) ^ (mv&0x80008000);\
605 if (!n || mv != AV_RN32A(&near_mv[idx]))\
606 AV_WN32A(&near_mv[++idx], mv);\
607 cnt[idx] += 1 + (n != 2);\
609 cnt[CNT_ZERO] += 1 + (n != 2);\
622 if (cnt[CNT_SPLITMV] &&
AV_RN32A(&near_mv[1 + VP8_EDGE_TOP]) ==
AV_RN32A(&near_mv[1 + VP8_EDGE_TOPLEFT]))
623 cnt[CNT_NEAREST] += 1;
626 if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) {
628 FFSWAP(
VP56mv, near_mv[CNT_NEAREST], near_mv[CNT_NEAR]);
635 clamp_mv(s, &mb->
mv, &near_mv[CNT_ZERO + (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])]);
665 int mb_x,
int keyframe,
int layout)
681 for (y = 0; y < 4; y++) {
682 for (x = 0; x < 4; x++) {
686 left[
y] = top[x] = *intra4x4;
692 for (i = 0; i < 16; i++)
707 *segment = ref ? *ref : *segment;
753 #ifndef decode_block_coeffs_internal
765 int i,
uint8_t *token_prob, int16_t qmul[2])
778 token_prob = probs[i][0];
784 token_prob = probs[i+1][1];
804 int cat = (a<<1) + b;
805 coeff = 3 + (8<<cat);
809 token_prob = probs[i+1][2];
833 int i,
int zero_nhood, int16_t qmul[2])
835 uint8_t *token_prob = probs[i][zero_nhood];
845 int i, x,
y, luma_start = 0, luma_ctx = 3;
846 int nnz_pred, nnz, nnz_total = 0;
851 nnz_pred = t_nnz[8] + l_nnz[8];
856 l_nnz[8] = t_nnz[8] = !!nnz;
870 for (y = 0; y < 4; y++)
871 for (x = 0; x < 4; x++) {
872 nnz_pred = l_nnz[
y] + t_nnz[x];
877 t_nnz[x] = l_nnz[
y] = !!nnz;
884 for (i = 4; i < 6; i++)
885 for (y = 0; y < 2; y++)
886 for (x = 0; x < 2; x++) {
887 nnz_pred = l_nnz[i+2*
y] + t_nnz[i+2*x];
891 t_nnz[i+2*x] = l_nnz[i+2*
y] = !!nnz;
904 int linesize,
int uvlinesize,
int simple)
908 AV_COPY64(top_border+16, src_cb + 7*uvlinesize);
909 AV_COPY64(top_border+24, src_cr + 7*uvlinesize);
915 int linesize,
int uvlinesize,
int mb_x,
int mb_y,
int mb_width,
916 int simple,
int xchg)
918 uint8_t *top_border_m1 = top_border-32;
920 src_cb -= uvlinesize;
921 src_cr -= uvlinesize;
923 #define XCHG(a,b,xchg) do { \
924 if (xchg) AV_SWAP64(b,a); \
925 else AV_COPY64(b,a); \
928 XCHG(top_border_m1+8, src_y-8, xchg);
929 XCHG(top_border, src_y, xchg);
930 XCHG(top_border+8, src_y+8, 1);
931 if (mb_x < mb_width-1)
932 XCHG(top_border+32, src_y+16, 1);
936 if (!simple || !mb_y) {
937 XCHG(top_border_m1+16, src_cb-8, xchg);
938 XCHG(top_border_m1+24, src_cr-8, xchg);
939 XCHG(top_border+16, src_cb, 1);
940 XCHG(top_border+24, src_cr, 1);
1005 if (!mb_x && mb_y) {
1039 int x,
y,
mode, nnz;
1059 uint8_t tr_top[4] = { 127, 127, 127, 127 };
1069 tr = tr_right[-1]*0x01010101
u;
1076 for (y = 0; y < 4; y++) {
1078 for (x = 0; x < 4; x++) {
1086 topright = tr_right;
1091 dst = copy_dst + 12;
1095 AV_WN32A(copy_dst+4, 127
U * 0x01010101U);
1101 copy_dst[3] = ptr[4*x-s->
linesize-1];
1108 copy_dst[35] = 129
U;
1110 copy_dst[11] = ptr[4*x -1];
1111 copy_dst[19] = ptr[4*x+s->
linesize -1];
1112 copy_dst[27] = ptr[4*x+s->
linesize*2-1];
1113 copy_dst[35] = ptr[4*x+s->
linesize*3-1];
1157 { 0, 1, 2, 1, 2, 1, 2, 1 },
1159 { 0, 3, 5, 3, 5, 3, 5, 3 },
1160 { 0, 2, 3, 2, 3, 2, 3, 2 },
1182 int x_off,
int y_off,
int block_w,
int block_h,
1190 int mx = (mv->
x << 1)&7, mx_idx =
subpel_idx[0][mx];
1191 int my = (mv->
y << 1)&7, my_idx =
subpel_idx[0][my];
1193 x_off += mv->
x >> 2;
1194 y_off += mv->
y >> 2;
1198 src += y_off * linesize + x_off;
1199 if (x_off < mx_idx || x_off >= width - block_w -
subpel_idx[2][mx] ||
1200 y_off < my_idx || y_off >= height - block_h -
subpel_idx[2][my]) {
1203 x_off - mx_idx, y_off - my_idx, width, height);
1206 mc_func[my_idx][mx_idx](dst, linesize,
src, linesize, block_h, mx, my);
1209 mc_func[0][0](dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0);
1233 int block_w,
int block_h,
int width,
int height,
int linesize,
1242 x_off += mv->
x >> 3;
1243 y_off += mv->
y >> 3;
1246 src1 += y_off * linesize + x_off;
1247 src2 += y_off * linesize + x_off;
1249 if (x_off < mx_idx || x_off >= width - block_w -
subpel_idx[2][mx] ||
1250 y_off < my_idx || y_off >= height - block_h -
subpel_idx[2][my]) {
1253 x_off - mx_idx, y_off - my_idx, width, height);
1255 mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my);
1259 x_off - mx_idx, y_off - my_idx, width, height);
1261 mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my);
1263 mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my);
1264 mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my);
1268 mc_func[0][0](dst1, linesize, src1 + y_off * linesize + x_off, linesize, block_h, 0, 0);
1269 mc_func[0][0](dst2, linesize, src2 + y_off * linesize + x_off, linesize, block_h, 0, 0);
1276 int bx_off,
int by_off,
1277 int block_w,
int block_h,
1284 ref_frame, mv, x_off + bx_off, y_off + by_off,
1285 block_w, block_h, width, height, s->
linesize,
1293 x_off >>= 1; y_off >>= 1;
1294 bx_off >>= 1; by_off >>= 1;
1295 width >>= 1; height >>= 1;
1296 block_w >>= 1; block_h >>= 1;
1298 dst[2] + by_off * s->
uvlinesize + bx_off, ref_frame,
1299 &uvmv, x_off + bx_off, y_off + by_off,
1300 block_w, block_h, width, height, s->
uvlinesize,
1309 if (s->
ref_count[ref-1] > (mb_xy >> 5)) {
1310 int x_off = mb_x << 4, y_off = mb_y << 4;
1311 int mx = (mb->
mv.
x>>2) + x_off + 8;
1312 int my = (mb->
mv.
y>>2) + y_off;
1319 off= (mx>>1) + ((my>>1) + (mb_x&7))*s->
uvlinesize + 64;
1331 int x_off = mb_x << 4, y_off = mb_y << 4;
1339 0, 0, 16, 16, width,
height, &mb->
mv);
1346 for (y = 0; y < 4; y++) {
1347 for (x = 0; x < 4; x++) {
1350 4*x + x_off, 4*y + y_off, 4, 4,
1357 x_off >>= 1; y_off >>= 1; width >>= 1;
height >>= 1;
1358 for (y = 0; y < 2; y++) {
1359 for (x = 0; x < 2; x++) {
1360 uvmv.
x = mb->
bmv[ 2*y * 4 + 2*x ].
x +
1361 mb->
bmv[ 2*y * 4 + 2*x+1].
x +
1362 mb->
bmv[(2*y+1) * 4 + 2*x ].x +
1363 mb->
bmv[(2*y+1) * 4 + 2*x+1].
x;
1364 uvmv.
y = mb->
bmv[ 2*y * 4 + 2*x ].
y +
1365 mb->
bmv[ 2*y * 4 + 2*x+1].
y +
1366 mb->
bmv[(2*y+1) * 4 + 2*x ].y +
1367 mb->
bmv[(2*y+1) * 4 + 2*x+1].
y;
1368 uvmv.
x = (uvmv.
x + 2 + (uvmv.
x >> (
INT_BIT-1))) >> 2;
1369 uvmv.
y = (uvmv.
y + 2 + (uvmv.
y >> (
INT_BIT-1))) >> 2;
1375 dst[2] + 4*y*s->
uvlinesize + x*4, ref, &uvmv,
1376 4*x + x_off, 4*y + y_off, 4, 4,
1385 0, 0, 16, 8, width,
height, &bmv[0]);
1387 0, 8, 16, 8, width,
height, &bmv[1]);
1391 0, 0, 8, 16, width,
height, &bmv[0]);
1393 8, 0, 8, 16, width,
height, &bmv[1]);
1397 0, 0, 8, 8, width,
height, &bmv[0]);
1399 8, 0, 8, 8, width,
height, &bmv[1]);
1401 0, 8, 8, 8, width,
height, &bmv[2]);
1403 8, 8, 8, 8, width,
height, &bmv[3]);
1415 for (y = 0; y < 4; y++) {
1418 if (nnz4&~0x01010101) {
1419 for (x = 0; x < 4; x++) {
1436 for (ch = 0; ch < 2; ch++) {
1440 if (nnz4&~0x01010101) {
1441 for (y = 0; y < 2; y++) {
1442 for (x = 0; x < 2; x++) {
1449 goto chroma_idct_end;
1463 int interior_limit, filter_level;
1477 filter_level = av_clip_uintp2(filter_level, 6);
1479 interior_limit = filter_level;
1484 interior_limit =
FFMAX(interior_limit, 1);
1493 int mbedge_lim, bedge_lim, hev_thresh;
1499 static const uint8_t hev_thresh_lut[2][64] = {
1500 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1501 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1502 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
1504 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1505 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1506 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1513 bedge_lim = 2*filter_level + inner_limit;
1514 mbedge_lim = bedge_lim + 4;
1516 hev_thresh = hev_thresh_lut[s->
keyframe][filter_level];
1520 mbedge_lim, inner_limit, hev_thresh);
1522 mbedge_lim, inner_limit, hev_thresh);
1527 inner_limit, hev_thresh);
1529 inner_limit, hev_thresh);
1531 inner_limit, hev_thresh);
1533 uvlinesize, bedge_lim,
1534 inner_limit, hev_thresh);
1539 mbedge_lim, inner_limit, hev_thresh);
1541 mbedge_lim, inner_limit, hev_thresh);
1546 linesize, bedge_lim,
1547 inner_limit, hev_thresh);
1549 linesize, bedge_lim,
1550 inner_limit, hev_thresh);
1552 linesize, bedge_lim,
1553 inner_limit, hev_thresh);
1555 dst[2] + 4 * uvlinesize,
1556 uvlinesize, bedge_lim,
1557 inner_limit, hev_thresh);
1563 int mbedge_lim, bedge_lim;
1572 bedge_lim = 2*filter_level + inner_limit;
1573 mbedge_lim = bedge_lim + 4;
1592 #define MARGIN (16 << 2)
1601 for (mb_y = 0; mb_y < s->
mb_height; mb_y++) {
1609 for (mb_x = 0; mb_x < s->
mb_width; mb_x++, mb_xy++, mb++) {
1613 prev_frame && prev_frame->
seg_map ?
1624 #define check_thread_pos(td, otd, mb_x_check, mb_y_check)\
1626 int tmp = (mb_y_check << 16) | (mb_x_check & 0xFFFF);\
1627 if (otd->thread_mb_pos < tmp) {\
1628 pthread_mutex_lock(&otd->lock);\
1629 td->wait_mb_pos = tmp;\
1631 if (otd->thread_mb_pos >= tmp)\
1633 pthread_cond_wait(&otd->cond, &otd->lock);\
1635 td->wait_mb_pos = INT_MAX;\
1636 pthread_mutex_unlock(&otd->lock);\
1640 #define update_pos(td, mb_y, mb_x)\
1642 int pos = (mb_y << 16) | (mb_x & 0xFFFF);\
1643 int sliced_threading = (avctx->active_thread_type == FF_THREAD_SLICE) && (num_jobs > 1);\
1644 int is_null = (next_td == NULL) || (prev_td == NULL);\
1645 int pos_check = (is_null) ? 1 :\
1646 (next_td != td && pos >= next_td->wait_mb_pos) ||\
1647 (prev_td != td && pos >= prev_td->wait_mb_pos);\
1648 td->thread_mb_pos = pos;\
1649 if (sliced_threading && pos_check) {\
1650 pthread_mutex_lock(&td->lock);\
1651 pthread_cond_broadcast(&td->cond);\
1652 pthread_mutex_unlock(&td->lock);\
1656 #define check_thread_pos(td, otd, mb_x_check, mb_y_check)
1657 #define update_pos(td, mb_y, mb_x)
1661 int jobnr,
int threadnr)
1666 int i,
y, mb_x, mb_xy = mb_y*s->
mb_width;
1676 if (mb_y == 0) prev_td =
td;
1677 else prev_td = &s->
thread_data[(jobnr + num_jobs - 1)%num_jobs];
1679 else next_td = &s->
thread_data[(jobnr + 1)%num_jobs];
1689 memset(mb - 1, 0,
sizeof(*mb));
1696 for (i = 0; i < 3; i++)
1697 for (y = 0; y < 16>>!!i; y++)
1707 for (mb_x = 0; mb_x < s->
mb_width; mb_x++, mb_xy++, mb++) {
1709 if (prev_td != td) {
1710 if (threadnr != 0) {
1722 prev_frame && prev_frame->seg_map ?
1723 prev_frame->seg_map->data + mb_xy : NULL, 0);
1753 if (s->
deblock_filter && num_jobs != 1 && threadnr == num_jobs-1) {
1777 int jobnr,
int threadnr)
1796 if (mb_y == 0) prev_td =
td;
1797 else prev_td = &s->
thread_data[(jobnr + num_jobs - 1)%num_jobs];
1799 else next_td = &s->
thread_data[(jobnr + 1)%num_jobs];
1801 for (mb_x = 0; mb_x < s->
mb_width; mb_x++, mb++) {
1803 if (prev_td != td) {
1811 if (num_jobs == 1) {
1831 int jobnr,
int threadnr)
1839 for (mb_y = jobnr; mb_y < s->
mb_height; mb_y += num_jobs) {
1861 int ret, i, referenced, num_jobs;
1884 for (i = 0; i < 5; i++)
1886 &s->
frames[i] != prev_frame &&
1893 for (i = 0; i < 5; i++)
1894 if (&s->
frames[i] != prev_frame &&
1905 if (curframe->tf.f->data[0])
1919 curframe->tf.f->key_frame = s->
keyframe;
1944 s->
linesize = curframe->tf.f->linesize[0];
2071 #define REBASE(pic) \
2072 pic ? pic - &s_src->frames[0] + &s->frames[0] : NULL
2086 s->
prob[0] = s_src->
prob[!s_src->update_probabilities];
2092 if (s_src->frames[i].tf.f->data[0]) {
2113 int buf_size = avpkt->
size;
2122 if (buf_size < 8 || riff_size < 8) {
2148 pkt.
size = buf_size;