| 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 20 matching lines...) Expand all Loading... |
| 31 #include "vp9/common/vp9_tile_common.h" | 31 #include "vp9/common/vp9_tile_common.h" |
| 32 | 32 |
| 33 #include "vp9/encoder/vp9_aq_complexity.h" | 33 #include "vp9/encoder/vp9_aq_complexity.h" |
| 34 #include "vp9/encoder/vp9_aq_cyclicrefresh.h" | 34 #include "vp9/encoder/vp9_aq_cyclicrefresh.h" |
| 35 #include "vp9/encoder/vp9_aq_variance.h" | 35 #include "vp9/encoder/vp9_aq_variance.h" |
| 36 #include "vp9/encoder/vp9_encodeframe.h" | 36 #include "vp9/encoder/vp9_encodeframe.h" |
| 37 #include "vp9/encoder/vp9_encodemb.h" | 37 #include "vp9/encoder/vp9_encodemb.h" |
| 38 #include "vp9/encoder/vp9_encodemv.h" | 38 #include "vp9/encoder/vp9_encodemv.h" |
| 39 #include "vp9/encoder/vp9_extend.h" | 39 #include "vp9/encoder/vp9_extend.h" |
| 40 #include "vp9/encoder/vp9_pickmode.h" | 40 #include "vp9/encoder/vp9_pickmode.h" |
| 41 #include "vp9/encoder/vp9_rd.h" |
| 41 #include "vp9/encoder/vp9_rdopt.h" | 42 #include "vp9/encoder/vp9_rdopt.h" |
| 42 #include "vp9/encoder/vp9_segmentation.h" | 43 #include "vp9/encoder/vp9_segmentation.h" |
| 43 #include "vp9/encoder/vp9_tokenize.h" | 44 #include "vp9/encoder/vp9_tokenize.h" |
| 44 | 45 |
| 45 #define GF_ZEROMV_ZBIN_BOOST 0 | 46 #define GF_ZEROMV_ZBIN_BOOST 0 |
| 46 #define LF_ZEROMV_ZBIN_BOOST 0 | 47 #define LF_ZEROMV_ZBIN_BOOST 0 |
| 47 #define MV_ZBIN_BOOST 0 | 48 #define MV_ZBIN_BOOST 0 |
| 48 #define SPLIT_MV_ZBIN_BOOST 0 | 49 #define SPLIT_MV_ZBIN_BOOST 0 |
| 49 #define INTRA_ZBIN_BOOST 0 | 50 #define INTRA_ZBIN_BOOST 0 |
| 50 | 51 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 63 128, 128, 128, 128, 128, 128, 128, 128, | 64 128, 128, 128, 128, 128, 128, 128, 128, |
| 64 128, 128, 128, 128, 128, 128, 128, 128, | 65 128, 128, 128, 128, 128, 128, 128, 128, |
| 65 128, 128, 128, 128, 128, 128, 128, 128, | 66 128, 128, 128, 128, 128, 128, 128, 128, |
| 66 128, 128, 128, 128, 128, 128, 128, 128, | 67 128, 128, 128, 128, 128, 128, 128, 128, |
| 67 128, 128, 128, 128, 128, 128, 128, 128, | 68 128, 128, 128, 128, 128, 128, 128, 128, |
| 68 128, 128, 128, 128, 128, 128, 128, 128, | 69 128, 128, 128, 128, 128, 128, 128, 128, |
| 69 128, 128, 128, 128, 128, 128, 128, 128, | 70 128, 128, 128, 128, 128, 128, 128, 128, |
| 70 128, 128, 128, 128, 128, 128, 128, 128 | 71 128, 128, 128, 128, 128, 128, 128, 128 |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 typedef struct { | |
| 74 unsigned int sse; | |
| 75 int sum; | |
| 76 unsigned int var; | |
| 77 } diff; | |
| 78 | |
| 79 static unsigned int get_sby_perpixel_variance(VP9_COMP *cpi, | 74 static unsigned int get_sby_perpixel_variance(VP9_COMP *cpi, |
| 80 const struct buf_2d *ref, | 75 const struct buf_2d *ref, |
| 81 BLOCK_SIZE bs) { | 76 BLOCK_SIZE bs) { |
| 82 unsigned int sse; | 77 unsigned int sse; |
| 83 const unsigned int var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride, | 78 const unsigned int var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride, |
| 84 VP9_VAR_OFFS, 0, &sse); | 79 VP9_VAR_OFFS, 0, &sse); |
| 85 return ROUND_POWER_OF_TWO(var, num_pels_log2_lookup[bs]); | 80 return ROUND_POWER_OF_TWO(var, num_pels_log2_lookup[bs]); |
| 86 } | 81 } |
| 87 | 82 |
| 88 static unsigned int get_sby_perpixel_diff_variance(VP9_COMP *cpi, | 83 static unsigned int get_sby_perpixel_diff_variance(VP9_COMP *cpi, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // pointers. | 127 // pointers. |
| 133 static INLINE void set_modeinfo_offsets(VP9_COMMON *const cm, | 128 static INLINE void set_modeinfo_offsets(VP9_COMMON *const cm, |
| 134 MACROBLOCKD *const xd, | 129 MACROBLOCKD *const xd, |
| 135 int mi_row, | 130 int mi_row, |
| 136 int mi_col) { | 131 int mi_col) { |
| 137 const int idx_str = xd->mi_stride * mi_row + mi_col; | 132 const int idx_str = xd->mi_stride * mi_row + mi_col; |
| 138 xd->mi = cm->mi_grid_visible + idx_str; | 133 xd->mi = cm->mi_grid_visible + idx_str; |
| 139 xd->mi[0] = cm->mi + idx_str; | 134 xd->mi[0] = cm->mi + idx_str; |
| 140 } | 135 } |
| 141 | 136 |
| 142 static int is_block_in_mb_map(const VP9_COMP *cpi, int mi_row, int mi_col, | |
| 143 BLOCK_SIZE bsize) { | |
| 144 const VP9_COMMON *const cm = &cpi->common; | |
| 145 const int mb_rows = cm->mb_rows; | |
| 146 const int mb_cols = cm->mb_cols; | |
| 147 const int mb_row = mi_row >> 1; | |
| 148 const int mb_col = mi_col >> 1; | |
| 149 const int mb_width = num_8x8_blocks_wide_lookup[bsize] >> 1; | |
| 150 const int mb_height = num_8x8_blocks_high_lookup[bsize] >> 1; | |
| 151 int r, c; | |
| 152 if (bsize <= BLOCK_16X16) { | |
| 153 return cpi->active_map[mb_row * mb_cols + mb_col]; | |
| 154 } | |
| 155 for (r = 0; r < mb_height; ++r) { | |
| 156 for (c = 0; c < mb_width; ++c) { | |
| 157 int row = mb_row + r; | |
| 158 int col = mb_col + c; | |
| 159 if (row >= mb_rows || col >= mb_cols) | |
| 160 continue; | |
| 161 if (cpi->active_map[row * mb_cols + col]) | |
| 162 return 1; | |
| 163 } | |
| 164 } | |
| 165 return 0; | |
| 166 } | |
| 167 | |
| 168 static int check_active_map(const VP9_COMP *cpi, const MACROBLOCK *x, | |
| 169 int mi_row, int mi_col, | |
| 170 BLOCK_SIZE bsize) { | |
| 171 if (cpi->active_map_enabled && !x->e_mbd.lossless) { | |
| 172 return is_block_in_mb_map(cpi, mi_row, mi_col, bsize); | |
| 173 } else { | |
| 174 return 1; | |
| 175 } | |
| 176 } | |
| 177 | |
| 178 static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile, | 137 static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile, |
| 179 int mi_row, int mi_col, BLOCK_SIZE bsize) { | 138 int mi_row, int mi_col, BLOCK_SIZE bsize) { |
| 180 MACROBLOCK *const x = &cpi->mb; | 139 MACROBLOCK *const x = &cpi->mb; |
| 181 VP9_COMMON *const cm = &cpi->common; | 140 VP9_COMMON *const cm = &cpi->common; |
| 182 MACROBLOCKD *const xd = &x->e_mbd; | 141 MACROBLOCKD *const xd = &x->e_mbd; |
| 183 MB_MODE_INFO *mbmi; | 142 MB_MODE_INFO *mbmi; |
| 184 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 143 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
| 185 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 144 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
| 186 const struct segmentation *const seg = &cm->seg; | 145 const struct segmentation *const seg = &cm->seg; |
| 187 | 146 |
| 188 set_skip_context(xd, mi_row, mi_col); | 147 set_skip_context(xd, mi_row, mi_col); |
| 189 | 148 |
| 190 // Activity map pointer | |
| 191 x->in_active_map = check_active_map(cpi, x, mi_row, mi_col, bsize); | |
| 192 | |
| 193 set_modeinfo_offsets(cm, xd, mi_row, mi_col); | 149 set_modeinfo_offsets(cm, xd, mi_row, mi_col); |
| 194 | 150 |
| 195 mbmi = &xd->mi[0]->mbmi; | 151 mbmi = &xd->mi[0]->mbmi; |
| 196 | 152 |
| 197 // Set up destination pointers. | 153 // Set up destination pointers. |
| 198 vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col); | 154 vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col); |
| 199 | 155 |
| 200 // Set up limit values for MV components. | 156 // Set up limit values for MV components. |
| 201 // Mv beyond the range do not produce new/different prediction block. | 157 // Mv beyond the range do not produce new/different prediction block. |
| 202 x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND); | 158 x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND); |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 tx_mode_to_biggest_tx_size[tx_mode]); | 672 tx_mode_to_biggest_tx_size[tx_mode]); |
| 717 mbmi->skip = 1; | 673 mbmi->skip = 1; |
| 718 mbmi->uv_mode = DC_PRED; | 674 mbmi->uv_mode = DC_PRED; |
| 719 mbmi->ref_frame[0] = LAST_FRAME; | 675 mbmi->ref_frame[0] = LAST_FRAME; |
| 720 mbmi->ref_frame[1] = NONE; | 676 mbmi->ref_frame[1] = NONE; |
| 721 mbmi->mv[0].as_int = 0; | 677 mbmi->mv[0].as_int = 0; |
| 722 mbmi->interp_filter = filter_ref; | 678 mbmi->interp_filter = filter_ref; |
| 723 | 679 |
| 724 xd->mi[0]->bmi[0].as_mv[0].as_int = 0; | 680 xd->mi[0]->bmi[0].as_mv[0].as_int = 0; |
| 725 x->skip = 1; | 681 x->skip = 1; |
| 726 x->skip_encode = 1; | |
| 727 | 682 |
| 728 *rate = 0; | 683 *rate = 0; |
| 729 *dist = 0; | 684 *dist = 0; |
| 730 } | 685 } |
| 731 | 686 |
| 732 static void rd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, | 687 static void rd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, |
| 733 int mi_row, int mi_col, | 688 int mi_row, int mi_col, |
| 734 int *totalrate, int64_t *totaldist, | 689 int *totalrate, int64_t *totaldist, |
| 735 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, | 690 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, |
| 736 int64_t best_rd, int block) { | 691 int64_t best_rd, int block) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 if (vp9_get_segment_id(cm, map, bsize, mi_row, mi_col)) | 770 if (vp9_get_segment_id(cm, map, bsize, mi_row, mi_col)) |
| 816 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); | 771 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); |
| 817 } | 772 } |
| 818 | 773 |
| 819 // Find best coding mode & reconstruct the MB so it is available | 774 // Find best coding mode & reconstruct the MB so it is available |
| 820 // as a predictor for MBs that follow in the SB | 775 // as a predictor for MBs that follow in the SB |
| 821 if (frame_is_intra_only(cm)) { | 776 if (frame_is_intra_only(cm)) { |
| 822 vp9_rd_pick_intra_mode_sb(cpi, x, totalrate, totaldist, bsize, ctx, | 777 vp9_rd_pick_intra_mode_sb(cpi, x, totalrate, totaldist, bsize, ctx, |
| 823 best_rd); | 778 best_rd); |
| 824 } else { | 779 } else { |
| 825 if (bsize >= BLOCK_8X8) | 780 if (bsize >= BLOCK_8X8) { |
| 826 vp9_rd_pick_inter_mode_sb(cpi, x, tile, mi_row, mi_col, | 781 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) |
| 827 totalrate, totaldist, bsize, ctx, best_rd); | 782 vp9_rd_pick_inter_mode_sb_seg_skip(cpi, x, totalrate, totaldist, bsize, |
| 828 else | 783 ctx, best_rd); |
| 784 else |
| 785 vp9_rd_pick_inter_mode_sb(cpi, x, tile, mi_row, mi_col, |
| 786 totalrate, totaldist, bsize, ctx, best_rd); |
| 787 } else { |
| 829 vp9_rd_pick_inter_mode_sub8x8(cpi, x, tile, mi_row, mi_col, totalrate, | 788 vp9_rd_pick_inter_mode_sub8x8(cpi, x, tile, mi_row, mi_col, totalrate, |
| 830 totaldist, bsize, ctx, best_rd); | 789 totaldist, bsize, ctx, best_rd); |
| 790 } |
| 831 } | 791 } |
| 832 | 792 |
| 833 x->rdmult = orig_rdmult; | 793 x->rdmult = orig_rdmult; |
| 834 | 794 |
| 835 if (aq_mode == VARIANCE_AQ && *totalrate != INT_MAX) { | 795 if (aq_mode == VARIANCE_AQ && *totalrate != INT_MAX) { |
| 836 vp9_clear_system_state(); | 796 vp9_clear_system_state(); |
| 837 *totalrate = (int)round(*totalrate * rdmult_ratio); | 797 *totalrate = (int)round(*totalrate * rdmult_ratio); |
| 838 } | 798 } |
| 839 } | 799 } |
| 840 | 800 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), | 862 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), |
| 903 l + num_4x4_blocks_high * p, | 863 l + num_4x4_blocks_high * p, |
| 904 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> | 864 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> |
| 905 xd->plane[p].subsampling_y); | 865 xd->plane[p].subsampling_y); |
| 906 } | 866 } |
| 907 vpx_memcpy(xd->above_seg_context + mi_col, sa, | 867 vpx_memcpy(xd->above_seg_context + mi_col, sa, |
| 908 sizeof(*xd->above_seg_context) * mi_width); | 868 sizeof(*xd->above_seg_context) * mi_width); |
| 909 vpx_memcpy(xd->left_seg_context + (mi_row & MI_MASK), sl, | 869 vpx_memcpy(xd->left_seg_context + (mi_row & MI_MASK), sl, |
| 910 sizeof(xd->left_seg_context[0]) * mi_height); | 870 sizeof(xd->left_seg_context[0]) * mi_height); |
| 911 } | 871 } |
| 872 |
| 912 static void save_context(VP9_COMP *cpi, int mi_row, int mi_col, | 873 static void save_context(VP9_COMP *cpi, int mi_row, int mi_col, |
| 913 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], | 874 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], |
| 914 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], | 875 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], |
| 915 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], | 876 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], |
| 916 BLOCK_SIZE bsize) { | 877 BLOCK_SIZE bsize) { |
| 917 const MACROBLOCK *const x = &cpi->mb; | 878 const MACROBLOCK *const x = &cpi->mb; |
| 918 const MACROBLOCKD *const xd = &x->e_mbd; | 879 const MACROBLOCKD *const xd = &x->e_mbd; |
| 919 int p; | 880 int p; |
| 920 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 881 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
| 921 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 882 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 939 vpx_memcpy(sa, xd->above_seg_context + mi_col, | 900 vpx_memcpy(sa, xd->above_seg_context + mi_col, |
| 940 sizeof(*xd->above_seg_context) * mi_width); | 901 sizeof(*xd->above_seg_context) * mi_width); |
| 941 vpx_memcpy(sl, xd->left_seg_context + (mi_row & MI_MASK), | 902 vpx_memcpy(sl, xd->left_seg_context + (mi_row & MI_MASK), |
| 942 sizeof(xd->left_seg_context[0]) * mi_height); | 903 sizeof(xd->left_seg_context[0]) * mi_height); |
| 943 } | 904 } |
| 944 | 905 |
| 945 static void encode_b(VP9_COMP *cpi, const TileInfo *const tile, | 906 static void encode_b(VP9_COMP *cpi, const TileInfo *const tile, |
| 946 TOKENEXTRA **tp, int mi_row, int mi_col, | 907 TOKENEXTRA **tp, int mi_row, int mi_col, |
| 947 int output_enabled, BLOCK_SIZE bsize, | 908 int output_enabled, BLOCK_SIZE bsize, |
| 948 PICK_MODE_CONTEXT *ctx) { | 909 PICK_MODE_CONTEXT *ctx) { |
| 949 | |
| 950 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 910 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 951 update_state(cpi, ctx, mi_row, mi_col, bsize, output_enabled); | 911 update_state(cpi, ctx, mi_row, mi_col, bsize, output_enabled); |
| 952 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize, ctx); | 912 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize, ctx); |
| 953 | 913 |
| 954 if (output_enabled) { | 914 if (output_enabled) { |
| 955 update_stats(cpi); | 915 update_stats(cpi); |
| 956 | 916 |
| 957 (*tp)->token = EOSB_TOKEN; | 917 (*tp)->token = EOSB_TOKEN; |
| 958 (*tp)++; | 918 (*tp)++; |
| 959 } | 919 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 mi_8x8[index]->mbmi.sb_type = bsize; | 1128 mi_8x8[index]->mbmi.sb_type = bsize; |
| 1169 } | 1129 } |
| 1170 } | 1130 } |
| 1171 } | 1131 } |
| 1172 } else { | 1132 } else { |
| 1173 // Else this is a partial SB64, copy previous partition. | 1133 // Else this is a partial SB64, copy previous partition. |
| 1174 copy_partitioning(cm, mi_8x8, prev_mi_8x8); | 1134 copy_partitioning(cm, mi_8x8, prev_mi_8x8); |
| 1175 } | 1135 } |
| 1176 } | 1136 } |
| 1177 | 1137 |
| 1178 | |
| 1179 const struct { | 1138 const struct { |
| 1180 int row; | 1139 int row; |
| 1181 int col; | 1140 int col; |
| 1182 } coord_lookup[16] = { | 1141 } coord_lookup[16] = { |
| 1183 // 32x32 index = 0 | 1142 // 32x32 index = 0 |
| 1184 {0, 0}, {0, 2}, {2, 0}, {2, 2}, | 1143 {0, 0}, {0, 2}, {2, 0}, {2, 2}, |
| 1185 // 32x32 index = 1 | 1144 // 32x32 index = 1 |
| 1186 {0, 4}, {0, 6}, {2, 4}, {2, 6}, | 1145 {0, 4}, {0, 6}, {2, 4}, {2, 6}, |
| 1187 // 32x32 index = 2 | 1146 // 32x32 index = 2 |
| 1188 {4, 0}, {4, 2}, {6, 0}, {6, 2}, | 1147 {4, 0}, {4, 2}, {6, 0}, {6, 2}, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1201 const int col8x8_remaining = tile->mi_col_end - mi_col; | 1160 const int col8x8_remaining = tile->mi_col_end - mi_col; |
| 1202 MODE_INFO *mi_upper_left = cm->mi + mi_row * mis + mi_col; | 1161 MODE_INFO *mi_upper_left = cm->mi + mi_row * mis + mi_col; |
| 1203 | 1162 |
| 1204 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); | 1163 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); |
| 1205 | 1164 |
| 1206 assert((row8x8_remaining > 0) && (col8x8_remaining > 0)); | 1165 assert((row8x8_remaining > 0) && (col8x8_remaining > 0)); |
| 1207 | 1166 |
| 1208 // In-image SB64 | 1167 // In-image SB64 |
| 1209 if ((col8x8_remaining >= MI_BLOCK_SIZE) && | 1168 if ((col8x8_remaining >= MI_BLOCK_SIZE) && |
| 1210 (row8x8_remaining >= MI_BLOCK_SIZE)) { | 1169 (row8x8_remaining >= MI_BLOCK_SIZE)) { |
| 1211 const int src_stride = x->plane[0].src.stride; | |
| 1212 const int pre_stride = cpi->Last_Source->y_stride; | |
| 1213 const uint8_t *src = x->plane[0].src.buf; | |
| 1214 const int pre_offset = (mi_row * MI_SIZE) * pre_stride + | |
| 1215 (mi_col * MI_SIZE); | |
| 1216 const uint8_t *pre_src = cpi->Last_Source->y_buffer + pre_offset; | |
| 1217 const unsigned int thr_32x32 = cpi->sf.source_var_thresh; | |
| 1218 const unsigned int thr_64x64 = thr_32x32 << 1; | |
| 1219 int i, j; | 1170 int i, j; |
| 1220 int index; | 1171 int index; |
| 1221 diff d32[4]; | 1172 diff d32[4]; |
| 1222 int use16x16 = 0; | 1173 const int offset = (mi_row >> 1) * cm->mb_cols + (mi_col >> 1); |
| 1174 int is_larger_better = 0; |
| 1175 int use32x32 = 0; |
| 1176 unsigned int thr = cpi->source_var_thresh; |
| 1177 |
| 1178 vpx_memset(d32, 0, 4 * sizeof(diff)); |
| 1223 | 1179 |
| 1224 for (i = 0; i < 4; i++) { | 1180 for (i = 0; i < 4; i++) { |
| 1225 diff d16[4]; | 1181 diff *d16[4]; |
| 1226 | 1182 |
| 1227 for (j = 0; j < 4; j++) { | 1183 for (j = 0; j < 4; j++) { |
| 1228 int b_mi_row = coord_lookup[i * 4 + j].row; | 1184 int b_mi_row = coord_lookup[i * 4 + j].row; |
| 1229 int b_mi_col = coord_lookup[i * 4 + j].col; | 1185 int b_mi_col = coord_lookup[i * 4 + j].col; |
| 1230 int b_offset = b_mi_row * MI_SIZE * src_stride + | 1186 int boffset = b_mi_row / 2 * cm->mb_cols + |
| 1231 b_mi_col * MI_SIZE; | 1187 b_mi_col / 2; |
| 1232 | 1188 |
| 1233 vp9_get16x16var(src + b_offset, src_stride, | 1189 d16[j] = cpi->source_diff_var + offset + boffset; |
| 1234 pre_src + b_offset, pre_stride, | |
| 1235 &d16[j].sse, &d16[j].sum); | |
| 1236 | |
| 1237 d16[j].var = d16[j].sse - | |
| 1238 (((uint32_t)d16[j].sum * d16[j].sum) >> 8); | |
| 1239 | 1190 |
| 1240 index = b_mi_row * mis + b_mi_col; | 1191 index = b_mi_row * mis + b_mi_col; |
| 1241 mi_8x8[index] = mi_upper_left + index; | 1192 mi_8x8[index] = mi_upper_left + index; |
| 1242 mi_8x8[index]->mbmi.sb_type = BLOCK_16X16; | 1193 mi_8x8[index]->mbmi.sb_type = BLOCK_16X16; |
| 1243 | 1194 |
| 1244 // TODO(yunqingwang): If d16[j].var is very large, use 8x8 partition | 1195 // TODO(yunqingwang): If d16[j].var is very large, use 8x8 partition |
| 1245 // size to further improve quality. | 1196 // size to further improve quality. |
| 1246 } | 1197 } |
| 1247 | 1198 |
| 1248 if (d16[0].var < thr_32x32 && d16[1].var < thr_32x32 && | 1199 is_larger_better = (d16[0]->var < thr) && (d16[1]->var < thr) && |
| 1249 d16[2].var < thr_32x32 && d16[3].var < thr_32x32) { | 1200 (d16[2]->var < thr) && (d16[3]->var < thr); |
| 1250 d32[i].sse = d16[0].sse; | |
| 1251 d32[i].sum = d16[0].sum; | |
| 1252 | 1201 |
| 1253 for (j = 1; j < 4; j++) { | 1202 // Use 32x32 partition |
| 1254 d32[i].sse += d16[j].sse; | 1203 if (is_larger_better) { |
| 1255 d32[i].sum += d16[j].sum; | 1204 use32x32 += 1; |
| 1205 |
| 1206 for (j = 0; j < 4; j++) { |
| 1207 d32[i].sse += d16[j]->sse; |
| 1208 d32[i].sum += d16[j]->sum; |
| 1256 } | 1209 } |
| 1257 | 1210 |
| 1258 d32[i].var = d32[i].sse - (((int64_t)d32[i].sum * d32[i].sum) >> 10); | 1211 d32[i].var = d32[i].sse - (((int64_t)d32[i].sum * d32[i].sum) >> 10); |
| 1259 | 1212 |
| 1260 index = coord_lookup[i*4].row * mis + coord_lookup[i*4].col; | 1213 index = coord_lookup[i*4].row * mis + coord_lookup[i*4].col; |
| 1261 mi_8x8[index] = mi_upper_left + index; | 1214 mi_8x8[index] = mi_upper_left + index; |
| 1262 mi_8x8[index]->mbmi.sb_type = BLOCK_32X32; | 1215 mi_8x8[index]->mbmi.sb_type = BLOCK_32X32; |
| 1263 | |
| 1264 if (!((cm->current_video_frame - 1) % | |
| 1265 cpi->sf.search_type_check_frequency)) | |
| 1266 cpi->use_large_partition_rate += 1; | |
| 1267 } else { | |
| 1268 use16x16 = 1; | |
| 1269 } | 1216 } |
| 1270 } | 1217 } |
| 1271 | 1218 |
| 1272 if (!use16x16) { | 1219 if (use32x32 == 4) { |
| 1273 if (d32[0].var < thr_64x64 && d32[1].var < thr_64x64 && | 1220 thr <<= 1; |
| 1274 d32[2].var < thr_64x64 && d32[3].var < thr_64x64) { | 1221 is_larger_better = (d32[0].var < thr) && (d32[1].var < thr) && |
| 1222 (d32[2].var < thr) && (d32[3].var < thr); |
| 1223 |
| 1224 // Use 64x64 partition |
| 1225 if (is_larger_better) { |
| 1275 mi_8x8[0] = mi_upper_left; | 1226 mi_8x8[0] = mi_upper_left; |
| 1276 mi_8x8[0]->mbmi.sb_type = BLOCK_64X64; | 1227 mi_8x8[0]->mbmi.sb_type = BLOCK_64X64; |
| 1277 } | 1228 } |
| 1278 } | 1229 } |
| 1279 } else { // partial in-image SB64 | 1230 } else { // partial in-image SB64 |
| 1280 int bh = num_8x8_blocks_high_lookup[BLOCK_16X16]; | 1231 int bh = num_8x8_blocks_high_lookup[BLOCK_16X16]; |
| 1281 int bw = num_8x8_blocks_wide_lookup[BLOCK_16X16]; | 1232 int bw = num_8x8_blocks_wide_lookup[BLOCK_16X16]; |
| 1282 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, | 1233 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, |
| 1283 row8x8_remaining, col8x8_remaining, BLOCK_16X16, mi_8x8); | 1234 row8x8_remaining, col8x8_remaining, BLOCK_16X16, mi_8x8); |
| 1284 } | 1235 } |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 | 1452 |
| 1502 partition = partition_lookup[bsl][bs_type]; | 1453 partition = partition_lookup[bsl][bs_type]; |
| 1503 subsize = get_subsize(bsize, partition); | 1454 subsize = get_subsize(bsize, partition); |
| 1504 | 1455 |
| 1505 pc_tree->partitioning = partition; | 1456 pc_tree->partitioning = partition; |
| 1506 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1457 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1507 | 1458 |
| 1508 if (bsize == BLOCK_16X16) { | 1459 if (bsize == BLOCK_16X16) { |
| 1509 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 1460 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 1510 x->mb_energy = vp9_block_energy(cpi, x, bsize); | 1461 x->mb_energy = vp9_block_energy(cpi, x, bsize); |
| 1511 } else { | |
| 1512 x->in_active_map = check_active_map(cpi, x, mi_row, mi_col, bsize); | |
| 1513 } | 1462 } |
| 1514 | 1463 |
| 1515 if (!x->in_active_map) { | |
| 1516 do_partition_search = 0; | |
| 1517 if (mi_row + (mi_step >> 1) < cm->mi_rows && | |
| 1518 mi_col + (mi_step >> 1) < cm->mi_cols) { | |
| 1519 pc_tree->partitioning = PARTITION_NONE; | |
| 1520 bs_type = mi_8x8[0]->mbmi.sb_type = bsize; | |
| 1521 subsize = bsize; | |
| 1522 partition = PARTITION_NONE; | |
| 1523 } | |
| 1524 } | |
| 1525 if (do_partition_search && | 1464 if (do_partition_search && |
| 1526 cpi->sf.partition_search_type == SEARCH_PARTITION && | 1465 cpi->sf.partition_search_type == SEARCH_PARTITION && |
| 1527 cpi->sf.adjust_partitioning_from_last_frame) { | 1466 cpi->sf.adjust_partitioning_from_last_frame) { |
| 1528 // Check if any of the sub blocks are further split. | 1467 // Check if any of the sub blocks are further split. |
| 1529 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { | 1468 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { |
| 1530 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); | 1469 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); |
| 1531 splits_below = 1; | 1470 splits_below = 1; |
| 1532 for (i = 0; i < 4; i++) { | 1471 for (i = 0; i < 4; i++) { |
| 1533 int jj = i >> 1, ii = i & 0x01; | 1472 int jj = i >> 1, ii = i & 0x01; |
| 1534 MODE_INFO * this_mi = mi_8x8[jj * bss * mis + ii * bss]; | 1473 MODE_INFO * this_mi = mi_8x8[jj * bss * mis + ii * bss]; |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1977 int partition_vert_allowed = !force_horz_split && xss <= yss && | 1916 int partition_vert_allowed = !force_horz_split && xss <= yss && |
| 1978 bsize >= BLOCK_8X8; | 1917 bsize >= BLOCK_8X8; |
| 1979 (void) *tp_orig; | 1918 (void) *tp_orig; |
| 1980 | 1919 |
| 1981 assert(num_8x8_blocks_wide_lookup[bsize] == | 1920 assert(num_8x8_blocks_wide_lookup[bsize] == |
| 1982 num_8x8_blocks_high_lookup[bsize]); | 1921 num_8x8_blocks_high_lookup[bsize]); |
| 1983 | 1922 |
| 1984 if (bsize == BLOCK_16X16) { | 1923 if (bsize == BLOCK_16X16) { |
| 1985 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 1924 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 1986 x->mb_energy = vp9_block_energy(cpi, x, bsize); | 1925 x->mb_energy = vp9_block_energy(cpi, x, bsize); |
| 1987 } else { | |
| 1988 x->in_active_map = check_active_map(cpi, x, mi_row, mi_col, bsize); | |
| 1989 } | 1926 } |
| 1990 // Determine partition types in search according to the speed features. | 1927 // Determine partition types in search according to the speed features. |
| 1991 // The threshold set here has to be of square block size. | 1928 // The threshold set here has to be of square block size. |
| 1992 if (cpi->sf.auto_min_max_partition_size) { | 1929 if (cpi->sf.auto_min_max_partition_size) { |
| 1993 partition_none_allowed &= (bsize <= cpi->sf.max_partition_size && | 1930 partition_none_allowed &= (bsize <= cpi->sf.max_partition_size && |
| 1994 bsize >= cpi->sf.min_partition_size); | 1931 bsize >= cpi->sf.min_partition_size); |
| 1995 partition_horz_allowed &= ((bsize <= cpi->sf.max_partition_size && | 1932 partition_horz_allowed &= ((bsize <= cpi->sf.max_partition_size && |
| 1996 bsize > cpi->sf.min_partition_size) || | 1933 bsize > cpi->sf.min_partition_size) || |
| 1997 force_horz_split); | 1934 force_horz_split); |
| 1998 partition_vert_allowed &= ((bsize <= cpi->sf.max_partition_size && | 1935 partition_vert_allowed &= ((bsize <= cpi->sf.max_partition_size && |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2011 unsigned int source_variancey; | 1948 unsigned int source_variancey; |
| 2012 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); | 1949 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); |
| 2013 source_variancey = get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); | 1950 source_variancey = get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); |
| 2014 if (source_variancey < cpi->sf.disable_split_var_thresh) { | 1951 if (source_variancey < cpi->sf.disable_split_var_thresh) { |
| 2015 do_split = 0; | 1952 do_split = 0; |
| 2016 if (source_variancey < cpi->sf.disable_split_var_thresh / 2) | 1953 if (source_variancey < cpi->sf.disable_split_var_thresh / 2) |
| 2017 do_rect = 0; | 1954 do_rect = 0; |
| 2018 } | 1955 } |
| 2019 } | 1956 } |
| 2020 | 1957 |
| 2021 if (!x->in_active_map && (partition_horz_allowed || partition_vert_allowed)) | |
| 2022 do_split = 0; | |
| 2023 // PARTITION_NONE | 1958 // PARTITION_NONE |
| 2024 if (partition_none_allowed) { | 1959 if (partition_none_allowed) { |
| 2025 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &this_rate, &this_dist, bsize, | 1960 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &this_rate, &this_dist, bsize, |
| 2026 ctx, best_rd, 0); | 1961 ctx, best_rd, 0); |
| 2027 if (this_rate != INT_MAX) { | 1962 if (this_rate != INT_MAX) { |
| 2028 if (bsize >= BLOCK_8X8) { | 1963 if (bsize >= BLOCK_8X8) { |
| 2029 pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 1964 pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2030 this_rate += cpi->partition_cost[pl][PARTITION_NONE]; | 1965 this_rate += cpi->partition_cost[pl][PARTITION_NONE]; |
| 2031 } | 1966 } |
| 2032 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); | 1967 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2046 | 1981 |
| 2047 stop_thresh_rd = RDCOST(x->rdmult, x->rddiv, 0, stop_thresh); | 1982 stop_thresh_rd = RDCOST(x->rdmult, x->rddiv, 0, stop_thresh); |
| 2048 // If obtained distortion is very small, choose current partition | 1983 // If obtained distortion is very small, choose current partition |
| 2049 // and stop splitting. | 1984 // and stop splitting. |
| 2050 if (!x->e_mbd.lossless && best_rd < stop_thresh_rd) { | 1985 if (!x->e_mbd.lossless && best_rd < stop_thresh_rd) { |
| 2051 do_split = 0; | 1986 do_split = 0; |
| 2052 do_rect = 0; | 1987 do_rect = 0; |
| 2053 } | 1988 } |
| 2054 } | 1989 } |
| 2055 } | 1990 } |
| 2056 if (!x->in_active_map) { | |
| 2057 do_split = 0; | |
| 2058 do_rect = 0; | |
| 2059 } | |
| 2060 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1991 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 2061 } | 1992 } |
| 2062 | 1993 |
| 2063 // store estimated motion vector | 1994 // store estimated motion vector |
| 2064 if (cpi->sf.adaptive_motion_search) | 1995 if (cpi->sf.adaptive_motion_search) |
| 2065 store_pred_mv(x, ctx); | 1996 store_pred_mv(x, ctx); |
| 2066 | 1997 |
| 2067 // PARTITION_SPLIT | 1998 // PARTITION_SPLIT |
| 2068 sum_rd = 0; | 1999 sum_rd = 0; |
| 2069 // TODO(jingning): use the motion vectors given by the above search as | 2000 // TODO(jingning): use the motion vectors given by the above search as |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2303 const int idx_str = cm->mi_stride * mi_row + mi_col; | 2234 const int idx_str = cm->mi_stride * mi_row + mi_col; |
| 2304 MODE_INFO **mi = cm->mi_grid_visible + idx_str; | 2235 MODE_INFO **mi = cm->mi_grid_visible + idx_str; |
| 2305 MODE_INFO **prev_mi = cm->prev_mi_grid_visible + idx_str; | 2236 MODE_INFO **prev_mi = cm->prev_mi_grid_visible + idx_str; |
| 2306 cpi->mb.source_variance = UINT_MAX; | 2237 cpi->mb.source_variance = UINT_MAX; |
| 2307 if (sf->partition_search_type == FIXED_PARTITION) { | 2238 if (sf->partition_search_type == FIXED_PARTITION) { |
| 2308 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 2239 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
| 2309 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, | 2240 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, |
| 2310 sf->always_this_block_size); | 2241 sf->always_this_block_size); |
| 2311 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 2242 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
| 2312 &dummy_rate, &dummy_dist, 1, cpi->pc_root); | 2243 &dummy_rate, &dummy_dist, 1, cpi->pc_root); |
| 2313 } else if (sf->partition_search_type == VAR_BASED_FIXED_PARTITION) { | 2244 } else if (cpi->skippable_frame || |
| 2245 sf->partition_search_type == VAR_BASED_FIXED_PARTITION) { |
| 2314 BLOCK_SIZE bsize; | 2246 BLOCK_SIZE bsize; |
| 2315 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 2247 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
| 2316 bsize = get_rd_var_based_fixed_partition(cpi, mi_row, mi_col); | 2248 bsize = get_rd_var_based_fixed_partition(cpi, mi_row, mi_col); |
| 2317 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize); | 2249 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize); |
| 2318 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 2250 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
| 2319 &dummy_rate, &dummy_dist, 1, cpi->pc_root); | 2251 &dummy_rate, &dummy_dist, 1, cpi->pc_root); |
| 2320 } else if (sf->partition_search_type == VAR_BASED_PARTITION) { | 2252 } else if (sf->partition_search_type == VAR_BASED_PARTITION) { |
| 2321 choose_partitioning(cpi, tile, mi_row, mi_col); | 2253 choose_partitioning(cpi, tile, mi_row, mi_col); |
| 2322 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 2254 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
| 2323 &dummy_rate, &dummy_dist, 1, cpi->pc_root); | 2255 &dummy_rate, &dummy_dist, 1, cpi->pc_root); |
| 2324 } else { | 2256 } else { |
| 2257 GF_GROUP * gf_grp = &cpi->twopass.gf_group; |
| 2258 int last_was_mid_sequence_overlay = 0; |
| 2259 if ((cpi->pass == 2) && (gf_grp->index)) { |
| 2260 if (gf_grp->update_type[gf_grp->index - 1] == OVERLAY_UPDATE) |
| 2261 last_was_mid_sequence_overlay = 1; |
| 2262 } |
| 2325 if ((cm->current_video_frame | 2263 if ((cm->current_video_frame |
| 2326 % sf->last_partitioning_redo_frequency) == 0 | 2264 % sf->last_partitioning_redo_frequency) == 0 |
| 2265 || last_was_mid_sequence_overlay |
| 2327 || cm->prev_mi == 0 | 2266 || cm->prev_mi == 0 |
| 2328 || cm->show_frame == 0 | 2267 || cm->show_frame == 0 |
| 2329 || cm->frame_type == KEY_FRAME | 2268 || cm->frame_type == KEY_FRAME |
| 2330 || cpi->rc.is_src_frame_alt_ref | 2269 || cpi->rc.is_src_frame_alt_ref |
| 2331 || ((sf->use_lastframe_partitioning == | 2270 || ((sf->use_lastframe_partitioning == |
| 2332 LAST_FRAME_PARTITION_LOW_MOTION) && | 2271 LAST_FRAME_PARTITION_LOW_MOTION) && |
| 2333 sb_has_motion(cm, prev_mi, sf->lf_motion_threshold))) { | 2272 sb_has_motion(cm, prev_mi, sf->lf_motion_threshold))) { |
| 2334 // If required set upper and lower partition size limits | 2273 // If required set upper and lower partition size limits |
| 2335 if (sf->auto_min_max_partition_size) { | 2274 if (sf->auto_min_max_partition_size) { |
| 2336 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 2275 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2429 } else { | 2368 } else { |
| 2430 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) { | 2369 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) { |
| 2431 return ALLOW_32X32; | 2370 return ALLOW_32X32; |
| 2432 } else if (cpi->sf.tx_size_search_method == USE_FULL_RD) { | 2371 } else if (cpi->sf.tx_size_search_method == USE_FULL_RD) { |
| 2433 const RD_OPT *const rd_opt = &cpi->rd; | 2372 const RD_OPT *const rd_opt = &cpi->rd; |
| 2434 const MV_REFERENCE_FRAME frame_type = get_frame_type(cpi); | 2373 const MV_REFERENCE_FRAME frame_type = get_frame_type(cpi); |
| 2435 return rd_opt->tx_select_threshes[frame_type][ALLOW_32X32] > | 2374 return rd_opt->tx_select_threshes[frame_type][ALLOW_32X32] > |
| 2436 rd_opt->tx_select_threshes[frame_type][TX_MODE_SELECT] ? | 2375 rd_opt->tx_select_threshes[frame_type][TX_MODE_SELECT] ? |
| 2437 ALLOW_32X32 : TX_MODE_SELECT; | 2376 ALLOW_32X32 : TX_MODE_SELECT; |
| 2438 } else if (cpi->sf.tx_size_search_method == USE_TX_8X8) { | 2377 } else if (cpi->sf.tx_size_search_method == USE_TX_8X8) { |
| 2439 return ALLOW_8X8; | 2378 return TX_MODE_SELECT; |
| 2440 } else { | 2379 } else { |
| 2441 unsigned int total = 0; | 2380 unsigned int total = 0; |
| 2442 int i; | 2381 int i; |
| 2443 for (i = 0; i < TX_SIZES; ++i) | 2382 for (i = 0; i < TX_SIZES; ++i) |
| 2444 total += cpi->tx_stepdown_count[i]; | 2383 total += cpi->tx_stepdown_count[i]; |
| 2445 | 2384 |
| 2446 if (total) { | 2385 if (total) { |
| 2447 const double fraction = (double)cpi->tx_stepdown_count[0] / total; | 2386 const double fraction = (double)cpi->tx_stepdown_count[0] / total; |
| 2448 return fraction > 0.90 ? ALLOW_32X32 : TX_MODE_SELECT; | 2387 return fraction > 0.90 ? ALLOW_32X32 : TX_MODE_SELECT; |
| 2449 } else { | 2388 } else { |
| 2450 return cpi->common.tx_mode; | 2389 return cpi->common.tx_mode; |
| 2451 } | 2390 } |
| 2452 } | 2391 } |
| 2453 } | 2392 } |
| 2454 } | 2393 } |
| 2455 | 2394 |
| 2456 static void set_mode_info(MB_MODE_INFO *mbmi, BLOCK_SIZE bsize, | |
| 2457 PREDICTION_MODE mode) { | |
| 2458 mbmi->mode = mode; | |
| 2459 mbmi->uv_mode = mode; | |
| 2460 mbmi->mv[0].as_int = 0; | |
| 2461 mbmi->mv[1].as_int = 0; | |
| 2462 mbmi->ref_frame[0] = INTRA_FRAME; | |
| 2463 mbmi->ref_frame[1] = NONE; | |
| 2464 mbmi->tx_size = max_txsize_lookup[bsize]; | |
| 2465 mbmi->skip = 0; | |
| 2466 mbmi->sb_type = bsize; | |
| 2467 mbmi->segment_id = 0; | |
| 2468 } | |
| 2469 | |
| 2470 static void nonrd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, | 2395 static void nonrd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, |
| 2471 int mi_row, int mi_col, | 2396 int mi_row, int mi_col, |
| 2472 int *rate, int64_t *dist, | 2397 int *rate, int64_t *dist, |
| 2473 BLOCK_SIZE bsize) { | 2398 BLOCK_SIZE bsize) { |
| 2474 VP9_COMMON *const cm = &cpi->common; | 2399 VP9_COMMON *const cm = &cpi->common; |
| 2475 MACROBLOCK *const x = &cpi->mb; | 2400 MACROBLOCK *const x = &cpi->mb; |
| 2476 MACROBLOCKD *const xd = &x->e_mbd; | 2401 MACROBLOCKD *const xd = &x->e_mbd; |
| 2477 MB_MODE_INFO *mbmi; | 2402 MB_MODE_INFO *mbmi; |
| 2478 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 2403 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 2479 mbmi = &xd->mi[0]->mbmi; | 2404 mbmi = &xd->mi[0]->mbmi; |
| 2480 mbmi->sb_type = bsize; | 2405 mbmi->sb_type = bsize; |
| 2481 | 2406 |
| 2482 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) { | 2407 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) |
| 2483 if (mbmi->segment_id && x->in_static_area) | 2408 if (mbmi->segment_id && x->in_static_area) |
| 2484 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); | 2409 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); |
| 2485 } | |
| 2486 | 2410 |
| 2487 if (!frame_is_intra_only(cm)) { | 2411 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) |
| 2488 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) | 2412 set_mode_info_seg_skip(x, cm->tx_mode, rate, dist, bsize); |
| 2489 set_mode_info_seg_skip(x, cm->tx_mode, rate, dist, bsize); | 2413 else |
| 2490 else | 2414 vp9_pick_inter_mode(cpi, x, tile, mi_row, mi_col, rate, dist, bsize); |
| 2491 vp9_pick_inter_mode(cpi, x, tile, mi_row, mi_col, rate, dist, bsize); | 2415 |
| 2492 } else { | |
| 2493 set_mode_info(&xd->mi[0]->mbmi, bsize, DC_PRED); | |
| 2494 } | |
| 2495 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); | 2416 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); |
| 2496 } | 2417 } |
| 2497 | 2418 |
| 2498 static void fill_mode_info_sb(VP9_COMMON *cm, MACROBLOCK *x, | 2419 static void fill_mode_info_sb(VP9_COMMON *cm, MACROBLOCK *x, |
| 2499 int mi_row, int mi_col, | 2420 int mi_row, int mi_col, |
| 2500 BLOCK_SIZE bsize, BLOCK_SIZE subsize, | 2421 BLOCK_SIZE bsize, BLOCK_SIZE subsize, |
| 2501 PC_TREE *pc_tree) { | 2422 PC_TREE *pc_tree) { |
| 2502 MACROBLOCKD *xd = &x->e_mbd; | 2423 MACROBLOCKD *xd = &x->e_mbd; |
| 2503 int bsl = b_width_log2(bsize), hbs = (1 << bsl) / 4; | 2424 int bsl = b_width_log2(bsize), hbs = (1 << bsl) / 4; |
| 2504 PARTITION_TYPE partition = pc_tree->partitioning; | 2425 PARTITION_TYPE partition = pc_tree->partitioning; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2579 int partition_none_allowed = !force_horz_split && !force_vert_split; | 2500 int partition_none_allowed = !force_horz_split && !force_vert_split; |
| 2580 int partition_horz_allowed = !force_vert_split && yss <= xss && | 2501 int partition_horz_allowed = !force_vert_split && yss <= xss && |
| 2581 bsize >= BLOCK_8X8; | 2502 bsize >= BLOCK_8X8; |
| 2582 int partition_vert_allowed = !force_horz_split && xss <= yss && | 2503 int partition_vert_allowed = !force_horz_split && xss <= yss && |
| 2583 bsize >= BLOCK_8X8; | 2504 bsize >= BLOCK_8X8; |
| 2584 (void) *tp_orig; | 2505 (void) *tp_orig; |
| 2585 | 2506 |
| 2586 assert(num_8x8_blocks_wide_lookup[bsize] == | 2507 assert(num_8x8_blocks_wide_lookup[bsize] == |
| 2587 num_8x8_blocks_high_lookup[bsize]); | 2508 num_8x8_blocks_high_lookup[bsize]); |
| 2588 | 2509 |
| 2589 x->in_active_map = check_active_map(cpi, x, mi_row, mi_col, bsize); | |
| 2590 | |
| 2591 // Determine partition types in search according to the speed features. | 2510 // Determine partition types in search according to the speed features. |
| 2592 // The threshold set here has to be of square block size. | 2511 // The threshold set here has to be of square block size. |
| 2593 if (cpi->sf.auto_min_max_partition_size) { | 2512 if (cpi->sf.auto_min_max_partition_size) { |
| 2594 partition_none_allowed &= (bsize <= cpi->sf.max_partition_size && | 2513 partition_none_allowed &= (bsize <= cpi->sf.max_partition_size && |
| 2595 bsize >= cpi->sf.min_partition_size); | 2514 bsize >= cpi->sf.min_partition_size); |
| 2596 partition_horz_allowed &= ((bsize <= cpi->sf.max_partition_size && | 2515 partition_horz_allowed &= ((bsize <= cpi->sf.max_partition_size && |
| 2597 bsize > cpi->sf.min_partition_size) || | 2516 bsize > cpi->sf.min_partition_size) || |
| 2598 force_horz_split); | 2517 force_horz_split); |
| 2599 partition_vert_allowed &= ((bsize <= cpi->sf.max_partition_size && | 2518 partition_vert_allowed &= ((bsize <= cpi->sf.max_partition_size && |
| 2600 bsize > cpi->sf.min_partition_size) || | 2519 bsize > cpi->sf.min_partition_size) || |
| 2601 force_vert_split); | 2520 force_vert_split); |
| 2602 do_split &= bsize > cpi->sf.min_partition_size; | 2521 do_split &= bsize > cpi->sf.min_partition_size; |
| 2603 } | 2522 } |
| 2604 if (cpi->sf.use_square_partition_only) { | 2523 if (cpi->sf.use_square_partition_only) { |
| 2605 partition_horz_allowed &= force_horz_split; | 2524 partition_horz_allowed &= force_horz_split; |
| 2606 partition_vert_allowed &= force_vert_split; | 2525 partition_vert_allowed &= force_vert_split; |
| 2607 } | 2526 } |
| 2608 | 2527 |
| 2609 if (!x->in_active_map && (partition_horz_allowed || partition_vert_allowed)) | |
| 2610 do_split = 0; | |
| 2611 | |
| 2612 // PARTITION_NONE | 2528 // PARTITION_NONE |
| 2613 if (partition_none_allowed) { | 2529 if (partition_none_allowed) { |
| 2614 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, | 2530 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, |
| 2615 &this_rate, &this_dist, bsize); | 2531 &this_rate, &this_dist, bsize); |
| 2616 ctx->mic.mbmi = xd->mi[0]->mbmi; | 2532 ctx->mic.mbmi = xd->mi[0]->mbmi; |
| 2617 ctx->skip_txfm = x->skip_txfm; | 2533 ctx->skip_txfm = x->skip_txfm; |
| 2534 ctx->skip = x->skip; |
| 2618 | 2535 |
| 2619 if (this_rate != INT_MAX) { | 2536 if (this_rate != INT_MAX) { |
| 2620 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2537 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2621 this_rate += cpi->partition_cost[pl][PARTITION_NONE]; | 2538 this_rate += cpi->partition_cost[pl][PARTITION_NONE]; |
| 2622 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); | 2539 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); |
| 2623 if (sum_rd < best_rd) { | 2540 if (sum_rd < best_rd) { |
| 2624 int64_t stop_thresh = 4096; | 2541 int64_t stop_thresh = 4096; |
| 2625 int64_t stop_thresh_rd; | 2542 int64_t stop_thresh_rd; |
| 2626 | 2543 |
| 2627 best_rate = this_rate; | 2544 best_rate = this_rate; |
| 2628 best_dist = this_dist; | 2545 best_dist = this_dist; |
| 2629 best_rd = sum_rd; | 2546 best_rd = sum_rd; |
| 2630 if (bsize >= BLOCK_8X8) | 2547 if (bsize >= BLOCK_8X8) |
| 2631 pc_tree->partitioning = PARTITION_NONE; | 2548 pc_tree->partitioning = PARTITION_NONE; |
| 2632 | 2549 |
| 2633 // Adjust threshold according to partition size. | 2550 // Adjust threshold according to partition size. |
| 2634 stop_thresh >>= 8 - (b_width_log2_lookup[bsize] + | 2551 stop_thresh >>= 8 - (b_width_log2_lookup[bsize] + |
| 2635 b_height_log2_lookup[bsize]); | 2552 b_height_log2_lookup[bsize]); |
| 2636 | 2553 |
| 2637 stop_thresh_rd = RDCOST(x->rdmult, x->rddiv, 0, stop_thresh); | 2554 stop_thresh_rd = RDCOST(x->rdmult, x->rddiv, 0, stop_thresh); |
| 2638 // If obtained distortion is very small, choose current partition | 2555 // If obtained distortion is very small, choose current partition |
| 2639 // and stop splitting. | 2556 // and stop splitting. |
| 2640 if (!x->e_mbd.lossless && best_rd < stop_thresh_rd) { | 2557 if (!x->e_mbd.lossless && best_rd < stop_thresh_rd) { |
| 2641 do_split = 0; | 2558 do_split = 0; |
| 2642 do_rect = 0; | 2559 do_rect = 0; |
| 2643 } | 2560 } |
| 2644 } | 2561 } |
| 2645 } | 2562 } |
| 2646 if (!x->in_active_map) { | |
| 2647 do_split = 0; | |
| 2648 do_rect = 0; | |
| 2649 } | |
| 2650 } | 2563 } |
| 2651 | 2564 |
| 2652 // store estimated motion vector | 2565 // store estimated motion vector |
| 2653 store_pred_mv(x, ctx); | 2566 store_pred_mv(x, ctx); |
| 2654 | 2567 |
| 2655 // PARTITION_SPLIT | 2568 // PARTITION_SPLIT |
| 2656 sum_rd = 0; | 2569 sum_rd = 0; |
| 2657 if (do_split) { | 2570 if (do_split) { |
| 2658 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2571 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2659 sum_rate += cpi->partition_cost[pl][PARTITION_SPLIT]; | 2572 sum_rate += cpi->partition_cost[pl][PARTITION_SPLIT]; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2695 if (partition_horz_allowed && do_rect) { | 2608 if (partition_horz_allowed && do_rect) { |
| 2696 subsize = get_subsize(bsize, PARTITION_HORZ); | 2609 subsize = get_subsize(bsize, PARTITION_HORZ); |
| 2697 if (cpi->sf.adaptive_motion_search) | 2610 if (cpi->sf.adaptive_motion_search) |
| 2698 load_pred_mv(x, ctx); | 2611 load_pred_mv(x, ctx); |
| 2699 | 2612 |
| 2700 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, | 2613 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, |
| 2701 &this_rate, &this_dist, subsize); | 2614 &this_rate, &this_dist, subsize); |
| 2702 | 2615 |
| 2703 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi; | 2616 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi; |
| 2704 pc_tree->horizontal[0].skip_txfm = x->skip_txfm; | 2617 pc_tree->horizontal[0].skip_txfm = x->skip_txfm; |
| 2618 pc_tree->horizontal[0].skip = x->skip; |
| 2705 | 2619 |
| 2706 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2620 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 2707 | 2621 |
| 2708 if (sum_rd < best_rd && mi_row + ms < cm->mi_rows) { | 2622 if (sum_rd < best_rd && mi_row + ms < cm->mi_rows) { |
| 2709 load_pred_mv(x, ctx); | 2623 load_pred_mv(x, ctx); |
| 2710 nonrd_pick_sb_modes(cpi, tile, mi_row + ms, mi_col, | 2624 nonrd_pick_sb_modes(cpi, tile, mi_row + ms, mi_col, |
| 2711 &this_rate, &this_dist, subsize); | 2625 &this_rate, &this_dist, subsize); |
| 2712 | 2626 |
| 2713 pc_tree->horizontal[1].mic.mbmi = xd->mi[0]->mbmi; | 2627 pc_tree->horizontal[1].mic.mbmi = xd->mi[0]->mbmi; |
| 2714 pc_tree->horizontal[1].skip_txfm = x->skip_txfm; | 2628 pc_tree->horizontal[1].skip_txfm = x->skip_txfm; |
| 2629 pc_tree->horizontal[1].skip = x->skip; |
| 2715 | 2630 |
| 2716 if (this_rate == INT_MAX) { | 2631 if (this_rate == INT_MAX) { |
| 2717 sum_rd = INT64_MAX; | 2632 sum_rd = INT64_MAX; |
| 2718 } else { | 2633 } else { |
| 2719 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2634 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2720 this_rate += cpi->partition_cost[pl][PARTITION_HORZ]; | 2635 this_rate += cpi->partition_cost[pl][PARTITION_HORZ]; |
| 2721 sum_rate += this_rate; | 2636 sum_rate += this_rate; |
| 2722 sum_dist += this_dist; | 2637 sum_dist += this_dist; |
| 2723 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2638 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 2724 } | 2639 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2735 if (partition_vert_allowed && do_rect) { | 2650 if (partition_vert_allowed && do_rect) { |
| 2736 subsize = get_subsize(bsize, PARTITION_VERT); | 2651 subsize = get_subsize(bsize, PARTITION_VERT); |
| 2737 | 2652 |
| 2738 if (cpi->sf.adaptive_motion_search) | 2653 if (cpi->sf.adaptive_motion_search) |
| 2739 load_pred_mv(x, ctx); | 2654 load_pred_mv(x, ctx); |
| 2740 | 2655 |
| 2741 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, | 2656 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, |
| 2742 &this_rate, &this_dist, subsize); | 2657 &this_rate, &this_dist, subsize); |
| 2743 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi; | 2658 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi; |
| 2744 pc_tree->vertical[0].skip_txfm = x->skip_txfm; | 2659 pc_tree->vertical[0].skip_txfm = x->skip_txfm; |
| 2660 pc_tree->vertical[0].skip = x->skip; |
| 2745 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2661 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 2746 if (sum_rd < best_rd && mi_col + ms < cm->mi_cols) { | 2662 if (sum_rd < best_rd && mi_col + ms < cm->mi_cols) { |
| 2747 load_pred_mv(x, ctx); | 2663 load_pred_mv(x, ctx); |
| 2748 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + ms, | 2664 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + ms, |
| 2749 &this_rate, &this_dist, subsize); | 2665 &this_rate, &this_dist, subsize); |
| 2750 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi; | 2666 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi; |
| 2751 pc_tree->vertical[1].skip_txfm = x->skip_txfm; | 2667 pc_tree->vertical[1].skip_txfm = x->skip_txfm; |
| 2668 pc_tree->vertical[1].skip = x->skip; |
| 2752 if (this_rate == INT_MAX) { | 2669 if (this_rate == INT_MAX) { |
| 2753 sum_rd = INT64_MAX; | 2670 sum_rd = INT64_MAX; |
| 2754 } else { | 2671 } else { |
| 2755 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2672 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2756 this_rate += cpi->partition_cost[pl][PARTITION_VERT]; | 2673 this_rate += cpi->partition_cost[pl][PARTITION_VERT]; |
| 2757 sum_rate += this_rate; | 2674 sum_rate += this_rate; |
| 2758 sum_dist += this_dist; | 2675 sum_dist += this_dist; |
| 2759 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2676 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 2760 } | 2677 } |
| 2761 } | 2678 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2831 return; | 2748 return; |
| 2832 | 2749 |
| 2833 subsize = (bsize >= BLOCK_8X8) ? mi[0]->mbmi.sb_type : BLOCK_4X4; | 2750 subsize = (bsize >= BLOCK_8X8) ? mi[0]->mbmi.sb_type : BLOCK_4X4; |
| 2834 partition = partition_lookup[bsl][subsize]; | 2751 partition = partition_lookup[bsl][subsize]; |
| 2835 | 2752 |
| 2836 switch (partition) { | 2753 switch (partition) { |
| 2837 case PARTITION_NONE: | 2754 case PARTITION_NONE: |
| 2838 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); | 2755 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); |
| 2839 pc_tree->none.mic.mbmi = xd->mi[0]->mbmi; | 2756 pc_tree->none.mic.mbmi = xd->mi[0]->mbmi; |
| 2840 pc_tree->none.skip_txfm = x->skip_txfm; | 2757 pc_tree->none.skip_txfm = x->skip_txfm; |
| 2758 pc_tree->none.skip = x->skip; |
| 2841 break; | 2759 break; |
| 2842 case PARTITION_VERT: | 2760 case PARTITION_VERT: |
| 2843 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); | 2761 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); |
| 2844 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi; | 2762 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi; |
| 2845 pc_tree->vertical[0].skip_txfm = x->skip_txfm; | 2763 pc_tree->vertical[0].skip_txfm = x->skip_txfm; |
| 2764 pc_tree->vertical[0].skip = x->skip; |
| 2846 if (mi_col + hbs < cm->mi_cols) { | 2765 if (mi_col + hbs < cm->mi_cols) { |
| 2847 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + hbs, | 2766 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + hbs, |
| 2848 &rate, &dist, subsize); | 2767 &rate, &dist, subsize); |
| 2849 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi; | 2768 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi; |
| 2850 pc_tree->vertical[1].skip_txfm = x->skip_txfm; | 2769 pc_tree->vertical[1].skip_txfm = x->skip_txfm; |
| 2770 pc_tree->vertical[1].skip = x->skip; |
| 2851 if (rate != INT_MAX && dist != INT64_MAX && | 2771 if (rate != INT_MAX && dist != INT64_MAX && |
| 2852 *totrate != INT_MAX && *totdist != INT64_MAX) { | 2772 *totrate != INT_MAX && *totdist != INT64_MAX) { |
| 2853 *totrate += rate; | 2773 *totrate += rate; |
| 2854 *totdist += dist; | 2774 *totdist += dist; |
| 2855 } | 2775 } |
| 2856 } | 2776 } |
| 2857 break; | 2777 break; |
| 2858 case PARTITION_HORZ: | 2778 case PARTITION_HORZ: |
| 2859 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); | 2779 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); |
| 2860 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi; | 2780 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi; |
| 2861 pc_tree->horizontal[0].skip_txfm = x->skip_txfm; | 2781 pc_tree->horizontal[0].skip_txfm = x->skip_txfm; |
| 2782 pc_tree->horizontal[0].skip = x->skip; |
| 2862 if (mi_row + hbs < cm->mi_rows) { | 2783 if (mi_row + hbs < cm->mi_rows) { |
| 2863 nonrd_pick_sb_modes(cpi, tile, mi_row + hbs, mi_col, | 2784 nonrd_pick_sb_modes(cpi, tile, mi_row + hbs, mi_col, |
| 2864 &rate, &dist, subsize); | 2785 &rate, &dist, subsize); |
| 2865 pc_tree->horizontal[1].mic.mbmi = xd->mi[0]->mbmi; | 2786 pc_tree->horizontal[1].mic.mbmi = xd->mi[0]->mbmi; |
| 2866 pc_tree->horizontal[1].skip_txfm = x->skip_txfm; | 2787 pc_tree->horizontal[1].skip_txfm = x->skip_txfm; |
| 2788 pc_tree->horizontal[1].skip = x->skip; |
| 2867 if (rate != INT_MAX && dist != INT64_MAX && | 2789 if (rate != INT_MAX && dist != INT64_MAX && |
| 2868 *totrate != INT_MAX && *totdist != INT64_MAX) { | 2790 *totrate != INT_MAX && *totdist != INT64_MAX) { |
| 2869 *totrate += rate; | 2791 *totrate += rate; |
| 2870 *totdist += dist; | 2792 *totdist += dist; |
| 2871 } | 2793 } |
| 2872 } | 2794 } |
| 2873 break; | 2795 break; |
| 2874 case PARTITION_SPLIT: | 2796 case PARTITION_SPLIT: |
| 2875 subsize = get_subsize(bsize, PARTITION_SPLIT); | 2797 subsize = get_subsize(bsize, PARTITION_SPLIT); |
| 2876 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, | 2798 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2977 cpi->pc_root); | 2899 cpi->pc_root); |
| 2978 } | 2900 } |
| 2979 break; | 2901 break; |
| 2980 default: | 2902 default: |
| 2981 assert(0); | 2903 assert(0); |
| 2982 } | 2904 } |
| 2983 } | 2905 } |
| 2984 } | 2906 } |
| 2985 // end RTC play code | 2907 // end RTC play code |
| 2986 | 2908 |
| 2909 static int set_var_thresh_from_histogram(VP9_COMP *cpi) { |
| 2910 SPEED_FEATURES *const sf = &cpi->sf; |
| 2911 VP9_COMMON *const cm = &cpi->common; |
| 2912 |
| 2913 const uint8_t *src = cpi->Source->y_buffer; |
| 2914 const uint8_t *last_src = cpi->Last_Source->y_buffer; |
| 2915 const int src_stride = cpi->Source->y_stride; |
| 2916 const int last_stride = cpi->Last_Source->y_stride; |
| 2917 |
| 2918 // Pick cutoff threshold |
| 2919 const int cutoff = (MIN(cm->width, cm->height) >= 720) ? |
| 2920 (cm->MBs * VAR_HIST_LARGE_CUT_OFF / 100) : |
| 2921 (cm->MBs * VAR_HIST_SMALL_CUT_OFF / 100); |
| 2922 DECLARE_ALIGNED_ARRAY(16, int, hist, VAR_HIST_BINS); |
| 2923 diff *var16 = cpi->source_diff_var; |
| 2924 |
| 2925 int sum = 0; |
| 2926 int i, j; |
| 2927 |
| 2928 vpx_memset(hist, 0, VAR_HIST_BINS * sizeof(hist[0])); |
| 2929 |
| 2930 for (i = 0; i < cm->mb_rows; i++) { |
| 2931 for (j = 0; j < cm->mb_cols; j++) { |
| 2932 vp9_get16x16var(src, src_stride, last_src, last_stride, |
| 2933 &var16->sse, &var16->sum); |
| 2934 |
| 2935 var16->var = var16->sse - |
| 2936 (((uint32_t)var16->sum * var16->sum) >> 8); |
| 2937 |
| 2938 if (var16->var >= VAR_HIST_MAX_BG_VAR) |
| 2939 hist[VAR_HIST_BINS - 1]++; |
| 2940 else |
| 2941 hist[var16->var / VAR_HIST_FACTOR]++; |
| 2942 |
| 2943 src += 16; |
| 2944 last_src += 16; |
| 2945 var16++; |
| 2946 } |
| 2947 |
| 2948 src = src - cm->mb_cols * 16 + 16 * src_stride; |
| 2949 last_src = last_src - cm->mb_cols * 16 + 16 * last_stride; |
| 2950 } |
| 2951 |
| 2952 cpi->source_var_thresh = 0; |
| 2953 |
| 2954 if (hist[VAR_HIST_BINS - 1] < cutoff) { |
| 2955 for (i = 0; i < VAR_HIST_BINS - 1; i++) { |
| 2956 sum += hist[i]; |
| 2957 |
| 2958 if (sum > cutoff) { |
| 2959 cpi->source_var_thresh = (i + 1) * VAR_HIST_FACTOR; |
| 2960 return 0; |
| 2961 } |
| 2962 } |
| 2963 } |
| 2964 |
| 2965 return sf->search_type_check_frequency; |
| 2966 } |
| 2967 |
| 2968 static void source_var_based_partition_search_method(VP9_COMP *cpi) { |
| 2969 VP9_COMMON *const cm = &cpi->common; |
| 2970 SPEED_FEATURES *const sf = &cpi->sf; |
| 2971 |
| 2972 if (cm->frame_type == KEY_FRAME) { |
| 2973 // For key frame, use SEARCH_PARTITION. |
| 2974 sf->partition_search_type = SEARCH_PARTITION; |
| 2975 } else if (cm->intra_only) { |
| 2976 sf->partition_search_type = FIXED_PARTITION; |
| 2977 } else { |
| 2978 if (cm->last_width != cm->width || cm->last_height != cm->height) { |
| 2979 if (cpi->source_diff_var) |
| 2980 vpx_free(cpi->source_diff_var); |
| 2981 |
| 2982 CHECK_MEM_ERROR(cm, cpi->source_diff_var, |
| 2983 vpx_calloc(cm->MBs, sizeof(diff))); |
| 2984 } |
| 2985 |
| 2986 if (!cpi->frames_till_next_var_check) |
| 2987 cpi->frames_till_next_var_check = set_var_thresh_from_histogram(cpi); |
| 2988 |
| 2989 if (cpi->frames_till_next_var_check > 0) { |
| 2990 sf->partition_search_type = FIXED_PARTITION; |
| 2991 cpi->frames_till_next_var_check--; |
| 2992 } |
| 2993 } |
| 2994 } |
| 2995 |
| 2987 static int get_skip_encode_frame(const VP9_COMMON *cm) { | 2996 static int get_skip_encode_frame(const VP9_COMMON *cm) { |
| 2988 unsigned int intra_count = 0, inter_count = 0; | 2997 unsigned int intra_count = 0, inter_count = 0; |
| 2989 int j; | 2998 int j; |
| 2990 | 2999 |
| 2991 for (j = 0; j < INTRA_INTER_CONTEXTS; ++j) { | 3000 for (j = 0; j < INTRA_INTER_CONTEXTS; ++j) { |
| 2992 intra_count += cm->counts.intra_inter[j][0]; | 3001 intra_count += cm->counts.intra_inter[j][0]; |
| 2993 inter_count += cm->counts.intra_inter[j][1]; | 3002 inter_count += cm->counts.intra_inter[j][1]; |
| 2994 } | 3003 } |
| 2995 | 3004 |
| 2996 return (intra_count << 2) < inter_count && | 3005 return (intra_count << 2) < inter_count && |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3007 | 3016 |
| 3008 for (tile_row = 0; tile_row < tile_rows; ++tile_row) { | 3017 for (tile_row = 0; tile_row < tile_rows; ++tile_row) { |
| 3009 for (tile_col = 0; tile_col < tile_cols; ++tile_col) { | 3018 for (tile_col = 0; tile_col < tile_cols; ++tile_col) { |
| 3010 TileInfo tile; | 3019 TileInfo tile; |
| 3011 TOKENEXTRA *old_tok = tok; | 3020 TOKENEXTRA *old_tok = tok; |
| 3012 int mi_row; | 3021 int mi_row; |
| 3013 | 3022 |
| 3014 vp9_tile_init(&tile, cm, tile_row, tile_col); | 3023 vp9_tile_init(&tile, cm, tile_row, tile_col); |
| 3015 for (mi_row = tile.mi_row_start; mi_row < tile.mi_row_end; | 3024 for (mi_row = tile.mi_row_start; mi_row < tile.mi_row_end; |
| 3016 mi_row += MI_BLOCK_SIZE) { | 3025 mi_row += MI_BLOCK_SIZE) { |
| 3017 if (cpi->sf.use_nonrd_pick_mode && cm->frame_type != KEY_FRAME) | 3026 if (cpi->sf.use_nonrd_pick_mode && !frame_is_intra_only(cm)) |
| 3018 encode_nonrd_sb_row(cpi, &tile, mi_row, &tok); | 3027 encode_nonrd_sb_row(cpi, &tile, mi_row, &tok); |
| 3019 else | 3028 else |
| 3020 encode_rd_sb_row(cpi, &tile, mi_row, &tok); | 3029 encode_rd_sb_row(cpi, &tile, mi_row, &tok); |
| 3021 } | 3030 } |
| 3022 cpi->tok_count[tile_row][tile_col] = (unsigned int)(tok - old_tok); | 3031 cpi->tok_count[tile_row][tile_col] = (unsigned int)(tok - old_tok); |
| 3023 assert(tok - cpi->tok <= get_token_alloc(cm->mb_rows, cm->mb_cols)); | 3032 assert(tok - cpi->tok <= get_token_alloc(cm->mb_rows, cm->mb_cols)); |
| 3024 } | 3033 } |
| 3025 } | 3034 } |
| 3026 } | 3035 } |
| 3027 | 3036 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3059 cpi->zbin_mode_boost_enabled = 0; | 3068 cpi->zbin_mode_boost_enabled = 0; |
| 3060 } | 3069 } |
| 3061 | 3070 |
| 3062 vp9_frame_init_quantizer(cpi); | 3071 vp9_frame_init_quantizer(cpi); |
| 3063 | 3072 |
| 3064 vp9_initialize_rd_consts(cpi); | 3073 vp9_initialize_rd_consts(cpi); |
| 3065 vp9_initialize_me_consts(cpi, cm->base_qindex); | 3074 vp9_initialize_me_consts(cpi, cm->base_qindex); |
| 3066 init_encode_frame_mb_context(cpi); | 3075 init_encode_frame_mb_context(cpi); |
| 3067 set_prev_mi(cm); | 3076 set_prev_mi(cm); |
| 3068 | 3077 |
| 3078 x->quant_fp = cpi->sf.use_quant_fp; |
| 3069 x->skip_txfm = 0; | 3079 x->skip_txfm = 0; |
| 3070 if (sf->use_nonrd_pick_mode) { | 3080 if (sf->use_nonrd_pick_mode) { |
| 3071 // Initialize internal buffer pointers for rtc coding, where non-RD | 3081 // Initialize internal buffer pointers for rtc coding, where non-RD |
| 3072 // mode decision is used and hence no buffer pointer swap needed. | 3082 // mode decision is used and hence no buffer pointer swap needed. |
| 3073 int i; | 3083 int i; |
| 3074 struct macroblock_plane *const p = x->plane; | 3084 struct macroblock_plane *const p = x->plane; |
| 3075 struct macroblockd_plane *const pd = xd->plane; | 3085 struct macroblockd_plane *const pd = xd->plane; |
| 3076 PICK_MODE_CONTEXT *ctx = &cpi->pc_root->none; | 3086 PICK_MODE_CONTEXT *ctx = &cpi->pc_root->none; |
| 3077 | 3087 |
| 3078 for (i = 0; i < MAX_MB_PLANE; ++i) { | 3088 for (i = 0; i < MAX_MB_PLANE; ++i) { |
| 3079 p[i].coeff = ctx->coeff_pbuf[i][0]; | 3089 p[i].coeff = ctx->coeff_pbuf[i][0]; |
| 3080 p[i].qcoeff = ctx->qcoeff_pbuf[i][0]; | 3090 p[i].qcoeff = ctx->qcoeff_pbuf[i][0]; |
| 3081 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0]; | 3091 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0]; |
| 3082 p[i].eobs = ctx->eobs_pbuf[i][0]; | 3092 p[i].eobs = ctx->eobs_pbuf[i][0]; |
| 3083 } | 3093 } |
| 3084 vp9_zero(x->zcoeff_blk); | 3094 vp9_zero(x->zcoeff_blk); |
| 3085 | 3095 |
| 3086 if (sf->partition_search_type == SOURCE_VAR_BASED_PARTITION && | 3096 if (sf->partition_search_type == SOURCE_VAR_BASED_PARTITION) |
| 3087 cm->current_video_frame > 0) { | 3097 source_var_based_partition_search_method(cpi); |
| 3088 int check_freq = sf->search_type_check_frequency; | |
| 3089 | |
| 3090 if ((cm->current_video_frame - 1) % check_freq == 0) { | |
| 3091 cpi->use_large_partition_rate = 0; | |
| 3092 } | |
| 3093 | |
| 3094 if ((cm->current_video_frame - 1) % check_freq == 1) { | |
| 3095 const int mbs_in_b32x32 = 1 << ((b_width_log2_lookup[BLOCK_32X32] - | |
| 3096 b_width_log2_lookup[BLOCK_16X16]) + | |
| 3097 (b_height_log2_lookup[BLOCK_32X32] - | |
| 3098 b_height_log2_lookup[BLOCK_16X16])); | |
| 3099 cpi->use_large_partition_rate = cpi->use_large_partition_rate * 100 * | |
| 3100 mbs_in_b32x32 / cm->MBs; | |
| 3101 } | |
| 3102 | |
| 3103 if ((cm->current_video_frame - 1) % check_freq >= 1) { | |
| 3104 if (cpi->use_large_partition_rate < 15) | |
| 3105 sf->partition_search_type = FIXED_PARTITION; | |
| 3106 } | |
| 3107 } | |
| 3108 } | 3098 } |
| 3109 | 3099 |
| 3110 { | 3100 { |
| 3111 struct vpx_usec_timer emr_timer; | 3101 struct vpx_usec_timer emr_timer; |
| 3112 vpx_usec_timer_start(&emr_timer); | 3102 vpx_usec_timer_start(&emr_timer); |
| 3113 | 3103 |
| 3114 encode_tiles(cpi); | 3104 encode_tiles(cpi); |
| 3115 | 3105 |
| 3116 vpx_usec_timer_mark(&emr_timer); | 3106 vpx_usec_timer_mark(&emr_timer); |
| 3117 cpi->time_encode_sb_row += vpx_usec_timer_elapsed(&emr_timer); | 3107 cpi->time_encode_sb_row += vpx_usec_timer_elapsed(&emr_timer); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3262 reset_skip_tx_size(cm, TX_4X4); | 3252 reset_skip_tx_size(cm, TX_4X4); |
| 3263 } else if (count8x8_lp == 0 && count16x16_lp == 0 && count4x4 == 0) { | 3253 } else if (count8x8_lp == 0 && count16x16_lp == 0 && count4x4 == 0) { |
| 3264 cm->tx_mode = ALLOW_32X32; | 3254 cm->tx_mode = ALLOW_32X32; |
| 3265 } else if (count32x32 == 0 && count8x8_lp == 0 && count4x4 == 0) { | 3255 } else if (count32x32 == 0 && count8x8_lp == 0 && count4x4 == 0) { |
| 3266 cm->tx_mode = ALLOW_16X16; | 3256 cm->tx_mode = ALLOW_16X16; |
| 3267 reset_skip_tx_size(cm, TX_16X16); | 3257 reset_skip_tx_size(cm, TX_16X16); |
| 3268 } | 3258 } |
| 3269 } | 3259 } |
| 3270 } else { | 3260 } else { |
| 3271 cm->reference_mode = SINGLE_REFERENCE; | 3261 cm->reference_mode = SINGLE_REFERENCE; |
| 3272 cm->interp_filter = SWITCHABLE; | |
| 3273 encode_frame_internal(cpi); | 3262 encode_frame_internal(cpi); |
| 3274 } | 3263 } |
| 3275 } | 3264 } |
| 3276 | 3265 |
| 3277 static void sum_intra_stats(FRAME_COUNTS *counts, const MODE_INFO *mi) { | 3266 static void sum_intra_stats(FRAME_COUNTS *counts, const MODE_INFO *mi) { |
| 3278 const PREDICTION_MODE y_mode = mi->mbmi.mode; | 3267 const PREDICTION_MODE y_mode = mi->mbmi.mode; |
| 3279 const PREDICTION_MODE uv_mode = mi->mbmi.uv_mode; | 3268 const PREDICTION_MODE uv_mode = mi->mbmi.uv_mode; |
| 3280 const BLOCK_SIZE bsize = mi->mbmi.sb_type; | 3269 const BLOCK_SIZE bsize = mi->mbmi.sb_type; |
| 3281 | 3270 |
| 3282 if (bsize < BLOCK_8X8) { | 3271 if (bsize < BLOCK_8X8) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3357 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); | 3346 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); |
| 3358 } else { | 3347 } else { |
| 3359 int ref; | 3348 int ref; |
| 3360 const int is_compound = has_second_ref(mbmi); | 3349 const int is_compound = has_second_ref(mbmi); |
| 3361 for (ref = 0; ref < 1 + is_compound; ++ref) { | 3350 for (ref = 0; ref < 1 + is_compound; ++ref) { |
| 3362 YV12_BUFFER_CONFIG *cfg = get_ref_frame_buffer(cpi, | 3351 YV12_BUFFER_CONFIG *cfg = get_ref_frame_buffer(cpi, |
| 3363 mbmi->ref_frame[ref]); | 3352 mbmi->ref_frame[ref]); |
| 3364 vp9_setup_pre_planes(xd, ref, cfg, mi_row, mi_col, | 3353 vp9_setup_pre_planes(xd, ref, cfg, mi_row, mi_col, |
| 3365 &xd->block_refs[ref]->sf); | 3354 &xd->block_refs[ref]->sf); |
| 3366 } | 3355 } |
| 3367 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); | 3356 if (!cpi->sf.reuse_inter_pred_sby) |
| 3357 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); |
| 3358 |
| 3359 vp9_build_inter_predictors_sbuv(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); |
| 3368 | 3360 |
| 3369 if (!x->skip) { | 3361 if (!x->skip) { |
| 3370 mbmi->skip = 1; | 3362 mbmi->skip = 1; |
| 3371 vp9_encode_sb(x, MAX(bsize, BLOCK_8X8)); | 3363 vp9_encode_sb(x, MAX(bsize, BLOCK_8X8)); |
| 3372 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); | 3364 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); |
| 3373 } else { | 3365 } else { |
| 3374 mbmi->skip = 1; | 3366 mbmi->skip = 1; |
| 3375 if (output_enabled && | 3367 if (output_enabled && |
| 3376 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) | 3368 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) |
| 3377 cm->counts.skip[vp9_get_skip_context(xd)][1]++; | 3369 cm->counts.skip[vp9_get_skip_context(xd)][1]++; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3398 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; | 3390 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; |
| 3399 } | 3391 } |
| 3400 | 3392 |
| 3401 for (y = 0; y < mi_height; y++) | 3393 for (y = 0; y < mi_height; y++) |
| 3402 for (x = 0; x < mi_width; x++) | 3394 for (x = 0; x < mi_width; x++) |
| 3403 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) | 3395 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) |
| 3404 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; | 3396 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; |
| 3405 } | 3397 } |
| 3406 } | 3398 } |
| 3407 } | 3399 } |
| OLD | NEW |