Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Urvang Joshi | 8a02d76 | 2016-07-28 15:51:12 -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 | * |
Urvang Joshi | 8a02d76 | 2016-07-28 15:51:12 -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 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 16 | #include "config/aom_config.h" |
Tom Finegan | 44702c8 | 2018-05-22 13:00:39 -0700 | [diff] [blame] | 17 | #include "config/aom_dsp_rtcd.h" |
| 18 | #include "config/aom_scale_rtcd.h" |
Yaowu Xu | fa3721d | 2018-07-30 14:38:49 -0700 | [diff] [blame] | 19 | #include "config/av1_rtcd.h" |
| 20 | |
| 21 | #include "aom_dsp/aom_dsp_common.h" |
| 22 | #include "aom_dsp/aom_filter.h" |
| 23 | #if CONFIG_DENOISE |
| 24 | #include "aom_dsp/grain_table.h" |
| 25 | #include "aom_dsp/noise_util.h" |
| 26 | #include "aom_dsp/noise_model.h" |
| 27 | #endif |
| 28 | #include "aom_dsp/psnr.h" |
| 29 | #if CONFIG_INTERNAL_STATS |
| 30 | #include "aom_dsp/ssim.h" |
| 31 | #endif |
| 32 | #include "aom_ports/aom_timer.h" |
| 33 | #include "aom_ports/mem.h" |
| 34 | #include "aom_ports/system_state.h" |
| 35 | #include "aom_scale/aom_scale.h" |
David Turner | 1539bb0 | 2019-01-24 15:28:13 +0000 | [diff] [blame] | 36 | #if CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | fa3721d | 2018-07-30 14:38:49 -0700 | [diff] [blame] | 37 | #include "aom_util/debug_util.h" |
David Turner | 1539bb0 | 2019-01-24 15:28:13 +0000 | [diff] [blame] | 38 | #endif // CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 39 | |
| 40 | #include "av1/common/alloccommon.h" |
Steinar Midtskogen | a9d41e8 | 2017-03-17 12:48:15 +0100 | [diff] [blame] | 41 | #include "av1/common/cdef.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 42 | #include "av1/common/filter.h" |
| 43 | #include "av1/common/idct.h" |
| 44 | #include "av1/common/reconinter.h" |
| 45 | #include "av1/common/reconintra.h" |
Fergus Simpson | d056500 | 2017-03-27 16:51:52 -0700 | [diff] [blame] | 46 | #include "av1/common/resize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 47 | #include "av1/common/tile_common.h" |
| 48 | |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 49 | #include "av1/encoder/av1_multi_thread.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 50 | #include "av1/encoder/aq_complexity.h" |
| 51 | #include "av1/encoder/aq_cyclicrefresh.h" |
| 52 | #include "av1/encoder/aq_variance.h" |
| 53 | #include "av1/encoder/bitstream.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 54 | #include "av1/encoder/context_tree.h" |
| 55 | #include "av1/encoder/encodeframe.h" |
| 56 | #include "av1/encoder/encodemv.h" |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 57 | #include "av1/encoder/encode_strategy.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 58 | #include "av1/encoder/encoder.h" |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 59 | #include "av1/encoder/encodetxb.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 60 | #include "av1/encoder/ethread.h" |
| 61 | #include "av1/encoder/firstpass.h" |
Yaowu Xu | fa3721d | 2018-07-30 14:38:49 -0700 | [diff] [blame] | 62 | #include "av1/encoder/grain_test_vectors.h" |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 63 | #include "av1/encoder/hash_motion.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 64 | #include "av1/encoder/mbgraph.h" |
David Turner | 0fa8c49 | 2019-02-06 16:38:13 +0000 | [diff] [blame] | 65 | #include "av1/encoder/pass2_strategy.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | #include "av1/encoder/picklpf.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 67 | #include "av1/encoder/pickrst.h" |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 68 | #include "av1/encoder/random.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 69 | #include "av1/encoder/ratectrl.h" |
| 70 | #include "av1/encoder/rd.h" |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 71 | #include "av1/encoder/rdopt.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 72 | #include "av1/encoder/segmentation.h" |
| 73 | #include "av1/encoder/speed_features.h" |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 74 | #include "av1/encoder/reconinter_enc.h" |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 75 | #include "av1/encoder/var_based_part.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 76 | |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 77 | #define DEFAULT_EXPLICIT_ORDER_HINT_BITS 7 |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 78 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 79 | #if CONFIG_ENTROPY_STATS |
| 80 | FRAME_COUNTS aggregate_fc; |
| 81 | #endif // CONFIG_ENTROPY_STATS |
| 82 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 83 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 84 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 85 | |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 86 | // Whether to use high precision mv for altref computation. |
| 87 | #define ALTREF_HIGH_PRECISION_MV 1 |
| 88 | |
| 89 | // Q threshold for high precision mv. Choose a very high value for now so that |
| 90 | // HIGH_PRECISION is always chosen. |
| 91 | #define HIGH_PRECISION_MV_QTHRESH 200 |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 92 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 93 | // #define OUTPUT_YUV_REC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 94 | #ifdef OUTPUT_YUV_SKINMAP |
| 95 | FILE *yuv_skinmap_file = NULL; |
| 96 | #endif |
| 97 | #ifdef OUTPUT_YUV_REC |
| 98 | FILE *yuv_rec_file; |
| 99 | #define FILE_NAME_LEN 100 |
| 100 | #endif |
| 101 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 102 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 103 | switch (mode) { |
| 104 | case NORMAL: |
| 105 | *hr = 1; |
| 106 | *hs = 1; |
| 107 | break; |
| 108 | case FOURFIVE: |
| 109 | *hr = 4; |
| 110 | *hs = 5; |
| 111 | break; |
| 112 | case THREEFIVE: |
| 113 | *hr = 3; |
| 114 | *hs = 5; |
| 115 | break; |
| 116 | case ONETWO: |
| 117 | *hr = 1; |
| 118 | *hs = 2; |
| 119 | break; |
| 120 | default: |
| 121 | *hr = 1; |
| 122 | *hs = 1; |
| 123 | assert(0); |
| 124 | break; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 129 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 130 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 131 | unsigned char *const seg_map = cpi->segmentation_map; |
| 132 | int i; |
| 133 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 134 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 135 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 136 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 137 | } |
| 138 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 139 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 140 | struct segmentation *const seg = &cpi->common.seg; |
| 141 | unsigned char *const seg_map = cpi->segmentation_map; |
| 142 | const unsigned char *const active_map = cpi->active_map.map; |
| 143 | int i; |
| 144 | |
| 145 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 146 | |
| 147 | if (frame_is_intra_only(&cpi->common)) { |
| 148 | cpi->active_map.enabled = 0; |
| 149 | cpi->active_map.update = 1; |
| 150 | } |
| 151 | |
| 152 | if (cpi->active_map.update) { |
| 153 | if (cpi->active_map.enabled) { |
| 154 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 155 | if (seg_map[i] == AM_SEGMENT_ID_ACTIVE) seg_map[i] = active_map[i]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 156 | av1_enable_segmentation(seg); |
| 157 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 158 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 159 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 160 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 161 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 162 | |
| 163 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H, |
| 164 | -MAX_LOOP_FILTER); |
| 165 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V, |
| 166 | -MAX_LOOP_FILTER); |
| 167 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U, |
| 168 | -MAX_LOOP_FILTER); |
| 169 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V, |
| 170 | -MAX_LOOP_FILTER); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 171 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 172 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 173 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 174 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 175 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 176 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 177 | if (seg->enabled) { |
| 178 | seg->update_data = 1; |
| 179 | seg->update_map = 1; |
| 180 | } |
| 181 | } |
| 182 | cpi->active_map.update = 0; |
| 183 | } |
| 184 | } |
| 185 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 186 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 187 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 188 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 189 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 190 | const int mi_rows = cpi->common.mi_rows; |
| 191 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 192 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 193 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 194 | cpi->active_map.update = 1; |
| 195 | if (new_map_16x16) { |
| 196 | int r, c; |
| 197 | for (r = 0; r < mi_rows; ++r) { |
| 198 | for (c = 0; c < mi_cols; ++c) { |
| 199 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 200 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 201 | ? AM_SEGMENT_ID_ACTIVE |
| 202 | : AM_SEGMENT_ID_INACTIVE; |
| 203 | } |
| 204 | } |
| 205 | cpi->active_map.enabled = 1; |
| 206 | } else { |
| 207 | cpi->active_map.enabled = 0; |
| 208 | } |
| 209 | return 0; |
| 210 | } else { |
| 211 | return -1; |
| 212 | } |
| 213 | } |
| 214 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 215 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 216 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 217 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 218 | new_map_16x16) { |
| 219 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 220 | const int mi_rows = cpi->common.mi_rows; |
| 221 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 222 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 223 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 224 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 225 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 226 | if (cpi->active_map.enabled) { |
| 227 | int r, c; |
| 228 | for (r = 0; r < mi_rows; ++r) { |
| 229 | for (c = 0; c < mi_cols; ++c) { |
| 230 | // Cyclic refresh segments are considered active despite not having |
| 231 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 232 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 233 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | return 0; |
| 238 | } else { |
| 239 | return -1; |
| 240 | } |
| 241 | } |
| 242 | |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 243 | // Compute the horizontal frequency components' energy in a frame |
| 244 | // by calculuating the 16x4 Horizontal DCT. This is to be used to |
| 245 | // decide the superresolution parameters. |
Yaowu Xu | bedbf4f | 2019-05-01 17:54:36 -0700 | [diff] [blame] | 246 | static void analyze_hor_freq(const AV1_COMP *cpi, double *energy) { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 247 | uint64_t freq_energy[16] = { 0 }; |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 248 | const YV12_BUFFER_CONFIG *buf = cpi->source; |
| 249 | const int bd = cpi->td.mb.e_mbd.bd; |
| 250 | const int width = buf->y_crop_width; |
| 251 | const int height = buf->y_crop_height; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 252 | DECLARE_ALIGNED(16, int32_t, coeff[16 * 4]); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 253 | int n = 0; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 254 | memset(freq_energy, 0, sizeof(freq_energy)); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 255 | if (buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 256 | const int16_t *src16 = (const int16_t *)CONVERT_TO_SHORTPTR(buf->y_buffer); |
| 257 | for (int i = 0; i < height - 4; i += 4) { |
| 258 | for (int j = 0; j < width - 16; j += 16) { |
| 259 | av1_fwd_txfm2d_16x4(src16 + i * buf->y_stride + j, coeff, buf->y_stride, |
| 260 | H_DCT, bd); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 261 | for (int k = 1; k < 16; ++k) { |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 262 | const uint64_t this_energy = |
| 263 | ((int64_t)coeff[k] * coeff[k]) + |
| 264 | ((int64_t)coeff[k + 16] * coeff[k + 16]) + |
| 265 | ((int64_t)coeff[k + 32] * coeff[k + 32]) + |
| 266 | ((int64_t)coeff[k + 48] * coeff[k + 48]); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 267 | freq_energy[k] += ROUND_POWER_OF_TWO(this_energy, 2 + 2 * (bd - 8)); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 268 | } |
| 269 | n++; |
| 270 | } |
| 271 | } |
| 272 | } else { |
Debargha Mukherjee | ac28c72 | 2018-11-14 22:09:46 -0800 | [diff] [blame] | 273 | assert(bd == 8); |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 274 | DECLARE_ALIGNED(16, int16_t, src16[16 * 4]); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 275 | for (int i = 0; i < height - 4; i += 4) { |
| 276 | for (int j = 0; j < width - 16; j += 16) { |
| 277 | for (int ii = 0; ii < 4; ++ii) |
| 278 | for (int jj = 0; jj < 16; ++jj) |
| 279 | src16[ii * 16 + jj] = |
| 280 | buf->y_buffer[(i + ii) * buf->y_stride + (j + jj)]; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 281 | av1_fwd_txfm2d_16x4(src16, coeff, 16, H_DCT, bd); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 282 | for (int k = 1; k < 16; ++k) { |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 283 | const uint64_t this_energy = |
| 284 | ((int64_t)coeff[k] * coeff[k]) + |
| 285 | ((int64_t)coeff[k + 16] * coeff[k + 16]) + |
| 286 | ((int64_t)coeff[k + 32] * coeff[k + 32]) + |
| 287 | ((int64_t)coeff[k + 48] * coeff[k + 48]); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 288 | freq_energy[k] += ROUND_POWER_OF_TWO(this_energy, 2); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 289 | } |
| 290 | n++; |
| 291 | } |
| 292 | } |
| 293 | } |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 294 | if (n) { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 295 | for (int k = 1; k < 16; ++k) energy[k] = (double)freq_energy[k] / n; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 296 | // Convert to cumulative energy |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 297 | for (int k = 14; k > 0; --k) energy[k] += energy[k + 1]; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 298 | } else { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 299 | for (int k = 1; k < 16; ++k) energy[k] = 1e+20; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 300 | } |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Yaowu Xu | 45295c3 | 2018-03-29 12:06:10 -0700 | [diff] [blame] | 303 | static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv, |
| 304 | int cur_frame_force_integer_mv) { |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 305 | MACROBLOCK *const mb = &cpi->td.mb; |
Hui Su | 5036115 | 2018-03-02 11:01:42 -0800 | [diff] [blame] | 306 | cpi->common.allow_high_precision_mv = |
| 307 | allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
Rupert Swarbrick | a84faf2 | 2017-12-11 13:56:40 +0000 | [diff] [blame] | 308 | const int copy_hp = |
| 309 | cpi->common.allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 310 | int *(*src)[2] = copy_hp ? &mb->nmvcost_hp : &mb->nmvcost; |
| 311 | mb->mv_cost_stack = *src; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 314 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 315 | const AV1_COMMON *const cm = &cpi->common; |
| 316 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 317 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 318 | return BLOCK_64X64; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 319 | #if CONFIG_FILEOPTIONS |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 320 | if (cm->options && cm->options->ext_partition) |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 321 | #endif |
| 322 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
| 323 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 324 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 325 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 326 | |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 327 | // TODO(any): Possibly could improve this with a heuristic. |
| 328 | #if CONFIG_FILEOPTIONS |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 329 | if (cm->options && !cm->options->ext_partition) return BLOCK_64X64; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 330 | #endif |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 331 | |
Urvang Joshi | aab7443 | 2018-06-01 12:06:22 -0700 | [diff] [blame] | 332 | // When superres / resize is on, 'cm->width / height' can change between |
Hui Su | 3e3b934 | 2019-04-12 18:27:28 +0000 | [diff] [blame] | 333 | // calls, so we don't apply this heuristic there. |
| 334 | // Things break if superblock size changes between the first pass and second |
| 335 | // pass encoding, which is why this heuristic is not configured as a |
| 336 | // speed-feature. |
Urvang Joshi | aab7443 | 2018-06-01 12:06:22 -0700 | [diff] [blame] | 337 | if (cpi->oxcf.superres_mode == SUPERRES_NONE && |
Hui Su | 3e3b934 | 2019-04-12 18:27:28 +0000 | [diff] [blame] | 338 | cpi->oxcf.resize_mode == RESIZE_NONE && cpi->oxcf.speed >= 1) { |
| 339 | return AOMMIN(cm->width, cm->height) > 480 ? BLOCK_128X128 : BLOCK_64X64; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 342 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 345 | static void setup_frame(AV1_COMP *cpi) { |
| 346 | AV1_COMMON *const cm = &cpi->common; |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 347 | // Set up entropy context depending on frame type. The decoder mandates |
| 348 | // the use of the default context, index 0, for keyframes and inter |
| 349 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 350 | // other inter-frames the encoder currently uses only two contexts; |
| 351 | // context 1 for ALTREF frames and context 0 for the others. |
Soo-Chul Han | 85e8c79 | 2018-01-21 01:58:15 -0500 | [diff] [blame] | 352 | |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 353 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 354 | cpi->ext_use_primary_ref_none) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 355 | av1_setup_past_independence(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Hui Su | eb4b7de | 2019-04-03 11:00:18 -0700 | [diff] [blame] | 358 | if ((cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) || |
| 359 | frame_is_sframe(cm)) { |
| 360 | if (!cpi->seq_params_locked) { |
| 361 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
| 362 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 363 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 364 | const RefCntBuffer *const primary_ref_buf = get_primary_ref_frame_buf(cm); |
| 365 | if (primary_ref_buf == NULL) { |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 366 | av1_setup_past_independence(cm); |
| 367 | cm->seg.update_map = 1; |
| 368 | cm->seg.update_data = 1; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 369 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 370 | *cm->fc = primary_ref_buf->frame_context; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 371 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 372 | } |
| 373 | |
David Turner | bc0993e | 2019-02-15 14:42:23 +0000 | [diff] [blame] | 374 | av1_zero(cm->cur_frame->interp_filter_selected); |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 375 | cm->prev_frame = get_primary_ref_frame_buf(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 376 | cpi->vaq_refresh = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 379 | static void enc_setup_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 380 | int i; |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 381 | int mi_rows_sb_aligned = calc_mi_size(cm->mi_rows); |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 382 | cm->mi = cm->mip; |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 383 | memset(cm->mip, 0, cm->mi_stride * mi_rows_sb_aligned * sizeof(*cm->mip)); |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 384 | cm->prev_mi = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 385 | // Clear top border row |
| 386 | memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride); |
| 387 | // Clear left border column |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 388 | for (i = 0; i < mi_rows_sb_aligned; ++i) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 389 | memset(&cm->prev_mip[i * cm->mi_stride], 0, sizeof(*cm->prev_mip)); |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 390 | cm->mi_grid_visible = cm->mi_grid_base; |
| 391 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 392 | |
| 393 | memset(cm->mi_grid_base, 0, |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 394 | cm->mi_stride * mi_rows_sb_aligned * sizeof(*cm->mi_grid_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 397 | static int enc_alloc_mi(AV1_COMMON *cm, int mi_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 398 | cm->mip = aom_calloc(mi_size, sizeof(*cm->mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 399 | if (!cm->mip) return 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 400 | cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 401 | if (!cm->prev_mip) return 1; |
| 402 | cm->mi_alloc_size = mi_size; |
| 403 | |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 404 | cm->mi_grid_base = |
| 405 | (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 406 | if (!cm->mi_grid_base) return 1; |
| 407 | cm->prev_mi_grid_base = |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 408 | (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 409 | if (!cm->prev_mi_grid_base) return 1; |
| 410 | |
| 411 | return 0; |
| 412 | } |
| 413 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 414 | static void enc_free_mi(AV1_COMMON *cm) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 415 | aom_free(cm->mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 416 | cm->mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 417 | aom_free(cm->prev_mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 418 | cm->prev_mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 419 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 420 | cm->mi_grid_base = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 421 | aom_free(cm->prev_mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 422 | cm->prev_mi_grid_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 423 | cm->mi_alloc_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 426 | static void swap_mi_and_prev_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 427 | // Current mip will be the prev_mip for the next frame. |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 428 | MB_MODE_INFO **temp_base = cm->prev_mi_grid_base; |
| 429 | MB_MODE_INFO *temp = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 430 | cm->prev_mip = cm->mip; |
| 431 | cm->mip = temp; |
| 432 | |
| 433 | // Update the upper left visible macroblock ptrs. |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 434 | cm->mi = cm->mip; |
| 435 | cm->prev_mi = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 436 | |
| 437 | cm->prev_mi_grid_base = cm->mi_grid_base; |
| 438 | cm->mi_grid_base = temp_base; |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 439 | cm->mi_grid_visible = cm->mi_grid_base; |
| 440 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 443 | void av1_initialize_enc(void) { |
Wan-Teh Chang | 3cac454 | 2018-06-29 10:21:39 -0700 | [diff] [blame] | 444 | av1_rtcd(); |
| 445 | aom_dsp_rtcd(); |
| 446 | aom_scale_rtcd(); |
| 447 | av1_init_intra_predictors(); |
| 448 | av1_init_me_luts(); |
| 449 | av1_rc_init_minq_luts(); |
| 450 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 453 | static void dealloc_context_buffers_ext(AV1_COMP *cpi) { |
| 454 | if (cpi->mbmi_ext_base) { |
| 455 | aom_free(cpi->mbmi_ext_base); |
| 456 | cpi->mbmi_ext_base = NULL; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
| 461 | AV1_COMMON *cm = &cpi->common; |
| 462 | int mi_size = cm->mi_cols * cm->mi_rows; |
| 463 | |
| 464 | dealloc_context_buffers_ext(cpi); |
| 465 | CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, |
| 466 | aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); |
| 467 | } |
| 468 | |
Yaowu Xu | c0ea258 | 2019-01-15 10:17:16 -0800 | [diff] [blame] | 469 | static void reset_film_grain_chroma_params(aom_film_grain_t *pars) { |
| 470 | pars->num_cr_points = 0; |
| 471 | pars->cr_mult = 0; |
| 472 | pars->cr_luma_mult = 0; |
| 473 | memset(pars->scaling_points_cr, 0, sizeof(pars->scaling_points_cr)); |
| 474 | memset(pars->ar_coeffs_cr, 0, sizeof(pars->ar_coeffs_cr)); |
| 475 | pars->num_cb_points = 0; |
| 476 | pars->cb_mult = 0; |
| 477 | pars->cb_luma_mult = 0; |
Yaowu Xu | fda7dcb | 2019-01-16 13:04:33 -0800 | [diff] [blame] | 478 | pars->chroma_scaling_from_luma = 0; |
Yaowu Xu | c0ea258 | 2019-01-15 10:17:16 -0800 | [diff] [blame] | 479 | memset(pars->scaling_points_cb, 0, sizeof(pars->scaling_points_cb)); |
| 480 | memset(pars->ar_coeffs_cb, 0, sizeof(pars->ar_coeffs_cb)); |
| 481 | } |
| 482 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 483 | static void update_film_grain_parameters(struct AV1_COMP *cpi, |
| 484 | const AV1EncoderConfig *oxcf) { |
| 485 | AV1_COMMON *const cm = &cpi->common; |
| 486 | cpi->oxcf = *oxcf; |
| 487 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 488 | if (cpi->film_grain_table) { |
| 489 | aom_film_grain_table_free(cpi->film_grain_table); |
| 490 | aom_free(cpi->film_grain_table); |
| 491 | cpi->film_grain_table = NULL; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 492 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 493 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 494 | if (oxcf->film_grain_test_vector) { |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 495 | cm->seq_params.film_grain_params_present = 1; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 496 | if (cm->current_frame.frame_type == KEY_FRAME) { |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 497 | memcpy(&cm->film_grain_params, |
| 498 | film_grain_test_vectors + oxcf->film_grain_test_vector - 1, |
| 499 | sizeof(cm->film_grain_params)); |
Yaowu Xu | c0ea258 | 2019-01-15 10:17:16 -0800 | [diff] [blame] | 500 | if (oxcf->monochrome) |
| 501 | reset_film_grain_chroma_params(&cm->film_grain_params); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 502 | cm->film_grain_params.bit_depth = cm->seq_params.bit_depth; |
| 503 | if (cm->seq_params.color_range == AOM_CR_FULL_RANGE) { |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 504 | cm->film_grain_params.clip_to_restricted_range = 0; |
| 505 | } |
| 506 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 507 | } else if (oxcf->film_grain_table_filename) { |
Neil Birkbeck | bd40ca7 | 2019-03-02 13:25:50 -0800 | [diff] [blame] | 508 | cm->seq_params.film_grain_params_present = 1; |
| 509 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 510 | cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table)); |
| 511 | memset(cpi->film_grain_table, 0, sizeof(aom_film_grain_table_t)); |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 512 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 513 | aom_film_grain_table_read(cpi->film_grain_table, |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 514 | oxcf->film_grain_table_filename, &cm->error); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 515 | } else { |
Neil Birkbeck | bd40ca7 | 2019-03-02 13:25:50 -0800 | [diff] [blame] | 516 | #if CONFIG_DENOISE |
| 517 | cm->seq_params.film_grain_params_present = (cpi->oxcf.noise_level > 0); |
| 518 | #else |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 519 | cm->seq_params.film_grain_params_present = 0; |
Neil Birkbeck | bd40ca7 | 2019-03-02 13:25:50 -0800 | [diff] [blame] | 520 | #endif |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 521 | memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params)); |
| 522 | } |
| 523 | } |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 524 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 525 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 526 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 527 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 528 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 529 | dealloc_context_buffers_ext(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 530 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 531 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 532 | cpi->tile_data = NULL; |
| 533 | |
| 534 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 535 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 536 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 537 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 538 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 539 | cpi->cyclic_refresh = NULL; |
| 540 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 541 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 542 | cpi->active_map.map = NULL; |
| 543 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 544 | aom_free(cpi->td.mb.above_pred_buf); |
| 545 | cpi->td.mb.above_pred_buf = NULL; |
| 546 | |
| 547 | aom_free(cpi->td.mb.left_pred_buf); |
| 548 | cpi->td.mb.left_pred_buf = NULL; |
| 549 | |
| 550 | aom_free(cpi->td.mb.wsrc_buf); |
| 551 | cpi->td.mb.wsrc_buf = NULL; |
| 552 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 553 | aom_free(cpi->td.mb.inter_modes_info); |
| 554 | cpi->td.mb.inter_modes_info = NULL; |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 555 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 556 | for (int i = 0; i < 2; i++) |
| 557 | for (int j = 0; j < 2; j++) { |
| 558 | aom_free(cpi->td.mb.hash_value_buffer[i][j]); |
| 559 | cpi->td.mb.hash_value_buffer[i][j] = NULL; |
| 560 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 561 | aom_free(cpi->td.mb.mask_buf); |
| 562 | cpi->td.mb.mask_buf = NULL; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 563 | |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 564 | aom_free(cm->tpl_mvs); |
| 565 | cm->tpl_mvs = NULL; |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 566 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 567 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 568 | av1_free_txb_buf(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 569 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 570 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 571 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 572 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 573 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 574 | aom_free_frame_buffer(&cpi->scaled_source); |
| 575 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 576 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 577 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 578 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 579 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 580 | cpi->tile_tok[0][0] = 0; |
| 581 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 582 | aom_free(cpi->tplist[0][0]); |
| 583 | cpi->tplist[0][0] = NULL; |
| 584 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 585 | av1_free_pc_tree(&cpi->td, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 586 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 587 | aom_free(cpi->td.mb.palette_buffer); |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 588 | |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 589 | aom_free(cpi->td.mb.tmp_conv_dst); |
| 590 | for (int j = 0; j < 2; ++j) { |
| 591 | aom_free(cpi->td.mb.tmp_obmc_bufs[j]); |
| 592 | } |
| 593 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 594 | #if CONFIG_DENOISE |
| 595 | if (cpi->denoise_and_model) { |
| 596 | aom_denoise_and_model_free(cpi->denoise_and_model); |
| 597 | cpi->denoise_and_model = NULL; |
| 598 | } |
| 599 | #endif |
| 600 | if (cpi->film_grain_table) { |
| 601 | aom_film_grain_table_free(cpi->film_grain_table); |
| 602 | cpi->film_grain_table = NULL; |
| 603 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 606 | static void save_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 607 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 608 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 609 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 610 | // Stores a snapshot of key state variables which can subsequently be |
| 611 | // restored with a call to av1_restore_coding_context. These functions are |
| 612 | // intended for use in a re-code loop in av1_compress_frame where the |
| 613 | // quantizer value is adjusted between loop iterations. |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 614 | av1_copy(cc->nmv_vec_cost, cpi->td.mb.nmv_vec_cost); |
| 615 | av1_copy(cc->nmv_costs, cpi->nmv_costs); |
| 616 | av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 617 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 618 | cc->fc = *cm->fc; |
| 619 | } |
| 620 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 621 | static void restore_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 622 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 623 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 624 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 625 | // Restore key state variables to the snapshot state stored in the |
| 626 | // previous call to av1_save_coding_context. |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 627 | av1_copy(cpi->td.mb.nmv_vec_cost, cc->nmv_vec_cost); |
| 628 | av1_copy(cpi->nmv_costs, cc->nmv_costs); |
| 629 | av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 630 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 631 | *cm->fc = cc->fc; |
| 632 | } |
| 633 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 634 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 635 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 636 | const RATE_CONTROL *const rc = &cpi->rc; |
| 637 | struct segmentation *const seg = &cm->seg; |
| 638 | |
| 639 | int high_q = (int)(rc->avg_q > 48.0); |
| 640 | int qi_delta; |
| 641 | |
| 642 | // Disable and clear down for KF |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 643 | if (cm->current_frame.frame_type == KEY_FRAME) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 644 | // Clear down the global segmentation map |
| 645 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 646 | seg->update_map = 0; |
| 647 | seg->update_data = 0; |
| 648 | cpi->static_mb_pct = 0; |
| 649 | |
| 650 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 651 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 652 | |
| 653 | // Clear down the segment features. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 654 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 655 | } else if (cpi->refresh_alt_ref_frame) { |
| 656 | // If this is an alt ref frame |
| 657 | // Clear down the global segmentation map |
| 658 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 659 | seg->update_map = 0; |
| 660 | seg->update_data = 0; |
| 661 | cpi->static_mb_pct = 0; |
| 662 | |
| 663 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 664 | av1_disable_segmentation(seg); |
| 665 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 666 | |
| 667 | // Scan frames from current to arf frame. |
| 668 | // This function re-enables segmentation if appropriate. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 669 | av1_update_mbgraph_stats(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 670 | |
| 671 | // If segmentation was enabled set those features needed for the |
| 672 | // arf itself. |
| 673 | if (seg->enabled) { |
| 674 | seg->update_map = 1; |
| 675 | seg->update_data = 1; |
| 676 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 677 | qi_delta = av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, |
| 678 | cm->seq_params.bit_depth); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 679 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 680 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 681 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 682 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 683 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 684 | |
| 685 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 686 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 687 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 688 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 689 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 690 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 691 | } |
| 692 | } else if (seg->enabled) { |
| 693 | // All other frames if segmentation has been enabled |
| 694 | |
| 695 | // First normal frame in a valid gf or alt ref group |
| 696 | if (rc->frames_since_golden == 0) { |
| 697 | // Set up segment features for normal frames in an arf group |
| 698 | if (rc->source_alt_ref_active) { |
| 699 | seg->update_map = 0; |
| 700 | seg->update_data = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 701 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 702 | qi_delta = av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, |
| 703 | cm->seq_params.bit_depth); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 704 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 705 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 706 | |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 707 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 708 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 709 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 710 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 711 | |
| 712 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 713 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 714 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 715 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 716 | |
| 717 | // Segment coding disabled for compred testing |
| 718 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 719 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 720 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 721 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 722 | } |
| 723 | } else { |
| 724 | // Disable segmentation and clear down features if alt ref |
| 725 | // is not active for this group |
| 726 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 727 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 728 | |
| 729 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 730 | |
| 731 | seg->update_map = 0; |
| 732 | seg->update_data = 0; |
| 733 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 734 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 735 | } |
| 736 | } else if (rc->is_src_frame_alt_ref) { |
| 737 | // Special case where we are coding over the top of a previous |
| 738 | // alt ref frame. |
| 739 | // Segment coding disabled for compred testing |
| 740 | |
| 741 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 742 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 743 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 744 | |
| 745 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 746 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 747 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 748 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 749 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 750 | |
| 751 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 752 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 753 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 754 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 755 | } |
| 756 | // Enable data update |
| 757 | seg->update_data = 1; |
| 758 | } else { |
| 759 | // All other frames. |
| 760 | |
| 761 | // No updates.. leave things as they are. |
| 762 | seg->update_map = 0; |
| 763 | seg->update_data = 0; |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 768 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 769 | AV1_COMMON *const cm = &cpi->common; |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 770 | MB_MODE_INFO **mi_4x4_ptr = cm->mi_grid_visible; |
David Turner | b757ce0 | 2018-11-12 15:01:28 +0000 | [diff] [blame] | 771 | uint8_t *cache_ptr = cm->cur_frame->seg_map; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 772 | int row, col; |
| 773 | |
| 774 | for (row = 0; row < cm->mi_rows; row++) { |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 775 | MB_MODE_INFO **mi_4x4 = mi_4x4_ptr; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 776 | uint8_t *cache = cache_ptr; |
Yushin Cho | a7f6592 | 2018-04-04 16:06:11 -0700 | [diff] [blame] | 777 | for (col = 0; col < cm->mi_cols; col++, mi_4x4++, cache++) |
| 778 | cache[0] = mi_4x4[0]->segment_id; |
| 779 | mi_4x4_ptr += cm->mi_stride; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 780 | cache_ptr += cm->mi_cols; |
| 781 | } |
| 782 | } |
| 783 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 784 | static void alloc_raw_frame_buffers(AV1_COMP *cpi) { |
| 785 | AV1_COMMON *cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 786 | const SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 787 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 788 | |
Satish Kumar Suman | 7a7239b | 2019-03-13 14:48:14 +0530 | [diff] [blame] | 789 | if (!cpi->lookahead) { |
| 790 | int is_scale = (oxcf->resize_mode || oxcf->superres_mode); |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 791 | cpi->lookahead = av1_lookahead_init( |
| 792 | oxcf->width, oxcf->height, seq_params->subsampling_x, |
| 793 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 7a7239b | 2019-03-13 14:48:14 +0530 | [diff] [blame] | 794 | oxcf->lag_in_frames, oxcf->border_in_pixels, is_scale); |
| 795 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 796 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 797 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 798 | "Failed to allocate lag buffers"); |
| 799 | |
| 800 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 801 | if (aom_realloc_frame_buffer( |
| 802 | &cpi->alt_ref_buffer, oxcf->width, oxcf->height, |
| 803 | seq_params->subsampling_x, seq_params->subsampling_y, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 804 | seq_params->use_highbitdepth, oxcf->border_in_pixels, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 805 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 806 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 807 | "Failed to allocate altref buffer"); |
| 808 | } |
| 809 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 810 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 811 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 812 | const SequenceHeader *const seq_params = &cm->seq_params; |
| 813 | if (aom_realloc_frame_buffer( |
| 814 | &cpi->last_frame_uf, cm->width, cm->height, seq_params->subsampling_x, |
| 815 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 816 | cpi->oxcf.border_in_pixels, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 817 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 818 | "Failed to allocate last frame buffer"); |
| 819 | |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 820 | if (aom_realloc_frame_buffer( |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 821 | &cpi->trial_frame_rst, cm->superres_upscaled_width, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 822 | cm->superres_upscaled_height, seq_params->subsampling_x, |
| 823 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 3b12c00 | 2018-12-19 15:27:20 +0530 | [diff] [blame] | 824 | AOM_RESTORATION_FRAME_BORDER, cm->byte_alignment, NULL, NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 825 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 826 | "Failed to allocate trial restored frame buffer"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 827 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 828 | if (aom_realloc_frame_buffer( |
| 829 | &cpi->scaled_source, cm->width, cm->height, seq_params->subsampling_x, |
| 830 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 831 | cpi->oxcf.border_in_pixels, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 832 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 833 | "Failed to allocate scaled source buffer"); |
| 834 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 835 | if (aom_realloc_frame_buffer( |
| 836 | &cpi->scaled_last_source, cm->width, cm->height, |
| 837 | seq_params->subsampling_x, seq_params->subsampling_y, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 838 | seq_params->use_highbitdepth, cpi->oxcf.border_in_pixels, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 839 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 840 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 841 | "Failed to allocate scaled last source buffer"); |
| 842 | } |
| 843 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 844 | static void alloc_compressor_data(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 845 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 846 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 847 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 848 | av1_alloc_context_buffers(cm, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 849 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 850 | int mi_rows_aligned_to_sb = |
| 851 | ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 852 | int sb_rows = mi_rows_aligned_to_sb >> cm->seq_params.mib_size_log2; |
| 853 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 854 | av1_alloc_txb_buf(cpi); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 855 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 856 | alloc_context_buffers_ext(cpi); |
| 857 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 858 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 859 | |
| 860 | { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 861 | unsigned int tokens = |
| 862 | get_token_alloc(cm->mb_rows, cm->mb_cols, MAX_SB_SIZE_LOG2, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 863 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 864 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 865 | } |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 866 | aom_free(cpi->tplist[0][0]); |
| 867 | |
| 868 | CHECK_MEM_ERROR(cm, cpi->tplist[0][0], |
| 869 | aom_calloc(sb_rows * MAX_TILE_ROWS * MAX_TILE_COLS, |
| 870 | sizeof(*cpi->tplist[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 871 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 872 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 875 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 876 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 877 | av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Yunqing Wang | 75e20e8 | 2018-06-16 12:10:48 -0700 | [diff] [blame] | 880 | static void set_tile_info(AV1_COMP *cpi) { |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 881 | AV1_COMMON *const cm = &cpi->common; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 882 | int i, start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 883 | |
| 884 | av1_get_tile_limits(cm); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 885 | |
| 886 | // configure tile columns |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 887 | if (cpi->oxcf.tile_width_count == 0 || cpi->oxcf.tile_height_count == 0) { |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 888 | cm->uniform_tile_spacing_flag = 1; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 889 | cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols); |
| 890 | cm->log2_tile_cols = AOMMIN(cm->log2_tile_cols, cm->max_log2_tile_cols); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 891 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 892 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->seq_params.mib_size_log2); |
| 893 | int sb_cols = mi_cols >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 894 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 895 | cm->uniform_tile_spacing_flag = 0; |
| 896 | for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) { |
| 897 | cm->tile_col_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 898 | size_sb = cpi->oxcf.tile_widths[j++]; |
| 899 | if (j >= cpi->oxcf.tile_width_count) j = 0; |
David Barker | 6cd5a82 | 2018-03-05 16:19:28 +0000 | [diff] [blame] | 900 | start_sb += AOMMIN(size_sb, cm->max_tile_width_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 901 | } |
| 902 | cm->tile_cols = i; |
| 903 | cm->tile_col_start_sb[i] = sb_cols; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 904 | } |
| 905 | av1_calculate_tile_cols(cm); |
| 906 | |
| 907 | // configure tile rows |
| 908 | if (cm->uniform_tile_spacing_flag) { |
| 909 | cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows); |
| 910 | cm->log2_tile_rows = AOMMIN(cm->log2_tile_rows, cm->max_log2_tile_rows); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 911 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 912 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 913 | int sb_rows = mi_rows >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 914 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 915 | for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) { |
| 916 | cm->tile_row_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 917 | size_sb = cpi->oxcf.tile_heights[j++]; |
| 918 | if (j >= cpi->oxcf.tile_height_count) j = 0; |
| 919 | start_sb += AOMMIN(size_sb, cm->max_tile_height_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 920 | } |
| 921 | cm->tile_rows = i; |
| 922 | cm->tile_row_start_sb[i] = sb_rows; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 923 | } |
| 924 | av1_calculate_tile_rows(cm); |
| 925 | } |
| 926 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 927 | static void update_frame_size(AV1_COMP *cpi) { |
| 928 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 929 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 930 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 931 | av1_set_mb_mi(cm, cm->width, cm->height); |
| 932 | av1_init_context_buffers(cm); |
Luc Trudeau | 1e84af5 | 2017-11-25 15:00:28 -0500 | [diff] [blame] | 933 | av1_init_macroblockd(cm, xd, NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 934 | memset(cpi->mbmi_ext_base, 0, |
| 935 | cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 936 | set_tile_info(cpi); |
| 937 | } |
| 938 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 939 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 940 | int fb_idx; |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 941 | for (fb_idx = 0; fb_idx < REF_FRAMES; ++fb_idx) |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 942 | cpi->common.remapped_ref_idx[fb_idx] = fb_idx; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 943 | cpi->rate_index = 0; |
| 944 | cpi->rate_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 947 | static INLINE int does_level_match(int width, int height, double fps, |
| 948 | int lvl_width, int lvl_height, |
| 949 | double lvl_fps, int lvl_dim_mult) { |
| 950 | const int64_t lvl_luma_pels = lvl_width * lvl_height; |
| 951 | const double lvl_display_sample_rate = lvl_luma_pels * lvl_fps; |
| 952 | const int64_t luma_pels = width * height; |
| 953 | const double display_sample_rate = luma_pels * fps; |
| 954 | return luma_pels <= lvl_luma_pels && |
| 955 | display_sample_rate <= lvl_display_sample_rate && |
| 956 | width <= lvl_width * lvl_dim_mult && |
| 957 | height <= lvl_height * lvl_dim_mult; |
| 958 | } |
| 959 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 960 | static void set_bitstream_level_tier(SequenceHeader *seq, AV1_COMMON *cm, |
Andrey Norkin | f481d98 | 2018-05-15 12:05:31 -0700 | [diff] [blame] | 961 | const AV1EncoderConfig *oxcf) { |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 962 | // TODO(any): This is a placeholder function that only addresses dimensions |
| 963 | // and max display sample rates. |
| 964 | // Need to add checks for max bit rate, max decoded luma sample rate, header |
| 965 | // rate, etc. that are not covered by this function. |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 966 | AV1_LEVEL level = SEQ_LEVEL_MAX; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 967 | if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, 512, |
| 968 | 288, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 969 | level = SEQ_LEVEL_2_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 970 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 971 | 704, 396, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 972 | level = SEQ_LEVEL_2_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 973 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 974 | 1088, 612, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 975 | level = SEQ_LEVEL_3_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 976 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 977 | 1376, 774, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 978 | level = SEQ_LEVEL_3_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 979 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 980 | 2048, 1152, 30.0, 3)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 981 | level = SEQ_LEVEL_4_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 982 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 983 | 2048, 1152, 60.0, 3)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 984 | level = SEQ_LEVEL_4_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 985 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 986 | 4096, 2176, 30.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 987 | level = SEQ_LEVEL_5_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 988 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 989 | 4096, 2176, 60.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 990 | level = SEQ_LEVEL_5_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 991 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 992 | 4096, 2176, 120.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 993 | level = SEQ_LEVEL_5_2; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 994 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 995 | 8192, 4352, 30.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 996 | level = SEQ_LEVEL_6_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 997 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 998 | 8192, 4352, 60.0, 2)) { |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 999 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1000 | 8192, 4352, 120.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1001 | level = SEQ_LEVEL_6_2; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1002 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1003 | 16384, 8704, 30.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1004 | level = SEQ_LEVEL_7_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1005 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1006 | 16384, 8704, 60.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1007 | level = SEQ_LEVEL_7_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1008 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1009 | 16384, 8704, 120.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1010 | level = SEQ_LEVEL_7_2; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1011 | } |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 1012 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1013 | seq->seq_level_idx[i] = level; |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1014 | // Set the maximum parameters for bitrate and buffer size for this profile, |
| 1015 | // level, and tier |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 1016 | cm->op_params[i].bitrate = av1_max_level_bitrate( |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1017 | cm->seq_params.profile, seq->seq_level_idx[i], seq->tier[i]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1018 | // Level with seq_level_idx = 31 returns a high "dummy" bitrate to pass the |
| 1019 | // check |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1020 | if (cm->op_params[i].bitrate == 0) |
| 1021 | aom_internal_error( |
| 1022 | &cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
| 1023 | "AV1 does not support this combination of profile, level, and tier."); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1024 | // Buffer size in bits/s is bitrate in bits/s * 1 s |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1025 | cm->op_params[i].buffer_size = cm->op_params[i].bitrate; |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1029 | static void init_seq_coding_tools(SequenceHeader *seq, AV1_COMMON *cm, |
| 1030 | const AV1EncoderConfig *oxcf) { |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1031 | seq->still_picture = (oxcf->limit == 1); |
| 1032 | seq->reduced_still_picture_hdr = seq->still_picture; |
Debargha Mukherjee | 9713ccb | 2018-04-08 19:09:17 -0700 | [diff] [blame] | 1033 | seq->reduced_still_picture_hdr &= !oxcf->full_still_picture_hdr; |
kyslov | 9424338 | 2019-05-02 15:33:32 -0700 | [diff] [blame] | 1034 | seq->force_screen_content_tools = (oxcf->mode == REALTIME) ? 0 : 2; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1035 | seq->force_integer_mv = 2; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1036 | seq->order_hint_info.enable_order_hint = oxcf->enable_order_hint; |
David Turner | 936235c | 2018-11-28 13:42:01 +0000 | [diff] [blame] | 1037 | seq->frame_id_numbers_present_flag = |
| 1038 | !(seq->still_picture && seq->reduced_still_picture_hdr) && |
| 1039 | !oxcf->large_scale_tile && oxcf->error_resilient_mode; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1040 | if (seq->still_picture && seq->reduced_still_picture_hdr) { |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1041 | seq->order_hint_info.enable_order_hint = 0; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1042 | seq->force_screen_content_tools = 2; |
| 1043 | seq->force_integer_mv = 2; |
| 1044 | } |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1045 | seq->order_hint_info.order_hint_bits_minus_1 = |
| 1046 | seq->order_hint_info.enable_order_hint |
| 1047 | ? DEFAULT_EXPLICIT_ORDER_HINT_BITS - 1 |
| 1048 | : -1; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1049 | |
David Turner | 760a2f4 | 2018-12-07 15:25:36 +0000 | [diff] [blame] | 1050 | seq->max_frame_width = |
| 1051 | oxcf->forced_max_frame_width ? oxcf->forced_max_frame_width : oxcf->width; |
| 1052 | seq->max_frame_height = oxcf->forced_max_frame_height |
| 1053 | ? oxcf->forced_max_frame_height |
| 1054 | : oxcf->height; |
| 1055 | seq->num_bits_width = |
| 1056 | (seq->max_frame_width > 1) ? get_msb(seq->max_frame_width - 1) + 1 : 1; |
| 1057 | seq->num_bits_height = |
| 1058 | (seq->max_frame_height > 1) ? get_msb(seq->max_frame_height - 1) + 1 : 1; |
| 1059 | assert(seq->num_bits_width <= 16); |
| 1060 | assert(seq->num_bits_height <= 16); |
| 1061 | |
| 1062 | seq->frame_id_length = FRAME_ID_LENGTH; |
| 1063 | seq->delta_frame_id_length = DELTA_FRAME_ID_LENGTH; |
| 1064 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1065 | seq->enable_dual_filter = oxcf->enable_dual_filter; |
Debargha Mukherjee | 7ac3eb1 | 2018-12-12 10:26:50 -0800 | [diff] [blame] | 1066 | seq->order_hint_info.enable_dist_wtd_comp = oxcf->enable_dist_wtd_comp; |
| 1067 | seq->order_hint_info.enable_dist_wtd_comp &= |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1068 | seq->order_hint_info.enable_order_hint; |
| 1069 | seq->order_hint_info.enable_ref_frame_mvs = oxcf->enable_ref_frame_mvs; |
| 1070 | seq->order_hint_info.enable_ref_frame_mvs &= |
| 1071 | seq->order_hint_info.enable_order_hint; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1072 | seq->enable_superres = oxcf->enable_superres; |
| 1073 | seq->enable_cdef = oxcf->enable_cdef; |
| 1074 | seq->enable_restoration = oxcf->enable_restoration; |
Debargha Mukherjee | 37df916 | 2018-03-25 12:48:24 -0700 | [diff] [blame] | 1075 | seq->enable_warped_motion = oxcf->enable_warped_motion; |
Debargha Mukherjee | 16ea6ba | 2018-12-10 12:01:38 -0800 | [diff] [blame] | 1076 | seq->enable_interintra_compound = oxcf->enable_interintra_comp; |
| 1077 | seq->enable_masked_compound = oxcf->enable_masked_comp; |
Debargha Mukherjee | 03c43ba | 2018-12-14 13:08:08 -0800 | [diff] [blame] | 1078 | seq->enable_intra_edge_filter = oxcf->enable_intra_edge_filter; |
Yue Chen | 8f9ca58 | 2018-12-12 15:11:47 -0800 | [diff] [blame] | 1079 | seq->enable_filter_intra = oxcf->enable_filter_intra; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1080 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1081 | set_bitstream_level_tier(seq, cm, oxcf); |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1082 | |
| 1083 | if (seq->operating_points_cnt_minus_1 == 0) { |
| 1084 | seq->operating_point_idc[0] = 0; |
| 1085 | } else { |
| 1086 | // Set operating_point_idc[] such that for the i-th operating point the |
| 1087 | // first (operating_points_cnt-i) spatial layers and the first temporal |
| 1088 | // layer are decoded Note that highest quality operating point should come |
| 1089 | // first |
| 1090 | for (int i = 0; i < seq->operating_points_cnt_minus_1 + 1; i++) |
| 1091 | seq->operating_point_idc[i] = |
| 1092 | (~(~0u << (seq->operating_points_cnt_minus_1 + 1 - i)) << 8) | 1; |
| 1093 | } |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1096 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 1097 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1098 | |
| 1099 | cpi->oxcf = *oxcf; |
| 1100 | cpi->framerate = oxcf->init_framerate; |
| 1101 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1102 | cm->seq_params.profile = oxcf->profile; |
| 1103 | cm->seq_params.bit_depth = oxcf->bit_depth; |
| 1104 | cm->seq_params.use_highbitdepth = oxcf->use_highbitdepth; |
| 1105 | cm->seq_params.color_primaries = oxcf->color_primaries; |
| 1106 | cm->seq_params.transfer_characteristics = oxcf->transfer_characteristics; |
| 1107 | cm->seq_params.matrix_coefficients = oxcf->matrix_coefficients; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 1108 | cm->seq_params.monochrome = oxcf->monochrome; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1109 | cm->seq_params.chroma_sample_position = oxcf->chroma_sample_position; |
| 1110 | cm->seq_params.color_range = oxcf->color_range; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 1111 | cm->timing_info_present = oxcf->timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1112 | cm->timing_info.num_units_in_display_tick = |
| 1113 | oxcf->timing_info.num_units_in_display_tick; |
| 1114 | cm->timing_info.time_scale = oxcf->timing_info.time_scale; |
| 1115 | cm->timing_info.equal_picture_interval = |
| 1116 | oxcf->timing_info.equal_picture_interval; |
| 1117 | cm->timing_info.num_ticks_per_picture = |
| 1118 | oxcf->timing_info.num_ticks_per_picture; |
| 1119 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1120 | cm->seq_params.display_model_info_present_flag = |
| 1121 | oxcf->display_model_info_present_flag; |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1122 | cm->seq_params.decoder_model_info_present_flag = |
| 1123 | oxcf->decoder_model_info_present_flag; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1124 | if (oxcf->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1125 | // set the decoder model parameters in schedule mode |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1126 | cm->buffer_model.num_units_in_decoding_tick = |
| 1127 | oxcf->buffer_model.num_units_in_decoding_tick; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 1128 | cm->buffer_removal_time_present = 1; |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 1129 | av1_set_aom_dec_model_info(&cm->buffer_model); |
| 1130 | av1_set_dec_model_op_parameters(&cm->op_params[0]); |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1131 | } else if (cm->timing_info_present && |
| 1132 | cm->timing_info.equal_picture_interval && |
| 1133 | !cm->seq_params.decoder_model_info_present_flag) { |
| 1134 | // set the decoder model parameters in resource availability mode |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 1135 | av1_set_resource_availability_parameters(&cm->op_params[0]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1136 | } else { |
| 1137 | cm->op_params[0].initial_display_delay = |
| 1138 | 10; // Default value (not signaled) |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1139 | } |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1140 | |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 1141 | if (cm->seq_params.monochrome) { |
| 1142 | cm->seq_params.subsampling_x = 1; |
| 1143 | cm->seq_params.subsampling_y = 1; |
| 1144 | } else if (cm->seq_params.color_primaries == AOM_CICP_CP_BT_709 && |
| 1145 | cm->seq_params.transfer_characteristics == AOM_CICP_TC_SRGB && |
| 1146 | cm->seq_params.matrix_coefficients == AOM_CICP_MC_IDENTITY) { |
| 1147 | cm->seq_params.subsampling_x = 0; |
| 1148 | cm->seq_params.subsampling_y = 0; |
| 1149 | } else { |
| 1150 | if (cm->seq_params.profile == 0) { |
| 1151 | cm->seq_params.subsampling_x = 1; |
| 1152 | cm->seq_params.subsampling_y = 1; |
| 1153 | } else if (cm->seq_params.profile == 1) { |
| 1154 | cm->seq_params.subsampling_x = 0; |
| 1155 | cm->seq_params.subsampling_y = 0; |
| 1156 | } else { |
| 1157 | if (cm->seq_params.bit_depth == AOM_BITS_12) { |
| 1158 | cm->seq_params.subsampling_x = oxcf->chroma_subsampling_x; |
| 1159 | cm->seq_params.subsampling_y = oxcf->chroma_subsampling_y; |
| 1160 | } else { |
| 1161 | cm->seq_params.subsampling_x = 1; |
| 1162 | cm->seq_params.subsampling_y = 0; |
| 1163 | } |
| 1164 | } |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1167 | cm->width = oxcf->width; |
| 1168 | cm->height = oxcf->height; |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 1169 | set_sb_size(&cm->seq_params, |
| 1170 | select_sb_size(cpi)); // set sb size before allocations |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 1171 | alloc_compressor_data(cpi); |
Yaowu Xu | c7119a7 | 2018-03-29 09:59:37 -0700 | [diff] [blame] | 1172 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 1173 | update_film_grain_parameters(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1174 | |
| 1175 | // Single thread case: use counts in common. |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 1176 | cpi->td.counts = &cpi->counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1177 | |
| 1178 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1179 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1180 | |
| 1181 | cpi->static_mb_pct = 0; |
| 1182 | cpi->ref_frame_flags = 0; |
| 1183 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 1184 | // Reset resize pending flags |
| 1185 | cpi->resize_pending_width = 0; |
| 1186 | cpi->resize_pending_height = 0; |
| 1187 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1188 | init_buffer_indices(cpi); |
| 1189 | } |
| 1190 | |
| 1191 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1192 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1193 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 1194 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 1195 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 1196 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 1197 | |
| 1198 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 1199 | rc->optimal_buffer_level = |
| 1200 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1201 | rc->maximum_buffer_size = |
| 1202 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1203 | } |
| 1204 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1205 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \ |
| 1206 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1207 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1208 | cpi->fn_ptr[BT].vf = VF; \ |
| 1209 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1210 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1211 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 1212 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1213 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1214 | |
| 1215 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1216 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1217 | int source_stride, \ |
| 1218 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1219 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1220 | } \ |
| 1221 | static unsigned int fnname##_bits10( \ |
| 1222 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1223 | int ref_stride) { \ |
| 1224 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1225 | } \ |
| 1226 | static unsigned int fnname##_bits12( \ |
| 1227 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1228 | int ref_stride) { \ |
| 1229 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1230 | } |
| 1231 | |
| 1232 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1233 | static unsigned int fnname##_bits8( \ |
| 1234 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1235 | int ref_stride, const uint8_t *second_pred) { \ |
| 1236 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1237 | } \ |
| 1238 | static unsigned int fnname##_bits10( \ |
| 1239 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1240 | int ref_stride, const uint8_t *second_pred) { \ |
| 1241 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1242 | 2; \ |
| 1243 | } \ |
| 1244 | static unsigned int fnname##_bits12( \ |
| 1245 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1246 | int ref_stride, const uint8_t *second_pred) { \ |
| 1247 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1248 | 4; \ |
| 1249 | } |
| 1250 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1251 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1252 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1253 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1254 | unsigned int *sad_array) { \ |
| 1255 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1256 | } \ |
| 1257 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1258 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1259 | unsigned int *sad_array) { \ |
| 1260 | int i; \ |
| 1261 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1262 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1263 | } \ |
| 1264 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1265 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1266 | unsigned int *sad_array) { \ |
| 1267 | int i; \ |
| 1268 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1269 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1270 | } |
| 1271 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1272 | #define MAKE_BFP_JSADAVG_WRAPPER(fnname) \ |
| 1273 | static unsigned int fnname##_bits8( \ |
| 1274 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1275 | int ref_stride, const uint8_t *second_pred, \ |
Debargha Mukherjee | f90004a | 2018-12-20 13:35:06 -0800 | [diff] [blame] | 1276 | const DIST_WTD_COMP_PARAMS *jcp_param) { \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1277 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1278 | jcp_param); \ |
| 1279 | } \ |
| 1280 | static unsigned int fnname##_bits10( \ |
| 1281 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1282 | int ref_stride, const uint8_t *second_pred, \ |
Debargha Mukherjee | f90004a | 2018-12-20 13:35:06 -0800 | [diff] [blame] | 1283 | const DIST_WTD_COMP_PARAMS *jcp_param) { \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1284 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1285 | jcp_param) >> \ |
| 1286 | 2; \ |
| 1287 | } \ |
| 1288 | static unsigned int fnname##_bits12( \ |
| 1289 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1290 | int ref_stride, const uint8_t *second_pred, \ |
Debargha Mukherjee | f90004a | 2018-12-20 13:35:06 -0800 | [diff] [blame] | 1291 | const DIST_WTD_COMP_PARAMS *jcp_param) { \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1292 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1293 | jcp_param) >> \ |
| 1294 | 4; \ |
| 1295 | } |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1296 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1297 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1298 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1299 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1300 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1301 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1302 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1303 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1304 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1305 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1306 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1307 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1308 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1309 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1310 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1311 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1312 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1313 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1314 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1315 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1316 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1317 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1318 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1319 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1320 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1321 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1322 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1323 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1324 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1325 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1326 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1327 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1328 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1329 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1330 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1331 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1332 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1333 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1334 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1335 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1336 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1337 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1338 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1339 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1340 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1341 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1342 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1343 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1344 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1345 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1346 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16) |
| 1347 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg) |
| 1348 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d) |
| 1349 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4) |
| 1350 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg) |
| 1351 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d) |
| 1352 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32) |
| 1353 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg) |
| 1354 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d) |
| 1355 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8) |
| 1356 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg) |
| 1357 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1358 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64) |
| 1359 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg) |
| 1360 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d) |
| 1361 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16) |
| 1362 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg) |
| 1363 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1364 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1365 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x128_avg) |
| 1366 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x64_avg) |
| 1367 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x128_avg) |
| 1368 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x16_avg) |
| 1369 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x32_avg) |
| 1370 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x32_avg) |
| 1371 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x64_avg) |
| 1372 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x32_avg) |
| 1373 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x64_avg) |
| 1374 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x16_avg) |
| 1375 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x8_avg) |
| 1376 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x16_avg) |
| 1377 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x8_avg) |
| 1378 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x4_avg) |
| 1379 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x8_avg) |
| 1380 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x4_avg) |
| 1381 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x16_avg) |
| 1382 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x4_avg) |
| 1383 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x32_avg) |
| 1384 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x8_avg) |
| 1385 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x64_avg) |
| 1386 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x16_avg) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1387 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1388 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1389 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1390 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1391 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1392 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1393 | static unsigned int fnname##_bits8( \ |
| 1394 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1395 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1396 | int m_stride, int invert_mask) { \ |
| 1397 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1398 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1399 | } \ |
| 1400 | static unsigned int fnname##_bits10( \ |
| 1401 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1402 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1403 | int m_stride, int invert_mask) { \ |
| 1404 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1405 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1406 | 2; \ |
| 1407 | } \ |
| 1408 | static unsigned int fnname##_bits12( \ |
| 1409 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1410 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1411 | int m_stride, int invert_mask) { \ |
| 1412 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1413 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1414 | 4; \ |
| 1415 | } |
| 1416 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1417 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1418 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1419 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1420 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1421 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1422 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1423 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1424 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1425 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1426 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1427 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1428 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1429 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1430 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1431 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1432 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1433 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1434 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1435 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1436 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1437 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1438 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1439 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1440 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1441 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1442 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1443 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1444 | |
| 1445 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1446 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1447 | const int32_t *wsrc, \ |
| 1448 | const int32_t *msk) { \ |
| 1449 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1450 | } \ |
| 1451 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1452 | const int32_t *wsrc, \ |
| 1453 | const int32_t *msk) { \ |
| 1454 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1455 | } \ |
| 1456 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1457 | const int32_t *wsrc, \ |
| 1458 | const int32_t *msk) { \ |
| 1459 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1460 | } |
| 1461 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1462 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1463 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1464 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1465 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1466 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1467 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1468 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1469 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1470 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1471 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1472 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1473 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1474 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1475 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1476 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1477 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1478 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1479 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1480 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1481 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1482 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1483 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1484 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1485 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1486 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1487 | if (cm->seq_params.use_highbitdepth) { |
| 1488 | switch (cm->seq_params.bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1489 | case AOM_BITS_8: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1490 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1491 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1492 | aom_highbd_8_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1493 | aom_highbd_8_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1494 | aom_highbd_sad64x16x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1495 | aom_highbd_dist_wtd_sad64x16_avg_bits8, |
| 1496 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1497 | |
| 1498 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1499 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1500 | aom_highbd_8_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1501 | aom_highbd_8_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1502 | aom_highbd_sad16x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1503 | aom_highbd_dist_wtd_sad16x64_avg_bits8, |
| 1504 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1505 | |
| 1506 | HIGHBD_BFP( |
| 1507 | BLOCK_32X8, aom_highbd_sad32x8_bits8, aom_highbd_sad32x8_avg_bits8, |
| 1508 | aom_highbd_8_variance32x8, aom_highbd_8_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1509 | aom_highbd_8_sub_pixel_avg_variance32x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1510 | aom_highbd_sad32x8x4d_bits8, aom_highbd_dist_wtd_sad32x8_avg_bits8, |
| 1511 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x8) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1512 | |
| 1513 | HIGHBD_BFP( |
| 1514 | BLOCK_8X32, aom_highbd_sad8x32_bits8, aom_highbd_sad8x32_avg_bits8, |
| 1515 | aom_highbd_8_variance8x32, aom_highbd_8_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1516 | aom_highbd_8_sub_pixel_avg_variance8x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1517 | aom_highbd_sad8x32x4d_bits8, aom_highbd_dist_wtd_sad8x32_avg_bits8, |
| 1518 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1519 | |
| 1520 | HIGHBD_BFP( |
| 1521 | BLOCK_16X4, aom_highbd_sad16x4_bits8, aom_highbd_sad16x4_avg_bits8, |
| 1522 | aom_highbd_8_variance16x4, aom_highbd_8_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1523 | aom_highbd_8_sub_pixel_avg_variance16x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1524 | aom_highbd_sad16x4x4d_bits8, aom_highbd_dist_wtd_sad16x4_avg_bits8, |
| 1525 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x4) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1526 | |
| 1527 | HIGHBD_BFP( |
| 1528 | BLOCK_4X16, aom_highbd_sad4x16_bits8, aom_highbd_sad4x16_avg_bits8, |
| 1529 | aom_highbd_8_variance4x16, aom_highbd_8_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1530 | aom_highbd_8_sub_pixel_avg_variance4x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1531 | aom_highbd_sad4x16x4d_bits8, aom_highbd_dist_wtd_sad4x16_avg_bits8, |
| 1532 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance4x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1533 | |
| 1534 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1535 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1536 | aom_highbd_8_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1537 | aom_highbd_8_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1538 | aom_highbd_sad32x16x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1539 | aom_highbd_dist_wtd_sad32x16_avg_bits8, |
| 1540 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1541 | |
| 1542 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1543 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1544 | aom_highbd_8_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1545 | aom_highbd_8_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1546 | aom_highbd_sad16x32x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1547 | aom_highbd_dist_wtd_sad16x32_avg_bits8, |
| 1548 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1549 | |
| 1550 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1551 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1552 | aom_highbd_8_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1553 | aom_highbd_8_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1554 | aom_highbd_sad64x32x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1555 | aom_highbd_dist_wtd_sad64x32_avg_bits8, |
| 1556 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1557 | |
| 1558 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1559 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1560 | aom_highbd_8_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1561 | aom_highbd_8_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1562 | aom_highbd_sad32x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1563 | aom_highbd_dist_wtd_sad32x64_avg_bits8, |
| 1564 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1565 | |
| 1566 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1567 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1568 | aom_highbd_8_sub_pixel_variance32x32, |
| 1569 | aom_highbd_8_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1570 | aom_highbd_sad32x32x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1571 | aom_highbd_dist_wtd_sad32x32_avg_bits8, |
| 1572 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1573 | |
| 1574 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1575 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1576 | aom_highbd_8_sub_pixel_variance64x64, |
| 1577 | aom_highbd_8_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1578 | aom_highbd_sad64x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1579 | aom_highbd_dist_wtd_sad64x64_avg_bits8, |
| 1580 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1581 | |
| 1582 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1583 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1584 | aom_highbd_8_sub_pixel_variance16x16, |
| 1585 | aom_highbd_8_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1586 | aom_highbd_sad16x16x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1587 | aom_highbd_dist_wtd_sad16x16_avg_bits8, |
| 1588 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1589 | |
| 1590 | HIGHBD_BFP( |
| 1591 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1592 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1593 | aom_highbd_8_sub_pixel_avg_variance16x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1594 | aom_highbd_sad16x8x4d_bits8, aom_highbd_dist_wtd_sad16x8_avg_bits8, |
| 1595 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x8) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1596 | |
| 1597 | HIGHBD_BFP( |
| 1598 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1599 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1600 | aom_highbd_8_sub_pixel_avg_variance8x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1601 | aom_highbd_sad8x16x4d_bits8, aom_highbd_dist_wtd_sad8x16_avg_bits8, |
| 1602 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1603 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1604 | HIGHBD_BFP( |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1605 | BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8, |
| 1606 | aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8, |
| 1607 | aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x4d_bits8, |
| 1608 | aom_highbd_dist_wtd_sad8x8_avg_bits8, |
| 1609 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x8) |
| 1610 | |
| 1611 | HIGHBD_BFP( |
| 1612 | BLOCK_8X4, aom_highbd_sad8x4_bits8, aom_highbd_sad8x4_avg_bits8, |
| 1613 | aom_highbd_8_variance8x4, aom_highbd_8_sub_pixel_variance8x4, |
| 1614 | aom_highbd_8_sub_pixel_avg_variance8x4, aom_highbd_sad8x4x4d_bits8, |
| 1615 | aom_highbd_dist_wtd_sad8x4_avg_bits8, |
| 1616 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x4) |
| 1617 | |
| 1618 | HIGHBD_BFP( |
| 1619 | BLOCK_4X8, aom_highbd_sad4x8_bits8, aom_highbd_sad4x8_avg_bits8, |
| 1620 | aom_highbd_8_variance4x8, aom_highbd_8_sub_pixel_variance4x8, |
| 1621 | aom_highbd_8_sub_pixel_avg_variance4x8, aom_highbd_sad4x8x4d_bits8, |
| 1622 | aom_highbd_dist_wtd_sad4x8_avg_bits8, |
| 1623 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance4x8) |
| 1624 | |
| 1625 | HIGHBD_BFP( |
| 1626 | BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8, |
| 1627 | aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4, |
| 1628 | aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x4d_bits8, |
| 1629 | aom_highbd_dist_wtd_sad4x4_avg_bits8, |
| 1630 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance4x4) |
| 1631 | |
| 1632 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1633 | aom_highbd_sad128x128_avg_bits8, |
| 1634 | aom_highbd_8_variance128x128, |
| 1635 | aom_highbd_8_sub_pixel_variance128x128, |
| 1636 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1637 | aom_highbd_sad128x128x4d_bits8, |
| 1638 | aom_highbd_dist_wtd_sad128x128_avg_bits8, |
| 1639 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance128x128) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1640 | |
| 1641 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1642 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1643 | aom_highbd_8_sub_pixel_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1644 | aom_highbd_8_sub_pixel_avg_variance128x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1645 | aom_highbd_sad128x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1646 | aom_highbd_dist_wtd_sad128x64_avg_bits8, |
| 1647 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance128x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1648 | |
| 1649 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1650 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1651 | aom_highbd_8_sub_pixel_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1652 | aom_highbd_8_sub_pixel_avg_variance64x128, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1653 | aom_highbd_sad64x128x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1654 | aom_highbd_dist_wtd_sad64x128_avg_bits8, |
| 1655 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1656 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1657 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1658 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1659 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1660 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1661 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1662 | aom_highbd_8_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1663 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1664 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1665 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1666 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1667 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1668 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1669 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1670 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1671 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1672 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1673 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1674 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1675 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1676 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1677 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1678 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1679 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1680 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1681 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1682 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1683 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1684 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1685 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1686 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1687 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1688 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1689 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1690 | aom_highbd_8_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1691 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1692 | aom_highbd_8_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1693 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1694 | aom_highbd_8_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1695 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1696 | aom_highbd_8_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1697 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1698 | aom_highbd_8_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1699 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1700 | aom_highbd_8_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1701 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1702 | aom_highbd_obmc_variance128x128, |
| 1703 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1704 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1705 | aom_highbd_obmc_variance128x64, |
| 1706 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1707 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1708 | aom_highbd_obmc_variance64x128, |
| 1709 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1710 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1711 | aom_highbd_obmc_variance64x64, |
| 1712 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1713 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1714 | aom_highbd_obmc_variance64x32, |
| 1715 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1716 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1717 | aom_highbd_obmc_variance32x64, |
| 1718 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1719 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1720 | aom_highbd_obmc_variance32x32, |
| 1721 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1722 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1723 | aom_highbd_obmc_variance32x16, |
| 1724 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1725 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1726 | aom_highbd_obmc_variance16x32, |
| 1727 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1728 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1729 | aom_highbd_obmc_variance16x16, |
| 1730 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1731 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1732 | aom_highbd_obmc_variance8x16, |
| 1733 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1734 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1735 | aom_highbd_obmc_variance16x8, |
| 1736 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1737 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1738 | aom_highbd_obmc_variance8x8, |
| 1739 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 1740 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 1741 | aom_highbd_obmc_variance4x8, |
| 1742 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 1743 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 1744 | aom_highbd_obmc_variance8x4, |
| 1745 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 1746 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 1747 | aom_highbd_obmc_variance4x4, |
| 1748 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1749 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 1750 | aom_highbd_obmc_variance64x16, |
| 1751 | aom_highbd_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1752 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 1753 | aom_highbd_obmc_variance16x64, |
| 1754 | aom_highbd_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1755 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 1756 | aom_highbd_obmc_variance32x8, |
| 1757 | aom_highbd_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1758 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 1759 | aom_highbd_obmc_variance8x32, |
| 1760 | aom_highbd_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1761 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 1762 | aom_highbd_obmc_variance16x4, |
| 1763 | aom_highbd_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1764 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 1765 | aom_highbd_obmc_variance4x16, |
| 1766 | aom_highbd_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1767 | break; |
| 1768 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1769 | case AOM_BITS_10: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1770 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 1771 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 1772 | aom_highbd_10_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1773 | aom_highbd_10_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1774 | aom_highbd_sad64x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1775 | aom_highbd_dist_wtd_sad64x16_avg_bits10, |
| 1776 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1777 | |
| 1778 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 1779 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 1780 | aom_highbd_10_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1781 | aom_highbd_10_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1782 | aom_highbd_sad16x64x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1783 | aom_highbd_dist_wtd_sad16x64_avg_bits10, |
| 1784 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1785 | |
| 1786 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 1787 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 1788 | aom_highbd_10_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1789 | aom_highbd_10_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1790 | aom_highbd_sad32x8x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1791 | aom_highbd_dist_wtd_sad32x8_avg_bits10, |
| 1792 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1793 | |
| 1794 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 1795 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 1796 | aom_highbd_10_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1797 | aom_highbd_10_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1798 | aom_highbd_sad8x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1799 | aom_highbd_dist_wtd_sad8x32_avg_bits10, |
| 1800 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1801 | |
| 1802 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 1803 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 1804 | aom_highbd_10_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1805 | aom_highbd_10_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1806 | aom_highbd_sad16x4x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1807 | aom_highbd_dist_wtd_sad16x4_avg_bits10, |
| 1808 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1809 | |
| 1810 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 1811 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 1812 | aom_highbd_10_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1813 | aom_highbd_10_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1814 | aom_highbd_sad4x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1815 | aom_highbd_dist_wtd_sad4x16_avg_bits10, |
| 1816 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1817 | |
| 1818 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 1819 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 1820 | aom_highbd_10_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1821 | aom_highbd_10_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1822 | aom_highbd_sad32x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1823 | aom_highbd_dist_wtd_sad32x16_avg_bits10, |
| 1824 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1825 | |
| 1826 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 1827 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 1828 | aom_highbd_10_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1829 | aom_highbd_10_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1830 | aom_highbd_sad16x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1831 | aom_highbd_dist_wtd_sad16x32_avg_bits10, |
| 1832 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1833 | |
| 1834 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 1835 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 1836 | aom_highbd_10_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1837 | aom_highbd_10_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1838 | aom_highbd_sad64x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1839 | aom_highbd_dist_wtd_sad64x32_avg_bits10, |
| 1840 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1841 | |
| 1842 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 1843 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 1844 | aom_highbd_10_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1845 | aom_highbd_10_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1846 | aom_highbd_sad32x64x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1847 | aom_highbd_dist_wtd_sad32x64_avg_bits10, |
| 1848 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1849 | |
| 1850 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 1851 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 1852 | aom_highbd_10_sub_pixel_variance32x32, |
| 1853 | aom_highbd_10_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1854 | aom_highbd_sad32x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1855 | aom_highbd_dist_wtd_sad32x32_avg_bits10, |
| 1856 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1857 | |
| 1858 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 1859 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 1860 | aom_highbd_10_sub_pixel_variance64x64, |
| 1861 | aom_highbd_10_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1862 | aom_highbd_sad64x64x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1863 | aom_highbd_dist_wtd_sad64x64_avg_bits10, |
| 1864 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1865 | |
| 1866 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 1867 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 1868 | aom_highbd_10_sub_pixel_variance16x16, |
| 1869 | aom_highbd_10_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1870 | aom_highbd_sad16x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1871 | aom_highbd_dist_wtd_sad16x16_avg_bits10, |
| 1872 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1873 | |
| 1874 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 1875 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 1876 | aom_highbd_10_sub_pixel_variance16x8, |
| 1877 | aom_highbd_10_sub_pixel_avg_variance16x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1878 | aom_highbd_sad16x8x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1879 | aom_highbd_dist_wtd_sad16x8_avg_bits10, |
| 1880 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1881 | |
| 1882 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 1883 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 1884 | aom_highbd_10_sub_pixel_variance8x16, |
| 1885 | aom_highbd_10_sub_pixel_avg_variance8x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1886 | aom_highbd_sad8x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1887 | aom_highbd_dist_wtd_sad8x16_avg_bits10, |
| 1888 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1889 | |
| 1890 | HIGHBD_BFP( |
| 1891 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 1892 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1893 | aom_highbd_10_sub_pixel_avg_variance8x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1894 | aom_highbd_sad8x8x4d_bits10, aom_highbd_dist_wtd_sad8x8_avg_bits10, |
| 1895 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1896 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1897 | HIGHBD_BFP( |
| 1898 | BLOCK_8X4, aom_highbd_sad8x4_bits10, aom_highbd_sad8x4_avg_bits10, |
| 1899 | aom_highbd_10_variance8x4, aom_highbd_10_sub_pixel_variance8x4, |
| 1900 | aom_highbd_10_sub_pixel_avg_variance8x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1901 | aom_highbd_sad8x4x4d_bits10, aom_highbd_dist_wtd_sad8x4_avg_bits10, |
| 1902 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1903 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1904 | HIGHBD_BFP( |
| 1905 | BLOCK_4X8, aom_highbd_sad4x8_bits10, aom_highbd_sad4x8_avg_bits10, |
| 1906 | aom_highbd_10_variance4x8, aom_highbd_10_sub_pixel_variance4x8, |
| 1907 | aom_highbd_10_sub_pixel_avg_variance4x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1908 | aom_highbd_sad4x8x4d_bits10, aom_highbd_dist_wtd_sad4x8_avg_bits10, |
| 1909 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance4x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1910 | |
| 1911 | HIGHBD_BFP( |
| 1912 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 1913 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1914 | aom_highbd_10_sub_pixel_avg_variance4x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1915 | aom_highbd_sad4x4x4d_bits10, aom_highbd_dist_wtd_sad4x4_avg_bits10, |
| 1916 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance4x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1917 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1918 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 1919 | aom_highbd_sad128x128_avg_bits10, |
| 1920 | aom_highbd_10_variance128x128, |
| 1921 | aom_highbd_10_sub_pixel_variance128x128, |
| 1922 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 1923 | aom_highbd_sad128x128x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1924 | aom_highbd_dist_wtd_sad128x128_avg_bits10, |
| 1925 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance128x128); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1926 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1927 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 1928 | aom_highbd_sad128x64_avg_bits10, |
| 1929 | aom_highbd_10_variance128x64, |
| 1930 | aom_highbd_10_sub_pixel_variance128x64, |
| 1931 | aom_highbd_10_sub_pixel_avg_variance128x64, |
| 1932 | aom_highbd_sad128x64x4d_bits10, |
| 1933 | aom_highbd_dist_wtd_sad128x64_avg_bits10, |
| 1934 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance128x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1935 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1936 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 1937 | aom_highbd_sad64x128_avg_bits10, |
| 1938 | aom_highbd_10_variance64x128, |
| 1939 | aom_highbd_10_sub_pixel_variance64x128, |
| 1940 | aom_highbd_10_sub_pixel_avg_variance64x128, |
| 1941 | aom_highbd_sad64x128x4d_bits10, |
| 1942 | aom_highbd_dist_wtd_sad64x128_avg_bits10, |
| 1943 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1944 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1945 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 1946 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 1947 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 1948 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 1949 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 1950 | aom_highbd_10_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1951 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 1952 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 1953 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 1954 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 1955 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 1956 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 1957 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 1958 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 1959 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 1960 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 1961 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 1962 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 1963 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 1964 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 1965 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 1966 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 1967 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 1968 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 1969 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 1970 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 1971 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 1972 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 1973 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 1974 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 1975 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 1976 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1977 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 1978 | aom_highbd_10_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1979 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 1980 | aom_highbd_10_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1981 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 1982 | aom_highbd_10_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1983 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 1984 | aom_highbd_10_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1985 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 1986 | aom_highbd_10_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1987 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 1988 | aom_highbd_10_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1989 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 1990 | aom_highbd_10_obmc_variance128x128, |
| 1991 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 1992 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 1993 | aom_highbd_10_obmc_variance128x64, |
| 1994 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 1995 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 1996 | aom_highbd_10_obmc_variance64x128, |
| 1997 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1998 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 1999 | aom_highbd_10_obmc_variance64x64, |
| 2000 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 2001 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 2002 | aom_highbd_10_obmc_variance64x32, |
| 2003 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 2004 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 2005 | aom_highbd_10_obmc_variance32x64, |
| 2006 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 2007 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 2008 | aom_highbd_10_obmc_variance32x32, |
| 2009 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 2010 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 2011 | aom_highbd_10_obmc_variance32x16, |
| 2012 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 2013 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 2014 | aom_highbd_10_obmc_variance16x32, |
| 2015 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 2016 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 2017 | aom_highbd_10_obmc_variance16x16, |
| 2018 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 2019 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 2020 | aom_highbd_10_obmc_variance8x16, |
| 2021 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 2022 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 2023 | aom_highbd_10_obmc_variance16x8, |
| 2024 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 2025 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 2026 | aom_highbd_10_obmc_variance8x8, |
| 2027 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 2028 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 2029 | aom_highbd_10_obmc_variance4x8, |
| 2030 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 2031 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 2032 | aom_highbd_10_obmc_variance8x4, |
| 2033 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 2034 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 2035 | aom_highbd_10_obmc_variance4x4, |
| 2036 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2037 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2038 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 2039 | aom_highbd_10_obmc_variance64x16, |
| 2040 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 2041 | |
| 2042 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 2043 | aom_highbd_10_obmc_variance16x64, |
| 2044 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 2045 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2046 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 2047 | aom_highbd_10_obmc_variance32x8, |
| 2048 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 2049 | |
| 2050 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 2051 | aom_highbd_10_obmc_variance8x32, |
| 2052 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 2053 | |
| 2054 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 2055 | aom_highbd_10_obmc_variance16x4, |
| 2056 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 2057 | |
| 2058 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 2059 | aom_highbd_10_obmc_variance4x16, |
| 2060 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2061 | break; |
| 2062 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2063 | case AOM_BITS_12: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2064 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 2065 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 2066 | aom_highbd_12_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2067 | aom_highbd_12_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2068 | aom_highbd_sad64x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2069 | aom_highbd_dist_wtd_sad64x16_avg_bits12, |
| 2070 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2071 | |
| 2072 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 2073 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 2074 | aom_highbd_12_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2075 | aom_highbd_12_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2076 | aom_highbd_sad16x64x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2077 | aom_highbd_dist_wtd_sad16x64_avg_bits12, |
| 2078 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2079 | |
| 2080 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 2081 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 2082 | aom_highbd_12_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2083 | aom_highbd_12_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2084 | aom_highbd_sad32x8x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2085 | aom_highbd_dist_wtd_sad32x8_avg_bits12, |
| 2086 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2087 | |
| 2088 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 2089 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 2090 | aom_highbd_12_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2091 | aom_highbd_12_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2092 | aom_highbd_sad8x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2093 | aom_highbd_dist_wtd_sad8x32_avg_bits12, |
| 2094 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2095 | |
| 2096 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 2097 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 2098 | aom_highbd_12_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2099 | aom_highbd_12_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2100 | aom_highbd_sad16x4x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2101 | aom_highbd_dist_wtd_sad16x4_avg_bits12, |
| 2102 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2103 | |
| 2104 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 2105 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 2106 | aom_highbd_12_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2107 | aom_highbd_12_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2108 | aom_highbd_sad4x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2109 | aom_highbd_dist_wtd_sad4x16_avg_bits12, |
| 2110 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2111 | |
| 2112 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 2113 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 2114 | aom_highbd_12_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2115 | aom_highbd_12_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2116 | aom_highbd_sad32x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2117 | aom_highbd_dist_wtd_sad32x16_avg_bits12, |
| 2118 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2119 | |
| 2120 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 2121 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 2122 | aom_highbd_12_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2123 | aom_highbd_12_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2124 | aom_highbd_sad16x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2125 | aom_highbd_dist_wtd_sad16x32_avg_bits12, |
| 2126 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2127 | |
| 2128 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 2129 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 2130 | aom_highbd_12_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2131 | aom_highbd_12_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2132 | aom_highbd_sad64x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2133 | aom_highbd_dist_wtd_sad64x32_avg_bits12, |
| 2134 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2135 | |
| 2136 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 2137 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 2138 | aom_highbd_12_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2139 | aom_highbd_12_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2140 | aom_highbd_sad32x64x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2141 | aom_highbd_dist_wtd_sad32x64_avg_bits12, |
| 2142 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2143 | |
| 2144 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 2145 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 2146 | aom_highbd_12_sub_pixel_variance32x32, |
| 2147 | aom_highbd_12_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2148 | aom_highbd_sad32x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2149 | aom_highbd_dist_wtd_sad32x32_avg_bits12, |
| 2150 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2151 | |
| 2152 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2153 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2154 | aom_highbd_12_sub_pixel_variance64x64, |
| 2155 | aom_highbd_12_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2156 | aom_highbd_sad64x64x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2157 | aom_highbd_dist_wtd_sad64x64_avg_bits12, |
| 2158 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2159 | |
| 2160 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2161 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2162 | aom_highbd_12_sub_pixel_variance16x16, |
| 2163 | aom_highbd_12_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2164 | aom_highbd_sad16x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2165 | aom_highbd_dist_wtd_sad16x16_avg_bits12, |
| 2166 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2167 | |
| 2168 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2169 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2170 | aom_highbd_12_sub_pixel_variance16x8, |
| 2171 | aom_highbd_12_sub_pixel_avg_variance16x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2172 | aom_highbd_sad16x8x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2173 | aom_highbd_dist_wtd_sad16x8_avg_bits12, |
| 2174 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2175 | |
| 2176 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2177 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2178 | aom_highbd_12_sub_pixel_variance8x16, |
| 2179 | aom_highbd_12_sub_pixel_avg_variance8x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2180 | aom_highbd_sad8x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2181 | aom_highbd_dist_wtd_sad8x16_avg_bits12, |
| 2182 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2183 | |
| 2184 | HIGHBD_BFP( |
| 2185 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2186 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2187 | aom_highbd_12_sub_pixel_avg_variance8x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2188 | aom_highbd_sad8x8x4d_bits12, aom_highbd_dist_wtd_sad8x8_avg_bits12, |
| 2189 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2190 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2191 | HIGHBD_BFP( |
| 2192 | BLOCK_8X4, aom_highbd_sad8x4_bits12, aom_highbd_sad8x4_avg_bits12, |
| 2193 | aom_highbd_12_variance8x4, aom_highbd_12_sub_pixel_variance8x4, |
| 2194 | aom_highbd_12_sub_pixel_avg_variance8x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2195 | aom_highbd_sad8x4x4d_bits12, aom_highbd_dist_wtd_sad8x4_avg_bits12, |
| 2196 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2197 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2198 | HIGHBD_BFP( |
| 2199 | BLOCK_4X8, aom_highbd_sad4x8_bits12, aom_highbd_sad4x8_avg_bits12, |
| 2200 | aom_highbd_12_variance4x8, aom_highbd_12_sub_pixel_variance4x8, |
| 2201 | aom_highbd_12_sub_pixel_avg_variance4x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2202 | aom_highbd_sad4x8x4d_bits12, aom_highbd_dist_wtd_sad4x8_avg_bits12, |
| 2203 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance4x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2204 | |
| 2205 | HIGHBD_BFP( |
| 2206 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2207 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2208 | aom_highbd_12_sub_pixel_avg_variance4x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2209 | aom_highbd_sad4x4x4d_bits12, aom_highbd_dist_wtd_sad4x4_avg_bits12, |
| 2210 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance4x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2211 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2212 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2213 | aom_highbd_sad128x128_avg_bits12, |
| 2214 | aom_highbd_12_variance128x128, |
| 2215 | aom_highbd_12_sub_pixel_variance128x128, |
| 2216 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2217 | aom_highbd_sad128x128x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2218 | aom_highbd_dist_wtd_sad128x128_avg_bits12, |
| 2219 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance128x128); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2220 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2221 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2222 | aom_highbd_sad128x64_avg_bits12, |
| 2223 | aom_highbd_12_variance128x64, |
| 2224 | aom_highbd_12_sub_pixel_variance128x64, |
| 2225 | aom_highbd_12_sub_pixel_avg_variance128x64, |
| 2226 | aom_highbd_sad128x64x4d_bits12, |
| 2227 | aom_highbd_dist_wtd_sad128x64_avg_bits12, |
| 2228 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance128x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2229 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2230 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2231 | aom_highbd_sad64x128_avg_bits12, |
| 2232 | aom_highbd_12_variance64x128, |
| 2233 | aom_highbd_12_sub_pixel_variance64x128, |
| 2234 | aom_highbd_12_sub_pixel_avg_variance64x128, |
| 2235 | aom_highbd_sad64x128x4d_bits12, |
| 2236 | aom_highbd_dist_wtd_sad64x128_avg_bits12, |
| 2237 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2238 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2239 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2240 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2241 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2242 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2243 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2244 | aom_highbd_12_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2245 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2246 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2247 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2248 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2249 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2250 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2251 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2252 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2253 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2254 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2255 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2256 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2257 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2258 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2259 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2260 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2261 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2262 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2263 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2264 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2265 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2266 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2267 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2268 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2269 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2270 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2271 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2272 | aom_highbd_12_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2273 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2274 | aom_highbd_12_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2275 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2276 | aom_highbd_12_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2277 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2278 | aom_highbd_12_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2279 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2280 | aom_highbd_12_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2281 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2282 | aom_highbd_12_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2283 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2284 | aom_highbd_12_obmc_variance128x128, |
| 2285 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2286 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2287 | aom_highbd_12_obmc_variance128x64, |
| 2288 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 2289 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 2290 | aom_highbd_12_obmc_variance64x128, |
| 2291 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2292 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 2293 | aom_highbd_12_obmc_variance64x64, |
| 2294 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 2295 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 2296 | aom_highbd_12_obmc_variance64x32, |
| 2297 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 2298 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 2299 | aom_highbd_12_obmc_variance32x64, |
| 2300 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 2301 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 2302 | aom_highbd_12_obmc_variance32x32, |
| 2303 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 2304 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 2305 | aom_highbd_12_obmc_variance32x16, |
| 2306 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 2307 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 2308 | aom_highbd_12_obmc_variance16x32, |
| 2309 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 2310 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 2311 | aom_highbd_12_obmc_variance16x16, |
| 2312 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 2313 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 2314 | aom_highbd_12_obmc_variance8x16, |
| 2315 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 2316 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 2317 | aom_highbd_12_obmc_variance16x8, |
| 2318 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 2319 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 2320 | aom_highbd_12_obmc_variance8x8, |
| 2321 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 2322 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 2323 | aom_highbd_12_obmc_variance4x8, |
| 2324 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 2325 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 2326 | aom_highbd_12_obmc_variance8x4, |
| 2327 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 2328 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 2329 | aom_highbd_12_obmc_variance4x4, |
| 2330 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2331 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 2332 | aom_highbd_12_obmc_variance64x16, |
| 2333 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2334 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 2335 | aom_highbd_12_obmc_variance16x64, |
| 2336 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2337 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 2338 | aom_highbd_12_obmc_variance32x8, |
| 2339 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2340 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 2341 | aom_highbd_12_obmc_variance8x32, |
| 2342 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2343 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 2344 | aom_highbd_12_obmc_variance16x4, |
| 2345 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2346 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 2347 | aom_highbd_12_obmc_variance4x16, |
| 2348 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2349 | break; |
| 2350 | |
| 2351 | default: |
| 2352 | assert(0 && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2353 | "cm->seq_params.bit_depth should be AOM_BITS_8, " |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2354 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2355 | } |
| 2356 | } |
| 2357 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2358 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2359 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 2360 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2361 | |
| 2362 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2363 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2364 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2365 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2366 | |
| 2367 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2368 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2369 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2370 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2371 | |
| 2372 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2373 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2374 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2375 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2378 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 2379 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2380 | SequenceHeader *const seq_params = &cm->seq_params; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2381 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2382 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2383 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2384 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2385 | if (seq_params->profile != oxcf->profile) seq_params->profile = oxcf->profile; |
| 2386 | seq_params->bit_depth = oxcf->bit_depth; |
| 2387 | seq_params->color_primaries = oxcf->color_primaries; |
| 2388 | seq_params->transfer_characteristics = oxcf->transfer_characteristics; |
| 2389 | seq_params->matrix_coefficients = oxcf->matrix_coefficients; |
| 2390 | seq_params->monochrome = oxcf->monochrome; |
| 2391 | seq_params->chroma_sample_position = oxcf->chroma_sample_position; |
| 2392 | seq_params->color_range = oxcf->color_range; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2393 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2394 | assert(IMPLIES(seq_params->profile <= PROFILE_1, |
| 2395 | seq_params->bit_depth <= AOM_BITS_10)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2396 | |
Hui Su | 2aa492c | 2019-03-12 15:18:18 -0700 | [diff] [blame] | 2397 | memcpy(cpi->target_seq_level_idx, oxcf->target_seq_level_idx, |
| 2398 | sizeof(cpi->target_seq_level_idx)); |
| 2399 | cpi->keep_level_stats = 0; |
| 2400 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
| 2401 | if (cpi->target_seq_level_idx[i] < SEQ_LEVELS) { |
| 2402 | cpi->keep_level_stats = 1; |
| 2403 | break; |
| 2404 | } |
| 2405 | } |
kyslov | abeeb7c | 2019-03-06 18:35:04 -0800 | [diff] [blame] | 2406 | |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2407 | cm->timing_info_present = oxcf->timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2408 | cm->timing_info.num_units_in_display_tick = |
| 2409 | oxcf->timing_info.num_units_in_display_tick; |
| 2410 | cm->timing_info.time_scale = oxcf->timing_info.time_scale; |
| 2411 | cm->timing_info.equal_picture_interval = |
| 2412 | oxcf->timing_info.equal_picture_interval; |
| 2413 | cm->timing_info.num_ticks_per_picture = |
| 2414 | oxcf->timing_info.num_ticks_per_picture; |
| 2415 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2416 | seq_params->display_model_info_present_flag = |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2417 | oxcf->display_model_info_present_flag; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2418 | seq_params->decoder_model_info_present_flag = |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 2419 | oxcf->decoder_model_info_present_flag; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2420 | if (oxcf->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2421 | // set the decoder model parameters in schedule mode |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2422 | cm->buffer_model.num_units_in_decoding_tick = |
| 2423 | oxcf->buffer_model.num_units_in_decoding_tick; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 2424 | cm->buffer_removal_time_present = 1; |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 2425 | av1_set_aom_dec_model_info(&cm->buffer_model); |
| 2426 | av1_set_dec_model_op_parameters(&cm->op_params[0]); |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2427 | } else if (cm->timing_info_present && |
| 2428 | cm->timing_info.equal_picture_interval && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2429 | !seq_params->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2430 | // set the decoder model parameters in resource availability mode |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 2431 | av1_set_resource_availability_parameters(&cm->op_params[0]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 2432 | } else { |
| 2433 | cm->op_params[0].initial_display_delay = |
| 2434 | 10; // Default value (not signaled) |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2435 | } |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2436 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2437 | update_film_grain_parameters(cpi, oxcf); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2438 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2439 | cpi->oxcf = *oxcf; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 2440 | cpi->common.options = oxcf->cfg; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2441 | x->e_mbd.bd = (int)seq_params->bit_depth; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2442 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2443 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2444 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2445 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 2446 | } else { |
| 2447 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 2448 | } |
| 2449 | |
| 2450 | cpi->refresh_last_frame = 1; |
| 2451 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2452 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 2453 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2454 | |
Debargha Mukherjee | 229fdc8 | 2018-03-10 07:45:33 -0800 | [diff] [blame] | 2455 | cm->refresh_frame_context = (oxcf->frame_parallel_decoding_mode) |
| 2456 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 2457 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2458 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 2459 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2460 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 2461 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2462 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 2463 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 2464 | } |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2465 | |
| 2466 | if (x->tmp_conv_dst == NULL) { |
| 2467 | CHECK_MEM_ERROR( |
| 2468 | cm, x->tmp_conv_dst, |
| 2469 | aom_memalign(32, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(*x->tmp_conv_dst))); |
Urvang Joshi | e58f6ec | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 2470 | x->e_mbd.tmp_conv_dst = x->tmp_conv_dst; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2471 | } |
| 2472 | for (int i = 0; i < 2; ++i) { |
| 2473 | if (x->tmp_obmc_bufs[i] == NULL) { |
| 2474 | CHECK_MEM_ERROR(cm, x->tmp_obmc_bufs[i], |
wenyao.liu | 22d8ab3 | 2018-10-16 09:11:29 +0800 | [diff] [blame] | 2475 | aom_memalign(32, 2 * MAX_MB_PLANE * MAX_SB_SQUARE * |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2476 | sizeof(*x->tmp_obmc_bufs[i]))); |
Urvang Joshi | e58f6ec | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 2477 | x->e_mbd.tmp_obmc_bufs[i] = x->tmp_obmc_bufs[i]; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2481 | av1_reset_segment_features(cm); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2482 | set_high_precision_mv(cpi, 1, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2483 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2484 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 2485 | |
| 2486 | // Under a configuration change, where maximum_buffer_size may change, |
| 2487 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2488 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2489 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2490 | |
| 2491 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2492 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2493 | |
| 2494 | // Set absolute upper and lower quality limits |
| 2495 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2496 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2497 | |
Urvang Joshi | b55cb5e | 2018-09-12 14:50:21 -0700 | [diff] [blame] | 2498 | cm->interp_filter = oxcf->large_scale_tile ? EIGHTTAP_REGULAR : SWITCHABLE; |
Yue Chen | 5380cb5 | 2018-02-23 15:33:21 -0800 | [diff] [blame] | 2499 | cm->switchable_motion_mode = 1; |
| 2500 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2501 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2502 | cm->render_width = cpi->oxcf.render_width; |
| 2503 | cm->render_height = cpi->oxcf.render_height; |
| 2504 | } else { |
| 2505 | cm->render_width = cpi->oxcf.width; |
| 2506 | cm->render_height = cpi->oxcf.height; |
| 2507 | } |
| 2508 | cm->width = cpi->oxcf.width; |
| 2509 | cm->height = cpi->oxcf.height; |
| 2510 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2511 | int sb_size = seq_params->sb_size; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 2512 | // Superblock size should not be updated after the first key frame. |
| 2513 | if (!cpi->seq_params_locked) { |
| 2514 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Hui Su | d909c2c | 2019-03-08 11:51:14 -0800 | [diff] [blame] | 2515 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) |
| 2516 | seq_params->tier[i] = (oxcf->tier_mask >> i) & 1; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 2517 | } |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2518 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2519 | if (cpi->initial_width || sb_size != seq_params->sb_size) { |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2520 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height || |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2521 | seq_params->sb_size != sb_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2522 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2523 | av1_free_pc_tree(&cpi->td, num_planes); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2524 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2525 | realloc_segmentation_maps(cpi); |
| 2526 | cpi->initial_width = cpi->initial_height = 0; |
| 2527 | } |
| 2528 | } |
| 2529 | update_frame_size(cpi); |
| 2530 | |
| 2531 | cpi->alt_ref_source = NULL; |
| 2532 | rc->is_src_frame_alt_ref = 0; |
| 2533 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2534 | set_tile_info(cpi); |
| 2535 | |
| 2536 | cpi->ext_refresh_frame_flags_pending = 0; |
| 2537 | cpi->ext_refresh_frame_context_pending = 0; |
| 2538 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2539 | highbd_set_var_fns(cpi); |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 2540 | |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 2541 | // Init sequence level coding tools |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2542 | // This should not be called after the first key frame. |
| 2543 | if (!cpi->seq_params_locked) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2544 | seq_params->operating_points_cnt_minus_1 = |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 2545 | cm->number_spatial_layers > 1 ? cm->number_spatial_layers - 1 : 0; |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2546 | init_seq_coding_tools(&cm->seq_params, cm, oxcf); |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2547 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2550 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 2551 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2552 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2553 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2554 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2555 | |
| 2556 | if (!cm) return NULL; |
| 2557 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2558 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2559 | |
Wan-Teh Chang | a2fad3e | 2018-07-19 16:55:19 -0700 | [diff] [blame] | 2560 | // The jmp_buf is valid only for the duration of the function that calls |
| 2561 | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
| 2562 | // before it returns. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2563 | if (setjmp(cm->error.jmp)) { |
| 2564 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2565 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2566 | return 0; |
| 2567 | } |
| 2568 | |
| 2569 | cm->error.setjmp = 1; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2570 | cm->alloc_mi = enc_alloc_mi; |
| 2571 | cm->free_mi = enc_free_mi; |
| 2572 | cm->setup_mi = enc_setup_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2573 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2574 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2575 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 2576 | CHECK_MEM_ERROR( |
| 2577 | cm, cm->default_frame_context, |
| 2578 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->default_frame_context))); |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2579 | memset(cm->fc, 0, sizeof(*cm->fc)); |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 2580 | memset(cm->default_frame_context, 0, sizeof(*cm->default_frame_context)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2581 | |
| 2582 | cpi->resize_state = 0; |
| 2583 | cpi->resize_avg_qp = 0; |
| 2584 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2585 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2586 | cpi->common.buffer_pool = pool; |
| 2587 | |
| 2588 | init_config(cpi, oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2589 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2590 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 2591 | cm->current_frame.frame_number = 0; |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 2592 | cm->current_frame_id = -1; |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2593 | cpi->seq_params_locked = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2594 | cpi->partition_search_skippable_frame = 0; |
| 2595 | cpi->tile_data = NULL; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 2596 | cpi->last_show_frame_buf = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2597 | realloc_segmentation_maps(cpi); |
| 2598 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 2599 | memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs)); |
| 2600 | memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp)); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2601 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2602 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 2603 | i++) { |
| 2604 | CHECK_MEM_ERROR( |
| 2605 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2606 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2607 | } |
| 2608 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2609 | cpi->refresh_alt_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2610 | |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 2611 | av1_init_level_info(cpi->level_info); |
chiyotsai | d16a257 | 2019-03-05 17:48:10 -0800 | [diff] [blame] | 2612 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2613 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 2614 | #if CONFIG_INTERNAL_STATS |
| 2615 | cpi->b_calculate_blockiness = 1; |
| 2616 | cpi->b_calculate_consistency = 1; |
| 2617 | cpi->total_inconsistency = 0; |
| 2618 | cpi->psnr.worst = 100.0; |
| 2619 | cpi->worst_ssim = 100.0; |
| 2620 | |
| 2621 | cpi->count = 0; |
| 2622 | cpi->bytes = 0; |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 2623 | #if CONFIG_SPEED_STATS |
| 2624 | cpi->tx_search_count = 0; |
| 2625 | #endif // CONFIG_SPEED_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2626 | |
| 2627 | if (cpi->b_calculate_psnr) { |
| 2628 | cpi->total_sq_error = 0; |
| 2629 | cpi->total_samples = 0; |
| 2630 | cpi->tot_recode_hits = 0; |
| 2631 | cpi->summed_quality = 0; |
| 2632 | cpi->summed_weights = 0; |
| 2633 | } |
| 2634 | |
| 2635 | cpi->fastssim.worst = 100.0; |
| 2636 | cpi->psnrhvs.worst = 100.0; |
| 2637 | |
| 2638 | if (cpi->b_calculate_blockiness) { |
| 2639 | cpi->total_blockiness = 0; |
| 2640 | cpi->worst_blockiness = 0.0; |
| 2641 | } |
| 2642 | |
| 2643 | if (cpi->b_calculate_consistency) { |
| 2644 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2645 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2646 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 2647 | cpi->worst_consistency = 100.0; |
| 2648 | } |
| 2649 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2650 | #if CONFIG_ENTROPY_STATS |
| 2651 | av1_zero(aggregate_fc); |
| 2652 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2653 | |
| 2654 | cpi->first_time_stamp_ever = INT64_MAX; |
| 2655 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 2656 | cpi->td.mb.nmvcost[0] = &cpi->nmv_costs[0][MV_MAX]; |
| 2657 | cpi->td.mb.nmvcost[1] = &cpi->nmv_costs[1][MV_MAX]; |
| 2658 | cpi->td.mb.nmvcost_hp[0] = &cpi->nmv_costs_hp[0][MV_MAX]; |
| 2659 | cpi->td.mb.nmvcost_hp[1] = &cpi->nmv_costs_hp[1][MV_MAX]; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2660 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2661 | #ifdef OUTPUT_YUV_SKINMAP |
| 2662 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 2663 | #endif |
| 2664 | #ifdef OUTPUT_YUV_REC |
| 2665 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 2666 | #endif |
| 2667 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2668 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2669 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2670 | } else if (oxcf->pass == 2) { |
| 2671 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 2672 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 2673 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2674 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 2675 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 2676 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 2677 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2678 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2681 | CHECK_MEM_ERROR( |
| 2682 | cm, cpi->td.mb.above_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 2683 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 2684 | sizeof(*cpi->td.mb.above_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2685 | CHECK_MEM_ERROR( |
| 2686 | cm, cpi->td.mb.left_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 2687 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 2688 | sizeof(*cpi->td.mb.left_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2689 | |
| 2690 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 2691 | (int32_t *)aom_memalign( |
| 2692 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 2693 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 2694 | CHECK_MEM_ERROR( |
| 2695 | cm, cpi->td.mb.inter_modes_info, |
| 2696 | (InterModesInfo *)aom_malloc(sizeof(*cpi->td.mb.inter_modes_info))); |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 2697 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 2698 | for (int x = 0; x < 2; x++) |
| 2699 | for (int y = 0; y < 2; y++) |
| 2700 | CHECK_MEM_ERROR( |
| 2701 | cm, cpi->td.mb.hash_value_buffer[x][y], |
| 2702 | (uint32_t *)aom_malloc(AOM_BUFFER_SIZE_FOR_BLOCK_HASH * |
| 2703 | sizeof(*cpi->td.mb.hash_value_buffer[0][0]))); |
| 2704 | |
| 2705 | cpi->td.mb.g_crc_initialized = 0; |
| 2706 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2707 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 2708 | (int32_t *)aom_memalign( |
| 2709 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 2710 | |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 2711 | av1_set_speed_features_framesize_independent(cpi, oxcf->speed); |
| 2712 | av1_set_speed_features_framesize_dependent(cpi, oxcf->speed); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2713 | |
Yue Chen | c9b23e0 | 2019-04-10 16:54:03 -0700 | [diff] [blame] | 2714 | for (int frame = 0; frame < MAX_LENGTH_TPL_FRAME_STATS; ++frame) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 2715 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); |
| 2716 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); |
| 2717 | |
| 2718 | CHECK_MEM_ERROR(cm, cpi->tpl_stats[frame].tpl_stats_ptr, |
| 2719 | aom_calloc(mi_rows * mi_cols, |
| 2720 | sizeof(*cpi->tpl_stats[frame].tpl_stats_ptr))); |
| 2721 | cpi->tpl_stats[frame].is_valid = 0; |
| 2722 | cpi->tpl_stats[frame].width = mi_cols; |
| 2723 | cpi->tpl_stats[frame].height = mi_rows; |
| 2724 | cpi->tpl_stats[frame].stride = mi_cols; |
| 2725 | cpi->tpl_stats[frame].mi_rows = cm->mi_rows; |
| 2726 | cpi->tpl_stats[frame].mi_cols = cm->mi_cols; |
| 2727 | } |
| 2728 | |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 2729 | #if CONFIG_COLLECT_PARTITION_STATS == 2 |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 2730 | av1_zero(cpi->partition_stats); |
| 2731 | #endif |
| 2732 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2733 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \ |
| 2734 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 2735 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 2736 | cpi->fn_ptr[BT].vf = VF; \ |
| 2737 | cpi->fn_ptr[BT].svf = SVF; \ |
| 2738 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 2739 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 2740 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2741 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2742 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2743 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2744 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2745 | aom_sad4x16x4d, aom_dist_wtd_sad4x16_avg, |
| 2746 | aom_dist_wtd_sub_pixel_avg_variance4x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2747 | |
| 2748 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2749 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2750 | aom_sad16x4x4d, aom_dist_wtd_sad16x4_avg, |
| 2751 | aom_dist_wtd_sub_pixel_avg_variance16x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2752 | |
| 2753 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2754 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2755 | aom_sad8x32x4d, aom_dist_wtd_sad8x32_avg, |
| 2756 | aom_dist_wtd_sub_pixel_avg_variance8x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2757 | |
| 2758 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2759 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2760 | aom_sad32x8x4d, aom_dist_wtd_sad32x8_avg, |
| 2761 | aom_dist_wtd_sub_pixel_avg_variance32x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2762 | |
| 2763 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2764 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2765 | aom_sad16x64x4d, aom_dist_wtd_sad16x64_avg, |
| 2766 | aom_dist_wtd_sub_pixel_avg_variance16x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2767 | |
| 2768 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2769 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2770 | aom_sad64x16x4d, aom_dist_wtd_sad64x16_avg, |
| 2771 | aom_dist_wtd_sub_pixel_avg_variance64x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2772 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2773 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 2774 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2775 | aom_sad128x128x4d, aom_dist_wtd_sad128x128_avg, |
| 2776 | aom_dist_wtd_sub_pixel_avg_variance128x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2777 | |
| 2778 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2779 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2780 | aom_sad128x64x4d, aom_dist_wtd_sad128x64_avg, |
| 2781 | aom_dist_wtd_sub_pixel_avg_variance128x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2782 | |
| 2783 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2784 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2785 | aom_sad64x128x4d, aom_dist_wtd_sad64x128_avg, |
| 2786 | aom_dist_wtd_sub_pixel_avg_variance64x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2787 | |
| 2788 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2789 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2790 | aom_sad32x16x4d, aom_dist_wtd_sad32x16_avg, |
| 2791 | aom_dist_wtd_sub_pixel_avg_variance32x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2792 | |
| 2793 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2794 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2795 | aom_sad16x32x4d, aom_dist_wtd_sad16x32_avg, |
| 2796 | aom_dist_wtd_sub_pixel_avg_variance16x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2797 | |
| 2798 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2799 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2800 | aom_sad64x32x4d, aom_dist_wtd_sad64x32_avg, |
| 2801 | aom_dist_wtd_sub_pixel_avg_variance64x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2802 | |
| 2803 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2804 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2805 | aom_sad32x64x4d, aom_dist_wtd_sad32x64_avg, |
| 2806 | aom_dist_wtd_sub_pixel_avg_variance32x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2807 | |
| 2808 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 2809 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2810 | aom_sad32x32x4d, aom_dist_wtd_sad32x32_avg, |
| 2811 | aom_dist_wtd_sub_pixel_avg_variance32x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2812 | |
| 2813 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 2814 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2815 | aom_sad64x64x4d, aom_dist_wtd_sad64x64_avg, |
| 2816 | aom_dist_wtd_sub_pixel_avg_variance64x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2817 | |
| 2818 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 2819 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2820 | aom_sad16x16x4d, aom_dist_wtd_sad16x16_avg, |
| 2821 | aom_dist_wtd_sub_pixel_avg_variance16x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2822 | |
| 2823 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2824 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2825 | aom_sad16x8x4d, aom_dist_wtd_sad16x8_avg, |
| 2826 | aom_dist_wtd_sub_pixel_avg_variance16x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2827 | |
| 2828 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2829 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2830 | aom_sad8x16x4d, aom_dist_wtd_sad8x16_avg, |
| 2831 | aom_dist_wtd_sub_pixel_avg_variance8x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2832 | |
| 2833 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2834 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2835 | aom_dist_wtd_sad8x8_avg, aom_dist_wtd_sub_pixel_avg_variance8x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2836 | |
| 2837 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2838 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, aom_sad8x4x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2839 | aom_dist_wtd_sad8x4_avg, aom_dist_wtd_sub_pixel_avg_variance8x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2840 | |
| 2841 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2842 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, aom_sad4x8x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2843 | aom_dist_wtd_sad4x8_avg, aom_dist_wtd_sub_pixel_avg_variance4x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2844 | |
| 2845 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2846 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2847 | aom_dist_wtd_sad4x4_avg, aom_dist_wtd_sub_pixel_avg_variance4x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2848 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2849 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 2850 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 2851 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 2852 | cpi->fn_ptr[BT].osvf = OSVF; |
| 2853 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2854 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 2855 | aom_obmc_sub_pixel_variance128x128) |
| 2856 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 2857 | aom_obmc_sub_pixel_variance128x64) |
| 2858 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 2859 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2860 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 2861 | aom_obmc_sub_pixel_variance64x64) |
| 2862 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 2863 | aom_obmc_sub_pixel_variance64x32) |
| 2864 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 2865 | aom_obmc_sub_pixel_variance32x64) |
| 2866 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 2867 | aom_obmc_sub_pixel_variance32x32) |
| 2868 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 2869 | aom_obmc_sub_pixel_variance32x16) |
| 2870 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 2871 | aom_obmc_sub_pixel_variance16x32) |
| 2872 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 2873 | aom_obmc_sub_pixel_variance16x16) |
| 2874 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 2875 | aom_obmc_sub_pixel_variance16x8) |
| 2876 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 2877 | aom_obmc_sub_pixel_variance8x16) |
| 2878 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 2879 | aom_obmc_sub_pixel_variance8x8) |
| 2880 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 2881 | aom_obmc_sub_pixel_variance4x8) |
| 2882 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 2883 | aom_obmc_sub_pixel_variance8x4) |
| 2884 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 2885 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2886 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 2887 | aom_obmc_sub_pixel_variance4x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2888 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 2889 | aom_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2890 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 2891 | aom_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2892 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 2893 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2894 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 2895 | aom_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2896 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 2897 | aom_obmc_sub_pixel_variance64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2898 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2899 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 2900 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 2901 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2902 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2903 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 2904 | aom_masked_sub_pixel_variance128x128) |
| 2905 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 2906 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2907 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 2908 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 2909 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 2910 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 2911 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 2912 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 2913 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 2914 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 2915 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 2916 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 2917 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 2918 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 2919 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2920 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2921 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 2922 | |
| 2923 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 2924 | |
| 2925 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 2926 | |
| 2927 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2928 | |
| 2929 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 2930 | |
| 2931 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2932 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2933 | highbd_set_var_fns(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2934 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2935 | /* av1_init_quantizer() is first called here. Add check in |
| 2936 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2937 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2938 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2939 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2940 | av1_init_quantizer(cpi); |
Zoe Liu | d902b74 | 2018-02-19 17:02:41 -0800 | [diff] [blame] | 2941 | av1_qm_init(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2942 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2943 | av1_loop_filter_init(cm); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 2944 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 2945 | cm->superres_upscaled_width = oxcf->width; |
| 2946 | cm->superres_upscaled_height = oxcf->height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2947 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2948 | |
| 2949 | cm->error.setjmp = 0; |
| 2950 | |
| 2951 | return cpi; |
| 2952 | } |
| 2953 | |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 2954 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2955 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 2956 | |
| 2957 | #define SNPRINT2(H, T, V) \ |
| 2958 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 2959 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2960 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2961 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 2962 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2963 | unsigned int i; |
| 2964 | int t; |
| 2965 | |
| 2966 | if (!cpi) return; |
| 2967 | |
| 2968 | cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2969 | const int num_planes = av1_num_planes(cm); |
| 2970 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 2971 | if (cm->current_frame.frame_number > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2972 | #if CONFIG_ENTROPY_STATS |
| 2973 | if (cpi->oxcf.pass != 1) { |
| 2974 | fprintf(stderr, "Writing counts.stt\n"); |
| 2975 | FILE *f = fopen("counts.stt", "wb"); |
| 2976 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
| 2977 | fclose(f); |
| 2978 | } |
| 2979 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2980 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2981 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2982 | |
| 2983 | if (cpi->oxcf.pass != 1) { |
| 2984 | char headings[512] = { 0 }; |
| 2985 | char results[512] = { 0 }; |
| 2986 | FILE *f = fopen("opsnr.stt", "a"); |
| 2987 | double time_encoded = |
| 2988 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 2989 | 10000000.000; |
| 2990 | double total_encode_time = |
| 2991 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 2992 | const double dr = |
| 2993 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 2994 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 2995 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 2996 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 2997 | |
| 2998 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2999 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3000 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 3001 | const double total_ssim = |
| 3002 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 3003 | snprintf(headings, sizeof(headings), |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3004 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3005 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3006 | "WstPsnr\tWstSsim\tWstFast\tWstHVS\t" |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3007 | "AVPsrnY\tAPsnrCb\tAPsnrCr"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3008 | snprintf(results, sizeof(results), |
| 3009 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 3010 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3011 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3012 | "%7.3f\t%7.3f\t%7.3f", |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 3013 | dr, cpi->psnr.stat[STAT_ALL] / cpi->count, total_psnr, |
| 3014 | cpi->psnr.stat[STAT_ALL] / cpi->count, total_psnr, total_ssim, |
| 3015 | total_ssim, cpi->fastssim.stat[STAT_ALL] / cpi->count, |
| 3016 | cpi->psnrhvs.stat[STAT_ALL] / cpi->count, cpi->psnr.worst, |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3017 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst, |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 3018 | cpi->psnr.stat[STAT_Y] / cpi->count, |
| 3019 | cpi->psnr.stat[STAT_U] / cpi->count, |
| 3020 | cpi->psnr.stat[STAT_V] / cpi->count); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3021 | |
| 3022 | if (cpi->b_calculate_blockiness) { |
| 3023 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 3024 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 3025 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 3026 | } |
| 3027 | |
| 3028 | if (cpi->b_calculate_consistency) { |
| 3029 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3030 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3031 | (double)cpi->total_inconsistency); |
| 3032 | |
| 3033 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 3034 | SNPRINT2(results, "\t%7.3f", consistency); |
| 3035 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 3036 | } |
Sarah Parker | f97b786 | 2016-08-25 17:42:57 -0700 | [diff] [blame] | 3037 | fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings); |
| 3038 | fprintf(f, "%s\t%8.0f\t%7.2f\t%7.2f\n", results, total_encode_time, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3039 | rate_err, fabs(rate_err)); |
| 3040 | } |
| 3041 | |
| 3042 | fclose(f); |
| 3043 | } |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 3044 | #endif // CONFIG_INTERNAL_STATS |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 3045 | #if CONFIG_SPEED_STATS |
| 3046 | if (cpi->oxcf.pass != 1) { |
| 3047 | fprintf(stdout, "tx_search_count = %d\n", cpi->tx_search_count); |
| 3048 | } |
| 3049 | #endif // CONFIG_SPEED_STATS |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 3050 | |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 3051 | #if CONFIG_COLLECT_PARTITION_STATS == 2 |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 3052 | if (cpi->oxcf.pass != 1) { |
| 3053 | av1_print_partition_stats(&cpi->partition_stats); |
| 3054 | } |
| 3055 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
Yue Chen | c9b23e0 | 2019-04-10 16:54:03 -0700 | [diff] [blame] | 3058 | for (int frame = 0; frame < MAX_LENGTH_TPL_FRAME_STATS; ++frame) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 3059 | aom_free(cpi->tpl_stats[frame].tpl_stats_ptr); |
| 3060 | cpi->tpl_stats[frame].is_valid = 0; |
| 3061 | } |
| 3062 | |
Ravi Chaudhary | 1f58dd8 | 2018-12-07 17:24:15 +0530 | [diff] [blame] | 3063 | for (t = cpi->num_workers - 1; t >= 0; --t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3064 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3065 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 3066 | |
| 3067 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3068 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3069 | |
| 3070 | // Deallocate allocated thread data. |
Ravi Chaudhary | 1cf7d16 | 2018-10-09 17:00:43 +0530 | [diff] [blame] | 3071 | if (cpi->row_mt == 1) aom_free(thread_data->td->tctx); |
Ravi Chaudhary | 1f58dd8 | 2018-12-07 17:24:15 +0530 | [diff] [blame] | 3072 | if (t > 0) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3073 | aom_free(thread_data->td->palette_buffer); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3074 | aom_free(thread_data->td->tmp_conv_dst); |
| 3075 | for (int j = 0; j < 2; ++j) { |
| 3076 | aom_free(thread_data->td->tmp_obmc_bufs[j]); |
| 3077 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3078 | aom_free(thread_data->td->above_pred_buf); |
| 3079 | aom_free(thread_data->td->left_pred_buf); |
| 3080 | aom_free(thread_data->td->wsrc_buf); |
wenyao.liu | 22d8ab3 | 2018-10-16 09:11:29 +0800 | [diff] [blame] | 3081 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 3082 | aom_free(thread_data->td->inter_modes_info); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3083 | for (int x = 0; x < 2; x++) { |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3084 | for (int y = 0; y < 2; y++) { |
| 3085 | aom_free(thread_data->td->hash_value_buffer[x][y]); |
| 3086 | thread_data->td->hash_value_buffer[x][y] = NULL; |
| 3087 | } |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3088 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3089 | aom_free(thread_data->td->mask_buf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3090 | aom_free(thread_data->td->counts); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3091 | av1_free_pc_tree(thread_data->td, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3092 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3093 | } |
| 3094 | } |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 3095 | #if CONFIG_MULTITHREAD |
| 3096 | if (cpi->row_mt == 1) { |
| 3097 | if (cpi->row_mt_mutex_ != NULL) { |
| 3098 | pthread_mutex_destroy(cpi->row_mt_mutex_); |
| 3099 | aom_free(cpi->row_mt_mutex_); |
| 3100 | } |
| 3101 | } |
| 3102 | #endif |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 3103 | av1_row_mt_mem_dealloc(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3104 | aom_free(cpi->tile_thr_data); |
| 3105 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3106 | |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 3107 | if (cpi->num_workers > 1) { |
| 3108 | av1_loop_filter_dealloc(&cpi->lf_row_sync); |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 3109 | av1_loop_restoration_dealloc(&cpi->lr_row_sync, cpi->num_workers); |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 3110 | } |
| 3111 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3112 | dealloc_compressor_data(cpi); |
| 3113 | |
| 3114 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 3115 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3116 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3117 | } |
| 3118 | |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 3119 | #if CONFIG_INTERNAL_STATS |
| 3120 | aom_free(cpi->ssim_vars); |
| 3121 | cpi->ssim_vars = NULL; |
| 3122 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3123 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3124 | av1_remove_common(cm); |
RogerZhou | 80d5234 | 2017-11-20 10:56:26 -0800 | [diff] [blame] | 3125 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 3126 | av1_hash_table_destroy(&cm->buffer_pool->frame_bufs[i].hash_table); |
| 3127 | } |
Yaowu Xu | 74e6335 | 2019-05-06 09:21:33 -0700 | [diff] [blame] | 3128 | #if CONFIG_HTB_TRELLIS |
Michelle Findlay-Olynyk | dea531d | 2017-12-13 14:10:56 -0800 | [diff] [blame] | 3129 | if (cpi->sf.use_hash_based_trellis) hbt_destroy(); |
Yaowu Xu | 74e6335 | 2019-05-06 09:21:33 -0700 | [diff] [blame] | 3130 | #endif // CONFIG_HTB_TRELLIS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3131 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 3132 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3133 | |
| 3134 | #ifdef OUTPUT_YUV_SKINMAP |
| 3135 | fclose(yuv_skinmap_file); |
| 3136 | #endif |
| 3137 | #ifdef OUTPUT_YUV_REC |
| 3138 | fclose(yuv_rec_file); |
| 3139 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3140 | } |
| 3141 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3142 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 3143 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3144 | int i; |
| 3145 | PSNR_STATS psnr; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 3146 | aom_calc_highbd_psnr(cpi->source, &cpi->common.cur_frame->buf, &psnr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3147 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3148 | |
| 3149 | for (i = 0; i < 4; ++i) { |
| 3150 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 3151 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 3152 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 3153 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3154 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 3155 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3156 | } |
| 3157 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3158 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3159 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 3160 | |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 3161 | cpi->ext_ref_frame_flags = ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3162 | return 0; |
| 3163 | } |
| 3164 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3165 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3166 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3167 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3168 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3169 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3170 | aom_yv12_copy_frame(cfg, sd, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3171 | return 0; |
| 3172 | } else { |
| 3173 | return -1; |
| 3174 | } |
| 3175 | } |
| 3176 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3177 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3178 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3179 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3180 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3181 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3182 | aom_yv12_copy_frame(sd, cfg, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3183 | return 0; |
| 3184 | } else { |
| 3185 | return -1; |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3190 | cpi->ext_refresh_frame_context = update; |
| 3191 | cpi->ext_refresh_frame_context_pending = 1; |
| 3192 | return 0; |
| 3193 | } |
| 3194 | |
| 3195 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 3196 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 3197 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 3198 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 3199 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3200 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3201 | uint8_t *src = s->y_buffer; |
| 3202 | int h = s->y_height; |
| 3203 | |
| 3204 | do { |
| 3205 | fwrite(src, s->y_width, 1, f); |
| 3206 | src += s->y_stride; |
| 3207 | } while (--h); |
| 3208 | |
| 3209 | src = s->u_buffer; |
| 3210 | h = s->uv_height; |
| 3211 | |
| 3212 | do { |
| 3213 | fwrite(src, s->uv_width, 1, f); |
| 3214 | src += s->uv_stride; |
| 3215 | } while (--h); |
| 3216 | |
| 3217 | src = s->v_buffer; |
| 3218 | h = s->uv_height; |
| 3219 | |
| 3220 | do { |
| 3221 | fwrite(src, s->uv_width, 1, f); |
| 3222 | src += s->uv_stride; |
| 3223 | } while (--h); |
| 3224 | } |
| 3225 | #endif |
| 3226 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3227 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3228 | void aom_write_one_yuv_frame(AV1_COMMON *cm, YV12_BUFFER_CONFIG *s) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3229 | uint8_t *src = s->y_buffer; |
| 3230 | int h = cm->height; |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3231 | if (yuv_rec_file == NULL) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3232 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 3233 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 3234 | |
| 3235 | do { |
| 3236 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 3237 | src16 += s->y_stride; |
| 3238 | } while (--h); |
| 3239 | |
| 3240 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 3241 | h = s->uv_height; |
| 3242 | |
| 3243 | do { |
| 3244 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3245 | src16 += s->uv_stride; |
| 3246 | } while (--h); |
| 3247 | |
| 3248 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 3249 | h = s->uv_height; |
| 3250 | |
| 3251 | do { |
| 3252 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3253 | src16 += s->uv_stride; |
| 3254 | } while (--h); |
| 3255 | |
| 3256 | fflush(yuv_rec_file); |
| 3257 | return; |
| 3258 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3259 | |
| 3260 | do { |
| 3261 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 3262 | src += s->y_stride; |
| 3263 | } while (--h); |
| 3264 | |
| 3265 | src = s->u_buffer; |
| 3266 | h = s->uv_height; |
| 3267 | |
| 3268 | do { |
| 3269 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3270 | src += s->uv_stride; |
| 3271 | } while (--h); |
| 3272 | |
| 3273 | src = s->v_buffer; |
| 3274 | h = s->uv_height; |
| 3275 | |
| 3276 | do { |
| 3277 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3278 | src += s->uv_stride; |
| 3279 | } while (--h); |
| 3280 | |
| 3281 | fflush(yuv_rec_file); |
| 3282 | } |
| 3283 | #endif // OUTPUT_YUV_REC |
| 3284 | |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 3285 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3286 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 3287 | int i; |
| 3288 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3289 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3290 | AV1_COMMON *const cm = &cpi->common; |
| 3291 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3292 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3293 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3294 | cpi->gmparams_cost[i]) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3295 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3296 | assert(cm->global_motion[i].wmtype == IDENTITY); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3297 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 3298 | recode = 1; |
Urvang Joshi | 02aade8 | 2017-12-18 17:18:16 -0800 | [diff] [blame] | 3299 | // TODO(sarahparker): The earlier condition for recoding here was: |
| 3300 | // "recode |= (rdc->global_motion_used[i] > 0);". Can we bring something |
| 3301 | // similar to that back to speed up global motion? |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3302 | } |
| 3303 | } |
| 3304 | return recode; |
| 3305 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3306 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3307 | // Function to test for conditions that indicate we should loop |
| 3308 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3309 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 3310 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3311 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3312 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3313 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 3314 | int force_recode = 0; |
| 3315 | |
| 3316 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 3317 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 3318 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3319 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 3320 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 3321 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 3322 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3323 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3324 | // Deal with frame undershoot and whether or not we are |
| 3325 | // below the automatically set cq level. |
| 3326 | if (q > oxcf->cq_level && |
| 3327 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 3328 | force_recode = 1; |
| 3329 | } |
| 3330 | } |
| 3331 | } |
| 3332 | return force_recode; |
| 3333 | } |
| 3334 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3335 | static void scale_references(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3336 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3337 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3338 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3339 | const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = { |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3340 | AOM_LAST_FLAG, AOM_LAST2_FLAG, AOM_LAST3_FLAG, AOM_GOLD_FLAG, |
| 3341 | AOM_BWD_FLAG, AOM_ALT2_FLAG, AOM_ALT_FLAG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3342 | }; |
| 3343 | |
| 3344 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3345 | // Need to convert from AOM_REFFRAME to index into ref_mask (subtract 1). |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3346 | if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 3347 | BufferPool *const pool = cm->buffer_pool; |
| 3348 | const YV12_BUFFER_CONFIG *const ref = |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3349 | get_ref_frame_yv12_buf(cm, ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3350 | |
| 3351 | if (ref == NULL) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3352 | cpi->scaled_ref_buf[ref_frame - 1] = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3353 | continue; |
| 3354 | } |
| 3355 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3356 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
Debargha Mukherjee | 13cccf2 | 2019-03-27 23:49:14 -0700 | [diff] [blame] | 3357 | // Replace the reference buffer with a copy having a thicker border, |
| 3358 | // if the reference buffer is higher resolution than the current |
| 3359 | // frame, and the border is thin. |
| 3360 | if ((ref->y_crop_width > cm->width || |
| 3361 | ref->y_crop_height > cm->height) && |
| 3362 | ref->border < AOM_BORDER_IN_PIXELS) { |
| 3363 | RefCntBuffer *ref_fb = get_ref_frame_buf(cm, ref_frame); |
| 3364 | if (aom_yv12_realloc_with_new_border( |
| 3365 | &ref_fb->buf, AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
| 3366 | num_planes) != 0) { |
| 3367 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3368 | "Failed to allocate frame buffer"); |
| 3369 | } |
| 3370 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3371 | int force_scaling = 0; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3372 | RefCntBuffer *new_fb = cpi->scaled_ref_buf[ref_frame - 1]; |
| 3373 | if (new_fb == NULL) { |
| 3374 | const int new_fb_idx = get_free_fb(cm); |
| 3375 | if (new_fb_idx == INVALID_IDX) { |
Wan-Teh Chang | 4a8c004 | 2018-10-05 09:41:52 -0700 | [diff] [blame] | 3376 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3377 | "Unable to find free frame buffer"); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3378 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3379 | force_scaling = 1; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3380 | new_fb = &pool->frame_bufs[new_fb_idx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3381 | } |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3382 | |
| 3383 | if (force_scaling || new_fb->buf.y_crop_width != cm->width || |
| 3384 | new_fb->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3385 | if (aom_realloc_frame_buffer( |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3386 | &new_fb->buf, cm->width, cm->height, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3387 | cm->seq_params.subsampling_x, cm->seq_params.subsampling_y, |
Debargha Mukherjee | fa946af | 2019-03-26 16:58:55 -0700 | [diff] [blame] | 3388 | cm->seq_params.use_highbitdepth, AOM_BORDER_IN_PIXELS, |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3389 | cm->byte_alignment, NULL, NULL, NULL)) { |
| 3390 | if (force_scaling) { |
| 3391 | // Release the reference acquired in the get_free_fb() call above. |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3392 | --new_fb->ref_count; |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3393 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3394 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3395 | "Failed to allocate frame buffer"); |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3396 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3397 | av1_resize_and_extend_frame( |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3398 | ref, &new_fb->buf, (int)cm->seq_params.bit_depth, num_planes); |
| 3399 | cpi->scaled_ref_buf[ref_frame - 1] = new_fb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3400 | alloc_frame_mvs(cm, new_fb); |
| 3401 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3402 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3403 | RefCntBuffer *buf = get_ref_frame_buf(cm, ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3404 | buf->buf.y_crop_width = ref->y_crop_width; |
| 3405 | buf->buf.y_crop_height = ref->y_crop_height; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3406 | cpi->scaled_ref_buf[ref_frame - 1] = buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3407 | ++buf->ref_count; |
| 3408 | } |
| 3409 | } else { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3410 | if (cpi->oxcf.pass != 0) cpi->scaled_ref_buf[ref_frame - 1] = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3411 | } |
| 3412 | } |
| 3413 | } |
| 3414 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3415 | static void release_scaled_references(AV1_COMP *cpi) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3416 | // TODO(isbs): only refresh the necessary frames, rather than all of them |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3417 | for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
| 3418 | RefCntBuffer *const buf = cpi->scaled_ref_buf[i]; |
| 3419 | if (buf != NULL) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3420 | --buf->ref_count; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3421 | cpi->scaled_ref_buf[i] = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3422 | } |
| 3423 | } |
| 3424 | } |
| 3425 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3426 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 3427 | const AV1_COMMON *const cm = &cpi->common; |
| 3428 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3429 | |
| 3430 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3431 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3432 | |
| 3433 | if (cpi->sf.mv.auto_mv_step_size) { |
| 3434 | if (frame_is_intra_only(cm)) { |
| 3435 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 3436 | // after a key/intra-only frame. |
| 3437 | cpi->max_mv_magnitude = max_mv_def; |
| 3438 | } else { |
| 3439 | if (cm->show_frame) { |
| 3440 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 3441 | // in the previous frame, capped by the default max_mv_magnitude based |
| 3442 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3443 | cpi->mv_step_param = av1_init_search_range( |
| 3444 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3445 | } |
| 3446 | cpi->max_mv_magnitude = 0; |
| 3447 | } |
| 3448 | } |
| 3449 | } |
| 3450 | |
Hui Su | bdf0c99 | 2019-02-14 14:52:41 -0800 | [diff] [blame] | 3451 | static void set_screen_content_options(AV1_COMP *cpi) { |
| 3452 | AV1_COMMON *cm = &cpi->common; |
| 3453 | |
| 3454 | if (cm->seq_params.force_screen_content_tools != 2) { |
| 3455 | cm->allow_screen_content_tools = cm->allow_intrabc = |
| 3456 | cm->seq_params.force_screen_content_tools; |
| 3457 | return; |
| 3458 | } |
| 3459 | |
| 3460 | if (cpi->oxcf.content == AOM_CONTENT_SCREEN) { |
| 3461 | cm->allow_screen_content_tools = cm->allow_intrabc = 1; |
| 3462 | return; |
| 3463 | } |
| 3464 | |
| 3465 | // Estimate if the source frame is screen content, based on the portion of |
| 3466 | // blocks that have few luma colors. |
| 3467 | const uint8_t *src = cpi->source->y_buffer; |
| 3468 | assert(src != NULL); |
| 3469 | const int use_hbd = cpi->source->flags & YV12_FLAG_HIGHBITDEPTH; |
| 3470 | const int stride = cpi->source->y_stride; |
| 3471 | const int width = cpi->source->y_width; |
| 3472 | const int height = cpi->source->y_height; |
| 3473 | const int bd = cm->seq_params.bit_depth; |
| 3474 | const int blk_w = 16; |
| 3475 | const int blk_h = 16; |
| 3476 | // These threshold values are selected experimentally. |
| 3477 | const int color_thresh = 4; |
| 3478 | const unsigned int var_thresh = 0; |
| 3479 | // Counts of blocks with no more than color_thresh colors. |
| 3480 | int counts_1 = 0; |
| 3481 | // Counts of blocks with no more than color_thresh colors and variance larger |
| 3482 | // than var_thresh. |
| 3483 | int counts_2 = 0; |
| 3484 | |
| 3485 | for (int r = 0; r + blk_h <= height; r += blk_h) { |
| 3486 | for (int c = 0; c + blk_w <= width; c += blk_w) { |
| 3487 | int count_buf[1 << 12]; // Maximum (1 << 12) color levels. |
| 3488 | const uint8_t *const this_src = src + r * stride + c; |
| 3489 | const int n_colors = |
| 3490 | use_hbd ? av1_count_colors_highbd(this_src, stride, blk_w, blk_h, bd, |
| 3491 | count_buf) |
| 3492 | : av1_count_colors(this_src, stride, blk_w, blk_h, count_buf); |
| 3493 | if (n_colors > 1 && n_colors <= color_thresh) { |
| 3494 | ++counts_1; |
| 3495 | struct buf_2d buf; |
| 3496 | buf.stride = stride; |
| 3497 | buf.buf = (uint8_t *)this_src; |
| 3498 | const unsigned int var = |
| 3499 | use_hbd |
| 3500 | ? av1_high_get_sby_perpixel_variance(cpi, &buf, BLOCK_16X16, bd) |
| 3501 | : av1_get_sby_perpixel_variance(cpi, &buf, BLOCK_16X16); |
| 3502 | if (var > var_thresh) ++counts_2; |
| 3503 | } |
| 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | // The threshold values are selected experimentally. |
| 3508 | cm->allow_screen_content_tools = |
| 3509 | counts_1 * blk_h * blk_w * 10 > width * height; |
| 3510 | // IntraBC would force loop filters off, so we use more strict rules that also |
| 3511 | // requires that the block has high variance. |
| 3512 | cm->allow_intrabc = cm->allow_screen_content_tools && |
Hui Su | 64a2ffb | 2019-04-11 16:47:13 -0700 | [diff] [blame] | 3513 | counts_2 * blk_h * blk_w * 12 > width * height; |
Hui Su | bdf0c99 | 2019-02-14 14:52:41 -0800 | [diff] [blame] | 3514 | } |
| 3515 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3516 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3517 | int i; |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3518 | AV1_COMMON *cm = &cpi->common; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3519 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3520 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3521 | } |
| 3522 | cpi->global_motion_search_done = 0; |
Yunqing Wang | 9411e43 | 2019-03-14 15:53:23 -0700 | [diff] [blame] | 3523 | |
| 3524 | if (frame_is_intra_only(cm)) set_screen_content_options(cpi); |
| 3525 | cpi->is_screen_content_type = (cm->allow_screen_content_tools != 0); |
| 3526 | |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 3527 | av1_set_speed_features_framesize_independent(cpi, cpi->speed); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3528 | av1_set_rd_speed_thresholds(cpi); |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3529 | cm->interp_filter = SWITCHABLE; |
| 3530 | cm->switchable_motion_mode = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3533 | static void set_size_dependent_vars(AV1_COMP *cpi, int *q, int *bottom_index, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3534 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3535 | AV1_COMMON *const cm = &cpi->common; |
| 3536 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3537 | |
| 3538 | // Setup variables that depend on the dimensions of the frame. |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 3539 | av1_set_speed_features_framesize_dependent(cpi, cpi->speed); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3540 | |
Sebastien Alaiwan | 41cae6a | 2018-01-12 12:22:29 +0100 | [diff] [blame] | 3541 | // Decide q and q bounds. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3542 | *q = av1_rc_pick_q_and_bounds(cpi, cm->width, cm->height, bottom_index, |
| 3543 | top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3544 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3545 | if (!frame_is_intra_only(cm)) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3546 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH, |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 3547 | cpi->common.cur_frame_force_integer_mv); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3548 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3549 | |
| 3550 | // Configure experimental use of segmentation for enhanced coding of |
| 3551 | // static regions if indicated. |
| 3552 | // Only allowed in the second pass of a two pass encode, as it requires |
| 3553 | // lagged coding, and if the relevant speed feature flag is set. |
| 3554 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 3555 | configure_static_seg_features(cpi); |
| 3556 | } |
| 3557 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3558 | static void init_motion_estimation(AV1_COMP *cpi) { |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 3559 | const int y_stride = cpi->scaled_source.y_stride; |
| 3560 | const int y_stride_src = (cpi->oxcf.resize_mode || cpi->oxcf.superres_mode) |
| 3561 | ? y_stride |
| 3562 | : cpi->lookahead->buf->img.y_stride; |
| 3563 | // Update if ss_cfg is uninitialized or the current frame has a new stride |
| 3564 | const int should_update = !cpi->ss_cfg[SS_CFG_SRC].stride || |
| 3565 | !cpi->ss_cfg[SS_CFG_LOOKAHEAD].stride || |
| 3566 | (y_stride != cpi->ss_cfg[SS_CFG_SRC].stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3567 | |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 3568 | if (!should_update) { |
| 3569 | return; |
| 3570 | } |
| 3571 | |
| 3572 | if (cpi->sf.mv.search_method == DIAMOND) { |
Satish Kumar Suman | e6d0be5 | 2019-02-14 14:33:28 +0530 | [diff] [blame] | 3573 | av1_init_dsmotion_compensation(&cpi->ss_cfg[SS_CFG_SRC], y_stride); |
| 3574 | av1_init_dsmotion_compensation(&cpi->ss_cfg[SS_CFG_LOOKAHEAD], |
| 3575 | y_stride_src); |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 3576 | } else { |
| 3577 | // Update the offsets in search_sites as y_stride can change due to scaled |
| 3578 | // references. This update allows NSTEP to be used on scaled references as |
| 3579 | // long as sf.mv.search_method is not DIAMOND. Currently in the codebae, |
| 3580 | // sf.mv.search_method is never set to DIAMOND. |
| 3581 | av1_init3smotion_compensation(&cpi->ss_cfg[SS_CFG_SRC], y_stride); |
| 3582 | av1_init3smotion_compensation(&cpi->ss_cfg[SS_CFG_LOOKAHEAD], y_stride_src); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3583 | } |
| 3584 | } |
| 3585 | |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3586 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 3587 | static void set_restoration_unit_size(int width, int height, int sx, int sy, |
| 3588 | RestorationInfo *rst) { |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3589 | (void)width; |
| 3590 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3591 | (void)sx; |
| 3592 | (void)sy; |
| 3593 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3594 | int s = AOMMIN(sx, sy); |
| 3595 | #else |
| 3596 | int s = 0; |
| 3597 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3598 | |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 3599 | if (width * height > 352 * 288) |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 3600 | rst[0].restoration_unit_size = RESTORATION_UNITSIZE_MAX; |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 3601 | else |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 3602 | rst[0].restoration_unit_size = (RESTORATION_UNITSIZE_MAX >> 1); |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 3603 | rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s; |
| 3604 | rst[2].restoration_unit_size = rst[1].restoration_unit_size; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3605 | } |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3606 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3607 | static void init_ref_frame_bufs(AV1_COMP *cpi) { |
| 3608 | AV1_COMMON *const cm = &cpi->common; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3609 | int i; |
| 3610 | BufferPool *const pool = cm->buffer_pool; |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 3611 | cm->cur_frame = NULL; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3612 | for (i = 0; i < REF_FRAMES; ++i) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3613 | cm->ref_frame_map[i] = NULL; |
Wan-Teh Chang | d05e033 | 2018-10-03 12:00:43 -0700 | [diff] [blame] | 3614 | } |
| 3615 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3616 | pool->frame_bufs[i].ref_count = 0; |
| 3617 | } |
RogerZhou | 86902d0 | 2018-02-28 15:29:16 -0800 | [diff] [blame] | 3618 | if (cm->seq_params.force_screen_content_tools) { |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 3619 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3620 | av1_hash_table_init(&pool->frame_bufs[i].hash_table, &cpi->td.mb); |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 3621 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3622 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3623 | } |
| 3624 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 3625 | static void check_initial_width(AV1_COMP *cpi, int use_highbitdepth, |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3626 | int subsampling_x, int subsampling_y) { |
| 3627 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3628 | SequenceHeader *const seq_params = &cm->seq_params; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3629 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3630 | if (!cpi->initial_width || seq_params->use_highbitdepth != use_highbitdepth || |
| 3631 | seq_params->subsampling_x != subsampling_x || |
| 3632 | seq_params->subsampling_y != subsampling_y) { |
| 3633 | seq_params->subsampling_x = subsampling_x; |
| 3634 | seq_params->subsampling_y = subsampling_y; |
| 3635 | seq_params->use_highbitdepth = use_highbitdepth; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3636 | |
| 3637 | alloc_raw_frame_buffers(cpi); |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3638 | init_ref_frame_bufs(cpi); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3639 | alloc_util_frame_buffers(cpi); |
| 3640 | |
| 3641 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 3642 | |
| 3643 | cpi->initial_width = cm->width; |
| 3644 | cpi->initial_height = cm->height; |
| 3645 | cpi->initial_mbs = cm->MBs; |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | // Returns 1 if the assigned width or height was <= 0. |
| 3650 | static int set_size_literal(AV1_COMP *cpi, int width, int height) { |
| 3651 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3652 | const int num_planes = av1_num_planes(cm); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3653 | check_initial_width(cpi, cm->seq_params.use_highbitdepth, |
| 3654 | cm->seq_params.subsampling_x, |
| 3655 | cm->seq_params.subsampling_y); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3656 | |
| 3657 | if (width <= 0 || height <= 0) return 1; |
| 3658 | |
| 3659 | cm->width = width; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3660 | cm->height = height; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3661 | |
| 3662 | if (cpi->initial_width && cpi->initial_height && |
| 3663 | (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) { |
| 3664 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3665 | av1_free_pc_tree(&cpi->td, num_planes); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3666 | alloc_compressor_data(cpi); |
| 3667 | realloc_segmentation_maps(cpi); |
| 3668 | cpi->initial_width = cpi->initial_height = 0; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3669 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3670 | update_frame_size(cpi); |
| 3671 | |
| 3672 | return 0; |
| 3673 | } |
| 3674 | |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 3675 | void av1_set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3676 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3677 | const SequenceHeader *const seq_params = &cm->seq_params; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3678 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3679 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3680 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3681 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3682 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 3683 | // There has been a change in the encoded frame size |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3684 | set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3685 | set_mv_search_params(cpi); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 3686 | // Recalculate 'all_lossless' in case super-resolution was (un)selected. |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 3687 | cm->all_lossless = cm->coded_lossless && !av1_superres_scaled(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3688 | } |
| 3689 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3690 | if (cpi->oxcf.pass == 2) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3691 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3692 | } |
| 3693 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3694 | alloc_frame_mvs(cm, cm->cur_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3695 | |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 3696 | // Allocate above context buffers |
Cherma Rajan A | f147908 | 2018-05-09 14:26:34 +0530 | [diff] [blame] | 3697 | if (cm->num_allocated_above_context_planes < av1_num_planes(cm) || |
| 3698 | cm->num_allocated_above_context_mi_col < cm->mi_cols || |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 3699 | cm->num_allocated_above_contexts < cm->tile_rows) { |
| 3700 | av1_free_above_context_buffers(cm, cm->num_allocated_above_contexts); |
| 3701 | if (av1_alloc_above_context_buffers(cm, cm->tile_rows)) |
| 3702 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3703 | "Failed to allocate context buffers"); |
| 3704 | } |
| 3705 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3706 | // Reset the frame pointers to the current frame size. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3707 | if (aom_realloc_frame_buffer( |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 3708 | &cm->cur_frame->buf, cm->width, cm->height, seq_params->subsampling_x, |
| 3709 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 3710 | cpi->oxcf.border_in_pixels, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3711 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3712 | "Failed to allocate frame buffer"); |
| 3713 | |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 3714 | const int frame_width = cm->superres_upscaled_width; |
| 3715 | const int frame_height = cm->superres_upscaled_height; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3716 | set_restoration_unit_size(frame_width, frame_height, |
| 3717 | seq_params->subsampling_x, |
| 3718 | seq_params->subsampling_y, cm->rst_info); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3719 | for (int i = 0; i < num_planes; ++i) |
Rupert Swarbrick | 1a96c3f | 2017-10-24 11:55:00 +0100 | [diff] [blame] | 3720 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 3721 | |
| 3722 | av1_alloc_restoration_buffers(cm); |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3723 | alloc_util_frame_buffers(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3724 | init_motion_estimation(cpi); |
| 3725 | |
| 3726 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3727 | RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3728 | if (buf != NULL) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3729 | struct scale_factors *sf = get_ref_scale_factors(cm, ref_frame); |
| 3730 | av1_setup_scale_factors_for_frame(sf, buf->buf.y_crop_width, |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 3731 | buf->buf.y_crop_height, cm->width, |
Debargha Mukherjee | e242a81 | 2018-03-07 21:43:09 -0800 | [diff] [blame] | 3732 | cm->height); |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3733 | if (av1_is_scaled(sf)) aom_extend_frame_borders(&buf->buf, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3734 | } |
| 3735 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 3736 | |
Hui Su | 5ebd870 | 2018-01-08 18:09:20 -0800 | [diff] [blame] | 3737 | av1_setup_scale_factors_for_frame(&cm->sf_identity, cm->width, cm->height, |
Debargha Mukherjee | e242a81 | 2018-03-07 21:43:09 -0800 | [diff] [blame] | 3738 | cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3739 | |
| 3740 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 3741 | } |
| 3742 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3743 | static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) { |
| 3744 | // Choose an arbitrary random number |
| 3745 | static unsigned int seed = 56789; |
| 3746 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3747 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 3748 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3749 | |
Debargha Mukherjee | 2b7c2b3 | 2018-04-10 07:35:28 -0700 | [diff] [blame] | 3750 | if (cpi->common.seq_params.reduced_still_picture_hdr) return SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3751 | switch (oxcf->resize_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3752 | case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3753 | case RESIZE_FIXED: |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 3754 | if (cpi->common.current_frame.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3755 | new_denom = oxcf->resize_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3756 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3757 | new_denom = oxcf->resize_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3758 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3759 | case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3760 | default: assert(0); |
| 3761 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3762 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3763 | } |
| 3764 | |
Debargha Mukherjee | e3cd5a5 | 2018-11-29 11:05:22 -0800 | [diff] [blame] | 3765 | #define ENERGY_BY_Q2_THRESH 0.01 |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 3766 | #define ENERGY_BY_AC_THRESH 0.2 |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3767 | |
| 3768 | static uint8_t get_superres_denom_from_qindex_energy(int qindex, double *energy, |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 3769 | double threshq, |
| 3770 | double threshp) { |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3771 | const double q = av1_convert_qindex_to_q(qindex, AOM_BITS_8); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 3772 | const double tq = threshq * q * q; |
| 3773 | const double tp = threshp * energy[1]; |
| 3774 | const double thresh = AOMMIN(tq, tp); |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3775 | int k; |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 3776 | for (k = 16; k > 8; --k) { |
| 3777 | if (energy[k - 1] > thresh) break; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3778 | } |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 3779 | return 3 * SCALE_NUMERATOR - k; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | static uint8_t get_superres_denom_for_qindex(const AV1_COMP *cpi, int qindex) { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 3783 | double energy[16]; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3784 | analyze_hor_freq(cpi, energy); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 3785 | /* |
| 3786 | printf("\nenergy = ["); |
| 3787 | for (int k = 1; k < 16; ++k) printf("%f, ", energy[k]); |
| 3788 | printf("]\n"); |
| 3789 | */ |
| 3790 | return get_superres_denom_from_qindex_energy( |
| 3791 | qindex, energy, ENERGY_BY_Q2_THRESH, ENERGY_BY_AC_THRESH); |
Debargha Mukherjee | f48b0d2 | 2018-11-20 12:23:43 -0800 | [diff] [blame] | 3792 | } |
| 3793 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3794 | static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) { |
| 3795 | // Choose an arbitrary random number |
| 3796 | static unsigned int seed = 34567; |
| 3797 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3798 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 3799 | uint8_t new_denom = SCALE_NUMERATOR; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 3800 | |
| 3801 | // Make sure that superres mode of the frame is consistent with the |
| 3802 | // sequence-level flag. |
| 3803 | assert(IMPLIES(oxcf->superres_mode != SUPERRES_NONE, |
| 3804 | cpi->common.seq_params.enable_superres)); |
| 3805 | assert(IMPLIES(!cpi->common.seq_params.enable_superres, |
| 3806 | oxcf->superres_mode == SUPERRES_NONE)); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3807 | |
| 3808 | switch (oxcf->superres_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3809 | case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3810 | case SUPERRES_FIXED: |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 3811 | if (cpi->common.current_frame.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3812 | new_denom = oxcf->superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3813 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3814 | new_denom = oxcf->superres_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3815 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3816 | case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 3817 | case SUPERRES_QTHRESH: { |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3818 | // Do not use superres when screen content tools are used. |
| 3819 | if (cpi->common.allow_screen_content_tools) break; |
Debargha Mukherjee | 2b2c5fd | 2018-11-14 13:21:24 -0800 | [diff] [blame] | 3820 | if (oxcf->rc_mode == AOM_VBR || oxcf->rc_mode == AOM_CQ) |
| 3821 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 3822 | int bottom_index, top_index; |
| 3823 | const int q = av1_rc_pick_q_and_bounds( |
| 3824 | cpi, cpi->oxcf.width, cpi->oxcf.height, &bottom_index, &top_index); |
Debargha Mukherjee | f48b0d2 | 2018-11-20 12:23:43 -0800 | [diff] [blame] | 3825 | |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3826 | const int qthresh = (frame_is_intra_only(&cpi->common)) |
| 3827 | ? oxcf->superres_kf_qthresh |
| 3828 | : oxcf->superres_qthresh; |
Urvang Joshi | b17e0a6 | 2019-01-11 16:11:54 -0800 | [diff] [blame] | 3829 | if (q <= qthresh) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3830 | new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3831 | } else { |
Debargha Mukherjee | e3cd5a5 | 2018-11-29 11:05:22 -0800 | [diff] [blame] | 3832 | new_denom = get_superres_denom_for_qindex(cpi, q); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3833 | } |
| 3834 | break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 3835 | } |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 3836 | case SUPERRES_AUTO: { |
| 3837 | // Don't use when screen content tools are used. |
| 3838 | if (cpi->common.allow_screen_content_tools) break; |
| 3839 | // Don't use for inter frames. |
| 3840 | if (!frame_is_intra_only(&cpi->common)) break; |
Urvang Joshi | bf5e770 | 2019-04-01 11:55:09 -0700 | [diff] [blame] | 3841 | // Don't use for keyframes that can be used as references, except when |
| 3842 | // using AOM_Q mode. |
| 3843 | if (cpi->rc.frames_to_key != 1 && cpi->oxcf.rc_mode != AOM_Q) break; |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 3844 | |
| 3845 | // Now decide the use of superres based on 'q'. |
| 3846 | int bottom_index, top_index; |
| 3847 | const int q = av1_rc_pick_q_and_bounds( |
| 3848 | cpi, cpi->oxcf.width, cpi->oxcf.height, &bottom_index, &top_index); |
| 3849 | |
| 3850 | const int qthresh = 128; |
| 3851 | if (q <= qthresh) { |
| 3852 | new_denom = SCALE_NUMERATOR; |
| 3853 | } else { |
| 3854 | new_denom = get_superres_denom_for_qindex(cpi, q); |
| 3855 | } |
| 3856 | break; |
| 3857 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3858 | default: assert(0); |
| 3859 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3860 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3861 | } |
| 3862 | |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3863 | static int dimension_is_ok(int orig_dim, int resized_dim, int denom) { |
| 3864 | return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2); |
| 3865 | } |
| 3866 | |
| 3867 | static int dimensions_are_ok(int owidth, int oheight, size_params_type *rsz) { |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 3868 | // Only need to check the width, as scaling is horizontal only. |
| 3869 | (void)oheight; |
| 3870 | return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3871 | } |
| 3872 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3873 | static int validate_size_scales(RESIZE_MODE resize_mode, |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3874 | SUPERRES_MODE superres_mode, int owidth, |
| 3875 | int oheight, size_params_type *rsz) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3876 | if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3877 | return 1; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3878 | } |
| 3879 | |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 3880 | // Calculate current resize scale. |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3881 | int resize_denom = |
| 3882 | AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width), |
| 3883 | DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height)); |
| 3884 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3885 | if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3886 | // Alter superres scale as needed to enforce conformity. |
| 3887 | rsz->superres_denom = |
| 3888 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom; |
| 3889 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 3890 | if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3891 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3892 | } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3893 | // Alter resize scale as needed to enforce conformity. |
| 3894 | resize_denom = |
| 3895 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3896 | rsz->resize_width = owidth; |
| 3897 | rsz->resize_height = oheight; |
| 3898 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3899 | resize_denom); |
| 3900 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 3901 | if (resize_denom > SCALE_NUMERATOR) { |
| 3902 | --resize_denom; |
| 3903 | rsz->resize_width = owidth; |
| 3904 | rsz->resize_height = oheight; |
| 3905 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
| 3906 | resize_denom); |
| 3907 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3908 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3909 | } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3910 | // Alter both resize and superres scales as needed to enforce conformity. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3911 | do { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3912 | if (resize_denom > rsz->superres_denom) |
| 3913 | --resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3914 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3915 | --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3916 | rsz->resize_width = owidth; |
| 3917 | rsz->resize_height = oheight; |
| 3918 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3919 | resize_denom); |
| 3920 | } while (!dimensions_are_ok(owidth, oheight, rsz) && |
| 3921 | (resize_denom > SCALE_NUMERATOR || |
| 3922 | rsz->superres_denom > SCALE_NUMERATOR)); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 3923 | } else { // We are allowed to alter neither resize scale nor superres |
| 3924 | // scale. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3925 | return 0; |
| 3926 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3927 | return dimensions_are_ok(owidth, oheight, rsz); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3928 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3929 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3930 | // Calculates resize and superres params for next frame |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 3931 | static size_params_type calculate_next_size_params(AV1_COMP *cpi) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3932 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 3933 | size_params_type rsz = { oxcf->width, oxcf->height, SCALE_NUMERATOR }; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3934 | int resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3935 | if (oxcf->pass == 1) return rsz; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3936 | if (cpi->resize_pending_width && cpi->resize_pending_height) { |
| 3937 | rsz.resize_width = cpi->resize_pending_width; |
| 3938 | rsz.resize_height = cpi->resize_pending_height; |
| 3939 | cpi->resize_pending_width = cpi->resize_pending_height = 0; |
| 3940 | } else { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3941 | resize_denom = calculate_next_resize_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3942 | rsz.resize_width = cpi->oxcf.width; |
| 3943 | rsz.resize_height = cpi->oxcf.height; |
| 3944 | av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3945 | resize_denom); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3946 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3947 | rsz.superres_denom = calculate_next_superres_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3948 | if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width, |
| 3949 | oxcf->height, &rsz)) |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3950 | assert(0 && "Invalid scale parameters"); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3951 | return rsz; |
| 3952 | } |
| 3953 | |
Urvang Joshi | 22b150b | 2019-01-10 14:32:32 -0800 | [diff] [blame] | 3954 | static void setup_frame_size_from_params(AV1_COMP *cpi, |
| 3955 | const size_params_type *rsz) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3956 | int encode_width = rsz->resize_width; |
| 3957 | int encode_height = rsz->resize_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3958 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3959 | AV1_COMMON *cm = &cpi->common; |
| 3960 | cm->superres_upscaled_width = encode_width; |
| 3961 | cm->superres_upscaled_height = encode_height; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3962 | cm->superres_scale_denominator = rsz->superres_denom; |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 3963 | av1_calculate_scaled_superres_size(&encode_width, &encode_height, |
| 3964 | rsz->superres_denom); |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 3965 | av1_set_frame_size(cpi, encode_width, encode_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3966 | } |
| 3967 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 3968 | void av1_setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 3969 | AV1_COMMON *cm = &cpi->common; |
Urvang Joshi | 22b150b | 2019-01-10 14:32:32 -0800 | [diff] [blame] | 3970 | // Reset superres params from previous frame. |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 3971 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 3972 | const size_params_type rsz = calculate_next_size_params(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3973 | setup_frame_size_from_params(cpi, &rsz); |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 3974 | |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 3975 | assert(av1_is_min_tile_width_satisfied(cm)); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3976 | } |
| 3977 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3978 | static void superres_post_encode(AV1_COMP *cpi) { |
| 3979 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3980 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3981 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 3982 | if (!av1_superres_scaled(cm)) return; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3983 | |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 3984 | assert(cpi->oxcf.enable_superres); |
| 3985 | assert(!is_lossless_requested(&cpi->oxcf)); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 3986 | assert(!cm->all_lossless); |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 3987 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3988 | av1_superres_upscale(cm, NULL); |
| 3989 | |
| 3990 | // If regular resizing is occurring the source will need to be downscaled to |
| 3991 | // match the upscaled superres resolution. Otherwise the original source is |
| 3992 | // used. |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 3993 | if (!av1_resize_scaled(cm)) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3994 | cpi->source = cpi->unscaled_source; |
| 3995 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 3996 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 3997 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 3998 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 3999 | // Do downscale. cm->(width|height) has been updated by |
| 4000 | // av1_superres_upscale |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4001 | if (aom_realloc_frame_buffer( |
| 4002 | &cpi->scaled_source, cm->superres_upscaled_width, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4003 | cm->superres_upscaled_height, cm->seq_params.subsampling_x, |
| 4004 | cm->seq_params.subsampling_y, cm->seq_params.use_highbitdepth, |
| 4005 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4006 | aom_internal_error( |
| 4007 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 4008 | "Failed to reallocate scaled source buffer for superres"); |
| 4009 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 4010 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4011 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4012 | (int)cm->seq_params.bit_depth, num_planes); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4013 | cpi->source = &cpi->scaled_source; |
| 4014 | } |
| 4015 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4016 | |
| 4017 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4018 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4019 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
Urvang Joshi | 14072aa | 2018-03-21 17:43:36 -0700 | [diff] [blame] | 4020 | |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4021 | assert(IMPLIES(is_lossless_requested(&cpi->oxcf), |
| 4022 | cm->coded_lossless && cm->all_lossless)); |
| 4023 | |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4024 | const int use_loopfilter = !cm->coded_lossless && !cm->large_scale_tile; |
| 4025 | const int use_cdef = cm->seq_params.enable_cdef && !cm->coded_lossless && |
| 4026 | !cm->large_scale_tile; |
| 4027 | const int use_restoration = cm->seq_params.enable_restoration && |
| 4028 | !cm->all_lossless && !cm->large_scale_tile; |
Urvang Joshi | 14072aa | 2018-03-21 17:43:36 -0700 | [diff] [blame] | 4029 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4030 | struct loopfilter *lf = &cm->lf; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4031 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4032 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4033 | start_timing(cpi, loop_filter_time); |
| 4034 | #endif |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4035 | if (use_loopfilter) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4036 | aom_clear_system_state(); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4037 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4038 | } else { |
| 4039 | lf->filter_level[0] = 0; |
| 4040 | lf->filter_level[1] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
Debargha Mukherjee | 2382b14 | 2018-02-26 14:31:32 -0800 | [diff] [blame] | 4043 | if (lf->filter_level[0] || lf->filter_level[1]) { |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 4044 | if (cpi->num_workers > 1) |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4045 | av1_loop_filter_frame_mt(&cm->cur_frame->buf, cm, xd, 0, num_planes, 0, |
Yaowu Xu | 8e718cf | 2019-05-02 09:06:57 -0700 | [diff] [blame] | 4046 | #if CONFIG_LPF_MASK |
Cheng Chen | e3600cd | 2018-09-21 18:45:42 -0700 | [diff] [blame] | 4047 | 0, |
| 4048 | #endif |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 4049 | cpi->workers, cpi->num_workers, |
| 4050 | &cpi->lf_row_sync); |
| 4051 | else |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4052 | av1_loop_filter_frame(&cm->cur_frame->buf, cm, xd, |
Yaowu Xu | 8e718cf | 2019-05-02 09:06:57 -0700 | [diff] [blame] | 4053 | #if CONFIG_LPF_MASK |
Cheng Chen | 84b0993 | 2018-08-12 17:35:13 -0700 | [diff] [blame] | 4054 | 0, |
Cheng Chen | 8ab1f44 | 2018-04-27 18:01:52 -0700 | [diff] [blame] | 4055 | #endif |
Cheng Chen | 84b0993 | 2018-08-12 17:35:13 -0700 | [diff] [blame] | 4056 | 0, num_planes, 0); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4057 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4058 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4059 | end_timing(cpi, loop_filter_time); |
| 4060 | #endif |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 4061 | |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4062 | if (use_restoration) |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4063 | av1_loop_restoration_save_boundary_lines(&cm->cur_frame->buf, cm, 0); |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 4064 | |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4065 | if (use_cdef) { |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4066 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4067 | start_timing(cpi, cdef_time); |
| 4068 | #endif |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 4069 | // Find CDEF parameters |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4070 | av1_cdef_search(&cm->cur_frame->buf, cpi->source, cm, xd, |
Debargha Mukherjee | d7338aa | 2017-11-04 07:34:50 -0700 | [diff] [blame] | 4071 | cpi->sf.fast_cdef_search); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4072 | |
| 4073 | // Apply the filter |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4074 | av1_cdef_frame(&cm->cur_frame->buf, cm, xd); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4075 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4076 | end_timing(cpi, cdef_time); |
| 4077 | #endif |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4078 | } else { |
| 4079 | cm->cdef_info.cdef_bits = 0; |
| 4080 | cm->cdef_info.cdef_strengths[0] = 0; |
| 4081 | cm->cdef_info.nb_cdef_strengths = 1; |
| 4082 | cm->cdef_info.cdef_uv_strengths[0] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4083 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4084 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4085 | superres_post_encode(cpi); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4086 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4087 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4088 | start_timing(cpi, loop_restoration_time); |
| 4089 | #endif |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4090 | if (use_restoration) { |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4091 | av1_loop_restoration_save_boundary_lines(&cm->cur_frame->buf, cm, 1); |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4092 | av1_pick_filter_restoration(cpi->source, cpi); |
| 4093 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 4094 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 4095 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4096 | if (cpi->num_workers > 1) |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4097 | av1_loop_restoration_filter_frame_mt(&cm->cur_frame->buf, cm, 0, |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4098 | cpi->workers, cpi->num_workers, |
| 4099 | &cpi->lr_row_sync, &cpi->lr_ctxt); |
| 4100 | else |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4101 | av1_loop_restoration_filter_frame(&cm->cur_frame->buf, cm, 0, |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4102 | &cpi->lr_ctxt); |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4103 | } |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4104 | } else { |
| 4105 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 4106 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 4107 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4108 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4109 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4110 | end_timing(cpi, loop_restoration_time); |
| 4111 | #endif |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4112 | } |
| 4113 | |
David Turner | f2b334c | 2018-12-13 13:00:55 +0000 | [diff] [blame] | 4114 | static void fix_interp_filter(InterpFilter *const interp_filter, |
| 4115 | const FRAME_COUNTS *const counts) { |
| 4116 | if (*interp_filter == SWITCHABLE) { |
| 4117 | // Check to see if only one of the filters is actually used |
| 4118 | int count[SWITCHABLE_FILTERS] = { 0 }; |
| 4119 | int num_filters_used = 0; |
| 4120 | for (int i = 0; i < SWITCHABLE_FILTERS; ++i) { |
| 4121 | for (int j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) |
| 4122 | count[i] += counts->switchable_interp[j][i]; |
| 4123 | num_filters_used += (count[i] > 0); |
| 4124 | } |
| 4125 | if (num_filters_used == 1) { |
| 4126 | // Only one filter is used. So set the filter at frame level |
| 4127 | for (int i = 0; i < SWITCHABLE_FILTERS; ++i) { |
| 4128 | if (count[i]) { |
| 4129 | if (i == EIGHTTAP_REGULAR) *interp_filter = i; |
| 4130 | break; |
| 4131 | } |
| 4132 | } |
| 4133 | } |
| 4134 | } |
| 4135 | } |
| 4136 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4137 | static void finalize_encoded_frame(AV1_COMP *const cpi) { |
| 4138 | AV1_COMMON *const cm = &cpi->common; |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4139 | CurrentFrame *const current_frame = &cm->current_frame; |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4140 | |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4141 | if (!cm->seq_params.reduced_still_picture_hdr && |
| 4142 | encode_show_existing_frame(cm)) { |
| 4143 | RefCntBuffer *const frame_to_show = |
| 4144 | cm->ref_frame_map[cpi->existing_fb_idx_to_show]; |
| 4145 | |
Wan-Teh Chang | 88cd166 | 2019-01-14 12:38:41 -0800 | [diff] [blame] | 4146 | if (frame_to_show == NULL) { |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4147 | aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
| 4148 | "Buffer does not contain a reconstructed frame"); |
| 4149 | } |
Wan-Teh Chang | 88cd166 | 2019-01-14 12:38:41 -0800 | [diff] [blame] | 4150 | assert(frame_to_show->ref_count > 0); |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4151 | assign_frame_buffer_p(&cm->cur_frame, frame_to_show); |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4152 | } |
David Turner | 08f909c | 2018-12-18 13:29:14 +0000 | [diff] [blame] | 4153 | |
| 4154 | if (!encode_show_existing_frame(cm) && |
| 4155 | cm->seq_params.film_grain_params_present && |
| 4156 | (cm->show_frame || cm->showable_frame)) { |
| 4157 | // Copy the current frame's film grain params to the its corresponding |
| 4158 | // RefCntBuffer slot. |
| 4159 | cm->cur_frame->film_grain_params = cm->film_grain_params; |
| 4160 | |
| 4161 | // We must update the parameters if this is not an INTER_FRAME |
| 4162 | if (current_frame->frame_type != INTER_FRAME) |
| 4163 | cm->cur_frame->film_grain_params.update_parameters = 1; |
| 4164 | |
| 4165 | // Iterate the random seed for the next frame. |
| 4166 | cm->film_grain_params.random_seed += 3381; |
| 4167 | if (cm->film_grain_params.random_seed == 0) |
| 4168 | cm->film_grain_params.random_seed = 7391; |
| 4169 | } |
David Turner | f2b334c | 2018-12-13 13:00:55 +0000 | [diff] [blame] | 4170 | |
| 4171 | // Initialise all tiles' contexts from the global frame context |
| 4172 | for (int tile_col = 0; tile_col < cm->tile_cols; tile_col++) { |
| 4173 | for (int tile_row = 0; tile_row < cm->tile_rows; tile_row++) { |
| 4174 | const int tile_idx = tile_row * cm->tile_cols + tile_col; |
| 4175 | cpi->tile_data[tile_idx].tctx = *cm->fc; |
| 4176 | } |
| 4177 | } |
| 4178 | |
| 4179 | fix_interp_filter(&cm->interp_filter, cpi->td.counts); |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4180 | } |
| 4181 | |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4182 | static int get_regulated_q_overshoot(AV1_COMP *const cpi, int q_low, int q_high, |
| 4183 | int top_index, int bottom_index) { |
| 4184 | const AV1_COMMON *const cm = &cpi->common; |
| 4185 | const RATE_CONTROL *const rc = &cpi->rc; |
| 4186 | |
| 4187 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4188 | |
| 4189 | int q_regulated = |
| 4190 | av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4191 | AOMMAX(q_high, top_index), cm->width, cm->height); |
| 4192 | |
| 4193 | int retries = 0; |
| 4194 | while (q_regulated < q_low && retries < 10) { |
| 4195 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4196 | q_regulated = |
| 4197 | av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4198 | AOMMAX(q_high, top_index), cm->width, cm->height); |
| 4199 | retries++; |
| 4200 | } |
| 4201 | return q_regulated; |
| 4202 | } |
| 4203 | |
| 4204 | static int get_regulated_q_undershoot(AV1_COMP *const cpi, int q_high, |
| 4205 | int top_index, int bottom_index) { |
| 4206 | const AV1_COMMON *const cm = &cpi->common; |
| 4207 | const RATE_CONTROL *const rc = &cpi->rc; |
| 4208 | |
| 4209 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4210 | int q_regulated = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4211 | top_index, cm->width, cm->height); |
| 4212 | |
| 4213 | int retries = 0; |
| 4214 | while (q_regulated > q_high && retries < 10) { |
| 4215 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4216 | q_regulated = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4217 | top_index, cm->width, cm->height); |
| 4218 | retries++; |
| 4219 | } |
| 4220 | return q_regulated; |
| 4221 | } |
| 4222 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4223 | // Called after encode_with_recode_loop() has just encoded a frame and packed |
| 4224 | // its bitstream. This function works out whether we under- or over-shot |
| 4225 | // our bitrate target and adjusts q as appropriate. Also decides whether |
| 4226 | // or not we should do another recode loop, indicated by *loop |
| 4227 | static void recode_loop_update_q(AV1_COMP *const cpi, int *const loop, |
| 4228 | int *const q, int *const q_low, |
| 4229 | int *const q_high, const int top_index, |
| 4230 | const int bottom_index, |
| 4231 | int *const undershoot_seen, |
| 4232 | int *const overshoot_seen, |
| 4233 | const int loop_at_this_size) { |
| 4234 | AV1_COMMON *const cm = &cpi->common; |
| 4235 | RATE_CONTROL *const rc = &cpi->rc; |
| 4236 | |
| 4237 | int frame_over_shoot_limit = 0, frame_under_shoot_limit = 0; |
| 4238 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4239 | &frame_under_shoot_limit, |
| 4240 | &frame_over_shoot_limit); |
| 4241 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4242 | |
| 4243 | if ((cm->current_frame.frame_type == KEY_FRAME) && |
| 4244 | rc->this_key_frame_forced && |
| 4245 | (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
| 4246 | int last_q = *q; |
| 4247 | int64_t kf_err; |
| 4248 | |
| 4249 | int64_t high_err_target = cpi->ambient_err; |
| 4250 | int64_t low_err_target = cpi->ambient_err >> 1; |
| 4251 | |
| 4252 | if (cm->seq_params.use_highbitdepth) { |
| 4253 | kf_err = aom_highbd_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 4254 | } else { |
| 4255 | kf_err = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 4256 | } |
| 4257 | // Prevent possible divide by zero error below for perfect KF |
| 4258 | kf_err += !kf_err; |
| 4259 | |
| 4260 | // The key frame is not good enough or we can afford |
| 4261 | // to make it better without undue risk of popping. |
| 4262 | if ((kf_err > high_err_target && |
| 4263 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4264 | (kf_err > low_err_target && |
| 4265 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4266 | // Lower q_high |
| 4267 | *q_high = *q > *q_low ? *q - 1 : *q_low; |
| 4268 | |
| 4269 | // Adjust Q |
| 4270 | *q = (int)((*q * high_err_target) / kf_err); |
| 4271 | *q = AOMMIN(*q, (*q_high + *q_low) >> 1); |
| 4272 | } else if (kf_err < low_err_target && |
| 4273 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4274 | // The key frame is much better than the previous frame |
| 4275 | // Raise q_low |
| 4276 | *q_low = *q < *q_high ? *q + 1 : *q_high; |
| 4277 | |
| 4278 | // Adjust Q |
| 4279 | *q = (int)((*q * low_err_target) / kf_err); |
| 4280 | *q = AOMMIN(*q, (*q_high + *q_low + 1) >> 1); |
| 4281 | } |
| 4282 | |
| 4283 | // Clamp Q to upper and lower limits: |
| 4284 | *q = clamp(*q, *q_low, *q_high); |
| 4285 | |
| 4286 | *loop = *q != last_q; |
| 4287 | } else if (recode_loop_test(cpi, frame_over_shoot_limit, |
| 4288 | frame_under_shoot_limit, *q, |
| 4289 | AOMMAX(*q_high, top_index), bottom_index)) { |
| 4290 | // Is the projected frame size out of range and are we allowed |
| 4291 | // to attempt to recode. |
| 4292 | int last_q = *q; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4293 | |
| 4294 | // Frame size out of permitted range: |
| 4295 | // Update correction factor & compute new Q to try... |
| 4296 | // Frame is too large |
| 4297 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 4298 | // Special case if the projected size is > the max allowed. |
| 4299 | if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
| 4300 | *q_high = rc->worst_quality; |
| 4301 | |
| 4302 | // Raise Qlow as to at least the current value |
| 4303 | *q_low = *q < *q_high ? *q + 1 : *q_high; |
| 4304 | |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4305 | if (*undershoot_seen || loop_at_this_size > 2 || |
| 4306 | (loop_at_this_size == 2 && !frame_is_intra_only(cm))) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4307 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4308 | |
| 4309 | *q = (*q_high + *q_low + 1) / 2; |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4310 | } else if (loop_at_this_size == 2 && frame_is_intra_only(cm)) { |
| 4311 | const int q_mid = (*q_high + *q_low + 1) / 2; |
| 4312 | const int q_regulated = get_regulated_q_overshoot( |
| 4313 | cpi, *q_low, *q_high, top_index, bottom_index); |
| 4314 | // Get 'q' in-between 'q_mid' and 'q_regulated' for a smooth |
| 4315 | // transition between loop_at_this_size < 2 and loop_at_this_size > 2. |
| 4316 | *q = (q_mid + q_regulated + 1) / 2; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4317 | } else { |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4318 | *q = get_regulated_q_overshoot(cpi, *q_low, *q_high, top_index, |
| 4319 | bottom_index); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | *overshoot_seen = 1; |
| 4323 | } else { |
| 4324 | // Frame is too small |
| 4325 | *q_high = *q > *q_low ? *q - 1 : *q_low; |
| 4326 | |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4327 | if (*overshoot_seen || loop_at_this_size > 2 || |
| 4328 | (loop_at_this_size == 2 && !frame_is_intra_only(cm))) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4329 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4330 | *q = (*q_high + *q_low) / 2; |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4331 | } else if (loop_at_this_size == 2 && frame_is_intra_only(cm)) { |
| 4332 | const int q_mid = (*q_high + *q_low) / 2; |
| 4333 | const int q_regulated = |
| 4334 | get_regulated_q_undershoot(cpi, *q_high, top_index, bottom_index); |
| 4335 | // Get 'q' in-between 'q_mid' and 'q_regulated' for a smooth |
| 4336 | // transition between loop_at_this_size < 2 and loop_at_this_size > 2. |
| 4337 | *q = (q_mid + q_regulated) / 2; |
| 4338 | |
| 4339 | // Special case reset for qlow for constrained quality. |
| 4340 | // This should only trigger where there is very substantial |
| 4341 | // undershoot on a frame and the auto cq level is above |
| 4342 | // the user passsed in value. |
| 4343 | if (cpi->oxcf.rc_mode == AOM_CQ && q_regulated < *q_low) { |
| 4344 | *q_low = *q; |
| 4345 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4346 | } else { |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4347 | *q = get_regulated_q_undershoot(cpi, *q_high, top_index, bottom_index); |
| 4348 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4349 | // Special case reset for qlow for constrained quality. |
| 4350 | // This should only trigger where there is very substantial |
| 4351 | // undershoot on a frame and the auto cq level is above |
| 4352 | // the user passsed in value. |
| 4353 | if (cpi->oxcf.rc_mode == AOM_CQ && *q < *q_low) { |
| 4354 | *q_low = *q; |
| 4355 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4356 | } |
| 4357 | |
| 4358 | *undershoot_seen = 1; |
| 4359 | } |
| 4360 | |
| 4361 | // Clamp Q to upper and lower limits: |
| 4362 | *q = clamp(*q, *q_low, *q_high); |
| 4363 | |
| 4364 | *loop = (*q != last_q); |
| 4365 | } else { |
| 4366 | *loop = 0; |
| 4367 | } |
| 4368 | } |
| 4369 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4370 | static int encode_with_recode_loop(AV1_COMP *cpi, size_t *size, uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4371 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4372 | RATE_CONTROL *const rc = &cpi->rc; |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame^] | 4373 | const int allow_recode = (cpi->sf.recode_loop != DISALLOW_RECODE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4374 | |
| 4375 | set_size_independent_vars(cpi); |
| 4376 | |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4377 | cpi->source->buf_8bit_valid = 0; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4378 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 4379 | av1_setup_frame_size(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4380 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4381 | int top_index = 0, bottom_index = 0; |
| 4382 | int q = 0, q_low = 0, q_high = 0; |
| 4383 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4384 | q_low = bottom_index; |
| 4385 | q_high = top_index; |
| 4386 | |
| 4387 | // Loop variables |
| 4388 | int loop_count = 0; |
| 4389 | int loop_at_this_size = 0; |
| 4390 | int loop = 0; |
| 4391 | int overshoot_seen = 0; |
| 4392 | int undershoot_seen = 0; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4393 | |
| 4394 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4395 | printf("\n Encoding a frame:"); |
| 4396 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4397 | do { |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame^] | 4398 | loop = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4399 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4400 | |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4401 | // if frame was scaled calculate global_motion_search again if already |
| 4402 | // done |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4403 | if (loop_count > 0 && cpi->source && cpi->global_motion_search_done) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4404 | if (cpi->source->y_crop_width != cm->width || |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4405 | cpi->source->y_crop_height != cm->height) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4406 | cpi->global_motion_search_done = 0; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4407 | } |
| 4408 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4409 | cpi->source = |
| 4410 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4411 | if (cpi->unscaled_last_source != NULL) { |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4412 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4413 | &cpi->scaled_last_source); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4414 | } |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4415 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4416 | if (!frame_is_intra_only(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4417 | if (loop_count > 0) { |
| 4418 | release_scaled_references(cpi); |
| 4419 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4420 | scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4421 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4422 | av1_set_quantizer(cm, q); |
Yue Chen | a7d8048 | 2019-01-31 09:48:09 -0800 | [diff] [blame] | 4423 | av1_init_quantizer(cpi); |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 4424 | |
| 4425 | av1_set_variance_partition_thresholds(cpi, q, 0); |
| 4426 | |
Debargha Mukherjee | f48b0d2 | 2018-11-20 12:23:43 -0800 | [diff] [blame] | 4427 | // printf("Frame %d/%d: q = %d, frame_type = %d superres_denom = %d\n", |
| 4428 | // cm->current_frame.frame_number, cm->show_frame, q, |
| 4429 | // cm->current_frame.frame_type, cm->superres_scale_denominator); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4430 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4431 | if (loop_count == 0) { |
| 4432 | setup_frame(cpi); |
| 4433 | } else if (get_primary_ref_frame_buf(cm) == NULL) { |
| 4434 | // Base q-index may have changed, so we need to assign proper default coef |
| 4435 | // probs before every iteration. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4436 | av1_default_coef_probs(cm); |
Hui Su | 3694c83 | 2017-11-10 14:15:58 -0800 | [diff] [blame] | 4437 | av1_setup_frame_contexts(cm); |
David Barker | fc91b39 | 2018-03-09 15:32:03 +0000 | [diff] [blame] | 4438 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4439 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4440 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4441 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4442 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4443 | av1_setup_in_frame_q_adj(cpi); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4444 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && !allow_recode) { |
| 4445 | suppress_active_map(cpi); |
| 4446 | av1_cyclic_refresh_setup(cpi); |
| 4447 | apply_active_map(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4448 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4449 | |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4450 | if (cm->seg.enabled) { |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4451 | if (!cm->seg.update_data && cm->prev_frame) { |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4452 | segfeatures_copy(&cm->seg, &cm->prev_frame->seg); |
David Barker | 11c9356 | 2018-06-05 12:00:07 +0100 | [diff] [blame] | 4453 | } else { |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 4454 | av1_calculate_segdata(&cm->seg); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 4455 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4456 | } else { |
| 4457 | memset(&cm->seg, 0, sizeof(cm->seg)); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4458 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4459 | segfeatures_copy(&cm->cur_frame->seg, &cm->seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4460 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4461 | if (allow_recode) save_coding_context(cpi); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4462 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4463 | start_timing(cpi, av1_encode_frame_time); |
| 4464 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4465 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4466 | av1_encode_frame(cpi); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4467 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4468 | end_timing(cpi, av1_encode_frame_time); |
| 4469 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4470 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4471 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4472 | |
| 4473 | // Dummy pack of the bitstream using up to date stats to get an |
| 4474 | // accurate estimate of output frame size to determine if we need |
| 4475 | // to recode. |
| 4476 | if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4477 | restore_coding_context(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4478 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4479 | finalize_encoded_frame(cpi); |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 4480 | int largest_tile_id = 0; // Output from bitstream: unused here |
| 4481 | if (av1_pack_bitstream(cpi, dest, size, &largest_tile_id) != AOM_CODEC_OK) |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4482 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4483 | |
| 4484 | rc->projected_frame_size = (int)(*size) << 3; |
| 4485 | restore_coding_context(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4486 | } |
| 4487 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4488 | if (allow_recode && cpi->oxcf.rc_mode != AOM_Q) { |
| 4489 | // Update q and decide whether to do a recode loop |
| 4490 | recode_loop_update_q(cpi, &loop, &q, &q_low, &q_high, top_index, |
| 4491 | bottom_index, &undershoot_seen, &overshoot_seen, |
| 4492 | loop_at_this_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | // Special case for overlay frame. |
| 4496 | if (rc->is_src_frame_alt_ref && |
| 4497 | rc->projected_frame_size < rc->max_frame_bandwidth) |
| 4498 | loop = 0; |
| 4499 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4500 | if (allow_recode && !cpi->sf.gm_disable_recode && |
| 4501 | recode_loop_test_global_motion(cpi)) { |
| 4502 | loop = 1; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4503 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4504 | |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame^] | 4505 | if (cpi->tpl_model_pass == 1) { |
| 4506 | assert(cpi->oxcf.enable_tpl_model == 2); |
| 4507 | |
| 4508 | // TODO(debargha, yuec): Update forward tpl model here |
| 4509 | |
| 4510 | cpi->tpl_model_pass = 0; |
| 4511 | loop = 1; |
| 4512 | } |
| 4513 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4514 | if (loop) { |
| 4515 | ++loop_count; |
| 4516 | ++loop_at_this_size; |
| 4517 | |
| 4518 | #if CONFIG_INTERNAL_STATS |
| 4519 | ++cpi->tot_recode_hits; |
| 4520 | #endif |
| 4521 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4522 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4523 | if (loop) printf("\n Recoding:"); |
| 4524 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4525 | } while (loop); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4526 | |
| 4527 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4528 | } |
| 4529 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4530 | #define DUMP_RECON_FRAMES 0 |
| 4531 | |
| 4532 | #if DUMP_RECON_FRAMES == 1 |
| 4533 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4534 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 4535 | AV1_COMMON *const cm = &cpi->common; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4536 | const CurrentFrame *const current_frame = &cm->current_frame; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4537 | const YV12_BUFFER_CONFIG *recon_buf = &cm->cur_frame->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4538 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4539 | if (recon_buf == NULL) { |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4540 | printf("Frame %d is not ready.\n", current_frame->frame_number); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4541 | return; |
| 4542 | } |
| 4543 | |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 4544 | static const int flag_list[REF_FRAMES] = { 0, |
| 4545 | AOM_LAST_FLAG, |
| 4546 | AOM_LAST2_FLAG, |
| 4547 | AOM_LAST3_FLAG, |
| 4548 | AOM_GOLD_FLAG, |
| 4549 | AOM_BWD_FLAG, |
| 4550 | AOM_ALT2_FLAG, |
| 4551 | AOM_ALT_FLAG }; |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4552 | printf( |
| 4553 | "\n***Frame=%d (frame_offset=%d, show_frame=%d, " |
| 4554 | "show_existing_frame=%d) " |
| 4555 | "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[", |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4556 | current_frame->frame_number, current_frame->order_hint, cm->show_frame, |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4557 | cm->show_existing_frame); |
| 4558 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4559 | const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame); |
| 4560 | const int ref_offset = buf != NULL ? (int)buf->order_hint : -1; |
Urvang Joshi | b6f1767 | 2019-03-05 11:51:02 -0800 | [diff] [blame] | 4561 | printf(" %d(%c)", ref_offset, |
| 4562 | (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N'); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4563 | } |
| 4564 | printf(" ]\n"); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4565 | |
| 4566 | if (!cm->show_frame) { |
| 4567 | printf("Frame %d is a no show frame, so no image dump.\n", |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4568 | current_frame->frame_number); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4569 | return; |
| 4570 | } |
| 4571 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4572 | int h; |
| 4573 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 4574 | FILE *f_recon = NULL; |
| 4575 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4576 | if (current_frame->frame_number == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4577 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 4578 | printf("Unable to open file %s to write.\n", file_name); |
| 4579 | return; |
| 4580 | } |
| 4581 | } else { |
| 4582 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 4583 | printf("Unable to open file %s to append.\n", file_name); |
| 4584 | return; |
| 4585 | } |
| 4586 | } |
| 4587 | printf( |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4588 | "\nFrame=%5d, encode_update_type[%5d]=%1d, frame_offset=%d, " |
| 4589 | "show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, " |
Urvang Joshi | 7a89023 | 2019-03-22 17:00:31 -0700 | [diff] [blame] | 4590 | "refresh_alt_ref_frame=%d, " |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4591 | "y_stride=%4d, uv_stride=%4d, cm->width=%4d, cm->height=%4d\n\n", |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4592 | current_frame->frame_number, cpi->twopass.gf_group.index, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4593 | cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4594 | current_frame->order_hint, cm->show_frame, cm->show_existing_frame, |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4595 | cpi->rc.source_alt_ref_active, cpi->refresh_alt_ref_frame, |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4596 | recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4597 | #if 0 |
| 4598 | int ref_frame; |
| 4599 | printf("get_ref_frame_map_idx: ["); |
| 4600 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4601 | printf(" %d", get_ref_frame_map_idx(cm, ref_frame)); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4602 | printf(" ]\n"); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4603 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4604 | |
| 4605 | // --- Y --- |
| 4606 | for (h = 0; h < cm->height; ++h) { |
| 4607 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 4608 | f_recon); |
| 4609 | } |
| 4610 | // --- U --- |
| 4611 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4612 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4613 | f_recon); |
| 4614 | } |
| 4615 | // --- V --- |
| 4616 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4617 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4618 | f_recon); |
| 4619 | } |
| 4620 | |
| 4621 | fclose(f_recon); |
| 4622 | } |
| 4623 | #endif // DUMP_RECON_FRAMES |
| 4624 | |
David Turner | bc0993e | 2019-02-15 14:42:23 +0000 | [diff] [blame] | 4625 | static int get_interp_filter_selected(const AV1_COMMON *const cm, |
| 4626 | MV_REFERENCE_FRAME ref, |
| 4627 | InterpFilters ifilter) { |
| 4628 | const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref); |
| 4629 | if (buf == NULL) return 0; |
| 4630 | return buf->interp_filter_selected[ifilter]; |
| 4631 | } |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 4632 | |
David Turner | bc0993e | 2019-02-15 14:42:23 +0000 | [diff] [blame] | 4633 | static int setup_interp_filter_search_mask(AV1_COMP *cpi) { |
| 4634 | const AV1_COMMON *const cm = &cpi->common; |
| 4635 | int ref_total[REF_FRAMES] = { 0 }; |
| 4636 | |
| 4637 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame) |
| 4638 | return 0; |
| 4639 | |
| 4640 | for (MV_REFERENCE_FRAME ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) { |
| 4641 | for (InterpFilters ifilter = EIGHTTAP_REGULAR; ifilter <= MULTITAP_SHARP; |
| 4642 | ++ifilter) { |
| 4643 | ref_total[ref] += get_interp_filter_selected(cm, ref, ifilter); |
| 4644 | } |
| 4645 | } |
| 4646 | int ref_total_total = (ref_total[LAST2_FRAME] + ref_total[LAST3_FRAME] + |
| 4647 | ref_total[GOLDEN_FRAME] + ref_total[BWDREF_FRAME] + |
| 4648 | ref_total[ALTREF2_FRAME] + ref_total[ALTREF_FRAME]); |
| 4649 | |
| 4650 | int mask = 0; |
| 4651 | for (InterpFilters ifilter = EIGHTTAP_REGULAR; ifilter <= MULTITAP_SHARP; |
| 4652 | ++ifilter) { |
| 4653 | int last_score = get_interp_filter_selected(cm, LAST_FRAME, ifilter) * 30; |
| 4654 | if (ref_total[LAST_FRAME] && last_score <= ref_total[LAST_FRAME]) { |
| 4655 | int filter_score = |
| 4656 | get_interp_filter_selected(cm, LAST2_FRAME, ifilter) * 20 + |
| 4657 | get_interp_filter_selected(cm, LAST3_FRAME, ifilter) * 20 + |
| 4658 | get_interp_filter_selected(cm, GOLDEN_FRAME, ifilter) * 20 + |
| 4659 | get_interp_filter_selected(cm, BWDREF_FRAME, ifilter) * 10 + |
| 4660 | get_interp_filter_selected(cm, ALTREF2_FRAME, ifilter) * 10 + |
| 4661 | get_interp_filter_selected(cm, ALTREF_FRAME, ifilter) * 10; |
| 4662 | if (filter_score < ref_total_total) mask |= 1 << ifilter; |
| 4663 | } |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 4664 | } |
| 4665 | return mask; |
| 4666 | } |
| 4667 | |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 4668 | static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture, |
| 4669 | const YV12_BUFFER_CONFIG *last_picture, |
| 4670 | hash_table *last_hash_table) { |
| 4671 | aom_clear_system_state(); |
| 4672 | // check use hash ME |
| 4673 | int k; |
| 4674 | uint32_t hash_value_1; |
| 4675 | uint32_t hash_value_2; |
| 4676 | |
| 4677 | const int block_size = 8; |
| 4678 | const double threshold_current = 0.8; |
| 4679 | const double threshold_average = 0.95; |
| 4680 | const int max_history_size = 32; |
| 4681 | int T = 0; // total block |
| 4682 | int C = 0; // match with collocated block |
| 4683 | int S = 0; // smooth region but not match with collocated block |
| 4684 | int M = 0; // match with other block |
| 4685 | |
| 4686 | const int pic_width = cur_picture->y_width; |
| 4687 | const int pic_height = cur_picture->y_height; |
| 4688 | for (int i = 0; i + block_size <= pic_height; i += block_size) { |
| 4689 | for (int j = 0; j + block_size <= pic_width; j += block_size) { |
| 4690 | const int x_pos = j; |
| 4691 | const int y_pos = i; |
| 4692 | int match = 1; |
| 4693 | T++; |
| 4694 | |
| 4695 | // check whether collocated block match with current |
| 4696 | uint8_t *p_cur = cur_picture->y_buffer; |
| 4697 | uint8_t *p_ref = last_picture->y_buffer; |
| 4698 | int stride_cur = cur_picture->y_stride; |
| 4699 | int stride_ref = last_picture->y_stride; |
| 4700 | p_cur += (y_pos * stride_cur + x_pos); |
| 4701 | p_ref += (y_pos * stride_ref + x_pos); |
| 4702 | |
| 4703 | if (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 4704 | uint16_t *p16_cur = CONVERT_TO_SHORTPTR(p_cur); |
| 4705 | uint16_t *p16_ref = CONVERT_TO_SHORTPTR(p_ref); |
| 4706 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 4707 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 4708 | if (p16_cur[tmpX] != p16_ref[tmpX]) { |
| 4709 | match = 0; |
| 4710 | } |
| 4711 | } |
| 4712 | p16_cur += stride_cur; |
| 4713 | p16_ref += stride_ref; |
| 4714 | } |
| 4715 | } else { |
| 4716 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 4717 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 4718 | if (p_cur[tmpX] != p_ref[tmpX]) { |
| 4719 | match = 0; |
| 4720 | } |
| 4721 | } |
| 4722 | p_cur += stride_cur; |
| 4723 | p_ref += stride_ref; |
| 4724 | } |
| 4725 | } |
| 4726 | |
| 4727 | if (match) { |
| 4728 | C++; |
| 4729 | continue; |
| 4730 | } |
| 4731 | |
| 4732 | if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos, |
| 4733 | y_pos) || |
| 4734 | av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) { |
| 4735 | S++; |
| 4736 | continue; |
| 4737 | } |
| 4738 | |
| 4739 | av1_get_block_hash_value( |
| 4740 | cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur, |
| 4741 | block_size, &hash_value_1, &hash_value_2, |
| 4742 | (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH), &cpi->td.mb); |
| 4743 | // Hashing does not work for highbitdepth currently. |
| 4744 | // TODO(Roger): Make it work for highbitdepth. |
| 4745 | if (av1_use_hash_me(&cpi->common)) { |
| 4746 | if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) { |
| 4747 | M++; |
| 4748 | } |
| 4749 | } |
| 4750 | } |
| 4751 | } |
| 4752 | |
| 4753 | assert(T > 0); |
| 4754 | double csm_rate = ((double)(C + S + M)) / ((double)(T)); |
| 4755 | double m_rate = ((double)(M)) / ((double)(T)); |
| 4756 | |
| 4757 | cpi->csm_rate_array[cpi->rate_index] = csm_rate; |
| 4758 | cpi->m_rate_array[cpi->rate_index] = m_rate; |
| 4759 | |
| 4760 | cpi->rate_index = (cpi->rate_index + 1) % max_history_size; |
| 4761 | cpi->rate_size++; |
| 4762 | cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size); |
| 4763 | |
| 4764 | if (csm_rate < threshold_current) { |
| 4765 | return 0; |
| 4766 | } |
| 4767 | |
| 4768 | if (C == T) { |
| 4769 | return 1; |
| 4770 | } |
| 4771 | |
| 4772 | double csm_average = 0.0; |
| 4773 | double m_average = 0.0; |
| 4774 | |
| 4775 | for (k = 0; k < cpi->rate_size; k++) { |
| 4776 | csm_average += cpi->csm_rate_array[k]; |
| 4777 | m_average += cpi->m_rate_array[k]; |
| 4778 | } |
| 4779 | csm_average /= cpi->rate_size; |
| 4780 | m_average /= cpi->rate_size; |
| 4781 | |
| 4782 | if (csm_average < threshold_average) { |
| 4783 | return 0; |
| 4784 | } |
| 4785 | |
| 4786 | if (M > (T - C - S) / 3) { |
| 4787 | return 1; |
| 4788 | } |
| 4789 | |
| 4790 | if (csm_rate > 0.99 && m_rate > 0.01) { |
| 4791 | return 1; |
| 4792 | } |
| 4793 | |
| 4794 | if (csm_average + m_average > 1.01) { |
| 4795 | return 1; |
| 4796 | } |
| 4797 | |
| 4798 | return 0; |
| 4799 | } |
| 4800 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 4801 | // Refresh reference frame buffers according to refresh_frame_flags. |
| 4802 | static void refresh_reference_frames(AV1_COMP *cpi) { |
| 4803 | AV1_COMMON *const cm = &cpi->common; |
| 4804 | // All buffers are refreshed for shown keyframes and S-frames. |
| 4805 | |
| 4806 | for (int ref_frame = 0; ref_frame < REF_FRAMES; ref_frame++) { |
| 4807 | if (((cm->current_frame.refresh_frame_flags >> ref_frame) & 1) == 1) { |
| 4808 | assign_frame_buffer_p(&cm->ref_frame_map[ref_frame], cm->cur_frame); |
| 4809 | } |
| 4810 | } |
| 4811 | } |
| 4812 | |
| 4813 | static int encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, |
| 4814 | uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4815 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4816 | SequenceHeader *const seq_params = &cm->seq_params; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4817 | CurrentFrame *const current_frame = &cm->current_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4818 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4819 | struct segmentation *const seg = &cm->seg; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 4820 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4821 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4822 | start_timing(cpi, encode_frame_to_data_rate_time); |
| 4823 | #endif |
| 4824 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 4825 | // frame type has been decided outside of this function call |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4826 | cm->cur_frame->frame_type = current_frame->frame_type; |
Debargha Mukherjee | 07a7c1f | 2018-03-21 17:39:13 -0700 | [diff] [blame] | 4827 | |
Yunqing Wang | 9612d55 | 2018-05-15 14:58:30 -0700 | [diff] [blame] | 4828 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 4829 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Yunqing Wang | 9612d55 | 2018-05-15 14:58:30 -0700 | [diff] [blame] | 4830 | |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 4831 | cm->allow_ref_frame_mvs &= frame_might_allow_ref_frame_mvs(cm); |
Yunqing Wang | d48fb16 | 2018-06-15 10:55:28 -0700 | [diff] [blame] | 4832 | // cm->allow_ref_frame_mvs needs to be written into the frame header while |
| 4833 | // cm->large_scale_tile is 1, therefore, "cm->large_scale_tile=1" case is |
| 4834 | // separated from frame_might_allow_ref_frame_mvs(). |
| 4835 | cm->allow_ref_frame_mvs &= !cm->large_scale_tile; |
| 4836 | |
Debargha Mukherjee | 1d7217e | 2018-03-26 13:32:13 -0700 | [diff] [blame] | 4837 | cm->allow_warped_motion = |
Debargha Mukherjee | a5b810a | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 4838 | cpi->oxcf.allow_warped_motion && frame_might_allow_warped_motion(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4839 | |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 4840 | cm->last_frame_type = current_frame->frame_type; |
| 4841 | if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search) |
| 4842 | cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi); |
| 4843 | |
Yunqing Wang | c3e21ec | 2019-02-28 16:29:27 -0800 | [diff] [blame] | 4844 | cpi->two_pass_partition_search = cpi->sf.two_pass_partition_search && |
| 4845 | !cpi->partition_search_skippable_frame; |
Yunqing Wang | c3e21ec | 2019-02-28 16:29:27 -0800 | [diff] [blame] | 4846 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 4847 | if (encode_show_existing_frame(cm)) { |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4848 | restore_coding_context(cpi); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4849 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4850 | finalize_encoded_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4851 | // Build the bitstream |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 4852 | int largest_tile_id = 0; // Output from bitstream: unused here |
| 4853 | if (av1_pack_bitstream(cpi, dest, size, &largest_tile_id) != AOM_CODEC_OK) |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4854 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4855 | |
David Turner | 9031186 | 2018-11-29 13:34:36 +0000 | [diff] [blame] | 4856 | if (seq_params->frame_id_numbers_present_flag && |
| 4857 | current_frame->frame_type == KEY_FRAME) { |
| 4858 | // Displaying a forward key-frame, so reset the ref buffer IDs |
| 4859 | int display_frame_id = cm->ref_frame_id[cpi->existing_fb_idx_to_show]; |
| 4860 | for (int i = 0; i < REF_FRAMES; i++) |
| 4861 | cm->ref_frame_id[i] = display_frame_id; |
| 4862 | } |
| 4863 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 4864 | cpi->seq_params_locked = 1; |
| 4865 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4866 | #if DUMP_RECON_FRAMES == 1 |
| 4867 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 4868 | dump_filtered_recon_frames(cpi); |
| 4869 | #endif // DUMP_RECON_FRAMES |
| 4870 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 4871 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 4872 | // for the purpose to verify no mismatch between encoder and decoder. |
| 4873 | if (cm->show_frame) cpi->last_show_frame_buf = cm->cur_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4874 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 4875 | refresh_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4876 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4877 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 4878 | // to do post-encoding update accordingly. |
| 4879 | if (cpi->rc.is_src_frame_alt_ref) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4880 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4881 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4882 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4883 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4884 | ++current_frame->frame_number; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4885 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4886 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4887 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4888 | |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 4889 | // Work out whether to force_integer_mv this frame |
| 4890 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools && |
| 4891 | !frame_is_intra_only(cm)) { |
| 4892 | if (cpi->common.seq_params.force_integer_mv == 2) { |
| 4893 | // Adaptive mode: see what previous frame encoded did |
| 4894 | if (cpi->unscaled_last_source != NULL) { |
| 4895 | cm->cur_frame_force_integer_mv = |
| 4896 | is_integer_mv(cpi, cpi->source, cpi->unscaled_last_source, |
| 4897 | cpi->previous_hash_table); |
| 4898 | } else { |
| 4899 | cpi->common.cur_frame_force_integer_mv = 0; |
| 4900 | } |
| 4901 | } else { |
| 4902 | cpi->common.cur_frame_force_integer_mv = |
| 4903 | cpi->common.seq_params.force_integer_mv; |
| 4904 | } |
| 4905 | } else { |
| 4906 | cpi->common.cur_frame_force_integer_mv = 0; |
| 4907 | } |
| 4908 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4909 | // Set default state for segment based loop filter update flags. |
| 4910 | cm->lf.mode_ref_delta_update = 0; |
| 4911 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4912 | // Set various flags etc to special state if it is a key frame. |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 4913 | if (frame_is_intra_only(cm) || frame_is_sframe(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4914 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4915 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4916 | |
| 4917 | // If segmentation is enabled force a map update for key frames. |
| 4918 | if (seg->enabled) { |
| 4919 | seg->update_map = 1; |
| 4920 | seg->update_data = 1; |
| 4921 | } |
| 4922 | |
| 4923 | // The alternate reference frame cannot be active for a key frame. |
| 4924 | cpi->rc.source_alt_ref_active = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4925 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4926 | if (cpi->oxcf.mtu == 0) { |
| 4927 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 4928 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 4929 | // Use a default value for the purposes of weighting costs in probability |
| 4930 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4931 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 4932 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4933 | |
| 4934 | // For 1 pass CBR, check if we are dropping this frame. |
| 4935 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4936 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4937 | current_frame->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4938 | if (av1_rc_drop_frame(cpi)) { |
| 4939 | av1_rc_postencode_update_drop_frame(cpi); |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 4940 | release_scaled_references(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4941 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4942 | } |
| 4943 | } |
| 4944 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4945 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4946 | |
| 4947 | #if CONFIG_INTERNAL_STATS |
| 4948 | memset(cpi->mode_chosen_counts, 0, |
| 4949 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 4950 | #endif |
| 4951 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4952 | if (seq_params->frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4953 | /* Non-normative definition of current_frame_id ("frame counter" with |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 4954 | * wraparound) */ |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4955 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4956 | int lsb, msb; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 4957 | /* quasi-random initialization of current_frame_id for a key frame */ |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4958 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 4959 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 4960 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4961 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4962 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 4963 | msb = cpi->source->y_buffer[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4964 | } |
David Turner | 760a2f4 | 2018-12-07 15:25:36 +0000 | [diff] [blame] | 4965 | cm->current_frame_id = |
| 4966 | ((msb << 8) + lsb) % (1 << seq_params->frame_id_length); |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 4967 | |
| 4968 | // S_frame is meant for stitching different streams of different |
| 4969 | // resolutions together, so current_frame_id must be the |
| 4970 | // same across different streams of the same content current_frame_id |
| 4971 | // should be the same and not random. 0x37 is a chosen number as start |
| 4972 | // point |
| 4973 | if (cpi->oxcf.sframe_enabled) cm->current_frame_id = 0x37; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4974 | } else { |
| 4975 | cm->current_frame_id = |
David Turner | 760a2f4 | 2018-12-07 15:25:36 +0000 | [diff] [blame] | 4976 | (cm->current_frame_id + 1 + (1 << seq_params->frame_id_length)) % |
| 4977 | (1 << seq_params->frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4978 | } |
| 4979 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4980 | |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 4981 | switch (cpi->oxcf.cdf_update_mode) { |
| 4982 | case 0: // No CDF update for any frames(4~6% compression loss). |
| 4983 | cm->disable_cdf_update = 1; |
| 4984 | break; |
| 4985 | case 1: // Enable CDF update for all frames. |
| 4986 | cm->disable_cdf_update = 0; |
| 4987 | break; |
| 4988 | case 2: |
| 4989 | // Strategically determine at which frames to do CDF update. |
| 4990 | // Currently only enable CDF update for all-intra and no-show frames(1.5% |
| 4991 | // compression loss). |
| 4992 | // TODO(huisu@google.com): design schemes for various trade-offs between |
| 4993 | // compression quality and decoding speed. |
Hui Su | b1b76b3 | 2018-02-27 15:24:48 -0800 | [diff] [blame] | 4994 | cm->disable_cdf_update = |
| 4995 | (frame_is_intra_only(cm) || !cm->show_frame) ? 0 : 1; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 4996 | break; |
| 4997 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4998 | cm->timing_info_present &= !seq_params->reduced_still_picture_hdr; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 4999 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5000 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5001 | start_timing(cpi, encode_with_recode_loop_time); |
| 5002 | #endif |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame^] | 5003 | |
| 5004 | if (cpi->oxcf.pass == 2 && cpi->oxcf.enable_tpl_model == 2 && |
| 5005 | current_frame->frame_type == INTER_FRAME) { |
| 5006 | if (!cm->show_frame) { |
| 5007 | assert(cpi->tpl_model_pass == 0); |
| 5008 | cpi->tpl_model_pass = 1; |
| 5009 | } |
| 5010 | } |
| 5011 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5012 | if (encode_with_recode_loop(cpi, size, dest) != AOM_CODEC_OK) |
| 5013 | return AOM_CODEC_ERROR; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5014 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5015 | end_timing(cpi, encode_with_recode_loop_time); |
| 5016 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5017 | |
| 5018 | #ifdef OUTPUT_YUV_SKINMAP |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5019 | if (cpi->common.current_frame.frame_number > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5020 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5021 | } |
| 5022 | #endif // OUTPUT_YUV_SKINMAP |
| 5023 | |
| 5024 | // Special case code to reduce pulsing when key frames are forced at a |
| 5025 | // fixed interval. Note the reconstruction error if it is the frame before |
| 5026 | // the force key frame |
| 5027 | if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5028 | if (seq_params->use_highbitdepth) { |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 5029 | cpi->ambient_err = aom_highbd_get_y_sse(cpi->source, &cm->cur_frame->buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5030 | } else { |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 5031 | cpi->ambient_err = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5032 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5033 | } |
| 5034 | |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5035 | cm->cur_frame->buf.color_primaries = seq_params->color_primaries; |
| 5036 | cm->cur_frame->buf.transfer_characteristics = |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5037 | seq_params->transfer_characteristics; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5038 | cm->cur_frame->buf.matrix_coefficients = seq_params->matrix_coefficients; |
| 5039 | cm->cur_frame->buf.monochrome = seq_params->monochrome; |
| 5040 | cm->cur_frame->buf.chroma_sample_position = |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5041 | seq_params->chroma_sample_position; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5042 | cm->cur_frame->buf.color_range = seq_params->color_range; |
| 5043 | cm->cur_frame->buf.render_width = cm->render_width; |
| 5044 | cm->cur_frame->buf.render_height = cm->render_height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5045 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5046 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 5047 | // off. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5048 | |
| 5049 | // Pick the loop filter level for the frame. |
Cheng Chen | 68dc914 | 2018-05-02 17:46:28 -0700 | [diff] [blame] | 5050 | if (!cm->allow_intrabc) { |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 5051 | loopfilter_frame(cpi, cm); |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5052 | } else { |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5053 | cm->lf.filter_level[0] = 0; |
| 5054 | cm->lf.filter_level[1] = 0; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 5055 | cm->cdef_info.cdef_bits = 0; |
| 5056 | cm->cdef_info.cdef_strengths[0] = 0; |
| 5057 | cm->cdef_info.nb_cdef_strengths = 1; |
| 5058 | cm->cdef_info.cdef_uv_strengths[0] = 0; |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5059 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 5060 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 5061 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5062 | } |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 5063 | |
| 5064 | // TODO(debargha): Fix mv search range on encoder side |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5065 | // aom_extend_frame_inner_borders(&cm->cur_frame->buf, av1_num_planes(cm)); |
| 5066 | aom_extend_frame_borders(&cm->cur_frame->buf, av1_num_planes(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5067 | |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 5068 | #ifdef OUTPUT_YUV_REC |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5069 | aom_write_one_yuv_frame(cm, &cm->cur_frame->buf); |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 5070 | #endif |
| 5071 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 5072 | finalize_encoded_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5073 | // Build the bitstream |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 5074 | int largest_tile_id = 0; // Output from pack_bitstream |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5075 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5076 | start_timing(cpi, av1_pack_bitstream_final_time); |
| 5077 | #endif |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 5078 | if (av1_pack_bitstream(cpi, dest, size, &largest_tile_id) != AOM_CODEC_OK) |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5079 | return AOM_CODEC_ERROR; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5080 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5081 | end_timing(cpi, av1_pack_bitstream_final_time); |
| 5082 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5083 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 5084 | cpi->seq_params_locked = 1; |
| 5085 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 5086 | // Update reference frame ids for reference frames this frame will overwrite |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5087 | if (seq_params->frame_id_numbers_present_flag) { |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 5088 | for (int i = 0; i < REF_FRAMES; i++) { |
| 5089 | if ((current_frame->refresh_frame_flags >> i) & 1) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5090 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 5091 | } |
| 5092 | } |
| 5093 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5094 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5095 | #if DUMP_RECON_FRAMES == 1 |
| 5096 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5097 | dump_filtered_recon_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5098 | #endif // DUMP_RECON_FRAMES |
| 5099 | |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 5100 | if (cm->seg.enabled) { |
| 5101 | if (cm->seg.update_map) { |
| 5102 | update_reference_segmentation_map(cpi); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 5103 | } else if (cm->last_frame_seg_map) { |
David Turner | b757ce0 | 2018-11-12 15:01:28 +0000 | [diff] [blame] | 5104 | memcpy(cm->cur_frame->seg_map, cm->last_frame_seg_map, |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 5105 | cm->mi_cols * cm->mi_rows * sizeof(uint8_t)); |
| 5106 | } |
| 5107 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5108 | |
| 5109 | if (frame_is_intra_only(cm) == 0) { |
| 5110 | release_scaled_references(cpi); |
| 5111 | } |
| 5112 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 5113 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 5114 | // for the purpose to verify no mismatch between encoder and decoder. |
| 5115 | if (cm->show_frame) cpi->last_show_frame_buf = cm->cur_frame; |
| 5116 | |
| 5117 | refresh_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5118 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5119 | #if CONFIG_ENTROPY_STATS |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 5120 | av1_accumulate_frame_counts(&aggregate_fc, &cpi->counts); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5121 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5122 | |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 5123 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 5124 | *cm->fc = cpi->tile_data[largest_tile_id].tctx; |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 5125 | av1_reset_cdf_symbol_counters(cm->fc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5126 | } |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 5127 | if (!cm->large_scale_tile) { |
| 5128 | cm->cur_frame->frame_context = *cm->fc; |
| 5129 | } |
| 5130 | #define EXT_TILE_DEBUG 0 |
| 5131 | #if EXT_TILE_DEBUG |
| 5132 | if (cm->large_scale_tile && oxcf->pass == 2) { |
| 5133 | char fn[20] = "./fc"; |
| 5134 | fn[4] = current_frame->frame_number / 100 + '0'; |
| 5135 | fn[5] = (current_frame->frame_number % 100) / 10 + '0'; |
| 5136 | fn[6] = (current_frame->frame_number % 10) + '0'; |
| 5137 | fn[7] = '\0'; |
| 5138 | av1_print_frame_contexts(cm->fc, fn); |
| 5139 | } |
| 5140 | #endif // EXT_TILE_DEBUG |
| 5141 | #undef EXT_TILE_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5142 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5143 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5144 | end_timing(cpi, encode_frame_to_data_rate_time); |
| 5145 | |
| 5146 | // Print out timing information. |
| 5147 | int i; |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 5148 | fprintf(stderr, "\n Frame number: %d, Frame type: %s, Show Frame: %d\n", |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5149 | cm->current_frame.frame_number, |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 5150 | get_frame_type_enum(cm->current_frame.frame_type), cm->show_frame); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5151 | for (i = 0; i < kTimingComponents; i++) { |
| 5152 | cpi->component_time[i] += cpi->frame_component_time[i]; |
| 5153 | fprintf(stderr, " %s: %" PRId64 " us (total: %" PRId64 " us)\n", |
| 5154 | get_component_name(i), cpi->frame_component_time[i], |
| 5155 | cpi->component_time[i]); |
| 5156 | cpi->frame_component_time[i] = 0; |
| 5157 | } |
| 5158 | #endif |
| 5159 | |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 5160 | cm->last_frame_type = current_frame->frame_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5161 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5162 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5163 | |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 5164 | // Store encoded frame's hash table for is_integer_mv() next time |
| 5165 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
| 5166 | cpi->previous_hash_table = &cm->cur_frame->hash_table; |
| 5167 | } |
| 5168 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5169 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 5170 | // filter deltas. |
| 5171 | cm->seg.update_map = 0; |
| 5172 | cm->seg.update_data = 0; |
| 5173 | cm->lf.mode_ref_delta_update = 0; |
| 5174 | |
Wei-Ting Lin | fb7dc06 | 2018-06-28 18:26:13 -0700 | [diff] [blame] | 5175 | // A droppable frame might not be shown but it always |
| 5176 | // takes a space in the gf group. Therefore, even when |
| 5177 | // it is not shown, we still need update the count down. |
| 5178 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5179 | if (cm->show_frame) { |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5180 | // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that |
| 5181 | // are |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5182 | // being used as reference. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5183 | swap_mi_and_prev_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5184 | // Don't increment frame counters if this was an altref buffer |
| 5185 | // update not a real frame |
Wei-Ting Lin | 96ee0eb | 2018-06-22 15:27:22 -0700 | [diff] [blame] | 5186 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5187 | ++current_frame->frame_number; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5188 | } |
| 5189 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5190 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5191 | } |
| 5192 | |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 5193 | int av1_encode(AV1_COMP *const cpi, uint8_t *const dest, |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 5194 | const EncodeFrameInput *const frame_input, |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 5195 | const EncodeFrameParams *const frame_params, |
| 5196 | EncodeFrameResults *const frame_results) { |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 5197 | AV1_COMMON *const cm = &cpi->common; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 5198 | CurrentFrame *const current_frame = &cm->current_frame; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 5199 | |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 5200 | cpi->unscaled_source = frame_input->source; |
| 5201 | cpi->source = frame_input->source; |
| 5202 | cpi->unscaled_last_source = frame_input->last_source; |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 5203 | |
David Turner | 6e8b4d9 | 2019-02-18 15:01:33 +0000 | [diff] [blame] | 5204 | current_frame->refresh_frame_flags = frame_params->refresh_frame_flags; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 5205 | cm->error_resilient_mode = frame_params->error_resilient_mode; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 5206 | cm->primary_ref_frame = frame_params->primary_ref_frame; |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 5207 | cm->current_frame.frame_type = frame_params->frame_type; |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 5208 | cm->show_frame = frame_params->show_frame; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 5209 | cpi->ref_frame_flags = frame_params->ref_frame_flags; |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 5210 | cpi->speed = frame_params->speed; |
David Turner | e86ee0d | 2019-02-18 17:16:28 +0000 | [diff] [blame] | 5211 | cm->show_existing_frame = frame_params->show_existing_frame; |
| 5212 | cpi->existing_fb_idx_to_show = frame_params->existing_fb_idx_to_show; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 5213 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 5214 | memcpy(cm->remapped_ref_idx, frame_params->remapped_ref_idx, |
| 5215 | REF_FRAMES * sizeof(*cm->remapped_ref_idx)); |
| 5216 | |
David Turner | fe3aecb | 2019-02-06 14:42:42 +0000 | [diff] [blame] | 5217 | cpi->refresh_last_frame = frame_params->refresh_last_frame; |
| 5218 | cpi->refresh_golden_frame = frame_params->refresh_golden_frame; |
| 5219 | cpi->refresh_bwd_ref_frame = frame_params->refresh_bwd_ref_frame; |
| 5220 | cpi->refresh_alt2_ref_frame = frame_params->refresh_alt2_ref_frame; |
| 5221 | cpi->refresh_alt_ref_frame = frame_params->refresh_alt_ref_frame; |
| 5222 | |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 5223 | if (current_frame->frame_type == KEY_FRAME && cm->show_frame) |
| 5224 | current_frame->frame_number = 0; |
| 5225 | |
| 5226 | if (cm->show_existing_frame) { |
| 5227 | current_frame->order_hint = cm->cur_frame->order_hint; |
| 5228 | } else { |
| 5229 | current_frame->order_hint = |
| 5230 | current_frame->frame_number + frame_params->order_offset; |
| 5231 | current_frame->order_hint %= |
| 5232 | (1 << (cm->seq_params.order_hint_info.order_hint_bits_minus_1 + 1)); |
| 5233 | } |
| 5234 | |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 5235 | if (cpi->oxcf.pass == 1) { |
| 5236 | av1_first_pass(cpi, frame_input->ts_duration); |
| 5237 | } else if (cpi->oxcf.pass == 0 || cpi->oxcf.pass == 2) { |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 5238 | if (encode_frame_to_data_rate(cpi, &frame_results->size, dest) != |
| 5239 | AOM_CODEC_OK) { |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 5240 | return AOM_CODEC_ERROR; |
| 5241 | } |
| 5242 | } else { |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 5243 | return AOM_CODEC_ERROR; |
| 5244 | } |
| 5245 | |
| 5246 | return AOM_CODEC_OK; |
| 5247 | } |
| 5248 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 5249 | #if CONFIG_DENOISE |
| 5250 | static int apply_denoise_2d(AV1_COMP *cpi, YV12_BUFFER_CONFIG *sd, |
| 5251 | int block_size, float noise_level, |
| 5252 | int64_t time_stamp, int64_t end_time) { |
| 5253 | AV1_COMMON *const cm = &cpi->common; |
| 5254 | if (!cpi->denoise_and_model) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5255 | cpi->denoise_and_model = aom_denoise_and_model_alloc( |
| 5256 | cm->seq_params.bit_depth, block_size, noise_level); |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 5257 | if (!cpi->denoise_and_model) { |
| 5258 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 5259 | "Error allocating denoise and model"); |
| 5260 | return -1; |
| 5261 | } |
| 5262 | } |
| 5263 | if (!cpi->film_grain_table) { |
| 5264 | cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table)); |
| 5265 | if (!cpi->film_grain_table) { |
| 5266 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 5267 | "Error allocating grain table"); |
| 5268 | return -1; |
| 5269 | } |
| 5270 | memset(cpi->film_grain_table, 0, sizeof(*cpi->film_grain_table)); |
| 5271 | } |
| 5272 | if (aom_denoise_and_model_run(cpi->denoise_and_model, sd, |
| 5273 | &cm->film_grain_params)) { |
| 5274 | if (cm->film_grain_params.apply_grain) { |
| 5275 | aom_film_grain_table_append(cpi->film_grain_table, time_stamp, end_time, |
| 5276 | &cm->film_grain_params); |
| 5277 | } |
| 5278 | } |
| 5279 | return 0; |
| 5280 | } |
| 5281 | #endif |
| 5282 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 5283 | int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5284 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 5285 | int64_t end_time) { |
| 5286 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5287 | const SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5288 | int res = 0; |
| 5289 | const int subsampling_x = sd->subsampling_x; |
| 5290 | const int subsampling_y = sd->subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5291 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5292 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5293 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5294 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5295 | #if CONFIG_INTERNAL_STATS |
| 5296 | struct aom_usec_timer timer; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5297 | aom_usec_timer_start(&timer); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5298 | #endif |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 5299 | #if CONFIG_DENOISE |
| 5300 | if (cpi->oxcf.noise_level > 0) |
| 5301 | if (apply_denoise_2d(cpi, sd, cpi->oxcf.noise_block_size, |
| 5302 | cpi->oxcf.noise_level, time_stamp, end_time) < 0) |
| 5303 | res = -1; |
| 5304 | #endif // CONFIG_DENOISE |
| 5305 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5306 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5307 | use_highbitdepth, frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5308 | res = -1; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5309 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5310 | aom_usec_timer_mark(&timer); |
| 5311 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5312 | #endif |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5313 | if ((seq_params->profile == PROFILE_0) && !seq_params->monochrome && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5314 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5315 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5316 | "Non-4:2:0 color format requires profile 1 or 2"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5317 | res = -1; |
| 5318 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5319 | if ((seq_params->profile == PROFILE_1) && |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5320 | !(subsampling_x == 0 && subsampling_y == 0)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5321 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5322 | "Profile 1 requires 4:4:4 color format"); |
| 5323 | res = -1; |
| 5324 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5325 | if ((seq_params->profile == PROFILE_2) && |
| 5326 | (seq_params->bit_depth <= AOM_BITS_10) && |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5327 | !(subsampling_x == 1 && subsampling_y == 0)) { |
| 5328 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
| 5329 | "Profile 2 bit-depth < 10 requires 4:2:2 color format"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5330 | res = -1; |
| 5331 | } |
| 5332 | |
| 5333 | return res; |
| 5334 | } |
| 5335 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5336 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5337 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 5338 | const unsigned char *img2, int img2_pitch, |
| 5339 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5340 | |
| 5341 | static void adjust_image_stat(double y, double u, double v, double all, |
| 5342 | ImageStat *s) { |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 5343 | s->stat[STAT_Y] += y; |
| 5344 | s->stat[STAT_U] += u; |
| 5345 | s->stat[STAT_V] += v; |
| 5346 | s->stat[STAT_ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5347 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5348 | } |
| 5349 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5350 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5351 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5352 | double samples = 0.0; |
| 5353 | uint32_t in_bit_depth = 8; |
| 5354 | uint32_t bit_depth = 8; |
| 5355 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5356 | #if CONFIG_INTER_STATS_ONLY |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5357 | if (cm->current_frame.frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5358 | #endif |
| 5359 | cpi->bytes += frame_bytes; |
| 5360 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5361 | if (cm->seq_params.use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5362 | in_bit_depth = cpi->oxcf.input_bit_depth; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5363 | bit_depth = cm->seq_params.bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5364 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5365 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5366 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5367 | const YV12_BUFFER_CONFIG *recon = &cpi->common.cur_frame->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5368 | double y, u, v, frame_all; |
| 5369 | |
| 5370 | cpi->count++; |
| 5371 | if (cpi->b_calculate_psnr) { |
| 5372 | PSNR_STATS psnr; |
| 5373 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5374 | aom_clear_system_state(); |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5375 | // TODO(yaowu): unify these two versions into one. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5376 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5377 | |
| 5378 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 5379 | &cpi->psnr); |
| 5380 | cpi->total_sq_error += psnr.sse[0]; |
| 5381 | cpi->total_samples += psnr.samples[0]; |
| 5382 | samples = psnr.samples[0]; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5383 | // TODO(yaowu): unify these two versions into one. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5384 | if (cm->seq_params.use_highbitdepth) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5385 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5386 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5387 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5388 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5389 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5390 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5391 | cpi->summed_quality += frame_ssim2 * weight; |
| 5392 | cpi->summed_weights += weight; |
| 5393 | |
| 5394 | #if 0 |
| 5395 | { |
| 5396 | FILE *f = fopen("q_used.stt", "a"); |
Zoe Liu | ee202be | 2017-11-17 12:14:33 -0800 | [diff] [blame] | 5397 | double y2 = psnr.psnr[1]; |
| 5398 | double u2 = psnr.psnr[2]; |
| 5399 | double v2 = psnr.psnr[3]; |
| 5400 | double frame_psnr2 = psnr.psnr[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5401 | fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5402 | cm->current_frame.frame_number, y2, u2, v2, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5403 | frame_psnr2, frame_ssim2); |
| 5404 | fclose(f); |
| 5405 | } |
| 5406 | #endif |
| 5407 | } |
| 5408 | if (cpi->b_calculate_blockiness) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5409 | if (!cm->seq_params.use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5410 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5411 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 5412 | recon->y_stride, orig->y_width, orig->y_height); |
| 5413 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5414 | cpi->total_blockiness += frame_blockiness; |
| 5415 | } |
| 5416 | |
| 5417 | if (cpi->b_calculate_consistency) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5418 | if (!cm->seq_params.use_highbitdepth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5419 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5420 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 5421 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 5422 | |
| 5423 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 5424 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5425 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5426 | if (consistency > 0.0) |
| 5427 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5428 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5429 | cpi->total_inconsistency += this_inconsistency; |
| 5430 | } |
| 5431 | } |
| 5432 | } |
| 5433 | |
| 5434 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5435 | aom_calc_fastssim(orig, recon, &y, &u, &v, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5436 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5437 | frame_all = aom_psnrhvs(orig, recon, &y, &u, &v, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5438 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 5439 | } |
| 5440 | } |
| 5441 | #endif // CONFIG_INTERNAL_STATS |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 5442 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 5443 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 5444 | int64_t *time_end, int flush, |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 5445 | const aom_rational64_t *timestamp_ratio) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5446 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 5447 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5448 | |
| 5449 | #if CONFIG_BITSTREAM_DEBUG |
| 5450 | assert(cpi->oxcf.max_threads == 0 && |
| 5451 | "bitstream debug tool does not support multithreading"); |
| 5452 | bitstream_queue_record_write(); |
Yaowu Xu | 63f2ea3 | 2019-04-29 10:47:42 -0700 | [diff] [blame] | 5453 | aom_bitstream_queue_set_frame_write(cm->current_frame.frame_number * 2 + |
| 5454 | cm->show_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5455 | #endif |
| 5456 | |
Sarah Parker | 740e839 | 2019-01-23 15:47:53 -0800 | [diff] [blame] | 5457 | // Indicates whether or not to use an adaptive quantize b rather than |
| 5458 | // the traditional version |
| 5459 | cm->use_quant_b_adapt = cpi->oxcf.quant_b_adapt; |
| 5460 | |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 5461 | cm->showable_frame = 0; |
David Turner | e43f7fe | 2019-01-15 14:58:00 +0000 | [diff] [blame] | 5462 | *size = 0; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5463 | #if CONFIG_INTERNAL_STATS |
| 5464 | struct aom_usec_timer cmptimer; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5465 | aom_usec_timer_start(&cmptimer); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5466 | #endif |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5467 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5468 | |
Debargha Mukherjee | ba7b8fe | 2018-03-15 23:10:07 -0700 | [diff] [blame] | 5469 | // Normal defaults |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5470 | cm->refresh_frame_context = oxcf->frame_parallel_decoding_mode |
| 5471 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 5472 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 5473 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 5474 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5475 | |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 5476 | // Initialize fields related to forward keyframes |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 5477 | cpi->no_show_kf = 0; |
Zoe Liu | b499120 | 2017-12-21 15:31:06 -0800 | [diff] [blame] | 5478 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 5479 | if (assign_cur_frame_new_fb(cm) == NULL) return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5480 | |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 5481 | const int result = |
| 5482 | av1_encode_strategy(cpi, size, dest, frame_flags, time_stamp, time_end, |
| 5483 | timestamp_ratio, flush); |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 5484 | if (result != AOM_CODEC_OK && result != -1) { |
David Turner | 1539bb0 | 2019-01-24 15:28:13 +0000 | [diff] [blame] | 5485 | return AOM_CODEC_ERROR; |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 5486 | } else if (result == -1) { |
| 5487 | // Returning -1 indicates no frame encoded; more input is required |
| 5488 | return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5489 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5490 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5491 | aom_usec_timer_mark(&cmptimer); |
| 5492 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 5493 | #endif // CONFIG_INTERNAL_STATS |
David Turner | c4bf8c7 | 2019-01-15 13:14:37 +0000 | [diff] [blame] | 5494 | if (cpi->b_calculate_psnr) { |
| 5495 | if (cm->show_existing_frame || (oxcf->pass != 1 && cm->show_frame)) { |
| 5496 | generate_psnr_packet(cpi); |
| 5497 | } |
| 5498 | } |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 5499 | |
| 5500 | if (cpi->keep_level_stats && oxcf->pass != 1) { |
| 5501 | // Initialize level info. at the beginning of each sequence. |
| 5502 | if (cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) { |
| 5503 | av1_init_level_info(cpi->level_info); |
| 5504 | } |
kyslov | abeeb7c | 2019-03-06 18:35:04 -0800 | [diff] [blame] | 5505 | av1_update_level_info(cpi, *size, *time_stamp, *time_end); |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 5506 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5507 | |
| 5508 | #if CONFIG_INTERNAL_STATS |
| 5509 | if (oxcf->pass != 1) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5510 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5511 | } |
| 5512 | #endif // CONFIG_INTERNAL_STATS |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 5513 | #if CONFIG_SPEED_STATS |
David Turner | c4bf8c7 | 2019-01-15 13:14:37 +0000 | [diff] [blame] | 5514 | if (cpi->oxcf.pass != 1 && !cm->show_existing_frame) { |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 5515 | cpi->tx_search_count += cpi->td.mb.tx_search_count; |
| 5516 | cpi->td.mb.tx_search_count = 0; |
| 5517 | } |
| 5518 | #endif // CONFIG_SPEED_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5519 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5520 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5521 | |
| 5522 | return 0; |
| 5523 | } |
| 5524 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5525 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 5526 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5527 | if (!cm->show_frame) { |
| 5528 | return -1; |
| 5529 | } else { |
| 5530 | int ret; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5531 | if (cm->cur_frame != NULL) { |
| 5532 | *dest = cm->cur_frame->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5533 | dest->y_width = cm->width; |
| 5534 | dest->y_height = cm->height; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5535 | dest->uv_width = cm->width >> cm->seq_params.subsampling_x; |
| 5536 | dest->uv_height = cm->height >> cm->seq_params.subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5537 | ret = 0; |
| 5538 | } else { |
| 5539 | ret = -1; |
| 5540 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5541 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5542 | return ret; |
| 5543 | } |
| 5544 | } |
| 5545 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5546 | int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 5547 | if (cpi->last_show_frame_buf == NULL) return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5548 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 5549 | *frame = cpi->last_show_frame_buf->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5550 | return 0; |
| 5551 | } |
| 5552 | |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 5553 | static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a, |
| 5554 | const YV12_BUFFER_CONFIG *b) { |
| 5555 | return a->y_height == b->y_height && a->y_width == b->y_width && |
| 5556 | a->uv_height == b->uv_height && a->uv_width == b->uv_width && |
| 5557 | a->y_stride == b->y_stride && a->uv_stride == b->uv_stride && |
| 5558 | a->border == b->border && |
| 5559 | (a->flags & YV12_FLAG_HIGHBITDEPTH) == |
| 5560 | (b->flags & YV12_FLAG_HIGHBITDEPTH); |
| 5561 | } |
| 5562 | |
Yunqing Wang | 93b18f3 | 2018-06-08 21:08:29 -0700 | [diff] [blame] | 5563 | aom_codec_err_t av1_copy_new_frame_enc(AV1_COMMON *cm, |
| 5564 | YV12_BUFFER_CONFIG *new_frame, |
| 5565 | YV12_BUFFER_CONFIG *sd) { |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 5566 | const int num_planes = av1_num_planes(cm); |
| 5567 | if (!equal_dimensions_and_border(new_frame, sd)) |
| 5568 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, |
| 5569 | "Incorrect buffer dimensions"); |
| 5570 | else |
| 5571 | aom_yv12_copy_frame(new_frame, sd, num_planes); |
| 5572 | |
| 5573 | return cm->error.error_code; |
| 5574 | } |
| 5575 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5576 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 5577 | AOM_SCALING vert_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5578 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 5579 | |
| 5580 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 5581 | |
| 5582 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 5583 | Scale2Ratio(vert_mode, &vr, &vs); |
| 5584 | |
| 5585 | // always go to the next whole number |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5586 | cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 5587 | cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5588 | |
| 5589 | return 0; |
| 5590 | } |
| 5591 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5592 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5593 | |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 5594 | int av1_convert_sect5obus_to_annexb(uint8_t *buffer, size_t *frame_size) { |
| 5595 | size_t output_size = 0; |
| 5596 | size_t total_bytes_read = 0; |
| 5597 | size_t remaining_size = *frame_size; |
| 5598 | uint8_t *buff_ptr = buffer; |
| 5599 | |
| 5600 | // go through each OBUs |
| 5601 | while (total_bytes_read < *frame_size) { |
| 5602 | uint8_t saved_obu_header[2]; |
| 5603 | uint64_t obu_payload_size; |
| 5604 | size_t length_of_payload_size; |
| 5605 | size_t length_of_obu_size; |
| 5606 | uint32_t obu_header_size = (buff_ptr[0] >> 2) & 0x1 ? 2 : 1; |
| 5607 | size_t obu_bytes_read = obu_header_size; // bytes read for current obu |
| 5608 | |
| 5609 | // save the obu header (1 or 2 bytes) |
| 5610 | memmove(saved_obu_header, buff_ptr, obu_header_size); |
| 5611 | // clear the obu_has_size_field |
| 5612 | saved_obu_header[0] = saved_obu_header[0] & (~0x2); |
| 5613 | |
| 5614 | // get the payload_size and length of payload_size |
| 5615 | if (aom_uleb_decode(buff_ptr + obu_header_size, remaining_size, |
| 5616 | &obu_payload_size, &length_of_payload_size) != 0) { |
| 5617 | return AOM_CODEC_ERROR; |
| 5618 | } |
| 5619 | obu_bytes_read += length_of_payload_size; |
| 5620 | |
| 5621 | // calculate the length of size of the obu header plus payload |
| 5622 | length_of_obu_size = |
| 5623 | aom_uleb_size_in_bytes((uint64_t)(obu_header_size + obu_payload_size)); |
| 5624 | |
| 5625 | // move the rest of data to new location |
| 5626 | memmove(buff_ptr + length_of_obu_size + obu_header_size, |
| 5627 | buff_ptr + obu_bytes_read, remaining_size - obu_bytes_read); |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 5628 | obu_bytes_read += (size_t)obu_payload_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 5629 | |
| 5630 | // write the new obu size |
| 5631 | const uint64_t obu_size = obu_header_size + obu_payload_size; |
| 5632 | size_t coded_obu_size; |
| 5633 | if (aom_uleb_encode(obu_size, sizeof(obu_size), buff_ptr, |
| 5634 | &coded_obu_size) != 0) { |
| 5635 | return AOM_CODEC_ERROR; |
| 5636 | } |
| 5637 | |
| 5638 | // write the saved (modified) obu_header following obu size |
| 5639 | memmove(buff_ptr + length_of_obu_size, saved_obu_header, obu_header_size); |
| 5640 | |
| 5641 | total_bytes_read += obu_bytes_read; |
| 5642 | remaining_size -= obu_bytes_read; |
| 5643 | buff_ptr += length_of_obu_size + obu_size; |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 5644 | output_size += length_of_obu_size + (size_t)obu_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 5645 | } |
| 5646 | |
| 5647 | *frame_size = output_size; |
| 5648 | return AOM_CODEC_OK; |
| 5649 | } |
| 5650 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5651 | void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags) { |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5652 | // TODO(yunqingwang): For what references to use, external encoding flags |
| 5653 | // should be consistent with internal reference frame selection. Need to |
| 5654 | // ensure that there is not conflict between the two. In AV1 encoder, the |
| 5655 | // priority rank for 7 reference frames are: LAST, ALTREF, LAST2, LAST3, |
| 5656 | // GOLDEN, BWDREF, ALTREF2. If only one reference frame is used, it must be |
| 5657 | // LAST. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 5658 | cpi->ext_ref_frame_flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5659 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5660 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | |
| 5661 | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD | |
| 5662 | AOM_EFLAG_NO_REF_ARF2)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5663 | if (flags & AOM_EFLAG_NO_REF_LAST) { |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 5664 | cpi->ext_ref_frame_flags = 0; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5665 | } else { |
| 5666 | int ref = AOM_REFFRAME_ALL; |
| 5667 | |
| 5668 | if (flags & AOM_EFLAG_NO_REF_LAST2) ref ^= AOM_LAST2_FLAG; |
| 5669 | if (flags & AOM_EFLAG_NO_REF_LAST3) ref ^= AOM_LAST3_FLAG; |
| 5670 | |
| 5671 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
| 5672 | |
| 5673 | if (flags & AOM_EFLAG_NO_REF_ARF) { |
| 5674 | ref ^= AOM_ALT_FLAG; |
| 5675 | ref ^= AOM_BWD_FLAG; |
| 5676 | ref ^= AOM_ALT2_FLAG; |
| 5677 | } else { |
| 5678 | if (flags & AOM_EFLAG_NO_REF_BWD) ref ^= AOM_BWD_FLAG; |
| 5679 | if (flags & AOM_EFLAG_NO_REF_ARF2) ref ^= AOM_ALT2_FLAG; |
| 5680 | } |
| 5681 | |
| 5682 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5683 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5687 | (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5688 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5689 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5690 | // Refreshing LAST/LAST2/LAST3 is handled by 1 common flag. |
| 5691 | if (flags & AOM_EFLAG_NO_UPD_LAST) upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5692 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5693 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5694 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5695 | if (flags & AOM_EFLAG_NO_UPD_ARF) { |
| 5696 | upd ^= AOM_ALT_FLAG; |
| 5697 | upd ^= AOM_BWD_FLAG; |
| 5698 | upd ^= AOM_ALT2_FLAG; |
| 5699 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5700 | |
David Turner | ce9b590 | 2019-01-23 17:25:47 +0000 | [diff] [blame] | 5701 | cpi->ext_refresh_last_frame = (upd & AOM_LAST_FLAG) != 0; |
| 5702 | cpi->ext_refresh_golden_frame = (upd & AOM_GOLD_FLAG) != 0; |
| 5703 | cpi->ext_refresh_alt_ref_frame = (upd & AOM_ALT_FLAG) != 0; |
| 5704 | cpi->ext_refresh_bwd_ref_frame = (upd & AOM_BWD_FLAG) != 0; |
| 5705 | cpi->ext_refresh_alt2_ref_frame = (upd & AOM_ALT2_FLAG) != 0; |
| 5706 | cpi->ext_refresh_frame_flags_pending = 1; |
David Turner | 4f1f181 | 2019-01-24 17:00:24 +0000 | [diff] [blame] | 5707 | } else { |
| 5708 | cpi->ext_refresh_frame_flags_pending = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5709 | } |
| 5710 | |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5711 | cpi->ext_use_ref_frame_mvs = cpi->oxcf.allow_ref_frame_mvs & |
| 5712 | ((flags & AOM_EFLAG_NO_REF_FRAME_MVS) == 0); |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5713 | cpi->ext_use_error_resilient = cpi->oxcf.error_resilient_mode | |
| 5714 | ((flags & AOM_EFLAG_ERROR_RESILIENT) != 0); |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5715 | cpi->ext_use_s_frame = |
| 5716 | cpi->oxcf.s_frame_mode | ((flags & AOM_EFLAG_SET_S_FRAME) != 0); |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 5717 | cpi->ext_use_primary_ref_none = (flags & AOM_EFLAG_SET_PRIMARY_REF_NONE) != 0; |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5718 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5719 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 5720 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5721 | } |
| 5722 | } |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 5723 | |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 5724 | aom_fixed_buf_t *av1_get_global_headers(AV1_COMP *cpi) { |
| 5725 | if (!cpi) return NULL; |
| 5726 | |
| 5727 | uint8_t header_buf[512] = { 0 }; |
| 5728 | const uint32_t sequence_header_size = |
Yaowu Xu | 797674b | 2019-05-01 17:38:11 -0700 | [diff] [blame] | 5729 | av1_write_sequence_header_obu(cpi, &header_buf[0]); |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 5730 | assert(sequence_header_size <= sizeof(header_buf)); |
| 5731 | if (sequence_header_size == 0) return NULL; |
| 5732 | |
| 5733 | const size_t obu_header_size = 1; |
| 5734 | const size_t size_field_size = aom_uleb_size_in_bytes(sequence_header_size); |
| 5735 | const size_t payload_offset = obu_header_size + size_field_size; |
| 5736 | |
| 5737 | if (payload_offset + sequence_header_size > sizeof(header_buf)) return NULL; |
| 5738 | memmove(&header_buf[payload_offset], &header_buf[0], sequence_header_size); |
| 5739 | |
Hui Su | 4fd1176 | 2019-03-26 16:05:07 -0700 | [diff] [blame] | 5740 | if (av1_write_obu_header(cpi, OBU_SEQUENCE_HEADER, 0, &header_buf[0]) != |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 5741 | obu_header_size) { |
| 5742 | return NULL; |
| 5743 | } |
| 5744 | |
| 5745 | size_t coded_size_field_size = 0; |
| 5746 | if (aom_uleb_encode(sequence_header_size, size_field_size, |
| 5747 | &header_buf[obu_header_size], |
| 5748 | &coded_size_field_size) != 0) { |
| 5749 | return NULL; |
| 5750 | } |
| 5751 | assert(coded_size_field_size == size_field_size); |
| 5752 | |
| 5753 | aom_fixed_buf_t *global_headers = |
| 5754 | (aom_fixed_buf_t *)malloc(sizeof(*global_headers)); |
| 5755 | if (!global_headers) return NULL; |
| 5756 | |
| 5757 | const size_t global_header_buf_size = |
| 5758 | obu_header_size + size_field_size + sequence_header_size; |
| 5759 | |
| 5760 | global_headers->buf = malloc(global_header_buf_size); |
| 5761 | if (!global_headers->buf) { |
| 5762 | free(global_headers); |
| 5763 | return NULL; |
| 5764 | } |
| 5765 | |
| 5766 | memcpy(global_headers->buf, &header_buf[0], global_header_buf_size); |
| 5767 | global_headers->sz = global_header_buf_size; |
| 5768 | return global_headers; |
| 5769 | } |