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 |
11 #include <assert.h> | 11 #include <assert.h> |
12 #include <limits.h> | |
13 #include <math.h> | 12 #include <math.h> |
14 #include <stdio.h> | 13 #include <stdio.h> |
15 | 14 |
16 #include "./vp9_rtcd.h" | 15 #include "./vp9_rtcd.h" |
17 | 16 |
18 #include "vpx_mem/vpx_mem.h" | 17 #include "vpx_mem/vpx_mem.h" |
19 | 18 |
20 #include "vp9/common/vp9_common.h" | 19 #include "vp9/common/vp9_common.h" |
21 #include "vp9/common/vp9_entropy.h" | 20 #include "vp9/common/vp9_entropy.h" |
22 #include "vp9/common/vp9_entropymode.h" | 21 #include "vp9/common/vp9_entropymode.h" |
23 #include "vp9/common/vp9_idct.h" | 22 #include "vp9/common/vp9_idct.h" |
24 #include "vp9/common/vp9_mvref_common.h" | 23 #include "vp9/common/vp9_mvref_common.h" |
25 #include "vp9/common/vp9_pragmas.h" | |
26 #include "vp9/common/vp9_pred_common.h" | 24 #include "vp9/common/vp9_pred_common.h" |
27 #include "vp9/common/vp9_quant_common.h" | 25 #include "vp9/common/vp9_quant_common.h" |
28 #include "vp9/common/vp9_reconinter.h" | 26 #include "vp9/common/vp9_reconinter.h" |
29 #include "vp9/common/vp9_reconintra.h" | 27 #include "vp9/common/vp9_reconintra.h" |
30 #include "vp9/common/vp9_seg_common.h" | 28 #include "vp9/common/vp9_seg_common.h" |
31 #include "vp9/common/vp9_systemdependent.h" | 29 #include "vp9/common/vp9_systemdependent.h" |
32 | 30 |
33 #include "vp9/encoder/vp9_cost.h" | 31 #include "vp9/encoder/vp9_cost.h" |
34 #include "vp9/encoder/vp9_encodemb.h" | 32 #include "vp9/encoder/vp9_encodemb.h" |
35 #include "vp9/encoder/vp9_encodemv.h" | 33 #include "vp9/encoder/vp9_encodemv.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // TODO(debargha): Adjust the function below | 233 // TODO(debargha): Adjust the function below |
236 const int q = (int)(pow(vp9_dc_quant(qindex, 0) / 4.0, RD_THRESH_POW) * 5.12); | 234 const int q = (int)(pow(vp9_dc_quant(qindex, 0) / 4.0, RD_THRESH_POW) * 5.12); |
237 return MAX(q, 8); | 235 return MAX(q, 8); |
238 } | 236 } |
239 | 237 |
240 void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex) { | 238 void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex) { |
241 cpi->mb.sadperbit16 = sad_per_bit16lut[qindex]; | 239 cpi->mb.sadperbit16 = sad_per_bit16lut[qindex]; |
242 cpi->mb.sadperbit4 = sad_per_bit4lut[qindex]; | 240 cpi->mb.sadperbit4 = sad_per_bit4lut[qindex]; |
243 } | 241 } |
244 | 242 |
| 243 static void swap_block_ptr(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, |
| 244 int m, int n, int min_plane, int max_plane) { |
| 245 int i; |
| 246 |
| 247 for (i = min_plane; i < max_plane; ++i) { |
| 248 struct macroblock_plane *const p = &x->plane[i]; |
| 249 struct macroblockd_plane *const pd = &x->e_mbd.plane[i]; |
| 250 |
| 251 p->coeff = ctx->coeff_pbuf[i][m]; |
| 252 p->qcoeff = ctx->qcoeff_pbuf[i][m]; |
| 253 pd->dqcoeff = ctx->dqcoeff_pbuf[i][m]; |
| 254 p->eobs = ctx->eobs_pbuf[i][m]; |
| 255 |
| 256 ctx->coeff_pbuf[i][m] = ctx->coeff_pbuf[i][n]; |
| 257 ctx->qcoeff_pbuf[i][m] = ctx->qcoeff_pbuf[i][n]; |
| 258 ctx->dqcoeff_pbuf[i][m] = ctx->dqcoeff_pbuf[i][n]; |
| 259 ctx->eobs_pbuf[i][m] = ctx->eobs_pbuf[i][n]; |
| 260 |
| 261 ctx->coeff_pbuf[i][n] = p->coeff; |
| 262 ctx->qcoeff_pbuf[i][n] = p->qcoeff; |
| 263 ctx->dqcoeff_pbuf[i][n] = pd->dqcoeff; |
| 264 ctx->eobs_pbuf[i][n] = p->eobs; |
| 265 } |
| 266 } |
| 267 |
245 static void set_block_thresholds(const VP9_COMMON *cm, RD_OPT *rd) { | 268 static void set_block_thresholds(const VP9_COMMON *cm, RD_OPT *rd) { |
246 int i, bsize, segment_id; | 269 int i, bsize, segment_id; |
247 | 270 |
248 for (segment_id = 0; segment_id < MAX_SEGMENTS; ++segment_id) { | 271 for (segment_id = 0; segment_id < MAX_SEGMENTS; ++segment_id) { |
249 const int qindex = clamp(vp9_get_qindex(&cm->seg, segment_id, | 272 const int qindex = clamp(vp9_get_qindex(&cm->seg, segment_id, |
250 cm->base_qindex) + cm->y_dc_delta_q, | 273 cm->base_qindex) + cm->y_dc_delta_q, |
251 0, MAXQ); | 274 0, MAXQ); |
252 const int q = compute_rd_thresh_factor(qindex); | 275 const int q = compute_rd_thresh_factor(qindex); |
253 | 276 |
254 for (bsize = 0; bsize < BLOCK_SIZES; ++bsize) { | 277 for (bsize = 0; bsize < BLOCK_SIZES; ++bsize) { |
(...skipping 26 matching lines...) Expand all Loading... |
281 int i; | 304 int i; |
282 | 305 |
283 vp9_clear_system_state(); | 306 vp9_clear_system_state(); |
284 | 307 |
285 rd->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128) | 308 rd->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128) |
286 rd->RDMULT = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q); | 309 rd->RDMULT = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q); |
287 | 310 |
288 x->errorperbit = rd->RDMULT / RD_MULT_EPB_RATIO; | 311 x->errorperbit = rd->RDMULT / RD_MULT_EPB_RATIO; |
289 x->errorperbit += (x->errorperbit == 0); | 312 x->errorperbit += (x->errorperbit == 0); |
290 | 313 |
291 x->select_txfm_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL && | 314 x->select_tx_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL && |
292 cm->frame_type != KEY_FRAME) ? 0 : 1; | 315 cm->frame_type != KEY_FRAME) ? 0 : 1; |
293 | 316 |
294 set_block_thresholds(cm, rd); | 317 set_block_thresholds(cm, rd); |
295 | 318 |
296 if (!cpi->sf.use_nonrd_pick_mode || cm->frame_type == KEY_FRAME) { | 319 if (!cpi->sf.use_nonrd_pick_mode || cm->frame_type == KEY_FRAME) { |
297 fill_token_costs(x->token_costs, cm->fc.coef_probs); | 320 fill_token_costs(x->token_costs, cm->fc.coef_probs); |
298 | 321 |
299 for (i = 0; i < PARTITION_CONTEXTS; i++) | 322 for (i = 0; i < PARTITION_CONTEXTS; i++) |
300 vp9_cost_tokens(x->partition_cost[i], get_partition_probs(cm, i), | 323 vp9_cost_tokens(cpi->partition_cost[i], get_partition_probs(cm, i), |
301 vp9_partition_tree); | 324 vp9_partition_tree); |
302 } | 325 } |
303 | 326 |
304 if (!cpi->sf.use_nonrd_pick_mode || (cm->current_video_frame & 0x07) == 1 || | 327 if (!cpi->sf.use_nonrd_pick_mode || (cm->current_video_frame & 0x07) == 1 || |
305 cm->frame_type == KEY_FRAME) { | 328 cm->frame_type == KEY_FRAME) { |
306 fill_mode_costs(cpi); | 329 fill_mode_costs(cpi); |
307 | 330 |
308 if (!frame_is_intra_only(cm)) { | 331 if (!frame_is_intra_only(cm)) { |
309 vp9_build_nmv_cost_table(x->nmvjointcost, | 332 vp9_build_nmv_cost_table(x->nmvjointcost, |
310 cm->allow_high_precision_mv ? x->nmvcost_hp | 333 cm->allow_high_precision_mv ? x->nmvcost_hp |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 *sse = INT64_MAX; | 789 *sse = INT64_MAX; |
767 *skippable = 0; | 790 *skippable = 0; |
768 } else { | 791 } else { |
769 *distortion = args.this_dist; | 792 *distortion = args.this_dist; |
770 *rate = args.this_rate; | 793 *rate = args.this_rate; |
771 *sse = args.this_sse; | 794 *sse = args.this_sse; |
772 *skippable = vp9_is_skippable_in_plane(x, bsize, plane); | 795 *skippable = vp9_is_skippable_in_plane(x, bsize, plane); |
773 } | 796 } |
774 } | 797 } |
775 | 798 |
776 static void choose_largest_txfm_size(VP9_COMP *cpi, MACROBLOCK *x, | 799 static void choose_largest_tx_size(VP9_COMP *cpi, MACROBLOCK *x, |
777 int *rate, int64_t *distortion, | 800 int *rate, int64_t *distortion, |
778 int *skip, int64_t *sse, | 801 int *skip, int64_t *sse, |
779 int64_t ref_best_rd, | 802 int64_t ref_best_rd, |
780 BLOCK_SIZE bs) { | 803 BLOCK_SIZE bs) { |
781 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 804 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
782 VP9_COMMON *const cm = &cpi->common; | 805 VP9_COMMON *const cm = &cpi->common; |
783 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; | 806 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; |
784 MACROBLOCKD *const xd = &x->e_mbd; | 807 MACROBLOCKD *const xd = &x->e_mbd; |
785 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 808 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
786 | 809 |
787 mbmi->tx_size = MIN(max_tx_size, largest_tx_size); | 810 mbmi->tx_size = MIN(max_tx_size, largest_tx_size); |
788 | 811 |
789 txfm_rd_in_plane(x, rate, distortion, skip, | 812 txfm_rd_in_plane(x, rate, distortion, skip, |
790 &sse[mbmi->tx_size], ref_best_rd, 0, bs, | 813 &sse[mbmi->tx_size], ref_best_rd, 0, bs, |
791 mbmi->tx_size, cpi->sf.use_fast_coef_costing); | 814 mbmi->tx_size, cpi->sf.use_fast_coef_costing); |
792 cpi->tx_stepdown_count[0]++; | 815 cpi->tx_stepdown_count[0]++; |
793 } | 816 } |
794 | 817 |
795 static void choose_txfm_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, | 818 static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, |
796 int (*r)[2], int *rate, | 819 int (*r)[2], int *rate, |
797 int64_t *d, int64_t *distortion, | 820 int64_t *d, int64_t *distortion, |
798 int *s, int *skip, | 821 int *s, int *skip, |
799 int64_t tx_cache[TX_MODES], | 822 int64_t tx_cache[TX_MODES], |
800 BLOCK_SIZE bs) { | 823 BLOCK_SIZE bs) { |
801 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 824 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
802 VP9_COMMON *const cm = &cpi->common; | 825 VP9_COMMON *const cm = &cpi->common; |
803 MACROBLOCKD *const xd = &x->e_mbd; | 826 MACROBLOCKD *const xd = &x->e_mbd; |
804 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 827 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
805 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); | 828 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); |
806 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, | 829 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, |
807 {INT64_MAX, INT64_MAX}, | 830 {INT64_MAX, INT64_MAX}, |
808 {INT64_MAX, INT64_MAX}, | 831 {INT64_MAX, INT64_MAX}, |
809 {INT64_MAX, INT64_MAX}}; | 832 {INT64_MAX, INT64_MAX}}; |
810 TX_SIZE n, m; | 833 TX_SIZE n, m; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 tx_cache[TX_MODE_SELECT] = rd[TX_4X4][1]; | 891 tx_cache[TX_MODE_SELECT] = rd[TX_4X4][1]; |
869 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; | 892 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; |
870 } | 893 } |
871 } | 894 } |
872 | 895 |
873 static int64_t scaled_rd_cost(int rdmult, int rddiv, | 896 static int64_t scaled_rd_cost(int rdmult, int rddiv, |
874 int rate, int64_t dist, double scale) { | 897 int rate, int64_t dist, double scale) { |
875 return (int64_t) (RDCOST(rdmult, rddiv, rate, dist) * scale); | 898 return (int64_t) (RDCOST(rdmult, rddiv, rate, dist) * scale); |
876 } | 899 } |
877 | 900 |
878 static void choose_txfm_size_from_modelrd(VP9_COMP *cpi, MACROBLOCK *x, | 901 static void choose_tx_size_from_modelrd(VP9_COMP *cpi, MACROBLOCK *x, |
879 int (*r)[2], int *rate, | 902 int (*r)[2], int *rate, |
880 int64_t *d, int64_t *distortion, | 903 int64_t *d, int64_t *distortion, |
881 int *s, int *skip, int64_t *sse, | 904 int *s, int *skip, int64_t *sse, |
882 int64_t ref_best_rd, | 905 int64_t ref_best_rd, |
883 BLOCK_SIZE bs) { | 906 BLOCK_SIZE bs) { |
884 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 907 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
885 VP9_COMMON *const cm = &cpi->common; | 908 VP9_COMMON *const cm = &cpi->common; |
886 MACROBLOCKD *const xd = &x->e_mbd; | 909 MACROBLOCKD *const xd = &x->e_mbd; |
887 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 910 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
888 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); | 911 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); |
889 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, | 912 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, |
890 {INT64_MAX, INT64_MAX}, | 913 {INT64_MAX, INT64_MAX}, |
891 {INT64_MAX, INT64_MAX}, | 914 {INT64_MAX, INT64_MAX}, |
892 {INT64_MAX, INT64_MAX}}; | 915 {INT64_MAX, INT64_MAX}}; |
893 TX_SIZE n, m; | 916 TX_SIZE n, m; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 980 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
958 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 981 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
959 TX_SIZE tx_size; | 982 TX_SIZE tx_size; |
960 | 983 |
961 assert(bs == mbmi->sb_type); | 984 assert(bs == mbmi->sb_type); |
962 | 985 |
963 vp9_subtract_plane(x, bs, 0); | 986 vp9_subtract_plane(x, bs, 0); |
964 | 987 |
965 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || xd->lossless) { | 988 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || xd->lossless) { |
966 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); | 989 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); |
967 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse, | 990 choose_largest_tx_size(cpi, x, rate, distortion, skip, sse, ref_best_rd, |
968 ref_best_rd, bs); | 991 bs); |
969 if (psse) | 992 if (psse) |
970 *psse = sse[mbmi->tx_size]; | 993 *psse = sse[mbmi->tx_size]; |
971 return; | 994 return; |
972 } | 995 } |
973 | 996 |
974 if (cpi->sf.tx_size_search_method == USE_LARGESTINTRA_MODELINTER) { | 997 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) |
975 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) | 998 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size], &s[tx_size], |
976 model_rd_for_sb_y_tx(cpi, bs, tx_size, x, xd, | 999 &sse[tx_size], ref_best_rd, 0, bs, tx_size, |
977 &r[tx_size][0], &d[tx_size], &s[tx_size]); | 1000 cpi->sf.use_fast_coef_costing); |
978 choose_txfm_size_from_modelrd(cpi, x, r, rate, d, distortion, s, | 1001 choose_tx_size_from_rd(cpi, x, r, rate, d, distortion, s, |
979 skip, sse, ref_best_rd, bs); | 1002 skip, txfm_cache, bs); |
980 } else { | 1003 |
981 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) | |
982 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size], | |
983 &s[tx_size], &sse[tx_size], | |
984 ref_best_rd, 0, bs, tx_size, | |
985 cpi->sf.use_fast_coef_costing); | |
986 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, | |
987 skip, txfm_cache, bs); | |
988 } | |
989 if (psse) | 1004 if (psse) |
990 *psse = sse[mbmi->tx_size]; | 1005 *psse = sse[mbmi->tx_size]; |
991 } | 1006 } |
992 | 1007 |
993 static void intra_super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, | 1008 static void intra_super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, |
994 int64_t *distortion, int *skip, | 1009 int64_t *distortion, int *skip, |
995 int64_t *psse, BLOCK_SIZE bs, | 1010 int64_t *psse, BLOCK_SIZE bs, |
996 int64_t txfm_cache[TX_MODES], | 1011 int64_t txfm_cache[TX_MODES], |
997 int64_t ref_best_rd) { | 1012 int64_t ref_best_rd) { |
998 int64_t sse[TX_SIZES]; | 1013 int64_t sse[TX_SIZES]; |
999 MACROBLOCKD *xd = &x->e_mbd; | 1014 MACROBLOCKD *xd = &x->e_mbd; |
1000 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 1015 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
1001 | 1016 |
1002 assert(bs == mbmi->sb_type); | 1017 assert(bs == mbmi->sb_type); |
1003 if (cpi->sf.tx_size_search_method != USE_FULL_RD || xd->lossless) { | 1018 if (cpi->sf.tx_size_search_method != USE_FULL_RD || xd->lossless) { |
1004 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); | 1019 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); |
1005 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse, | 1020 choose_largest_tx_size(cpi, x, rate, distortion, skip, sse, ref_best_rd, |
1006 ref_best_rd, bs); | 1021 bs); |
1007 } else { | 1022 } else { |
1008 int r[TX_SIZES][2], s[TX_SIZES]; | 1023 int r[TX_SIZES][2], s[TX_SIZES]; |
1009 int64_t d[TX_SIZES]; | 1024 int64_t d[TX_SIZES]; |
1010 TX_SIZE tx_size; | 1025 TX_SIZE tx_size; |
1011 for (tx_size = TX_4X4; tx_size <= max_txsize_lookup[bs]; ++tx_size) | 1026 for (tx_size = TX_4X4; tx_size <= max_txsize_lookup[bs]; ++tx_size) |
1012 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size], | 1027 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size], |
1013 &s[tx_size], &sse[tx_size], | 1028 &s[tx_size], &sse[tx_size], |
1014 ref_best_rd, 0, bs, tx_size, | 1029 ref_best_rd, 0, bs, tx_size, |
1015 cpi->sf.use_fast_coef_costing); | 1030 cpi->sf.use_fast_coef_costing); |
1016 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, | 1031 choose_tx_size_from_rd(cpi, x, r, rate, d, distortion, s, skip, txfm_cache, |
1017 skip, txfm_cache, bs); | 1032 bs); |
1018 } | 1033 } |
1019 if (psse) | 1034 if (psse) |
1020 *psse = sse[mbmi->tx_size]; | 1035 *psse = sse[mbmi->tx_size]; |
1021 } | 1036 } |
1022 | 1037 |
1023 | 1038 |
1024 static int conditional_skipintra(PREDICTION_MODE mode, | 1039 static int conditional_skipintra(PREDICTION_MODE mode, |
1025 PREDICTION_MODE best_intra_mode) { | 1040 PREDICTION_MODE best_intra_mode) { |
1026 if (mode == D117_PRED && | 1041 if (mode == D117_PRED && |
1027 best_intra_mode != V_PRED && | 1042 best_intra_mode != V_PRED && |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 if (cpi->sf.tx_size_search_method == USE_FULL_RD) | 1270 if (cpi->sf.tx_size_search_method == USE_FULL_RD) |
1256 for (i = 0; i < TX_MODES; i++) | 1271 for (i = 0; i < TX_MODES; i++) |
1257 tx_cache[i] = INT64_MAX; | 1272 tx_cache[i] = INT64_MAX; |
1258 | 1273 |
1259 /* Y Search for intra prediction mode */ | 1274 /* Y Search for intra prediction mode */ |
1260 for (mode = DC_PRED; mode <= TM_PRED; mode++) { | 1275 for (mode = DC_PRED; mode <= TM_PRED; mode++) { |
1261 int64_t local_tx_cache[TX_MODES]; | 1276 int64_t local_tx_cache[TX_MODES]; |
1262 MODE_INFO *above_mi = xd->mi[-xd->mi_stride]; | 1277 MODE_INFO *above_mi = xd->mi[-xd->mi_stride]; |
1263 MODE_INFO *left_mi = xd->left_available ? xd->mi[-1] : NULL; | 1278 MODE_INFO *left_mi = xd->left_available ? xd->mi[-1] : NULL; |
1264 | 1279 |
1265 if (!(cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]] & (1 << mode))) | |
1266 continue; | |
1267 | |
1268 if (cpi->common.frame_type == KEY_FRAME) { | 1280 if (cpi->common.frame_type == KEY_FRAME) { |
1269 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); | 1281 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); |
1270 const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); | 1282 const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); |
1271 | 1283 |
1272 bmode_costs = cpi->y_mode_costs[A][L]; | 1284 bmode_costs = cpi->y_mode_costs[A][L]; |
1273 } | 1285 } |
1274 mic->mbmi.mode = mode; | 1286 mic->mbmi.mode = mode; |
1275 | 1287 |
1276 intra_super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, | 1288 intra_super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, |
1277 &s, NULL, bsize, local_tx_cache, best_rd); | 1289 &s, NULL, bsize, local_tx_cache, best_rd); |
(...skipping 30 matching lines...) Expand all Loading... |
1308 | 1320 |
1309 return best_rd; | 1321 return best_rd; |
1310 } | 1322 } |
1311 | 1323 |
1312 static void super_block_uvrd(const VP9_COMP *cpi, MACROBLOCK *x, | 1324 static void super_block_uvrd(const VP9_COMP *cpi, MACROBLOCK *x, |
1313 int *rate, int64_t *distortion, int *skippable, | 1325 int *rate, int64_t *distortion, int *skippable, |
1314 int64_t *sse, BLOCK_SIZE bsize, | 1326 int64_t *sse, BLOCK_SIZE bsize, |
1315 int64_t ref_best_rd) { | 1327 int64_t ref_best_rd) { |
1316 MACROBLOCKD *const xd = &x->e_mbd; | 1328 MACROBLOCKD *const xd = &x->e_mbd; |
1317 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 1329 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
1318 TX_SIZE uv_txfm_size = get_uv_tx_size(mbmi); | 1330 const TX_SIZE uv_tx_size = get_uv_tx_size(mbmi); |
1319 int plane; | 1331 int plane; |
1320 int pnrate = 0, pnskip = 1; | 1332 int pnrate = 0, pnskip = 1; |
1321 int64_t pndist = 0, pnsse = 0; | 1333 int64_t pndist = 0, pnsse = 0; |
1322 | 1334 |
1323 if (ref_best_rd < 0) | 1335 if (ref_best_rd < 0) |
1324 goto term; | 1336 goto term; |
1325 | 1337 |
1326 if (is_inter_block(mbmi)) { | 1338 if (is_inter_block(mbmi)) { |
1327 int plane; | 1339 int plane; |
1328 for (plane = 1; plane < MAX_MB_PLANE; ++plane) | 1340 for (plane = 1; plane < MAX_MB_PLANE; ++plane) |
1329 vp9_subtract_plane(x, bsize, plane); | 1341 vp9_subtract_plane(x, bsize, plane); |
1330 } | 1342 } |
1331 | 1343 |
1332 *rate = 0; | 1344 *rate = 0; |
1333 *distortion = 0; | 1345 *distortion = 0; |
1334 *sse = 0; | 1346 *sse = 0; |
1335 *skippable = 1; | 1347 *skippable = 1; |
1336 | 1348 |
1337 for (plane = 1; plane < MAX_MB_PLANE; ++plane) { | 1349 for (plane = 1; plane < MAX_MB_PLANE; ++plane) { |
1338 txfm_rd_in_plane(x, &pnrate, &pndist, &pnskip, &pnsse, | 1350 txfm_rd_in_plane(x, &pnrate, &pndist, &pnskip, &pnsse, |
1339 ref_best_rd, plane, bsize, uv_txfm_size, | 1351 ref_best_rd, plane, bsize, uv_tx_size, |
1340 cpi->sf.use_fast_coef_costing); | 1352 cpi->sf.use_fast_coef_costing); |
1341 if (pnrate == INT_MAX) | 1353 if (pnrate == INT_MAX) |
1342 goto term; | 1354 goto term; |
1343 *rate += pnrate; | 1355 *rate += pnrate; |
1344 *distortion += pndist; | 1356 *distortion += pndist; |
1345 *sse += pnsse; | 1357 *sse += pnsse; |
1346 *skippable &= pnskip; | 1358 *skippable &= pnskip; |
1347 } | 1359 } |
1348 return; | 1360 return; |
1349 | 1361 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 cpi->intra_uv_mode_cost[cpi->common.frame_type][mode]; | 1393 cpi->intra_uv_mode_cost[cpi->common.frame_type][mode]; |
1382 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); | 1394 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); |
1383 | 1395 |
1384 if (this_rd < best_rd) { | 1396 if (this_rd < best_rd) { |
1385 mode_selected = mode; | 1397 mode_selected = mode; |
1386 best_rd = this_rd; | 1398 best_rd = this_rd; |
1387 *rate = this_rate; | 1399 *rate = this_rate; |
1388 *rate_tokenonly = this_rate_tokenonly; | 1400 *rate_tokenonly = this_rate_tokenonly; |
1389 *distortion = this_distortion; | 1401 *distortion = this_distortion; |
1390 *skippable = s; | 1402 *skippable = s; |
1391 if (!x->select_txfm_size) { | 1403 if (!x->select_tx_size) |
1392 int i; | 1404 swap_block_ptr(x, ctx, 2, 0, 1, MAX_MB_PLANE); |
1393 struct macroblock_plane *const p = x->plane; | |
1394 struct macroblockd_plane *const pd = xd->plane; | |
1395 for (i = 1; i < MAX_MB_PLANE; ++i) { | |
1396 p[i].coeff = ctx->coeff_pbuf[i][2]; | |
1397 p[i].qcoeff = ctx->qcoeff_pbuf[i][2]; | |
1398 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][2]; | |
1399 p[i].eobs = ctx->eobs_pbuf[i][2]; | |
1400 | |
1401 ctx->coeff_pbuf[i][2] = ctx->coeff_pbuf[i][0]; | |
1402 ctx->qcoeff_pbuf[i][2] = ctx->qcoeff_pbuf[i][0]; | |
1403 ctx->dqcoeff_pbuf[i][2] = ctx->dqcoeff_pbuf[i][0]; | |
1404 ctx->eobs_pbuf[i][2] = ctx->eobs_pbuf[i][0]; | |
1405 | |
1406 ctx->coeff_pbuf[i][0] = p[i].coeff; | |
1407 ctx->qcoeff_pbuf[i][0] = p[i].qcoeff; | |
1408 ctx->dqcoeff_pbuf[i][0] = pd[i].dqcoeff; | |
1409 ctx->eobs_pbuf[i][0] = p[i].eobs; | |
1410 } | |
1411 } | |
1412 } | 1405 } |
1413 } | 1406 } |
1414 | 1407 |
1415 xd->mi[0]->mbmi.uv_mode = mode_selected; | 1408 xd->mi[0]->mbmi.uv_mode = mode_selected; |
1416 return best_rd; | 1409 return best_rd; |
1417 } | 1410 } |
1418 | 1411 |
1419 static int64_t rd_sbuv_dcpred(const VP9_COMP *cpi, MACROBLOCK *x, | 1412 static int64_t rd_sbuv_dcpred(const VP9_COMP *cpi, MACROBLOCK *x, |
1420 int *rate, int *rate_tokenonly, | 1413 int *rate, int *rate_tokenonly, |
1421 int64_t *distortion, int *skippable, | 1414 int64_t *distortion, int *skippable, |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1664 | 1657 |
1665 static INLINE int mv_has_subpel(const MV *mv) { | 1658 static INLINE int mv_has_subpel(const MV *mv) { |
1666 return (mv->row & 0x0F) || (mv->col & 0x0F); | 1659 return (mv->row & 0x0F) || (mv->col & 0x0F); |
1667 } | 1660 } |
1668 | 1661 |
1669 // Check if NEARESTMV/NEARMV/ZEROMV is the cheapest way encode zero motion. | 1662 // Check if NEARESTMV/NEARMV/ZEROMV is the cheapest way encode zero motion. |
1670 // TODO(aconverse): Find out if this is still productive then clean up or remove | 1663 // TODO(aconverse): Find out if this is still productive then clean up or remove |
1671 static int check_best_zero_mv( | 1664 static int check_best_zero_mv( |
1672 const VP9_COMP *cpi, const uint8_t mode_context[MAX_REF_FRAMES], | 1665 const VP9_COMP *cpi, const uint8_t mode_context[MAX_REF_FRAMES], |
1673 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], | 1666 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], |
1674 int disable_inter_mode_mask, int this_mode, | 1667 int inter_mode_mask, int this_mode, |
1675 const MV_REFERENCE_FRAME ref_frames[2]) { | 1668 const MV_REFERENCE_FRAME ref_frames[2]) { |
1676 if (!(disable_inter_mode_mask & (1 << INTER_OFFSET(ZEROMV))) && | 1669 if ((inter_mode_mask & (1 << ZEROMV)) && |
1677 (this_mode == NEARMV || this_mode == NEARESTMV || this_mode == ZEROMV) && | 1670 (this_mode == NEARMV || this_mode == NEARESTMV || this_mode == ZEROMV) && |
1678 frame_mv[this_mode][ref_frames[0]].as_int == 0 && | 1671 frame_mv[this_mode][ref_frames[0]].as_int == 0 && |
1679 (ref_frames[1] == NONE || | 1672 (ref_frames[1] == NONE || |
1680 frame_mv[this_mode][ref_frames[1]].as_int == 0)) { | 1673 frame_mv[this_mode][ref_frames[1]].as_int == 0)) { |
1681 int rfc = mode_context[ref_frames[0]]; | 1674 int rfc = mode_context[ref_frames[0]]; |
1682 int c1 = cost_mv_ref(cpi, NEARMV, rfc); | 1675 int c1 = cost_mv_ref(cpi, NEARMV, rfc); |
1683 int c2 = cost_mv_ref(cpi, NEARESTMV, rfc); | 1676 int c2 = cost_mv_ref(cpi, NEARESTMV, rfc); |
1684 int c3 = cost_mv_ref(cpi, ZEROMV, rfc); | 1677 int c3 = cost_mv_ref(cpi, ZEROMV, rfc); |
1685 | 1678 |
1686 if (this_mode == NEARMV) { | 1679 if (this_mode == NEARMV) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1732 const int label_count = 4; | 1725 const int label_count = 4; |
1733 int64_t this_segment_rd = 0; | 1726 int64_t this_segment_rd = 0; |
1734 int label_mv_thresh; | 1727 int label_mv_thresh; |
1735 int segmentyrate = 0; | 1728 int segmentyrate = 0; |
1736 const BLOCK_SIZE bsize = mbmi->sb_type; | 1729 const BLOCK_SIZE bsize = mbmi->sb_type; |
1737 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 1730 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
1738 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 1731 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
1739 ENTROPY_CONTEXT t_above[2], t_left[2]; | 1732 ENTROPY_CONTEXT t_above[2], t_left[2]; |
1740 int subpelmv = 1, have_ref = 0; | 1733 int subpelmv = 1, have_ref = 0; |
1741 const int has_second_rf = has_second_ref(mbmi); | 1734 const int has_second_rf = has_second_ref(mbmi); |
1742 const int disable_inter_mode_mask = cpi->sf.disable_inter_mode_mask[bsize]; | 1735 const int inter_mode_mask = cpi->sf.inter_mode_mask[bsize]; |
1743 | 1736 |
1744 vp9_zero(*bsi); | 1737 vp9_zero(*bsi); |
1745 | 1738 |
1746 bsi->segment_rd = best_rd; | 1739 bsi->segment_rd = best_rd; |
1747 bsi->ref_mv[0] = best_ref_mv; | 1740 bsi->ref_mv[0] = best_ref_mv; |
1748 bsi->ref_mv[1] = second_best_ref_mv; | 1741 bsi->ref_mv[1] = second_best_ref_mv; |
1749 bsi->mvp.as_int = best_ref_mv->as_int; | 1742 bsi->mvp.as_int = best_ref_mv->as_int; |
1750 bsi->mvthresh = mvthresh; | 1743 bsi->mvthresh = mvthresh; |
1751 | 1744 |
1752 for (i = 0; i < 4; i++) | 1745 for (i = 0; i < 4; i++) |
(...skipping 28 matching lines...) Expand all Loading... |
1781 &frame_mv[NEARMV][frame]); | 1774 &frame_mv[NEARMV][frame]); |
1782 } | 1775 } |
1783 | 1776 |
1784 // search for the best motion vector on this segment | 1777 // search for the best motion vector on this segment |
1785 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { | 1778 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { |
1786 const struct buf_2d orig_src = x->plane[0].src; | 1779 const struct buf_2d orig_src = x->plane[0].src; |
1787 struct buf_2d orig_pre[2]; | 1780 struct buf_2d orig_pre[2]; |
1788 | 1781 |
1789 mode_idx = INTER_OFFSET(this_mode); | 1782 mode_idx = INTER_OFFSET(this_mode); |
1790 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; | 1783 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; |
1791 if (disable_inter_mode_mask & (1 << mode_idx)) | 1784 if (!(inter_mode_mask & (1 << this_mode))) |
1792 continue; | 1785 continue; |
1793 | 1786 |
1794 if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv, | 1787 if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv, |
1795 disable_inter_mode_mask, | 1788 inter_mode_mask, |
1796 this_mode, mbmi->ref_frame)) | 1789 this_mode, mbmi->ref_frame)) |
1797 continue; | 1790 continue; |
1798 | 1791 |
1799 vpx_memcpy(orig_pre, pd->pre, sizeof(orig_pre)); | 1792 vpx_memcpy(orig_pre, pd->pre, sizeof(orig_pre)); |
1800 vpx_memcpy(bsi->rdstat[i][mode_idx].ta, t_above, | 1793 vpx_memcpy(bsi->rdstat[i][mode_idx].ta, t_above, |
1801 sizeof(bsi->rdstat[i][mode_idx].ta)); | 1794 sizeof(bsi->rdstat[i][mode_idx].ta)); |
1802 vpx_memcpy(bsi->rdstat[i][mode_idx].tl, t_left, | 1795 vpx_memcpy(bsi->rdstat[i][mode_idx].tl, t_left, |
1803 sizeof(bsi->rdstat[i][mode_idx].tl)); | 1796 sizeof(bsi->rdstat[i][mode_idx].tl)); |
1804 | 1797 |
1805 // motion search for newmv (single predictor case only) | 1798 // motion search for newmv (single predictor case only) |
(...skipping 17 matching lines...) Expand all Loading... |
1823 bsi->mvp.as_int = mi->bmi[i - 1].as_mv[0].as_int; | 1816 bsi->mvp.as_int = mi->bmi[i - 1].as_mv[0].as_int; |
1824 if (i == 2) | 1817 if (i == 2) |
1825 bsi->mvp.as_int = mi->bmi[i - 2].as_mv[0].as_int; | 1818 bsi->mvp.as_int = mi->bmi[i - 2].as_mv[0].as_int; |
1826 } | 1819 } |
1827 } | 1820 } |
1828 if (i == 0) | 1821 if (i == 0) |
1829 max_mv = x->max_mv_context[mbmi->ref_frame[0]]; | 1822 max_mv = x->max_mv_context[mbmi->ref_frame[0]]; |
1830 else | 1823 else |
1831 max_mv = MAX(abs(bsi->mvp.as_mv.row), abs(bsi->mvp.as_mv.col)) >> 3; | 1824 max_mv = MAX(abs(bsi->mvp.as_mv.row), abs(bsi->mvp.as_mv.col)) >> 3; |
1832 | 1825 |
1833 if (cpi->sf.auto_mv_step_size && cm->show_frame) { | 1826 if (cpi->sf.mv.auto_mv_step_size && cm->show_frame) { |
1834 // Take wtd average of the step_params based on the last frame's | 1827 // Take wtd average of the step_params based on the last frame's |
1835 // max mv magnitude and the best ref mvs of the current block for | 1828 // max mv magnitude and the best ref mvs of the current block for |
1836 // the given reference. | 1829 // the given reference. |
1837 step_param = (vp9_init_search_range(&cpi->sf, max_mv) + | 1830 step_param = (vp9_init_search_range(&cpi->sf, max_mv) + |
1838 cpi->mv_step_param) / 2; | 1831 cpi->mv_step_param) / 2; |
1839 } else { | 1832 } else { |
1840 step_param = cpi->mv_step_param; | 1833 step_param = cpi->mv_step_param; |
1841 } | 1834 } |
1842 | 1835 |
1843 mvp_full.row = bsi->mvp.as_mv.row >> 3; | 1836 mvp_full.row = bsi->mvp.as_mv.row >> 3; |
1844 mvp_full.col = bsi->mvp.as_mv.col >> 3; | 1837 mvp_full.col = bsi->mvp.as_mv.col >> 3; |
1845 | 1838 |
1846 if (cpi->sf.adaptive_motion_search && cm->show_frame) { | 1839 if (cpi->sf.adaptive_motion_search && cm->show_frame) { |
1847 mvp_full.row = x->pred_mv[mbmi->ref_frame[0]].as_mv.row >> 3; | 1840 mvp_full.row = x->pred_mv[mbmi->ref_frame[0]].row >> 3; |
1848 mvp_full.col = x->pred_mv[mbmi->ref_frame[0]].as_mv.col >> 3; | 1841 mvp_full.col = x->pred_mv[mbmi->ref_frame[0]].col >> 3; |
1849 step_param = MAX(step_param, 8); | 1842 step_param = MAX(step_param, 8); |
1850 } | 1843 } |
1851 | 1844 |
1852 // adjust src pointer for this block | 1845 // adjust src pointer for this block |
1853 mi_buf_shift(x, i); | 1846 mi_buf_shift(x, i); |
1854 | 1847 |
1855 vp9_set_mv_search_range(x, &bsi->ref_mv[0]->as_mv); | 1848 vp9_set_mv_search_range(x, &bsi->ref_mv[0]->as_mv); |
1856 | 1849 |
1857 bestsme = full_pixel_search(cpi, x, bsize, &mvp_full, step_param, | 1850 bestsme = vp9_full_pixel_search(cpi, x, bsize, &mvp_full, step_param, |
1858 sadpb, &bsi->ref_mv[0]->as_mv, new_mv, | 1851 sadpb, &bsi->ref_mv[0]->as_mv, new_mv, |
1859 INT_MAX, 1); | 1852 INT_MAX, 1); |
1860 | 1853 |
1861 // Should we do a full search (best quality only) | 1854 // Should we do a full search (best quality only) |
1862 if (is_best_mode(cpi->oxcf.mode)) { | 1855 if (is_best_mode(cpi->oxcf.mode)) { |
1863 int_mv *const best_mv = &mi->bmi[i].as_mv[0]; | 1856 int_mv *const best_mv = &mi->bmi[i].as_mv[0]; |
1864 /* Check if mvp_full is within the range. */ | 1857 /* Check if mvp_full is within the range. */ |
1865 clamp_mv(&mvp_full, x->mv_col_min, x->mv_col_max, | 1858 clamp_mv(&mvp_full, x->mv_col_min, x->mv_col_max, |
1866 x->mv_row_min, x->mv_row_max); | 1859 x->mv_row_min, x->mv_row_max); |
1867 thissme = cpi->full_search_sad(x, &mvp_full, | 1860 thissme = cpi->full_search_sad(x, &mvp_full, |
1868 sadpb, 16, &cpi->fn_ptr[bsize], | 1861 sadpb, 16, &cpi->fn_ptr[bsize], |
1869 &bsi->ref_mv[0]->as_mv, | 1862 &bsi->ref_mv[0]->as_mv, |
1870 &best_mv->as_mv); | 1863 &best_mv->as_mv); |
1871 if (thissme < bestsme) { | 1864 if (thissme < bestsme) { |
1872 bestsme = thissme; | 1865 bestsme = thissme; |
1873 *new_mv = best_mv->as_mv; | 1866 *new_mv = best_mv->as_mv; |
1874 } else { | 1867 } else { |
1875 // The full search result is actually worse so re-instate the | 1868 // The full search result is actually worse so re-instate the |
1876 // previous best vector | 1869 // previous best vector |
1877 best_mv->as_mv = *new_mv; | 1870 best_mv->as_mv = *new_mv; |
1878 } | 1871 } |
1879 } | 1872 } |
1880 | 1873 |
1881 if (bestsme < INT_MAX) { | 1874 if (bestsme < INT_MAX) { |
1882 int distortion; | 1875 int distortion; |
1883 cpi->find_fractional_mv_step(x, | 1876 cpi->find_fractional_mv_step(x, |
1884 new_mv, | 1877 new_mv, |
1885 &bsi->ref_mv[0]->as_mv, | 1878 &bsi->ref_mv[0]->as_mv, |
1886 cm->allow_high_precision_mv, | 1879 cm->allow_high_precision_mv, |
1887 x->errorperbit, &cpi->fn_ptr[bsize], | 1880 x->errorperbit, &cpi->fn_ptr[bsize], |
1888 cpi->sf.subpel_force_stop, | 1881 cpi->sf.mv.subpel_force_stop, |
1889 cpi->sf.subpel_iters_per_step, | 1882 cpi->sf.mv.subpel_iters_per_step, |
1890 x->nmvjointcost, x->mvcost, | 1883 x->nmvjointcost, x->mvcost, |
1891 &distortion, | 1884 &distortion, |
1892 &x->pred_sse[mbmi->ref_frame[0]]); | 1885 &x->pred_sse[mbmi->ref_frame[0]]); |
1893 | 1886 |
1894 // save motion search result for use in compound prediction | 1887 // save motion search result for use in compound prediction |
1895 seg_mvs[i][mbmi->ref_frame[0]].as_mv = *new_mv; | 1888 seg_mvs[i][mbmi->ref_frame[0]].as_mv = *new_mv; |
1896 } | 1889 } |
1897 | 1890 |
1898 if (cpi->sf.adaptive_motion_search) | 1891 if (cpi->sf.adaptive_motion_search) |
1899 x->pred_mv[mbmi->ref_frame[0]].as_mv = *new_mv; | 1892 x->pred_mv[mbmi->ref_frame[0]] = *new_mv; |
1900 | 1893 |
1901 // restore src pointers | 1894 // restore src pointers |
1902 mi_buf_restore(x, orig_src, orig_pre); | 1895 mi_buf_restore(x, orig_src, orig_pre); |
1903 } | 1896 } |
1904 | 1897 |
1905 if (has_second_rf) { | 1898 if (has_second_rf) { |
1906 if (seg_mvs[i][mbmi->ref_frame[1]].as_int == INVALID_MV || | 1899 if (seg_mvs[i][mbmi->ref_frame[1]].as_int == INVALID_MV || |
1907 seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV) | 1900 seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV) |
1908 continue; | 1901 continue; |
1909 } | 1902 } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2095 int max_mv = 0; | 2088 int max_mv = 0; |
2096 | 2089 |
2097 uint8_t *src_y_ptr = x->plane[0].src.buf; | 2090 uint8_t *src_y_ptr = x->plane[0].src.buf; |
2098 uint8_t *ref_y_ptr; | 2091 uint8_t *ref_y_ptr; |
2099 int row_offset, col_offset; | 2092 int row_offset, col_offset; |
2100 int num_mv_refs = MAX_MV_REF_CANDIDATES + | 2093 int num_mv_refs = MAX_MV_REF_CANDIDATES + |
2101 (cpi->sf.adaptive_motion_search && | 2094 (cpi->sf.adaptive_motion_search && |
2102 cpi->common.show_frame && | 2095 cpi->common.show_frame && |
2103 block_size < cpi->sf.max_partition_size); | 2096 block_size < cpi->sf.max_partition_size); |
2104 | 2097 |
2105 int_mv pred_mv[3]; | 2098 MV pred_mv[3]; |
2106 pred_mv[0] = mbmi->ref_mvs[ref_frame][0]; | 2099 pred_mv[0] = mbmi->ref_mvs[ref_frame][0].as_mv; |
2107 pred_mv[1] = mbmi->ref_mvs[ref_frame][1]; | 2100 pred_mv[1] = mbmi->ref_mvs[ref_frame][1].as_mv; |
2108 pred_mv[2] = x->pred_mv[ref_frame]; | 2101 pred_mv[2] = x->pred_mv[ref_frame]; |
2109 | 2102 |
2110 // Get the sad for each candidate reference mv | 2103 // Get the sad for each candidate reference mv |
2111 for (i = 0; i < num_mv_refs; i++) { | 2104 for (i = 0; i < num_mv_refs; i++) { |
2112 this_mv.as_int = pred_mv[i].as_int; | 2105 this_mv.as_mv = pred_mv[i]; |
2113 | 2106 |
2114 max_mv = MAX(max_mv, | 2107 max_mv = MAX(max_mv, |
2115 MAX(abs(this_mv.as_mv.row), abs(this_mv.as_mv.col)) >> 3); | 2108 MAX(abs(this_mv.as_mv.row), abs(this_mv.as_mv.col)) >> 3); |
2116 // only need to check zero mv once | 2109 // only need to check zero mv once |
2117 if (!this_mv.as_int && zero_seen) | 2110 if (!this_mv.as_int && zero_seen) |
2118 continue; | 2111 continue; |
2119 | 2112 |
2120 zero_seen = zero_seen || !this_mv.as_int; | 2113 zero_seen = zero_seen || !this_mv.as_int; |
2121 | 2114 |
2122 row_offset = this_mv.as_mv.row >> 3; | 2115 row_offset = this_mv.as_mv.row >> 3; |
2123 col_offset = this_mv.as_mv.col >> 3; | 2116 col_offset = this_mv.as_mv.col >> 3; |
2124 ref_y_ptr = ref_y_buffer + (ref_y_stride * row_offset) + col_offset; | 2117 ref_y_ptr = ref_y_buffer + (ref_y_stride * row_offset) + col_offset; |
2125 | 2118 |
2126 // Find sad for current vector. | 2119 // Find sad for current vector. |
2127 this_sad = cpi->fn_ptr[block_size].sdf(src_y_ptr, x->plane[0].src.stride, | 2120 this_sad = cpi->fn_ptr[block_size].sdf(src_y_ptr, x->plane[0].src.stride, |
2128 ref_y_ptr, ref_y_stride, | 2121 ref_y_ptr, ref_y_stride); |
2129 0x7fffffff); | |
2130 | 2122 |
2131 // Note if it is the best so far. | 2123 // Note if it is the best so far. |
2132 if (this_sad < best_sad) { | 2124 if (this_sad < best_sad) { |
2133 best_sad = this_sad; | 2125 best_sad = this_sad; |
2134 best_index = i; | 2126 best_index = i; |
2135 } | 2127 } |
2136 } | 2128 } |
2137 | 2129 |
2138 // Note the index of the mv that worked best in the reference list. | 2130 // Note the index of the mv that worked best in the reference list. |
2139 x->mv_best_ref_index[ref_frame] = best_index; | 2131 x->mv_best_ref_index[ref_frame] = best_index; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2197 ref_costs_comp[GOLDEN_FRAME] = base_cost + vp9_cost_bit(ref_comp_p, 1); | 2189 ref_costs_comp[GOLDEN_FRAME] = base_cost + vp9_cost_bit(ref_comp_p, 1); |
2198 } else { | 2190 } else { |
2199 ref_costs_comp[LAST_FRAME] = 512; | 2191 ref_costs_comp[LAST_FRAME] = 512; |
2200 ref_costs_comp[GOLDEN_FRAME] = 512; | 2192 ref_costs_comp[GOLDEN_FRAME] = 512; |
2201 } | 2193 } |
2202 } | 2194 } |
2203 } | 2195 } |
2204 | 2196 |
2205 static void store_coding_context(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, | 2197 static void store_coding_context(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, |
2206 int mode_index, | 2198 int mode_index, |
2207 int_mv *ref_mv, | |
2208 int_mv *second_ref_mv, | |
2209 int64_t comp_pred_diff[REFERENCE_MODES], | 2199 int64_t comp_pred_diff[REFERENCE_MODES], |
2210 const int64_t tx_size_diff[TX_MODES], | 2200 const int64_t tx_size_diff[TX_MODES], |
2211 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]) { | 2201 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]) { |
2212 MACROBLOCKD *const xd = &x->e_mbd; | 2202 MACROBLOCKD *const xd = &x->e_mbd; |
2213 | 2203 |
2214 // Take a snapshot of the coding context so it can be | 2204 // Take a snapshot of the coding context so it can be |
2215 // restored if we decide to encode this way | 2205 // restored if we decide to encode this way |
2216 ctx->skip = x->skip; | 2206 ctx->skip = x->skip; |
2217 ctx->best_mode_index = mode_index; | 2207 ctx->best_mode_index = mode_index; |
2218 ctx->mic = *xd->mi[0]; | 2208 ctx->mic = *xd->mi[0]; |
2219 | |
2220 ctx->best_ref_mv[0].as_int = ref_mv->as_int; | |
2221 ctx->best_ref_mv[1].as_int = second_ref_mv->as_int; | |
2222 | |
2223 ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_REFERENCE]; | 2209 ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_REFERENCE]; |
2224 ctx->comp_pred_diff = (int)comp_pred_diff[COMPOUND_REFERENCE]; | 2210 ctx->comp_pred_diff = (int)comp_pred_diff[COMPOUND_REFERENCE]; |
2225 ctx->hybrid_pred_diff = (int)comp_pred_diff[REFERENCE_MODE_SELECT]; | 2211 ctx->hybrid_pred_diff = (int)comp_pred_diff[REFERENCE_MODE_SELECT]; |
2226 | 2212 |
2227 vpx_memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff)); | 2213 vpx_memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff)); |
2228 vpx_memcpy(ctx->best_filter_diff, best_filter_diff, | 2214 vpx_memcpy(ctx->best_filter_diff, best_filter_diff, |
2229 sizeof(*best_filter_diff) * SWITCHABLE_FILTER_CONTEXTS); | 2215 sizeof(*best_filter_diff) * SWITCHABLE_FILTER_CONTEXTS); |
2230 } | 2216 } |
2231 | 2217 |
2232 static void setup_pred_block(const MACROBLOCKD *xd, | 2218 static void setup_pred_block(const MACROBLOCKD *xd, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2325 int tmp_col_max = x->mv_col_max; | 2311 int tmp_col_max = x->mv_col_max; |
2326 int tmp_row_min = x->mv_row_min; | 2312 int tmp_row_min = x->mv_row_min; |
2327 int tmp_row_max = x->mv_row_max; | 2313 int tmp_row_max = x->mv_row_max; |
2328 | 2314 |
2329 const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, | 2315 const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, |
2330 ref); | 2316 ref); |
2331 | 2317 |
2332 MV pred_mv[3]; | 2318 MV pred_mv[3]; |
2333 pred_mv[0] = mbmi->ref_mvs[ref][0].as_mv; | 2319 pred_mv[0] = mbmi->ref_mvs[ref][0].as_mv; |
2334 pred_mv[1] = mbmi->ref_mvs[ref][1].as_mv; | 2320 pred_mv[1] = mbmi->ref_mvs[ref][1].as_mv; |
2335 pred_mv[2] = x->pred_mv[ref].as_mv; | 2321 pred_mv[2] = x->pred_mv[ref]; |
2336 | 2322 |
2337 if (scaled_ref_frame) { | 2323 if (scaled_ref_frame) { |
2338 int i; | 2324 int i; |
2339 // Swap out the reference frame for a version that's been scaled to | 2325 // Swap out the reference frame for a version that's been scaled to |
2340 // match the resolution of the current frame, allowing the existing | 2326 // match the resolution of the current frame, allowing the existing |
2341 // motion search code to be used without additional modifications. | 2327 // motion search code to be used without additional modifications. |
2342 for (i = 0; i < MAX_MB_PLANE; i++) | 2328 for (i = 0; i < MAX_MB_PLANE; i++) |
2343 backup_yv12[i] = xd->plane[i].pre[0]; | 2329 backup_yv12[i] = xd->plane[i].pre[0]; |
2344 | 2330 |
2345 vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); | 2331 vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); |
2346 } | 2332 } |
2347 | 2333 |
2348 vp9_set_mv_search_range(x, &ref_mv); | 2334 vp9_set_mv_search_range(x, &ref_mv); |
2349 | 2335 |
2350 // Work out the size of the first step in the mv step search. | 2336 // Work out the size of the first step in the mv step search. |
2351 // 0 here is maximum length first step. 1 is MAX >> 1 etc. | 2337 // 0 here is maximum length first step. 1 is MAX >> 1 etc. |
2352 if (cpi->sf.auto_mv_step_size && cm->show_frame) { | 2338 if (cpi->sf.mv.auto_mv_step_size && cm->show_frame) { |
2353 // Take wtd average of the step_params based on the last frame's | 2339 // Take wtd average of the step_params based on the last frame's |
2354 // max mv magnitude and that based on the best ref mvs of the current | 2340 // max mv magnitude and that based on the best ref mvs of the current |
2355 // block for the given reference. | 2341 // block for the given reference. |
2356 step_param = (vp9_init_search_range(&cpi->sf, x->max_mv_context[ref]) + | 2342 step_param = (vp9_init_search_range(&cpi->sf, x->max_mv_context[ref]) + |
2357 cpi->mv_step_param) / 2; | 2343 cpi->mv_step_param) / 2; |
2358 } else { | 2344 } else { |
2359 step_param = cpi->mv_step_param; | 2345 step_param = cpi->mv_step_param; |
2360 } | 2346 } |
2361 | 2347 |
2362 if (cpi->sf.adaptive_motion_search && bsize < BLOCK_64X64 && | 2348 if (cpi->sf.adaptive_motion_search && bsize < BLOCK_64X64 && |
2363 cm->show_frame) { | 2349 cm->show_frame) { |
2364 int boffset = 2 * (b_width_log2(BLOCK_64X64) - MIN(b_height_log2(bsize), | 2350 int boffset = 2 * (b_width_log2(BLOCK_64X64) - MIN(b_height_log2(bsize), |
2365 b_width_log2(bsize))); | 2351 b_width_log2(bsize))); |
2366 step_param = MAX(step_param, boffset); | 2352 step_param = MAX(step_param, boffset); |
2367 } | 2353 } |
2368 | 2354 |
2369 if (cpi->sf.adaptive_motion_search) { | 2355 if (cpi->sf.adaptive_motion_search) { |
2370 int bwl = b_width_log2_lookup[bsize]; | 2356 int bwl = b_width_log2_lookup[bsize]; |
2371 int bhl = b_height_log2_lookup[bsize]; | 2357 int bhl = b_height_log2_lookup[bsize]; |
2372 int i; | 2358 int i; |
2373 int tlevel = x->pred_mv_sad[ref] >> (bwl + bhl + 4); | 2359 int tlevel = x->pred_mv_sad[ref] >> (bwl + bhl + 4); |
2374 | 2360 |
2375 if (tlevel < 5) | 2361 if (tlevel < 5) |
2376 step_param += 2; | 2362 step_param += 2; |
2377 | 2363 |
2378 for (i = LAST_FRAME; i <= ALTREF_FRAME && cm->show_frame; ++i) { | 2364 for (i = LAST_FRAME; i <= ALTREF_FRAME && cm->show_frame; ++i) { |
2379 if ((x->pred_mv_sad[ref] >> 3) > x->pred_mv_sad[i]) { | 2365 if ((x->pred_mv_sad[ref] >> 3) > x->pred_mv_sad[i]) { |
2380 x->pred_mv[ref].as_int = 0; | 2366 x->pred_mv[ref].row = 0; |
| 2367 x->pred_mv[ref].col = 0; |
2381 tmp_mv->as_int = INVALID_MV; | 2368 tmp_mv->as_int = INVALID_MV; |
2382 | 2369 |
2383 if (scaled_ref_frame) { | 2370 if (scaled_ref_frame) { |
2384 int i; | 2371 int i; |
2385 for (i = 0; i < MAX_MB_PLANE; i++) | 2372 for (i = 0; i < MAX_MB_PLANE; i++) |
2386 xd->plane[i].pre[0] = backup_yv12[i]; | 2373 xd->plane[i].pre[0] = backup_yv12[i]; |
2387 } | 2374 } |
2388 return; | 2375 return; |
2389 } | 2376 } |
2390 } | 2377 } |
2391 } | 2378 } |
2392 | 2379 |
2393 mvp_full = pred_mv[x->mv_best_ref_index[ref]]; | 2380 mvp_full = pred_mv[x->mv_best_ref_index[ref]]; |
2394 | 2381 |
2395 mvp_full.col >>= 3; | 2382 mvp_full.col >>= 3; |
2396 mvp_full.row >>= 3; | 2383 mvp_full.row >>= 3; |
2397 | 2384 |
2398 bestsme = full_pixel_search(cpi, x, bsize, &mvp_full, step_param, sadpb, | 2385 bestsme = vp9_full_pixel_search(cpi, x, bsize, &mvp_full, step_param, sadpb, |
2399 &ref_mv, &tmp_mv->as_mv, INT_MAX, 1); | 2386 &ref_mv, &tmp_mv->as_mv, INT_MAX, 1); |
2400 | 2387 |
2401 x->mv_col_min = tmp_col_min; | 2388 x->mv_col_min = tmp_col_min; |
2402 x->mv_col_max = tmp_col_max; | 2389 x->mv_col_max = tmp_col_max; |
2403 x->mv_row_min = tmp_row_min; | 2390 x->mv_row_min = tmp_row_min; |
2404 x->mv_row_max = tmp_row_max; | 2391 x->mv_row_max = tmp_row_max; |
2405 | 2392 |
2406 if (bestsme < INT_MAX) { | 2393 if (bestsme < INT_MAX) { |
2407 int dis; /* TODO: use dis in distortion calculation later. */ | 2394 int dis; /* TODO: use dis in distortion calculation later. */ |
2408 cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv, | 2395 cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv, |
2409 cm->allow_high_precision_mv, | 2396 cm->allow_high_precision_mv, |
2410 x->errorperbit, | 2397 x->errorperbit, |
2411 &cpi->fn_ptr[bsize], | 2398 &cpi->fn_ptr[bsize], |
2412 cpi->sf.subpel_force_stop, | 2399 cpi->sf.mv.subpel_force_stop, |
2413 cpi->sf.subpel_iters_per_step, | 2400 cpi->sf.mv.subpel_iters_per_step, |
2414 x->nmvjointcost, x->mvcost, | 2401 x->nmvjointcost, x->mvcost, |
2415 &dis, &x->pred_sse[ref]); | 2402 &dis, &x->pred_sse[ref]); |
2416 } | 2403 } |
2417 *rate_mv = vp9_mv_bit_cost(&tmp_mv->as_mv, &ref_mv, | 2404 *rate_mv = vp9_mv_bit_cost(&tmp_mv->as_mv, &ref_mv, |
2418 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); | 2405 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); |
2419 | 2406 |
2420 if (cpi->sf.adaptive_motion_search && cm->show_frame) | 2407 if (cpi->sf.adaptive_motion_search && cm->show_frame) |
2421 x->pred_mv[ref].as_int = tmp_mv->as_int; | 2408 x->pred_mv[ref] = tmp_mv->as_mv; |
2422 | 2409 |
2423 if (scaled_ref_frame) { | 2410 if (scaled_ref_frame) { |
2424 int i; | 2411 int i; |
2425 for (i = 0; i < MAX_MB_PLANE; i++) | 2412 for (i = 0; i < MAX_MB_PLANE; i++) |
2426 xd->plane[i].pre[0] = backup_yv12[i]; | 2413 xd->plane[i].pre[0] = backup_yv12[i]; |
2427 } | 2414 } |
2428 } | 2415 } |
2429 | 2416 |
2430 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, | 2417 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, |
2431 BLOCK_SIZE bsize, | 2418 BLOCK_SIZE bsize, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2527 | 2514 |
2528 if (bestsme < INT_MAX) { | 2515 if (bestsme < INT_MAX) { |
2529 int dis; /* TODO: use dis in distortion calculation later. */ | 2516 int dis; /* TODO: use dis in distortion calculation later. */ |
2530 unsigned int sse; | 2517 unsigned int sse; |
2531 bestsme = cpi->find_fractional_mv_step_comp( | 2518 bestsme = cpi->find_fractional_mv_step_comp( |
2532 x, &tmp_mv, | 2519 x, &tmp_mv, |
2533 &ref_mv[id].as_mv, | 2520 &ref_mv[id].as_mv, |
2534 cpi->common.allow_high_precision_mv, | 2521 cpi->common.allow_high_precision_mv, |
2535 x->errorperbit, | 2522 x->errorperbit, |
2536 &cpi->fn_ptr[bsize], | 2523 &cpi->fn_ptr[bsize], |
2537 0, cpi->sf.subpel_iters_per_step, | 2524 0, cpi->sf.mv.subpel_iters_per_step, |
2538 x->nmvjointcost, x->mvcost, | 2525 x->nmvjointcost, x->mvcost, |
2539 &dis, &sse, second_pred, | 2526 &dis, &sse, second_pred, |
2540 pw, ph); | 2527 pw, ph); |
2541 } | 2528 } |
2542 | 2529 |
2543 if (id) | 2530 if (id) |
2544 xd->plane[0].pre[0] = scaled_first_yv12; | 2531 xd->plane[0].pre[0] = scaled_first_yv12; |
2545 | 2532 |
2546 if (bestsme < last_besterr[id]) { | 2533 if (bestsme < last_besterr[id]) { |
2547 frame_mv[refs[id]].as_mv = tmp_mv; | 2534 frame_mv[refs[id]].as_mv = tmp_mv; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2805 if (rd / 2 > ref_best_rd) { | 2792 if (rd / 2 > ref_best_rd) { |
2806 restore_dst_buf(xd, orig_dst, orig_dst_stride); | 2793 restore_dst_buf(xd, orig_dst, orig_dst_stride); |
2807 return INT64_MAX; | 2794 return INT64_MAX; |
2808 } | 2795 } |
2809 } | 2796 } |
2810 | 2797 |
2811 if (cm->interp_filter == SWITCHABLE) | 2798 if (cm->interp_filter == SWITCHABLE) |
2812 *rate2 += vp9_get_switchable_rate(cpi); | 2799 *rate2 += vp9_get_switchable_rate(cpi); |
2813 | 2800 |
2814 if (!is_comp_pred) { | 2801 if (!is_comp_pred) { |
2815 if (!x->in_active_map) { | 2802 if (!x->in_active_map || |
| 2803 vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
2816 if (psse) | 2804 if (psse) |
2817 *psse = 0; | 2805 *psse = 0; |
2818 *distortion = 0; | 2806 *distortion = 0; |
2819 x->skip = 1; | 2807 x->skip = 1; |
2820 } else if (cpi->allow_encode_breakout && x->encode_breakout) { | 2808 } else if (cpi->allow_encode_breakout && x->encode_breakout) { |
2821 const BLOCK_SIZE y_size = get_plane_block_size(bsize, &xd->plane[0]); | 2809 const BLOCK_SIZE y_size = get_plane_block_size(bsize, &xd->plane[0]); |
2822 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]); | 2810 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]); |
2823 unsigned int var, sse; | 2811 unsigned int var, sse; |
2824 // Skipping threshold for ac. | 2812 // Skipping threshold for ac. |
2825 unsigned int thresh_ac; | 2813 unsigned int thresh_ac; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2924 *psse += sseuv; | 2912 *psse += sseuv; |
2925 *rate2 += *rate_uv; | 2913 *rate2 += *rate_uv; |
2926 *distortion += *distortion_uv; | 2914 *distortion += *distortion_uv; |
2927 *skippable = skippable_y && skippable_uv; | 2915 *skippable = skippable_y && skippable_uv; |
2928 } | 2916 } |
2929 | 2917 |
2930 restore_dst_buf(xd, orig_dst, orig_dst_stride); | 2918 restore_dst_buf(xd, orig_dst, orig_dst_stride); |
2931 return this_rd; // if 0, this will be re-calculated by caller | 2919 return this_rd; // if 0, this will be re-calculated by caller |
2932 } | 2920 } |
2933 | 2921 |
2934 static void swap_block_ptr(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, | |
2935 int max_plane) { | |
2936 struct macroblock_plane *const p = x->plane; | |
2937 struct macroblockd_plane *const pd = x->e_mbd.plane; | |
2938 int i; | |
2939 | |
2940 for (i = 0; i < max_plane; ++i) { | |
2941 p[i].coeff = ctx->coeff_pbuf[i][1]; | |
2942 p[i].qcoeff = ctx->qcoeff_pbuf[i][1]; | |
2943 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1]; | |
2944 p[i].eobs = ctx->eobs_pbuf[i][1]; | |
2945 | |
2946 ctx->coeff_pbuf[i][1] = ctx->coeff_pbuf[i][0]; | |
2947 ctx->qcoeff_pbuf[i][1] = ctx->qcoeff_pbuf[i][0]; | |
2948 ctx->dqcoeff_pbuf[i][1] = ctx->dqcoeff_pbuf[i][0]; | |
2949 ctx->eobs_pbuf[i][1] = ctx->eobs_pbuf[i][0]; | |
2950 | |
2951 ctx->coeff_pbuf[i][0] = p[i].coeff; | |
2952 ctx->qcoeff_pbuf[i][0] = p[i].qcoeff; | |
2953 ctx->dqcoeff_pbuf[i][0] = pd[i].dqcoeff; | |
2954 ctx->eobs_pbuf[i][0] = p[i].eobs; | |
2955 } | |
2956 } | |
2957 | |
2958 void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, | 2922 void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, |
2959 int *returnrate, int64_t *returndist, | 2923 int *returnrate, int64_t *returndist, |
2960 BLOCK_SIZE bsize, | 2924 BLOCK_SIZE bsize, |
2961 PICK_MODE_CONTEXT *ctx, int64_t best_rd) { | 2925 PICK_MODE_CONTEXT *ctx, int64_t best_rd) { |
2962 VP9_COMMON *const cm = &cpi->common; | 2926 VP9_COMMON *const cm = &cpi->common; |
2963 MACROBLOCKD *const xd = &x->e_mbd; | 2927 MACROBLOCKD *const xd = &x->e_mbd; |
2964 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0; | 2928 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0; |
2965 int y_skip = 0, uv_skip = 0; | 2929 int y_skip = 0, uv_skip = 0; |
2966 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 }; | 2930 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 }; |
2967 TX_SIZE max_uv_tx_size; | 2931 TX_SIZE max_uv_tx_size; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3005 if (tx_cache[i] < INT64_MAX && tx_cache[cm->tx_mode] < INT64_MAX) | 2969 if (tx_cache[i] < INT64_MAX && tx_cache[cm->tx_mode] < INT64_MAX) |
3006 ctx->tx_rd_diff[i] = tx_cache[i] - tx_cache[cm->tx_mode]; | 2970 ctx->tx_rd_diff[i] = tx_cache[i] - tx_cache[cm->tx_mode]; |
3007 else | 2971 else |
3008 ctx->tx_rd_diff[i] = 0; | 2972 ctx->tx_rd_diff[i] = 0; |
3009 } | 2973 } |
3010 } | 2974 } |
3011 | 2975 |
3012 ctx->mic = *xd->mi[0]; | 2976 ctx->mic = *xd->mi[0]; |
3013 } | 2977 } |
3014 | 2978 |
3015 static INLINE int rd_less_than_thresh(int64_t best_rd, int thresh, | |
3016 int thresh_fact) { | |
3017 return best_rd < ((int64_t)thresh * thresh_fact >> 5) || thresh == INT_MAX; | |
3018 } | |
3019 | |
3020 // Updating rd_thresh_freq_fact[] here means that the different | 2979 // Updating rd_thresh_freq_fact[] here means that the different |
3021 // partition/block sizes are handled independently based on the best | 2980 // partition/block sizes are handled independently based on the best |
3022 // choice for the current partition. It may well be better to keep a scaled | 2981 // choice for the current partition. It may well be better to keep a scaled |
3023 // best rd so far value and update rd_thresh_freq_fact based on the mode/size | 2982 // best rd so far value and update rd_thresh_freq_fact based on the mode/size |
3024 // combination that wins out. | 2983 // combination that wins out. |
3025 static void update_rd_thresh_fact(VP9_COMP *cpi, int bsize, | 2984 static void update_rd_thresh_fact(VP9_COMP *cpi, int bsize, |
3026 int best_mode_index) { | 2985 int best_mode_index) { |
3027 if (cpi->sf.adaptive_rd_thresh > 0) { | 2986 if (cpi->sf.adaptive_rd_thresh > 0) { |
3028 const int top_mode = bsize < BLOCK_8X8 ? MAX_REFS : MAX_MODES; | 2987 const int top_mode = bsize < BLOCK_8X8 ? MAX_REFS : MAX_MODES; |
3029 int mode; | 2988 int mode; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3087 const int bws = num_8x8_blocks_wide_lookup[bsize] / 2; | 3046 const int bws = num_8x8_blocks_wide_lookup[bsize] / 2; |
3088 const int bhs = num_8x8_blocks_high_lookup[bsize] / 2; | 3047 const int bhs = num_8x8_blocks_high_lookup[bsize] / 2; |
3089 int best_skip2 = 0; | 3048 int best_skip2 = 0; |
3090 int mode_skip_mask = 0; | 3049 int mode_skip_mask = 0; |
3091 int mode_skip_start = cpi->sf.mode_skip_start + 1; | 3050 int mode_skip_start = cpi->sf.mode_skip_start + 1; |
3092 const int *const rd_threshes = rd_opt->threshes[segment_id][bsize]; | 3051 const int *const rd_threshes = rd_opt->threshes[segment_id][bsize]; |
3093 const int *const rd_thresh_freq_fact = rd_opt->thresh_freq_fact[bsize]; | 3052 const int *const rd_thresh_freq_fact = rd_opt->thresh_freq_fact[bsize]; |
3094 const int mode_search_skip_flags = cpi->sf.mode_search_skip_flags; | 3053 const int mode_search_skip_flags = cpi->sf.mode_search_skip_flags; |
3095 const int intra_y_mode_mask = | 3054 const int intra_y_mode_mask = |
3096 cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]]; | 3055 cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]]; |
3097 int disable_inter_mode_mask = cpi->sf.disable_inter_mode_mask[bsize]; | 3056 int inter_mode_mask = cpi->sf.inter_mode_mask[bsize]; |
3098 vp9_zero(best_mbmode); | 3057 vp9_zero(best_mbmode); |
3099 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; | 3058 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; |
3100 | 3059 |
3101 estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp, | 3060 estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp, |
3102 &comp_mode_p); | 3061 &comp_mode_p); |
3103 | 3062 |
3104 for (i = 0; i < REFERENCE_MODES; ++i) | 3063 for (i = 0; i < REFERENCE_MODES; ++i) |
3105 best_pred_rd[i] = INT64_MAX; | 3064 best_pred_rd[i] = INT64_MAX; |
3106 for (i = 0; i < TX_MODES; i++) | 3065 for (i = 0; i < TX_MODES; i++) |
3107 best_tx_rd[i] = INT64_MAX; | 3066 best_tx_rd[i] = INT64_MAX; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3151 // then do nothing if the current ref frame is not allowed.. | 3110 // then do nothing if the current ref frame is not allowed.. |
3152 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && | 3111 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && |
3153 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) { | 3112 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) { |
3154 mode_skip_mask |= ref_frame_mask_all[ref_frame]; | 3113 mode_skip_mask |= ref_frame_mask_all[ref_frame]; |
3155 } | 3114 } |
3156 } | 3115 } |
3157 | 3116 |
3158 // If the segment skip feature is enabled.... | 3117 // If the segment skip feature is enabled.... |
3159 // then do nothing if the current mode is not allowed.. | 3118 // then do nothing if the current mode is not allowed.. |
3160 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)) { | 3119 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)) { |
3161 const int inter_non_zero_mode_mask = 0x1F7F7; | 3120 mode_skip_mask = ~(1 << THR_ZEROMV); |
3162 mode_skip_mask |= inter_non_zero_mode_mask; | 3121 inter_mode_mask = (1 << ZEROMV); |
3163 } | 3122 } |
3164 | 3123 |
3165 // Disable this drop out case if the ref frame | 3124 // Disable this drop out case if the ref frame |
3166 // segment level feature is enabled for this segment. This is to | 3125 // segment level feature is enabled for this segment. This is to |
3167 // prevent the possibility that we end up unable to pick any mode. | 3126 // prevent the possibility that we end up unable to pick any mode. |
3168 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) { | 3127 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) { |
3169 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, | 3128 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, |
3170 // unless ARNR filtering is enabled in which case we want | 3129 // unless ARNR filtering is enabled in which case we want |
3171 // an unfiltered alternative. We allow near/nearest as well | 3130 // an unfiltered alternative. We allow near/nearest as well |
3172 // because they may result in zero-zero MVs but be cheaper. | 3131 // because they may result in zero-zero MVs but be cheaper. |
(...skipping 13 matching lines...) Expand all Loading... |
3186 // a representative block in the boundary ( first ) and then implement a | 3145 // a representative block in the boundary ( first ) and then implement a |
3187 // function that does sads when inside the border.. | 3146 // function that does sads when inside the border.. |
3188 if ((mi_row + bhs) > cm->mi_rows || (mi_col + bws) > cm->mi_cols) { | 3147 if ((mi_row + bhs) > cm->mi_rows || (mi_col + bws) > cm->mi_cols) { |
3189 const int new_modes_mask = | 3148 const int new_modes_mask = |
3190 (1 << THR_NEWMV) | (1 << THR_NEWG) | (1 << THR_NEWA) | | 3149 (1 << THR_NEWMV) | (1 << THR_NEWG) | (1 << THR_NEWA) | |
3191 (1 << THR_COMP_NEWLA) | (1 << THR_COMP_NEWGA); | 3150 (1 << THR_COMP_NEWLA) | (1 << THR_COMP_NEWGA); |
3192 mode_skip_mask |= new_modes_mask; | 3151 mode_skip_mask |= new_modes_mask; |
3193 } | 3152 } |
3194 | 3153 |
3195 if (bsize > cpi->sf.max_intra_bsize) { | 3154 if (bsize > cpi->sf.max_intra_bsize) { |
3196 mode_skip_mask |= 0xFF30808; | 3155 const int all_intra_modes = (1 << THR_DC) | (1 << THR_TM) | |
| 3156 (1 << THR_H_PRED) | (1 << THR_V_PRED) | (1 << THR_D135_PRED) | |
| 3157 (1 << THR_D207_PRED) | (1 << THR_D153_PRED) | (1 << THR_D63_PRED) | |
| 3158 (1 << THR_D117_PRED) | (1 << THR_D45_PRED); |
| 3159 mode_skip_mask |= all_intra_modes; |
3197 } | 3160 } |
3198 | 3161 |
3199 if (!x->in_active_map) { | 3162 if (!x->in_active_map) { |
3200 int mode_index; | 3163 int mode_index; |
3201 assert(cpi->ref_frame_flags & VP9_LAST_FLAG); | 3164 assert(cpi->ref_frame_flags & VP9_LAST_FLAG); |
3202 if (frame_mv[NEARESTMV][LAST_FRAME].as_int == 0) | 3165 if (frame_mv[NEARESTMV][LAST_FRAME].as_int == 0) |
3203 mode_index = THR_NEARESTMV; | 3166 mode_index = THR_NEARESTMV; |
3204 else if (frame_mv[NEARMV][LAST_FRAME].as_int == 0) | 3167 else if (frame_mv[NEARMV][LAST_FRAME].as_int == 0) |
3205 mode_index = THR_NEARMV; | 3168 mode_index = THR_NEARMV; |
3206 else | 3169 else |
3207 mode_index = THR_ZEROMV; | 3170 mode_index = THR_ZEROMV; |
3208 mode_skip_mask = ~(1 << mode_index); | 3171 mode_skip_mask = ~(1 << mode_index); |
3209 mode_skip_start = MAX_MODES; | 3172 mode_skip_start = MAX_MODES; |
3210 disable_inter_mode_mask = 0; | 3173 inter_mode_mask = (1 << NEARESTMV) | (1 << NEARMV) | (1 << ZEROMV) | |
| 3174 (1 << NEWMV); |
3211 } | 3175 } |
3212 | 3176 |
3213 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { | 3177 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { |
3214 int mode_excluded = 0; | 3178 int mode_excluded = 0; |
3215 int64_t this_rd = INT64_MAX; | 3179 int64_t this_rd = INT64_MAX; |
3216 int disable_skip = 0; | 3180 int disable_skip = 0; |
3217 int compmode_cost = 0; | 3181 int compmode_cost = 0; |
3218 int rate2 = 0, rate_y = 0, rate_uv = 0; | 3182 int rate2 = 0, rate_y = 0, rate_uv = 0; |
3219 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; | 3183 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; |
3220 int skippable = 0; | 3184 int skippable = 0; |
(...skipping 21 matching lines...) Expand all Loading... |
3242 case NONE: | 3206 case NONE: |
3243 case MAX_REF_FRAMES: | 3207 case MAX_REF_FRAMES: |
3244 assert(0 && "Invalid Reference frame"); | 3208 assert(0 && "Invalid Reference frame"); |
3245 } | 3209 } |
3246 } | 3210 } |
3247 if (mode_skip_mask & (1 << mode_index)) | 3211 if (mode_skip_mask & (1 << mode_index)) |
3248 continue; | 3212 continue; |
3249 | 3213 |
3250 // Test best rd so far against threshold for trying this mode. | 3214 // Test best rd so far against threshold for trying this mode. |
3251 if (rd_less_than_thresh(best_rd, rd_threshes[mode_index], | 3215 if (rd_less_than_thresh(best_rd, rd_threshes[mode_index], |
3252 rd_thresh_freq_fact[mode_index])) | 3216 rd_thresh_freq_fact[mode_index])) |
3253 continue; | 3217 continue; |
3254 | 3218 |
3255 this_mode = vp9_mode_order[mode_index].mode; | 3219 this_mode = vp9_mode_order[mode_index].mode; |
3256 ref_frame = vp9_mode_order[mode_index].ref_frame[0]; | 3220 ref_frame = vp9_mode_order[mode_index].ref_frame[0]; |
3257 if (ref_frame != INTRA_FRAME && | 3221 if (ref_frame != INTRA_FRAME && !(inter_mode_mask & (1 << this_mode))) |
3258 disable_inter_mode_mask & (1 << INTER_OFFSET(this_mode))) | |
3259 continue; | 3222 continue; |
3260 second_ref_frame = vp9_mode_order[mode_index].ref_frame[1]; | 3223 second_ref_frame = vp9_mode_order[mode_index].ref_frame[1]; |
3261 | 3224 |
3262 comp_pred = second_ref_frame > INTRA_FRAME; | 3225 comp_pred = second_ref_frame > INTRA_FRAME; |
3263 if (comp_pred) { | 3226 if (comp_pred) { |
3264 if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && | 3227 if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && |
3265 best_mode_index >=0 && | 3228 best_mode_index >=0 && |
3266 vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) | 3229 vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) |
3267 continue; | 3230 continue; |
3268 if ((mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) && | 3231 if ((mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) && |
(...skipping 28 matching lines...) Expand all Loading... |
3297 if (mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { | 3260 if (mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { |
3298 if (conditional_skipintra(this_mode, best_intra_mode)) | 3261 if (conditional_skipintra(this_mode, best_intra_mode)) |
3299 continue; | 3262 continue; |
3300 } | 3263 } |
3301 } | 3264 } |
3302 } else { | 3265 } else { |
3303 if (x->in_active_map && | 3266 if (x->in_active_map && |
3304 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { | 3267 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
3305 const MV_REFERENCE_FRAME ref_frames[2] = {ref_frame, second_ref_frame}; | 3268 const MV_REFERENCE_FRAME ref_frames[2] = {ref_frame, second_ref_frame}; |
3306 if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv, | 3269 if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv, |
3307 disable_inter_mode_mask, this_mode, ref_frames)) | 3270 inter_mode_mask, this_mode, ref_frames)) |
3308 continue; | 3271 continue; |
3309 } | 3272 } |
3310 } | 3273 } |
3311 | 3274 |
3312 mbmi->mode = this_mode; | 3275 mbmi->mode = this_mode; |
3313 mbmi->uv_mode = x->in_active_map ? DC_PRED : this_mode; | 3276 mbmi->uv_mode = x->in_active_map ? DC_PRED : this_mode; |
3314 mbmi->ref_frame[0] = ref_frame; | 3277 mbmi->ref_frame[0] = ref_frame; |
3315 mbmi->ref_frame[1] = second_ref_frame; | 3278 mbmi->ref_frame[1] = second_ref_frame; |
3316 // Evaluate all sub-pel filters irrespective of whether we can use | 3279 // Evaluate all sub-pel filters irrespective of whether we can use |
3317 // them for this frame. | 3280 // them for this frame. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3468 /* required for left and above block mv */ | 3431 /* required for left and above block mv */ |
3469 mbmi->mv[0].as_int = 0; | 3432 mbmi->mv[0].as_int = 0; |
3470 max_plane = 1; | 3433 max_plane = 1; |
3471 } | 3434 } |
3472 | 3435 |
3473 *returnrate = rate2; | 3436 *returnrate = rate2; |
3474 *returndistortion = distortion2; | 3437 *returndistortion = distortion2; |
3475 best_rd = this_rd; | 3438 best_rd = this_rd; |
3476 best_mbmode = *mbmi; | 3439 best_mbmode = *mbmi; |
3477 best_skip2 = this_skip2; | 3440 best_skip2 = this_skip2; |
3478 if (!x->select_txfm_size) | 3441 if (!x->select_tx_size) |
3479 swap_block_ptr(x, ctx, max_plane); | 3442 swap_block_ptr(x, ctx, 1, 0, 0, max_plane); |
3480 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], | 3443 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], |
3481 sizeof(uint8_t) * ctx->num_4x4_blk); | 3444 sizeof(uint8_t) * ctx->num_4x4_blk); |
3482 | 3445 |
3483 // TODO(debargha): enhance this test with a better distortion prediction | 3446 // TODO(debargha): enhance this test with a better distortion prediction |
3484 // based on qp, activity mask and history | 3447 // based on qp, activity mask and history |
3485 if ((mode_search_skip_flags & FLAG_EARLY_TERMINATE) && | 3448 if ((mode_search_skip_flags & FLAG_EARLY_TERMINATE) && |
3486 (mode_index > MIN_EARLY_TERM_INDEX)) { | 3449 (mode_index > MIN_EARLY_TERM_INDEX)) { |
3487 const int qstep = xd->plane[0].dequant[1]; | 3450 const int qstep = xd->plane[0].dequant[1]; |
3488 // TODO(debargha): Enhance this by specializing for each mode_index | 3451 // TODO(debargha): Enhance this by specializing for each mode_index |
3489 int scale = 4; | 3452 int scale = 4; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3635 assert(mbmi->ref_frame[1] == NONE); | 3598 assert(mbmi->ref_frame[1] == NONE); |
3636 assert(mbmi->mode == NEARESTMV || | 3599 assert(mbmi->mode == NEARESTMV || |
3637 mbmi->mode == NEARMV || | 3600 mbmi->mode == NEARMV || |
3638 mbmi->mode == ZEROMV); | 3601 mbmi->mode == ZEROMV); |
3639 assert(frame_mv[mbmi->mode][LAST_FRAME].as_int == 0); | 3602 assert(frame_mv[mbmi->mode][LAST_FRAME].as_int == 0); |
3640 assert(mbmi->mode == mbmi->uv_mode); | 3603 assert(mbmi->mode == mbmi->uv_mode); |
3641 } | 3604 } |
3642 | 3605 |
3643 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); | 3606 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); |
3644 store_coding_context(x, ctx, best_mode_index, | 3607 store_coding_context(x, ctx, best_mode_index, |
3645 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], | |
3646 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : | |
3647 mbmi->ref_frame[1]][0], | |
3648 best_pred_diff, best_tx_diff, best_filter_diff); | 3608 best_pred_diff, best_tx_diff, best_filter_diff); |
3649 | 3609 |
3650 return best_rd; | 3610 return best_rd; |
3651 } | 3611 } |
3652 | 3612 |
3653 | 3613 |
3654 int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, | 3614 int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, |
3655 const TileInfo *const tile, | 3615 const TileInfo *const tile, |
3656 int mi_row, int mi_col, | 3616 int mi_row, int mi_col, |
3657 int *returnrate, | 3617 int *returnrate, |
(...skipping 28 matching lines...) Expand all Loading... |
3686 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME; | 3646 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME; |
3687 INTERP_FILTER tmp_best_filter = SWITCHABLE; | 3647 INTERP_FILTER tmp_best_filter = SWITCHABLE; |
3688 int rate_uv_intra, rate_uv_tokenonly; | 3648 int rate_uv_intra, rate_uv_tokenonly; |
3689 int64_t dist_uv; | 3649 int64_t dist_uv; |
3690 int skip_uv; | 3650 int skip_uv; |
3691 PREDICTION_MODE mode_uv = DC_PRED; | 3651 PREDICTION_MODE mode_uv = DC_PRED; |
3692 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); | 3652 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); |
3693 int_mv seg_mvs[4][MAX_REF_FRAMES]; | 3653 int_mv seg_mvs[4][MAX_REF_FRAMES]; |
3694 b_mode_info best_bmodes[4]; | 3654 b_mode_info best_bmodes[4]; |
3695 int best_skip2 = 0; | 3655 int best_skip2 = 0; |
3696 int ref_frame_mask = 0; | |
3697 int mode_skip_mask = 0; | 3656 int mode_skip_mask = 0; |
3698 | 3657 |
3699 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; | 3658 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; |
3700 vpx_memset(x->zcoeff_blk[TX_4X4], 0, 4); | 3659 vpx_memset(x->zcoeff_blk[TX_4X4], 0, 4); |
3701 vp9_zero(best_mbmode); | 3660 vp9_zero(best_mbmode); |
3702 | 3661 |
3703 for (i = 0; i < 4; i++) { | 3662 for (i = 0; i < 4; i++) { |
3704 int j; | 3663 int j; |
3705 for (j = 0; j < MAX_REF_FRAMES; j++) | 3664 for (j = 0; j < MAX_REF_FRAMES; j++) |
3706 seg_mvs[i][j].as_int = INVALID_MV; | 3665 seg_mvs[i][j].as_int = INVALID_MV; |
(...skipping 14 matching lines...) Expand all Loading... |
3721 if (cpi->ref_frame_flags & flag_list[ref_frame]) { | 3680 if (cpi->ref_frame_flags & flag_list[ref_frame]) { |
3722 vp9_setup_buffer_inter(cpi, x, tile, | 3681 vp9_setup_buffer_inter(cpi, x, tile, |
3723 ref_frame, bsize, mi_row, mi_col, | 3682 ref_frame, bsize, mi_row, mi_col, |
3724 frame_mv[NEARESTMV], frame_mv[NEARMV], | 3683 frame_mv[NEARESTMV], frame_mv[NEARMV], |
3725 yv12_mb); | 3684 yv12_mb); |
3726 } | 3685 } |
3727 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; | 3686 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; |
3728 frame_mv[ZEROMV][ref_frame].as_int = 0; | 3687 frame_mv[ZEROMV][ref_frame].as_int = 0; |
3729 } | 3688 } |
3730 | 3689 |
3731 for (ref_frame = LAST_FRAME; | |
3732 ref_frame <= ALTREF_FRAME && cpi->sf.reference_masking; ++ref_frame) { | |
3733 int i; | |
3734 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { | |
3735 if ((x->pred_mv_sad[ref_frame] >> 1) > x->pred_mv_sad[i]) { | |
3736 ref_frame_mask |= (1 << ref_frame); | |
3737 break; | |
3738 } | |
3739 } | |
3740 } | |
3741 | |
3742 for (ref_index = 0; ref_index < MAX_REFS; ++ref_index) { | 3690 for (ref_index = 0; ref_index < MAX_REFS; ++ref_index) { |
3743 int mode_excluded = 0; | 3691 int mode_excluded = 0; |
3744 int64_t this_rd = INT64_MAX; | 3692 int64_t this_rd = INT64_MAX; |
3745 int disable_skip = 0; | 3693 int disable_skip = 0; |
3746 int compmode_cost = 0; | 3694 int compmode_cost = 0; |
3747 int rate2 = 0, rate_y = 0, rate_uv = 0; | 3695 int rate2 = 0, rate_y = 0, rate_uv = 0; |
3748 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; | 3696 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; |
3749 int skippable = 0; | 3697 int skippable = 0; |
3750 int i; | 3698 int i; |
3751 int this_skip2 = 0; | 3699 int this_skip2 = 0; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3826 mode_excluded = mode_excluded ? mode_excluded | 3774 mode_excluded = mode_excluded ? mode_excluded |
3827 : cm->reference_mode == COMPOUND_REFERENCE; | 3775 : cm->reference_mode == COMPOUND_REFERENCE; |
3828 } | 3776 } |
3829 | 3777 |
3830 // If the segment reference frame feature is enabled.... | 3778 // If the segment reference frame feature is enabled.... |
3831 // then do nothing if the current ref frame is not allowed.. | 3779 // then do nothing if the current ref frame is not allowed.. |
3832 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && | 3780 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && |
3833 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != | 3781 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != |
3834 (int)ref_frame) { | 3782 (int)ref_frame) { |
3835 continue; | 3783 continue; |
3836 // If the segment skip feature is enabled.... | |
3837 // then do nothing if the current mode is not allowed.. | |
3838 } else if (vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP) && | |
3839 ref_frame != INTRA_FRAME) { | |
3840 continue; | |
3841 // Disable this drop out case if the ref frame | 3784 // Disable this drop out case if the ref frame |
3842 // segment level feature is enabled for this segment. This is to | 3785 // segment level feature is enabled for this segment. This is to |
3843 // prevent the possibility that we end up unable to pick any mode. | 3786 // prevent the possibility that we end up unable to pick any mode. |
3844 } else if (!vp9_segfeature_active(seg, segment_id, | 3787 } else if (!vp9_segfeature_active(seg, segment_id, |
3845 SEG_LVL_REF_FRAME)) { | 3788 SEG_LVL_REF_FRAME)) { |
3846 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, | 3789 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, |
3847 // unless ARNR filtering is enabled in which case we want | 3790 // unless ARNR filtering is enabled in which case we want |
3848 // an unfiltered alternative. We allow near/nearest as well | 3791 // an unfiltered alternative. We allow near/nearest as well |
3849 // because they may result in zero-zero MVs but be cheaper. | 3792 // because they may result in zero-zero MVs but be cheaper. |
3850 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) | 3793 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4055 | 3998 |
4056 // Estimate the reference frame signaling cost and add it | 3999 // Estimate the reference frame signaling cost and add it |
4057 // to the rolling cost variable. | 4000 // to the rolling cost variable. |
4058 if (second_ref_frame > INTRA_FRAME) { | 4001 if (second_ref_frame > INTRA_FRAME) { |
4059 rate2 += ref_costs_comp[ref_frame]; | 4002 rate2 += ref_costs_comp[ref_frame]; |
4060 } else { | 4003 } else { |
4061 rate2 += ref_costs_single[ref_frame]; | 4004 rate2 += ref_costs_single[ref_frame]; |
4062 } | 4005 } |
4063 | 4006 |
4064 if (!disable_skip) { | 4007 if (!disable_skip) { |
4065 // Test for the condition where skip block will be activated | 4008 // Skip is never coded at the segment level for sub8x8 blocks and instead |
4066 // because there are no non zero coefficients and make any | 4009 // always coded in the bitstream at the mode info level. |
4067 // necessary adjustment for rate. Ignore if skip is coded at | |
4068 // segment level as the cost wont have been added in. | |
4069 // Is Mb level skip allowed (i.e. not coded at segment level). | |
4070 const int mb_skip_allowed = !vp9_segfeature_active(seg, segment_id, | |
4071 SEG_LVL_SKIP); | |
4072 | 4010 |
4073 if (mb_skip_allowed && ref_frame != INTRA_FRAME && !xd->lossless) { | 4011 if (ref_frame != INTRA_FRAME && !xd->lossless) { |
4074 if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) < | 4012 if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) < |
4075 RDCOST(x->rdmult, x->rddiv, 0, total_sse)) { | 4013 RDCOST(x->rdmult, x->rddiv, 0, total_sse)) { |
4076 // Add in the cost of the no skip flag. | 4014 // Add in the cost of the no skip flag. |
4077 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); | 4015 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); |
4078 } else { | 4016 } else { |
4079 // FIXME(rbultje) make this work for splitmv also | 4017 // FIXME(rbultje) make this work for splitmv also |
4080 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); | 4018 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); |
4081 distortion2 = total_sse; | 4019 distortion2 = total_sse; |
4082 assert(total_sse >= 0); | 4020 assert(total_sse >= 0); |
4083 rate2 -= (rate_y + rate_uv); | 4021 rate2 -= (rate_y + rate_uv); |
4084 rate_y = 0; | 4022 rate_y = 0; |
4085 rate_uv = 0; | 4023 rate_uv = 0; |
4086 this_skip2 = 1; | 4024 this_skip2 = 1; |
4087 } | 4025 } |
4088 } else if (mb_skip_allowed) { | 4026 } else { |
4089 // Add in the cost of the no skip flag. | 4027 // Add in the cost of the no skip flag. |
4090 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); | 4028 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); |
4091 } | 4029 } |
4092 | 4030 |
4093 // Calculate the final RD estimate for this mode. | 4031 // Calculate the final RD estimate for this mode. |
4094 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); | 4032 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); |
4095 } | 4033 } |
4096 | 4034 |
4097 // Keep record of best inter rd with single reference | 4035 // Keep record of best inter rd with single reference |
4098 if (is_inter_block(mbmi) && | 4036 if (is_inter_block(mbmi) && |
(...skipping 24 matching lines...) Expand all Loading... |
4123 max_plane = 1; | 4061 max_plane = 1; |
4124 } | 4062 } |
4125 | 4063 |
4126 *returnrate = rate2; | 4064 *returnrate = rate2; |
4127 *returndistortion = distortion2; | 4065 *returndistortion = distortion2; |
4128 best_rd = this_rd; | 4066 best_rd = this_rd; |
4129 best_yrd = best_rd - | 4067 best_yrd = best_rd - |
4130 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv); | 4068 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv); |
4131 best_mbmode = *mbmi; | 4069 best_mbmode = *mbmi; |
4132 best_skip2 = this_skip2; | 4070 best_skip2 = this_skip2; |
4133 if (!x->select_txfm_size) | 4071 if (!x->select_tx_size) |
4134 swap_block_ptr(x, ctx, max_plane); | 4072 swap_block_ptr(x, ctx, 1, 0, 0, max_plane); |
4135 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[TX_4X4], | 4073 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[TX_4X4], |
4136 sizeof(uint8_t) * ctx->num_4x4_blk); | 4074 sizeof(uint8_t) * ctx->num_4x4_blk); |
4137 | 4075 |
4138 for (i = 0; i < 4; i++) | 4076 for (i = 0; i < 4; i++) |
4139 best_bmodes[i] = xd->mi[0]->bmi[i]; | 4077 best_bmodes[i] = xd->mi[0]->bmi[i]; |
4140 | 4078 |
4141 // TODO(debargha): enhance this test with a better distortion prediction | 4079 // TODO(debargha): enhance this test with a better distortion prediction |
4142 // based on qp, activity mask and history | 4080 // based on qp, activity mask and history |
4143 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) && | 4081 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) && |
4144 (ref_index > MIN_EARLY_TERM_INDEX)) { | 4082 (ref_index > MIN_EARLY_TERM_INDEX)) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4268 best_filter_diff[i] = best_rd - best_filter_rd[i]; | 4206 best_filter_diff[i] = best_rd - best_filter_rd[i]; |
4269 } | 4207 } |
4270 if (cm->interp_filter == SWITCHABLE) | 4208 if (cm->interp_filter == SWITCHABLE) |
4271 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); | 4209 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); |
4272 } else { | 4210 } else { |
4273 vp9_zero(best_filter_diff); | 4211 vp9_zero(best_filter_diff); |
4274 } | 4212 } |
4275 | 4213 |
4276 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); | 4214 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); |
4277 store_coding_context(x, ctx, best_ref_index, | 4215 store_coding_context(x, ctx, best_ref_index, |
4278 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], | |
4279 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : | |
4280 mbmi->ref_frame[1]][0], | |
4281 best_pred_diff, best_tx_diff, best_filter_diff); | 4216 best_pred_diff, best_tx_diff, best_filter_diff); |
4282 | 4217 |
4283 return best_rd; | 4218 return best_rd; |
4284 } | 4219 } |
4285 | 4220 |
4286 void vp9_set_rd_speed_thresholds(VP9_COMP *cpi) { | 4221 void vp9_set_rd_speed_thresholds(VP9_COMP *cpi) { |
4287 int i; | 4222 int i; |
4288 RD_OPT *const rd = &cpi->rd; | 4223 RD_OPT *const rd = &cpi->rd; |
4289 | 4224 |
4290 // Set baseline threshold values | 4225 // Set baseline threshold values |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4392 rd->thresh_mult_sub8x8[THR_GOLD] = INT_MAX; | 4327 rd->thresh_mult_sub8x8[THR_GOLD] = INT_MAX; |
4393 if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) | 4328 if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) |
4394 rd->thresh_mult_sub8x8[THR_ALTR] = INT_MAX; | 4329 rd->thresh_mult_sub8x8[THR_ALTR] = INT_MAX; |
4395 if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) != | 4330 if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) != |
4396 (VP9_LAST_FLAG | VP9_ALT_FLAG)) | 4331 (VP9_LAST_FLAG | VP9_ALT_FLAG)) |
4397 rd->thresh_mult_sub8x8[THR_COMP_LA] = INT_MAX; | 4332 rd->thresh_mult_sub8x8[THR_COMP_LA] = INT_MAX; |
4398 if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) != | 4333 if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) != |
4399 (VP9_GOLD_FLAG | VP9_ALT_FLAG)) | 4334 (VP9_GOLD_FLAG | VP9_ALT_FLAG)) |
4400 rd->thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX; | 4335 rd->thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX; |
4401 } | 4336 } |
OLD | NEW |