Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <limits.h> |
| 13 | #include <math.h> |
| 14 | #include <stdio.h> |
| 15 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | #include "./av1_rtcd.h" |
| 17 | #include "./aom_dsp_rtcd.h" |
| 18 | #include "./aom_config.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 19 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 20 | #include "aom_dsp/aom_dsp_common.h" |
Sarah Parker | f178329 | 2017-04-05 11:55:27 -0700 | [diff] [blame] | 21 | #include "aom_dsp/binary_codes_writer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 22 | #include "aom_ports/mem.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 23 | #include "aom_ports/aom_timer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | #include "aom_ports/system_state.h" |
| 25 | |
| 26 | #include "av1/common/common.h" |
| 27 | #include "av1/common/entropy.h" |
| 28 | #include "av1/common/entropymode.h" |
| 29 | #include "av1/common/idct.h" |
emilkeyder@google.com | f347763 | 2017-03-01 16:29:14 -0500 | [diff] [blame] | 30 | #include "av1/common/mv.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 31 | #include "av1/common/mvref_common.h" |
| 32 | #include "av1/common/pred_common.h" |
| 33 | #include "av1/common/quant_common.h" |
| 34 | #include "av1/common/reconintra.h" |
| 35 | #include "av1/common/reconinter.h" |
| 36 | #include "av1/common/seg_common.h" |
| 37 | #include "av1/common/tile_common.h" |
| 38 | |
| 39 | #include "av1/encoder/aq_complexity.h" |
| 40 | #include "av1/encoder/aq_cyclicrefresh.h" |
| 41 | #include "av1/encoder/aq_variance.h" |
Sarah Parker | e529986 | 2016-08-16 14:57:37 -0700 | [diff] [blame] | 42 | #include "av1/common/warped_motion.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | #include "av1/encoder/global_motion.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 44 | #include "av1/encoder/encodeframe.h" |
| 45 | #include "av1/encoder/encodemb.h" |
| 46 | #include "av1/encoder/encodemv.h" |
Angie Chiang | 0397eda | 2017-03-15 16:57:14 -0700 | [diff] [blame] | 47 | #if CONFIG_LV_MAP |
| 48 | #include "av1/encoder/encodetxb.h" |
| 49 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 50 | #include "av1/encoder/ethread.h" |
| 51 | #include "av1/encoder/extend.h" |
| 52 | #include "av1/encoder/rd.h" |
| 53 | #include "av1/encoder/rdopt.h" |
| 54 | #include "av1/encoder/segmentation.h" |
| 55 | #include "av1/encoder/tokenize.h" |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 56 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 57 | #define IF_HBD(...) __VA_ARGS__ |
| 58 | #else |
| 59 | #define IF_HBD(...) |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 60 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 61 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 62 | static void encode_superblock(const AV1_COMP *const cpi, ThreadData *td, |
| 63 | TOKENEXTRA **t, RUN_TYPE dry_run, int mi_row, |
Yushin Cho | 6d72a2f | 2017-05-03 17:37:37 -0700 | [diff] [blame] | 64 | int mi_col, BLOCK_SIZE bsize, int *rate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 65 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | // This is used as a reference when computing the source variance for the |
| 67 | // purposes of activity masking. |
| 68 | // Eventually this should be replaced by custom no-reference routines, |
| 69 | // which will be faster. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 70 | static const uint8_t AV1_VAR_OFFS[MAX_SB_SIZE] = { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 71 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 72 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 73 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 74 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 75 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 76 | #if CONFIG_EXT_PARTITION |
| 77 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 78 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 79 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 80 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 81 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 |
| 82 | #endif // CONFIG_EXT_PARTITION |
| 83 | }; |
| 84 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 85 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 86 | static const uint16_t AV1_HIGH_VAR_OFFS_8[MAX_SB_SIZE] = { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 87 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 88 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 89 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 90 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 91 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 92 | #if CONFIG_EXT_PARTITION |
| 93 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 94 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 95 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 96 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 97 | 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 |
| 98 | #endif // CONFIG_EXT_PARTITION |
| 99 | }; |
| 100 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 101 | static const uint16_t AV1_HIGH_VAR_OFFS_10[MAX_SB_SIZE] = { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 102 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 103 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 104 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 105 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 106 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 107 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 108 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 109 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 110 | #if CONFIG_EXT_PARTITION |
| 111 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 112 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 113 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 114 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 115 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 116 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 117 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, |
| 118 | 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4, 128 * 4 |
| 119 | #endif // CONFIG_EXT_PARTITION |
| 120 | }; |
| 121 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 122 | static const uint16_t AV1_HIGH_VAR_OFFS_12[MAX_SB_SIZE] = { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 123 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 124 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 125 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 126 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 127 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 128 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 129 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 130 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 131 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 132 | 128 * 16, |
| 133 | #if CONFIG_EXT_PARTITION |
| 134 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 135 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 136 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 137 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 138 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 139 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 140 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 141 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 142 | 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, 128 * 16, |
| 143 | 128 * 16 |
| 144 | #endif // CONFIG_EXT_PARTITION |
| 145 | }; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 146 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 147 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 148 | unsigned int av1_get_sby_perpixel_variance(const AV1_COMP *cpi, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 149 | const struct buf_2d *ref, |
| 150 | BLOCK_SIZE bs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 151 | unsigned int sse; |
| 152 | const unsigned int var = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 153 | cpi->fn_ptr[bs].vf(ref->buf, ref->stride, AV1_VAR_OFFS, 0, &sse); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 154 | return ROUND_POWER_OF_TWO(var, num_pels_log2_lookup[bs]); |
| 155 | } |
| 156 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 157 | #if CONFIG_HIGHBITDEPTH |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 158 | unsigned int av1_high_get_sby_perpixel_variance(const AV1_COMP *cpi, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 159 | const struct buf_2d *ref, |
| 160 | BLOCK_SIZE bs, int bd) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 161 | unsigned int var, sse; |
| 162 | switch (bd) { |
| 163 | case 10: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 164 | var = |
| 165 | cpi->fn_ptr[bs].vf(ref->buf, ref->stride, |
| 166 | CONVERT_TO_BYTEPTR(AV1_HIGH_VAR_OFFS_10), 0, &sse); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 167 | break; |
| 168 | case 12: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 169 | var = |
| 170 | cpi->fn_ptr[bs].vf(ref->buf, ref->stride, |
| 171 | CONVERT_TO_BYTEPTR(AV1_HIGH_VAR_OFFS_12), 0, &sse); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 172 | break; |
| 173 | case 8: |
| 174 | default: |
| 175 | var = |
| 176 | cpi->fn_ptr[bs].vf(ref->buf, ref->stride, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 177 | CONVERT_TO_BYTEPTR(AV1_HIGH_VAR_OFFS_8), 0, &sse); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 178 | break; |
| 179 | } |
| 180 | return ROUND_POWER_OF_TWO(var, num_pels_log2_lookup[bs]); |
| 181 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 182 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 183 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 184 | static unsigned int get_sby_perpixel_diff_variance(const AV1_COMP *const cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 185 | const struct buf_2d *ref, |
| 186 | int mi_row, int mi_col, |
| 187 | BLOCK_SIZE bs) { |
| 188 | unsigned int sse, var; |
| 189 | uint8_t *last_y; |
| 190 | const YV12_BUFFER_CONFIG *last = get_ref_frame_buffer(cpi, LAST_FRAME); |
| 191 | |
| 192 | assert(last != NULL); |
| 193 | last_y = |
| 194 | &last->y_buffer[mi_row * MI_SIZE * last->y_stride + mi_col * MI_SIZE]; |
| 195 | var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride, last_y, last->y_stride, &sse); |
| 196 | return ROUND_POWER_OF_TWO(var, num_pels_log2_lookup[bs]); |
| 197 | } |
| 198 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 199 | static BLOCK_SIZE get_rd_var_based_fixed_partition(AV1_COMP *cpi, MACROBLOCK *x, |
| 200 | int mi_row, int mi_col) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 201 | unsigned int var = get_sby_perpixel_diff_variance( |
| 202 | cpi, &x->plane[0].src, mi_row, mi_col, BLOCK_64X64); |
| 203 | if (var < 8) |
| 204 | return BLOCK_64X64; |
| 205 | else if (var < 128) |
| 206 | return BLOCK_32X32; |
| 207 | else if (var < 2048) |
| 208 | return BLOCK_16X16; |
| 209 | else |
| 210 | return BLOCK_8X8; |
| 211 | } |
| 212 | |
| 213 | // Lighter version of set_offsets that only sets the mode info |
| 214 | // pointers. |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 215 | static void set_mode_info_offsets(const AV1_COMP *const cpi, |
| 216 | MACROBLOCK *const x, MACROBLOCKD *const xd, |
| 217 | int mi_row, int mi_col) { |
| 218 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 219 | const int idx_str = xd->mi_stride * mi_row + mi_col; |
| 220 | xd->mi = cm->mi_grid_visible + idx_str; |
| 221 | xd->mi[0] = cm->mi + idx_str; |
| 222 | x->mbmi_ext = cpi->mbmi_ext_base + (mi_row * cm->mi_cols + mi_col); |
| 223 | } |
| 224 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 225 | static void set_offsets_without_segment_id(const AV1_COMP *const cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 226 | const TileInfo *const tile, |
| 227 | MACROBLOCK *const x, int mi_row, |
| 228 | int mi_col, BLOCK_SIZE bsize) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 229 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 230 | MACROBLOCKD *const xd = &x->e_mbd; |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 231 | const int mi_width = mi_size_wide[bsize]; |
| 232 | const int mi_height = mi_size_high[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 233 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 234 | set_mode_info_offsets(cpi, x, xd, mi_row, mi_col); |
Jingning Han | f5a4d3b | 2017-08-27 23:01:19 -0700 | [diff] [blame] | 235 | |
Jingning Han | 9a80e7c | 2017-05-23 23:39:31 -0700 | [diff] [blame] | 236 | set_skip_context(xd, mi_row, mi_col); |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 237 | xd->above_txfm_context = |
| 238 | cm->above_txfm_context + (mi_col << TX_UNIT_WIDE_LOG2); |
| 239 | xd->left_txfm_context = xd->left_txfm_context_buffer + |
| 240 | ((mi_row & MAX_MIB_MASK) << TX_UNIT_HIGH_LOG2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 241 | |
| 242 | // Set up destination pointers. |
Jingning Han | 91d9a79 | 2017-04-18 12:01:52 -0700 | [diff] [blame] | 243 | av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row, |
| 244 | mi_col); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 245 | |
| 246 | // Set up limit values for MV components. |
| 247 | // Mv beyond the range do not produce new/different prediction block. |
Alex Converse | 0fa0f42 | 2017-04-24 12:51:14 -0700 | [diff] [blame] | 248 | x->mv_limits.row_min = |
| 249 | -(((mi_row + mi_height) * MI_SIZE) + AOM_INTERP_EXTEND); |
| 250 | x->mv_limits.col_min = -(((mi_col + mi_width) * MI_SIZE) + AOM_INTERP_EXTEND); |
| 251 | x->mv_limits.row_max = (cm->mi_rows - mi_row) * MI_SIZE + AOM_INTERP_EXTEND; |
| 252 | x->mv_limits.col_max = (cm->mi_cols - mi_col) * MI_SIZE + AOM_INTERP_EXTEND; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 253 | |
Jingning Han | faad0e1 | 2016-12-07 10:54:57 -0800 | [diff] [blame] | 254 | set_plane_n4(xd, mi_width, mi_height); |
Jingning Han | a6923f7 | 2016-07-15 08:50:14 -0700 | [diff] [blame] | 255 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 256 | // Set up distance of MB to edge of frame in 1/8th pel units. |
| 257 | assert(!(mi_col & (mi_width - 1)) && !(mi_row & (mi_height - 1))); |
Urvang Joshi | 359dc2b | 2017-04-27 15:41:47 -0700 | [diff] [blame] | 258 | set_mi_row_col(xd, tile, mi_row, mi_height, mi_col, mi_width, |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 259 | #if CONFIG_DEPENDENT_HORZTILES |
Urvang Joshi | 359dc2b | 2017-04-27 15:41:47 -0700 | [diff] [blame] | 260 | cm->dependent_horz_tiles, |
| 261 | #endif // CONFIG_DEPENDENT_HORZTILES |
| 262 | cm->mi_rows, cm->mi_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 263 | |
| 264 | // Set up source buffers. |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 265 | av1_setup_src_planes(x, cpi->source, mi_row, mi_col); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 266 | |
| 267 | // R/D setup. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 268 | x->rdmult = cpi->rd.RDMULT; |
| 269 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 270 | // required by av1_append_sub8x8_mvs_for_idx() and av1_find_best_ref_mvs() |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 271 | xd->tile = *tile; |
| 272 | } |
| 273 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 274 | static void set_offsets(const AV1_COMP *const cpi, const TileInfo *const tile, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 275 | MACROBLOCK *const x, int mi_row, int mi_col, |
| 276 | BLOCK_SIZE bsize) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 277 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 278 | MACROBLOCKD *const xd = &x->e_mbd; |
| 279 | MB_MODE_INFO *mbmi; |
| 280 | const struct segmentation *const seg = &cm->seg; |
| 281 | |
| 282 | set_offsets_without_segment_id(cpi, tile, x, mi_row, mi_col, bsize); |
| 283 | |
| 284 | mbmi = &xd->mi[0]->mbmi; |
Luc Trudeau | 780d249 | 2017-06-15 22:26:41 -0400 | [diff] [blame] | 285 | #if CONFIG_CFL |
| 286 | xd->cfl->mi_row = mi_row; |
| 287 | xd->cfl->mi_col = mi_col; |
| 288 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 289 | |
| 290 | // Setup segment ID. |
| 291 | if (seg->enabled) { |
| 292 | if (!cpi->vaq_refresh) { |
| 293 | const uint8_t *const map = |
| 294 | seg->update_map ? cpi->segmentation_map : cm->last_frame_seg_map; |
| 295 | mbmi->segment_id = get_segment_id(cm, map, bsize, mi_row, mi_col); |
| 296 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 297 | av1_init_plane_quantizers(cpi, x, mbmi->segment_id); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 298 | } else { |
| 299 | mbmi->segment_id = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 300 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 303 | #if CONFIG_DUAL_FILTER |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 304 | static void reset_intmv_filter_type(const AV1_COMMON *const cm, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 305 | MB_MODE_INFO *mbmi) { |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 306 | InterpFilter filters[2]; |
| 307 | InterpFilter default_filter = av1_unswitchable_filter(cm->interp_filter); |
| 308 | |
| 309 | for (int dir = 0; dir < 2; ++dir) { |
| 310 | filters[dir] = ((!has_subpel_mv_component(xd->mi[0], xd, dir) && |
| 311 | (mbmi->ref_frame[1] == NONE_FRAME || |
| 312 | !has_subpel_mv_component(xd->mi[0], xd, dir + 2))) |
| 313 | ? default_filter |
| 314 | : av1_extract_interp_filter(mbmi->interp_filters, dir)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 315 | } |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 316 | mbmi->interp_filters = av1_make_interp_filters(filters[0], filters[1]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static void update_filter_type_count(FRAME_COUNTS *counts, |
| 320 | const MACROBLOCKD *xd, |
| 321 | const MB_MODE_INFO *mbmi) { |
| 322 | int dir; |
| 323 | for (dir = 0; dir < 2; ++dir) { |
| 324 | if (has_subpel_mv_component(xd->mi[0], xd, dir) || |
| 325 | (mbmi->ref_frame[1] > INTRA_FRAME && |
| 326 | has_subpel_mv_component(xd->mi[0], xd, dir + 2))) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 327 | const int ctx = av1_get_pred_context_switchable_interp(xd, dir); |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 328 | InterpFilter filter = |
| 329 | av1_extract_interp_filter(mbmi->interp_filters, dir); |
| 330 | ++counts->switchable_interp[ctx][filter]; |
| 331 | update_cdf(xd->tile_ctx->switchable_interp_cdf[ctx], filter, |
| 332 | SWITCHABLE_FILTERS); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | } |
| 336 | #endif |
Debargha Mukherjee | 705544c | 2016-11-22 08:55:49 -0800 | [diff] [blame] | 337 | static void update_global_motion_used(PREDICTION_MODE mode, BLOCK_SIZE bsize, |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 338 | const MB_MODE_INFO *mbmi, |
| 339 | RD_COUNTS *rdc) { |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 340 | if (mode == ZEROMV || mode == ZERO_ZEROMV) { |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 341 | const int num_4x4s = |
| 342 | num_4x4_blocks_wide_lookup[bsize] * num_4x4_blocks_high_lookup[bsize]; |
Sarah Parker | c2d3871 | 2017-01-24 15:15:41 -0800 | [diff] [blame] | 343 | int ref; |
| 344 | for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) { |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 345 | rdc->global_motion_used[mbmi->ref_frame[ref]] += num_4x4s; |
Debargha Mukherjee | 705544c | 2016-11-22 08:55:49 -0800 | [diff] [blame] | 346 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 347 | } |
| 348 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 349 | |
Jingning Han | 4470af1 | 2017-03-06 15:34:41 -0800 | [diff] [blame] | 350 | static void reset_tx_size(MACROBLOCKD *xd, MB_MODE_INFO *mbmi, |
| 351 | const TX_MODE tx_mode) { |
| 352 | if (xd->lossless[mbmi->segment_id]) { |
| 353 | mbmi->tx_size = TX_4X4; |
| 354 | } else if (tx_mode != TX_MODE_SELECT) { |
| 355 | mbmi->tx_size = |
| 356 | tx_size_from_tx_mode(mbmi->sb_type, tx_mode, is_inter_block(mbmi)); |
| 357 | } |
| 358 | } |
| 359 | |
Zoe Liu | 3be7aa6 | 2017-04-26 09:27:57 -0700 | [diff] [blame] | 360 | static void set_ref_and_pred_mvs(MACROBLOCK *const x, int_mv *const mi_pred_mv, |
| 361 | int8_t rf_type) { |
| 362 | MACROBLOCKD *const xd = &x->e_mbd; |
| 363 | MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
| 364 | |
| 365 | const int bw = xd->n8_w << MI_SIZE_LOG2; |
| 366 | const int bh = xd->n8_h << MI_SIZE_LOG2; |
| 367 | int ref_mv_idx = mbmi->ref_mv_idx; |
| 368 | MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext; |
| 369 | CANDIDATE_MV *const curr_ref_mv_stack = mbmi_ext->ref_mv_stack[rf_type]; |
| 370 | |
Zoe Liu | 3be7aa6 | 2017-04-26 09:27:57 -0700 | [diff] [blame] | 371 | if (has_second_ref(mbmi)) { |
| 372 | // Special case: NEAR_NEWMV and NEW_NEARMV modes use 1 + mbmi->ref_mv_idx |
| 373 | // (like NEARMV) instead |
| 374 | if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV) ref_mv_idx += 1; |
| 375 | |
| 376 | if (compound_ref0_mode(mbmi->mode) == NEWMV) { |
| 377 | int_mv this_mv = curr_ref_mv_stack[ref_mv_idx].this_mv; |
| 378 | clamp_mv_ref(&this_mv.as_mv, bw, bh, xd); |
| 379 | mbmi_ext->ref_mvs[mbmi->ref_frame[0]][0] = this_mv; |
| 380 | mbmi->pred_mv[0] = this_mv; |
| 381 | mi_pred_mv[0] = this_mv; |
| 382 | } |
| 383 | if (compound_ref1_mode(mbmi->mode) == NEWMV) { |
| 384 | int_mv this_mv = curr_ref_mv_stack[ref_mv_idx].comp_mv; |
| 385 | clamp_mv_ref(&this_mv.as_mv, bw, bh, xd); |
| 386 | mbmi_ext->ref_mvs[mbmi->ref_frame[1]][0] = this_mv; |
| 387 | mbmi->pred_mv[1] = this_mv; |
| 388 | mi_pred_mv[1] = this_mv; |
| 389 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 390 | #if CONFIG_COMPOUND_SINGLEREF |
| 391 | } else if (is_inter_singleref_comp_mode(mbmi->mode)) { |
| 392 | // Special case: SR_NEAR_NEWMV uses 1 + mbmi->ref_mv_idx |
| 393 | // (like NEARMV) instead |
| 394 | if (mbmi->mode == SR_NEAR_NEWMV) ref_mv_idx += 1; |
| 395 | |
| 396 | if (compound_ref0_mode(mbmi->mode) == NEWMV || |
| 397 | compound_ref1_mode(mbmi->mode) == NEWMV) { |
| 398 | int_mv this_mv = curr_ref_mv_stack[ref_mv_idx].this_mv; |
| 399 | clamp_mv_ref(&this_mv.as_mv, bw, bh, xd); |
| 400 | mbmi_ext->ref_mvs[mbmi->ref_frame[0]][0] = this_mv; |
| 401 | mbmi->pred_mv[0] = this_mv; |
| 402 | mi_pred_mv[0] = this_mv; |
| 403 | } |
| 404 | #endif // CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 3be7aa6 | 2017-04-26 09:27:57 -0700 | [diff] [blame] | 405 | } else { |
Zoe Liu | 3be7aa6 | 2017-04-26 09:27:57 -0700 | [diff] [blame] | 406 | if (mbmi->mode == NEWMV) { |
| 407 | int i; |
| 408 | for (i = 0; i < 1 + has_second_ref(mbmi); ++i) { |
| 409 | int_mv this_mv = (i == 0) ? curr_ref_mv_stack[ref_mv_idx].this_mv |
| 410 | : curr_ref_mv_stack[ref_mv_idx].comp_mv; |
| 411 | clamp_mv_ref(&this_mv.as_mv, bw, bh, xd); |
| 412 | mbmi_ext->ref_mvs[mbmi->ref_frame[i]][0] = this_mv; |
| 413 | mbmi->pred_mv[i] = this_mv; |
| 414 | mi_pred_mv[i] = this_mv; |
| 415 | } |
| 416 | } |
Zoe Liu | 3be7aa6 | 2017-04-26 09:27:57 -0700 | [diff] [blame] | 417 | } |
Zoe Liu | 3be7aa6 | 2017-04-26 09:27:57 -0700 | [diff] [blame] | 418 | } |
Zoe Liu | 3be7aa6 | 2017-04-26 09:27:57 -0700 | [diff] [blame] | 419 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 420 | static void update_state(const AV1_COMP *const cpi, ThreadData *td, |
| 421 | PICK_MODE_CONTEXT *ctx, int mi_row, int mi_col, |
| 422 | BLOCK_SIZE bsize, RUN_TYPE dry_run) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 423 | int i, x_idx, y; |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 424 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 425 | RD_COUNTS *const rdc = &td->rd_counts; |
| 426 | MACROBLOCK *const x = &td->mb; |
| 427 | MACROBLOCKD *const xd = &x->e_mbd; |
| 428 | struct macroblock_plane *const p = x->plane; |
| 429 | struct macroblockd_plane *const pd = xd->plane; |
| 430 | MODE_INFO *mi = &ctx->mic; |
| 431 | MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
| 432 | MODE_INFO *mi_addr = xd->mi[0]; |
| 433 | const struct segmentation *const seg = &cm->seg; |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 434 | const int bw = mi_size_wide[mi->mbmi.sb_type]; |
| 435 | const int bh = mi_size_high[mi->mbmi.sb_type]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 436 | const int mis = cm->mi_stride; |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 437 | const int mi_width = mi_size_wide[bsize]; |
| 438 | const int mi_height = mi_size_high[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 439 | int8_t rf_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 440 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 441 | assert(mi->mbmi.sb_type == bsize); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 442 | |
| 443 | *mi_addr = *mi; |
| 444 | *x->mbmi_ext = ctx->mbmi_ext; |
| 445 | |
| 446 | #if CONFIG_DUAL_FILTER |
| 447 | reset_intmv_filter_type(cm, xd, mbmi); |
| 448 | #endif |
| 449 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 450 | rf_type = av1_ref_frame_type(mbmi->ref_frame); |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 451 | if (x->mbmi_ext->ref_mv_count[rf_type] > 1) { |
Zoe Liu | 3be7aa6 | 2017-04-26 09:27:57 -0700 | [diff] [blame] | 452 | set_ref_and_pred_mvs(x, mi->mbmi.pred_mv, rf_type); |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 453 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 454 | |
| 455 | // If segmentation in use |
| 456 | if (seg->enabled) { |
| 457 | // For in frame complexity AQ copy the segment id from the segment map. |
| 458 | if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
| 459 | const uint8_t *const map = |
| 460 | seg->update_map ? cpi->segmentation_map : cm->last_frame_seg_map; |
| 461 | mi_addr->mbmi.segment_id = get_segment_id(cm, map, bsize, mi_row, mi_col); |
Jingning Han | 4470af1 | 2017-03-06 15:34:41 -0800 | [diff] [blame] | 462 | reset_tx_size(xd, &mi_addr->mbmi, cm->tx_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 463 | } |
| 464 | // Else for cyclic refresh mode update the segment map, set the segment id |
| 465 | // and then update the quantizer. |
| 466 | if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 467 | av1_cyclic_refresh_update_segment(cpi, &xd->mi[0]->mbmi, mi_row, mi_col, |
| 468 | bsize, ctx->rate, ctx->dist, x->skip); |
Jingning Han | 4470af1 | 2017-03-06 15:34:41 -0800 | [diff] [blame] | 469 | reset_tx_size(xd, &mi_addr->mbmi, cm->tx_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
Brennan Shacklett | e0b5ae8 | 2016-11-07 17:25:20 -0800 | [diff] [blame] | 473 | for (i = 0; i < MAX_MB_PLANE; ++i) { |
| 474 | p[i].coeff = ctx->coeff[i]; |
| 475 | p[i].qcoeff = ctx->qcoeff[i]; |
| 476 | pd[i].dqcoeff = ctx->dqcoeff[i]; |
Brennan Shacklett | e0b5ae8 | 2016-11-07 17:25:20 -0800 | [diff] [blame] | 477 | p[i].eobs = ctx->eobs[i]; |
Angie Chiang | 74e2307 | 2017-03-24 14:54:23 -0700 | [diff] [blame] | 478 | #if CONFIG_LV_MAP |
| 479 | p[i].txb_entropy_ctx = ctx->txb_entropy_ctx[i]; |
| 480 | #endif // CONFIG_LV_MAP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 481 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 482 | for (i = 0; i < 2; ++i) pd[i].color_index_map = ctx->color_index_map[i]; |
Sarah Parker | 5c6744b | 2017-08-25 17:27:45 -0700 | [diff] [blame] | 483 | #if CONFIG_MRC_TX |
| 484 | xd->mrc_mask = ctx->mrc_mask; |
| 485 | #endif // CONFIG_MRC_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 486 | // Restore the coding context of the MB to that that was in place |
| 487 | // when the mode was picked for it |
| 488 | for (y = 0; y < mi_height; y++) |
| 489 | for (x_idx = 0; x_idx < mi_width; x_idx++) |
| 490 | if ((xd->mb_to_right_edge >> (3 + MI_SIZE_LOG2)) + mi_width > x_idx && |
| 491 | (xd->mb_to_bottom_edge >> (3 + MI_SIZE_LOG2)) + mi_height > y) { |
| 492 | xd->mi[x_idx + y * mis] = mi_addr; |
| 493 | } |
| 494 | |
Thomas Davies | 3ab20b4 | 2017-09-19 10:30:53 +0100 | [diff] [blame] | 495 | #if !CONFIG_EXT_DELTA_Q |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 496 | if (cpi->oxcf.aq_mode > NO_AQ && cpi->oxcf.aq_mode < DELTA_AQ) |
Yaowu Xu | 5bb8f5b | 2016-11-02 15:31:29 -0700 | [diff] [blame] | 497 | av1_init_plane_quantizers(cpi, x, xd->mi[0]->mbmi.segment_id); |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 498 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 499 | if (cpi->oxcf.aq_mode) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 500 | av1_init_plane_quantizers(cpi, x, xd->mi[0]->mbmi.segment_id); |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 501 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 502 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 503 | x->skip = ctx->skip; |
| 504 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 505 | for (i = 0; i < 1; ++i) |
| 506 | memcpy(x->blk_skip[i], ctx->blk_skip[i], |
| 507 | sizeof(uint8_t) * ctx->num_4x4_blk); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 508 | |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 509 | if (dry_run) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 510 | |
| 511 | #if CONFIG_INTERNAL_STATS |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 512 | { |
| 513 | unsigned int *const mode_chosen_counts = |
| 514 | (unsigned int *)cpi->mode_chosen_counts; // Cast const away. |
| 515 | if (frame_is_intra_only(cm)) { |
| 516 | static const int kf_mode_index[] = { |
Urvang Joshi | 6be4a54 | 2016-11-03 15:24:05 -0700 | [diff] [blame] | 517 | THR_DC /*DC_PRED*/, |
| 518 | THR_V_PRED /*V_PRED*/, |
| 519 | THR_H_PRED /*H_PRED*/, |
| 520 | THR_D45_PRED /*D45_PRED*/, |
| 521 | THR_D135_PRED /*D135_PRED*/, |
| 522 | THR_D117_PRED /*D117_PRED*/, |
| 523 | THR_D153_PRED /*D153_PRED*/, |
| 524 | THR_D207_PRED /*D207_PRED*/, |
| 525 | THR_D63_PRED /*D63_PRED*/, |
Urvang Joshi | 6be4a54 | 2016-11-03 15:24:05 -0700 | [diff] [blame] | 526 | THR_SMOOTH, /*SMOOTH_PRED*/ |
Urvang Joshi | e6ca8e8 | 2017-03-15 14:57:41 -0700 | [diff] [blame] | 527 | #if CONFIG_SMOOTH_HV |
| 528 | THR_SMOOTH_V, /*SMOOTH_V_PRED*/ |
| 529 | THR_SMOOTH_H, /*SMOOTH_H_PRED*/ |
| 530 | #endif // CONFIG_SMOOTH_HV |
Urvang Joshi | 96d1c0a | 2017-10-10 13:15:32 -0700 | [diff] [blame] | 531 | THR_PAETH /*PAETH_PRED*/, |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 532 | }; |
| 533 | ++mode_chosen_counts[kf_mode_index[mbmi->mode]]; |
| 534 | } else { |
| 535 | // Note how often each mode chosen as best |
| 536 | ++mode_chosen_counts[ctx->best_mode_index]; |
| 537 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 538 | } |
| 539 | #endif |
| 540 | if (!frame_is_intra_only(cm)) { |
| 541 | if (is_inter_block(mbmi)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 542 | av1_update_mv_count(td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 543 | if (bsize >= BLOCK_8X8) { |
James Zern | af322e1 | 2016-10-22 12:43:15 -0700 | [diff] [blame] | 544 | // TODO(sarahparker): global motion stats need to be handled per-tile |
| 545 | // to be compatible with tile-based threading. |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 546 | update_global_motion_used(mbmi->mode, bsize, mbmi, rdc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 547 | } else { |
| 548 | const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; |
| 549 | const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; |
| 550 | int idx, idy; |
| 551 | for (idy = 0; idy < 2; idy += num_4x4_h) { |
| 552 | for (idx = 0; idx < 2; idx += num_4x4_w) { |
| 553 | const int j = idy * 2 + idx; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 554 | update_global_motion_used(mi->bmi[j].as_mode, bsize, mbmi, rdc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | } |
Sebastien Alaiwan | 1f56b8e | 2017-10-31 17:37:16 +0100 | [diff] [blame] | 558 | if (cm->interp_filter == SWITCHABLE && |
| 559 | mbmi->motion_mode != WARPED_CAUSAL && |
| 560 | !is_nontrans_global_motion(xd)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 561 | #if CONFIG_DUAL_FILTER |
| 562 | update_filter_type_count(td->counts, xd, mbmi); |
| 563 | #else |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 564 | const int switchable_ctx = av1_get_pred_context_switchable_interp(xd); |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 565 | const InterpFilter filter = |
| 566 | av1_extract_interp_filter(mbmi->interp_filters, 0); |
| 567 | ++td->counts->switchable_interp[switchable_ctx][filter]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 568 | #endif |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | rdc->comp_pred_diff[SINGLE_REFERENCE] += ctx->single_pred_diff; |
| 573 | rdc->comp_pred_diff[COMPOUND_REFERENCE] += ctx->comp_pred_diff; |
| 574 | rdc->comp_pred_diff[REFERENCE_MODE_SELECT] += ctx->hybrid_pred_diff; |
| 575 | } |
| 576 | |
Yunqing Wang | d1d511f | 2017-10-05 08:44:46 -0700 | [diff] [blame] | 577 | const int x_mis = AOMMIN(bw, cm->mi_cols - mi_col); |
| 578 | const int y_mis = AOMMIN(bh, cm->mi_rows - mi_row); |
| 579 | av1_copy_frame_mvs(cm, mi, mi_row, mi_col, x_mis, y_mis); |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 580 | |
| 581 | #if CONFIG_JNT_COMP |
| 582 | if (has_second_ref(mbmi)) { |
| 583 | const int comp_index_ctx = get_comp_index_context(cm, xd); |
| 584 | ++td->counts->compound_index[comp_index_ctx][mbmi->compound_idx]; |
| 585 | } |
| 586 | #endif // CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 589 | #if NC_MODE_INFO |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 590 | static void set_mode_info_b(const AV1_COMP *const cpi, |
| 591 | const TileInfo *const tile, ThreadData *td, |
| 592 | int mi_row, int mi_col, BLOCK_SIZE bsize, |
| 593 | PICK_MODE_CONTEXT *ctx) { |
| 594 | MACROBLOCK *const x = &td->mb; |
| 595 | set_offsets(cpi, tile, x, mi_row, mi_col, bsize); |
| 596 | update_state(cpi, td, ctx, mi_row, mi_col, bsize, 1); |
| 597 | } |
| 598 | |
| 599 | static void set_mode_info_sb(const AV1_COMP *const cpi, ThreadData *td, |
| 600 | const TileInfo *const tile, TOKENEXTRA **tp, |
| 601 | int mi_row, int mi_col, BLOCK_SIZE bsize, |
| 602 | PC_TREE *pc_tree) { |
| 603 | const AV1_COMMON *const cm = &cpi->common; |
Jingning Han | 91f01fd | 2017-01-18 17:16:40 -0800 | [diff] [blame] | 604 | const int hbs = mi_size_wide[bsize] / 2; |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 605 | const PARTITION_TYPE partition = pc_tree->partitioning; |
| 606 | BLOCK_SIZE subsize = get_subsize(bsize, partition); |
| 607 | #if CONFIG_EXT_PARTITION_TYPES |
| 608 | const BLOCK_SIZE bsize2 = get_subsize(bsize, PARTITION_SPLIT); |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 609 | const int quarter_step = mi_size_wide[bsize] / 4; |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 610 | #endif |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 611 | |
| 612 | if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) return; |
| 613 | |
| 614 | switch (partition) { |
| 615 | case PARTITION_NONE: |
| 616 | set_mode_info_b(cpi, tile, td, mi_row, mi_col, subsize, &pc_tree->none); |
| 617 | break; |
| 618 | case PARTITION_VERT: |
| 619 | set_mode_info_b(cpi, tile, td, mi_row, mi_col, subsize, |
| 620 | &pc_tree->vertical[0]); |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 621 | if (mi_col + hbs < cm->mi_cols) { |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 622 | set_mode_info_b(cpi, tile, td, mi_row, mi_col + hbs, subsize, |
| 623 | &pc_tree->vertical[1]); |
| 624 | } |
| 625 | break; |
| 626 | case PARTITION_HORZ: |
| 627 | set_mode_info_b(cpi, tile, td, mi_row, mi_col, subsize, |
| 628 | &pc_tree->horizontal[0]); |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 629 | if (mi_row + hbs < cm->mi_rows) { |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 630 | set_mode_info_b(cpi, tile, td, mi_row + hbs, mi_col, subsize, |
| 631 | &pc_tree->horizontal[1]); |
| 632 | } |
| 633 | break; |
| 634 | case PARTITION_SPLIT: |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 635 | set_mode_info_sb(cpi, td, tile, tp, mi_row, mi_col, subsize, |
| 636 | pc_tree->split[0]); |
| 637 | set_mode_info_sb(cpi, td, tile, tp, mi_row, mi_col + hbs, subsize, |
| 638 | pc_tree->split[1]); |
| 639 | set_mode_info_sb(cpi, td, tile, tp, mi_row + hbs, mi_col, subsize, |
| 640 | pc_tree->split[2]); |
| 641 | set_mode_info_sb(cpi, td, tile, tp, mi_row + hbs, mi_col + hbs, subsize, |
| 642 | pc_tree->split[3]); |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 643 | break; |
| 644 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 645 | #if CONFIG_EXT_PARTITION_TYPES_AB |
| 646 | #error NC_MODE_INFO+MOTION_VAR not yet supported for new HORZ/VERT_AB partitions |
| 647 | #endif |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 648 | case PARTITION_HORZ_A: |
| 649 | set_mode_info_b(cpi, tile, td, mi_row, mi_col, bsize2, |
| 650 | &pc_tree->horizontala[0]); |
| 651 | set_mode_info_b(cpi, tile, td, mi_row, mi_col + hbs, bsize2, |
| 652 | &pc_tree->horizontala[1]); |
| 653 | set_mode_info_b(cpi, tile, td, mi_row + hbs, mi_col, subsize, |
| 654 | &pc_tree->horizontala[2]); |
| 655 | break; |
| 656 | case PARTITION_HORZ_B: |
| 657 | set_mode_info_b(cpi, tile, td, mi_row, mi_col, subsize, |
| 658 | &pc_tree->horizontalb[0]); |
| 659 | set_mode_info_b(cpi, tile, td, mi_row + hbs, mi_col, bsize2, |
| 660 | &pc_tree->horizontalb[1]); |
| 661 | set_mode_info_b(cpi, tile, td, mi_row + hbs, mi_col + hbs, bsize2, |
| 662 | &pc_tree->horizontalb[2]); |
| 663 | break; |
| 664 | case PARTITION_VERT_A: |
| 665 | set_mode_info_b(cpi, tile, td, mi_row, mi_col, bsize2, |
| 666 | &pc_tree->verticala[0]); |
| 667 | set_mode_info_b(cpi, tile, td, mi_row + hbs, mi_col, bsize2, |
| 668 | &pc_tree->verticala[1]); |
| 669 | set_mode_info_b(cpi, tile, td, mi_row, mi_col + hbs, subsize, |
| 670 | &pc_tree->verticala[2]); |
| 671 | break; |
| 672 | case PARTITION_VERT_B: |
| 673 | set_mode_info_b(cpi, tile, td, mi_row, mi_col, subsize, |
| 674 | &pc_tree->verticalb[0]); |
| 675 | set_mode_info_b(cpi, tile, td, mi_row, mi_col + hbs, bsize2, |
| 676 | &pc_tree->verticalb[1]); |
| 677 | set_mode_info_b(cpi, tile, td, mi_row + hbs, mi_col + hbs, bsize2, |
| 678 | &pc_tree->verticalb[2]); |
| 679 | break; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 680 | case PARTITION_HORZ_4: |
| 681 | for (int i = 0; i < 4; ++i) { |
| 682 | int this_mi_row = mi_row + i * quarter_step; |
| 683 | if (i > 0 && this_mi_row >= cm->mi_rows) break; |
| 684 | |
| 685 | set_mode_info_b(cpi, tile, td, this_mi_row, mi_col, subsize, |
| 686 | &pc_tree->horizontal4[i]); |
| 687 | } |
| 688 | break; |
| 689 | case PARTITION_VERT_4: |
| 690 | for (int i = 0; i < 4; ++i) { |
| 691 | int this_mi_col = mi_col + i * quarter_step; |
| 692 | if (i > 0 && this_mi_col >= cm->mi_cols) break; |
| 693 | |
| 694 | set_mode_info_b(cpi, tile, td, mi_row, this_mi_col, subsize, |
| 695 | &pc_tree->vertical4[i]); |
| 696 | } |
| 697 | break; |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 698 | #endif // CONFIG_EXT_PARTITION_TYPES |
| 699 | default: assert(0 && "Invalid partition type."); break; |
| 700 | } |
| 701 | } |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 702 | |
| 703 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 704 | static void av1_get_ncobmc_mode_rd(const AV1_COMP *const cpi, |
| 705 | MACROBLOCK *const x, MACROBLOCKD *const xd, |
| 706 | int bsize, const int mi_row, |
| 707 | const int mi_col, NCOBMC_MODE *mode) { |
| 708 | const AV1_COMMON *const cm = &cpi->common; |
| 709 | const int mi_width = mi_size_wide[bsize]; |
| 710 | const int mi_height = mi_size_high[bsize]; |
| 711 | |
| 712 | assert(bsize >= BLOCK_8X8); |
| 713 | |
| 714 | reset_xd_boundary(xd, mi_row, mi_height, mi_col, mi_width, cm->mi_rows, |
| 715 | cm->mi_cols); |
| 716 | |
| 717 | // set up source buffers before calling the mode searching function |
| 718 | av1_setup_src_planes(x, cpi->source, mi_row, mi_col); |
| 719 | |
| 720 | *mode = get_ncobmc_mode(cpi, x, xd, mi_row, mi_col, bsize); |
| 721 | } |
| 722 | static void get_ncobmc_intrpl_pred(const AV1_COMP *const cpi, ThreadData *td, |
| 723 | int mi_row, int mi_col, BLOCK_SIZE bsize) { |
| 724 | MACROBLOCK *const x = &td->mb; |
| 725 | MACROBLOCKD *const xd = &x->e_mbd; |
| 726 | MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
| 727 | const int mi_width = mi_size_wide[bsize]; |
| 728 | const int mi_height = mi_size_high[bsize]; |
| 729 | const int hbs = AOMMAX(mi_size_wide[bsize] / 2, mi_size_high[bsize] / 2); |
| 730 | const BLOCK_SIZE sqr_blk = bsize_2_sqr_bsize[bsize]; |
| 731 | |
| 732 | if (mi_width > mi_height) { |
| 733 | // horizontal partition |
| 734 | av1_get_ncobmc_mode_rd(cpi, x, xd, sqr_blk, mi_row, mi_col, |
| 735 | &mbmi->ncobmc_mode[0]); |
| 736 | xd->mi += hbs; |
| 737 | av1_get_ncobmc_mode_rd(cpi, x, xd, sqr_blk, mi_row, mi_col + hbs, |
| 738 | &mbmi->ncobmc_mode[1]); |
| 739 | } else if (mi_height > mi_width) { |
| 740 | // vertical partition |
| 741 | av1_get_ncobmc_mode_rd(cpi, x, xd, sqr_blk, mi_row, mi_col, |
| 742 | &mbmi->ncobmc_mode[0]); |
| 743 | xd->mi += hbs * xd->mi_stride; |
| 744 | av1_get_ncobmc_mode_rd(cpi, x, xd, sqr_blk, mi_row + hbs, mi_col, |
| 745 | &mbmi->ncobmc_mode[1]); |
| 746 | } else { |
| 747 | av1_get_ncobmc_mode_rd(cpi, x, xd, sqr_blk, mi_row, mi_col, |
| 748 | &mbmi->ncobmc_mode[0]); |
| 749 | } |
| 750 | // restore the info |
| 751 | av1_setup_src_planes(x, cpi->source, mi_row, mi_col); |
| 752 | set_mode_info_offsets(cpi, x, xd, mi_row, mi_col); |
| 753 | } |
| 754 | #endif // CONFIG_NCOBMC_ADAPT_WEIGHT |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 755 | #endif // (CONFIG_NCOBMC || CONFIG_NCOBMC_ADAPT_WEIGHT) |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 756 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 757 | void av1_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src, |
| 758 | int mi_row, int mi_col) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 759 | uint8_t *const buffers[3] = { src->y_buffer, src->u_buffer, src->v_buffer }; |
| 760 | const int widths[3] = { src->y_crop_width, src->uv_crop_width, |
| 761 | src->uv_crop_width }; |
| 762 | const int heights[3] = { src->y_crop_height, src->uv_crop_height, |
| 763 | src->uv_crop_height }; |
| 764 | const int strides[3] = { src->y_stride, src->uv_stride, src->uv_stride }; |
| 765 | int i; |
| 766 | |
| 767 | // Set current frame pointer. |
| 768 | x->e_mbd.cur_buf = src; |
| 769 | |
| 770 | for (i = 0; i < MAX_MB_PLANE; i++) |
Jingning Han | 91d9a79 | 2017-04-18 12:01:52 -0700 | [diff] [blame] | 771 | setup_pred_plane(&x->plane[i].src, x->e_mbd.mi[0]->mbmi.sb_type, buffers[i], |
| 772 | widths[i], heights[i], strides[i], mi_row, mi_col, NULL, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 773 | x->e_mbd.plane[i].subsampling_x, |
| 774 | x->e_mbd.plane[i].subsampling_y); |
| 775 | } |
| 776 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 777 | static int set_segment_rdmult(const AV1_COMP *const cpi, MACROBLOCK *const x, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 778 | int8_t segment_id) { |
| 779 | int segment_qindex; |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 780 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 781 | av1_init_plane_quantizers(cpi, x, segment_id); |
| 782 | aom_clear_system_state(); |
| 783 | segment_qindex = av1_get_qindex(&cm->seg, segment_id, cm->base_qindex); |
| 784 | return av1_compute_rd_mult(cpi, segment_qindex + cm->y_dc_delta_q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 787 | #if CONFIG_DIST_8X8 |
Yushin Cho | b7b60c5 | 2017-07-14 16:18:52 -0700 | [diff] [blame] | 788 | static void dist_8x8_set_sub8x8_dst(MACROBLOCK *const x, uint8_t *dst8x8, |
| 789 | BLOCK_SIZE bsize, int bw, int bh, |
| 790 | int mi_row, int mi_col) { |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 791 | MACROBLOCKD *const xd = &x->e_mbd; |
| 792 | struct macroblockd_plane *const pd = &xd->plane[0]; |
| 793 | const int dst_stride = pd->dst.stride; |
| 794 | uint8_t *dst = pd->dst.buf; |
| 795 | |
| 796 | assert(bsize < BLOCK_8X8); |
| 797 | |
| 798 | if (bsize < BLOCK_8X8) { |
| 799 | int i, j; |
Yushin Cho | 8ab875d | 2017-06-23 14:47:21 -0700 | [diff] [blame] | 800 | #if CONFIG_HIGHBITDEPTH |
| 801 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 802 | uint16_t *dst8x8_16 = (uint16_t *)dst8x8; |
| 803 | uint16_t *dst_sub8x8 = &dst8x8_16[((mi_row & 1) * 8 + (mi_col & 1)) << 2]; |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 804 | |
Yushin Cho | 8ab875d | 2017-06-23 14:47:21 -0700 | [diff] [blame] | 805 | for (j = 0; j < bh; ++j) |
| 806 | for (i = 0; i < bw; ++i) |
| 807 | dst_sub8x8[j * 8 + i] = CONVERT_TO_SHORTPTR(dst)[j * dst_stride + i]; |
| 808 | } else { |
| 809 | #endif |
| 810 | uint8_t *dst_sub8x8 = &dst8x8[((mi_row & 1) * 8 + (mi_col & 1)) << 2]; |
| 811 | |
| 812 | for (j = 0; j < bh; ++j) |
| 813 | for (i = 0; i < bw; ++i) |
| 814 | dst_sub8x8[j * 8 + i] = dst[j * dst_stride + i]; |
| 815 | #if CONFIG_HIGHBITDEPTH |
| 816 | } |
| 817 | #endif |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 818 | } |
| 819 | } |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 820 | #endif // CONFIG_DIST_8X8 |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 821 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 822 | static void rd_pick_sb_modes(const AV1_COMP *const cpi, TileDataEnc *tile_data, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 823 | MACROBLOCK *const x, int mi_row, int mi_col, |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 824 | RD_STATS *rd_cost, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 825 | #if CONFIG_EXT_PARTITION_TYPES |
| 826 | PARTITION_TYPE partition, |
| 827 | #endif |
| 828 | BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, |
| 829 | int64_t best_rd) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 830 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 831 | TileInfo *const tile_info = &tile_data->tile_info; |
| 832 | MACROBLOCKD *const xd = &x->e_mbd; |
| 833 | MB_MODE_INFO *mbmi; |
| 834 | struct macroblock_plane *const p = x->plane; |
| 835 | struct macroblockd_plane *const pd = xd->plane; |
| 836 | const AQ_MODE aq_mode = cpi->oxcf.aq_mode; |
| 837 | int i, orig_rdmult; |
| 838 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 839 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 840 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 841 | set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); |
| 842 | mbmi = &xd->mi[0]->mbmi; |
| 843 | mbmi->sb_type = bsize; |
Angie Chiang | 394c337 | 2016-11-03 11:13:15 -0700 | [diff] [blame] | 844 | #if CONFIG_RD_DEBUG |
| 845 | mbmi->mi_row = mi_row; |
| 846 | mbmi->mi_col = mi_col; |
| 847 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 848 | #if CONFIG_EXT_PARTITION_TYPES |
| 849 | mbmi->partition = partition; |
| 850 | #endif |
| 851 | |
| 852 | for (i = 0; i < MAX_MB_PLANE; ++i) { |
Brennan Shacklett | e0b5ae8 | 2016-11-07 17:25:20 -0800 | [diff] [blame] | 853 | p[i].coeff = ctx->coeff[i]; |
| 854 | p[i].qcoeff = ctx->qcoeff[i]; |
| 855 | pd[i].dqcoeff = ctx->dqcoeff[i]; |
Brennan Shacklett | e0b5ae8 | 2016-11-07 17:25:20 -0800 | [diff] [blame] | 856 | p[i].eobs = ctx->eobs[i]; |
Angie Chiang | 74e2307 | 2017-03-24 14:54:23 -0700 | [diff] [blame] | 857 | #if CONFIG_LV_MAP |
| 858 | p[i].txb_entropy_ctx = ctx->txb_entropy_ctx[i]; |
| 859 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | for (i = 0; i < 2; ++i) pd[i].color_index_map = ctx->color_index_map[i]; |
Sarah Parker | 5c6744b | 2017-08-25 17:27:45 -0700 | [diff] [blame] | 863 | #if CONFIG_MRC_TX |
| 864 | xd->mrc_mask = ctx->mrc_mask; |
| 865 | #endif // CONFIG_MRC_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 866 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 867 | ctx->skippable = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 868 | |
| 869 | // Set to zero to make sure we do not use the previous encoded frame stats |
| 870 | mbmi->skip = 0; |
| 871 | |
Jingning Han | 8efdbc8 | 2017-02-19 14:40:03 -0800 | [diff] [blame] | 872 | x->skip_chroma_rd = |
Jingning Han | d3a6443 | 2017-04-06 17:04:17 -0700 | [diff] [blame] | 873 | !is_chroma_reference(mi_row, mi_col, bsize, xd->plane[1].subsampling_x, |
| 874 | xd->plane[1].subsampling_y); |
Jingning Han | 8efdbc8 | 2017-02-19 14:40:03 -0800 | [diff] [blame] | 875 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 876 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 877 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 878 | x->source_variance = av1_high_get_sby_perpixel_variance( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 879 | cpi, &x->plane[0].src, bsize, xd->bd); |
| 880 | } else { |
| 881 | x->source_variance = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 882 | av1_get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 883 | } |
| 884 | #else |
| 885 | x->source_variance = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 886 | av1_get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 887 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 888 | |
| 889 | // Save rdmult before it might be changed, so it can be restored later. |
| 890 | orig_rdmult = x->rdmult; |
| 891 | |
| 892 | if (aq_mode == VARIANCE_AQ) { |
| 893 | if (cpi->vaq_refresh) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 894 | const int energy = |
| 895 | bsize <= BLOCK_16X16 ? x->mb_energy : av1_block_energy(cpi, x, bsize); |
| 896 | mbmi->segment_id = av1_vaq_segment_id(energy); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 897 | // Re-initialise quantiser |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 898 | av1_init_plane_quantizers(cpi, x, mbmi->segment_id); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 899 | } |
| 900 | x->rdmult = set_segment_rdmult(cpi, x, mbmi->segment_id); |
| 901 | } else if (aq_mode == COMPLEXITY_AQ) { |
| 902 | x->rdmult = set_segment_rdmult(cpi, x, mbmi->segment_id); |
| 903 | } else if (aq_mode == CYCLIC_REFRESH_AQ) { |
| 904 | // If segment is boosted, use rdmult for that segment. |
| 905 | if (cyclic_refresh_segment_id_boosted(mbmi->segment_id)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 906 | x->rdmult = av1_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | // Find best coding mode & reconstruct the MB so it is available |
| 910 | // as a predictor for MBs that follow in the SB |
| 911 | if (frame_is_intra_only(cm)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 912 | av1_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, best_rd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 913 | } else { |
Jingning Han | b2a01db | 2017-06-01 13:52:02 -0700 | [diff] [blame] | 914 | if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
| 915 | av1_rd_pick_inter_mode_sb_seg_skip(cpi, tile_data, x, mi_row, mi_col, |
| 916 | rd_cost, bsize, ctx, best_rd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 917 | } else { |
Jingning Han | b2a01db | 2017-06-01 13:52:02 -0700 | [diff] [blame] | 918 | av1_rd_pick_inter_mode_sb(cpi, tile_data, x, mi_row, mi_col, rd_cost, |
Jingning Han | b2a01db | 2017-06-01 13:52:02 -0700 | [diff] [blame] | 919 | bsize, ctx, best_rd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 920 | } |
| 921 | } |
| 922 | |
| 923 | // Examine the resulting rate and for AQ mode 2 make a segment choice. |
| 924 | if ((rd_cost->rate != INT_MAX) && (aq_mode == COMPLEXITY_AQ) && |
| 925 | (bsize >= BLOCK_16X16) && |
| 926 | (cm->frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame || |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 927 | cpi->refresh_alt2_ref_frame || |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 928 | (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref))) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 929 | av1_caq_select_segment(cpi, x, bsize, mi_row, mi_col, rd_cost->rate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | x->rdmult = orig_rdmult; |
| 933 | |
| 934 | // TODO(jingning) The rate-distortion optimization flow needs to be |
| 935 | // refactored to provide proper exit/return handle. |
| 936 | if (rd_cost->rate == INT_MAX) rd_cost->rdcost = INT64_MAX; |
| 937 | |
| 938 | ctx->rate = rd_cost->rate; |
| 939 | ctx->dist = rd_cost->dist; |
| 940 | } |
| 941 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 942 | static void update_inter_mode_stats(FRAME_COUNTS *counts, PREDICTION_MODE mode, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 943 | int16_t mode_context) { |
| 944 | int16_t mode_ctx = mode_context & NEWMV_CTX_MASK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 945 | if (mode == NEWMV) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 946 | ++counts->newmv_mode[mode_ctx][0]; |
| 947 | return; |
| 948 | } else { |
| 949 | ++counts->newmv_mode[mode_ctx][1]; |
| 950 | |
| 951 | if (mode_context & (1 << ALL_ZERO_FLAG_OFFSET)) { |
| 952 | return; |
| 953 | } |
| 954 | |
| 955 | mode_ctx = (mode_context >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK; |
| 956 | if (mode == ZEROMV) { |
| 957 | ++counts->zeromv_mode[mode_ctx][0]; |
| 958 | return; |
| 959 | } else { |
| 960 | ++counts->zeromv_mode[mode_ctx][1]; |
| 961 | mode_ctx = (mode_context >> REFMV_OFFSET) & REFMV_CTX_MASK; |
| 962 | |
| 963 | if (mode_context & (1 << SKIP_NEARESTMV_OFFSET)) mode_ctx = 6; |
| 964 | if (mode_context & (1 << SKIP_NEARMV_OFFSET)) mode_ctx = 7; |
| 965 | if (mode_context & (1 << SKIP_NEARESTMV_SUB8X8_OFFSET)) mode_ctx = 8; |
| 966 | |
| 967 | ++counts->refmv_mode[mode_ctx][mode != NEARESTMV]; |
| 968 | } |
| 969 | } |
| 970 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 971 | |
Yaowu Xu | 5bb8f5b | 2016-11-02 15:31:29 -0700 | [diff] [blame] | 972 | static void update_stats(const AV1_COMMON *const cm, ThreadData *td, int mi_row, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 973 | int mi_col) { |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 974 | MACROBLOCK *x = &td->mb; |
| 975 | MACROBLOCKD *const xd = &x->e_mbd; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 976 | const MODE_INFO *const mi = xd->mi[0]; |
| 977 | const MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 978 | const MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext; |
| 979 | const BLOCK_SIZE bsize = mbmi->sb_type; |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 980 | FRAME_CONTEXT *fc = xd->tile_ctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 981 | |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 982 | // delta quant applies to both intra and inter |
Ryan | 676c25c | 2017-09-19 21:19:01 -0700 | [diff] [blame] | 983 | int super_block_upper_left = |
| 984 | ((mi_row & MAX_MIB_MASK) == 0) && ((mi_col & MAX_MIB_MASK) == 0); |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 985 | |
Zoe Liu | 1eed2df | 2017-10-16 17:13:15 -0700 | [diff] [blame] | 986 | const int seg_ref_active = |
| 987 | segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_REF_FRAME); |
| 988 | |
| 989 | if (!seg_ref_active) { |
| 990 | const int skip_ctx = av1_get_skip_context(xd); |
| 991 | td->counts->skip[skip_ctx][mbmi->skip]++; |
| 992 | #if CONFIG_NEW_MULTISYMBOL |
| 993 | update_cdf(fc->skip_cdfs[skip_ctx], mbmi->skip, 2); |
| 994 | #endif // CONFIG_NEW_MULTISYMBOL |
| 995 | } |
| 996 | |
Debargha Mukherjee | e30159c | 2017-10-08 12:04:43 -0700 | [diff] [blame] | 997 | if (cm->delta_q_present_flag && (bsize != cm->sb_size || !mbmi->skip) && |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 998 | super_block_upper_left) { |
| 999 | const int dq = (mbmi->current_q_index - xd->prev_qindex) / cm->delta_q_res; |
| 1000 | const int absdq = abs(dq); |
| 1001 | int i; |
Arild Fuldseth (arilfuld) | 54de7d6 | 2017-03-20 13:07:11 +0100 | [diff] [blame] | 1002 | for (i = 0; i < AOMMIN(absdq, DELTA_Q_SMALL); ++i) { |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 1003 | td->counts->delta_q[i][1]++; |
| 1004 | } |
| 1005 | if (absdq < DELTA_Q_SMALL) td->counts->delta_q[absdq][0]++; |
| 1006 | xd->prev_qindex = mbmi->current_q_index; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 1007 | #if CONFIG_EXT_DELTA_Q |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 1008 | #if CONFIG_LOOPFILTER_LEVEL |
| 1009 | if (cm->delta_lf_present_flag) { |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 1010 | if (cm->delta_lf_multi) { |
| 1011 | for (int lf_id = 0; lf_id < FRAME_LF_COUNT; ++lf_id) { |
| 1012 | const int delta_lf = |
| 1013 | (mbmi->curr_delta_lf[lf_id] - xd->prev_delta_lf[lf_id]) / |
| 1014 | cm->delta_lf_res; |
| 1015 | const int abs_delta_lf = abs(delta_lf); |
| 1016 | for (i = 0; i < AOMMIN(abs_delta_lf, DELTA_LF_SMALL); ++i) { |
| 1017 | td->counts->delta_lf_multi[lf_id][i][1]++; |
| 1018 | } |
| 1019 | if (abs_delta_lf < DELTA_LF_SMALL) |
| 1020 | td->counts->delta_lf_multi[lf_id][abs_delta_lf][0]++; |
| 1021 | xd->prev_delta_lf[lf_id] = mbmi->curr_delta_lf[lf_id]; |
| 1022 | } |
| 1023 | } else { |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 1024 | const int delta_lf = |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 1025 | (mbmi->current_delta_lf_from_base - xd->prev_delta_lf_from_base) / |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 1026 | cm->delta_lf_res; |
| 1027 | const int abs_delta_lf = abs(delta_lf); |
| 1028 | for (i = 0; i < AOMMIN(abs_delta_lf, DELTA_LF_SMALL); ++i) { |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 1029 | td->counts->delta_lf[i][1]++; |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 1030 | } |
| 1031 | if (abs_delta_lf < DELTA_LF_SMALL) |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 1032 | td->counts->delta_lf[abs_delta_lf][0]++; |
| 1033 | xd->prev_delta_lf_from_base = mbmi->current_delta_lf_from_base; |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 1034 | } |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 1035 | } |
| 1036 | #else |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 1037 | if (cm->delta_lf_present_flag) { |
| 1038 | const int dlf = |
| 1039 | (mbmi->current_delta_lf_from_base - xd->prev_delta_lf_from_base) / |
| 1040 | cm->delta_lf_res; |
| 1041 | const int absdlf = abs(dlf); |
| 1042 | for (i = 0; i < AOMMIN(absdlf, DELTA_LF_SMALL); ++i) { |
| 1043 | td->counts->delta_lf[i][1]++; |
| 1044 | } |
| 1045 | if (absdlf < DELTA_LF_SMALL) td->counts->delta_lf[absdlf][0]++; |
| 1046 | xd->prev_delta_lf_from_base = mbmi->current_delta_lf_from_base; |
| 1047 | } |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 1048 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 1049 | #endif |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 1050 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1051 | if (!frame_is_intra_only(cm)) { |
| 1052 | FRAME_COUNTS *const counts = td->counts; |
Arild Fuldseth (arilfuld) | 6c20c78 | 2017-06-15 09:45:02 +0200 | [diff] [blame] | 1053 | RD_COUNTS *rdc = &td->rd_counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1054 | const int inter_block = is_inter_block(mbmi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1055 | if (!seg_ref_active) { |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 1056 | counts->intra_inter[av1_get_intra_inter_context(xd)][inter_block]++; |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1057 | #if CONFIG_NEW_MULTISYMBOL |
| 1058 | update_cdf(fc->intra_inter_cdf[av1_get_intra_inter_context(xd)], |
| 1059 | inter_block, 2); |
| 1060 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1061 | // If the segment reference feature is enabled we have only a single |
| 1062 | // reference frame allowed for the segment so exclude it from |
| 1063 | // the reference frame counts used to work out probabilities. |
| 1064 | if (inter_block) { |
| 1065 | const MV_REFERENCE_FRAME ref0 = mbmi->ref_frame[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1066 | const MV_REFERENCE_FRAME ref1 = mbmi->ref_frame[1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1067 | |
Jingning Han | c41a549 | 2017-02-24 11:18:52 -0800 | [diff] [blame] | 1068 | if (cm->reference_mode == REFERENCE_MODE_SELECT) { |
Arild Fuldseth (arilfuld) | 6c20c78 | 2017-06-15 09:45:02 +0200 | [diff] [blame] | 1069 | if (has_second_ref(mbmi)) |
| 1070 | // This flag is also updated for 4x4 blocks |
| 1071 | rdc->compound_ref_used_flag = 1; |
| 1072 | else |
| 1073 | // This flag is also updated for 4x4 blocks |
| 1074 | rdc->single_ref_used_flag = 1; |
Debargha Mukherjee | 0f248c4 | 2017-09-07 12:40:18 -0700 | [diff] [blame] | 1075 | if (is_comp_ref_allowed(mbmi->sb_type)) { |
Jingning Han | c41a549 | 2017-02-24 11:18:52 -0800 | [diff] [blame] | 1076 | counts->comp_inter[av1_get_reference_mode_context(cm, xd)] |
| 1077 | [has_second_ref(mbmi)]++; |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1078 | #if CONFIG_NEW_MULTISYMBOL |
| 1079 | update_cdf(av1_get_reference_mode_cdf(cm, xd), has_second_ref(mbmi), |
| 1080 | 2); |
Debargha Mukherjee | 0f248c4 | 2017-09-07 12:40:18 -0700 | [diff] [blame] | 1081 | #endif // CONFIG_NEW_MULTISYMBOL |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1082 | } |
Jingning Han | c41a549 | 2017-02-24 11:18:52 -0800 | [diff] [blame] | 1083 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1084 | |
| 1085 | if (has_second_ref(mbmi)) { |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1086 | #if CONFIG_EXT_COMP_REFS |
| 1087 | const COMP_REFERENCE_TYPE comp_ref_type = has_uni_comp_refs(mbmi) |
| 1088 | ? UNIDIR_COMP_REFERENCE |
| 1089 | : BIDIR_COMP_REFERENCE; |
| 1090 | #if !USE_UNI_COMP_REFS |
| 1091 | // TODO(zoeliu): Temporarily turn off uni-directional comp refs |
| 1092 | assert(comp_ref_type == BIDIR_COMP_REFERENCE); |
| 1093 | #endif // !USE_UNI_COMP_REFS |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1094 | counts->comp_ref_type[av1_get_comp_reference_type_context(xd)] |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1095 | [comp_ref_type]++; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1096 | |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1097 | if (comp_ref_type == UNIDIR_COMP_REFERENCE) { |
| 1098 | const int bit = (ref0 == BWDREF_FRAME); |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1099 | counts->uni_comp_ref[av1_get_pred_context_uni_comp_ref_p(xd)][0] |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1100 | [bit]++; |
| 1101 | if (!bit) { |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 1102 | const int bit1 = (ref1 == LAST3_FRAME || ref1 == GOLDEN_FRAME); |
| 1103 | counts->uni_comp_ref[av1_get_pred_context_uni_comp_ref_p1(xd)][1] |
| 1104 | [bit1]++; |
| 1105 | if (bit1) { |
| 1106 | counts->uni_comp_ref[av1_get_pred_context_uni_comp_ref_p2(xd)] |
| 1107 | [2][ref1 == GOLDEN_FRAME]++; |
| 1108 | } |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1109 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1110 | } else { |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1111 | #endif // CONFIG_EXT_COMP_REFS |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1112 | const int bit = (ref0 == GOLDEN_FRAME || ref0 == LAST3_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1113 | |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1114 | counts->comp_ref[av1_get_pred_context_comp_ref_p(cm, xd)][0][bit]++; |
| 1115 | if (!bit) { |
| 1116 | counts->comp_ref[av1_get_pred_context_comp_ref_p1(cm, xd)][1] |
| 1117 | [ref0 == LAST_FRAME]++; |
| 1118 | } else { |
| 1119 | counts->comp_ref[av1_get_pred_context_comp_ref_p2(cm, xd)][2] |
| 1120 | [ref0 == GOLDEN_FRAME]++; |
| 1121 | } |
| 1122 | |
| 1123 | counts->comp_bwdref[av1_get_pred_context_comp_bwdref_p(cm, xd)][0] |
| 1124 | [ref1 == ALTREF_FRAME]++; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1125 | if (ref1 != ALTREF_FRAME) |
| 1126 | counts->comp_bwdref[av1_get_pred_context_comp_bwdref_p1(cm, xd)] |
| 1127 | [1][ref1 == ALTREF2_FRAME]++; |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 1128 | #if CONFIG_EXT_COMP_REFS |
| 1129 | } |
| 1130 | #endif // CONFIG_EXT_COMP_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1131 | } else { |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1132 | const int bit = (ref0 >= BWDREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1133 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1134 | counts->single_ref[av1_get_pred_context_single_ref_p1(xd)][0][bit]++; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1135 | if (bit) { |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1136 | assert(ref0 <= ALTREF_FRAME); |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 1137 | counts->single_ref[av1_get_pred_context_single_ref_p2(xd)][1] |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1138 | [ref0 == ALTREF_FRAME]++; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1139 | if (ref0 != ALTREF_FRAME) |
| 1140 | counts->single_ref[av1_get_pred_context_single_ref_p6(xd)][5] |
| 1141 | [ref0 == ALTREF2_FRAME]++; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1142 | } else { |
| 1143 | const int bit1 = !(ref0 == LAST2_FRAME || ref0 == LAST_FRAME); |
clang-format | 55ce9e0 | 2017-02-15 22:27:12 -0800 | [diff] [blame] | 1144 | counts |
| 1145 | ->single_ref[av1_get_pred_context_single_ref_p3(xd)][2][bit1]++; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1146 | if (!bit1) { |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 1147 | counts->single_ref[av1_get_pred_context_single_ref_p4(xd)][3] |
| 1148 | [ref0 != LAST_FRAME]++; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1149 | } else { |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 1150 | counts->single_ref[av1_get_pred_context_single_ref_p5(xd)][4] |
| 1151 | [ref0 != LAST3_FRAME]++; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1152 | } |
| 1153 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 1156 | #if CONFIG_COMPOUND_SINGLEREF |
| 1157 | if (!has_second_ref(mbmi)) |
| 1158 | counts->comp_inter_mode[av1_get_inter_mode_context(xd)] |
| 1159 | [is_inter_singleref_comp_mode(mbmi->mode)]++; |
| 1160 | #endif // CONFIG_COMPOUND_SINGLEREF |
| 1161 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1162 | if (cm->reference_mode != COMPOUND_REFERENCE && |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 1163 | cm->allow_interintra_compound && is_interintra_allowed(mbmi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1164 | const int bsize_group = size_group_lookup[bsize]; |
| 1165 | if (mbmi->ref_frame[1] == INTRA_FRAME) { |
| 1166 | counts->interintra[bsize_group][1]++; |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1167 | #if CONFIG_NEW_MULTISYMBOL |
| 1168 | update_cdf(fc->interintra_cdf[bsize_group], 1, 2); |
| 1169 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1170 | counts->interintra_mode[bsize_group][mbmi->interintra_mode]++; |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1171 | update_cdf(fc->interintra_mode_cdf[bsize_group], |
| 1172 | mbmi->interintra_mode, INTERINTRA_MODES); |
| 1173 | if (is_interintra_wedge_used(bsize)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1174 | counts->wedge_interintra[bsize][mbmi->use_wedge_interintra]++; |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1175 | #if CONFIG_NEW_MULTISYMBOL |
| 1176 | update_cdf(fc->wedge_interintra_cdf[bsize], |
| 1177 | mbmi->use_wedge_interintra, 2); |
| 1178 | #endif |
| 1179 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1180 | } else { |
| 1181 | counts->interintra[bsize_group][0]++; |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1182 | #if CONFIG_NEW_MULTISYMBOL |
| 1183 | update_cdf(fc->interintra_cdf[bsize_group], 0, 2); |
| 1184 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1185 | } |
| 1186 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1187 | |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 1188 | set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 1189 | const MOTION_MODE motion_allowed = |
Sebastien Alaiwan | 1f56b8e | 2017-10-31 17:37:16 +0100 | [diff] [blame] | 1190 | motion_mode_allowed(0, xd->global_motion, xd, mi); |
| 1191 | if (mbmi->ref_frame[1] != INTRA_FRAME) { |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 1192 | if (motion_allowed == WARPED_CAUSAL) { |
| 1193 | counts->motion_mode[mbmi->sb_type][mbmi->motion_mode]++; |
| 1194 | update_cdf(fc->motion_mode_cdf[mbmi->sb_type], mbmi->motion_mode, |
| 1195 | MOTION_MODES); |
Wei-Ting Lin | 07ed3ab | 2017-08-28 17:50:25 -0700 | [diff] [blame] | 1196 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 1197 | } else if (motion_allowed == NCOBMC_ADAPT_WEIGHT) { |
| 1198 | counts->ncobmc[mbmi->sb_type][mbmi->motion_mode]++; |
| 1199 | update_cdf(fc->ncobmc_cdf[mbmi->sb_type], mbmi->motion_mode, |
| 1200 | OBMC_FAMILY_MODES); |
| 1201 | } else if (motion_allowed == OBMC_CAUSAL) { |
| 1202 | counts->obmc[mbmi->sb_type][mbmi->motion_mode == OBMC_CAUSAL]++; |
| 1203 | update_cdf(fc->obmc_cdf[mbmi->sb_type], mbmi->motion_mode, 2); |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1204 | } |
| 1205 | #else |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 1206 | } else if (motion_allowed == OBMC_CAUSAL) { |
| 1207 | counts->obmc[mbmi->sb_type][mbmi->motion_mode == OBMC_CAUSAL]++; |
| 1208 | #if CONFIG_NEW_MULTISYMBOL |
| 1209 | update_cdf(fc->obmc_cdf[mbmi->sb_type], |
| 1210 | mbmi->motion_mode == OBMC_CAUSAL, 2); |
| 1211 | #endif |
| 1212 | } |
| 1213 | #endif // CONFIG_NCOBMC_ADAPT_WEIGHT |
| 1214 | } |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 1215 | |
| 1216 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
Wei-Ting Lin | 77c4118 | 2017-07-12 15:58:35 -0700 | [diff] [blame] | 1217 | if (mbmi->motion_mode == NCOBMC_ADAPT_WEIGHT) { |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 1218 | ADAPT_OVERLAP_BLOCK ao_block = |
| 1219 | adapt_overlap_block_lookup[mbmi->sb_type]; |
| 1220 | ++counts->ncobmc_mode[ao_block][mbmi->ncobmc_mode[0]]; |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1221 | update_cdf(fc->ncobmc_mode_cdf[ao_block], mbmi->ncobmc_mode[0], |
| 1222 | MAX_NCOBMC_MODES); |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 1223 | if (mi_size_wide[mbmi->sb_type] != mi_size_high[mbmi->sb_type]) { |
| 1224 | ++counts->ncobmc_mode[ao_block][mbmi->ncobmc_mode[1]]; |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1225 | update_cdf(fc->ncobmc_mode_cdf[ao_block], mbmi->ncobmc_mode[1], |
| 1226 | MAX_NCOBMC_MODES); |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | #endif |
| 1230 | |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 1231 | if ( |
| 1232 | #if CONFIG_COMPOUND_SINGLEREF |
| 1233 | is_inter_anyref_comp_mode(mbmi->mode) |
| 1234 | #else // !CONFIG_COMPOUND_SINGLEREF |
| 1235 | cm->reference_mode != SINGLE_REFERENCE && |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 1236 | is_inter_compound_mode(mbmi->mode) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 1237 | #endif // CONFIG_COMPOUND_SINGLEREF |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 1238 | && mbmi->motion_mode == SIMPLE_TRANSLATION) { |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1239 | if (is_interinter_compound_used(COMPOUND_WEDGE, bsize)) { |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1240 | counts |
| 1241 | ->compound_interinter[bsize][mbmi->interinter_compound_type]++; |
| 1242 | update_cdf(fc->compound_type_cdf[bsize], |
| 1243 | mbmi->interinter_compound_type, COMPOUND_TYPES); |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1244 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1245 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | if (inter_block && |
| 1250 | !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
Yaowu Xu | b0d0d00 | 2016-11-22 09:26:43 -0800 | [diff] [blame] | 1251 | int16_t mode_ctx; |
Jingning Han | b2a01db | 2017-06-01 13:52:02 -0700 | [diff] [blame] | 1252 | const PREDICTION_MODE mode = mbmi->mode; |
Jingning Han | b2a01db | 2017-06-01 13:52:02 -0700 | [diff] [blame] | 1253 | if (has_second_ref(mbmi)) { |
| 1254 | mode_ctx = mbmi_ext->compound_mode_context[mbmi->ref_frame[0]]; |
| 1255 | ++counts->inter_compound_mode[mode_ctx][INTER_COMPOUND_OFFSET(mode)]; |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 1256 | update_cdf(fc->inter_compound_mode_cdf[mode_ctx], |
| 1257 | INTER_COMPOUND_OFFSET(mode), INTER_COMPOUND_MODES); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 1258 | #if CONFIG_COMPOUND_SINGLEREF |
| 1259 | } else if (is_inter_singleref_comp_mode(mode)) { |
| 1260 | mode_ctx = mbmi_ext->compound_mode_context[mbmi->ref_frame[0]]; |
| 1261 | ++counts->inter_singleref_comp_mode[mode_ctx] |
| 1262 | [INTER_SINGLEREF_COMP_OFFSET(mode)]; |
| 1263 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1264 | } else { |
Jingning Han | b2a01db | 2017-06-01 13:52:02 -0700 | [diff] [blame] | 1265 | mode_ctx = av1_mode_context_analyzer(mbmi_ext->mode_context, |
| 1266 | mbmi->ref_frame, bsize, -1); |
| 1267 | update_inter_mode_stats(counts, mode, mode_ctx); |
Jingning Han | b2a01db | 2017-06-01 13:52:02 -0700 | [diff] [blame] | 1268 | } |
Jingning Han | b2a01db | 2017-06-01 13:52:02 -0700 | [diff] [blame] | 1269 | |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 1270 | int mode_allowed = (mbmi->mode == NEWMV); |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 1271 | mode_allowed |= (mbmi->mode == NEW_NEWMV); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 1272 | #if CONFIG_COMPOUND_SINGLEREF |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 1273 | mode_allowed |= (mbmi->mode == SR_NEW_NEWMV); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 1274 | #endif // CONFIG_COMPOUND_SINGLEREF |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 1275 | if (mode_allowed) { |
Jingning Han | b2a01db | 2017-06-01 13:52:02 -0700 | [diff] [blame] | 1276 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
| 1277 | int idx; |
| 1278 | |
| 1279 | for (idx = 0; idx < 2; ++idx) { |
| 1280 | if (mbmi_ext->ref_mv_count[ref_frame_type] > idx + 1) { |
| 1281 | uint8_t drl_ctx = |
| 1282 | av1_drl_ctx(mbmi_ext->ref_mv_stack[ref_frame_type], idx); |
| 1283 | ++counts->drl_mode[drl_ctx][mbmi->ref_mv_idx != idx]; |
| 1284 | |
| 1285 | if (mbmi->ref_mv_idx == idx) break; |
| 1286 | } |
| 1287 | } |
| 1288 | } |
| 1289 | |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 1290 | if (have_nearmv_in_inter_mode(mbmi->mode)) { |
Jingning Han | b2a01db | 2017-06-01 13:52:02 -0700 | [diff] [blame] | 1291 | uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); |
| 1292 | int idx; |
| 1293 | |
| 1294 | for (idx = 1; idx < 3; ++idx) { |
| 1295 | if (mbmi_ext->ref_mv_count[ref_frame_type] > idx + 1) { |
| 1296 | uint8_t drl_ctx = |
| 1297 | av1_drl_ctx(mbmi_ext->ref_mv_stack[ref_frame_type], idx); |
| 1298 | ++counts->drl_mode[drl_ctx][mbmi->ref_mv_idx != idx - 1]; |
| 1299 | |
| 1300 | if (mbmi->ref_mv_idx == idx - 1) break; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | } |
| 1304 | } |
Alex Converse | 7c412ea | 2017-06-01 15:16:22 -0700 | [diff] [blame] | 1305 | #if CONFIG_INTRABC |
| 1306 | } else { |
RogerZhou | ca86546 | 2017-10-05 15:06:27 -0700 | [diff] [blame] | 1307 | if (av1_allow_intrabc(bsize, cm)) { |
Alex Converse | 7c412ea | 2017-06-01 15:16:22 -0700 | [diff] [blame] | 1308 | FRAME_COUNTS *const counts = td->counts; |
| 1309 | ++counts->intrabc[mbmi->use_intrabc]; |
| 1310 | } else { |
| 1311 | assert(!mbmi->use_intrabc); |
| 1312 | } |
| 1313 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | typedef struct { |
| 1318 | ENTROPY_CONTEXT a[2 * MAX_MIB_SIZE * MAX_MB_PLANE]; |
| 1319 | ENTROPY_CONTEXT l[2 * MAX_MIB_SIZE * MAX_MB_PLANE]; |
| 1320 | PARTITION_CONTEXT sa[MAX_MIB_SIZE]; |
| 1321 | PARTITION_CONTEXT sl[MAX_MIB_SIZE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1322 | TXFM_CONTEXT *p_ta; |
| 1323 | TXFM_CONTEXT *p_tl; |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 1324 | TXFM_CONTEXT ta[2 * MAX_MIB_SIZE]; |
| 1325 | TXFM_CONTEXT tl[2 * MAX_MIB_SIZE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1326 | } RD_SEARCH_MACROBLOCK_CONTEXT; |
| 1327 | |
| 1328 | static void restore_context(MACROBLOCK *x, |
| 1329 | const RD_SEARCH_MACROBLOCK_CONTEXT *ctx, int mi_row, |
Yushin Cho | d0b77ac | 2017-10-20 17:33:16 -0700 | [diff] [blame] | 1330 | int mi_col, BLOCK_SIZE bsize) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1331 | MACROBLOCKD *xd = &x->e_mbd; |
| 1332 | int p; |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 1333 | const int num_4x4_blocks_wide = |
| 1334 | block_size_wide[bsize] >> tx_size_wide_log2[0]; |
| 1335 | const int num_4x4_blocks_high = |
| 1336 | block_size_high[bsize] >> tx_size_high_log2[0]; |
| 1337 | int mi_width = mi_size_wide[bsize]; |
| 1338 | int mi_height = mi_size_high[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1339 | for (p = 0; p < MAX_MB_PLANE; p++) { |
Timothy B. Terriberry | 5e81643 | 2017-05-05 13:58:32 -0700 | [diff] [blame] | 1340 | int tx_col; |
| 1341 | int tx_row; |
| 1342 | tx_col = mi_col << (MI_SIZE_LOG2 - tx_size_wide_log2[0]); |
| 1343 | tx_row = (mi_row & MAX_MIB_MASK) << (MI_SIZE_LOG2 - tx_size_high_log2[0]); |
| 1344 | memcpy(xd->above_context[p] + (tx_col >> xd->plane[p].subsampling_x), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1345 | ctx->a + num_4x4_blocks_wide * p, |
| 1346 | (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> |
| 1347 | xd->plane[p].subsampling_x); |
Timothy B. Terriberry | 5e81643 | 2017-05-05 13:58:32 -0700 | [diff] [blame] | 1348 | memcpy(xd->left_context[p] + (tx_row >> xd->plane[p].subsampling_y), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1349 | ctx->l + num_4x4_blocks_high * p, |
| 1350 | (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> |
| 1351 | xd->plane[p].subsampling_y); |
| 1352 | } |
| 1353 | memcpy(xd->above_seg_context + mi_col, ctx->sa, |
| 1354 | sizeof(*xd->above_seg_context) * mi_width); |
| 1355 | memcpy(xd->left_seg_context + (mi_row & MAX_MIB_MASK), ctx->sl, |
| 1356 | sizeof(xd->left_seg_context[0]) * mi_height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1357 | xd->above_txfm_context = ctx->p_ta; |
| 1358 | xd->left_txfm_context = ctx->p_tl; |
| 1359 | memcpy(xd->above_txfm_context, ctx->ta, |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 1360 | sizeof(*xd->above_txfm_context) * (mi_width << TX_UNIT_WIDE_LOG2)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1361 | memcpy(xd->left_txfm_context, ctx->tl, |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 1362 | sizeof(*xd->left_txfm_context) * (mi_height << TX_UNIT_HIGH_LOG2)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | static void save_context(const MACROBLOCK *x, RD_SEARCH_MACROBLOCK_CONTEXT *ctx, |
Yushin Cho | d0b77ac | 2017-10-20 17:33:16 -0700 | [diff] [blame] | 1366 | int mi_row, int mi_col, BLOCK_SIZE bsize) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1367 | const MACROBLOCKD *xd = &x->e_mbd; |
| 1368 | int p; |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 1369 | const int num_4x4_blocks_wide = |
| 1370 | block_size_wide[bsize] >> tx_size_wide_log2[0]; |
| 1371 | const int num_4x4_blocks_high = |
| 1372 | block_size_high[bsize] >> tx_size_high_log2[0]; |
| 1373 | int mi_width = mi_size_wide[bsize]; |
| 1374 | int mi_height = mi_size_high[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1375 | |
| 1376 | // buffer the above/left context information of the block in search. |
| 1377 | for (p = 0; p < MAX_MB_PLANE; ++p) { |
Timothy B. Terriberry | 5e81643 | 2017-05-05 13:58:32 -0700 | [diff] [blame] | 1378 | int tx_col; |
| 1379 | int tx_row; |
| 1380 | tx_col = mi_col << (MI_SIZE_LOG2 - tx_size_wide_log2[0]); |
| 1381 | tx_row = (mi_row & MAX_MIB_MASK) << (MI_SIZE_LOG2 - tx_size_high_log2[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1382 | memcpy(ctx->a + num_4x4_blocks_wide * p, |
Timothy B. Terriberry | 5e81643 | 2017-05-05 13:58:32 -0700 | [diff] [blame] | 1383 | xd->above_context[p] + (tx_col >> xd->plane[p].subsampling_x), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1384 | (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> |
| 1385 | xd->plane[p].subsampling_x); |
| 1386 | memcpy(ctx->l + num_4x4_blocks_high * p, |
Timothy B. Terriberry | 5e81643 | 2017-05-05 13:58:32 -0700 | [diff] [blame] | 1387 | xd->left_context[p] + (tx_row >> xd->plane[p].subsampling_y), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1388 | (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> |
| 1389 | xd->plane[p].subsampling_y); |
| 1390 | } |
| 1391 | memcpy(ctx->sa, xd->above_seg_context + mi_col, |
| 1392 | sizeof(*xd->above_seg_context) * mi_width); |
| 1393 | memcpy(ctx->sl, xd->left_seg_context + (mi_row & MAX_MIB_MASK), |
| 1394 | sizeof(xd->left_seg_context[0]) * mi_height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1395 | memcpy(ctx->ta, xd->above_txfm_context, |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 1396 | sizeof(*xd->above_txfm_context) * (mi_width << TX_UNIT_WIDE_LOG2)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1397 | memcpy(ctx->tl, xd->left_txfm_context, |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 1398 | sizeof(*xd->left_txfm_context) * (mi_height << TX_UNIT_HIGH_LOG2)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1399 | ctx->p_ta = xd->above_txfm_context; |
| 1400 | ctx->p_tl = xd->left_txfm_context; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 1403 | static void encode_b(const AV1_COMP *const cpi, const TileInfo *const tile, |
| 1404 | ThreadData *td, TOKENEXTRA **tp, int mi_row, int mi_col, |
| 1405 | RUN_TYPE dry_run, BLOCK_SIZE bsize, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1406 | #if CONFIG_EXT_PARTITION_TYPES |
| 1407 | PARTITION_TYPE partition, |
| 1408 | #endif |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1409 | PICK_MODE_CONTEXT *ctx, int *rate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1410 | MACROBLOCK *const x = &td->mb; |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 1411 | #if (CONFIG_NCOBMC) | CONFIG_EXT_DELTA_Q | CONFIG_NCOBMC_ADAPT_WEIGHT |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 1412 | MACROBLOCKD *xd = &x->e_mbd; |
| 1413 | MB_MODE_INFO *mbmi; |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 1414 | #if CONFIG_NCOBMC |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 1415 | int check_ncobmc; |
| 1416 | #endif |
Fangwen Fu | 4e2df09 | 2017-05-01 16:58:38 -0700 | [diff] [blame] | 1417 | #endif |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 1418 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1419 | set_offsets(cpi, tile, x, mi_row, mi_col, bsize); |
| 1420 | #if CONFIG_EXT_PARTITION_TYPES |
| 1421 | x->e_mbd.mi[0]->mbmi.partition = partition; |
| 1422 | #endif |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1423 | update_state(cpi, td, ctx, mi_row, mi_col, bsize, dry_run); |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 1424 | #if (CONFIG_NCOBMC || CONFIG_NCOBMC_ADAPT_WEIGHT) |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 1425 | mbmi = &xd->mi[0]->mbmi; |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 1426 | set_ref_ptrs(&cpi->common, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); |
| 1427 | #endif |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 1428 | |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 1429 | #if (CONFIG_NCOBMC || CONFIG_NCOBMC_ADAPT_WEIGHT) |
Sebastien Alaiwan | 1f56b8e | 2017-10-31 17:37:16 +0100 | [diff] [blame] | 1430 | const MOTION_MODE motion_allowed = |
| 1431 | motion_mode_allowed(0, xd->global_motion, xd, xd->mi[0]); |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 1432 | #endif // (CONFIG_NCOBMC || CONFIG_NCOBMC_ADAPT_WEIGHT) |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 1433 | |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 1434 | #if CONFIG_NCOBMC |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1435 | check_ncobmc = is_inter_block(mbmi) && motion_allowed >= OBMC_CAUSAL; |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 1436 | if (!dry_run && check_ncobmc) { |
| 1437 | av1_check_ncobmc_rd(cpi, x, mi_row, mi_col); |
Jingning Han | 91d9a79 | 2017-04-18 12:01:52 -0700 | [diff] [blame] | 1438 | av1_setup_dst_planes(x->e_mbd.plane, bsize, |
| 1439 | get_frame_new_buffer(&cpi->common), mi_row, mi_col); |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 1440 | } |
| 1441 | #endif |
Jingning Han | f5a4d3b | 2017-08-27 23:01:19 -0700 | [diff] [blame] | 1442 | |
| 1443 | #if CONFIG_LV_MAP |
| 1444 | av1_set_coeff_buffer(cpi, x, mi_row, mi_col); |
| 1445 | #endif |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 1446 | |
| 1447 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
Wei-Ting Lin | 3122b7d | 2017-08-30 17:26:58 -0700 | [diff] [blame] | 1448 | if (dry_run == OUTPUT_ENABLED && !frame_is_intra_only(&cpi->common)) { |
Wei-Ting Lin | 5f8f7a1 | 2017-08-31 14:39:52 -0700 | [diff] [blame] | 1449 | if (motion_allowed >= NCOBMC_ADAPT_WEIGHT && is_inter_block(mbmi)) { |
Wei-Ting Lin | 3122b7d | 2017-08-30 17:26:58 -0700 | [diff] [blame] | 1450 | get_ncobmc_intrpl_pred(cpi, td, mi_row, mi_col, bsize); |
| 1451 | av1_check_ncobmc_adapt_weight_rd(cpi, x, mi_row, mi_col); |
| 1452 | } |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 1453 | av1_setup_dst_planes(x->e_mbd.plane, bsize, |
| 1454 | get_frame_new_buffer(&cpi->common), mi_row, mi_col); |
| 1455 | } |
| 1456 | #endif // CONFIG_NCOBMC_ADAPT_WEIGHT |
| 1457 | |
Yushin Cho | 6d72a2f | 2017-05-03 17:37:37 -0700 | [diff] [blame] | 1458 | encode_superblock(cpi, td, tp, dry_run, mi_row, mi_col, bsize, rate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1459 | |
Jingning Han | f5a4d3b | 2017-08-27 23:01:19 -0700 | [diff] [blame] | 1460 | #if CONFIG_LV_MAP |
| 1461 | if (dry_run == 0) |
| 1462 | x->cb_offset += block_size_wide[bsize] * block_size_high[bsize]; |
| 1463 | #endif |
| 1464 | |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1465 | if (!dry_run) { |
Fangwen Fu | 4e2df09 | 2017-05-01 16:58:38 -0700 | [diff] [blame] | 1466 | #if CONFIG_EXT_DELTA_Q |
| 1467 | mbmi = &xd->mi[0]->mbmi; |
Debargha Mukherjee | e30159c | 2017-10-08 12:04:43 -0700 | [diff] [blame] | 1468 | if (bsize == cpi->common.sb_size && mbmi->skip == 1 && |
Fangwen Fu | 4e2df09 | 2017-05-01 16:58:38 -0700 | [diff] [blame] | 1469 | cpi->common.delta_lf_present_flag) { |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 1470 | #if CONFIG_LOOPFILTER_LEVEL |
| 1471 | for (int lf_id = 0; lf_id < FRAME_LF_COUNT; ++lf_id) |
| 1472 | mbmi->curr_delta_lf[lf_id] = xd->prev_delta_lf[lf_id]; |
| 1473 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 4e2df09 | 2017-05-01 16:58:38 -0700 | [diff] [blame] | 1474 | mbmi->current_delta_lf_from_base = xd->prev_delta_lf_from_base; |
| 1475 | } |
| 1476 | #endif |
Yaowu Xu | 5bb8f5b | 2016-11-02 15:31:29 -0700 | [diff] [blame] | 1477 | update_stats(&cpi->common, td, mi_row, mi_col); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1478 | } |
| 1479 | } |
| 1480 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 1481 | static void encode_sb(const AV1_COMP *const cpi, ThreadData *td, |
| 1482 | const TileInfo *const tile, TOKENEXTRA **tp, int mi_row, |
| 1483 | int mi_col, RUN_TYPE dry_run, BLOCK_SIZE bsize, |
| 1484 | PC_TREE *pc_tree, int *rate) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1485 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1486 | MACROBLOCK *const x = &td->mb; |
| 1487 | MACROBLOCKD *const xd = &x->e_mbd; |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 1488 | const int hbs = mi_size_wide[bsize] / 2; |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 1489 | #if CONFIG_EXT_PARTITION_TYPES && CONFIG_EXT_PARTITION_TYPES_AB |
| 1490 | const int qbs = mi_size_wide[bsize] / 4; |
| 1491 | #endif |
Jingning Han | bf9c6b7 | 2016-12-14 14:50:45 -0800 | [diff] [blame] | 1492 | const int is_partition_root = bsize >= BLOCK_8X8; |
| 1493 | const int ctx = is_partition_root |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 1494 | ? partition_plane_context(xd, mi_row, mi_col, |
| 1495 | #if CONFIG_UNPOISON_PARTITION_CTX |
| 1496 | mi_row + hbs < cm->mi_rows, |
| 1497 | mi_col + hbs < cm->mi_cols, |
| 1498 | #endif |
| 1499 | bsize) |
| 1500 | : -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1501 | const PARTITION_TYPE partition = pc_tree->partitioning; |
| 1502 | const BLOCK_SIZE subsize = get_subsize(bsize, partition); |
| 1503 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1504 | int quarter_step = mi_size_wide[bsize] / 4; |
| 1505 | int i; |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 1506 | #if !CONFIG_EXT_PARTITION_TYPES_AB |
| 1507 | BLOCK_SIZE bsize2 = get_subsize(bsize, PARTITION_SPLIT); |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1508 | #endif // !CONFIG_EXT_PARTITION_TYPES_AB |
| 1509 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1510 | |
| 1511 | if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) return; |
| 1512 | |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 1513 | if (!dry_run && ctx >= 0) td->counts->partition[ctx][partition]++; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1514 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1515 | switch (partition) { |
| 1516 | case PARTITION_NONE: |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1517 | encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1518 | #if CONFIG_EXT_PARTITION_TYPES |
| 1519 | partition, |
| 1520 | #endif |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1521 | &pc_tree->none, rate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1522 | break; |
| 1523 | case PARTITION_VERT: |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1524 | encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1525 | #if CONFIG_EXT_PARTITION_TYPES |
| 1526 | partition, |
| 1527 | #endif |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1528 | &pc_tree->vertical[0], rate); |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1529 | if (mi_col + hbs < cm->mi_cols) { |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1530 | encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, dry_run, subsize, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1531 | #if CONFIG_EXT_PARTITION_TYPES |
| 1532 | partition, |
| 1533 | #endif |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1534 | &pc_tree->vertical[1], rate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1535 | } |
| 1536 | break; |
| 1537 | case PARTITION_HORZ: |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1538 | encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1539 | #if CONFIG_EXT_PARTITION_TYPES |
| 1540 | partition, |
| 1541 | #endif |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1542 | &pc_tree->horizontal[0], rate); |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1543 | if (mi_row + hbs < cm->mi_rows) { |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1544 | encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, dry_run, subsize, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1545 | #if CONFIG_EXT_PARTITION_TYPES |
| 1546 | partition, |
| 1547 | #endif |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1548 | &pc_tree->horizontal[1], rate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1549 | } |
| 1550 | break; |
| 1551 | case PARTITION_SPLIT: |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1552 | encode_sb(cpi, td, tile, tp, mi_row, mi_col, dry_run, subsize, |
| 1553 | pc_tree->split[0], rate); |
| 1554 | encode_sb(cpi, td, tile, tp, mi_row, mi_col + hbs, dry_run, subsize, |
| 1555 | pc_tree->split[1], rate); |
| 1556 | encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col, dry_run, subsize, |
| 1557 | pc_tree->split[2], rate); |
| 1558 | encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col + hbs, dry_run, subsize, |
| 1559 | pc_tree->split[3], rate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1560 | break; |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 1561 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1562 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 1563 | #if CONFIG_EXT_PARTITION_TYPES_AB |
| 1564 | case PARTITION_HORZ_A: |
| 1565 | encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, |
| 1566 | get_subsize(bsize, PARTITION_HORZ_4), partition, |
| 1567 | &pc_tree->horizontala[0], rate); |
| 1568 | encode_b(cpi, tile, td, tp, mi_row + qbs, mi_col, dry_run, |
| 1569 | get_subsize(bsize, PARTITION_HORZ_4), partition, |
| 1570 | &pc_tree->horizontala[1], rate); |
| 1571 | encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, dry_run, subsize, |
| 1572 | partition, &pc_tree->horizontala[2], rate); |
| 1573 | break; |
| 1574 | case PARTITION_HORZ_B: |
| 1575 | encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize, partition, |
| 1576 | &pc_tree->horizontalb[0], rate); |
| 1577 | encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, dry_run, |
| 1578 | get_subsize(bsize, PARTITION_HORZ_4), partition, |
| 1579 | &pc_tree->horizontalb[1], rate); |
| 1580 | if (mi_row + 3 * qbs < cm->mi_rows) |
| 1581 | encode_b(cpi, tile, td, tp, mi_row + 3 * qbs, mi_col, dry_run, |
| 1582 | get_subsize(bsize, PARTITION_HORZ_4), partition, |
| 1583 | &pc_tree->horizontalb[2], rate); |
| 1584 | break; |
| 1585 | case PARTITION_VERT_A: |
| 1586 | encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, |
| 1587 | get_subsize(bsize, PARTITION_VERT_4), partition, |
| 1588 | &pc_tree->verticala[0], rate); |
| 1589 | encode_b(cpi, tile, td, tp, mi_row, mi_col + qbs, dry_run, |
| 1590 | get_subsize(bsize, PARTITION_VERT_4), partition, |
| 1591 | &pc_tree->verticala[1], rate); |
| 1592 | encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, dry_run, subsize, |
| 1593 | partition, &pc_tree->verticala[2], rate); |
| 1594 | |
| 1595 | break; |
| 1596 | case PARTITION_VERT_B: |
| 1597 | encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize, partition, |
| 1598 | &pc_tree->verticalb[0], rate); |
| 1599 | encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, dry_run, |
| 1600 | get_subsize(bsize, PARTITION_VERT_4), partition, |
| 1601 | &pc_tree->verticalb[1], rate); |
| 1602 | if (mi_col + 3 * qbs < cm->mi_cols) |
| 1603 | encode_b(cpi, tile, td, tp, mi_row, mi_col + 3 * qbs, dry_run, |
| 1604 | get_subsize(bsize, PARTITION_VERT_4), partition, |
| 1605 | &pc_tree->verticalb[2], rate); |
| 1606 | break; |
| 1607 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1608 | case PARTITION_HORZ_A: |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1609 | encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, bsize2, partition, |
| 1610 | &pc_tree->horizontala[0], rate); |
| 1611 | encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, dry_run, bsize2, |
| 1612 | partition, &pc_tree->horizontala[1], rate); |
| 1613 | encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, dry_run, subsize, |
| 1614 | partition, &pc_tree->horizontala[2], rate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1615 | break; |
| 1616 | case PARTITION_HORZ_B: |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1617 | encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize, partition, |
| 1618 | &pc_tree->horizontalb[0], rate); |
| 1619 | encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, dry_run, bsize2, |
| 1620 | partition, &pc_tree->horizontalb[1], rate); |
| 1621 | encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col + hbs, dry_run, bsize2, |
| 1622 | partition, &pc_tree->horizontalb[2], rate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1623 | break; |
| 1624 | case PARTITION_VERT_A: |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1625 | encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, bsize2, partition, |
| 1626 | &pc_tree->verticala[0], rate); |
| 1627 | encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col, dry_run, bsize2, |
| 1628 | partition, &pc_tree->verticala[1], rate); |
| 1629 | encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, dry_run, subsize, |
| 1630 | partition, &pc_tree->verticala[2], rate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1631 | |
| 1632 | break; |
| 1633 | case PARTITION_VERT_B: |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1634 | encode_b(cpi, tile, td, tp, mi_row, mi_col, dry_run, subsize, partition, |
| 1635 | &pc_tree->verticalb[0], rate); |
| 1636 | encode_b(cpi, tile, td, tp, mi_row, mi_col + hbs, dry_run, bsize2, |
| 1637 | partition, &pc_tree->verticalb[1], rate); |
| 1638 | encode_b(cpi, tile, td, tp, mi_row + hbs, mi_col + hbs, dry_run, bsize2, |
| 1639 | partition, &pc_tree->verticalb[2], rate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1640 | break; |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 1641 | #endif |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1642 | case PARTITION_HORZ_4: |
| 1643 | for (i = 0; i < 4; ++i) { |
| 1644 | int this_mi_row = mi_row + i * quarter_step; |
| 1645 | if (i > 0 && this_mi_row >= cm->mi_rows) break; |
| 1646 | |
| 1647 | encode_b(cpi, tile, td, tp, this_mi_row, mi_col, dry_run, subsize, |
| 1648 | partition, &pc_tree->horizontal4[i], rate); |
| 1649 | } |
| 1650 | break; |
| 1651 | case PARTITION_VERT_4: |
| 1652 | for (i = 0; i < 4; ++i) { |
| 1653 | int this_mi_col = mi_col + i * quarter_step; |
| 1654 | if (i > 0 && this_mi_col >= cm->mi_cols) break; |
| 1655 | |
| 1656 | encode_b(cpi, tile, td, tp, mi_row, this_mi_col, dry_run, subsize, |
| 1657 | partition, &pc_tree->vertical4[i], rate); |
| 1658 | } |
| 1659 | break; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1660 | #endif // CONFIG_EXT_PARTITION_TYPES |
| 1661 | default: assert(0 && "Invalid partition type."); break; |
| 1662 | } |
| 1663 | |
| 1664 | #if CONFIG_EXT_PARTITION_TYPES |
| 1665 | update_ext_partition_context(xd, mi_row, mi_col, subsize, bsize, partition); |
| 1666 | #else |
| 1667 | if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) |
| 1668 | update_partition_context(xd, mi_row, mi_col, subsize, bsize); |
| 1669 | #endif // CONFIG_EXT_PARTITION_TYPES |
| 1670 | } |
| 1671 | |
| 1672 | // Check to see if the given partition size is allowed for a specified number |
| 1673 | // of mi block rows and columns remaining in the image. |
| 1674 | // If not then return the largest allowed partition size |
| 1675 | static BLOCK_SIZE find_partition_size(BLOCK_SIZE bsize, int rows_left, |
| 1676 | int cols_left, int *bh, int *bw) { |
| 1677 | if (rows_left <= 0 || cols_left <= 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1678 | return AOMMIN(bsize, BLOCK_8X8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1679 | } else { |
| 1680 | for (; bsize > 0; bsize -= 3) { |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 1681 | *bh = mi_size_high[bsize]; |
| 1682 | *bw = mi_size_wide[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1683 | if ((*bh <= rows_left) && (*bw <= cols_left)) { |
| 1684 | break; |
| 1685 | } |
| 1686 | } |
| 1687 | } |
| 1688 | return bsize; |
| 1689 | } |
| 1690 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1691 | static void set_partial_sb_partition(const AV1_COMMON *const cm, MODE_INFO *mi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1692 | int bh_in, int bw_in, |
| 1693 | int mi_rows_remaining, |
| 1694 | int mi_cols_remaining, BLOCK_SIZE bsize, |
| 1695 | MODE_INFO **mib) { |
| 1696 | int bh = bh_in; |
| 1697 | int r, c; |
| 1698 | for (r = 0; r < cm->mib_size; r += bh) { |
| 1699 | int bw = bw_in; |
| 1700 | for (c = 0; c < cm->mib_size; c += bw) { |
| 1701 | const int index = r * cm->mi_stride + c; |
| 1702 | mib[index] = mi + index; |
| 1703 | mib[index]->mbmi.sb_type = find_partition_size( |
| 1704 | bsize, mi_rows_remaining - r, mi_cols_remaining - c, &bh, &bw); |
| 1705 | } |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | // This function attempts to set all mode info entries in a given superblock |
| 1710 | // to the same block partition size. |
| 1711 | // However, at the bottom and right borders of the image the requested size |
| 1712 | // may not be allowed in which case this code attempts to choose the largest |
| 1713 | // allowable partition. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1714 | static void set_fixed_partitioning(AV1_COMP *cpi, const TileInfo *const tile, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1715 | MODE_INFO **mib, int mi_row, int mi_col, |
| 1716 | BLOCK_SIZE bsize) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1717 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1718 | const int mi_rows_remaining = tile->mi_row_end - mi_row; |
| 1719 | const int mi_cols_remaining = tile->mi_col_end - mi_col; |
| 1720 | int block_row, block_col; |
| 1721 | MODE_INFO *const mi_upper_left = cm->mi + mi_row * cm->mi_stride + mi_col; |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 1722 | int bh = mi_size_high[bsize]; |
| 1723 | int bw = mi_size_wide[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1724 | |
| 1725 | assert((mi_rows_remaining > 0) && (mi_cols_remaining > 0)); |
| 1726 | |
| 1727 | // Apply the requested partition size to the SB if it is all "in image" |
| 1728 | if ((mi_cols_remaining >= cm->mib_size) && |
| 1729 | (mi_rows_remaining >= cm->mib_size)) { |
| 1730 | for (block_row = 0; block_row < cm->mib_size; block_row += bh) { |
| 1731 | for (block_col = 0; block_col < cm->mib_size; block_col += bw) { |
| 1732 | int index = block_row * cm->mi_stride + block_col; |
| 1733 | mib[index] = mi_upper_left + index; |
| 1734 | mib[index]->mbmi.sb_type = bsize; |
| 1735 | } |
| 1736 | } |
| 1737 | } else { |
| 1738 | // Else this is a partial SB. |
| 1739 | set_partial_sb_partition(cm, mi_upper_left, bh, bw, mi_rows_remaining, |
| 1740 | mi_cols_remaining, bsize, mib); |
| 1741 | } |
| 1742 | } |
| 1743 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1744 | static void rd_use_partition(AV1_COMP *cpi, ThreadData *td, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1745 | TileDataEnc *tile_data, MODE_INFO **mib, |
| 1746 | TOKENEXTRA **tp, int mi_row, int mi_col, |
| 1747 | BLOCK_SIZE bsize, int *rate, int64_t *dist, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1748 | int do_recon, PC_TREE *pc_tree) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1749 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1750 | TileInfo *const tile_info = &tile_data->tile_info; |
| 1751 | MACROBLOCK *const x = &td->mb; |
| 1752 | MACROBLOCKD *const xd = &x->e_mbd; |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 1753 | const int bs = mi_size_wide[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1754 | const int hbs = bs / 2; |
| 1755 | int i; |
Jingning Han | 6fc515e | 2017-04-07 11:30:09 -0700 | [diff] [blame] | 1756 | const int pl = (bsize >= BLOCK_8X8) |
| 1757 | ? partition_plane_context(xd, mi_row, mi_col, |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 1758 | #if CONFIG_UNPOISON_PARTITION_CTX |
Jingning Han | 6fc515e | 2017-04-07 11:30:09 -0700 | [diff] [blame] | 1759 | mi_row + hbs < cm->mi_rows, |
| 1760 | mi_col + hbs < cm->mi_cols, |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 1761 | #endif |
Jingning Han | 6fc515e | 2017-04-07 11:30:09 -0700 | [diff] [blame] | 1762 | bsize) |
| 1763 | : 0; |
| 1764 | const PARTITION_TYPE partition = |
| 1765 | (bsize >= BLOCK_8X8) ? get_partition(cm, mi_row, mi_col, bsize) |
| 1766 | : PARTITION_NONE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1767 | const BLOCK_SIZE subsize = get_subsize(bsize, partition); |
| 1768 | RD_SEARCH_MACROBLOCK_CONTEXT x_ctx; |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1769 | RD_STATS last_part_rdc, none_rdc, chosen_rdc; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1770 | BLOCK_SIZE sub_subsize = BLOCK_4X4; |
| 1771 | int splits_below = 0; |
| 1772 | BLOCK_SIZE bs_type = mib[0]->mbmi.sb_type; |
| 1773 | int do_partition_search = 1; |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 1774 | PICK_MODE_CONTEXT *ctx_none = &pc_tree->none; |
Yushin Cho | d0b77ac | 2017-10-20 17:33:16 -0700 | [diff] [blame] | 1775 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1776 | if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) return; |
| 1777 | |
| 1778 | assert(num_4x4_blocks_wide_lookup[bsize] == |
| 1779 | num_4x4_blocks_high_lookup[bsize]); |
| 1780 | |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1781 | av1_invalid_rd_stats(&last_part_rdc); |
| 1782 | av1_invalid_rd_stats(&none_rdc); |
| 1783 | av1_invalid_rd_stats(&chosen_rdc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1784 | |
| 1785 | pc_tree->partitioning = partition; |
| 1786 | |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 1787 | xd->above_txfm_context = |
| 1788 | cm->above_txfm_context + (mi_col << TX_UNIT_WIDE_LOG2); |
| 1789 | xd->left_txfm_context = xd->left_txfm_context_buffer + |
| 1790 | ((mi_row & MAX_MIB_MASK) << TX_UNIT_HIGH_LOG2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1791 | save_context(x, &x_ctx, mi_row, mi_col, bsize); |
| 1792 | |
| 1793 | if (bsize == BLOCK_16X16 && cpi->vaq_refresh) { |
| 1794 | set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1795 | x->mb_energy = av1_block_energy(cpi, x, bsize); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | if (do_partition_search && |
| 1799 | cpi->sf.partition_search_type == SEARCH_PARTITION && |
| 1800 | cpi->sf.adjust_partitioning_from_last_frame) { |
| 1801 | // Check if any of the sub blocks are further split. |
| 1802 | if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { |
| 1803 | sub_subsize = get_subsize(subsize, PARTITION_SPLIT); |
| 1804 | splits_below = 1; |
| 1805 | for (i = 0; i < 4; i++) { |
| 1806 | int jj = i >> 1, ii = i & 0x01; |
| 1807 | MODE_INFO *this_mi = mib[jj * hbs * cm->mi_stride + ii * hbs]; |
| 1808 | if (this_mi && this_mi->mbmi.sb_type >= sub_subsize) { |
| 1809 | splits_below = 0; |
| 1810 | } |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | // If partition is not none try none unless each of the 4 splits are split |
| 1815 | // even further.. |
| 1816 | if (partition != PARTITION_NONE && !splits_below && |
| 1817 | mi_row + hbs < cm->mi_rows && mi_col + hbs < cm->mi_cols) { |
| 1818 | pc_tree->partitioning = PARTITION_NONE; |
| 1819 | rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &none_rdc, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1820 | #if CONFIG_EXT_PARTITION_TYPES |
| 1821 | PARTITION_NONE, |
| 1822 | #endif |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 1823 | bsize, ctx_none, INT64_MAX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1824 | |
| 1825 | if (none_rdc.rate < INT_MAX) { |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 1826 | none_rdc.rate += x->partition_cost[pl][PARTITION_NONE]; |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 1827 | none_rdc.rdcost = RDCOST(x->rdmult, none_rdc.rate, none_rdc.dist); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1831 | mib[0]->mbmi.sb_type = bs_type; |
| 1832 | pc_tree->partitioning = partition; |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | switch (partition) { |
| 1837 | case PARTITION_NONE: |
| 1838 | rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &last_part_rdc, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1839 | #if CONFIG_EXT_PARTITION_TYPES |
| 1840 | PARTITION_NONE, |
| 1841 | #endif |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 1842 | bsize, ctx_none, INT64_MAX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1843 | break; |
| 1844 | case PARTITION_HORZ: |
| 1845 | rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &last_part_rdc, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1846 | #if CONFIG_EXT_PARTITION_TYPES |
| 1847 | PARTITION_HORZ, |
| 1848 | #endif |
| 1849 | subsize, &pc_tree->horizontal[0], INT64_MAX); |
| 1850 | if (last_part_rdc.rate != INT_MAX && bsize >= BLOCK_8X8 && |
| 1851 | mi_row + hbs < cm->mi_rows) { |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1852 | RD_STATS tmp_rdc; |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 1853 | PICK_MODE_CONTEXT *ctx_h = &pc_tree->horizontal[0]; |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1854 | av1_init_rd_stats(&tmp_rdc); |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 1855 | update_state(cpi, td, ctx_h, mi_row, mi_col, subsize, 1); |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1856 | encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row, mi_col, subsize, |
Yushin Cho | 6d72a2f | 2017-05-03 17:37:37 -0700 | [diff] [blame] | 1857 | NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1858 | rd_pick_sb_modes(cpi, tile_data, x, mi_row + hbs, mi_col, &tmp_rdc, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1859 | #if CONFIG_EXT_PARTITION_TYPES |
| 1860 | PARTITION_HORZ, |
| 1861 | #endif |
| 1862 | subsize, &pc_tree->horizontal[1], INT64_MAX); |
| 1863 | if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1864 | av1_invalid_rd_stats(&last_part_rdc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1865 | break; |
| 1866 | } |
| 1867 | last_part_rdc.rate += tmp_rdc.rate; |
| 1868 | last_part_rdc.dist += tmp_rdc.dist; |
| 1869 | last_part_rdc.rdcost += tmp_rdc.rdcost; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1870 | } |
| 1871 | break; |
| 1872 | case PARTITION_VERT: |
| 1873 | rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &last_part_rdc, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1874 | #if CONFIG_EXT_PARTITION_TYPES |
| 1875 | PARTITION_VERT, |
| 1876 | #endif |
| 1877 | subsize, &pc_tree->vertical[0], INT64_MAX); |
| 1878 | if (last_part_rdc.rate != INT_MAX && bsize >= BLOCK_8X8 && |
| 1879 | mi_col + hbs < cm->mi_cols) { |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1880 | RD_STATS tmp_rdc; |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 1881 | PICK_MODE_CONTEXT *ctx_v = &pc_tree->vertical[0]; |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1882 | av1_init_rd_stats(&tmp_rdc); |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 1883 | update_state(cpi, td, ctx_v, mi_row, mi_col, subsize, 1); |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1884 | encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row, mi_col, subsize, |
Yushin Cho | 6d72a2f | 2017-05-03 17:37:37 -0700 | [diff] [blame] | 1885 | NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1886 | rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + hbs, &tmp_rdc, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1887 | #if CONFIG_EXT_PARTITION_TYPES |
| 1888 | PARTITION_VERT, |
| 1889 | #endif |
| 1890 | subsize, &pc_tree->vertical[bsize > BLOCK_8X8], |
| 1891 | INT64_MAX); |
| 1892 | if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1893 | av1_invalid_rd_stats(&last_part_rdc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1894 | break; |
| 1895 | } |
| 1896 | last_part_rdc.rate += tmp_rdc.rate; |
| 1897 | last_part_rdc.dist += tmp_rdc.dist; |
| 1898 | last_part_rdc.rdcost += tmp_rdc.rdcost; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1899 | } |
| 1900 | break; |
| 1901 | case PARTITION_SPLIT: |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1902 | last_part_rdc.rate = 0; |
| 1903 | last_part_rdc.dist = 0; |
| 1904 | last_part_rdc.rdcost = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1905 | for (i = 0; i < 4; i++) { |
| 1906 | int x_idx = (i & 1) * hbs; |
| 1907 | int y_idx = (i >> 1) * hbs; |
| 1908 | int jj = i >> 1, ii = i & 0x01; |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1909 | RD_STATS tmp_rdc; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1910 | if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) |
| 1911 | continue; |
| 1912 | |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1913 | av1_init_rd_stats(&tmp_rdc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1914 | rd_use_partition(cpi, td, tile_data, |
| 1915 | mib + jj * hbs * cm->mi_stride + ii * hbs, tp, |
| 1916 | mi_row + y_idx, mi_col + x_idx, subsize, &tmp_rdc.rate, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 1917 | &tmp_rdc.dist, i != 3, pc_tree->split[i]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1918 | if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1919 | av1_invalid_rd_stats(&last_part_rdc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1920 | break; |
| 1921 | } |
| 1922 | last_part_rdc.rate += tmp_rdc.rate; |
| 1923 | last_part_rdc.dist += tmp_rdc.dist; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1924 | } |
| 1925 | break; |
| 1926 | #if CONFIG_EXT_PARTITION_TYPES |
| 1927 | case PARTITION_VERT_A: |
| 1928 | case PARTITION_VERT_B: |
| 1929 | case PARTITION_HORZ_A: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1930 | case PARTITION_HORZ_B: |
| 1931 | case PARTITION_HORZ_4: |
| 1932 | case PARTITION_VERT_4: assert(0 && "Cannot handle extended partiton types"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1933 | #endif // CONFIG_EXT_PARTITION_TYPES |
| 1934 | default: assert(0); break; |
| 1935 | } |
| 1936 | |
| 1937 | if (last_part_rdc.rate < INT_MAX) { |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 1938 | last_part_rdc.rate += x->partition_cost[pl][partition]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1939 | last_part_rdc.rdcost = |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 1940 | RDCOST(x->rdmult, last_part_rdc.rate, last_part_rdc.dist); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | if (do_partition_search && cpi->sf.adjust_partitioning_from_last_frame && |
| 1944 | cpi->sf.partition_search_type == SEARCH_PARTITION && |
| 1945 | partition != PARTITION_SPLIT && bsize > BLOCK_8X8 && |
| 1946 | (mi_row + bs < cm->mi_rows || mi_row + hbs == cm->mi_rows) && |
| 1947 | (mi_col + bs < cm->mi_cols || mi_col + hbs == cm->mi_cols)) { |
| 1948 | BLOCK_SIZE split_subsize = get_subsize(bsize, PARTITION_SPLIT); |
| 1949 | chosen_rdc.rate = 0; |
| 1950 | chosen_rdc.dist = 0; |
Yushin Cho | d0b77ac | 2017-10-20 17:33:16 -0700 | [diff] [blame] | 1951 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1952 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1953 | pc_tree->partitioning = PARTITION_SPLIT; |
| 1954 | |
| 1955 | // Split partition. |
| 1956 | for (i = 0; i < 4; i++) { |
| 1957 | int x_idx = (i & 1) * hbs; |
| 1958 | int y_idx = (i >> 1) * hbs; |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1959 | RD_STATS tmp_rdc; |
Yushin Cho | d0b77ac | 2017-10-20 17:33:16 -0700 | [diff] [blame] | 1960 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1961 | if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) |
| 1962 | continue; |
| 1963 | |
| 1964 | save_context(x, &x_ctx, mi_row, mi_col, bsize); |
| 1965 | pc_tree->split[i]->partitioning = PARTITION_NONE; |
| 1966 | rd_pick_sb_modes(cpi, tile_data, x, mi_row + y_idx, mi_col + x_idx, |
| 1967 | &tmp_rdc, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1968 | #if CONFIG_EXT_PARTITION_TYPES |
| 1969 | PARTITION_SPLIT, |
| 1970 | #endif |
| 1971 | split_subsize, &pc_tree->split[i]->none, INT64_MAX); |
| 1972 | |
| 1973 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1974 | if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 1975 | av1_invalid_rd_stats(&chosen_rdc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1976 | break; |
| 1977 | } |
| 1978 | |
| 1979 | chosen_rdc.rate += tmp_rdc.rate; |
| 1980 | chosen_rdc.dist += tmp_rdc.dist; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1981 | |
| 1982 | if (i != 3) |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 1983 | encode_sb(cpi, td, tile_info, tp, mi_row + y_idx, mi_col + x_idx, |
| 1984 | OUTPUT_ENABLED, split_subsize, pc_tree->split[i], NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1985 | |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 1986 | chosen_rdc.rate += x->partition_cost[pl][PARTITION_NONE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1987 | } |
| 1988 | if (chosen_rdc.rate < INT_MAX) { |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 1989 | chosen_rdc.rate += x->partition_cost[pl][PARTITION_SPLIT]; |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 1990 | chosen_rdc.rdcost = RDCOST(x->rdmult, chosen_rdc.rate, chosen_rdc.dist); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1991 | } |
| 1992 | } |
| 1993 | |
| 1994 | // If last_part is better set the partitioning to that. |
| 1995 | if (last_part_rdc.rdcost < chosen_rdc.rdcost) { |
| 1996 | mib[0]->mbmi.sb_type = bsize; |
| 1997 | if (bsize >= BLOCK_8X8) pc_tree->partitioning = partition; |
| 1998 | chosen_rdc = last_part_rdc; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1999 | } |
| 2000 | // If none was better set the partitioning to that. |
| 2001 | if (none_rdc.rdcost < chosen_rdc.rdcost) { |
| 2002 | if (bsize >= BLOCK_8X8) pc_tree->partitioning = PARTITION_NONE; |
| 2003 | chosen_rdc = none_rdc; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
| 2007 | |
| 2008 | // We must have chosen a partitioning and encoding or we'll fail later on. |
| 2009 | // No other opportunities for success. |
| 2010 | if (bsize == cm->sb_size) |
| 2011 | assert(chosen_rdc.rate < INT_MAX && chosen_rdc.dist < INT64_MAX); |
| 2012 | |
| 2013 | if (do_recon) { |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 2014 | if (bsize == cm->sb_size) { |
| 2015 | // NOTE: To get estimate for rate due to the tokens, use: |
| 2016 | // int rate_coeffs = 0; |
| 2017 | // encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, DRY_RUN_COSTCOEFFS, |
| 2018 | // bsize, pc_tree, &rate_coeffs); |
| 2019 | encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, OUTPUT_ENABLED, bsize, |
| 2020 | pc_tree, NULL); |
| 2021 | } else { |
| 2022 | encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, DRY_RUN_NORMAL, bsize, |
| 2023 | pc_tree, NULL); |
| 2024 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | *rate = chosen_rdc.rate; |
| 2028 | *dist = chosen_rdc.dist; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | /* clang-format off */ |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2032 | static const BLOCK_SIZE min_partition_size[BLOCK_SIZES_ALL] = { |
Jingning Han | f1702dd | 2016-11-30 21:17:59 -0800 | [diff] [blame] | 2033 | BLOCK_2X2, BLOCK_2X2, BLOCK_2X2, // 2x2, 2x4, 4x2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2034 | BLOCK_4X4, // 4x4 |
| 2035 | BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, // 4x8, 8x4, 8x8 |
| 2036 | BLOCK_4X4, BLOCK_4X4, BLOCK_8X8, // 8x16, 16x8, 16x16 |
| 2037 | BLOCK_8X8, BLOCK_8X8, BLOCK_16X16, // 16x32, 32x16, 32x32 |
| 2038 | BLOCK_16X16, BLOCK_16X16, BLOCK_16X16, // 32x64, 64x32, 64x64 |
| 2039 | #if CONFIG_EXT_PARTITION |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2040 | BLOCK_16X16, BLOCK_16X16, BLOCK_16X16, // 64x128, 128x64, 128x128 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2041 | #endif // CONFIG_EXT_PARTITION |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2042 | BLOCK_4X4, BLOCK_4X4, BLOCK_8X8, // 4x16, 16x4, 8x32 |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2043 | BLOCK_8X8, BLOCK_16X16, BLOCK_16X16, // 32x8, 16x64, 64x16 |
| 2044 | #if CONFIG_EXT_PARTITION |
| 2045 | BLOCK_16X16, BLOCK_16X16 // 32x128, 128x32 |
| 2046 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2047 | }; |
| 2048 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2049 | static const BLOCK_SIZE max_partition_size[BLOCK_SIZES_ALL] = { |
Jingning Han | f1702dd | 2016-11-30 21:17:59 -0800 | [diff] [blame] | 2050 | BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, // 2x2, 2x4, 4x2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2051 | BLOCK_8X8, // 4x4 |
| 2052 | BLOCK_16X16, BLOCK_16X16, BLOCK_16X16, // 4x8, 8x4, 8x8 |
| 2053 | BLOCK_32X32, BLOCK_32X32, BLOCK_32X32, // 8x16, 16x8, 16x16 |
| 2054 | BLOCK_64X64, BLOCK_64X64, BLOCK_64X64, // 16x32, 32x16, 32x32 |
| 2055 | BLOCK_LARGEST, BLOCK_LARGEST, BLOCK_LARGEST, // 32x64, 64x32, 64x64 |
| 2056 | #if CONFIG_EXT_PARTITION |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2057 | BLOCK_LARGEST, BLOCK_LARGEST, BLOCK_LARGEST, // 64x128, 128x64, 128x128 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2058 | #endif // CONFIG_EXT_PARTITION |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2059 | BLOCK_16X16, BLOCK_16X16, BLOCK_32X32, // 4x16, 16x4, 8x32 |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2060 | BLOCK_32X32, BLOCK_LARGEST, BLOCK_LARGEST, // 32x8, 16x64, 64x16 |
| 2061 | #if CONFIG_EXT_PARTITION |
| 2062 | BLOCK_LARGEST, BLOCK_LARGEST // 32x128, 128x32 |
| 2063 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2064 | }; |
| 2065 | |
| 2066 | // Next square block size less or equal than current block size. |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2067 | static const BLOCK_SIZE next_square_size[BLOCK_SIZES_ALL] = { |
Jingning Han | f1702dd | 2016-11-30 21:17:59 -0800 | [diff] [blame] | 2068 | BLOCK_2X2, BLOCK_2X2, BLOCK_2X2, // 2x2, 2x4, 4x2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2069 | BLOCK_4X4, // 4x4 |
| 2070 | BLOCK_4X4, BLOCK_4X4, BLOCK_8X8, // 4x8, 8x4, 8x8 |
| 2071 | BLOCK_8X8, BLOCK_8X8, BLOCK_16X16, // 8x16, 16x8, 16x16 |
| 2072 | BLOCK_16X16, BLOCK_16X16, BLOCK_32X32, // 16x32, 32x16, 32x32 |
| 2073 | BLOCK_32X32, BLOCK_32X32, BLOCK_64X64, // 32x64, 64x32, 64x64 |
| 2074 | #if CONFIG_EXT_PARTITION |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2075 | BLOCK_64X64, BLOCK_64X64, BLOCK_128X128, // 64x128, 128x64, 128x128 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2076 | #endif // CONFIG_EXT_PARTITION |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2077 | BLOCK_4X4, BLOCK_4X4, BLOCK_8X8, // 4x16, 16x4, 8x32 |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2078 | BLOCK_8X8, BLOCK_16X16, BLOCK_16X16, // 32x8, 16x64, 64x16 |
| 2079 | #if CONFIG_EXT_PARTITION |
| 2080 | BLOCK_32X32, BLOCK_32X32 // 32x128, 128x32 |
| 2081 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2082 | }; |
| 2083 | /* clang-format on */ |
| 2084 | |
| 2085 | // Look at all the mode_info entries for blocks that are part of this |
| 2086 | // partition and find the min and max values for sb_type. |
| 2087 | // At the moment this is designed to work on a superblock but could be |
| 2088 | // adjusted to use a size parameter. |
| 2089 | // |
| 2090 | // The min and max are assumed to have been initialized prior to calling this |
| 2091 | // function so repeat calls can accumulate a min and max of more than one |
| 2092 | // superblock. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2093 | static void get_sb_partition_size_range(const AV1_COMMON *const cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2094 | MACROBLOCKD *xd, MODE_INFO **mib, |
| 2095 | BLOCK_SIZE *min_block_size, |
| 2096 | BLOCK_SIZE *max_block_size) { |
| 2097 | int i, j; |
| 2098 | int index = 0; |
| 2099 | |
| 2100 | // Check the sb_type for each block that belongs to this region. |
| 2101 | for (i = 0; i < cm->mib_size; ++i) { |
| 2102 | for (j = 0; j < cm->mib_size; ++j) { |
| 2103 | MODE_INFO *mi = mib[index + j]; |
| 2104 | BLOCK_SIZE sb_type = mi ? mi->mbmi.sb_type : BLOCK_4X4; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2105 | *min_block_size = AOMMIN(*min_block_size, sb_type); |
| 2106 | *max_block_size = AOMMAX(*max_block_size, sb_type); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2107 | } |
| 2108 | index += xd->mi_stride; |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | // Look at neighboring blocks and set a min and max partition size based on |
| 2113 | // what they chose. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2114 | static void rd_auto_partition_range(AV1_COMP *cpi, const TileInfo *const tile, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2115 | MACROBLOCKD *const xd, int mi_row, |
| 2116 | int mi_col, BLOCK_SIZE *min_block_size, |
| 2117 | BLOCK_SIZE *max_block_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2118 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2119 | MODE_INFO **mi = xd->mi; |
| 2120 | const int left_in_image = xd->left_available && mi[-1]; |
| 2121 | const int above_in_image = xd->up_available && mi[-xd->mi_stride]; |
| 2122 | const int mi_rows_remaining = tile->mi_row_end - mi_row; |
| 2123 | const int mi_cols_remaining = tile->mi_col_end - mi_col; |
| 2124 | int bh, bw; |
| 2125 | BLOCK_SIZE min_size = BLOCK_4X4; |
| 2126 | BLOCK_SIZE max_size = BLOCK_LARGEST; |
| 2127 | |
| 2128 | // Trap case where we do not have a prediction. |
| 2129 | if (left_in_image || above_in_image || cm->frame_type != KEY_FRAME) { |
| 2130 | // Default "min to max" and "max to min" |
| 2131 | min_size = BLOCK_LARGEST; |
| 2132 | max_size = BLOCK_4X4; |
| 2133 | |
| 2134 | // NOTE: each call to get_sb_partition_size_range() uses the previous |
| 2135 | // passed in values for min and max as a starting point. |
| 2136 | // Find the min and max partition used in previous frame at this location |
| 2137 | if (cm->frame_type != KEY_FRAME) { |
| 2138 | MODE_INFO **prev_mi = |
| 2139 | &cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col]; |
| 2140 | get_sb_partition_size_range(cm, xd, prev_mi, &min_size, &max_size); |
| 2141 | } |
| 2142 | // Find the min and max partition sizes used in the left superblock |
| 2143 | if (left_in_image) { |
| 2144 | MODE_INFO **left_sb_mi = &mi[-cm->mib_size]; |
| 2145 | get_sb_partition_size_range(cm, xd, left_sb_mi, &min_size, &max_size); |
| 2146 | } |
| 2147 | // Find the min and max partition sizes used in the above suprblock. |
| 2148 | if (above_in_image) { |
| 2149 | MODE_INFO **above_sb_mi = &mi[-xd->mi_stride * cm->mib_size]; |
| 2150 | get_sb_partition_size_range(cm, xd, above_sb_mi, &min_size, &max_size); |
| 2151 | } |
| 2152 | |
| 2153 | // Adjust observed min and max for "relaxed" auto partition case. |
| 2154 | if (cpi->sf.auto_min_max_partition_size == RELAXED_NEIGHBORING_MIN_MAX) { |
| 2155 | min_size = min_partition_size[min_size]; |
| 2156 | max_size = max_partition_size[max_size]; |
| 2157 | } |
| 2158 | } |
| 2159 | |
| 2160 | // Check border cases where max and min from neighbors may not be legal. |
| 2161 | max_size = find_partition_size(max_size, mi_rows_remaining, mi_cols_remaining, |
| 2162 | &bh, &bw); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2163 | min_size = AOMMIN(min_size, max_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2164 | |
| 2165 | // Test for blocks at the edge of the active image. |
| 2166 | // This may be the actual edge of the image or where there are formatting |
| 2167 | // bars. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2168 | if (av1_active_edge_sb(cpi, mi_row, mi_col)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2169 | min_size = BLOCK_4X4; |
| 2170 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2171 | min_size = AOMMIN(cpi->sf.rd_auto_partition_min_limit, min_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | // When use_square_partition_only is true, make sure at least one square |
| 2175 | // partition is allowed by selecting the next smaller square size as |
| 2176 | // *min_block_size. |
| 2177 | if (cpi->sf.use_square_partition_only) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2178 | min_size = AOMMIN(min_size, next_square_size[max_size]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2181 | *min_block_size = AOMMIN(min_size, cm->sb_size); |
| 2182 | *max_block_size = AOMMIN(max_size, cm->sb_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | // TODO(jingning) refactor functions setting partition search range |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2186 | static void set_partition_range(const AV1_COMMON *const cm, |
| 2187 | const MACROBLOCKD *const xd, int mi_row, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2188 | int mi_col, BLOCK_SIZE bsize, |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2189 | BLOCK_SIZE *const min_bs, |
| 2190 | BLOCK_SIZE *const max_bs) { |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 2191 | const int mi_width = mi_size_wide[bsize]; |
| 2192 | const int mi_height = mi_size_high[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2193 | int idx, idy; |
| 2194 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2195 | const int idx_str = cm->mi_stride * mi_row + mi_col; |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2196 | MODE_INFO **const prev_mi = &cm->prev_mi_grid_visible[idx_str]; |
Debargha Mukherjee | e30159c | 2017-10-08 12:04:43 -0700 | [diff] [blame] | 2197 | BLOCK_SIZE min_size = cm->sb_size; // default values |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2198 | BLOCK_SIZE max_size = BLOCK_4X4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2199 | |
| 2200 | if (prev_mi) { |
| 2201 | for (idy = 0; idy < mi_height; ++idy) { |
| 2202 | for (idx = 0; idx < mi_width; ++idx) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2203 | const MODE_INFO *const mi = prev_mi[idy * cm->mi_stride + idx]; |
| 2204 | const BLOCK_SIZE bs = mi ? mi->mbmi.sb_type : bsize; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2205 | min_size = AOMMIN(min_size, bs); |
| 2206 | max_size = AOMMAX(max_size, bs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2207 | } |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | if (xd->left_available) { |
| 2212 | for (idy = 0; idy < mi_height; ++idy) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2213 | const MODE_INFO *const mi = xd->mi[idy * cm->mi_stride - 1]; |
| 2214 | const BLOCK_SIZE bs = mi ? mi->mbmi.sb_type : bsize; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2215 | min_size = AOMMIN(min_size, bs); |
| 2216 | max_size = AOMMAX(max_size, bs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | if (xd->up_available) { |
| 2221 | for (idx = 0; idx < mi_width; ++idx) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2222 | const MODE_INFO *const mi = xd->mi[idx - cm->mi_stride]; |
| 2223 | const BLOCK_SIZE bs = mi ? mi->mbmi.sb_type : bsize; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2224 | min_size = AOMMIN(min_size, bs); |
| 2225 | max_size = AOMMAX(max_size, bs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2226 | } |
| 2227 | } |
| 2228 | |
| 2229 | if (min_size == max_size) { |
| 2230 | min_size = min_partition_size[min_size]; |
| 2231 | max_size = max_partition_size[max_size]; |
| 2232 | } |
| 2233 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2234 | *min_bs = AOMMIN(min_size, cm->sb_size); |
| 2235 | *max_bs = AOMMIN(max_size, cm->sb_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | static INLINE void store_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { |
| 2239 | memcpy(ctx->pred_mv, x->pred_mv, sizeof(x->pred_mv)); |
| 2240 | } |
| 2241 | |
| 2242 | static INLINE void load_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { |
| 2243 | memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv)); |
| 2244 | } |
| 2245 | |
| 2246 | #if CONFIG_FP_MB_STATS |
| 2247 | const int qindex_skip_threshold_lookup[BLOCK_SIZES] = { |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 2248 | 0, 10, 10, 30, 40, 40, 60, 80, 80, 90, 100, 100, 120, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2249 | #if CONFIG_EXT_PARTITION |
| 2250 | // TODO(debargha): What are the correct numbers here? |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 2251 | 130, 130, 150 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2252 | #endif // CONFIG_EXT_PARTITION |
| 2253 | }; |
| 2254 | const int qindex_split_threshold_lookup[BLOCK_SIZES] = { |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 2255 | 0, 3, 3, 7, 15, 15, 30, 40, 40, 60, 80, 80, 120, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2256 | #if CONFIG_EXT_PARTITION |
| 2257 | // TODO(debargha): What are the correct numbers here? |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 2258 | 160, 160, 240 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2259 | #endif // CONFIG_EXT_PARTITION |
| 2260 | }; |
| 2261 | const int complexity_16x16_blocks_threshold[BLOCK_SIZES] = { |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 2262 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 6, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2263 | #if CONFIG_EXT_PARTITION |
| 2264 | // TODO(debargha): What are the correct numbers here? |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 2265 | 8, 8, 10 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2266 | #endif // CONFIG_EXT_PARTITION |
| 2267 | }; |
| 2268 | |
| 2269 | typedef enum { |
| 2270 | MV_ZERO = 0, |
| 2271 | MV_LEFT = 1, |
| 2272 | MV_UP = 2, |
| 2273 | MV_RIGHT = 3, |
| 2274 | MV_DOWN = 4, |
| 2275 | MV_INVALID |
| 2276 | } MOTION_DIRECTION; |
| 2277 | |
| 2278 | static INLINE MOTION_DIRECTION get_motion_direction_fp(uint8_t fp_byte) { |
| 2279 | if (fp_byte & FPMB_MOTION_ZERO_MASK) { |
| 2280 | return MV_ZERO; |
| 2281 | } else if (fp_byte & FPMB_MOTION_LEFT_MASK) { |
| 2282 | return MV_LEFT; |
| 2283 | } else if (fp_byte & FPMB_MOTION_RIGHT_MASK) { |
| 2284 | return MV_RIGHT; |
| 2285 | } else if (fp_byte & FPMB_MOTION_UP_MASK) { |
| 2286 | return MV_UP; |
| 2287 | } else { |
| 2288 | return MV_DOWN; |
| 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | static INLINE int get_motion_inconsistency(MOTION_DIRECTION this_mv, |
| 2293 | MOTION_DIRECTION that_mv) { |
| 2294 | if (this_mv == that_mv) { |
| 2295 | return 0; |
| 2296 | } else { |
| 2297 | return abs(this_mv - that_mv) == 2 ? 2 : 1; |
| 2298 | } |
| 2299 | } |
| 2300 | #endif |
| 2301 | |
| 2302 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2303 | // Try searching for an encoding for the given subblock. Returns zero if the |
| 2304 | // rdcost is already too high (to tell the caller not to bother searching for |
| 2305 | // encodings of further subblocks) |
| 2306 | static int rd_try_subblock(const AV1_COMP *const cpi, ThreadData *td, |
| 2307 | TileDataEnc *tile_data, TOKENEXTRA **tp, |
| 2308 | int is_first, int is_last, int mi_row, int mi_col, |
| 2309 | BLOCK_SIZE subsize, RD_STATS *best_rdc, |
| 2310 | RD_STATS *sum_rdc, RD_STATS *this_rdc, |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2311 | PARTITION_TYPE partition, |
| 2312 | PICK_MODE_CONTEXT *prev_ctx, |
| 2313 | PICK_MODE_CONTEXT *this_ctx) { |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2314 | #define RTS_X_RATE_NOCOEF_ARG |
| 2315 | #define RTS_MAX_RDCOST best_rdc->rdcost |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2316 | |
| 2317 | MACROBLOCK *const x = &td->mb; |
| 2318 | |
| 2319 | if (cpi->sf.adaptive_motion_search) load_pred_mv(x, prev_ctx); |
| 2320 | |
| 2321 | // On the first time around, write the rd stats straight to sum_rdc. Also, we |
| 2322 | // should treat sum_rdc as containing zeros (even if it doesn't) to avoid |
| 2323 | // having to zero it at the start. |
| 2324 | if (is_first) this_rdc = sum_rdc; |
| 2325 | const int64_t spent_rdcost = is_first ? 0 : sum_rdc->rdcost; |
| 2326 | const int64_t rdcost_remaining = best_rdc->rdcost - spent_rdcost; |
| 2327 | |
| 2328 | rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, this_rdc, |
| 2329 | RTS_X_RATE_NOCOEF_ARG partition, subsize, this_ctx, |
| 2330 | rdcost_remaining); |
| 2331 | |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2332 | if (!is_first) { |
| 2333 | if (this_rdc->rate == INT_MAX) { |
| 2334 | sum_rdc->rdcost = INT64_MAX; |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2335 | } else { |
| 2336 | sum_rdc->rate += this_rdc->rate; |
| 2337 | sum_rdc->dist += this_rdc->dist; |
| 2338 | sum_rdc->rdcost += this_rdc->rdcost; |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | if (sum_rdc->rdcost >= RTS_MAX_RDCOST) return 0; |
| 2343 | |
| 2344 | if (!is_last) { |
| 2345 | update_state(cpi, td, this_ctx, mi_row, mi_col, subsize, 1); |
| 2346 | encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row, mi_col, subsize, |
| 2347 | NULL); |
| 2348 | } |
| 2349 | |
| 2350 | return 1; |
| 2351 | |
| 2352 | #undef RTS_X_RATE_NOCOEF_ARG |
| 2353 | #undef RTS_MAX_RDCOST |
| 2354 | } |
| 2355 | |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 2356 | static void rd_test_partition3(const AV1_COMP *const cpi, ThreadData *td, |
| 2357 | TileDataEnc *tile_data, TOKENEXTRA **tp, |
| 2358 | PC_TREE *pc_tree, RD_STATS *best_rdc, |
| 2359 | PICK_MODE_CONTEXT ctxs[3], |
| 2360 | PICK_MODE_CONTEXT *ctx, int mi_row, int mi_col, |
| 2361 | BLOCK_SIZE bsize, PARTITION_TYPE partition, |
| 2362 | int mi_row0, int mi_col0, BLOCK_SIZE subsize0, |
| 2363 | int mi_row1, int mi_col1, BLOCK_SIZE subsize1, |
| 2364 | int mi_row2, int mi_col2, BLOCK_SIZE subsize2) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2365 | MACROBLOCK *const x = &td->mb; |
| 2366 | MACROBLOCKD *const xd = &x->e_mbd; |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2367 | RD_STATS sum_rdc, this_rdc; |
Debargha Mukherjee | ab8bf50 | 2017-10-05 09:10:39 -0700 | [diff] [blame] | 2368 | #if CONFIG_UNPOISON_PARTITION_CTX |
| 2369 | const AV1_COMMON *const cm = &cpi->common; |
| 2370 | const int hbs = mi_size_wide[bsize] / 2; |
| 2371 | const int has_rows = mi_row + hbs < cm->mi_rows; |
| 2372 | const int has_cols = mi_col + hbs < cm->mi_cols; |
| 2373 | #endif // CONFIG_UNPOISON_PARTITION_CTX |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 2374 | #if CONFIG_EXT_PARTITION_TYPES_AB |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2375 | const AV1_COMMON *const cm = &cpi->common; |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 2376 | #endif |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2377 | #define RTP_STX_TRY_ARGS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2378 | |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2379 | if (!rd_try_subblock(cpi, td, tile_data, tp, 1, 0, mi_row0, mi_col0, subsize0, |
| 2380 | best_rdc, &sum_rdc, &this_rdc, |
| 2381 | RTP_STX_TRY_ARGS partition, ctx, &ctxs[0])) |
| 2382 | return; |
| 2383 | |
| 2384 | if (!rd_try_subblock(cpi, td, tile_data, tp, 0, 0, mi_row1, mi_col1, subsize1, |
| 2385 | best_rdc, &sum_rdc, &this_rdc, |
| 2386 | RTP_STX_TRY_ARGS partition, &ctxs[0], &ctxs[1])) |
| 2387 | return; |
| 2388 | |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 2389 | // With the new layout of mixed partitions for PARTITION_HORZ_B and |
| 2390 | // PARTITION_VERT_B, the last subblock might start past halfway through the |
| 2391 | // main block, so we might signal it even though the subblock lies strictly |
| 2392 | // outside the image. In that case, we won't spend any bits coding it and the |
| 2393 | // difference (obviously) doesn't contribute to the error. |
| 2394 | #if CONFIG_EXT_PARTITION_TYPES_AB |
| 2395 | const int try_block2 = mi_row2 < cm->mi_rows && mi_col2 < cm->mi_cols; |
| 2396 | #else |
| 2397 | const int try_block2 = 1; |
| 2398 | #endif |
| 2399 | if (try_block2 && |
| 2400 | !rd_try_subblock(cpi, td, tile_data, tp, 0, 1, mi_row2, mi_col2, subsize2, |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2401 | best_rdc, &sum_rdc, &this_rdc, |
| 2402 | RTP_STX_TRY_ARGS partition, &ctxs[1], &ctxs[2])) |
| 2403 | return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2404 | |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2405 | if (sum_rdc.rdcost >= best_rdc->rdcost) return; |
| 2406 | |
| 2407 | int pl = partition_plane_context(xd, mi_row, mi_col, |
| 2408 | #if CONFIG_UNPOISON_PARTITION_CTX |
| 2409 | has_rows, has_cols, |
| 2410 | #endif |
| 2411 | bsize); |
| 2412 | sum_rdc.rate += x->partition_cost[pl][partition]; |
| 2413 | sum_rdc.rdcost = RDCOST(x->rdmult, sum_rdc.rate, sum_rdc.dist); |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2414 | |
| 2415 | if (sum_rdc.rdcost >= best_rdc->rdcost) return; |
| 2416 | |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 2417 | *best_rdc = sum_rdc; |
| 2418 | pc_tree->partitioning = partition; |
| 2419 | |
| 2420 | #undef RTP_STX_TRY_ARGS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2421 | } |
| 2422 | #endif // CONFIG_EXT_PARTITION_TYPES |
| 2423 | |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 2424 | #if CONFIG_DIST_8X8 |
Yushin Cho | 8e75e8b | 2017-09-12 16:33:28 -0700 | [diff] [blame] | 2425 | static int64_t dist_8x8_yuv(const AV1_COMP *const cpi, MACROBLOCK *const x, |
| 2426 | uint8_t *y_src_8x8) { |
| 2427 | MACROBLOCKD *const xd = &x->e_mbd; |
| 2428 | int64_t dist_8x8, dist_8x8_uv, total_dist; |
| 2429 | const int src_stride = x->plane[0].src.stride; |
| 2430 | uint8_t *decoded_8x8; |
| 2431 | int plane; |
| 2432 | |
| 2433 | #if CONFIG_HIGHBITDEPTH |
| 2434 | if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) |
| 2435 | decoded_8x8 = CONVERT_TO_BYTEPTR(x->decoded_8x8); |
| 2436 | else |
| 2437 | #endif |
| 2438 | decoded_8x8 = (uint8_t *)x->decoded_8x8; |
| 2439 | |
| 2440 | dist_8x8 = av1_dist_8x8(cpi, x, y_src_8x8, src_stride, decoded_8x8, 8, |
| 2441 | BLOCK_8X8, 8, 8, 8, 8, x->qindex) |
| 2442 | << 4; |
| 2443 | |
| 2444 | // Compute chroma distortion for a luma 8x8 block |
| 2445 | dist_8x8_uv = 0; |
| 2446 | |
| 2447 | for (plane = 1; plane < MAX_MB_PLANE; ++plane) { |
| 2448 | const int src_stride_uv = x->plane[plane].src.stride; |
| 2449 | const int dst_stride_uv = xd->plane[plane].dst.stride; |
| 2450 | // uv buff pointers now (i.e. the last sub8x8 block) is the same |
| 2451 | // to those at the first sub8x8 block because |
| 2452 | // uv buff pointer is set only once at first sub8x8 block in a 8x8. |
| 2453 | uint8_t *src_uv = x->plane[plane].src.buf; |
| 2454 | uint8_t *dst_uv = xd->plane[plane].dst.buf; |
| 2455 | unsigned sse; |
Yushin Cho | 8e75e8b | 2017-09-12 16:33:28 -0700 | [diff] [blame] | 2456 | const BLOCK_SIZE plane_bsize = |
| 2457 | AOMMAX(BLOCK_4X4, get_plane_block_size(BLOCK_8X8, &xd->plane[plane])); |
Yushin Cho | 8e75e8b | 2017-09-12 16:33:28 -0700 | [diff] [blame] | 2458 | cpi->fn_ptr[plane_bsize].vf(src_uv, src_stride_uv, dst_uv, dst_stride_uv, |
| 2459 | &sse); |
| 2460 | dist_8x8_uv += (int64_t)sse << 4; |
| 2461 | } |
| 2462 | |
| 2463 | return total_dist = dist_8x8 + dist_8x8_uv; |
| 2464 | } |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 2465 | #endif // CONFIG_DIST_8X8 |
Yushin Cho | 8e75e8b | 2017-09-12 16:33:28 -0700 | [diff] [blame] | 2466 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2467 | // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are |
| 2468 | // unlikely to be selected depending on previous rate-distortion optimization |
| 2469 | // results, for encoding speed-up. |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2470 | static void rd_pick_partition(const AV1_COMP *const cpi, ThreadData *td, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2471 | TileDataEnc *tile_data, TOKENEXTRA **tp, |
| 2472 | int mi_row, int mi_col, BLOCK_SIZE bsize, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 2473 | RD_STATS *rd_cost, int64_t best_rd, |
| 2474 | PC_TREE *pc_tree) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2475 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2476 | TileInfo *const tile_info = &tile_data->tile_info; |
| 2477 | MACROBLOCK *const x = &td->mb; |
| 2478 | MACROBLOCKD *const xd = &x->e_mbd; |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 2479 | const int mi_step = mi_size_wide[bsize] / 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2480 | RD_SEARCH_MACROBLOCK_CONTEXT x_ctx; |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2481 | const TOKENEXTRA *const tp_orig = *tp; |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 2482 | PICK_MODE_CONTEXT *ctx_none = &pc_tree->none; |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 2483 | #if CONFIG_UNPOISON_PARTITION_CTX |
| 2484 | const int hbs = mi_size_wide[bsize] / 2; |
| 2485 | const int has_rows = mi_row + hbs < cm->mi_rows; |
| 2486 | const int has_cols = mi_col + hbs < cm->mi_cols; |
| 2487 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2488 | int tmp_partition_cost[PARTITION_TYPES]; |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 2489 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2490 | BLOCK_SIZE subsize; |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 2491 | RD_STATS this_rdc, sum_rdc, best_rdc; |
Jingning Han | bf9c6b7 | 2016-12-14 14:50:45 -0800 | [diff] [blame] | 2492 | const int bsize_at_least_8x8 = (bsize >= BLOCK_8X8); |
| 2493 | int do_square_split = bsize_at_least_8x8; |
Jingning Han | bf9c6b7 | 2016-12-14 14:50:45 -0800 | [diff] [blame] | 2494 | const int pl = bsize_at_least_8x8 |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 2495 | ? partition_plane_context(xd, mi_row, mi_col, |
| 2496 | #if CONFIG_UNPOISON_PARTITION_CTX |
| 2497 | has_rows, has_cols, |
| 2498 | #endif |
| 2499 | bsize) |
Yaowu Xu | 281def7 | 2017-04-12 08:26:55 -0700 | [diff] [blame] | 2500 | : 0; |
Yaowu Xu | ba9dd8a | 2017-09-07 17:50:49 -0700 | [diff] [blame] | 2501 | const int *partition_cost = |
| 2502 | pl >= 0 ? x->partition_cost[pl] : x->partition_cost[0]; |
Jingning Han | bf9c6b7 | 2016-12-14 14:50:45 -0800 | [diff] [blame] | 2503 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2504 | int do_rectangular_split = 1; |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 2505 | #if CONFIG_EXT_PARTITION_TYPES && !CONFIG_EXT_PARTITION_TYPES_AB |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2506 | BLOCK_SIZE bsize2 = get_subsize(bsize, PARTITION_SPLIT); |
| 2507 | #endif |
| 2508 | |
| 2509 | // Override skipping rectangular partition operations for edge blocks |
| 2510 | const int force_horz_split = (mi_row + mi_step >= cm->mi_rows); |
| 2511 | const int force_vert_split = (mi_col + mi_step >= cm->mi_cols); |
| 2512 | const int xss = x->e_mbd.plane[1].subsampling_x; |
| 2513 | const int yss = x->e_mbd.plane[1].subsampling_y; |
| 2514 | |
| 2515 | BLOCK_SIZE min_size = x->min_partition_size; |
| 2516 | BLOCK_SIZE max_size = x->max_partition_size; |
| 2517 | |
| 2518 | #if CONFIG_FP_MB_STATS |
| 2519 | unsigned int src_diff_var = UINT_MAX; |
| 2520 | int none_complexity = 0; |
| 2521 | #endif |
| 2522 | |
| 2523 | int partition_none_allowed = !force_horz_split && !force_vert_split; |
| 2524 | int partition_horz_allowed = |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2525 | !force_vert_split && yss <= xss && bsize_at_least_8x8; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2526 | int partition_vert_allowed = |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2527 | !force_horz_split && xss <= yss && bsize_at_least_8x8; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 2528 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2529 | (void)*tp_orig; |
| 2530 | |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 2531 | #if !CONFIG_UNPOISON_PARTITION_CTX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2532 | if (force_horz_split || force_vert_split) { |
| 2533 | tmp_partition_cost[PARTITION_NONE] = INT_MAX; |
| 2534 | |
| 2535 | if (!force_vert_split) { // force_horz_split only |
| 2536 | tmp_partition_cost[PARTITION_VERT] = INT_MAX; |
| 2537 | tmp_partition_cost[PARTITION_HORZ] = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2538 | av1_cost_bit(cm->fc->partition_prob[pl][PARTITION_HORZ], 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2539 | tmp_partition_cost[PARTITION_SPLIT] = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2540 | av1_cost_bit(cm->fc->partition_prob[pl][PARTITION_HORZ], 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2541 | } else if (!force_horz_split) { // force_vert_split only |
| 2542 | tmp_partition_cost[PARTITION_HORZ] = INT_MAX; |
| 2543 | tmp_partition_cost[PARTITION_VERT] = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2544 | av1_cost_bit(cm->fc->partition_prob[pl][PARTITION_VERT], 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2545 | tmp_partition_cost[PARTITION_SPLIT] = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2546 | av1_cost_bit(cm->fc->partition_prob[pl][PARTITION_VERT], 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2547 | } else { // force_ horz_split && force_vert_split horz_split |
| 2548 | tmp_partition_cost[PARTITION_HORZ] = INT_MAX; |
| 2549 | tmp_partition_cost[PARTITION_VERT] = INT_MAX; |
| 2550 | tmp_partition_cost[PARTITION_SPLIT] = 0; |
| 2551 | } |
| 2552 | |
| 2553 | partition_cost = tmp_partition_cost; |
| 2554 | } |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 2555 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2556 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2557 | #ifndef NDEBUG |
| 2558 | // Nothing should rely on the default value of this array (which is just |
| 2559 | // leftover from encoding the previous block. Setting it to magic number |
| 2560 | // when debugging. |
| 2561 | memset(x->blk_skip[0], 234, sizeof(x->blk_skip[0])); |
| 2562 | #endif // NDEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2563 | |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 2564 | assert(mi_size_wide[bsize] == mi_size_high[bsize]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2565 | |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 2566 | av1_init_rd_stats(&this_rdc); |
| 2567 | av1_init_rd_stats(&sum_rdc); |
| 2568 | av1_invalid_rd_stats(&best_rdc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2569 | best_rdc.rdcost = best_rd; |
| 2570 | |
| 2571 | set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); |
| 2572 | |
| 2573 | if (bsize == BLOCK_16X16 && cpi->vaq_refresh) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2574 | x->mb_energy = av1_block_energy(cpi, x, bsize); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2575 | |
| 2576 | if (cpi->sf.cb_partition_search && bsize == BLOCK_16X16) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2577 | const int cb_partition_search_ctrl = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2578 | ((pc_tree->index == 0 || pc_tree->index == 3) + |
| 2579 | get_chessboard_index(cm->current_video_frame)) & |
| 2580 | 0x1; |
| 2581 | |
| 2582 | if (cb_partition_search_ctrl && bsize > min_size && bsize < max_size) |
| 2583 | set_partition_range(cm, xd, mi_row, mi_col, bsize, &min_size, &max_size); |
| 2584 | } |
| 2585 | |
| 2586 | // Determine partition types in search according to the speed features. |
| 2587 | // The threshold set here has to be of square block size. |
| 2588 | if (cpi->sf.auto_min_max_partition_size) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2589 | const int no_partition_allowed = (bsize <= max_size && bsize >= min_size); |
| 2590 | // Note: Further partitioning is NOT allowed when bsize == min_size already. |
| 2591 | const int partition_allowed = (bsize <= max_size && bsize > min_size); |
| 2592 | partition_none_allowed &= no_partition_allowed; |
| 2593 | partition_horz_allowed &= partition_allowed || force_horz_split; |
| 2594 | partition_vert_allowed &= partition_allowed || force_vert_split; |
| 2595 | do_square_split &= bsize > min_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2596 | } |
| 2597 | if (cpi->sf.use_square_partition_only) { |
| 2598 | partition_horz_allowed &= force_horz_split; |
| 2599 | partition_vert_allowed &= force_vert_split; |
| 2600 | } |
| 2601 | |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 2602 | xd->above_txfm_context = |
| 2603 | cm->above_txfm_context + (mi_col << TX_UNIT_WIDE_LOG2); |
| 2604 | xd->left_txfm_context = xd->left_txfm_context_buffer + |
| 2605 | ((mi_row & MAX_MIB_MASK) << TX_UNIT_HIGH_LOG2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2606 | save_context(x, &x_ctx, mi_row, mi_col, bsize); |
| 2607 | |
| 2608 | #if CONFIG_FP_MB_STATS |
| 2609 | if (cpi->use_fp_mb_stats) { |
| 2610 | set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); |
| 2611 | src_diff_var = get_sby_perpixel_diff_variance(cpi, &x->plane[0].src, mi_row, |
| 2612 | mi_col, bsize); |
| 2613 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2614 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2615 | // Decide whether we shall split directly and skip searching NONE by using |
| 2616 | // the first pass block statistics |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2617 | if (cpi->use_fp_mb_stats && bsize >= BLOCK_32X32 && do_square_split && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2618 | partition_none_allowed && src_diff_var > 4 && |
| 2619 | cm->base_qindex < qindex_split_threshold_lookup[bsize]) { |
| 2620 | int mb_row = mi_row >> 1; |
| 2621 | int mb_col = mi_col >> 1; |
| 2622 | int mb_row_end = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2623 | AOMMIN(mb_row + num_16x16_blocks_high_lookup[bsize], cm->mb_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2624 | int mb_col_end = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2625 | AOMMIN(mb_col + num_16x16_blocks_wide_lookup[bsize], cm->mb_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2626 | int r, c; |
| 2627 | |
| 2628 | // compute a complexity measure, basically measure inconsistency of motion |
| 2629 | // vectors obtained from the first pass in the current block |
| 2630 | for (r = mb_row; r < mb_row_end; r++) { |
| 2631 | for (c = mb_col; c < mb_col_end; c++) { |
| 2632 | const int mb_index = r * cm->mb_cols + c; |
| 2633 | |
| 2634 | MOTION_DIRECTION this_mv; |
| 2635 | MOTION_DIRECTION right_mv; |
| 2636 | MOTION_DIRECTION bottom_mv; |
| 2637 | |
| 2638 | this_mv = |
| 2639 | get_motion_direction_fp(cpi->twopass.this_frame_mb_stats[mb_index]); |
| 2640 | |
| 2641 | // to its right |
| 2642 | if (c != mb_col_end - 1) { |
| 2643 | right_mv = get_motion_direction_fp( |
| 2644 | cpi->twopass.this_frame_mb_stats[mb_index + 1]); |
| 2645 | none_complexity += get_motion_inconsistency(this_mv, right_mv); |
| 2646 | } |
| 2647 | |
| 2648 | // to its bottom |
| 2649 | if (r != mb_row_end - 1) { |
| 2650 | bottom_mv = get_motion_direction_fp( |
| 2651 | cpi->twopass.this_frame_mb_stats[mb_index + cm->mb_cols]); |
| 2652 | none_complexity += get_motion_inconsistency(this_mv, bottom_mv); |
| 2653 | } |
| 2654 | |
| 2655 | // do not count its left and top neighbors to avoid double counting |
| 2656 | } |
| 2657 | } |
| 2658 | |
| 2659 | if (none_complexity > complexity_16x16_blocks_threshold[bsize]) { |
| 2660 | partition_none_allowed = 0; |
| 2661 | } |
| 2662 | } |
| 2663 | #endif |
| 2664 | |
| 2665 | // PARTITION_NONE |
| 2666 | if (partition_none_allowed) { |
| 2667 | rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &this_rdc, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2668 | #if CONFIG_EXT_PARTITION_TYPES |
| 2669 | PARTITION_NONE, |
| 2670 | #endif |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 2671 | bsize, ctx_none, best_rdc.rdcost); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2672 | if (this_rdc.rate != INT_MAX) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2673 | if (bsize_at_least_8x8) { |
Yaowu Xu | 897dd19 | 2017-08-02 18:41:56 -0700 | [diff] [blame] | 2674 | const int pt_cost = partition_cost[PARTITION_NONE] < INT_MAX |
| 2675 | ? partition_cost[PARTITION_NONE] |
| 2676 | : 0; |
| 2677 | this_rdc.rate += pt_cost; |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 2678 | this_rdc.rdcost = RDCOST(x->rdmult, this_rdc.rate, this_rdc.dist); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | if (this_rdc.rdcost < best_rdc.rdcost) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2682 | // Adjust dist breakout threshold according to the partition size. |
| 2683 | const int64_t dist_breakout_thr = |
| 2684 | cpi->sf.partition_search_breakout_dist_thr >> |
| 2685 | ((2 * (MAX_SB_SIZE_LOG2 - 2)) - |
| 2686 | (b_width_log2_lookup[bsize] + b_height_log2_lookup[bsize])); |
| 2687 | const int rate_breakout_thr = |
| 2688 | cpi->sf.partition_search_breakout_rate_thr * |
| 2689 | num_pels_log2_lookup[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2690 | |
| 2691 | best_rdc = this_rdc; |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2692 | if (bsize_at_least_8x8) pc_tree->partitioning = PARTITION_NONE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2693 | |
| 2694 | // If all y, u, v transform blocks in this partition are skippable, and |
| 2695 | // the dist & rate are within the thresholds, the partition search is |
| 2696 | // terminated for current branch of the partition search tree. |
| 2697 | // The dist & rate thresholds are set to 0 at speed 0 to disable the |
| 2698 | // early termination at that speed. |
| 2699 | if (!x->e_mbd.lossless[xd->mi[0]->mbmi.segment_id] && |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 2700 | (ctx_none->skippable && best_rdc.dist < dist_breakout_thr && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2701 | best_rdc.rate < rate_breakout_thr)) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2702 | do_square_split = 0; |
| 2703 | do_rectangular_split = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | #if CONFIG_FP_MB_STATS |
| 2707 | // Check if every 16x16 first pass block statistics has zero |
| 2708 | // motion and the corresponding first pass residue is small enough. |
| 2709 | // If that is the case, check the difference variance between the |
| 2710 | // current frame and the last frame. If the variance is small enough, |
| 2711 | // stop further splitting in RD optimization |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2712 | if (cpi->use_fp_mb_stats && do_square_split && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2713 | cm->base_qindex > qindex_skip_threshold_lookup[bsize]) { |
| 2714 | int mb_row = mi_row >> 1; |
| 2715 | int mb_col = mi_col >> 1; |
| 2716 | int mb_row_end = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2717 | AOMMIN(mb_row + num_16x16_blocks_high_lookup[bsize], cm->mb_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2718 | int mb_col_end = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2719 | AOMMIN(mb_col + num_16x16_blocks_wide_lookup[bsize], cm->mb_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2720 | int r, c; |
| 2721 | |
| 2722 | int skip = 1; |
| 2723 | for (r = mb_row; r < mb_row_end; r++) { |
| 2724 | for (c = mb_col; c < mb_col_end; c++) { |
| 2725 | const int mb_index = r * cm->mb_cols + c; |
| 2726 | if (!(cpi->twopass.this_frame_mb_stats[mb_index] & |
| 2727 | FPMB_MOTION_ZERO_MASK) || |
| 2728 | !(cpi->twopass.this_frame_mb_stats[mb_index] & |
| 2729 | FPMB_ERROR_SMALL_MASK)) { |
| 2730 | skip = 0; |
| 2731 | break; |
| 2732 | } |
| 2733 | } |
| 2734 | if (skip == 0) { |
| 2735 | break; |
| 2736 | } |
| 2737 | } |
| 2738 | if (skip) { |
| 2739 | if (src_diff_var == UINT_MAX) { |
| 2740 | set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); |
| 2741 | src_diff_var = get_sby_perpixel_diff_variance( |
| 2742 | cpi, &x->plane[0].src, mi_row, mi_col, bsize); |
| 2743 | } |
| 2744 | if (src_diff_var < 8) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2745 | do_square_split = 0; |
| 2746 | do_rectangular_split = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2747 | } |
| 2748 | } |
| 2749 | } |
| 2750 | #endif |
| 2751 | } |
| 2752 | } |
Yushin Cho | d0b77ac | 2017-10-20 17:33:16 -0700 | [diff] [blame] | 2753 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2754 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
| 2755 | } |
| 2756 | |
| 2757 | // store estimated motion vector |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 2758 | if (cpi->sf.adaptive_motion_search) store_pred_mv(x, ctx_none); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2759 | |
Yaowu Xu | 049a788 | 2017-09-07 08:55:54 -0700 | [diff] [blame] | 2760 | int64_t temp_best_rdcost = best_rdc.rdcost; |
Yaowu Xu | 049a788 | 2017-09-07 08:55:54 -0700 | [diff] [blame] | 2761 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2762 | // PARTITION_SPLIT |
| 2763 | // TODO(jingning): use the motion vectors given by the above search as |
| 2764 | // the starting point of motion search in the following partition type check. |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2765 | if (do_square_split) { |
| 2766 | int reached_last_index = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2767 | subsize = get_subsize(bsize, PARTITION_SPLIT); |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 2768 | int idx; |
| 2769 | for (idx = 0; idx < 4 && sum_rdc.rdcost < temp_best_rdcost; ++idx) { |
| 2770 | const int x_idx = (idx & 1) * mi_step; |
| 2771 | const int y_idx = (idx >> 1) * mi_step; |
Yaowu Xu | 049a788 | 2017-09-07 08:55:54 -0700 | [diff] [blame] | 2772 | |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 2773 | if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) |
| 2774 | continue; |
| 2775 | |
| 2776 | if (cpi->sf.adaptive_motion_search) load_pred_mv(x, ctx_none); |
| 2777 | |
| 2778 | pc_tree->split[idx]->index = idx; |
| 2779 | rd_pick_partition(cpi, td, tile_data, tp, mi_row + y_idx, mi_col + x_idx, |
| 2780 | subsize, &this_rdc, temp_best_rdcost - sum_rdc.rdcost, |
| 2781 | pc_tree->split[idx]); |
| 2782 | |
| 2783 | if (this_rdc.rate == INT_MAX) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2784 | sum_rdc.rdcost = INT64_MAX; |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 2785 | break; |
| 2786 | } else { |
| 2787 | sum_rdc.rate += this_rdc.rate; |
| 2788 | sum_rdc.dist += this_rdc.dist; |
| 2789 | sum_rdc.rdcost += this_rdc.rdcost; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2790 | } |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 2791 | } |
| 2792 | reached_last_index = (idx == 4); |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 2793 | |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 2794 | #if CONFIG_DIST_8X8 |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 2795 | if (x->using_dist_8x8 && reached_last_index && |
| 2796 | sum_rdc.rdcost != INT64_MAX && bsize == BLOCK_8X8) { |
| 2797 | const int src_stride = x->plane[0].src.stride; |
| 2798 | int64_t dist_8x8; |
| 2799 | dist_8x8 = dist_8x8_yuv(cpi, x, x->plane[0].src.buf - 4 * src_stride - 4); |
| 2800 | if (x->tune_metric == AOM_TUNE_PSNR) assert(sum_rdc.dist == dist_8x8); |
| 2801 | sum_rdc.dist = dist_8x8; |
| 2802 | sum_rdc.rdcost = RDCOST(x->rdmult, sum_rdc.rate, sum_rdc.dist); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2803 | } |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 2804 | #endif // CONFIG_DIST_8X8 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2805 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2806 | if (reached_last_index && sum_rdc.rdcost < best_rdc.rdcost) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2807 | sum_rdc.rate += partition_cost[PARTITION_SPLIT]; |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 2808 | sum_rdc.rdcost = RDCOST(x->rdmult, sum_rdc.rate, sum_rdc.dist); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2809 | |
| 2810 | if (sum_rdc.rdcost < best_rdc.rdcost) { |
| 2811 | best_rdc = sum_rdc; |
Yaowu Xu | 049a788 | 2017-09-07 08:55:54 -0700 | [diff] [blame] | 2812 | temp_best_rdcost = best_rdc.rdcost; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2813 | pc_tree->partitioning = PARTITION_SPLIT; |
| 2814 | } |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2815 | } else if (cpi->sf.less_rectangular_check) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2816 | // skip rectangular partition test when larger block size |
| 2817 | // gives better rd cost |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2818 | do_rectangular_split &= !partition_none_allowed; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2819 | } |
Yushin Cho | d0b77ac | 2017-10-20 17:33:16 -0700 | [diff] [blame] | 2820 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2821 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
| 2822 | } // if (do_split) |
| 2823 | |
| 2824 | // PARTITION_HORZ |
| 2825 | if (partition_horz_allowed && |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2826 | (do_rectangular_split || av1_active_h_edge(cpi, mi_row, mi_step))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2827 | subsize = get_subsize(bsize, PARTITION_HORZ); |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 2828 | if (cpi->sf.adaptive_motion_search) load_pred_mv(x, ctx_none); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2829 | if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && |
| 2830 | partition_none_allowed) |
| 2831 | pc_tree->horizontal[0].pred_interp_filter = |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 2832 | av1_extract_interp_filter(ctx_none->mic.mbmi.interp_filters, 0); |
| 2833 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2834 | rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2835 | #if CONFIG_EXT_PARTITION_TYPES |
| 2836 | PARTITION_HORZ, |
| 2837 | #endif |
| 2838 | subsize, &pc_tree->horizontal[0], best_rdc.rdcost); |
| 2839 | |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 2840 | if (sum_rdc.rdcost < temp_best_rdcost && !force_horz_split) { |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 2841 | PICK_MODE_CONTEXT *ctx_h = &pc_tree->horizontal[0]; |
| 2842 | update_state(cpi, td, ctx_h, mi_row, mi_col, subsize, 1); |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 2843 | encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row, mi_col, subsize, |
Yushin Cho | 6d72a2f | 2017-05-03 17:37:37 -0700 | [diff] [blame] | 2844 | NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2845 | |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 2846 | if (cpi->sf.adaptive_motion_search) load_pred_mv(x, ctx_h); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2847 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2848 | if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && |
| 2849 | partition_none_allowed) |
| 2850 | pc_tree->horizontal[1].pred_interp_filter = |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 2851 | av1_extract_interp_filter(ctx_h->mic.mbmi.interp_filters, 0); |
| 2852 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2853 | rd_pick_sb_modes(cpi, tile_data, x, mi_row + mi_step, mi_col, &this_rdc, |
| 2854 | #if CONFIG_EXT_PARTITION_TYPES |
| 2855 | PARTITION_HORZ, |
| 2856 | #endif |
| 2857 | subsize, &pc_tree->horizontal[1], |
| 2858 | best_rdc.rdcost - sum_rdc.rdcost); |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 2859 | |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 2860 | #if CONFIG_DIST_8X8 |
Yushin Cho | 5510433 | 2017-08-14 16:15:43 -0700 | [diff] [blame] | 2861 | if (x->using_dist_8x8 && this_rdc.rate != INT_MAX && bsize == BLOCK_8X8) { |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 2862 | update_state(cpi, td, &pc_tree->horizontal[1], mi_row + mi_step, mi_col, |
| 2863 | subsize, DRY_RUN_NORMAL); |
| 2864 | encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row + mi_step, mi_col, |
| 2865 | subsize, NULL); |
| 2866 | } |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 2867 | #endif // CONFIG_DIST_8X8 |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 2868 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2869 | if (this_rdc.rate == INT_MAX) { |
| 2870 | sum_rdc.rdcost = INT64_MAX; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2871 | } else { |
| 2872 | sum_rdc.rate += this_rdc.rate; |
| 2873 | sum_rdc.dist += this_rdc.dist; |
| 2874 | sum_rdc.rdcost += this_rdc.rdcost; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2875 | } |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 2876 | #if CONFIG_DIST_8X8 |
Yushin Cho | 5510433 | 2017-08-14 16:15:43 -0700 | [diff] [blame] | 2877 | if (x->using_dist_8x8 && sum_rdc.rdcost != INT64_MAX && |
| 2878 | bsize == BLOCK_8X8) { |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 2879 | const int src_stride = x->plane[0].src.stride; |
Yushin Cho | 8e75e8b | 2017-09-12 16:33:28 -0700 | [diff] [blame] | 2880 | int64_t dist_8x8; |
| 2881 | dist_8x8 = dist_8x8_yuv(cpi, x, x->plane[0].src.buf - 4 * src_stride); |
Yushin Cho | 1cd3462 | 2017-10-06 13:00:41 -0700 | [diff] [blame] | 2882 | if (x->tune_metric == AOM_TUNE_PSNR) assert(sum_rdc.dist == dist_8x8); |
Yushin Cho | 8e75e8b | 2017-09-12 16:33:28 -0700 | [diff] [blame] | 2883 | sum_rdc.dist = dist_8x8; |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 2884 | sum_rdc.rdcost = RDCOST(x->rdmult, sum_rdc.rate, sum_rdc.dist); |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 2885 | } |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 2886 | #endif // CONFIG_DIST_8X8 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2887 | } |
| 2888 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2889 | if (sum_rdc.rdcost < best_rdc.rdcost) { |
| 2890 | sum_rdc.rate += partition_cost[PARTITION_HORZ]; |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 2891 | sum_rdc.rdcost = RDCOST(x->rdmult, sum_rdc.rate, sum_rdc.dist); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2892 | if (sum_rdc.rdcost < best_rdc.rdcost) { |
| 2893 | best_rdc = sum_rdc; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2894 | pc_tree->partitioning = PARTITION_HORZ; |
| 2895 | } |
| 2896 | } |
Yushin Cho | d0b77ac | 2017-10-20 17:33:16 -0700 | [diff] [blame] | 2897 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2898 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
| 2899 | } |
| 2900 | |
| 2901 | // PARTITION_VERT |
| 2902 | if (partition_vert_allowed && |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 2903 | (do_rectangular_split || av1_active_v_edge(cpi, mi_col, mi_step))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2904 | subsize = get_subsize(bsize, PARTITION_VERT); |
| 2905 | |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 2906 | if (cpi->sf.adaptive_motion_search) load_pred_mv(x, ctx_none); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2907 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2908 | if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && |
| 2909 | partition_none_allowed) |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 2910 | pc_tree->vertical[0].pred_interp_filter = |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 2911 | av1_extract_interp_filter(ctx_none->mic.mbmi.interp_filters, 0); |
| 2912 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2913 | rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2914 | #if CONFIG_EXT_PARTITION_TYPES |
| 2915 | PARTITION_VERT, |
| 2916 | #endif |
| 2917 | subsize, &pc_tree->vertical[0], best_rdc.rdcost); |
Rupert Swarbrick | 0a2299b | 2017-10-03 17:57:42 +0100 | [diff] [blame] | 2918 | const int64_t vert_max_rdcost = best_rdc.rdcost; |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 2919 | if (sum_rdc.rdcost < vert_max_rdcost && !force_vert_split) { |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 2920 | update_state(cpi, td, &pc_tree->vertical[0], mi_row, mi_col, subsize, 1); |
| 2921 | encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row, mi_col, subsize, |
Yushin Cho | 6d72a2f | 2017-05-03 17:37:37 -0700 | [diff] [blame] | 2922 | NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2923 | |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 2924 | if (cpi->sf.adaptive_motion_search) load_pred_mv(x, ctx_none); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2925 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2926 | if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && |
| 2927 | partition_none_allowed) |
| 2928 | pc_tree->vertical[1].pred_interp_filter = |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 2929 | av1_extract_interp_filter(ctx_none->mic.mbmi.interp_filters, 0); |
| 2930 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2931 | rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + mi_step, &this_rdc, |
| 2932 | #if CONFIG_EXT_PARTITION_TYPES |
| 2933 | PARTITION_VERT, |
| 2934 | #endif |
| 2935 | subsize, &pc_tree->vertical[1], |
| 2936 | best_rdc.rdcost - sum_rdc.rdcost); |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 2937 | |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 2938 | #if CONFIG_DIST_8X8 |
Yushin Cho | 5510433 | 2017-08-14 16:15:43 -0700 | [diff] [blame] | 2939 | if (x->using_dist_8x8 && this_rdc.rate != INT_MAX && bsize == BLOCK_8X8) { |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 2940 | update_state(cpi, td, &pc_tree->vertical[1], mi_row, mi_col + mi_step, |
| 2941 | subsize, DRY_RUN_NORMAL); |
| 2942 | encode_superblock(cpi, td, tp, DRY_RUN_NORMAL, mi_row, mi_col + mi_step, |
| 2943 | subsize, NULL); |
| 2944 | } |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 2945 | #endif // CONFIG_DIST_8X8 |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 2946 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2947 | if (this_rdc.rate == INT_MAX) { |
| 2948 | sum_rdc.rdcost = INT64_MAX; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2949 | } else { |
| 2950 | sum_rdc.rate += this_rdc.rate; |
| 2951 | sum_rdc.dist += this_rdc.dist; |
| 2952 | sum_rdc.rdcost += this_rdc.rdcost; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2953 | } |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 2954 | #if CONFIG_DIST_8X8 |
Yushin Cho | 5510433 | 2017-08-14 16:15:43 -0700 | [diff] [blame] | 2955 | if (x->using_dist_8x8 && sum_rdc.rdcost != INT64_MAX && |
| 2956 | bsize == BLOCK_8X8) { |
Yushin Cho | b7b60c5 | 2017-07-14 16:18:52 -0700 | [diff] [blame] | 2957 | int64_t dist_8x8; |
Yushin Cho | 8e75e8b | 2017-09-12 16:33:28 -0700 | [diff] [blame] | 2958 | dist_8x8 = dist_8x8_yuv(cpi, x, x->plane[0].src.buf - 4); |
Yushin Cho | 1cd3462 | 2017-10-06 13:00:41 -0700 | [diff] [blame] | 2959 | if (x->tune_metric == AOM_TUNE_PSNR) assert(sum_rdc.dist == dist_8x8); |
Yushin Cho | 8e75e8b | 2017-09-12 16:33:28 -0700 | [diff] [blame] | 2960 | sum_rdc.dist = dist_8x8; |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 2961 | sum_rdc.rdcost = RDCOST(x->rdmult, sum_rdc.rate, sum_rdc.dist); |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 2962 | } |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 2963 | #endif // CONFIG_DIST_8X8 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2964 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2965 | |
| 2966 | if (sum_rdc.rdcost < best_rdc.rdcost) { |
| 2967 | sum_rdc.rate += partition_cost[PARTITION_VERT]; |
Urvang Joshi | 70006e4 | 2017-06-14 16:08:55 -0700 | [diff] [blame] | 2968 | sum_rdc.rdcost = RDCOST(x->rdmult, sum_rdc.rate, sum_rdc.dist); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2969 | if (sum_rdc.rdcost < best_rdc.rdcost) { |
| 2970 | best_rdc = sum_rdc; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2971 | pc_tree->partitioning = PARTITION_VERT; |
| 2972 | } |
| 2973 | } |
Yushin Cho | d0b77ac | 2017-10-20 17:33:16 -0700 | [diff] [blame] | 2974 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2975 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
| 2976 | } |
| 2977 | |
| 2978 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 2979 | const int ext_partition_allowed = |
| 2980 | do_rectangular_split && bsize > BLOCK_8X8 && partition_none_allowed; |
| 2981 | |
Rupert Swarbrick | fc2ac95 | 2017-10-11 13:05:31 +0100 | [diff] [blame] | 2982 | // horz4_partition_allowed and vert4_partition_allowed encode the requirement |
| 2983 | // that we don't choose a block size that wouldn't be allowed by this |
| 2984 | // subsampling (stored in the xss and yss variables). |
| 2985 | // |
| 2986 | // We definitely can't allow (say) a 16x4 block if yss > xss because it would |
| 2987 | // subsample to 16x2, which doesn't have an enum. Also, there's no BLOCK_8X2 |
| 2988 | // or BLOCK_2X8, so we can't do 4:1 or 1:4 partitions for BLOCK_16X16 if there |
| 2989 | // is any subsampling. |
Debargha Mukherjee | ab68ddb | 2017-10-19 21:16:54 -0700 | [diff] [blame] | 2990 | const int horz4_partition_allowed = |
| 2991 | ext_partition_allowed && partition_horz_allowed; |
| 2992 | const int vert4_partition_allowed = |
| 2993 | ext_partition_allowed && partition_vert_allowed; |
Rupert Swarbrick | fc2ac95 | 2017-10-11 13:05:31 +0100 | [diff] [blame] | 2994 | |
| 2995 | #if CONFIG_EXT_PARTITION_TYPES_AB |
| 2996 | // The alternative AB partitions are allowed iff the corresponding 4:1 |
| 2997 | // partitions are allowed. |
| 2998 | const int horzab_partition_allowed = horz4_partition_allowed; |
| 2999 | const int vertab_partition_allowed = vert4_partition_allowed; |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3000 | #else |
Rupert Swarbrick | fc2ac95 | 2017-10-11 13:05:31 +0100 | [diff] [blame] | 3001 | // The standard AB partitions are allowed whenever ext-partition-types are |
| 3002 | // allowed |
| 3003 | const int horzab_partition_allowed = ext_partition_allowed; |
| 3004 | const int vertab_partition_allowed = ext_partition_allowed; |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3005 | #endif |
| 3006 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3007 | // PARTITION_HORZ_A |
Rupert Swarbrick | fc2ac95 | 2017-10-11 13:05:31 +0100 | [diff] [blame] | 3008 | if (partition_horz_allowed && horzab_partition_allowed) { |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3009 | #if CONFIG_EXT_PARTITION_TYPES_AB |
| 3010 | rd_test_partition3( |
| 3011 | cpi, td, tile_data, tp, pc_tree, &best_rdc, pc_tree->horizontala, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 3012 | ctx_none, mi_row, mi_col, bsize, PARTITION_HORZ_A, mi_row, mi_col, |
| 3013 | get_subsize(bsize, PARTITION_HORZ_4), mi_row + mi_step / 2, mi_col, |
| 3014 | get_subsize(bsize, PARTITION_HORZ_4), mi_row + mi_step, mi_col, |
| 3015 | get_subsize(bsize, PARTITION_HORZ)); |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3016 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3017 | subsize = get_subsize(bsize, PARTITION_HORZ_A); |
| 3018 | rd_test_partition3(cpi, td, tile_data, tp, pc_tree, &best_rdc, |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 3019 | pc_tree->horizontala, ctx_none, mi_row, mi_col, bsize, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 3020 | PARTITION_HORZ_A, mi_row, mi_col, bsize2, mi_row, |
| 3021 | mi_col + mi_step, bsize2, mi_row + mi_step, mi_col, |
| 3022 | subsize); |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3023 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3024 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
| 3025 | } |
| 3026 | // PARTITION_HORZ_B |
Rupert Swarbrick | fc2ac95 | 2017-10-11 13:05:31 +0100 | [diff] [blame] | 3027 | if (partition_horz_allowed && horzab_partition_allowed) { |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3028 | #if CONFIG_EXT_PARTITION_TYPES_AB |
| 3029 | rd_test_partition3( |
| 3030 | cpi, td, tile_data, tp, pc_tree, &best_rdc, pc_tree->horizontalb, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 3031 | ctx_none, mi_row, mi_col, bsize, PARTITION_HORZ_B, mi_row, mi_col, |
| 3032 | get_subsize(bsize, PARTITION_HORZ), mi_row + mi_step, mi_col, |
| 3033 | get_subsize(bsize, PARTITION_HORZ_4), mi_row + 3 * mi_step / 2, mi_col, |
| 3034 | get_subsize(bsize, PARTITION_HORZ_4)); |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3035 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3036 | subsize = get_subsize(bsize, PARTITION_HORZ_B); |
| 3037 | rd_test_partition3(cpi, td, tile_data, tp, pc_tree, &best_rdc, |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 3038 | pc_tree->horizontalb, ctx_none, mi_row, mi_col, bsize, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 3039 | PARTITION_HORZ_B, mi_row, mi_col, subsize, |
| 3040 | mi_row + mi_step, mi_col, bsize2, mi_row + mi_step, |
| 3041 | mi_col + mi_step, bsize2); |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3042 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3043 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
| 3044 | } |
| 3045 | // PARTITION_VERT_A |
Rupert Swarbrick | fc2ac95 | 2017-10-11 13:05:31 +0100 | [diff] [blame] | 3046 | if (partition_vert_allowed && vertab_partition_allowed) { |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3047 | #if CONFIG_EXT_PARTITION_TYPES_AB |
| 3048 | rd_test_partition3( |
| 3049 | cpi, td, tile_data, tp, pc_tree, &best_rdc, pc_tree->verticala, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 3050 | ctx_none, mi_row, mi_col, bsize, PARTITION_VERT_A, mi_row, mi_col, |
| 3051 | get_subsize(bsize, PARTITION_VERT_4), mi_row, mi_col + mi_step / 2, |
| 3052 | get_subsize(bsize, PARTITION_VERT_4), mi_row, mi_col + mi_step, |
| 3053 | get_subsize(bsize, PARTITION_VERT)); |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3054 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3055 | subsize = get_subsize(bsize, PARTITION_VERT_A); |
| 3056 | rd_test_partition3(cpi, td, tile_data, tp, pc_tree, &best_rdc, |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 3057 | pc_tree->verticala, ctx_none, mi_row, mi_col, bsize, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 3058 | PARTITION_VERT_A, mi_row, mi_col, bsize2, |
| 3059 | mi_row + mi_step, mi_col, bsize2, mi_row, |
| 3060 | mi_col + mi_step, subsize); |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3061 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3062 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
| 3063 | } |
| 3064 | // PARTITION_VERT_B |
Rupert Swarbrick | fc2ac95 | 2017-10-11 13:05:31 +0100 | [diff] [blame] | 3065 | if (partition_vert_allowed && vertab_partition_allowed) { |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3066 | #if CONFIG_EXT_PARTITION_TYPES_AB |
| 3067 | rd_test_partition3( |
| 3068 | cpi, td, tile_data, tp, pc_tree, &best_rdc, pc_tree->verticalb, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 3069 | ctx_none, mi_row, mi_col, bsize, PARTITION_VERT_B, mi_row, mi_col, |
| 3070 | get_subsize(bsize, PARTITION_VERT), mi_row, mi_col + mi_step, |
| 3071 | get_subsize(bsize, PARTITION_VERT_4), mi_row, mi_col + 3 * mi_step / 2, |
| 3072 | get_subsize(bsize, PARTITION_VERT_4)); |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3073 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3074 | subsize = get_subsize(bsize, PARTITION_VERT_B); |
| 3075 | rd_test_partition3(cpi, td, tile_data, tp, pc_tree, &best_rdc, |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 3076 | pc_tree->verticalb, ctx_none, mi_row, mi_col, bsize, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 3077 | PARTITION_VERT_B, mi_row, mi_col, subsize, mi_row, |
| 3078 | mi_col + mi_step, bsize2, mi_row + mi_step, |
| 3079 | mi_col + mi_step, bsize2); |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 3080 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3081 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
| 3082 | } |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3083 | |
| 3084 | // PARTITION_HORZ_4 |
| 3085 | // TODO(david.barker): For this and PARTITION_VERT_4, |
| 3086 | // * Add support for BLOCK_16X16 once we support 2x8 and 8x2 blocks for the |
| 3087 | // chroma plane |
| 3088 | // * Add support for supertx |
Rupert Swarbrick | fc2ac95 | 2017-10-11 13:05:31 +0100 | [diff] [blame] | 3089 | if (horz4_partition_allowed && !force_horz_split && |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3090 | (do_rectangular_split || av1_active_h_edge(cpi, mi_row, mi_step))) { |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3091 | const int quarter_step = mi_size_high[bsize] / 4; |
| 3092 | PICK_MODE_CONTEXT *ctx_prev = ctx_none; |
| 3093 | |
| 3094 | subsize = get_subsize(bsize, PARTITION_HORZ_4); |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3095 | |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 3096 | for (int i = 0; i < 4; ++i) { |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3097 | int this_mi_row = mi_row + i * quarter_step; |
| 3098 | |
| 3099 | if (i > 0 && this_mi_row >= cm->mi_rows) break; |
| 3100 | |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 3101 | PICK_MODE_CONTEXT *ctx_this = &pc_tree->horizontal4[i]; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3102 | |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 3103 | if (!rd_try_subblock(cpi, td, tile_data, tp, (i == 0), (i == 3), |
| 3104 | this_mi_row, mi_col, subsize, &best_rdc, &sum_rdc, |
| 3105 | &this_rdc, PARTITION_HORZ_4, ctx_prev, ctx_this)) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3106 | break; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3107 | |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 3108 | ctx_prev = ctx_this; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | if (sum_rdc.rdcost < best_rdc.rdcost) { |
| 3112 | sum_rdc.rate += partition_cost[PARTITION_HORZ_4]; |
| 3113 | sum_rdc.rdcost = RDCOST(x->rdmult, sum_rdc.rate, sum_rdc.dist); |
| 3114 | if (sum_rdc.rdcost < best_rdc.rdcost) { |
| 3115 | best_rdc = sum_rdc; |
| 3116 | pc_tree->partitioning = PARTITION_HORZ_4; |
| 3117 | } |
| 3118 | } |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3119 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3120 | } |
| 3121 | // PARTITION_VERT_4 |
Rupert Swarbrick | fc2ac95 | 2017-10-11 13:05:31 +0100 | [diff] [blame] | 3122 | if (vert4_partition_allowed && !force_vert_split && |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3123 | (do_rectangular_split || av1_active_v_edge(cpi, mi_row, mi_step))) { |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3124 | const int quarter_step = mi_size_wide[bsize] / 4; |
| 3125 | PICK_MODE_CONTEXT *ctx_prev = ctx_none; |
| 3126 | |
| 3127 | subsize = get_subsize(bsize, PARTITION_VERT_4); |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3128 | |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 3129 | for (int i = 0; i < 4; ++i) { |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3130 | int this_mi_col = mi_col + i * quarter_step; |
| 3131 | |
| 3132 | if (i > 0 && this_mi_col >= cm->mi_cols) break; |
| 3133 | |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 3134 | PICK_MODE_CONTEXT *ctx_this = &pc_tree->vertical4[i]; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3135 | |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 3136 | if (!rd_try_subblock(cpi, td, tile_data, tp, (i == 0), (i == 3), mi_row, |
| 3137 | this_mi_col, subsize, &best_rdc, &sum_rdc, &this_rdc, |
| 3138 | PARTITION_VERT_4, ctx_prev, ctx_this)) |
| 3139 | break; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3140 | |
Rupert Swarbrick | 0e653f9 | 2017-09-12 12:58:27 +0100 | [diff] [blame] | 3141 | ctx_prev = ctx_this; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3142 | } |
| 3143 | |
| 3144 | if (sum_rdc.rdcost < best_rdc.rdcost) { |
| 3145 | sum_rdc.rate += partition_cost[PARTITION_VERT_4]; |
| 3146 | sum_rdc.rdcost = RDCOST(x->rdmult, sum_rdc.rate, sum_rdc.dist); |
| 3147 | if (sum_rdc.rdcost < best_rdc.rdcost) { |
| 3148 | best_rdc = sum_rdc; |
| 3149 | pc_tree->partitioning = PARTITION_VERT_4; |
| 3150 | } |
| 3151 | } |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3152 | restore_context(x, &x_ctx, mi_row, mi_col, bsize); |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3153 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3154 | #endif // CONFIG_EXT_PARTITION_TYPES |
| 3155 | |
| 3156 | // TODO(jbb): This code added so that we avoid static analysis |
| 3157 | // warning related to the fact that best_rd isn't used after this |
| 3158 | // point. This code should be refactored so that the duplicate |
| 3159 | // checks occur in some sub function and thus are used... |
| 3160 | (void)best_rd; |
| 3161 | *rd_cost = best_rdc; |
Yushin Cho | c0f6bf2 | 2017-06-09 16:08:02 -0700 | [diff] [blame] | 3162 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3163 | if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX && |
| 3164 | pc_tree->index != 3) { |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 3165 | if (bsize == cm->sb_size) { |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 3166 | #if NC_MODE_INFO |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 3167 | set_mode_info_sb(cpi, td, tile_info, tp, mi_row, mi_col, bsize, pc_tree); |
| 3168 | #endif |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3169 | |
Jingning Han | f5a4d3b | 2017-08-27 23:01:19 -0700 | [diff] [blame] | 3170 | #if CONFIG_LV_MAP |
| 3171 | x->cb_offset = 0; |
| 3172 | #endif |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3173 | |
| 3174 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 3175 | set_sb_mi_boundaries(cm, xd, mi_row, mi_col); |
| 3176 | #endif |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 3177 | encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, OUTPUT_ENABLED, bsize, |
| 3178 | pc_tree, NULL); |
| 3179 | } else { |
| 3180 | encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, DRY_RUN_NORMAL, bsize, |
| 3181 | pc_tree, NULL); |
| 3182 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3183 | } |
| 3184 | |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 3185 | #if CONFIG_DIST_8X8 |
Yushin Cho | 5510433 | 2017-08-14 16:15:43 -0700 | [diff] [blame] | 3186 | if (x->using_dist_8x8 && best_rdc.rate < INT_MAX && |
| 3187 | best_rdc.dist < INT64_MAX && bsize == BLOCK_4X4 && pc_tree->index == 3) { |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 3188 | encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, DRY_RUN_NORMAL, bsize, |
| 3189 | pc_tree, NULL); |
| 3190 | } |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 3191 | #endif // CONFIG_DIST_8X8 |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 3192 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3193 | if (bsize == cm->sb_size) { |
Yushin Cho | d0b77ac | 2017-10-20 17:33:16 -0700 | [diff] [blame] | 3194 | #if !CONFIG_LV_MAP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3195 | assert(tp_orig < *tp || (tp_orig == *tp && xd->mi[0]->mbmi.skip)); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 3196 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3197 | assert(best_rdc.rate < INT_MAX); |
| 3198 | assert(best_rdc.dist < INT64_MAX); |
| 3199 | } else { |
| 3200 | assert(tp_orig == *tp); |
| 3201 | } |
| 3202 | } |
| 3203 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3204 | static void encode_rd_sb_row(AV1_COMP *cpi, ThreadData *td, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3205 | TileDataEnc *tile_data, int mi_row, |
| 3206 | TOKENEXTRA **tp) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3207 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3208 | const TileInfo *const tile_info = &tile_data->tile_info; |
| 3209 | MACROBLOCK *const x = &td->mb; |
| 3210 | MACROBLOCKD *const xd = &x->e_mbd; |
| 3211 | SPEED_FEATURES *const sf = &cpi->sf; |
| 3212 | int mi_col; |
| 3213 | #if CONFIG_EXT_PARTITION |
| 3214 | const int leaf_nodes = 256; |
| 3215 | #else |
| 3216 | const int leaf_nodes = 64; |
| 3217 | #endif // CONFIG_EXT_PARTITION |
| 3218 | |
| 3219 | // Initialize the left context for the new SB row |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3220 | av1_zero_left_context(xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3221 | |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 3222 | // Reset delta for every tile |
| 3223 | if (cm->delta_q_present_flag) |
| 3224 | if (mi_row == tile_info->mi_row_start) xd->prev_qindex = cm->base_qindex; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 3225 | #if CONFIG_EXT_DELTA_Q |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 3226 | if (cm->delta_lf_present_flag) { |
| 3227 | #if CONFIG_LOOPFILTER_LEVEL |
| 3228 | if (mi_row == tile_info->mi_row_start) |
| 3229 | for (int lf_id = 0; lf_id < FRAME_LF_COUNT; ++lf_id) |
| 3230 | xd->prev_delta_lf[lf_id] = 0; |
| 3231 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 3232 | if (mi_row == tile_info->mi_row_start) xd->prev_delta_lf_from_base = 0; |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 3233 | } |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 3234 | #endif |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 3235 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3236 | // Code each SB in the row |
| 3237 | for (mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end; |
| 3238 | mi_col += cm->mib_size) { |
| 3239 | const struct segmentation *const seg = &cm->seg; |
| 3240 | int dummy_rate; |
| 3241 | int64_t dummy_dist; |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 3242 | RD_STATS dummy_rdc; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3243 | int i; |
| 3244 | int seg_skip = 0; |
| 3245 | |
| 3246 | const int idx_str = cm->mi_stride * mi_row + mi_col; |
| 3247 | MODE_INFO **mi = cm->mi_grid_visible + idx_str; |
| 3248 | PC_TREE *const pc_root = td->pc_root[cm->mib_size_log2 - MIN_MIB_SIZE_LOG2]; |
| 3249 | |
Jingning Han | 00803a7 | 2017-10-25 16:04:34 -0700 | [diff] [blame] | 3250 | #if CONFIG_LV_MAP |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 3251 | av1_fill_coeff_costs(&td->mb, xd->tile_ctx); |
Jingning Han | 24b0cf9 | 2017-08-18 22:50:18 -0700 | [diff] [blame] | 3252 | #else |
hui su | bd57abe | 2017-07-24 18:14:03 -0700 | [diff] [blame] | 3253 | av1_fill_token_costs_from_cdf(x->token_head_costs, |
| 3254 | x->e_mbd.tile_ctx->coef_head_cdfs); |
| 3255 | av1_fill_token_costs_from_cdf(x->token_tail_costs, |
| 3256 | x->e_mbd.tile_ctx->coef_tail_cdfs); |
Jingning Han | 24b0cf9 | 2017-08-18 22:50:18 -0700 | [diff] [blame] | 3257 | #endif |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 3258 | av1_fill_mode_rates(cm, x, xd->tile_ctx); |
hui su | bd57abe | 2017-07-24 18:14:03 -0700 | [diff] [blame] | 3259 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3260 | if (sf->adaptive_pred_interp_filter) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3261 | for (i = 0; i < leaf_nodes; ++i) { |
| 3262 | td->pc_tree[i].vertical[0].pred_interp_filter = SWITCHABLE; |
| 3263 | td->pc_tree[i].vertical[1].pred_interp_filter = SWITCHABLE; |
| 3264 | td->pc_tree[i].horizontal[0].pred_interp_filter = SWITCHABLE; |
| 3265 | td->pc_tree[i].horizontal[1].pred_interp_filter = SWITCHABLE; |
| 3266 | } |
| 3267 | } |
| 3268 | |
Hui Su | 1ddf231 | 2017-08-19 15:21:34 -0700 | [diff] [blame] | 3269 | x->tx_rd_record.num = x->tx_rd_record.index_start = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3270 | av1_zero(x->pred_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3271 | pc_root->index = 0; |
| 3272 | |
| 3273 | if (seg->enabled) { |
| 3274 | const uint8_t *const map = |
| 3275 | seg->update_map ? cpi->segmentation_map : cm->last_frame_seg_map; |
| 3276 | int segment_id = get_segment_id(cm, map, cm->sb_size, mi_row, mi_col); |
| 3277 | seg_skip = segfeature_active(seg, segment_id, SEG_LVL_SKIP); |
| 3278 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3279 | #if CONFIG_AMVR |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 3280 | xd->cur_frame_force_integer_mv = cm->cur_frame_force_integer_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3281 | #endif |
Thomas Davies | 3ab20b4 | 2017-09-19 10:30:53 +0100 | [diff] [blame] | 3282 | |
Arild Fuldseth (arilfuld) | 54de7d6 | 2017-03-20 13:07:11 +0100 | [diff] [blame] | 3283 | if (cm->delta_q_present_flag) { |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 3284 | // Test mode for delta quantization |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 3285 | int sb_row = mi_row >> 3; |
| 3286 | int sb_col = mi_col >> 3; |
| 3287 | int sb_stride = (cm->width + MAX_SB_SIZE - 1) >> MAX_SB_SIZE_LOG2; |
| 3288 | int index = ((sb_row * sb_stride + sb_col + 8) & 31) - 16; |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 3289 | |
| 3290 | // Ensure divisibility of delta_qindex by delta_q_res |
| 3291 | int offset_qindex = (index < 0 ? -index - 8 : index - 8); |
| 3292 | int qmask = ~(cm->delta_q_res - 1); |
| 3293 | int current_qindex = clamp(cm->base_qindex + offset_qindex, |
| 3294 | cm->delta_q_res, 256 - cm->delta_q_res); |
Arild Fuldseth (arilfuld) | 54de7d6 | 2017-03-20 13:07:11 +0100 | [diff] [blame] | 3295 | |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 3296 | current_qindex = |
| 3297 | ((current_qindex - cm->base_qindex + cm->delta_q_res / 2) & qmask) + |
| 3298 | cm->base_qindex; |
Arild Fuldseth (arilfuld) | 54de7d6 | 2017-03-20 13:07:11 +0100 | [diff] [blame] | 3299 | assert(current_qindex > 0); |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 3300 | |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 3301 | xd->delta_qindex = current_qindex - cm->base_qindex; |
Debargha Mukherjee | e30159c | 2017-10-08 12:04:43 -0700 | [diff] [blame] | 3302 | set_offsets(cpi, tile_info, x, mi_row, mi_col, cm->sb_size); |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 3303 | xd->mi[0]->mbmi.current_q_index = current_qindex; |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 3304 | #if !CONFIG_EXT_DELTA_Q |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 3305 | xd->mi[0]->mbmi.segment_id = 0; |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 3306 | #endif // CONFIG_EXT_DELTA_Q |
Yaowu Xu | 5bb8f5b | 2016-11-02 15:31:29 -0700 | [diff] [blame] | 3307 | av1_init_plane_quantizers(cpi, x, xd->mi[0]->mbmi.segment_id); |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 3308 | #if CONFIG_EXT_DELTA_Q |
| 3309 | if (cpi->oxcf.deltaq_mode == DELTA_Q_LF) { |
| 3310 | int j, k; |
| 3311 | int lfmask = ~(cm->delta_lf_res - 1); |
| 3312 | int current_delta_lf_from_base = offset_qindex / 2; |
| 3313 | current_delta_lf_from_base = |
| 3314 | ((current_delta_lf_from_base + cm->delta_lf_res / 2) & lfmask); |
| 3315 | |
| 3316 | // pre-set the delta lf for loop filter. Note that this value is set |
| 3317 | // before mi is assigned for each block in current superblock |
| 3318 | for (j = 0; j < AOMMIN(cm->mib_size, cm->mi_rows - mi_row); j++) { |
| 3319 | for (k = 0; k < AOMMIN(cm->mib_size, cm->mi_cols - mi_col); k++) { |
| 3320 | cm->mi[(mi_row + j) * cm->mi_stride + (mi_col + k)] |
Cheng Chen | aff479f | 2017-10-26 16:53:10 -0700 | [diff] [blame] | 3321 | .mbmi.current_delta_lf_from_base = clamp( |
| 3322 | current_delta_lf_from_base, -MAX_LOOP_FILTER, MAX_LOOP_FILTER); |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 3323 | #if CONFIG_LOOPFILTER_LEVEL |
| 3324 | for (int lf_id = 0; lf_id < FRAME_LF_COUNT; ++lf_id) { |
| 3325 | cm->mi[(mi_row + j) * cm->mi_stride + (mi_col + k)] |
Cheng Chen | aff479f | 2017-10-26 16:53:10 -0700 | [diff] [blame] | 3326 | .mbmi.curr_delta_lf[lf_id] = |
| 3327 | clamp(current_delta_lf_from_base, -MAX_LOOP_FILTER, |
| 3328 | MAX_LOOP_FILTER); |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 3329 | } |
| 3330 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 3331 | } |
| 3332 | } |
| 3333 | } |
| 3334 | #endif // CONFIG_EXT_DELTA_Q |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 3335 | } |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 3336 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3337 | x->source_variance = UINT_MAX; |
| 3338 | if (sf->partition_search_type == FIXED_PARTITION || seg_skip) { |
| 3339 | BLOCK_SIZE bsize; |
| 3340 | set_offsets(cpi, tile_info, x, mi_row, mi_col, cm->sb_size); |
| 3341 | bsize = seg_skip ? cm->sb_size : sf->always_this_block_size; |
| 3342 | set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize); |
| 3343 | rd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, cm->sb_size, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 3344 | &dummy_rate, &dummy_dist, 1, pc_root); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3345 | } else if (cpi->partition_search_skippable_frame) { |
| 3346 | BLOCK_SIZE bsize; |
| 3347 | set_offsets(cpi, tile_info, x, mi_row, mi_col, cm->sb_size); |
| 3348 | bsize = get_rd_var_based_fixed_partition(cpi, x, mi_row, mi_col); |
| 3349 | set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize); |
| 3350 | rd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, cm->sb_size, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 3351 | &dummy_rate, &dummy_dist, 1, pc_root); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3352 | } else { |
| 3353 | // If required set upper and lower partition size limits |
| 3354 | if (sf->auto_min_max_partition_size) { |
| 3355 | set_offsets(cpi, tile_info, x, mi_row, mi_col, cm->sb_size); |
| 3356 | rd_auto_partition_range(cpi, tile_info, xd, mi_row, mi_col, |
| 3357 | &x->min_partition_size, &x->max_partition_size); |
| 3358 | } |
| 3359 | rd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, cm->sb_size, |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 3360 | &dummy_rdc, INT64_MAX, pc_root); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3361 | } |
Cheng Chen | 5ad5b28 | 2017-10-05 16:36:06 -0700 | [diff] [blame] | 3362 | #if CONFIG_LPF_SB |
| 3363 | if (USE_LOOP_FILTER_SUPERBLOCK) { |
| 3364 | // apply deblocking filtering right after each superblock is encoded. |
| 3365 | const int guess_filter_lvl = FAKE_FILTER_LEVEL; |
| 3366 | av1_loop_filter_frame(get_frame_new_buffer(cm), cm, xd, guess_filter_lvl, |
| 3367 | 0, 1, mi_row, mi_col); |
| 3368 | } |
| 3369 | #endif // CONFIG_LPF_SB |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3370 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3371 | } |
| 3372 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3373 | static void init_encode_frame_mb_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3374 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3375 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3376 | MACROBLOCKD *const xd = &x->e_mbd; |
| 3377 | |
| 3378 | // Copy data over into macro block data structures. |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3379 | av1_setup_src_planes(x, cpi->source, 0, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3380 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3381 | av1_setup_block_planes(xd, cm->subsampling_x, cm->subsampling_y); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3382 | } |
| 3383 | |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 3384 | #if !CONFIG_REF_ADAPT && !CONFIG_JNT_COMP |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3385 | static int check_dual_ref_flags(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3386 | const int ref_flags = cpi->ref_frame_flags; |
| 3387 | |
| 3388 | if (segfeature_active(&cpi->common.seg, 1, SEG_LVL_REF_FRAME)) { |
| 3389 | return 0; |
| 3390 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3391 | return (!!(ref_flags & AOM_GOLD_FLAG) + !!(ref_flags & AOM_LAST_FLAG) + |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3392 | !!(ref_flags & AOM_LAST2_FLAG) + !!(ref_flags & AOM_LAST3_FLAG) + |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 3393 | !!(ref_flags & AOM_BWD_FLAG) + !!(ref_flags & AOM_ALT2_FLAG) + |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3394 | !!(ref_flags & AOM_ALT_FLAG)) >= 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3395 | } |
| 3396 | } |
Zoe Liu | b05e5d1 | 2017-02-07 14:32:53 -0800 | [diff] [blame] | 3397 | #endif // !CONFIG_REF_ADAPT |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3398 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3399 | static MV_REFERENCE_FRAME get_frame_type(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3400 | if (frame_is_intra_only(&cpi->common)) return INTRA_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3401 | // We will not update the golden frame with an internal overlay frame |
| 3402 | else if ((cpi->rc.is_src_frame_alt_ref && cpi->refresh_golden_frame) || |
| 3403 | cpi->rc.is_src_frame_ext_arf) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3404 | return ALTREF_FRAME; |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3405 | else if (cpi->refresh_golden_frame || cpi->refresh_alt2_ref_frame || |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3406 | cpi->refresh_alt_ref_frame) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3407 | return GOLDEN_FRAME; |
| 3408 | else |
| 3409 | // TODO(zoeliu): To investigate whether a frame_type other than |
| 3410 | // INTRA/ALTREF/GOLDEN/LAST needs to be specified seperately. |
| 3411 | return LAST_FRAME; |
| 3412 | } |
| 3413 | |
Thomas Daede | f636d5c | 2017-06-29 13:48:27 -0700 | [diff] [blame] | 3414 | static TX_MODE select_tx_mode(const AV1_COMP *cpi) { |
| 3415 | if (cpi->common.all_lossless) return ONLY_4X4; |
Nathan E. Egge | a33304f | 2017-06-28 20:48:34 -0400 | [diff] [blame] | 3416 | #if CONFIG_VAR_TX_NO_TX_MODE |
| 3417 | return TX_MODE_SELECT; |
| 3418 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3419 | if (cpi->sf.tx_size_search_method == USE_LARGESTALL) |
Debargha Mukherjee | 18d38f6 | 2016-11-17 20:30:16 -0800 | [diff] [blame] | 3420 | return ALLOW_32X32 + CONFIG_TX64X64; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3421 | else if (cpi->sf.tx_size_search_method == USE_FULL_RD || |
Debargha Mukherjee | 5166686 | 2017-10-24 14:29:13 -0700 | [diff] [blame] | 3422 | cpi->sf.tx_size_search_method == USE_FAST_RD) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3423 | return TX_MODE_SELECT; |
| 3424 | else |
| 3425 | return cpi->common.tx_mode; |
Nathan E. Egge | a33304f | 2017-06-28 20:48:34 -0400 | [diff] [blame] | 3426 | #endif // CONFIG_VAR_TX_NO_TX_MODE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3429 | void av1_init_tile_data(AV1_COMP *cpi) { |
| 3430 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3431 | const int tile_cols = cm->tile_cols; |
| 3432 | const int tile_rows = cm->tile_rows; |
| 3433 | int tile_col, tile_row; |
| 3434 | TOKENEXTRA *pre_tok = cpi->tile_tok[0][0]; |
| 3435 | unsigned int tile_tok = 0; |
| 3436 | |
| 3437 | if (cpi->tile_data == NULL || cpi->allocated_tiles < tile_cols * tile_rows) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3438 | if (cpi->tile_data != NULL) aom_free(cpi->tile_data); |
Yaowu Xu | bf6ad90 | 2017-04-28 11:03:33 -0700 | [diff] [blame] | 3439 | CHECK_MEM_ERROR( |
| 3440 | cm, cpi->tile_data, |
| 3441 | aom_memalign(32, tile_cols * tile_rows * sizeof(*cpi->tile_data))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3442 | cpi->allocated_tiles = tile_cols * tile_rows; |
| 3443 | |
| 3444 | for (tile_row = 0; tile_row < tile_rows; ++tile_row) |
| 3445 | for (tile_col = 0; tile_col < tile_cols; ++tile_col) { |
| 3446 | TileDataEnc *const tile_data = |
| 3447 | &cpi->tile_data[tile_row * tile_cols + tile_col]; |
| 3448 | int i, j; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3449 | for (i = 0; i < BLOCK_SIZES_ALL; ++i) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3450 | for (j = 0; j < MAX_MODES; ++j) { |
| 3451 | tile_data->thresh_freq_fact[i][j] = 32; |
| 3452 | tile_data->mode_map[i][j] = j; |
| 3453 | } |
| 3454 | } |
| 3455 | } |
| 3456 | } |
| 3457 | |
| 3458 | for (tile_row = 0; tile_row < tile_rows; ++tile_row) { |
| 3459 | for (tile_col = 0; tile_col < tile_cols; ++tile_col) { |
| 3460 | TileInfo *const tile_info = |
| 3461 | &cpi->tile_data[tile_row * tile_cols + tile_col].tile_info; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3462 | av1_tile_init(tile_info, cm, tile_row, tile_col); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3463 | |
| 3464 | cpi->tile_tok[tile_row][tile_col] = pre_tok + tile_tok; |
| 3465 | pre_tok = cpi->tile_tok[tile_row][tile_col]; |
| 3466 | tile_tok = allocated_tokens(*tile_info); |
| 3467 | } |
| 3468 | } |
| 3469 | } |
| 3470 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3471 | void av1_encode_tile(AV1_COMP *cpi, ThreadData *td, int tile_row, |
| 3472 | int tile_col) { |
| 3473 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3474 | TileDataEnc *const this_tile = |
| 3475 | &cpi->tile_data[tile_row * cm->tile_cols + tile_col]; |
| 3476 | const TileInfo *const tile_info = &this_tile->tile_info; |
| 3477 | TOKENEXTRA *tok = cpi->tile_tok[tile_row][tile_col]; |
| 3478 | int mi_row; |
Yushin Cho | c49ef3a | 2017-03-13 17:27:25 -0700 | [diff] [blame] | 3479 | |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 3480 | #if CONFIG_DEPENDENT_HORZTILES |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 3481 | if ((!cm->dependent_horz_tiles) || (tile_row == 0) || |
| 3482 | tile_info->tg_horz_boundary) { |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 3483 | av1_zero_above_context(cm, tile_info->mi_col_start, tile_info->mi_col_end); |
| 3484 | } |
| 3485 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3486 | av1_zero_above_context(cm, tile_info->mi_col_start, tile_info->mi_col_end); |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 3487 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3488 | |
| 3489 | // Set up pointers to per thread motion search counters. |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 3490 | this_tile->m_search_count = 0; // Count of motion search hits. |
| 3491 | this_tile->ex_search_count = 0; // Exhaustive mesh search hits. |
| 3492 | td->mb.m_search_count_ptr = &this_tile->m_search_count; |
| 3493 | td->mb.ex_search_count_ptr = &this_tile->ex_search_count; |
Thomas Davies | f77d4ad | 2017-01-10 18:55:42 +0000 | [diff] [blame] | 3494 | this_tile->tctx = *cm->fc; |
| 3495 | td->mb.e_mbd.tile_ctx = &this_tile->tctx; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 3496 | |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 3497 | #if CONFIG_CFL |
Luc Trudeau | baeb375 | 2017-04-24 11:19:25 -0400 | [diff] [blame] | 3498 | MACROBLOCKD *const xd = &td->mb.e_mbd; |
| 3499 | xd->cfl = &this_tile->cfl; |
Luc Trudeau | dac5e39 | 2017-06-05 15:52:02 -0400 | [diff] [blame] | 3500 | cfl_init(xd->cfl, cm); |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 3501 | #endif |
| 3502 | |
Angie Chiang | 0480893 | 2017-08-28 12:06:08 -0700 | [diff] [blame] | 3503 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
David Barker | c1018ad | 2017-08-29 12:05:02 +0100 | [diff] [blame] | 3504 | if (!cm->loop_filter_across_tiles_enabled) |
| 3505 | av1_setup_across_tile_boundary_info(cm, tile_info); |
Angie Chiang | 0480893 | 2017-08-28 12:06:08 -0700 | [diff] [blame] | 3506 | #endif |
Yi Luo | f190a16 | 2017-07-13 16:16:56 -0700 | [diff] [blame] | 3507 | |
Hui Su | 1ddf231 | 2017-08-19 15:21:34 -0700 | [diff] [blame] | 3508 | av1_crc_calculator_init(&td->mb.tx_rd_record.crc_calculator, 24, 0x5D6DCB); |
| 3509 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3510 | for (mi_row = tile_info->mi_row_start; mi_row < tile_info->mi_row_end; |
| 3511 | mi_row += cm->mib_size) { |
| 3512 | encode_rd_sb_row(cpi, td, this_tile, mi_row, &tok); |
| 3513 | } |
| 3514 | |
| 3515 | cpi->tok_count[tile_row][tile_col] = |
| 3516 | (unsigned int)(tok - cpi->tile_tok[tile_row][tile_col]); |
| 3517 | assert(cpi->tok_count[tile_row][tile_col] <= allocated_tokens(*tile_info)); |
| 3518 | } |
| 3519 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3520 | static void encode_tiles(AV1_COMP *cpi) { |
| 3521 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3522 | int tile_col, tile_row; |
| 3523 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3524 | av1_init_tile_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3525 | |
| 3526 | for (tile_row = 0; tile_row < cm->tile_rows; ++tile_row) |
| 3527 | for (tile_col = 0; tile_col < cm->tile_cols; ++tile_col) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3528 | av1_encode_tile(cpi, &cpi->td, tile_row, tile_col); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | #if CONFIG_FP_MB_STATS |
| 3532 | static int input_fpmb_stats(FIRSTPASS_MB_STATS *firstpass_mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3533 | AV1_COMMON *cm, uint8_t **this_frame_mb_stats) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3534 | uint8_t *mb_stats_in = firstpass_mb_stats->mb_stats_start + |
| 3535 | cm->current_video_frame * cm->MBs * sizeof(uint8_t); |
| 3536 | |
| 3537 | if (mb_stats_in > firstpass_mb_stats->mb_stats_end) return EOF; |
| 3538 | |
| 3539 | *this_frame_mb_stats = mb_stats_in; |
| 3540 | |
| 3541 | return 1; |
| 3542 | } |
| 3543 | #endif |
| 3544 | |
Debargha Mukherjee | 5f35e58 | 2017-04-25 18:05:18 -0700 | [diff] [blame] | 3545 | #define GLOBAL_TRANS_TYPES_ENC 3 // highest motion model to search |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3546 | static int gm_get_params_cost(const WarpedMotionParams *gm, |
| 3547 | const WarpedMotionParams *ref_gm, int allow_hp) { |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3548 | assert(gm->wmtype < GLOBAL_TRANS_TYPES); |
| 3549 | int params_cost = 0; |
Sarah Parker | f178329 | 2017-04-05 11:55:27 -0700 | [diff] [blame] | 3550 | int trans_bits, trans_prec_diff; |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3551 | switch (gm->wmtype) { |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3552 | case AFFINE: |
| 3553 | case ROTZOOM: |
Sarah Parker | f178329 | 2017-04-05 11:55:27 -0700 | [diff] [blame] | 3554 | params_cost += aom_count_signed_primitive_refsubexpfin( |
| 3555 | GM_ALPHA_MAX + 1, SUBEXPFIN_K, |
| 3556 | (ref_gm->wmmat[2] >> GM_ALPHA_PREC_DIFF) - (1 << GM_ALPHA_PREC_BITS), |
| 3557 | (gm->wmmat[2] >> GM_ALPHA_PREC_DIFF) - (1 << GM_ALPHA_PREC_BITS)); |
Debargha Mukherjee | 1a2b35f | 2017-10-21 10:41:46 -0700 | [diff] [blame] | 3558 | params_cost += aom_count_signed_primitive_refsubexpfin( |
| 3559 | GM_ALPHA_MAX + 1, SUBEXPFIN_K, |
| 3560 | (ref_gm->wmmat[3] >> GM_ALPHA_PREC_DIFF), |
| 3561 | (gm->wmmat[3] >> GM_ALPHA_PREC_DIFF)); |
| 3562 | if (gm->wmtype >= AFFINE) { |
Sarah Parker | f178329 | 2017-04-05 11:55:27 -0700 | [diff] [blame] | 3563 | params_cost += aom_count_signed_primitive_refsubexpfin( |
| 3564 | GM_ALPHA_MAX + 1, SUBEXPFIN_K, |
Debargha Mukherjee | 1a2b35f | 2017-10-21 10:41:46 -0700 | [diff] [blame] | 3565 | (ref_gm->wmmat[4] >> GM_ALPHA_PREC_DIFF), |
| 3566 | (gm->wmmat[4] >> GM_ALPHA_PREC_DIFF)); |
Sarah Parker | f178329 | 2017-04-05 11:55:27 -0700 | [diff] [blame] | 3567 | params_cost += aom_count_signed_primitive_refsubexpfin( |
| 3568 | GM_ALPHA_MAX + 1, SUBEXPFIN_K, |
| 3569 | (ref_gm->wmmat[5] >> GM_ALPHA_PREC_DIFF) - |
| 3570 | (1 << GM_ALPHA_PREC_BITS), |
| 3571 | (gm->wmmat[5] >> GM_ALPHA_PREC_DIFF) - (1 << GM_ALPHA_PREC_BITS)); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3572 | } |
| 3573 | // Fallthrough intended |
| 3574 | case TRANSLATION: |
Sarah Parker | f178329 | 2017-04-05 11:55:27 -0700 | [diff] [blame] | 3575 | trans_bits = (gm->wmtype == TRANSLATION) |
| 3576 | ? GM_ABS_TRANS_ONLY_BITS - !allow_hp |
| 3577 | : GM_ABS_TRANS_BITS; |
| 3578 | trans_prec_diff = (gm->wmtype == TRANSLATION) |
| 3579 | ? GM_TRANS_ONLY_PREC_DIFF + !allow_hp |
| 3580 | : GM_TRANS_PREC_DIFF; |
| 3581 | params_cost += aom_count_signed_primitive_refsubexpfin( |
| 3582 | (1 << trans_bits) + 1, SUBEXPFIN_K, |
| 3583 | (ref_gm->wmmat[0] >> trans_prec_diff), |
| 3584 | (gm->wmmat[0] >> trans_prec_diff)); |
| 3585 | params_cost += aom_count_signed_primitive_refsubexpfin( |
| 3586 | (1 << trans_bits) + 1, SUBEXPFIN_K, |
| 3587 | (ref_gm->wmmat[1] >> trans_prec_diff), |
| 3588 | (gm->wmmat[1] >> trans_prec_diff)); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3589 | // Fallthrough intended |
| 3590 | case IDENTITY: break; |
| 3591 | default: assert(0); |
| 3592 | } |
| 3593 | return (params_cost << AV1_PROB_COST_SHIFT); |
| 3594 | } |
Debargha Mukherjee | 2a9d746 | 2017-05-04 17:37:52 -0700 | [diff] [blame] | 3595 | |
| 3596 | static int do_gm_search_logic(SPEED_FEATURES *const sf, int num_refs_using_gm, |
| 3597 | int frame) { |
| 3598 | (void)num_refs_using_gm; |
| 3599 | (void)frame; |
| 3600 | switch (sf->gm_search_type) { |
| 3601 | case GM_FULL_SEARCH: return 1; |
| 3602 | case GM_REDUCED_REF_SEARCH: |
Debargha Mukherjee | 2a9d746 | 2017-05-04 17:37:52 -0700 | [diff] [blame] | 3603 | return !(frame == LAST2_FRAME || frame == LAST3_FRAME); |
Debargha Mukherjee | 2a9d746 | 2017-05-04 17:37:52 -0700 | [diff] [blame] | 3604 | case GM_DISABLE_SEARCH: return 0; |
| 3605 | default: assert(0); |
| 3606 | } |
| 3607 | return 1; |
| 3608 | } |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3609 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3610 | // Estimate if the source frame is screen content, based on the portion of |
| 3611 | // blocks that have no more than 4 (experimentally selected) luma colors. |
hui su | 105b72c | 2017-07-13 10:36:23 -0700 | [diff] [blame] | 3612 | static int is_screen_content(const uint8_t *src, |
| 3613 | #if CONFIG_HIGHBITDEPTH |
| 3614 | int use_hbd, int bd, |
| 3615 | #endif // CONFIG_HIGHBITDEPTH |
| 3616 | int stride, int width, int height) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3617 | assert(src != NULL); |
| 3618 | int counts = 0; |
| 3619 | const int blk_w = 16; |
| 3620 | const int blk_h = 16; |
| 3621 | const int limit = 4; |
| 3622 | for (int r = 0; r + blk_h <= height; r += blk_h) { |
| 3623 | for (int c = 0; c + blk_w <= width; c += blk_w) { |
| 3624 | const int n_colors = |
hui su | 105b72c | 2017-07-13 10:36:23 -0700 | [diff] [blame] | 3625 | #if CONFIG_HIGHBITDEPTH |
| 3626 | use_hbd ? av1_count_colors_highbd(src + r * stride + c, stride, blk_w, |
| 3627 | blk_h, bd) |
| 3628 | : |
| 3629 | #endif // CONFIG_HIGHBITDEPTH |
| 3630 | av1_count_colors(src + r * stride + c, stride, blk_w, blk_h); |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3631 | if (n_colors > 1 && n_colors <= limit) counts++; |
| 3632 | } |
| 3633 | } |
| 3634 | // The threshold is 10%. |
| 3635 | return counts * blk_h * blk_w * 10 > width * height; |
| 3636 | } |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3637 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3638 | static void encode_frame_internal(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3639 | ThreadData *const td = &cpi->td; |
| 3640 | MACROBLOCK *const x = &td->mb; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3641 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3642 | MACROBLOCKD *const xd = &x->e_mbd; |
| 3643 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
| 3644 | int i; |
Zoe Liu | 453aef6 | 2017-04-19 15:35:17 -0700 | [diff] [blame] | 3645 | const int last_fb_buf_idx = get_ref_frame_buf_idx(cpi, LAST_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3646 | |
Yi Luo | f8e87b4 | 2017-04-14 17:20:27 -0700 | [diff] [blame] | 3647 | #if CONFIG_ADAPT_SCAN |
| 3648 | av1_deliver_eob_threshold(cm, xd); |
| 3649 | #endif |
| 3650 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3651 | x->min_partition_size = AOMMIN(x->min_partition_size, cm->sb_size); |
| 3652 | x->max_partition_size = AOMMIN(x->max_partition_size, cm->sb_size); |
Yushin Cho | 5510433 | 2017-08-14 16:15:43 -0700 | [diff] [blame] | 3653 | #if CONFIG_DIST_8X8 |
| 3654 | x->using_dist_8x8 = cpi->oxcf.using_dist_8x8; |
| 3655 | x->tune_metric = cpi->oxcf.tuning; |
| 3656 | #endif |
Deng | ca8d24d | 2016-10-17 14:06:35 +0800 | [diff] [blame] | 3657 | cm->setup_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3658 | |
| 3659 | xd->mi = cm->mi_grid_visible; |
| 3660 | xd->mi[0] = cm->mi; |
| 3661 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3662 | av1_zero(*td->counts); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3663 | av1_zero(rdc->comp_pred_diff); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3664 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 3665 | if (frame_is_intra_only(cm)) { |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 3666 | cm->allow_screen_content_tools = |
| 3667 | cpi->oxcf.content == AOM_CONTENT_SCREEN || |
| 3668 | is_screen_content(cpi->source->y_buffer, |
hui su | 105b72c | 2017-07-13 10:36:23 -0700 | [diff] [blame] | 3669 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 3670 | cpi->source->flags & YV12_FLAG_HIGHBITDEPTH, xd->bd, |
hui su | 105b72c | 2017-07-13 10:36:23 -0700 | [diff] [blame] | 3671 | #endif // CONFIG_HIGHBITDEPTH |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 3672 | cpi->source->y_stride, cpi->source->y_width, |
| 3673 | cpi->source->y_height); |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 3674 | } |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3675 | |
RogerZhou | d15e7c1 | 2017-09-26 08:49:28 -0700 | [diff] [blame] | 3676 | #if CONFIG_HASH_ME |
| 3677 | if (cpi->oxcf.pass != 1 && cpi->common.allow_screen_content_tools) { |
| 3678 | // add to hash table |
| 3679 | const int pic_width = cpi->source->y_crop_width; |
| 3680 | const int pic_height = cpi->source->y_crop_height; |
| 3681 | uint32_t *block_hash_values[2][2]; |
| 3682 | int8_t *is_block_same[2][3]; |
| 3683 | int k, j; |
| 3684 | |
| 3685 | for (k = 0; k < 2; k++) { |
| 3686 | for (j = 0; j < 2; j++) { |
| 3687 | CHECK_MEM_ERROR(cm, block_hash_values[k][j], |
| 3688 | aom_malloc(sizeof(uint32_t) * pic_width * pic_height)); |
| 3689 | } |
| 3690 | |
| 3691 | for (j = 0; j < 3; j++) { |
| 3692 | CHECK_MEM_ERROR(cm, is_block_same[k][j], |
| 3693 | aom_malloc(sizeof(int8_t) * pic_width * pic_height)); |
| 3694 | } |
| 3695 | } |
| 3696 | |
| 3697 | av1_hash_table_create(&cm->cur_frame->hash_table); |
| 3698 | av1_generate_block_2x2_hash_value(cpi->source, block_hash_values[0], |
| 3699 | is_block_same[0]); |
| 3700 | av1_generate_block_hash_value(cpi->source, 4, block_hash_values[0], |
| 3701 | block_hash_values[1], is_block_same[0], |
| 3702 | is_block_same[1]); |
RogerZhou | ca86546 | 2017-10-05 15:06:27 -0700 | [diff] [blame] | 3703 | av1_add_to_hash_map_by_row_with_precal_data( |
| 3704 | &cm->cur_frame->hash_table, block_hash_values[1], is_block_same[1][2], |
| 3705 | pic_width, pic_height, 4); |
RogerZhou | d15e7c1 | 2017-09-26 08:49:28 -0700 | [diff] [blame] | 3706 | av1_generate_block_hash_value(cpi->source, 8, block_hash_values[1], |
| 3707 | block_hash_values[0], is_block_same[1], |
| 3708 | is_block_same[0]); |
| 3709 | av1_add_to_hash_map_by_row_with_precal_data( |
| 3710 | &cm->cur_frame->hash_table, block_hash_values[0], is_block_same[0][2], |
| 3711 | pic_width, pic_height, 8); |
| 3712 | av1_generate_block_hash_value(cpi->source, 16, block_hash_values[0], |
| 3713 | block_hash_values[1], is_block_same[0], |
| 3714 | is_block_same[1]); |
| 3715 | av1_add_to_hash_map_by_row_with_precal_data( |
| 3716 | &cm->cur_frame->hash_table, block_hash_values[1], is_block_same[1][2], |
| 3717 | pic_width, pic_height, 16); |
| 3718 | av1_generate_block_hash_value(cpi->source, 32, block_hash_values[1], |
| 3719 | block_hash_values[0], is_block_same[1], |
| 3720 | is_block_same[0]); |
| 3721 | av1_add_to_hash_map_by_row_with_precal_data( |
| 3722 | &cm->cur_frame->hash_table, block_hash_values[0], is_block_same[0][2], |
| 3723 | pic_width, pic_height, 32); |
| 3724 | av1_generate_block_hash_value(cpi->source, 64, block_hash_values[0], |
| 3725 | block_hash_values[1], is_block_same[0], |
| 3726 | is_block_same[1]); |
| 3727 | av1_add_to_hash_map_by_row_with_precal_data( |
| 3728 | &cm->cur_frame->hash_table, block_hash_values[1], is_block_same[1][2], |
| 3729 | pic_width, pic_height, 64); |
| 3730 | |
| 3731 | for (k = 0; k < 2; k++) { |
| 3732 | for (j = 0; j < 2; j++) { |
| 3733 | aom_free(block_hash_values[k][j]); |
| 3734 | } |
| 3735 | |
| 3736 | for (j = 0; j < 3; j++) { |
| 3737 | aom_free(is_block_same[k][j]); |
| 3738 | } |
| 3739 | } |
| 3740 | } |
| 3741 | #endif |
| 3742 | |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3743 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 3744 | alloc_ncobmc_pred_buffer(xd); |
| 3745 | #endif |
| 3746 | |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3747 | av1_zero(rdc->global_motion_used); |
Debargha Mukherjee | 2a9d746 | 2017-05-04 17:37:52 -0700 | [diff] [blame] | 3748 | av1_zero(cpi->gmparams_cost); |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3749 | if (cpi->common.frame_type == INTER_FRAME && cpi->source && |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3750 | !cpi->global_motion_search_done) { |
Debargha Mukherjee | 2a9d746 | 2017-05-04 17:37:52 -0700 | [diff] [blame] | 3751 | YV12_BUFFER_CONFIG *ref_buf[TOTAL_REFS_PER_FRAME]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3752 | int frame; |
emilkeyder@google.com | f347763 | 2017-03-01 16:29:14 -0500 | [diff] [blame] | 3753 | double params_by_motion[RANSAC_NUM_MOTIONS * (MAX_PARAMDIM - 1)]; |
| 3754 | const double *params_this_motion; |
| 3755 | int inliers_by_motion[RANSAC_NUM_MOTIONS]; |
| 3756 | WarpedMotionParams tmp_wm_params; |
emilkeyder@google.com | f347763 | 2017-03-01 16:29:14 -0500 | [diff] [blame] | 3757 | static const double kIdentityParams[MAX_PARAMDIM - 1] = { |
| 3758 | 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 |
| 3759 | }; |
Debargha Mukherjee | 2a9d746 | 2017-05-04 17:37:52 -0700 | [diff] [blame] | 3760 | int num_refs_using_gm = 0; |
emilkeyder@google.com | f347763 | 2017-03-01 16:29:14 -0500 | [diff] [blame] | 3761 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3762 | for (frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) { |
Debargha Mukherjee | 2a9d746 | 2017-05-04 17:37:52 -0700 | [diff] [blame] | 3763 | ref_buf[frame] = get_ref_frame_buffer(cpi, frame); |
| 3764 | int pframe; |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3765 | cm->global_motion[frame] = default_warp_params; |
| 3766 | const WarpedMotionParams *ref_params = |
| 3767 | cm->error_resilient_mode ? &default_warp_params |
| 3768 | : &cm->prev_frame->global_motion[frame]; |
Debargha Mukherjee | 2a9d746 | 2017-05-04 17:37:52 -0700 | [diff] [blame] | 3769 | // check for duplicate buffer |
| 3770 | for (pframe = LAST_FRAME; pframe < frame; ++pframe) { |
| 3771 | if (ref_buf[frame] == ref_buf[pframe]) break; |
| 3772 | } |
| 3773 | if (pframe < frame) { |
| 3774 | memcpy(&cm->global_motion[frame], &cm->global_motion[pframe], |
| 3775 | sizeof(WarpedMotionParams)); |
| 3776 | } else if (ref_buf[frame] && |
Debargha Mukherjee | 65e159b | 2017-07-11 12:03:04 -0700 | [diff] [blame] | 3777 | ref_buf[frame]->y_crop_width == cpi->source->y_crop_width && |
| 3778 | ref_buf[frame]->y_crop_height == cpi->source->y_crop_height && |
Debargha Mukherjee | 2a9d746 | 2017-05-04 17:37:52 -0700 | [diff] [blame] | 3779 | do_gm_search_logic(&cpi->sf, num_refs_using_gm, frame)) { |
Debargha Mukherjee | b0f6bd4 | 2016-12-02 09:19:39 -0800 | [diff] [blame] | 3780 | TransformationType model; |
emilkeyder@google.com | 6e3557c | 2017-03-27 10:52:53 -0400 | [diff] [blame] | 3781 | const int64_t ref_frame_error = av1_frame_error( |
| 3782 | #if CONFIG_HIGHBITDEPTH |
| 3783 | xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH, xd->bd, |
| 3784 | #endif // CONFIG_HIGHBITDEPTH |
| 3785 | ref_buf[frame]->y_buffer, ref_buf[frame]->y_stride, |
Sarah Parker | 81f6ecd | 2017-05-26 16:10:11 -0700 | [diff] [blame] | 3786 | cpi->source->y_buffer, cpi->source->y_width, cpi->source->y_height, |
| 3787 | cpi->source->y_stride); |
emilkeyder@google.com | 6e3557c | 2017-03-27 10:52:53 -0400 | [diff] [blame] | 3788 | |
| 3789 | if (ref_frame_error == 0) continue; |
| 3790 | |
Debargha Mukherjee | 53291fa | 2016-11-14 18:29:03 -0800 | [diff] [blame] | 3791 | aom_clear_system_state(); |
Debargha Mukherjee | 5f35e58 | 2017-04-25 18:05:18 -0700 | [diff] [blame] | 3792 | for (model = ROTZOOM; model < GLOBAL_TRANS_TYPES_ENC; ++model) { |
emilkeyder@google.com | 6e3557c | 2017-03-27 10:52:53 -0400 | [diff] [blame] | 3793 | int64_t best_warp_error = INT64_MAX; |
emilkeyder@google.com | f347763 | 2017-03-01 16:29:14 -0500 | [diff] [blame] | 3794 | // Initially set all params to identity. |
| 3795 | for (i = 0; i < RANSAC_NUM_MOTIONS; ++i) { |
| 3796 | memcpy(params_by_motion + (MAX_PARAMDIM - 1) * i, kIdentityParams, |
| 3797 | (MAX_PARAMDIM - 1) * sizeof(*params_by_motion)); |
| 3798 | } |
| 3799 | |
| 3800 | compute_global_motion_feature_based( |
Debargha Mukherjee | 2a9d746 | 2017-05-04 17:37:52 -0700 | [diff] [blame] | 3801 | model, cpi->source, ref_buf[frame], |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3802 | #if CONFIG_HIGHBITDEPTH |
emilkeyder@google.com | f347763 | 2017-03-01 16:29:14 -0500 | [diff] [blame] | 3803 | cpi->common.bit_depth, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3804 | #endif // CONFIG_HIGHBITDEPTH |
emilkeyder@google.com | f347763 | 2017-03-01 16:29:14 -0500 | [diff] [blame] | 3805 | inliers_by_motion, params_by_motion, RANSAC_NUM_MOTIONS); |
| 3806 | |
| 3807 | for (i = 0; i < RANSAC_NUM_MOTIONS; ++i) { |
| 3808 | if (inliers_by_motion[i] == 0) continue; |
| 3809 | |
| 3810 | params_this_motion = params_by_motion + (MAX_PARAMDIM - 1) * i; |
| 3811 | convert_model_to_params(params_this_motion, &tmp_wm_params); |
| 3812 | |
| 3813 | if (tmp_wm_params.wmtype != IDENTITY) { |
emilkeyder@google.com | 6e3557c | 2017-03-27 10:52:53 -0400 | [diff] [blame] | 3814 | const int64_t warp_error = refine_integerized_param( |
emilkeyder@google.com | f347763 | 2017-03-01 16:29:14 -0500 | [diff] [blame] | 3815 | &tmp_wm_params, tmp_wm_params.wmtype, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3816 | #if CONFIG_HIGHBITDEPTH |
Debargha Mukherjee | b0f6bd4 | 2016-12-02 09:19:39 -0800 | [diff] [blame] | 3817 | xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH, xd->bd, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3818 | #endif // CONFIG_HIGHBITDEPTH |
Debargha Mukherjee | 2a9d746 | 2017-05-04 17:37:52 -0700 | [diff] [blame] | 3819 | ref_buf[frame]->y_buffer, ref_buf[frame]->y_width, |
| 3820 | ref_buf[frame]->y_height, ref_buf[frame]->y_stride, |
| 3821 | cpi->source->y_buffer, cpi->source->y_width, |
Sarah Parker | 3e85f67 | 2017-06-15 09:04:32 -0700 | [diff] [blame] | 3822 | cpi->source->y_height, cpi->source->y_stride, 5, |
Sarah Parker | 81f6ecd | 2017-05-26 16:10:11 -0700 | [diff] [blame] | 3823 | best_warp_error); |
emilkeyder@google.com | 6e3557c | 2017-03-27 10:52:53 -0400 | [diff] [blame] | 3824 | if (warp_error < best_warp_error) { |
| 3825 | best_warp_error = warp_error; |
emilkeyder@google.com | f347763 | 2017-03-01 16:29:14 -0500 | [diff] [blame] | 3826 | // Save the wm_params modified by refine_integerized_param() |
| 3827 | // rather than motion index to avoid rerunning refine() below. |
| 3828 | memcpy(&(cm->global_motion[frame]), &tmp_wm_params, |
| 3829 | sizeof(WarpedMotionParams)); |
Debargha Mukherjee | b0f6bd4 | 2016-12-02 09:19:39 -0800 | [diff] [blame] | 3830 | } |
Debargha Mukherjee | e3e0079 | 2016-11-13 11:35:44 -0800 | [diff] [blame] | 3831 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3832 | } |
Debargha Mukherjee | 3b6c544 | 2017-03-30 08:22:00 -0700 | [diff] [blame] | 3833 | if (cm->global_motion[frame].wmtype <= AFFINE) |
| 3834 | if (!get_shear_params(&cm->global_motion[frame])) |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3835 | cm->global_motion[frame] = default_warp_params; |
Debargha Mukherjee | 3b6c544 | 2017-03-30 08:22:00 -0700 | [diff] [blame] | 3836 | |
Debargha Mukherjee | e832d57 | 2017-04-07 14:40:43 -0700 | [diff] [blame] | 3837 | if (cm->global_motion[frame].wmtype == TRANSLATION) { |
| 3838 | cm->global_motion[frame].wmmat[0] = |
| 3839 | convert_to_trans_prec(cm->allow_high_precision_mv, |
| 3840 | cm->global_motion[frame].wmmat[0]) * |
| 3841 | GM_TRANS_ONLY_DECODE_FACTOR; |
| 3842 | cm->global_motion[frame].wmmat[1] = |
| 3843 | convert_to_trans_prec(cm->allow_high_precision_mv, |
| 3844 | cm->global_motion[frame].wmmat[1]) * |
| 3845 | GM_TRANS_ONLY_DECODE_FACTOR; |
Sarah Parker | 13d0662 | 2017-03-10 17:03:28 -0800 | [diff] [blame] | 3846 | } |
Debargha Mukherjee | e832d57 | 2017-04-07 14:40:43 -0700 | [diff] [blame] | 3847 | |
| 3848 | // If the best error advantage found doesn't meet the threshold for |
| 3849 | // this motion type, revert to IDENTITY. |
| 3850 | if (!is_enough_erroradvantage( |
emilkeyder@google.com | 6e3557c | 2017-03-27 10:52:53 -0400 | [diff] [blame] | 3851 | (double)best_warp_error / ref_frame_error, |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3852 | gm_get_params_cost(&cm->global_motion[frame], ref_params, |
Debargha Mukherjee | e832d57 | 2017-04-07 14:40:43 -0700 | [diff] [blame] | 3853 | cm->allow_high_precision_mv))) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3854 | cm->global_motion[frame] = default_warp_params; |
Debargha Mukherjee | e832d57 | 2017-04-07 14:40:43 -0700 | [diff] [blame] | 3855 | } |
Debargha Mukherjee | e832d57 | 2017-04-07 14:40:43 -0700 | [diff] [blame] | 3856 | if (cm->global_motion[frame].wmtype != IDENTITY) break; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3857 | } |
Debargha Mukherjee | 53291fa | 2016-11-14 18:29:03 -0800 | [diff] [blame] | 3858 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3859 | } |
Debargha Mukherjee | 2a9d746 | 2017-05-04 17:37:52 -0700 | [diff] [blame] | 3860 | if (cm->global_motion[frame].wmtype != IDENTITY) num_refs_using_gm++; |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3861 | cpi->gmparams_cost[frame] = |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3862 | gm_get_params_cost(&cm->global_motion[frame], ref_params, |
Sarah Parker | f178329 | 2017-04-05 11:55:27 -0700 | [diff] [blame] | 3863 | cm->allow_high_precision_mv) + |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3864 | cpi->gmtype_cost[cm->global_motion[frame].wmtype] - |
| 3865 | cpi->gmtype_cost[IDENTITY]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3866 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3867 | cpi->global_motion_search_done = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3868 | } |
David Barker | cba7da7 | 2017-09-14 11:24:27 +0100 | [diff] [blame] | 3869 | memcpy(cm->cur_frame->global_motion, cm->global_motion, |
| 3870 | TOTAL_REFS_PER_FRAME * sizeof(WarpedMotionParams)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3871 | |
| 3872 | for (i = 0; i < MAX_SEGMENTS; ++i) { |
| 3873 | const int qindex = cm->seg.enabled |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3874 | ? av1_get_qindex(&cm->seg, i, cm->base_qindex) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3875 | : cm->base_qindex; |
| 3876 | xd->lossless[i] = qindex == 0 && cm->y_dc_delta_q == 0 && |
| 3877 | cm->uv_dc_delta_q == 0 && cm->uv_ac_delta_q == 0; |
Yue Chen | eeacc4c | 2017-01-17 17:29:17 -0800 | [diff] [blame] | 3878 | xd->qindex[i] = qindex; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3879 | } |
Thomas Daede | f636d5c | 2017-06-29 13:48:27 -0700 | [diff] [blame] | 3880 | cm->all_lossless = all_lossless(cm, xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3881 | if (!cm->seg.enabled && xd->lossless[0]) x->optimize = 0; |
| 3882 | |
Thomas Daede | f636d5c | 2017-06-29 13:48:27 -0700 | [diff] [blame] | 3883 | cm->tx_mode = select_tx_mode(cpi); |
Arild Fuldseth (arilfuld) | 54de7d6 | 2017-03-20 13:07:11 +0100 | [diff] [blame] | 3884 | |
Arild Fuldseth (arilfuld) | 54de7d6 | 2017-03-20 13:07:11 +0100 | [diff] [blame] | 3885 | // Fix delta q resolution for the moment |
| 3886 | cm->delta_q_res = DEFAULT_DELTA_Q_RES; |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 3887 | // Set delta_q_present_flag before it is used for the first time |
| 3888 | #if CONFIG_EXT_DELTA_Q |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 3889 | cm->delta_lf_res = DEFAULT_DELTA_LF_RES; |
| 3890 | // update delta_q_present_flag and delta_lf_present_flag based on base_qindex |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 3891 | cm->delta_q_present_flag &= cm->base_qindex > 0; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 3892 | cm->delta_lf_present_flag &= cm->base_qindex > 0; |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 3893 | #else |
Arild Fuldseth (arilfuld) | 54de7d6 | 2017-03-20 13:07:11 +0100 | [diff] [blame] | 3894 | cm->delta_q_present_flag = |
| 3895 | cpi->oxcf.aq_mode == DELTA_AQ && cm->base_qindex > 0; |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 3896 | #endif // CONFIG_EXT_DELTA_Q |
Arild Fuldseth (arilfuld) | 54de7d6 | 2017-03-20 13:07:11 +0100 | [diff] [blame] | 3897 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3898 | av1_frame_init_quantizer(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3899 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3900 | av1_initialize_rd_consts(cpi); |
| 3901 | av1_initialize_me_consts(cpi, x, cm->base_qindex); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3902 | init_encode_frame_mb_context(cpi); |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 3903 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3904 | // NOTE(zoeliu): As cm->prev_frame can take neither a frame of |
| 3905 | // show_exisiting_frame=1, nor can it take a frame not used as |
| 3906 | // a reference, it is probable that by the time it is being |
| 3907 | // referred to, the frame buffer it originally points to may |
| 3908 | // already get expired and have been reassigned to the current |
| 3909 | // newly coded frame. Hence, we need to check whether this is |
| 3910 | // the case, and if yes, we have 2 choices: |
| 3911 | // (1) Simply disable the use of previous frame mvs; or |
| 3912 | // (2) Have cm->prev_frame point to one reference frame buffer, |
| 3913 | // e.g. LAST_FRAME. |
David Barker | 40a42d4 | 2017-05-09 15:07:32 +0100 | [diff] [blame] | 3914 | if (!enc_is_ref_frame_buf(cpi, cm->prev_frame)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3915 | // Reassign the LAST_FRAME buffer to cm->prev_frame. |
David Barker | 40a42d4 | 2017-05-09 15:07:32 +0100 | [diff] [blame] | 3916 | cm->prev_frame = last_fb_buf_idx != INVALID_IDX |
| 3917 | ? &cm->buffer_pool->frame_bufs[last_fb_buf_idx] |
| 3918 | : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3919 | } |
David Barker | 40a42d4 | 2017-05-09 15:07:32 +0100 | [diff] [blame] | 3920 | |
| 3921 | #if CONFIG_TEMPMV_SIGNALING |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 3922 | cm->use_prev_frame_mvs &= frame_can_use_prev_frame_mvs(cm); |
David Barker | 40a42d4 | 2017-05-09 15:07:32 +0100 | [diff] [blame] | 3923 | #else |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3924 | if (cm->prev_frame) { |
| 3925 | cm->use_prev_frame_mvs = !cm->error_resilient_mode && |
| 3926 | #if CONFIG_FRAME_SUPERRES |
| 3927 | cm->width == cm->last_width && |
| 3928 | cm->height == cm->last_height && |
| 3929 | #else |
| 3930 | cm->width == cm->prev_frame->buf.y_crop_width && |
| 3931 | cm->height == cm->prev_frame->buf.y_crop_height && |
| 3932 | #endif // CONFIG_FRAME_SUPERRES |
| 3933 | !cm->intra_only && cm->last_show_frame; |
| 3934 | } else { |
| 3935 | cm->use_prev_frame_mvs = 0; |
| 3936 | } |
David Barker | 40a42d4 | 2017-05-09 15:07:32 +0100 | [diff] [blame] | 3937 | #endif // CONFIG_TEMPMV_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3938 | |
| 3939 | // Special case: set prev_mi to NULL when the previous mode info |
| 3940 | // context cannot be used. |
| 3941 | cm->prev_mi = |
| 3942 | cm->use_prev_frame_mvs ? cm->prev_mip + cm->mi_stride + 1 : NULL; |
| 3943 | |
Jingning Han | 9777afc | 2016-10-20 15:17:43 -0700 | [diff] [blame] | 3944 | x->txb_split_count = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3945 | av1_zero(x->blk_skip_drl); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3946 | |
Jingning Han | ea255c9 | 2017-09-29 08:12:09 -0700 | [diff] [blame] | 3947 | #if CONFIG_MFMV |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 3948 | av1_setup_motion_field(cm); |
Jingning Han | ea255c9 | 2017-09-29 08:12:09 -0700 | [diff] [blame] | 3949 | #endif // CONFIG_MFMV |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 3950 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3951 | { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3952 | struct aom_usec_timer emr_timer; |
| 3953 | aom_usec_timer_start(&emr_timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3954 | |
| 3955 | #if CONFIG_FP_MB_STATS |
| 3956 | if (cpi->use_fp_mb_stats) { |
| 3957 | input_fpmb_stats(&cpi->twopass.firstpass_mb_stats, cm, |
| 3958 | &cpi->twopass.this_frame_mb_stats); |
| 3959 | } |
| 3960 | #endif |
| 3961 | |
Yi Luo | f190a16 | 2017-07-13 16:16:56 -0700 | [diff] [blame] | 3962 | av1_setup_frame_boundary_info(cm); |
| 3963 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3964 | // If allowed, encoding tiles in parallel with one thread handling one tile. |
| 3965 | // TODO(geza.lore): The multi-threaded encoder is not safe with more than |
| 3966 | // 1 tile rows, as it uses the single above_context et al arrays from |
| 3967 | // cpi->common |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3968 | if (AOMMIN(cpi->oxcf.max_threads, cm->tile_cols) > 1 && cm->tile_rows == 1) |
| 3969 | av1_encode_tiles_mt(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3970 | else |
| 3971 | encode_tiles(cpi); |
| 3972 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3973 | aom_usec_timer_mark(&emr_timer); |
| 3974 | cpi->time_encode_sb_row += aom_usec_timer_elapsed(&emr_timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3975 | } |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3976 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 3977 | free_ncobmc_pred_buffer(xd); |
| 3978 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3979 | |
| 3980 | #if 0 |
| 3981 | // Keep record of the total distortion this time around for future use |
| 3982 | cpi->last_frame_distortion = cpi->frame_distortion; |
| 3983 | #endif |
| 3984 | } |
| 3985 | |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3986 | static void make_consistent_compound_tools(AV1_COMMON *cm) { |
| 3987 | (void)cm; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3988 | if (frame_is_intra_only(cm) || cm->reference_mode == COMPOUND_REFERENCE) |
| 3989 | cm->allow_interintra_compound = 0; |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 3990 | #if CONFIG_COMPOUND_SINGLEREF |
| 3991 | if (frame_is_intra_only(cm)) |
| 3992 | #else // !CONFIG_COMPOUND_SINGLEREF |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3993 | if (frame_is_intra_only(cm) || cm->reference_mode == SINGLE_REFERENCE) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 3994 | #endif // CONFIG_COMPOUND_SINGLEREF |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3995 | cm->allow_masked_compound = 0; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3996 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3997 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3998 | void av1_encode_frame(AV1_COMP *cpi) { |
| 3999 | AV1_COMMON *const cm = &cpi->common; |
Sarah Parker | e68a3e4 | 2017-02-16 14:03:24 -0800 | [diff] [blame] | 4000 | #if CONFIG_EXT_TX |
| 4001 | // Indicates whether or not to use a default reduced set for ext-tx |
| 4002 | // rather than the potential full set of 16 transforms |
| 4003 | cm->reduced_tx_set_used = 0; |
| 4004 | #endif // CONFIG_EXT_TX |
Angie Chiang | 6dbffbf | 2017-10-06 16:59:54 -0700 | [diff] [blame] | 4005 | #if CONFIG_ADAPT_SCAN |
| 4006 | cm->use_adapt_scan = 1; |
| 4007 | // TODO(angiebird): call av1_init_scan_order only when use_adapt_scan |
| 4008 | // switches from 1 to 0 |
| 4009 | if (cm->use_adapt_scan == 0) av1_init_scan_order(cm); |
| 4010 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4011 | |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 4012 | #if CONFIG_FRAME_MARKER |
| 4013 | if (cm->show_frame == 0) { |
| 4014 | int arf_offset = AOMMIN( |
| 4015 | (MAX_GF_INTERVAL - 1), |
| 4016 | cpi->twopass.gf_group.arf_src_offset[cpi->twopass.gf_group.index]); |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 4017 | int brf_offset = |
| 4018 | cpi->twopass.gf_group.brf_src_offset[cpi->twopass.gf_group.index]; |
| 4019 | arf_offset = AOMMIN((MAX_GF_INTERVAL - 1), arf_offset + brf_offset); |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 4020 | cm->frame_offset = cm->current_video_frame + arf_offset; |
| 4021 | } else { |
| 4022 | cm->frame_offset = cm->current_video_frame; |
| 4023 | } |
| 4024 | av1_setup_frame_buf_refs(cm); |
| 4025 | #if CONFIG_FRAME_SIGN_BIAS |
| 4026 | av1_setup_frame_sign_bias(cm); |
| 4027 | #endif // CONFIG_FRAME_SIGN_BIAS |
| 4028 | #endif // CONFIG_FRAME_MARKER |
| 4029 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4030 | // In the longer term the encoder should be generalized to match the |
| 4031 | // decoder such that we allow compound where one of the 3 buffers has a |
| 4032 | // different sign bias and that buffer is then the fixed ref. However, this |
| 4033 | // requires further work in the rd loop. For now the only supported encoder |
| 4034 | // side behavior is where the ALT ref buffer has opposite sign bias to |
| 4035 | // the other two. |
| 4036 | if (!frame_is_intra_only(cm)) { |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4037 | #if !CONFIG_ONE_SIDED_COMPOUND |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4038 | if ((cm->ref_frame_sign_bias[ALTREF_FRAME] == |
| 4039 | cm->ref_frame_sign_bias[GOLDEN_FRAME]) || |
| 4040 | (cm->ref_frame_sign_bias[ALTREF_FRAME] == |
| 4041 | cm->ref_frame_sign_bias[LAST_FRAME])) { |
| 4042 | cpi->allow_comp_inter_inter = 0; |
| 4043 | } else { |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4044 | #endif // !CONFIG_ONE_SIDED_COMPOUND |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4045 | cpi->allow_comp_inter_inter = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4046 | cm->comp_fwd_ref[0] = LAST_FRAME; |
| 4047 | cm->comp_fwd_ref[1] = LAST2_FRAME; |
| 4048 | cm->comp_fwd_ref[2] = LAST3_FRAME; |
| 4049 | cm->comp_fwd_ref[3] = GOLDEN_FRAME; |
| 4050 | cm->comp_bwd_ref[0] = BWDREF_FRAME; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4051 | cm->comp_bwd_ref[1] = ALTREF2_FRAME; |
| 4052 | cm->comp_bwd_ref[2] = ALTREF_FRAME; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4053 | #if !CONFIG_ONE_SIDED_COMPOUND // Normative in encoder |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4054 | } |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4055 | #endif // !CONFIG_ONE_SIDED_COMPOUND |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4056 | } else { |
| 4057 | cpi->allow_comp_inter_inter = 0; |
| 4058 | } |
| 4059 | |
| 4060 | if (cpi->sf.frame_parameter_update) { |
| 4061 | int i; |
| 4062 | RD_OPT *const rd_opt = &cpi->rd; |
| 4063 | FRAME_COUNTS *counts = cpi->td.counts; |
| 4064 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
| 4065 | |
| 4066 | // This code does a single RD pass over the whole frame assuming |
| 4067 | // either compound, single or hybrid prediction as per whatever has |
| 4068 | // worked best for that type of frame in the past. |
| 4069 | // It also predicts whether another coding mode would have worked |
| 4070 | // better than this coding mode. If that is the case, it remembers |
| 4071 | // that for subsequent frames. |
| 4072 | // It does the same analysis for transform size selection also. |
| 4073 | // |
| 4074 | // TODO(zoeliu): To investigate whether a frame_type other than |
| 4075 | // INTRA/ALTREF/GOLDEN/LAST needs to be specified seperately. |
| 4076 | const MV_REFERENCE_FRAME frame_type = get_frame_type(cpi); |
| 4077 | int64_t *const mode_thrs = rd_opt->prediction_type_threshes[frame_type]; |
| 4078 | const int is_alt_ref = frame_type == ALTREF_FRAME; |
| 4079 | |
Zoe Liu | b05e5d1 | 2017-02-07 14:32:53 -0800 | [diff] [blame] | 4080 | /* prediction (compound, single or hybrid) mode selection */ |
| 4081 | #if CONFIG_REF_ADAPT |
| 4082 | // NOTE(zoeliu): "is_alt_ref" is true only for OVERLAY/INTNL_OVERLAY frames |
| 4083 | if (is_alt_ref || !cpi->allow_comp_inter_inter) |
| 4084 | cm->reference_mode = SINGLE_REFERENCE; |
| 4085 | else |
| 4086 | cm->reference_mode = REFERENCE_MODE_SELECT; |
| 4087 | #else |
Todd Nguyen | 8493f91 | 2017-07-20 12:45:12 -0700 | [diff] [blame] | 4088 | #if CONFIG_BGSPRITE |
| 4089 | (void)is_alt_ref; |
| 4090 | if (!cpi->allow_comp_inter_inter) |
| 4091 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4092 | if (is_alt_ref || !cpi->allow_comp_inter_inter) |
Todd Nguyen | 8493f91 | 2017-07-20 12:45:12 -0700 | [diff] [blame] | 4093 | #endif // CONFIG_BGSPRITE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4094 | cm->reference_mode = SINGLE_REFERENCE; |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 4095 | #if !CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4096 | else if (mode_thrs[COMPOUND_REFERENCE] > mode_thrs[SINGLE_REFERENCE] && |
| 4097 | mode_thrs[COMPOUND_REFERENCE] > mode_thrs[REFERENCE_MODE_SELECT] && |
| 4098 | check_dual_ref_flags(cpi) && cpi->static_mb_pct == 100) |
| 4099 | cm->reference_mode = COMPOUND_REFERENCE; |
| 4100 | else if (mode_thrs[SINGLE_REFERENCE] > mode_thrs[REFERENCE_MODE_SELECT]) |
| 4101 | cm->reference_mode = SINGLE_REFERENCE; |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 4102 | #endif // CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4103 | else |
| 4104 | cm->reference_mode = REFERENCE_MODE_SELECT; |
Zoe Liu | b05e5d1 | 2017-02-07 14:32:53 -0800 | [diff] [blame] | 4105 | #endif // CONFIG_REF_ADAPT |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4106 | |
| 4107 | #if CONFIG_DUAL_FILTER |
| 4108 | cm->interp_filter = SWITCHABLE; |
| 4109 | #endif |
| 4110 | |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 4111 | make_consistent_compound_tools(cm); |
Arild Fuldseth (arilfuld) | 6c20c78 | 2017-06-15 09:45:02 +0200 | [diff] [blame] | 4112 | |
| 4113 | rdc->single_ref_used_flag = 0; |
| 4114 | rdc->compound_ref_used_flag = 0; |
| 4115 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4116 | encode_frame_internal(cpi); |
| 4117 | |
| 4118 | for (i = 0; i < REFERENCE_MODES; ++i) |
| 4119 | mode_thrs[i] = (mode_thrs[i] + rdc->comp_pred_diff[i] / cm->MBs) / 2; |
| 4120 | |
| 4121 | if (cm->reference_mode == REFERENCE_MODE_SELECT) { |
Arild Fuldseth (arilfuld) | 6c20c78 | 2017-06-15 09:45:02 +0200 | [diff] [blame] | 4122 | // Use a flag that includes 4x4 blocks |
| 4123 | if (rdc->compound_ref_used_flag == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4124 | cm->reference_mode = SINGLE_REFERENCE; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4125 | av1_zero(counts->comp_inter); |
Zoe Liu | b05e5d1 | 2017-02-07 14:32:53 -0800 | [diff] [blame] | 4126 | #if !CONFIG_REF_ADAPT |
Arild Fuldseth (arilfuld) | 6c20c78 | 2017-06-15 09:45:02 +0200 | [diff] [blame] | 4127 | // Use a flag that includes 4x4 blocks |
| 4128 | } else if (rdc->single_ref_used_flag == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4129 | cm->reference_mode = COMPOUND_REFERENCE; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4130 | av1_zero(counts->comp_inter); |
Zoe Liu | b05e5d1 | 2017-02-07 14:32:53 -0800 | [diff] [blame] | 4131 | #endif // !CONFIG_REF_ADAPT |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4132 | } |
| 4133 | } |
Debargha Mukherjee | 4374e43 | 2017-05-26 16:57:37 -0700 | [diff] [blame] | 4134 | make_consistent_compound_tools(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4135 | |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 4136 | #if CONFIG_RECT_TX_EXT |
| 4137 | if (cm->tx_mode == TX_MODE_SELECT && cpi->td.mb.txb_split_count == 0 && |
| 4138 | counts->quarter_tx_size[1] == 0) |
| 4139 | #else |
Jingning Han | 9777afc | 2016-10-20 15:17:43 -0700 | [diff] [blame] | 4140 | if (cm->tx_mode == TX_MODE_SELECT && cpi->td.mb.txb_split_count == 0) |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 4141 | #endif |
Debargha Mukherjee | 18d38f6 | 2016-11-17 20:30:16 -0800 | [diff] [blame] | 4142 | cm->tx_mode = ALLOW_32X32 + CONFIG_TX64X64; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4143 | } else { |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 4144 | make_consistent_compound_tools(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4145 | encode_frame_internal(cpi); |
| 4146 | } |
| 4147 | } |
| 4148 | |
Jingning Han | d3a6443 | 2017-04-06 17:04:17 -0700 | [diff] [blame] | 4149 | static void sum_intra_stats(FRAME_COUNTS *counts, MACROBLOCKD *xd, |
| 4150 | const MODE_INFO *mi, const MODE_INFO *above_mi, |
| 4151 | const MODE_INFO *left_mi, const int intraonly, |
| 4152 | const int mi_row, const int mi_col) { |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 4153 | FRAME_CONTEXT *fc = xd->tile_ctx; |
hui su | 4d668d7 | 2017-04-27 12:10:37 -0700 | [diff] [blame] | 4154 | const MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 4155 | const PREDICTION_MODE y_mode = mbmi->mode; |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 4156 | const UV_PREDICTION_MODE uv_mode = mbmi->uv_mode; |
Nathan E. Egge | 5bb3a74 | 2017-06-30 12:47:43 -0400 | [diff] [blame] | 4157 | (void)counts; |
hui su | 4d668d7 | 2017-04-27 12:10:37 -0700 | [diff] [blame] | 4158 | const BLOCK_SIZE bsize = mbmi->sb_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4159 | |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 4160 | if (intraonly) { |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 4161 | #if CONFIG_ENTROPY_STATS |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 4162 | const PREDICTION_MODE above = av1_above_block_mode(mi, above_mi, 0); |
| 4163 | const PREDICTION_MODE left = av1_left_block_mode(mi, left_mi, 0); |
| 4164 | ++counts->kf_y_mode[above][left][y_mode]; |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 4165 | #endif // CONFIG_ENTROPY_STATS |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 4166 | update_cdf(get_y_mode_cdf(fc, mi, above_mi, left_mi, 0), y_mode, |
| 4167 | INTRA_MODES); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4168 | } else { |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 4169 | #if CONFIG_ENTROPY_STATS |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 4170 | ++counts->y_mode[size_group_lookup[bsize]][y_mode]; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 4171 | #endif // CONFIG_ENTROPY_STATS |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 4172 | update_cdf(fc->y_mode_cdf[size_group_lookup[bsize]], y_mode, INTRA_MODES); |
| 4173 | } |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 4174 | |
hui su | 4d668d7 | 2017-04-27 12:10:37 -0700 | [diff] [blame] | 4175 | #if CONFIG_FILTER_INTRA |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 4176 | if (mbmi->mode == DC_PRED && mbmi->palette_mode_info.palette_size[0] == 0) { |
| 4177 | const int use_filter_intra_mode = |
| 4178 | mbmi->filter_intra_mode_info.use_filter_intra_mode[0]; |
| 4179 | ++counts->filter_intra[0][use_filter_intra_mode]; |
Yue Chen | 57b8ff6 | 2017-10-10 23:37:31 -0700 | [diff] [blame] | 4180 | #if CONFIG_ENTROPY_STATS |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 4181 | ++counts->filter_intra_mode[0][mbmi->filter_intra_mode_info |
| 4182 | .filter_intra_mode[0]]; |
Yue Chen | 57b8ff6 | 2017-10-10 23:37:31 -0700 | [diff] [blame] | 4183 | #endif // CONFIG_ENTROPY_STATS |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 4184 | update_cdf(fc->filter_intra_mode_cdf[0], |
| 4185 | mbmi->filter_intra_mode_info.filter_intra_mode[0], |
| 4186 | FILTER_INTRA_MODES); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4187 | } |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 4188 | #endif // CONFIG_FILTER_INTRA |
Joe Young | 3ca43bf | 2017-10-06 15:12:46 -0700 | [diff] [blame] | 4189 | #if CONFIG_EXT_INTRA && CONFIG_EXT_INTRA_MOD |
| 4190 | if (av1_is_directional_mode(mbmi->mode, bsize) && |
| 4191 | av1_use_angle_delta(bsize)) { |
| 4192 | #if CONFIG_ENTROPY_STATS |
| 4193 | ++counts->angle_delta[mbmi->mode - V_PRED] |
| 4194 | [mbmi->angle_delta[0] + MAX_ANGLE_DELTA]; |
| 4195 | #endif |
| 4196 | update_cdf(fc->angle_delta_cdf[mbmi->mode - V_PRED], |
| 4197 | mbmi->angle_delta[0] + MAX_ANGLE_DELTA, 2 * MAX_ANGLE_DELTA + 1); |
| 4198 | } |
| 4199 | #endif // CONFIG_EXT_INTRA && CONFIG_EXT_INTRA_MOD |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4200 | |
Jingning Han | d3a6443 | 2017-04-06 17:04:17 -0700 | [diff] [blame] | 4201 | if (!is_chroma_reference(mi_row, mi_col, bsize, xd->plane[1].subsampling_x, |
| 4202 | xd->plane[1].subsampling_y)) |
| 4203 | return; |
Joe Young | 3ca43bf | 2017-10-06 15:12:46 -0700 | [diff] [blame] | 4204 | #if CONFIG_EXT_INTRA && CONFIG_EXT_INTRA_MOD |
| 4205 | if (av1_is_directional_mode(mbmi->uv_mode, bsize) && |
| 4206 | av1_use_angle_delta(bsize)) { |
| 4207 | #if CONFIG_ENTROPY_STATS |
| 4208 | ++counts->angle_delta[mbmi->uv_mode - V_PRED] |
| 4209 | [mbmi->angle_delta[1] + MAX_ANGLE_DELTA]; |
| 4210 | #endif |
| 4211 | update_cdf(fc->angle_delta_cdf[mbmi->uv_mode - V_PRED], |
| 4212 | mbmi->angle_delta[1] + MAX_ANGLE_DELTA, 2 * MAX_ANGLE_DELTA + 1); |
| 4213 | } |
| 4214 | #endif // CONFIG_EXT_INTRA && CONFIG_EXT_INTRA_MOD |
Nathan E. Egge | 6bdc40f | 2017-06-18 19:02:23 -0400 | [diff] [blame] | 4215 | #if CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4216 | ++counts->uv_mode[y_mode][uv_mode]; |
Nathan E. Egge | 6bdc40f | 2017-06-18 19:02:23 -0400 | [diff] [blame] | 4217 | #endif // CONFIG_ENTROPY_STATS |
Hui Su | 814f41e | 2017-10-02 12:21:24 -0700 | [diff] [blame] | 4218 | update_cdf(fc->uv_mode_cdf[y_mode], uv_mode, UV_INTRA_MODES); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4219 | } |
| 4220 | |
Yue Chen | dab2ca9 | 2017-10-16 17:48:48 -0700 | [diff] [blame] | 4221 | #if CONFIG_NEW_MULTISYMBOL |
| 4222 | // TODO(anybody) We can add stats accumulation here to train entropy models for |
| 4223 | // palette modes |
| 4224 | static void update_palette_cdf(MACROBLOCKD *xd, const MODE_INFO *mi) { |
| 4225 | FRAME_CONTEXT *fc = xd->tile_ctx; |
| 4226 | const MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 4227 | const MODE_INFO *const above_mi = xd->above_mi; |
| 4228 | const MODE_INFO *const left_mi = xd->left_mi; |
| 4229 | const BLOCK_SIZE bsize = mbmi->sb_type; |
| 4230 | const PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info; |
| 4231 | |
| 4232 | assert(bsize >= BLOCK_8X8 && bsize <= BLOCK_LARGEST); |
| 4233 | const int block_palette_idx = bsize - BLOCK_8X8; |
| 4234 | |
| 4235 | if (mbmi->mode == DC_PRED) { |
| 4236 | const int n = pmi->palette_size[0]; |
| 4237 | int palette_y_mode_ctx = 0; |
| 4238 | if (above_mi) { |
| 4239 | palette_y_mode_ctx += |
| 4240 | (above_mi->mbmi.palette_mode_info.palette_size[0] > 0); |
| 4241 | } |
| 4242 | if (left_mi) { |
| 4243 | palette_y_mode_ctx += |
| 4244 | (left_mi->mbmi.palette_mode_info.palette_size[0] > 0); |
| 4245 | } |
| 4246 | update_cdf(fc->palette_y_mode_cdf[block_palette_idx][palette_y_mode_ctx], |
| 4247 | n > 0, 2); |
| 4248 | } |
| 4249 | |
| 4250 | if (mbmi->uv_mode == UV_DC_PRED) { |
| 4251 | const int n = pmi->palette_size[1]; |
| 4252 | const int palette_uv_mode_ctx = (pmi->palette_size[0] > 0); |
| 4253 | update_cdf(fc->palette_uv_mode_cdf[palette_uv_mode_ctx], n > 0, 2); |
| 4254 | } |
| 4255 | } |
| 4256 | #endif |
| 4257 | |
Jingning Han | 9777afc | 2016-10-20 15:17:43 -0700 | [diff] [blame] | 4258 | static void update_txfm_count(MACROBLOCK *x, MACROBLOCKD *xd, |
Jingning Han | c8b8936 | 2016-11-01 10:28:53 -0700 | [diff] [blame] | 4259 | FRAME_COUNTS *counts, TX_SIZE tx_size, int depth, |
Jingning Han | 9777afc | 2016-10-20 15:17:43 -0700 | [diff] [blame] | 4260 | int blk_row, int blk_col) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4261 | MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
| 4262 | const int tx_row = blk_row >> 1; |
| 4263 | const int tx_col = blk_col >> 1; |
Jingning Han | f65b870 | 2016-10-31 12:13:20 -0700 | [diff] [blame] | 4264 | const int max_blocks_high = max_block_high(xd, mbmi->sb_type, 0); |
| 4265 | const int max_blocks_wide = max_block_wide(xd, mbmi->sb_type, 0); |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 4266 | int ctx = txfm_partition_context(xd->above_txfm_context + blk_col, |
| 4267 | xd->left_txfm_context + blk_row, |
Jingning Han | c8b8936 | 2016-11-01 10:28:53 -0700 | [diff] [blame] | 4268 | mbmi->sb_type, tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4269 | const TX_SIZE plane_tx_size = mbmi->inter_tx_size[tx_row][tx_col]; |
| 4270 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4271 | if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return; |
David Barker | 16c64e3 | 2017-08-23 16:54:59 +0100 | [diff] [blame] | 4272 | assert(tx_size > TX_4X4); |
| 4273 | |
| 4274 | if (depth == MAX_VARTX_DEPTH) { |
| 4275 | // Don't add to counts in this case |
| 4276 | #if CONFIG_RECT_TX_EXT |
| 4277 | if (tx_size == plane_tx_size) |
| 4278 | #endif |
| 4279 | mbmi->tx_size = tx_size; |
| 4280 | txfm_partition_update(xd->above_txfm_context + blk_col, |
| 4281 | xd->left_txfm_context + blk_row, tx_size, tx_size); |
| 4282 | return; |
| 4283 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4284 | |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 4285 | #if CONFIG_RECT_TX_EXT |
| 4286 | if (tx_size == plane_tx_size || |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 4287 | mbmi->tx_size == quarter_txsize_lookup[mbmi->sb_type]) |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 4288 | #else |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 4289 | if (tx_size == plane_tx_size) |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 4290 | #endif |
Cheng Chen | 50b0f6c | 2017-08-03 12:25:03 -0700 | [diff] [blame] | 4291 | { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4292 | ++counts->txfm_partition[ctx][0]; |
Yue Chen | 171c17d | 2017-10-16 18:08:22 -0700 | [diff] [blame] | 4293 | #if CONFIG_NEW_MULTISYMBOL |
| 4294 | update_cdf(xd->tile_ctx->txfm_partition_cdf[ctx], 0, 2); |
| 4295 | #endif |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 4296 | #if CONFIG_RECT_TX_EXT |
| 4297 | if (tx_size == plane_tx_size) |
| 4298 | #endif |
| 4299 | mbmi->tx_size = tx_size; |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 4300 | txfm_partition_update(xd->above_txfm_context + blk_col, |
| 4301 | xd->left_txfm_context + blk_row, tx_size, tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4302 | } else { |
Jingning Han | a933632 | 2016-11-02 15:45:07 -0700 | [diff] [blame] | 4303 | const TX_SIZE sub_txs = sub_tx_size_map[tx_size]; |
| 4304 | const int bs = tx_size_wide_unit[sub_txs]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4305 | int i; |
Jingning Han | a933632 | 2016-11-02 15:45:07 -0700 | [diff] [blame] | 4306 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4307 | ++counts->txfm_partition[ctx][1]; |
Yue Chen | 171c17d | 2017-10-16 18:08:22 -0700 | [diff] [blame] | 4308 | #if CONFIG_NEW_MULTISYMBOL |
| 4309 | update_cdf(xd->tile_ctx->txfm_partition_cdf[ctx], 1, 2); |
| 4310 | #endif |
Jingning Han | 9777afc | 2016-10-20 15:17:43 -0700 | [diff] [blame] | 4311 | ++x->txb_split_count; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4312 | |
David Barker | 16c64e3 | 2017-08-23 16:54:59 +0100 | [diff] [blame] | 4313 | if (sub_txs == TX_4X4) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4314 | mbmi->inter_tx_size[tx_row][tx_col] = TX_4X4; |
| 4315 | mbmi->tx_size = TX_4X4; |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 4316 | txfm_partition_update(xd->above_txfm_context + blk_col, |
| 4317 | xd->left_txfm_context + blk_row, TX_4X4, tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4318 | return; |
| 4319 | } |
| 4320 | |
| 4321 | for (i = 0; i < 4; ++i) { |
Jingning Han | a933632 | 2016-11-02 15:45:07 -0700 | [diff] [blame] | 4322 | int offsetr = (i >> 1) * bs; |
| 4323 | int offsetc = (i & 0x01) * bs; |
| 4324 | update_txfm_count(x, xd, counts, sub_txs, depth + 1, blk_row + offsetr, |
| 4325 | blk_col + offsetc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4326 | } |
| 4327 | } |
| 4328 | } |
| 4329 | |
Jingning Han | 9777afc | 2016-10-20 15:17:43 -0700 | [diff] [blame] | 4330 | static void tx_partition_count_update(const AV1_COMMON *const cm, MACROBLOCK *x, |
| 4331 | BLOCK_SIZE plane_bsize, int mi_row, |
| 4332 | int mi_col, FRAME_COUNTS *td_counts) { |
| 4333 | MACROBLOCKD *xd = &x->e_mbd; |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 4334 | const int mi_width = block_size_wide[plane_bsize] >> tx_size_wide_log2[0]; |
| 4335 | const int mi_height = block_size_high[plane_bsize] >> tx_size_wide_log2[0]; |
Rupert Swarbrick | 4e7b7d6 | 2017-09-28 17:30:44 +0100 | [diff] [blame] | 4336 | TX_SIZE max_tx_size = get_vartx_max_txsize(&xd->mi[0]->mbmi, plane_bsize, 0); |
Jingning Han | a933632 | 2016-11-02 15:45:07 -0700 | [diff] [blame] | 4337 | const int bh = tx_size_high_unit[max_tx_size]; |
| 4338 | const int bw = tx_size_wide_unit[max_tx_size]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4339 | int idx, idy; |
Sarah Parker | d25ef8c | 2017-10-06 12:17:30 -0700 | [diff] [blame] | 4340 | int init_depth = |
| 4341 | (mi_height != mi_width) ? RECT_VARTX_DEPTH_INIT : SQR_VARTX_DEPTH_INIT; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4342 | |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 4343 | xd->above_txfm_context = |
| 4344 | cm->above_txfm_context + (mi_col << TX_UNIT_WIDE_LOG2); |
| 4345 | xd->left_txfm_context = xd->left_txfm_context_buffer + |
| 4346 | ((mi_row & MAX_MIB_MASK) << TX_UNIT_HIGH_LOG2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4347 | |
| 4348 | for (idy = 0; idy < mi_height; idy += bh) |
Jingning Han | a933632 | 2016-11-02 15:45:07 -0700 | [diff] [blame] | 4349 | for (idx = 0; idx < mi_width; idx += bw) |
Sarah Parker | d25ef8c | 2017-10-06 12:17:30 -0700 | [diff] [blame] | 4350 | update_txfm_count(x, xd, td_counts, max_tx_size, init_depth, idy, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | static void set_txfm_context(MACROBLOCKD *xd, TX_SIZE tx_size, int blk_row, |
| 4354 | int blk_col) { |
| 4355 | MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
| 4356 | const int tx_row = blk_row >> 1; |
| 4357 | const int tx_col = blk_col >> 1; |
Jingning Han | f65b870 | 2016-10-31 12:13:20 -0700 | [diff] [blame] | 4358 | const int max_blocks_high = max_block_high(xd, mbmi->sb_type, 0); |
| 4359 | const int max_blocks_wide = max_block_wide(xd, mbmi->sb_type, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4360 | const TX_SIZE plane_tx_size = mbmi->inter_tx_size[tx_row][tx_col]; |
| 4361 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4362 | if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return; |
| 4363 | |
| 4364 | if (tx_size == plane_tx_size) { |
| 4365 | mbmi->tx_size = tx_size; |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 4366 | txfm_partition_update(xd->above_txfm_context + blk_col, |
| 4367 | xd->left_txfm_context + blk_row, tx_size, tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4368 | |
| 4369 | } else { |
Jingning Han | a933632 | 2016-11-02 15:45:07 -0700 | [diff] [blame] | 4370 | const TX_SIZE sub_txs = sub_tx_size_map[tx_size]; |
| 4371 | const int bsl = tx_size_wide_unit[sub_txs]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4372 | int i; |
| 4373 | |
| 4374 | if (tx_size == TX_8X8) { |
| 4375 | mbmi->inter_tx_size[tx_row][tx_col] = TX_4X4; |
| 4376 | mbmi->tx_size = TX_4X4; |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 4377 | txfm_partition_update(xd->above_txfm_context + blk_col, |
| 4378 | xd->left_txfm_context + blk_row, TX_4X4, tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4379 | return; |
| 4380 | } |
| 4381 | |
| 4382 | assert(bsl > 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4383 | for (i = 0; i < 4; ++i) { |
Jingning Han | a933632 | 2016-11-02 15:45:07 -0700 | [diff] [blame] | 4384 | int offsetr = (i >> 1) * bsl; |
| 4385 | int offsetc = (i & 0x01) * bsl; |
| 4386 | set_txfm_context(xd, sub_txs, blk_row + offsetr, blk_col + offsetc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4387 | } |
| 4388 | } |
| 4389 | } |
| 4390 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 4391 | static void tx_partition_set_contexts(const AV1_COMMON *const cm, |
| 4392 | MACROBLOCKD *xd, BLOCK_SIZE plane_bsize, |
| 4393 | int mi_row, int mi_col) { |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 4394 | const int mi_width = block_size_wide[plane_bsize] >> tx_size_wide_log2[0]; |
| 4395 | const int mi_height = block_size_high[plane_bsize] >> tx_size_high_log2[0]; |
Rupert Swarbrick | 4e7b7d6 | 2017-09-28 17:30:44 +0100 | [diff] [blame] | 4396 | TX_SIZE max_tx_size = get_vartx_max_txsize(&xd->mi[0]->mbmi, plane_bsize, 0); |
Jingning Han | a933632 | 2016-11-02 15:45:07 -0700 | [diff] [blame] | 4397 | const int bh = tx_size_high_unit[max_tx_size]; |
| 4398 | const int bw = tx_size_wide_unit[max_tx_size]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4399 | int idx, idy; |
| 4400 | |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 4401 | xd->above_txfm_context = |
| 4402 | cm->above_txfm_context + (mi_col << TX_UNIT_WIDE_LOG2); |
| 4403 | xd->left_txfm_context = xd->left_txfm_context_buffer + |
| 4404 | ((mi_row & MAX_MIB_MASK) << TX_UNIT_HIGH_LOG2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4405 | |
| 4406 | for (idy = 0; idy < mi_height; idy += bh) |
Jingning Han | a933632 | 2016-11-02 15:45:07 -0700 | [diff] [blame] | 4407 | for (idx = 0; idx < mi_width; idx += bw) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4408 | set_txfm_context(xd, max_tx_size, idy, idx); |
| 4409 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4410 | |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4411 | void av1_update_tx_type_count(const AV1_COMMON *cm, MACROBLOCKD *xd, |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 4412 | #if CONFIG_TXK_SEL |
Jingning Han | 7eab9ff | 2017-07-06 10:12:54 -0700 | [diff] [blame] | 4413 | int blk_row, int blk_col, int block, int plane, |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4414 | #endif |
| 4415 | BLOCK_SIZE bsize, TX_SIZE tx_size, |
| 4416 | FRAME_COUNTS *counts) { |
| 4417 | MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
| 4418 | int is_inter = is_inter_block(mbmi); |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 4419 | FRAME_CONTEXT *fc = xd->tile_ctx; |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 4420 | #if !CONFIG_ENTROPY_STATS |
| 4421 | (void)counts; |
| 4422 | #endif // !CONFIG_ENTROPY_STATS |
Jingning Han | 243b66b | 2017-06-23 12:11:47 -0700 | [diff] [blame] | 4423 | |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 4424 | #if !CONFIG_TXK_SEL |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4425 | TX_TYPE tx_type = mbmi->tx_type; |
| 4426 | #else |
Jingning Han | 7eab9ff | 2017-07-06 10:12:54 -0700 | [diff] [blame] | 4427 | (void)blk_row; |
| 4428 | (void)blk_col; |
Angie Chiang | 39b06eb | 2017-04-14 09:52:29 -0700 | [diff] [blame] | 4429 | // Only y plane's tx_type is updated |
| 4430 | if (plane > 0) return; |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 4431 | TX_TYPE tx_type = |
| 4432 | av1_get_tx_type(PLANE_TYPE_Y, xd, blk_row, blk_col, block, tx_size); |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4433 | #endif |
| 4434 | #if CONFIG_EXT_TX |
| 4435 | if (get_ext_tx_types(tx_size, bsize, is_inter, cm->reduced_tx_set_used) > 1 && |
| 4436 | cm->base_qindex > 0 && !mbmi->skip && |
| 4437 | !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
| 4438 | const int eset = |
| 4439 | get_ext_tx_set(tx_size, bsize, is_inter, cm->reduced_tx_set_used); |
| 4440 | if (eset > 0) { |
Lester Lu | 432012f | 2017-08-17 14:39:29 -0700 | [diff] [blame] | 4441 | #if !CONFIG_LGT_FROM_PRED |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 4442 | const TxSetType tx_set_type = get_ext_tx_set_type( |
| 4443 | tx_size, bsize, is_inter, cm->reduced_tx_set_used); |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4444 | if (is_inter) { |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 4445 | update_cdf(fc->inter_ext_tx_cdf[eset][txsize_sqr_map[tx_size]], |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 4446 | av1_ext_tx_ind[tx_set_type][tx_type], |
| 4447 | av1_num_ext_tx_set[tx_set_type]); |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 4448 | #if CONFIG_ENTROPY_STATS |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4449 | ++counts->inter_ext_tx[eset][txsize_sqr_map[tx_size]][tx_type]; |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 4450 | #endif // CONFIG_ENTROPY_STATS |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4451 | } else { |
Yue Chen | 57b8ff6 | 2017-10-10 23:37:31 -0700 | [diff] [blame] | 4452 | #if CONFIG_FILTER_INTRA |
| 4453 | PREDICTION_MODE intra_dir; |
| 4454 | if (mbmi->filter_intra_mode_info.use_filter_intra_mode[0]) |
| 4455 | intra_dir = fimode_to_intradir[mbmi->filter_intra_mode_info |
| 4456 | .filter_intra_mode[0]]; |
| 4457 | else |
| 4458 | intra_dir = mbmi->mode; |
| 4459 | #if CONFIG_ENTROPY_STATS |
| 4460 | ++counts |
| 4461 | ->intra_ext_tx[eset][txsize_sqr_map[tx_size]][intra_dir][tx_type]; |
| 4462 | #endif // CONFIG_ENTROPY_STATS |
| 4463 | update_cdf( |
| 4464 | fc->intra_ext_tx_cdf[eset][txsize_sqr_map[tx_size]][intra_dir], |
| 4465 | av1_ext_tx_ind[tx_set_type][tx_type], |
| 4466 | av1_num_ext_tx_set[tx_set_type]); |
| 4467 | #else |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 4468 | #if CONFIG_ENTROPY_STATS |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4469 | ++counts->intra_ext_tx[eset][txsize_sqr_map[tx_size]][mbmi->mode] |
| 4470 | [tx_type]; |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 4471 | #endif // CONFIG_ENTROPY_STATS |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 4472 | update_cdf( |
| 4473 | fc->intra_ext_tx_cdf[eset][txsize_sqr_map[tx_size]][mbmi->mode], |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 4474 | av1_ext_tx_ind[tx_set_type][tx_type], |
| 4475 | av1_num_ext_tx_set[tx_set_type]); |
Yue Chen | 57b8ff6 | 2017-10-10 23:37:31 -0700 | [diff] [blame] | 4476 | #endif |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4477 | } |
Lester Lu | 432012f | 2017-08-17 14:39:29 -0700 | [diff] [blame] | 4478 | #else |
| 4479 | (void)tx_type; |
| 4480 | (void)fc; |
| 4481 | if (is_inter) { |
| 4482 | if (LGT_FROM_PRED_INTER) { |
| 4483 | if (is_lgt_allowed(mbmi->mode, tx_size) && !cm->reduced_tx_set_used) |
| 4484 | ++counts->inter_lgt[txsize_sqr_map[tx_size]][mbmi->use_lgt]; |
| 4485 | #if CONFIG_ENTROPY_STATS |
| 4486 | if (!mbmi->use_lgt) |
| 4487 | ++counts->inter_ext_tx[eset][txsize_sqr_map[tx_size]][tx_type]; |
| 4488 | else |
| 4489 | #endif // CONFIG_ENTROPY_STATS |
| 4490 | mbmi->tx_type = DCT_DCT; |
| 4491 | } else { |
| 4492 | #if CONFIG_ENTROPY_STATS |
| 4493 | ++counts->inter_ext_tx[eset][txsize_sqr_map[tx_size]][tx_type]; |
| 4494 | #endif // CONFIG_ENTROPY_STATS |
| 4495 | } |
| 4496 | } else { |
| 4497 | if (LGT_FROM_PRED_INTRA) { |
| 4498 | if (is_lgt_allowed(mbmi->mode, tx_size) && !cm->reduced_tx_set_used) |
| 4499 | ++counts->intra_lgt[txsize_sqr_map[tx_size]][mbmi->mode] |
| 4500 | [mbmi->use_lgt]; |
| 4501 | #if CONFIG_ENTROPY_STATS |
| 4502 | if (!mbmi->use_lgt) |
| 4503 | ++counts->intra_ext_tx[eset][txsize_sqr_map[tx_size]][mbmi->mode] |
| 4504 | [tx_type]; |
| 4505 | else |
| 4506 | #endif // CONFIG_ENTROPY_STATS |
| 4507 | mbmi->tx_type = DCT_DCT; |
| 4508 | } else { |
| 4509 | #if CONFIG_ENTROPY_STATS |
| 4510 | ++counts->intra_ext_tx[eset][txsize_sqr_map[tx_size]][mbmi->mode] |
| 4511 | [tx_type]; |
| 4512 | #endif // CONFIG_ENTROPY_STATS |
| 4513 | } |
| 4514 | } |
| 4515 | #endif // CONFIG_LGT_FROM_PRED |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4516 | } |
| 4517 | } |
| 4518 | #else |
| 4519 | (void)bsize; |
| 4520 | if (tx_size < TX_32X32 && |
| 4521 | ((!cm->seg.enabled && cm->base_qindex > 0) || |
| 4522 | (cm->seg.enabled && xd->qindex[mbmi->segment_id] > 0)) && |
| 4523 | !mbmi->skip && |
| 4524 | !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
| 4525 | if (is_inter) { |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 4526 | #if CONFIG_ENTROPY_STATS |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4527 | ++counts->inter_ext_tx[tx_size][tx_type]; |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 4528 | #endif // CONFIG_ENTROPY_STATS |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 4529 | update_cdf(fc->inter_ext_tx_cdf[tx_size], av1_ext_tx_ind[tx_type], |
| 4530 | TX_TYPES); |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4531 | } else { |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 4532 | #if CONFIG_ENTROPY_STATS |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4533 | ++counts->intra_ext_tx[tx_size][intra_mode_to_tx_type_context[mbmi->mode]] |
| 4534 | [tx_type]; |
Hui Su | 98b0b3e | 2017-09-19 13:54:02 -0700 | [diff] [blame] | 4535 | #endif // CONFIG_ENTROPY_STATS |
Yue Chen | a424551 | 2017-08-31 11:58:08 -0700 | [diff] [blame] | 4536 | update_cdf( |
| 4537 | fc->intra_ext_tx_cdf[tx_size] |
| 4538 | [intra_mode_to_tx_type_context[mbmi->mode]], |
| 4539 | av1_ext_tx_ind[tx_type], TX_TYPES); |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4540 | } |
| 4541 | } |
| 4542 | #endif // CONFIG_EXT_TX |
| 4543 | } |
| 4544 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 4545 | static void encode_superblock(const AV1_COMP *const cpi, ThreadData *td, |
| 4546 | TOKENEXTRA **t, RUN_TYPE dry_run, int mi_row, |
Yushin Cho | 6d72a2f | 2017-05-03 17:37:37 -0700 | [diff] [blame] | 4547 | int mi_col, BLOCK_SIZE bsize, int *rate) { |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 4548 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4549 | MACROBLOCK *const x = &td->mb; |
| 4550 | MACROBLOCKD *const xd = &x->e_mbd; |
| 4551 | MODE_INFO **mi_8x8 = xd->mi; |
| 4552 | MODE_INFO *mi = mi_8x8[0]; |
| 4553 | MB_MODE_INFO *mbmi = &mi->mbmi; |
| 4554 | const int seg_skip = |
| 4555 | segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP); |
| 4556 | const int mis = cm->mi_stride; |
Jingning Han | c709e1f | 2016-12-06 14:48:09 -0800 | [diff] [blame] | 4557 | const int mi_width = mi_size_wide[bsize]; |
| 4558 | const int mi_height = mi_size_high[bsize]; |
Jingning Han | 94ea1aa | 2016-11-08 12:10:46 -0800 | [diff] [blame] | 4559 | const int is_inter = is_inter_block(mbmi); |
Jingning Han | bf9c6b7 | 2016-12-14 14:50:45 -0800 | [diff] [blame] | 4560 | const BLOCK_SIZE block_size = bsize; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4561 | |
Jingning Han | 94ea1aa | 2016-11-08 12:10:46 -0800 | [diff] [blame] | 4562 | if (!is_inter) { |
Luc Trudeau | 32306c2 | 2017-08-14 14:44:26 -0400 | [diff] [blame] | 4563 | #if CONFIG_CFL |
Luc Trudeau | b05eeae | 2017-08-18 15:14:30 -0400 | [diff] [blame] | 4564 | xd->cfl->store_y = 1; |
Luc Trudeau | 32306c2 | 2017-08-14 14:44:26 -0400 | [diff] [blame] | 4565 | #endif // CONFIG_CFL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4566 | int plane; |
| 4567 | mbmi->skip = 1; |
hui su | 4d668d7 | 2017-04-27 12:10:37 -0700 | [diff] [blame] | 4568 | for (plane = 0; plane < MAX_MB_PLANE; ++plane) { |
Jingning Han | 18c53c8 | 2017-02-17 14:49:57 -0800 | [diff] [blame] | 4569 | av1_encode_intra_block_plane((AV1_COMMON *)cm, x, block_size, plane, 1, |
| 4570 | mi_row, mi_col); |
hui su | 4d668d7 | 2017-04-27 12:10:37 -0700 | [diff] [blame] | 4571 | } |
Luc Trudeau | 32306c2 | 2017-08-14 14:44:26 -0400 | [diff] [blame] | 4572 | #if CONFIG_CFL |
Luc Trudeau | fcca37a | 2017-08-14 15:05:07 -0400 | [diff] [blame] | 4573 | xd->cfl->store_y = 0; |
Luc Trudeau | 32306c2 | 2017-08-14 14:44:26 -0400 | [diff] [blame] | 4574 | #endif // CONFIG_CFL |
hui su | 4d668d7 | 2017-04-27 12:10:37 -0700 | [diff] [blame] | 4575 | if (!dry_run) { |
Jingning Han | d3a6443 | 2017-04-06 17:04:17 -0700 | [diff] [blame] | 4576 | sum_intra_stats(td->counts, xd, mi, xd->above_mi, xd->left_mi, |
Jingning Han | 36fe320 | 2017-02-20 22:31:49 -0800 | [diff] [blame] | 4577 | frame_is_intra_only(cm), mi_row, mi_col); |
Yue Chen | dab2ca9 | 2017-10-16 17:48:48 -0700 | [diff] [blame] | 4578 | #if CONFIG_NEW_MULTISYMBOL |
| 4579 | if (av1_allow_palette(cm->allow_screen_content_tools, bsize)) |
| 4580 | update_palette_cdf(xd, mi); |
| 4581 | #endif |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 4582 | } |
Yushin Cho | a881039 | 2017-09-06 15:16:14 -0700 | [diff] [blame] | 4583 | |
Sarah Parker | 9c0e451 | 2017-08-15 16:23:53 -0700 | [diff] [blame] | 4584 | if (bsize >= BLOCK_8X8) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4585 | for (plane = 0; plane <= 1; ++plane) { |
Sarah Parker | 9c0e451 | 2017-08-15 16:23:53 -0700 | [diff] [blame] | 4586 | if (mbmi->palette_mode_info.palette_size[plane] > 0) { |
| 4587 | if (!dry_run) |
Sarah Parker | 99e7daa | 2017-08-29 10:30:13 -0700 | [diff] [blame] | 4588 | av1_tokenize_color_map(x, plane, 0, t, bsize, mbmi->tx_size, |
| 4589 | PALETTE_MAP); |
Sarah Parker | 9c0e451 | 2017-08-15 16:23:53 -0700 | [diff] [blame] | 4590 | else if (dry_run == DRY_RUN_COSTCOEFFS) |
Sarah Parker | 99e7daa | 2017-08-29 10:30:13 -0700 | [diff] [blame] | 4591 | rate += av1_cost_color_map(x, plane, 0, bsize, mbmi->tx_size, |
| 4592 | PALETTE_MAP); |
Sarah Parker | 9c0e451 | 2017-08-15 16:23:53 -0700 | [diff] [blame] | 4593 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4594 | } |
| 4595 | } |
Yushin Cho | a881039 | 2017-09-06 15:16:14 -0700 | [diff] [blame] | 4596 | |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 4597 | mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size); |
Angie Chiang | 0397eda | 2017-03-15 16:57:14 -0700 | [diff] [blame] | 4598 | #if CONFIG_LV_MAP |
| 4599 | av1_update_txb_context(cpi, td, dry_run, block_size, rate, mi_row, mi_col); |
| 4600 | #else // CONFIG_LV_MAP |
Jingning Han | 18c53c8 | 2017-02-17 14:49:57 -0800 | [diff] [blame] | 4601 | av1_tokenize_sb(cpi, td, t, dry_run, block_size, rate, mi_row, mi_col); |
Angie Chiang | 0397eda | 2017-03-15 16:57:14 -0700 | [diff] [blame] | 4602 | #endif // CONFIG_LV_MAP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4603 | } else { |
| 4604 | int ref; |
| 4605 | const int is_compound = has_second_ref(mbmi); |
| 4606 | |
| 4607 | set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); |
| 4608 | for (ref = 0; ref < 1 + is_compound; ++ref) { |
| 4609 | YV12_BUFFER_CONFIG *cfg = get_ref_frame_buffer(cpi, mbmi->ref_frame[ref]); |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 4610 | #if CONFIG_INTRABC |
| 4611 | assert(IMPLIES(!is_intrabc_block(mbmi), cfg)); |
| 4612 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4613 | assert(cfg != NULL); |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 4614 | #endif // !CONFIG_INTRABC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4615 | av1_setup_pre_planes(xd, ref, cfg, mi_row, mi_col, |
| 4616 | &xd->block_refs[ref]->sf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4617 | } |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 4618 | #if CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 4619 | // Single ref compound mode |
| 4620 | if (!is_compound && is_inter_singleref_comp_mode(mbmi->mode)) { |
| 4621 | xd->block_refs[1] = xd->block_refs[0]; |
| 4622 | YV12_BUFFER_CONFIG *cfg = get_ref_frame_buffer(cpi, mbmi->ref_frame[0]); |
| 4623 | #if CONFIG_INTRABC |
| 4624 | assert(IMPLIES(!is_intrabc_block(mbmi), cfg)); |
| 4625 | #else |
| 4626 | assert(cfg != NULL); |
| 4627 | #endif // !CONFIG_INTRABC |
| 4628 | av1_setup_pre_planes(xd, 1, cfg, mi_row, mi_col, &xd->block_refs[1]->sf); |
| 4629 | } |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 4630 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 4631 | |
Urvang Joshi | 686d4fd | 2017-07-13 11:36:40 -0700 | [diff] [blame] | 4632 | av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL, block_size); |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 4633 | |
| 4634 | #if !CONFIG_NCOBMC_ADAPT_WEIGHT |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 4635 | if (mbmi->motion_mode == OBMC_CAUSAL) { |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 4636 | #if CONFIG_NCOBMC |
| 4637 | if (dry_run == OUTPUT_ENABLED) |
| 4638 | av1_build_ncobmc_inter_predictors_sb(cm, xd, mi_row, mi_col); |
| 4639 | else |
| 4640 | #endif |
| 4641 | av1_build_obmc_inter_predictors_sb(cm, xd, mi_row, mi_col); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4642 | } |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 4643 | #else |
| 4644 | if (mbmi->motion_mode == OBMC_CAUSAL) { |
| 4645 | av1_build_obmc_inter_predictors_sb(cm, xd, mi_row, mi_col); |
| 4646 | } else if (mbmi->motion_mode == NCOBMC_ADAPT_WEIGHT && |
| 4647 | dry_run == OUTPUT_ENABLED) { |
| 4648 | int p; |
| 4649 | for (p = 0; p < MAX_MB_PLANE; ++p) { |
| 4650 | get_pred_from_intrpl_buf(xd, mi_row, mi_col, block_size, p); |
| 4651 | } |
| 4652 | } |
| 4653 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4654 | |
Jingning Han | 18c53c8 | 2017-02-17 14:49:57 -0800 | [diff] [blame] | 4655 | av1_encode_sb((AV1_COMMON *)cm, x, block_size, mi_row, mi_col); |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 4656 | if (mbmi->skip) mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size); |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 4657 | av1_tokenize_sb_vartx(cpi, td, t, dry_run, mi_row, mi_col, block_size, |
| 4658 | rate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4659 | } |
| 4660 | |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 4661 | #if CONFIG_DIST_8X8 |
Yushin Cho | 5510433 | 2017-08-14 16:15:43 -0700 | [diff] [blame] | 4662 | if (x->using_dist_8x8 && bsize < BLOCK_8X8) { |
Yushin Cho | b7b60c5 | 2017-07-14 16:18:52 -0700 | [diff] [blame] | 4663 | dist_8x8_set_sub8x8_dst(x, (uint8_t *)x->decoded_8x8, bsize, |
| 4664 | block_size_wide[bsize], block_size_high[bsize], |
| 4665 | mi_row, mi_col); |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 4666 | } |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 4667 | #endif // CONFIG_DIST_8X8 |
Yushin Cho | 63927c4 | 2017-05-23 15:41:05 -0700 | [diff] [blame] | 4668 | |
Debargha Mukherjee | ceebb70 | 2016-10-11 05:26:50 -0700 | [diff] [blame] | 4669 | if (!dry_run) { |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 4670 | TX_SIZE tx_size = |
| 4671 | is_inter && !mbmi->skip ? mbmi->min_tx_size : mbmi->tx_size; |
Jingning Han | 5d2ed97 | 2017-03-06 12:19:54 -0800 | [diff] [blame] | 4672 | if (cm->tx_mode == TX_MODE_SELECT && !xd->lossless[mbmi->segment_id] && |
Debargha Mukherjee | 1181296 | 2017-10-29 15:16:14 -0700 | [diff] [blame] | 4673 | mbmi->sb_type > BLOCK_4X4 && !(is_inter && (mbmi->skip || seg_skip))) { |
Jingning Han | 581d169 | 2017-01-05 16:03:54 -0800 | [diff] [blame] | 4674 | if (is_inter) { |
| 4675 | tx_partition_count_update(cm, x, bsize, mi_row, mi_col, td->counts); |
| 4676 | } else { |
Jingning Han | 1341cba | 2017-05-25 13:23:08 -0700 | [diff] [blame] | 4677 | if (tx_size != max_txsize_rect_lookup[bsize]) ++x->txb_split_count; |
Jingning Han | 581d169 | 2017-01-05 16:03:54 -0800 | [diff] [blame] | 4678 | } |
Jingning Han | 581d169 | 2017-01-05 16:03:54 -0800 | [diff] [blame] | 4679 | |
Sebastien Alaiwan | fb83877 | 2017-10-24 12:02:54 +0200 | [diff] [blame] | 4680 | #if CONFIG_RECT_TX_EXT |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 4681 | if (is_quarter_tx_allowed(xd, mbmi, is_inter) && |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 4682 | quarter_txsize_lookup[bsize] != max_txsize_rect_lookup[bsize] && |
| 4683 | (mbmi->tx_size == quarter_txsize_lookup[bsize] || |
| 4684 | mbmi->tx_size == max_txsize_rect_lookup[bsize])) { |
Yue Chen | 3dd03e3 | 2017-10-17 15:39:52 -0700 | [diff] [blame] | 4685 | const int use_qttx = mbmi->tx_size == quarter_txsize_lookup[bsize]; |
| 4686 | ++td->counts->quarter_tx_size[use_qttx]; |
| 4687 | #if CONFIG_NEW_MULTISYMBOL |
| 4688 | update_cdf(xd->tile_ctx->quarter_tx_size_cdf, use_qttx, 2); |
| 4689 | #endif |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 4690 | } |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 4691 | #endif |
Debargha Mukherjee | 1181296 | 2017-10-29 15:16:14 -0700 | [diff] [blame] | 4692 | #if CONFIG_EXT_TX |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 4693 | assert(IMPLIES(is_rect_tx(tx_size), is_rect_tx_allowed(xd, mbmi))); |
Debargha Mukherjee | 1181296 | 2017-10-29 15:16:14 -0700 | [diff] [blame] | 4694 | #endif // CONFIG_EXT_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4695 | } else { |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 4696 | int i, j; |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 4697 | TX_SIZE intra_tx_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4698 | // The new intra coding scheme requires no change of transform size |
Jingning Han | 94ea1aa | 2016-11-08 12:10:46 -0800 | [diff] [blame] | 4699 | if (is_inter) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4700 | if (xd->lossless[mbmi->segment_id]) { |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 4701 | intra_tx_size = TX_4X4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4702 | } else { |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 4703 | intra_tx_size = tx_size_from_tx_mode(bsize, cm->tx_mode, 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4704 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4705 | } else { |
Debargha Mukherjee | 1181296 | 2017-10-29 15:16:14 -0700 | [diff] [blame] | 4706 | #if CONFIG_EXT_TX |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 4707 | intra_tx_size = tx_size; |
| 4708 | #else |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 4709 | intra_tx_size = (bsize >= BLOCK_8X8) ? tx_size : TX_4X4; |
Debargha Mukherjee | 1181296 | 2017-10-29 15:16:14 -0700 | [diff] [blame] | 4710 | #endif // CONFIG_EXT_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4711 | } |
Debargha Mukherjee | 1181296 | 2017-10-29 15:16:14 -0700 | [diff] [blame] | 4712 | #if CONFIG_EXT_TX |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 4713 | ++td->counts->tx_size_implied[max_txsize_lookup[bsize]] |
| 4714 | [txsize_sqr_up_map[tx_size]]; |
Debargha Mukherjee | 1181296 | 2017-10-29 15:16:14 -0700 | [diff] [blame] | 4715 | #endif // CONFIG_EXT_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4716 | |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 4717 | for (j = 0; j < mi_height; j++) |
| 4718 | for (i = 0; i < mi_width; i++) |
| 4719 | if (mi_col + i < cm->mi_cols && mi_row + j < cm->mi_rows) |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 4720 | mi_8x8[mis * j + i]->mbmi.tx_size = intra_tx_size; |
Jingning Han | 9777afc | 2016-10-20 15:17:43 -0700 | [diff] [blame] | 4721 | |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 4722 | mbmi->min_tx_size = get_min_tx_size(intra_tx_size); |
Jingning Han | 2d4fafa | 2017-05-26 11:35:05 -0700 | [diff] [blame] | 4723 | if (intra_tx_size != max_txsize_rect_lookup[bsize]) ++x->txb_split_count; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4724 | } |
Jingning Han | 9777afc | 2016-10-20 15:17:43 -0700 | [diff] [blame] | 4725 | |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 4726 | #if !CONFIG_TXK_SEL |
Angie Chiang | b14b73f | 2017-04-13 16:26:00 -0700 | [diff] [blame] | 4727 | av1_update_tx_type_count(cm, xd, bsize, tx_size, td->counts); |
| 4728 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4729 | } |
| 4730 | |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 4731 | if (cm->tx_mode == TX_MODE_SELECT && mbmi->sb_type > BLOCK_4X4 && is_inter && |
| 4732 | !(mbmi->skip || seg_skip) && !xd->lossless[mbmi->segment_id]) { |
Peter de Rivaz | 74d0ad8 | 2016-10-19 11:43:11 +0100 | [diff] [blame] | 4733 | if (dry_run) tx_partition_set_contexts(cm, xd, bsize, mi_row, mi_col); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4734 | } else { |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 4735 | TX_SIZE tx_size = mbmi->tx_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4736 | // The new intra coding scheme requires no change of transform size |
Ryan | 84a6f20 | 2017-09-25 12:37:33 -0700 | [diff] [blame] | 4737 | if (is_inter) { |
| 4738 | if (xd->lossless[mbmi->segment_id]) { |
| 4739 | tx_size = TX_4X4; |
| 4740 | } else { |
| 4741 | tx_size = tx_size_from_tx_mode(bsize, cm->tx_mode, is_inter); |
| 4742 | } |
| 4743 | } else { |
Jingning Han | 3daa4fd | 2017-01-20 10:33:50 -0800 | [diff] [blame] | 4744 | tx_size = (bsize > BLOCK_4X4) ? tx_size : TX_4X4; |
Ryan | 84a6f20 | 2017-09-25 12:37:33 -0700 | [diff] [blame] | 4745 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4746 | mbmi->tx_size = tx_size; |
Jingning Han | 1b1dc93 | 2016-11-09 10:55:30 -0800 | [diff] [blame] | 4747 | set_txfm_ctxs(tx_size, xd->n8_w, xd->n8_h, (mbmi->skip || seg_skip), xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4748 | } |
Hui Su | 9fa9623 | 2017-10-23 15:46:04 -0700 | [diff] [blame] | 4749 | #if CONFIG_CFL |
Luc Trudeau | b05eeae | 2017-08-18 15:14:30 -0400 | [diff] [blame] | 4750 | CFL_CTX *const cfl = xd->cfl; |
Luc Trudeau | b05eeae | 2017-08-18 15:14:30 -0400 | [diff] [blame] | 4751 | if (is_inter_block(mbmi) && |
| 4752 | !is_chroma_reference(mi_row, mi_col, bsize, cfl->subsampling_x, |
| 4753 | cfl->subsampling_y)) { |
| 4754 | cfl_store_block(xd, mbmi->sb_type, mbmi->tx_size); |
| 4755 | } |
Hui Su | 9fa9623 | 2017-10-23 15:46:04 -0700 | [diff] [blame] | 4756 | #endif // CONFIG_CFL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4757 | } |