OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1533 } | 1533 } |
1534 return 1; | 1534 return 1; |
1535 } | 1535 } |
1536 | 1536 |
1537 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, | 1537 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, |
1538 BLOCK_SIZE bsize, | 1538 BLOCK_SIZE bsize, |
1539 int_mv *frame_mv, | 1539 int_mv *frame_mv, |
1540 int mi_row, int mi_col, | 1540 int mi_row, int mi_col, |
1541 int_mv single_newmv[MAX_REF_FRAMES], | 1541 int_mv single_newmv[MAX_REF_FRAMES], |
1542 int *rate_mv) { | 1542 int *rate_mv) { |
| 1543 const VP9_COMMON *const cm = &cpi->common; |
1543 const int pw = 4 * num_4x4_blocks_wide_lookup[bsize]; | 1544 const int pw = 4 * num_4x4_blocks_wide_lookup[bsize]; |
1544 const int ph = 4 * num_4x4_blocks_high_lookup[bsize]; | 1545 const int ph = 4 * num_4x4_blocks_high_lookup[bsize]; |
1545 MACROBLOCKD *xd = &x->e_mbd; | 1546 MACROBLOCKD *xd = &x->e_mbd; |
1546 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; | 1547 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; |
1547 const int refs[2] = {mbmi->ref_frame[0], | 1548 const int refs[2] = {mbmi->ref_frame[0], |
1548 mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]}; | 1549 mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]}; |
1549 int_mv ref_mv[2]; | 1550 int_mv ref_mv[2]; |
1550 int ite, ref; | 1551 int ite, ref; |
1551 // Prediction buffer from second frame. | 1552 // Prediction buffer from second frame. |
1552 #if CONFIG_VP9_HIGHBITDEPTH | 1553 #if CONFIG_VP9_HIGHBITDEPTH |
1553 uint8_t *second_pred; | 1554 uint8_t *second_pred; |
1554 uint8_t *second_pred_alloc; | 1555 uint8_t *second_pred_alloc; |
1555 #else | 1556 #else |
1556 uint8_t *second_pred = vpx_memalign(16, pw * ph * sizeof(uint8_t)); | 1557 uint8_t *second_pred = vpx_memalign(16, pw * ph * sizeof(uint8_t)); |
1557 #endif // CONFIG_VP9_HIGHBITDEPTH | 1558 #endif // CONFIG_VP9_HIGHBITDEPTH |
1558 const InterpKernel *kernel = vp9_get_interp_kernel(mbmi->interp_filter); | 1559 const InterpKernel *kernel = vp9_get_interp_kernel(mbmi->interp_filter); |
| 1560 struct scale_factors sf; |
1559 | 1561 |
1560 // Do joint motion search in compound mode to get more accurate mv. | 1562 // Do joint motion search in compound mode to get more accurate mv. |
1561 struct buf_2d backup_yv12[2][MAX_MB_PLANE]; | 1563 struct buf_2d backup_yv12[2][MAX_MB_PLANE]; |
1562 int last_besterr[2] = {INT_MAX, INT_MAX}; | 1564 int last_besterr[2] = {INT_MAX, INT_MAX}; |
1563 const YV12_BUFFER_CONFIG *const scaled_ref_frame[2] = { | 1565 const YV12_BUFFER_CONFIG *const scaled_ref_frame[2] = { |
1564 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[0]), | 1566 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[0]), |
1565 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[1]) | 1567 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[1]) |
1566 }; | 1568 }; |
1567 #if CONFIG_VP9_HIGHBITDEPTH | 1569 #if CONFIG_VP9_HIGHBITDEPTH |
1568 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 1570 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
(...skipping 15 matching lines...) Expand all Loading... |
1584 // motion search code to be used without additional modifications. | 1586 // motion search code to be used without additional modifications. |
1585 for (i = 0; i < MAX_MB_PLANE; i++) | 1587 for (i = 0; i < MAX_MB_PLANE; i++) |
1586 backup_yv12[ref][i] = xd->plane[i].pre[ref]; | 1588 backup_yv12[ref][i] = xd->plane[i].pre[ref]; |
1587 vp9_setup_pre_planes(xd, ref, scaled_ref_frame[ref], mi_row, mi_col, | 1589 vp9_setup_pre_planes(xd, ref, scaled_ref_frame[ref], mi_row, mi_col, |
1588 NULL); | 1590 NULL); |
1589 } | 1591 } |
1590 | 1592 |
1591 frame_mv[refs[ref]].as_int = single_newmv[refs[ref]].as_int; | 1593 frame_mv[refs[ref]].as_int = single_newmv[refs[ref]].as_int; |
1592 } | 1594 } |
1593 | 1595 |
| 1596 // Since we have scaled the reference frames to match the size of the current |
| 1597 // frame we must use a unit scaling factor during mode selection. |
| 1598 #if CONFIG_VP9_HIGHBITDEPTH |
| 1599 vp9_setup_scale_factors_for_frame(&sf, cm->width, cm->height, |
| 1600 cm->width, cm->height, |
| 1601 cm->use_highbitdepth); |
| 1602 #else |
| 1603 vp9_setup_scale_factors_for_frame(&sf, cm->width, cm->height, |
| 1604 cm->width, cm->height); |
| 1605 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 1606 |
1594 // Allow joint search multiple times iteratively for each reference frame | 1607 // Allow joint search multiple times iteratively for each reference frame |
1595 // and break out of the search loop if it couldn't find a better mv. | 1608 // and break out of the search loop if it couldn't find a better mv. |
1596 for (ite = 0; ite < 4; ite++) { | 1609 for (ite = 0; ite < 4; ite++) { |
1597 struct buf_2d ref_yv12[2]; | 1610 struct buf_2d ref_yv12[2]; |
1598 int bestsme = INT_MAX; | 1611 int bestsme = INT_MAX; |
1599 int sadpb = x->sadperbit16; | 1612 int sadpb = x->sadperbit16; |
1600 MV tmp_mv; | 1613 MV tmp_mv; |
1601 int search_range = 3; | 1614 int search_range = 3; |
1602 | 1615 |
1603 int tmp_col_min = x->mv_col_min; | 1616 int tmp_col_min = x->mv_col_min; |
1604 int tmp_col_max = x->mv_col_max; | 1617 int tmp_col_max = x->mv_col_max; |
1605 int tmp_row_min = x->mv_row_min; | 1618 int tmp_row_min = x->mv_row_min; |
1606 int tmp_row_max = x->mv_row_max; | 1619 int tmp_row_max = x->mv_row_max; |
1607 int id = ite % 2; // Even iterations search in the first reference frame, | 1620 int id = ite % 2; // Even iterations search in the first reference frame, |
1608 // odd iterations search in the second. The predictor | 1621 // odd iterations search in the second. The predictor |
1609 // found for the 'other' reference frame is factored in. | 1622 // found for the 'other' reference frame is factored in. |
1610 | 1623 |
1611 // Initialized here because of compiler problem in Visual Studio. | 1624 // Initialized here because of compiler problem in Visual Studio. |
1612 ref_yv12[0] = xd->plane[0].pre[0]; | 1625 ref_yv12[0] = xd->plane[0].pre[0]; |
1613 ref_yv12[1] = xd->plane[0].pre[1]; | 1626 ref_yv12[1] = xd->plane[0].pre[1]; |
1614 | 1627 |
1615 // Get the prediction block from the 'other' reference frame. | 1628 // Get the prediction block from the 'other' reference frame. |
1616 #if CONFIG_VP9_HIGHBITDEPTH | 1629 #if CONFIG_VP9_HIGHBITDEPTH |
1617 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 1630 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
1618 vp9_highbd_build_inter_predictor(ref_yv12[!id].buf, | 1631 vp9_highbd_build_inter_predictor(ref_yv12[!id].buf, |
1619 ref_yv12[!id].stride, | 1632 ref_yv12[!id].stride, |
1620 second_pred, pw, | 1633 second_pred, pw, |
1621 &frame_mv[refs[!id]].as_mv, | 1634 &frame_mv[refs[!id]].as_mv, |
1622 &xd->block_refs[!id]->sf, | 1635 &sf, pw, ph, 0, |
1623 pw, ph, 0, | |
1624 kernel, MV_PRECISION_Q3, | 1636 kernel, MV_PRECISION_Q3, |
1625 mi_col * MI_SIZE, mi_row * MI_SIZE, | 1637 mi_col * MI_SIZE, mi_row * MI_SIZE, |
1626 xd->bd); | 1638 xd->bd); |
1627 } else { | 1639 } else { |
1628 vp9_build_inter_predictor(ref_yv12[!id].buf, | 1640 vp9_build_inter_predictor(ref_yv12[!id].buf, |
1629 ref_yv12[!id].stride, | 1641 ref_yv12[!id].stride, |
1630 second_pred, pw, | 1642 second_pred, pw, |
1631 &frame_mv[refs[!id]].as_mv, | 1643 &frame_mv[refs[!id]].as_mv, |
1632 &xd->block_refs[!id]->sf, | 1644 &sf, pw, ph, 0, |
1633 pw, ph, 0, | |
1634 kernel, MV_PRECISION_Q3, | 1645 kernel, MV_PRECISION_Q3, |
1635 mi_col * MI_SIZE, mi_row * MI_SIZE); | 1646 mi_col * MI_SIZE, mi_row * MI_SIZE); |
1636 } | 1647 } |
1637 #else | 1648 #else |
1638 vp9_build_inter_predictor(ref_yv12[!id].buf, | 1649 vp9_build_inter_predictor(ref_yv12[!id].buf, |
1639 ref_yv12[!id].stride, | 1650 ref_yv12[!id].stride, |
1640 second_pred, pw, | 1651 second_pred, pw, |
1641 &frame_mv[refs[!id]].as_mv, | 1652 &frame_mv[refs[!id]].as_mv, |
1642 &xd->block_refs[!id]->sf, | 1653 &sf, pw, ph, 0, |
1643 pw, ph, 0, | |
1644 kernel, MV_PRECISION_Q3, | 1654 kernel, MV_PRECISION_Q3, |
1645 mi_col * MI_SIZE, mi_row * MI_SIZE); | 1655 mi_col * MI_SIZE, mi_row * MI_SIZE); |
1646 #endif // CONFIG_VP9_HIGHBITDEPTH | 1656 #endif // CONFIG_VP9_HIGHBITDEPTH |
1647 | 1657 |
1648 // Do compound motion search on the current reference frame. | 1658 // Do compound motion search on the current reference frame. |
1649 if (id) | 1659 if (id) |
1650 xd->plane[0].pre[0] = ref_yv12[id]; | 1660 xd->plane[0].pre[0] = ref_yv12[id]; |
1651 vp9_set_mv_search_range(x, &ref_mv[id].as_mv); | 1661 vp9_set_mv_search_range(x, &ref_mv[id].as_mv); |
1652 | 1662 |
1653 // Use the mv result from the single mode as mv predictor. | 1663 // Use the mv result from the single mode as mv predictor. |
(...skipping 2577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4231 } | 4241 } |
4232 if (cm->interp_filter == SWITCHABLE) | 4242 if (cm->interp_filter == SWITCHABLE) |
4233 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); | 4243 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); |
4234 } else { | 4244 } else { |
4235 vp9_zero(best_filter_diff); | 4245 vp9_zero(best_filter_diff); |
4236 } | 4246 } |
4237 | 4247 |
4238 store_coding_context(x, ctx, best_ref_index, | 4248 store_coding_context(x, ctx, best_ref_index, |
4239 best_pred_diff, best_tx_diff, best_filter_diff, 0); | 4249 best_pred_diff, best_tx_diff, best_filter_diff, 0); |
4240 } | 4250 } |
OLD | NEW |