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" |
Debargha Mukherjee | 347c64d | 2019-05-08 13:53:46 -0700 | [diff] [blame] | 74 | #include "av1/encoder/tpl_model.h" |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 75 | #include "av1/encoder/reconinter_enc.h" |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 76 | #include "av1/encoder/var_based_part.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 77 | |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 78 | #define DEFAULT_EXPLICIT_ORDER_HINT_BITS 7 |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 79 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 80 | #if CONFIG_ENTROPY_STATS |
| 81 | FRAME_COUNTS aggregate_fc; |
| 82 | #endif // CONFIG_ENTROPY_STATS |
| 83 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 84 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 85 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 86 | |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 87 | // Whether to use high precision mv for altref computation. |
| 88 | #define ALTREF_HIGH_PRECISION_MV 1 |
| 89 | |
| 90 | // Q threshold for high precision mv. Choose a very high value for now so that |
| 91 | // HIGH_PRECISION is always chosen. |
| 92 | #define HIGH_PRECISION_MV_QTHRESH 200 |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 93 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 94 | // #define OUTPUT_YUV_REC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 95 | #ifdef OUTPUT_YUV_SKINMAP |
| 96 | FILE *yuv_skinmap_file = NULL; |
| 97 | #endif |
| 98 | #ifdef OUTPUT_YUV_REC |
| 99 | FILE *yuv_rec_file; |
| 100 | #define FILE_NAME_LEN 100 |
| 101 | #endif |
| 102 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 103 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 104 | switch (mode) { |
| 105 | case NORMAL: |
| 106 | *hr = 1; |
| 107 | *hs = 1; |
| 108 | break; |
| 109 | case FOURFIVE: |
| 110 | *hr = 4; |
| 111 | *hs = 5; |
| 112 | break; |
| 113 | case THREEFIVE: |
| 114 | *hr = 3; |
| 115 | *hs = 5; |
| 116 | break; |
| 117 | case ONETWO: |
| 118 | *hr = 1; |
| 119 | *hs = 2; |
| 120 | break; |
| 121 | default: |
| 122 | *hr = 1; |
| 123 | *hs = 1; |
| 124 | assert(0); |
| 125 | break; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 130 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 131 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 132 | unsigned char *const seg_map = cpi->segmentation_map; |
| 133 | int i; |
| 134 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 135 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 136 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 137 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 138 | } |
| 139 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 140 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 141 | struct segmentation *const seg = &cpi->common.seg; |
| 142 | unsigned char *const seg_map = cpi->segmentation_map; |
| 143 | const unsigned char *const active_map = cpi->active_map.map; |
| 144 | int i; |
| 145 | |
| 146 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 147 | |
| 148 | if (frame_is_intra_only(&cpi->common)) { |
| 149 | cpi->active_map.enabled = 0; |
| 150 | cpi->active_map.update = 1; |
| 151 | } |
| 152 | |
| 153 | if (cpi->active_map.update) { |
| 154 | if (cpi->active_map.enabled) { |
| 155 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 156 | 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] | 157 | av1_enable_segmentation(seg); |
| 158 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 159 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 160 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 161 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 162 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 163 | |
| 164 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H, |
| 165 | -MAX_LOOP_FILTER); |
| 166 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V, |
| 167 | -MAX_LOOP_FILTER); |
| 168 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U, |
| 169 | -MAX_LOOP_FILTER); |
| 170 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V, |
| 171 | -MAX_LOOP_FILTER); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 172 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 173 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 174 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 175 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 176 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 177 | 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] | 178 | if (seg->enabled) { |
| 179 | seg->update_data = 1; |
| 180 | seg->update_map = 1; |
| 181 | } |
| 182 | } |
| 183 | cpi->active_map.update = 0; |
| 184 | } |
| 185 | } |
| 186 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 187 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 188 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 189 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 190 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 191 | const int mi_rows = cpi->common.mi_rows; |
| 192 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 193 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 194 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 195 | cpi->active_map.update = 1; |
| 196 | if (new_map_16x16) { |
| 197 | int r, c; |
| 198 | for (r = 0; r < mi_rows; ++r) { |
| 199 | for (c = 0; c < mi_cols; ++c) { |
| 200 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 201 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 202 | ? AM_SEGMENT_ID_ACTIVE |
| 203 | : AM_SEGMENT_ID_INACTIVE; |
| 204 | } |
| 205 | } |
| 206 | cpi->active_map.enabled = 1; |
| 207 | } else { |
| 208 | cpi->active_map.enabled = 0; |
| 209 | } |
| 210 | return 0; |
| 211 | } else { |
| 212 | return -1; |
| 213 | } |
| 214 | } |
| 215 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 216 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 217 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 218 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 219 | new_map_16x16) { |
| 220 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 221 | const int mi_rows = cpi->common.mi_rows; |
| 222 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 223 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 224 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 225 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 226 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 227 | if (cpi->active_map.enabled) { |
| 228 | int r, c; |
| 229 | for (r = 0; r < mi_rows; ++r) { |
| 230 | for (c = 0; c < mi_cols; ++c) { |
| 231 | // Cyclic refresh segments are considered active despite not having |
| 232 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 233 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 234 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | return 0; |
| 239 | } else { |
| 240 | return -1; |
| 241 | } |
| 242 | } |
| 243 | |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 244 | // Compute the horizontal frequency components' energy in a frame |
| 245 | // by calculuating the 16x4 Horizontal DCT. This is to be used to |
| 246 | // decide the superresolution parameters. |
Yaowu Xu | bedbf4f | 2019-05-01 17:54:36 -0700 | [diff] [blame] | 247 | static void analyze_hor_freq(const AV1_COMP *cpi, double *energy) { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 248 | uint64_t freq_energy[16] = { 0 }; |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 249 | const YV12_BUFFER_CONFIG *buf = cpi->source; |
| 250 | const int bd = cpi->td.mb.e_mbd.bd; |
| 251 | const int width = buf->y_crop_width; |
| 252 | const int height = buf->y_crop_height; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 253 | DECLARE_ALIGNED(16, int32_t, coeff[16 * 4]); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 254 | int n = 0; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 255 | memset(freq_energy, 0, sizeof(freq_energy)); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 256 | if (buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 257 | const int16_t *src16 = (const int16_t *)CONVERT_TO_SHORTPTR(buf->y_buffer); |
| 258 | for (int i = 0; i < height - 4; i += 4) { |
| 259 | for (int j = 0; j < width - 16; j += 16) { |
| 260 | av1_fwd_txfm2d_16x4(src16 + i * buf->y_stride + j, coeff, buf->y_stride, |
| 261 | H_DCT, bd); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 262 | for (int k = 1; k < 16; ++k) { |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 263 | const uint64_t this_energy = |
| 264 | ((int64_t)coeff[k] * coeff[k]) + |
| 265 | ((int64_t)coeff[k + 16] * coeff[k + 16]) + |
| 266 | ((int64_t)coeff[k + 32] * coeff[k + 32]) + |
| 267 | ((int64_t)coeff[k + 48] * coeff[k + 48]); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 268 | 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] | 269 | } |
| 270 | n++; |
| 271 | } |
| 272 | } |
| 273 | } else { |
Debargha Mukherjee | ac28c72 | 2018-11-14 22:09:46 -0800 | [diff] [blame] | 274 | assert(bd == 8); |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 275 | DECLARE_ALIGNED(16, int16_t, src16[16 * 4]); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 276 | for (int i = 0; i < height - 4; i += 4) { |
| 277 | for (int j = 0; j < width - 16; j += 16) { |
| 278 | for (int ii = 0; ii < 4; ++ii) |
| 279 | for (int jj = 0; jj < 16; ++jj) |
| 280 | src16[ii * 16 + jj] = |
| 281 | buf->y_buffer[(i + ii) * buf->y_stride + (j + jj)]; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 282 | av1_fwd_txfm2d_16x4(src16, coeff, 16, H_DCT, bd); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 283 | for (int k = 1; k < 16; ++k) { |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 284 | const uint64_t this_energy = |
| 285 | ((int64_t)coeff[k] * coeff[k]) + |
| 286 | ((int64_t)coeff[k + 16] * coeff[k + 16]) + |
| 287 | ((int64_t)coeff[k + 32] * coeff[k + 32]) + |
| 288 | ((int64_t)coeff[k + 48] * coeff[k + 48]); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 289 | freq_energy[k] += ROUND_POWER_OF_TWO(this_energy, 2); |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 290 | } |
| 291 | n++; |
| 292 | } |
| 293 | } |
| 294 | } |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 295 | if (n) { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 296 | 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] | 297 | // Convert to cumulative energy |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 298 | for (int k = 14; k > 0; --k) energy[k] += energy[k + 1]; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 299 | } else { |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 300 | for (int k = 1; k < 16; ++k) energy[k] = 1e+20; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 301 | } |
Debargha Mukherjee | f50fdce | 2018-11-13 11:13:00 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Yaowu Xu | 45295c3 | 2018-03-29 12:06:10 -0700 | [diff] [blame] | 304 | static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv, |
| 305 | int cur_frame_force_integer_mv) { |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 306 | MACROBLOCK *const mb = &cpi->td.mb; |
Hui Su | 5036115 | 2018-03-02 11:01:42 -0800 | [diff] [blame] | 307 | cpi->common.allow_high_precision_mv = |
| 308 | allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
Rupert Swarbrick | a84faf2 | 2017-12-11 13:56:40 +0000 | [diff] [blame] | 309 | const int copy_hp = |
| 310 | cpi->common.allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 311 | int *(*src)[2] = copy_hp ? &mb->nmvcost_hp : &mb->nmvcost; |
| 312 | mb->mv_cost_stack = *src; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 315 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 316 | const AV1_COMMON *const cm = &cpi->common; |
| 317 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 318 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 319 | return BLOCK_64X64; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 320 | #if CONFIG_FILEOPTIONS |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 321 | if (cm->options && cm->options->ext_partition) |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 322 | #endif |
| 323 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
| 324 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 325 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 326 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 327 | |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 328 | // TODO(any): Possibly could improve this with a heuristic. |
| 329 | #if CONFIG_FILEOPTIONS |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 330 | if (cm->options && !cm->options->ext_partition) return BLOCK_64X64; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 331 | #endif |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 332 | |
Urvang Joshi | aab7443 | 2018-06-01 12:06:22 -0700 | [diff] [blame] | 333 | // When superres / resize is on, 'cm->width / height' can change between |
Hui Su | 3e3b934 | 2019-04-12 18:27:28 +0000 | [diff] [blame] | 334 | // calls, so we don't apply this heuristic there. |
| 335 | // Things break if superblock size changes between the first pass and second |
| 336 | // pass encoding, which is why this heuristic is not configured as a |
| 337 | // speed-feature. |
Urvang Joshi | aab7443 | 2018-06-01 12:06:22 -0700 | [diff] [blame] | 338 | if (cpi->oxcf.superres_mode == SUPERRES_NONE && |
Hui Su | 3e3b934 | 2019-04-12 18:27:28 +0000 | [diff] [blame] | 339 | cpi->oxcf.resize_mode == RESIZE_NONE && cpi->oxcf.speed >= 1) { |
| 340 | return AOMMIN(cm->width, cm->height) > 480 ? BLOCK_128X128 : BLOCK_64X64; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 341 | } |
| 342 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 343 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 346 | static void setup_frame(AV1_COMP *cpi) { |
| 347 | AV1_COMMON *const cm = &cpi->common; |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 348 | // Set up entropy context depending on frame type. The decoder mandates |
| 349 | // the use of the default context, index 0, for keyframes and inter |
| 350 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 351 | // other inter-frames the encoder currently uses only two contexts; |
| 352 | // context 1 for ALTREF frames and context 0 for the others. |
Soo-Chul Han | 85e8c79 | 2018-01-21 01:58:15 -0500 | [diff] [blame] | 353 | |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 354 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 355 | cpi->ext_use_primary_ref_none) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 356 | av1_setup_past_independence(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Hui Su | eb4b7de | 2019-04-03 11:00:18 -0700 | [diff] [blame] | 359 | if ((cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) || |
| 360 | frame_is_sframe(cm)) { |
| 361 | if (!cpi->seq_params_locked) { |
| 362 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
| 363 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 364 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 365 | const RefCntBuffer *const primary_ref_buf = get_primary_ref_frame_buf(cm); |
| 366 | if (primary_ref_buf == NULL) { |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 367 | av1_setup_past_independence(cm); |
| 368 | cm->seg.update_map = 1; |
| 369 | cm->seg.update_data = 1; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 370 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 371 | *cm->fc = primary_ref_buf->frame_context; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 372 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 373 | } |
| 374 | |
David Turner | bc0993e | 2019-02-15 14:42:23 +0000 | [diff] [blame] | 375 | av1_zero(cm->cur_frame->interp_filter_selected); |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 376 | cm->prev_frame = get_primary_ref_frame_buf(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 377 | cpi->vaq_refresh = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 380 | static void enc_setup_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 381 | int i; |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 382 | int mi_rows_sb_aligned = calc_mi_size(cm->mi_rows); |
chiyotsai | 04ca87d | 2019-05-24 15:06:19 -0700 | [diff] [blame] | 383 | memset(cm->mi, 0, cm->mi_stride * mi_rows_sb_aligned * sizeof(*cm->mi)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 384 | // Clear top border row |
chiyotsai | 04ca87d | 2019-05-24 15:06:19 -0700 | [diff] [blame] | 385 | memset(cm->prev_mi, 0, sizeof(*cm->prev_mi) * cm->mi_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 386 | // Clear left border column |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 387 | for (i = 0; i < mi_rows_sb_aligned; ++i) |
chiyotsai | 04ca87d | 2019-05-24 15:06:19 -0700 | [diff] [blame] | 388 | memset(&cm->prev_mi[i * cm->mi_stride], 0, sizeof(*cm->prev_mi)); |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 389 | cm->mi_grid_visible = cm->mi_grid_base; |
| 390 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 391 | |
| 392 | memset(cm->mi_grid_base, 0, |
Ravi Chaudhary | 75c4c5f | 2018-07-17 16:32:08 +0530 | [diff] [blame] | 393 | cm->mi_stride * mi_rows_sb_aligned * sizeof(*cm->mi_grid_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 396 | static int enc_alloc_mi(AV1_COMMON *cm, int mi_size) { |
chiyotsai | 04ca87d | 2019-05-24 15:06:19 -0700 | [diff] [blame] | 397 | cm->mi = aom_calloc(mi_size, sizeof(*cm->mi)); |
| 398 | if (!cm->mi) return 1; |
| 399 | cm->prev_mi = aom_calloc(mi_size, sizeof(*cm->prev_mi)); |
| 400 | if (!cm->prev_mi) return 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 401 | cm->mi_alloc_size = mi_size; |
| 402 | |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 403 | cm->mi_grid_base = |
| 404 | (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 405 | if (!cm->mi_grid_base) return 1; |
| 406 | cm->prev_mi_grid_base = |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 407 | (MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 408 | if (!cm->prev_mi_grid_base) return 1; |
| 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 413 | static void enc_free_mi(AV1_COMMON *cm) { |
chiyotsai | 04ca87d | 2019-05-24 15:06:19 -0700 | [diff] [blame] | 414 | aom_free(cm->mi); |
| 415 | cm->mi = NULL; |
| 416 | aom_free(cm->prev_mi); |
| 417 | cm->prev_mi = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 418 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 419 | cm->mi_grid_base = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 420 | aom_free(cm->prev_mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 421 | cm->prev_mi_grid_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 422 | cm->mi_alloc_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 425 | static void swap_mi_and_prev_mi(AV1_COMMON *cm) { |
chiyotsai | 04ca87d | 2019-05-24 15:06:19 -0700 | [diff] [blame] | 426 | // Current mi will be the prev_mi for the next frame. |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 427 | MB_MODE_INFO **temp_base = cm->prev_mi_grid_base; |
chiyotsai | 04ca87d | 2019-05-24 15:06:19 -0700 | [diff] [blame] | 428 | MB_MODE_INFO *temp = cm->prev_mi; |
| 429 | cm->prev_mi = cm->mi; |
| 430 | cm->mi = temp; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 431 | |
| 432 | // Update the upper left visible macroblock ptrs. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 433 | cm->prev_mi_grid_base = cm->mi_grid_base; |
| 434 | cm->mi_grid_base = temp_base; |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 435 | cm->mi_grid_visible = cm->mi_grid_base; |
| 436 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 439 | void av1_initialize_enc(void) { |
Wan-Teh Chang | 3cac454 | 2018-06-29 10:21:39 -0700 | [diff] [blame] | 440 | av1_rtcd(); |
| 441 | aom_dsp_rtcd(); |
| 442 | aom_scale_rtcd(); |
| 443 | av1_init_intra_predictors(); |
| 444 | av1_init_me_luts(); |
| 445 | av1_rc_init_minq_luts(); |
| 446 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 449 | static void dealloc_context_buffers_ext(AV1_COMP *cpi) { |
| 450 | if (cpi->mbmi_ext_base) { |
| 451 | aom_free(cpi->mbmi_ext_base); |
| 452 | cpi->mbmi_ext_base = NULL; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
| 457 | AV1_COMMON *cm = &cpi->common; |
| 458 | int mi_size = cm->mi_cols * cm->mi_rows; |
| 459 | |
| 460 | dealloc_context_buffers_ext(cpi); |
| 461 | CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, |
| 462 | aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); |
| 463 | } |
| 464 | |
Yaowu Xu | c0ea258 | 2019-01-15 10:17:16 -0800 | [diff] [blame] | 465 | static void reset_film_grain_chroma_params(aom_film_grain_t *pars) { |
| 466 | pars->num_cr_points = 0; |
| 467 | pars->cr_mult = 0; |
| 468 | pars->cr_luma_mult = 0; |
| 469 | memset(pars->scaling_points_cr, 0, sizeof(pars->scaling_points_cr)); |
| 470 | memset(pars->ar_coeffs_cr, 0, sizeof(pars->ar_coeffs_cr)); |
| 471 | pars->num_cb_points = 0; |
| 472 | pars->cb_mult = 0; |
| 473 | pars->cb_luma_mult = 0; |
Yaowu Xu | fda7dcb | 2019-01-16 13:04:33 -0800 | [diff] [blame] | 474 | pars->chroma_scaling_from_luma = 0; |
Yaowu Xu | c0ea258 | 2019-01-15 10:17:16 -0800 | [diff] [blame] | 475 | memset(pars->scaling_points_cb, 0, sizeof(pars->scaling_points_cb)); |
| 476 | memset(pars->ar_coeffs_cb, 0, sizeof(pars->ar_coeffs_cb)); |
| 477 | } |
| 478 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 479 | static void update_film_grain_parameters(struct AV1_COMP *cpi, |
| 480 | const AV1EncoderConfig *oxcf) { |
| 481 | AV1_COMMON *const cm = &cpi->common; |
| 482 | cpi->oxcf = *oxcf; |
| 483 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 484 | if (cpi->film_grain_table) { |
| 485 | aom_film_grain_table_free(cpi->film_grain_table); |
| 486 | aom_free(cpi->film_grain_table); |
| 487 | cpi->film_grain_table = NULL; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 488 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 489 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 490 | if (oxcf->film_grain_test_vector) { |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 491 | cm->seq_params.film_grain_params_present = 1; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 492 | if (cm->current_frame.frame_type == KEY_FRAME) { |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 493 | memcpy(&cm->film_grain_params, |
| 494 | film_grain_test_vectors + oxcf->film_grain_test_vector - 1, |
| 495 | sizeof(cm->film_grain_params)); |
Yaowu Xu | c0ea258 | 2019-01-15 10:17:16 -0800 | [diff] [blame] | 496 | if (oxcf->monochrome) |
| 497 | reset_film_grain_chroma_params(&cm->film_grain_params); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 498 | cm->film_grain_params.bit_depth = cm->seq_params.bit_depth; |
| 499 | if (cm->seq_params.color_range == AOM_CR_FULL_RANGE) { |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 500 | cm->film_grain_params.clip_to_restricted_range = 0; |
| 501 | } |
| 502 | } |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 503 | } else if (oxcf->film_grain_table_filename) { |
Neil Birkbeck | bd40ca7 | 2019-03-02 13:25:50 -0800 | [diff] [blame] | 504 | cm->seq_params.film_grain_params_present = 1; |
| 505 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 506 | cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table)); |
| 507 | memset(cpi->film_grain_table, 0, sizeof(aom_film_grain_table_t)); |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 508 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 509 | aom_film_grain_table_read(cpi->film_grain_table, |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 510 | oxcf->film_grain_table_filename, &cm->error); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 511 | } else { |
Neil Birkbeck | bd40ca7 | 2019-03-02 13:25:50 -0800 | [diff] [blame] | 512 | #if CONFIG_DENOISE |
| 513 | cm->seq_params.film_grain_params_present = (cpi->oxcf.noise_level > 0); |
| 514 | #else |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 515 | cm->seq_params.film_grain_params_present = 0; |
Neil Birkbeck | bd40ca7 | 2019-03-02 13:25:50 -0800 | [diff] [blame] | 516 | #endif |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 517 | memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params)); |
| 518 | } |
| 519 | } |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 520 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 521 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 522 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 523 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 524 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 525 | dealloc_context_buffers_ext(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 526 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 527 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 528 | cpi->tile_data = NULL; |
| 529 | |
| 530 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 531 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 532 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 533 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 534 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 535 | cpi->cyclic_refresh = NULL; |
| 536 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 537 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 538 | cpi->active_map.map = NULL; |
| 539 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 540 | aom_free(cpi->td.mb.above_pred_buf); |
| 541 | cpi->td.mb.above_pred_buf = NULL; |
| 542 | |
| 543 | aom_free(cpi->td.mb.left_pred_buf); |
| 544 | cpi->td.mb.left_pred_buf = NULL; |
| 545 | |
| 546 | aom_free(cpi->td.mb.wsrc_buf); |
| 547 | cpi->td.mb.wsrc_buf = NULL; |
| 548 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 549 | aom_free(cpi->td.mb.inter_modes_info); |
| 550 | cpi->td.mb.inter_modes_info = NULL; |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 551 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 552 | for (int i = 0; i < 2; i++) |
| 553 | for (int j = 0; j < 2; j++) { |
| 554 | aom_free(cpi->td.mb.hash_value_buffer[i][j]); |
| 555 | cpi->td.mb.hash_value_buffer[i][j] = NULL; |
| 556 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 557 | aom_free(cpi->td.mb.mask_buf); |
| 558 | cpi->td.mb.mask_buf = NULL; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 559 | |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 560 | aom_free(cm->tpl_mvs); |
| 561 | cm->tpl_mvs = NULL; |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 562 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 563 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 564 | av1_free_txb_buf(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 565 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 566 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 567 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 568 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 569 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 570 | aom_free_frame_buffer(&cpi->scaled_source); |
| 571 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 572 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 573 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 574 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 575 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 576 | cpi->tile_tok[0][0] = 0; |
| 577 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 578 | aom_free(cpi->tplist[0][0]); |
| 579 | cpi->tplist[0][0] = NULL; |
| 580 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 581 | av1_free_pc_tree(&cpi->td, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 582 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 583 | aom_free(cpi->td.mb.palette_buffer); |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 584 | |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 585 | aom_free(cpi->td.mb.tmp_conv_dst); |
| 586 | for (int j = 0; j < 2; ++j) { |
| 587 | aom_free(cpi->td.mb.tmp_obmc_bufs[j]); |
| 588 | } |
| 589 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 590 | #if CONFIG_DENOISE |
| 591 | if (cpi->denoise_and_model) { |
| 592 | aom_denoise_and_model_free(cpi->denoise_and_model); |
| 593 | cpi->denoise_and_model = NULL; |
| 594 | } |
| 595 | #endif |
| 596 | if (cpi->film_grain_table) { |
| 597 | aom_film_grain_table_free(cpi->film_grain_table); |
| 598 | cpi->film_grain_table = NULL; |
| 599 | } |
Hui Su | c3a8d37 | 2019-05-28 15:52:45 -0700 | [diff] [blame] | 600 | |
| 601 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
| 602 | aom_free(cpi->level_info[i]); |
| 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 | |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 880 | double av1_get_compression_ratio(const AV1_COMMON *const cm, |
| 881 | size_t encoded_frame_size) { |
| 882 | const int upscaled_width = cm->superres_upscaled_width; |
| 883 | const int height = cm->height; |
| 884 | const int luma_pic_size = upscaled_width * height; |
| 885 | const SequenceHeader *const seq_params = &cm->seq_params; |
| 886 | const BITSTREAM_PROFILE profile = seq_params->profile; |
| 887 | const int pic_size_profile_factor = |
| 888 | profile == PROFILE_0 ? 15 : (profile == PROFILE_1 ? 30 : 36); |
| 889 | encoded_frame_size = |
| 890 | (encoded_frame_size > 129 ? encoded_frame_size - 128 : 1); |
| 891 | const size_t uncompressed_frame_size = |
| 892 | (luma_pic_size * pic_size_profile_factor) >> 3; |
| 893 | return uncompressed_frame_size / (double)encoded_frame_size; |
| 894 | } |
| 895 | |
Yunqing Wang | 75e20e8 | 2018-06-16 12:10:48 -0700 | [diff] [blame] | 896 | static void set_tile_info(AV1_COMP *cpi) { |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 897 | AV1_COMMON *const cm = &cpi->common; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 898 | int i, start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 899 | |
| 900 | av1_get_tile_limits(cm); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 901 | |
| 902 | // configure tile columns |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 903 | 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] | 904 | cm->uniform_tile_spacing_flag = 1; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 905 | cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols); |
| 906 | 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] | 907 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 908 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->seq_params.mib_size_log2); |
| 909 | int sb_cols = mi_cols >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 910 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 911 | cm->uniform_tile_spacing_flag = 0; |
| 912 | for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) { |
| 913 | cm->tile_col_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 914 | size_sb = cpi->oxcf.tile_widths[j++]; |
| 915 | if (j >= cpi->oxcf.tile_width_count) j = 0; |
David Barker | 6cd5a82 | 2018-03-05 16:19:28 +0000 | [diff] [blame] | 916 | start_sb += AOMMIN(size_sb, cm->max_tile_width_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 917 | } |
| 918 | cm->tile_cols = i; |
| 919 | cm->tile_col_start_sb[i] = sb_cols; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 920 | } |
| 921 | av1_calculate_tile_cols(cm); |
| 922 | |
| 923 | // configure tile rows |
| 924 | if (cm->uniform_tile_spacing_flag) { |
| 925 | cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows); |
| 926 | 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] | 927 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 928 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 929 | int sb_rows = mi_rows >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 930 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 931 | for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) { |
| 932 | cm->tile_row_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 933 | size_sb = cpi->oxcf.tile_heights[j++]; |
| 934 | if (j >= cpi->oxcf.tile_height_count) j = 0; |
| 935 | start_sb += AOMMIN(size_sb, cm->max_tile_height_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 936 | } |
| 937 | cm->tile_rows = i; |
| 938 | cm->tile_row_start_sb[i] = sb_rows; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 939 | } |
| 940 | av1_calculate_tile_rows(cm); |
| 941 | } |
| 942 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 943 | static void update_frame_size(AV1_COMP *cpi) { |
| 944 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 945 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 946 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 947 | av1_set_mb_mi(cm, cm->width, cm->height); |
| 948 | av1_init_context_buffers(cm); |
Luc Trudeau | 1e84af5 | 2017-11-25 15:00:28 -0500 | [diff] [blame] | 949 | av1_init_macroblockd(cm, xd, NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 950 | memset(cpi->mbmi_ext_base, 0, |
| 951 | cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 952 | set_tile_info(cpi); |
| 953 | } |
| 954 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 955 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 956 | int fb_idx; |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 957 | for (fb_idx = 0; fb_idx < REF_FRAMES; ++fb_idx) |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 958 | cpi->common.remapped_ref_idx[fb_idx] = fb_idx; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 959 | cpi->rate_index = 0; |
| 960 | cpi->rate_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 963 | static INLINE int does_level_match(int width, int height, double fps, |
| 964 | int lvl_width, int lvl_height, |
| 965 | double lvl_fps, int lvl_dim_mult) { |
| 966 | const int64_t lvl_luma_pels = lvl_width * lvl_height; |
| 967 | const double lvl_display_sample_rate = lvl_luma_pels * lvl_fps; |
| 968 | const int64_t luma_pels = width * height; |
| 969 | const double display_sample_rate = luma_pels * fps; |
| 970 | return luma_pels <= lvl_luma_pels && |
| 971 | display_sample_rate <= lvl_display_sample_rate && |
| 972 | width <= lvl_width * lvl_dim_mult && |
| 973 | height <= lvl_height * lvl_dim_mult; |
| 974 | } |
| 975 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 976 | static void set_bitstream_level_tier(SequenceHeader *seq, AV1_COMMON *cm, |
Andrey Norkin | f481d98 | 2018-05-15 12:05:31 -0700 | [diff] [blame] | 977 | const AV1EncoderConfig *oxcf) { |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 978 | // TODO(any): This is a placeholder function that only addresses dimensions |
| 979 | // and max display sample rates. |
| 980 | // Need to add checks for max bit rate, max decoded luma sample rate, header |
| 981 | // rate, etc. that are not covered by this function. |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 982 | AV1_LEVEL level = SEQ_LEVEL_MAX; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 983 | if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, 512, |
| 984 | 288, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 985 | level = SEQ_LEVEL_2_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 986 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 987 | 704, 396, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 988 | level = SEQ_LEVEL_2_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 989 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 990 | 1088, 612, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 991 | level = SEQ_LEVEL_3_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 992 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 993 | 1376, 774, 30.0, 4)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 994 | level = SEQ_LEVEL_3_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 995 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 996 | 2048, 1152, 30.0, 3)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 997 | level = SEQ_LEVEL_4_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 998 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 999 | 2048, 1152, 60.0, 3)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1000 | level = SEQ_LEVEL_4_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1001 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1002 | 4096, 2176, 30.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1003 | level = SEQ_LEVEL_5_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1004 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1005 | 4096, 2176, 60.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1006 | level = SEQ_LEVEL_5_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1007 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1008 | 4096, 2176, 120.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1009 | level = SEQ_LEVEL_5_2; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1010 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1011 | 8192, 4352, 30.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1012 | level = SEQ_LEVEL_6_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1013 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1014 | 8192, 4352, 60.0, 2)) { |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1015 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1016 | 8192, 4352, 120.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1017 | level = SEQ_LEVEL_6_2; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1018 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1019 | 16384, 8704, 30.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1020 | level = SEQ_LEVEL_7_0; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1021 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1022 | 16384, 8704, 60.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1023 | level = SEQ_LEVEL_7_1; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1024 | } else if (does_level_match(oxcf->width, oxcf->height, oxcf->init_framerate, |
| 1025 | 16384, 8704, 120.0, 2)) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1026 | level = SEQ_LEVEL_7_2; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1027 | } |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 1028 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1029 | seq->seq_level_idx[i] = level; |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1030 | // Set the maximum parameters for bitrate and buffer size for this profile, |
| 1031 | // level, and tier |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 1032 | cm->op_params[i].bitrate = av1_max_level_bitrate( |
Hui Su | 8427ff2 | 2019-03-11 10:14:33 -0700 | [diff] [blame] | 1033 | cm->seq_params.profile, seq->seq_level_idx[i], seq->tier[i]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1034 | // Level with seq_level_idx = 31 returns a high "dummy" bitrate to pass the |
| 1035 | // check |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1036 | if (cm->op_params[i].bitrate == 0) |
| 1037 | aom_internal_error( |
| 1038 | &cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
| 1039 | "AV1 does not support this combination of profile, level, and tier."); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1040 | // Buffer size in bits/s is bitrate in bits/s * 1 s |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1041 | cm->op_params[i].buffer_size = cm->op_params[i].bitrate; |
Debargha Mukherjee | ea67540 | 2018-05-10 16:10:41 -0700 | [diff] [blame] | 1042 | } |
| 1043 | } |
| 1044 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1045 | static void init_seq_coding_tools(SequenceHeader *seq, AV1_COMMON *cm, |
| 1046 | const AV1EncoderConfig *oxcf) { |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1047 | seq->still_picture = (oxcf->limit == 1); |
| 1048 | seq->reduced_still_picture_hdr = seq->still_picture; |
Debargha Mukherjee | 9713ccb | 2018-04-08 19:09:17 -0700 | [diff] [blame] | 1049 | seq->reduced_still_picture_hdr &= !oxcf->full_still_picture_hdr; |
kyslov | 9424338 | 2019-05-02 15:33:32 -0700 | [diff] [blame] | 1050 | seq->force_screen_content_tools = (oxcf->mode == REALTIME) ? 0 : 2; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1051 | seq->force_integer_mv = 2; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1052 | seq->order_hint_info.enable_order_hint = oxcf->enable_order_hint; |
David Turner | 936235c | 2018-11-28 13:42:01 +0000 | [diff] [blame] | 1053 | seq->frame_id_numbers_present_flag = |
| 1054 | !(seq->still_picture && seq->reduced_still_picture_hdr) && |
| 1055 | !oxcf->large_scale_tile && oxcf->error_resilient_mode; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1056 | if (seq->still_picture && seq->reduced_still_picture_hdr) { |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1057 | seq->order_hint_info.enable_order_hint = 0; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1058 | seq->force_screen_content_tools = 2; |
| 1059 | seq->force_integer_mv = 2; |
| 1060 | } |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1061 | seq->order_hint_info.order_hint_bits_minus_1 = |
| 1062 | seq->order_hint_info.enable_order_hint |
| 1063 | ? DEFAULT_EXPLICIT_ORDER_HINT_BITS - 1 |
| 1064 | : -1; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1065 | |
David Turner | 760a2f4 | 2018-12-07 15:25:36 +0000 | [diff] [blame] | 1066 | seq->max_frame_width = |
| 1067 | oxcf->forced_max_frame_width ? oxcf->forced_max_frame_width : oxcf->width; |
| 1068 | seq->max_frame_height = oxcf->forced_max_frame_height |
| 1069 | ? oxcf->forced_max_frame_height |
| 1070 | : oxcf->height; |
| 1071 | seq->num_bits_width = |
| 1072 | (seq->max_frame_width > 1) ? get_msb(seq->max_frame_width - 1) + 1 : 1; |
| 1073 | seq->num_bits_height = |
| 1074 | (seq->max_frame_height > 1) ? get_msb(seq->max_frame_height - 1) + 1 : 1; |
| 1075 | assert(seq->num_bits_width <= 16); |
| 1076 | assert(seq->num_bits_height <= 16); |
| 1077 | |
| 1078 | seq->frame_id_length = FRAME_ID_LENGTH; |
| 1079 | seq->delta_frame_id_length = DELTA_FRAME_ID_LENGTH; |
| 1080 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 1081 | seq->enable_dual_filter = oxcf->enable_dual_filter; |
Debargha Mukherjee | 7ac3eb1 | 2018-12-12 10:26:50 -0800 | [diff] [blame] | 1082 | seq->order_hint_info.enable_dist_wtd_comp = oxcf->enable_dist_wtd_comp; |
| 1083 | seq->order_hint_info.enable_dist_wtd_comp &= |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1084 | seq->order_hint_info.enable_order_hint; |
| 1085 | seq->order_hint_info.enable_ref_frame_mvs = oxcf->enable_ref_frame_mvs; |
| 1086 | seq->order_hint_info.enable_ref_frame_mvs &= |
| 1087 | seq->order_hint_info.enable_order_hint; |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1088 | seq->enable_superres = oxcf->enable_superres; |
| 1089 | seq->enable_cdef = oxcf->enable_cdef; |
| 1090 | seq->enable_restoration = oxcf->enable_restoration; |
Debargha Mukherjee | 37df916 | 2018-03-25 12:48:24 -0700 | [diff] [blame] | 1091 | seq->enable_warped_motion = oxcf->enable_warped_motion; |
Debargha Mukherjee | 16ea6ba | 2018-12-10 12:01:38 -0800 | [diff] [blame] | 1092 | seq->enable_interintra_compound = oxcf->enable_interintra_comp; |
| 1093 | seq->enable_masked_compound = oxcf->enable_masked_comp; |
Debargha Mukherjee | 03c43ba | 2018-12-14 13:08:08 -0800 | [diff] [blame] | 1094 | seq->enable_intra_edge_filter = oxcf->enable_intra_edge_filter; |
Yue Chen | 8f9ca58 | 2018-12-12 15:11:47 -0800 | [diff] [blame] | 1095 | seq->enable_filter_intra = oxcf->enable_filter_intra; |
Debargha Mukherjee | 5749869 | 2018-05-11 13:29:31 -0700 | [diff] [blame] | 1096 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1097 | set_bitstream_level_tier(seq, cm, oxcf); |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1098 | |
| 1099 | if (seq->operating_points_cnt_minus_1 == 0) { |
| 1100 | seq->operating_point_idc[0] = 0; |
| 1101 | } else { |
| 1102 | // Set operating_point_idc[] such that for the i-th operating point the |
| 1103 | // first (operating_points_cnt-i) spatial layers and the first temporal |
| 1104 | // layer are decoded Note that highest quality operating point should come |
| 1105 | // first |
| 1106 | for (int i = 0; i < seq->operating_points_cnt_minus_1 + 1; i++) |
| 1107 | seq->operating_point_idc[i] = |
| 1108 | (~(~0u << (seq->operating_points_cnt_minus_1 + 1 - i)) << 8) | 1; |
| 1109 | } |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1112 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 1113 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1114 | |
| 1115 | cpi->oxcf = *oxcf; |
| 1116 | cpi->framerate = oxcf->init_framerate; |
| 1117 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1118 | cm->seq_params.profile = oxcf->profile; |
| 1119 | cm->seq_params.bit_depth = oxcf->bit_depth; |
| 1120 | cm->seq_params.use_highbitdepth = oxcf->use_highbitdepth; |
| 1121 | cm->seq_params.color_primaries = oxcf->color_primaries; |
| 1122 | cm->seq_params.transfer_characteristics = oxcf->transfer_characteristics; |
| 1123 | cm->seq_params.matrix_coefficients = oxcf->matrix_coefficients; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 1124 | cm->seq_params.monochrome = oxcf->monochrome; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1125 | cm->seq_params.chroma_sample_position = oxcf->chroma_sample_position; |
| 1126 | cm->seq_params.color_range = oxcf->color_range; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 1127 | cm->timing_info_present = oxcf->timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1128 | cm->timing_info.num_units_in_display_tick = |
| 1129 | oxcf->timing_info.num_units_in_display_tick; |
| 1130 | cm->timing_info.time_scale = oxcf->timing_info.time_scale; |
| 1131 | cm->timing_info.equal_picture_interval = |
| 1132 | oxcf->timing_info.equal_picture_interval; |
| 1133 | cm->timing_info.num_ticks_per_picture = |
| 1134 | oxcf->timing_info.num_ticks_per_picture; |
| 1135 | |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1136 | cm->seq_params.display_model_info_present_flag = |
| 1137 | oxcf->display_model_info_present_flag; |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 1138 | cm->seq_params.decoder_model_info_present_flag = |
| 1139 | oxcf->decoder_model_info_present_flag; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1140 | if (oxcf->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1141 | // set the decoder model parameters in schedule mode |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1142 | cm->buffer_model.num_units_in_decoding_tick = |
| 1143 | oxcf->buffer_model.num_units_in_decoding_tick; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 1144 | cm->buffer_removal_time_present = 1; |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 1145 | av1_set_aom_dec_model_info(&cm->buffer_model); |
| 1146 | av1_set_dec_model_op_parameters(&cm->op_params[0]); |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 1147 | } else if (cm->timing_info_present && |
| 1148 | cm->timing_info.equal_picture_interval && |
| 1149 | !cm->seq_params.decoder_model_info_present_flag) { |
| 1150 | // set the decoder model parameters in resource availability mode |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 1151 | av1_set_resource_availability_parameters(&cm->op_params[0]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1152 | } else { |
| 1153 | cm->op_params[0].initial_display_delay = |
| 1154 | 10; // Default value (not signaled) |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1155 | } |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 1156 | |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 1157 | if (cm->seq_params.monochrome) { |
| 1158 | cm->seq_params.subsampling_x = 1; |
| 1159 | cm->seq_params.subsampling_y = 1; |
| 1160 | } else if (cm->seq_params.color_primaries == AOM_CICP_CP_BT_709 && |
| 1161 | cm->seq_params.transfer_characteristics == AOM_CICP_TC_SRGB && |
| 1162 | cm->seq_params.matrix_coefficients == AOM_CICP_MC_IDENTITY) { |
| 1163 | cm->seq_params.subsampling_x = 0; |
| 1164 | cm->seq_params.subsampling_y = 0; |
| 1165 | } else { |
| 1166 | if (cm->seq_params.profile == 0) { |
| 1167 | cm->seq_params.subsampling_x = 1; |
| 1168 | cm->seq_params.subsampling_y = 1; |
| 1169 | } else if (cm->seq_params.profile == 1) { |
| 1170 | cm->seq_params.subsampling_x = 0; |
| 1171 | cm->seq_params.subsampling_y = 0; |
| 1172 | } else { |
| 1173 | if (cm->seq_params.bit_depth == AOM_BITS_12) { |
| 1174 | cm->seq_params.subsampling_x = oxcf->chroma_subsampling_x; |
| 1175 | cm->seq_params.subsampling_y = oxcf->chroma_subsampling_y; |
| 1176 | } else { |
| 1177 | cm->seq_params.subsampling_x = 1; |
| 1178 | cm->seq_params.subsampling_y = 0; |
| 1179 | } |
| 1180 | } |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1183 | cm->width = oxcf->width; |
| 1184 | cm->height = oxcf->height; |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 1185 | set_sb_size(&cm->seq_params, |
| 1186 | select_sb_size(cpi)); // set sb size before allocations |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 1187 | alloc_compressor_data(cpi); |
Yaowu Xu | c7119a7 | 2018-03-29 09:59:37 -0700 | [diff] [blame] | 1188 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 1189 | update_film_grain_parameters(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1190 | |
| 1191 | // Single thread case: use counts in common. |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 1192 | cpi->td.counts = &cpi->counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1193 | |
| 1194 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1195 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1196 | |
| 1197 | cpi->static_mb_pct = 0; |
| 1198 | cpi->ref_frame_flags = 0; |
| 1199 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 1200 | // Reset resize pending flags |
| 1201 | cpi->resize_pending_width = 0; |
| 1202 | cpi->resize_pending_height = 0; |
| 1203 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1204 | init_buffer_indices(cpi); |
| 1205 | } |
| 1206 | |
| 1207 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1208 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1209 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 1210 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 1211 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 1212 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 1213 | |
| 1214 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 1215 | rc->optimal_buffer_level = |
| 1216 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1217 | rc->maximum_buffer_size = |
| 1218 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1219 | } |
| 1220 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1221 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \ |
| 1222 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1223 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1224 | cpi->fn_ptr[BT].vf = VF; \ |
| 1225 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1226 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1227 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 1228 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1229 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1230 | |
| 1231 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1232 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1233 | int source_stride, \ |
| 1234 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1235 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1236 | } \ |
| 1237 | static unsigned int fnname##_bits10( \ |
| 1238 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1239 | int ref_stride) { \ |
| 1240 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1241 | } \ |
| 1242 | static unsigned int fnname##_bits12( \ |
| 1243 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1244 | int ref_stride) { \ |
| 1245 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1246 | } |
| 1247 | |
| 1248 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1249 | static unsigned int fnname##_bits8( \ |
| 1250 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1251 | int ref_stride, const uint8_t *second_pred) { \ |
| 1252 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1253 | } \ |
| 1254 | static unsigned int fnname##_bits10( \ |
| 1255 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1256 | int ref_stride, const uint8_t *second_pred) { \ |
| 1257 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1258 | 2; \ |
| 1259 | } \ |
| 1260 | static unsigned int fnname##_bits12( \ |
| 1261 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1262 | int ref_stride, const uint8_t *second_pred) { \ |
| 1263 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1264 | 4; \ |
| 1265 | } |
| 1266 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1267 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1268 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1269 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1270 | unsigned int *sad_array) { \ |
| 1271 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1272 | } \ |
| 1273 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1274 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1275 | unsigned int *sad_array) { \ |
| 1276 | int i; \ |
| 1277 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1278 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1279 | } \ |
| 1280 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1281 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1282 | unsigned int *sad_array) { \ |
| 1283 | int i; \ |
| 1284 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1285 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1286 | } |
| 1287 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1288 | #define MAKE_BFP_JSADAVG_WRAPPER(fnname) \ |
| 1289 | static unsigned int fnname##_bits8( \ |
| 1290 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1291 | int ref_stride, const uint8_t *second_pred, \ |
Debargha Mukherjee | f90004a | 2018-12-20 13:35:06 -0800 | [diff] [blame] | 1292 | const DIST_WTD_COMP_PARAMS *jcp_param) { \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1293 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1294 | jcp_param); \ |
| 1295 | } \ |
| 1296 | static unsigned int fnname##_bits10( \ |
| 1297 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1298 | int ref_stride, const uint8_t *second_pred, \ |
Debargha Mukherjee | f90004a | 2018-12-20 13:35:06 -0800 | [diff] [blame] | 1299 | const DIST_WTD_COMP_PARAMS *jcp_param) { \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1300 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1301 | jcp_param) >> \ |
| 1302 | 2; \ |
| 1303 | } \ |
| 1304 | static unsigned int fnname##_bits12( \ |
| 1305 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1306 | int ref_stride, const uint8_t *second_pred, \ |
Debargha Mukherjee | f90004a | 2018-12-20 13:35:06 -0800 | [diff] [blame] | 1307 | const DIST_WTD_COMP_PARAMS *jcp_param) { \ |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1308 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1309 | jcp_param) >> \ |
| 1310 | 4; \ |
| 1311 | } |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1312 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1313 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1314 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1315 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1316 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1317 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1318 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1319 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1320 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1321 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1322 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1323 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1324 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1325 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1326 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1327 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1328 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1329 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1330 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1331 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1332 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1333 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1334 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1335 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1336 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1337 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1338 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1339 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1340 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1341 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1342 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1343 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1344 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1345 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1346 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1347 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1348 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1349 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1350 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1351 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1352 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1353 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1354 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1355 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1356 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1357 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1358 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1359 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1360 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1361 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1362 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16) |
| 1363 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg) |
| 1364 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d) |
| 1365 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4) |
| 1366 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg) |
| 1367 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d) |
| 1368 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32) |
| 1369 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg) |
| 1370 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d) |
| 1371 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8) |
| 1372 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg) |
| 1373 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1374 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64) |
| 1375 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg) |
| 1376 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d) |
| 1377 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16) |
| 1378 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg) |
| 1379 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1380 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1381 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x128_avg) |
| 1382 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x64_avg) |
| 1383 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x128_avg) |
| 1384 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x16_avg) |
| 1385 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x32_avg) |
| 1386 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x32_avg) |
| 1387 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x64_avg) |
| 1388 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x32_avg) |
| 1389 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x64_avg) |
| 1390 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x16_avg) |
| 1391 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x8_avg) |
| 1392 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x16_avg) |
| 1393 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x8_avg) |
| 1394 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x4_avg) |
| 1395 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x8_avg) |
| 1396 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x4_avg) |
| 1397 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x16_avg) |
| 1398 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x4_avg) |
| 1399 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x32_avg) |
| 1400 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x8_avg) |
| 1401 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x64_avg) |
| 1402 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x16_avg) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1403 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1404 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1405 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1406 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1407 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1408 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1409 | static unsigned int fnname##_bits8( \ |
| 1410 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1411 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1412 | int m_stride, int invert_mask) { \ |
| 1413 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1414 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1415 | } \ |
| 1416 | static unsigned int fnname##_bits10( \ |
| 1417 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1418 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1419 | int m_stride, int invert_mask) { \ |
| 1420 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1421 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1422 | 2; \ |
| 1423 | } \ |
| 1424 | static unsigned int fnname##_bits12( \ |
| 1425 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1426 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1427 | int m_stride, int invert_mask) { \ |
| 1428 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1429 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1430 | 4; \ |
| 1431 | } |
| 1432 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1433 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1434 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1435 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1436 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1437 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1438 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1439 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1440 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1441 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1442 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1443 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1444 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1445 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1446 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1447 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1448 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1449 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1450 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1451 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1452 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1453 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1454 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1455 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1456 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1457 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1458 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1459 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1460 | |
| 1461 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1462 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1463 | const int32_t *wsrc, \ |
| 1464 | const int32_t *msk) { \ |
| 1465 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1466 | } \ |
| 1467 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1468 | const int32_t *wsrc, \ |
| 1469 | const int32_t *msk) { \ |
| 1470 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1471 | } \ |
| 1472 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1473 | const int32_t *wsrc, \ |
| 1474 | const int32_t *msk) { \ |
| 1475 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1476 | } |
| 1477 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1478 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1479 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1480 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1481 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1482 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1483 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1484 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1485 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1486 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1487 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1488 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1489 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1490 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1491 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1492 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1493 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1494 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1495 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1496 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1497 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1498 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1499 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1500 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1501 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1502 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1503 | if (cm->seq_params.use_highbitdepth) { |
| 1504 | switch (cm->seq_params.bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1505 | case AOM_BITS_8: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1506 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1507 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1508 | aom_highbd_8_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1509 | aom_highbd_8_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1510 | aom_highbd_sad64x16x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1511 | aom_highbd_dist_wtd_sad64x16_avg_bits8, |
| 1512 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1513 | |
| 1514 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1515 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1516 | aom_highbd_8_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1517 | aom_highbd_8_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1518 | aom_highbd_sad16x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1519 | aom_highbd_dist_wtd_sad16x64_avg_bits8, |
| 1520 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1521 | |
| 1522 | HIGHBD_BFP( |
| 1523 | BLOCK_32X8, aom_highbd_sad32x8_bits8, aom_highbd_sad32x8_avg_bits8, |
| 1524 | aom_highbd_8_variance32x8, aom_highbd_8_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1525 | aom_highbd_8_sub_pixel_avg_variance32x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1526 | aom_highbd_sad32x8x4d_bits8, aom_highbd_dist_wtd_sad32x8_avg_bits8, |
| 1527 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x8) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1528 | |
| 1529 | HIGHBD_BFP( |
| 1530 | BLOCK_8X32, aom_highbd_sad8x32_bits8, aom_highbd_sad8x32_avg_bits8, |
| 1531 | aom_highbd_8_variance8x32, aom_highbd_8_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1532 | aom_highbd_8_sub_pixel_avg_variance8x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1533 | aom_highbd_sad8x32x4d_bits8, aom_highbd_dist_wtd_sad8x32_avg_bits8, |
| 1534 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1535 | |
| 1536 | HIGHBD_BFP( |
| 1537 | BLOCK_16X4, aom_highbd_sad16x4_bits8, aom_highbd_sad16x4_avg_bits8, |
| 1538 | aom_highbd_8_variance16x4, aom_highbd_8_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1539 | aom_highbd_8_sub_pixel_avg_variance16x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1540 | aom_highbd_sad16x4x4d_bits8, aom_highbd_dist_wtd_sad16x4_avg_bits8, |
| 1541 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x4) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1542 | |
| 1543 | HIGHBD_BFP( |
| 1544 | BLOCK_4X16, aom_highbd_sad4x16_bits8, aom_highbd_sad4x16_avg_bits8, |
| 1545 | aom_highbd_8_variance4x16, aom_highbd_8_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1546 | aom_highbd_8_sub_pixel_avg_variance4x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1547 | aom_highbd_sad4x16x4d_bits8, aom_highbd_dist_wtd_sad4x16_avg_bits8, |
| 1548 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance4x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1549 | |
| 1550 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1551 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1552 | aom_highbd_8_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1553 | aom_highbd_8_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1554 | aom_highbd_sad32x16x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1555 | aom_highbd_dist_wtd_sad32x16_avg_bits8, |
| 1556 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1557 | |
| 1558 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1559 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1560 | aom_highbd_8_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1561 | aom_highbd_8_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1562 | aom_highbd_sad16x32x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1563 | aom_highbd_dist_wtd_sad16x32_avg_bits8, |
| 1564 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1565 | |
| 1566 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1567 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1568 | aom_highbd_8_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1569 | aom_highbd_8_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1570 | aom_highbd_sad64x32x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1571 | aom_highbd_dist_wtd_sad64x32_avg_bits8, |
| 1572 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1573 | |
| 1574 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1575 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1576 | aom_highbd_8_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1577 | aom_highbd_8_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1578 | aom_highbd_sad32x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1579 | aom_highbd_dist_wtd_sad32x64_avg_bits8, |
| 1580 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1581 | |
| 1582 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1583 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1584 | aom_highbd_8_sub_pixel_variance32x32, |
| 1585 | aom_highbd_8_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1586 | aom_highbd_sad32x32x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1587 | aom_highbd_dist_wtd_sad32x32_avg_bits8, |
| 1588 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance32x32) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1589 | |
| 1590 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1591 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1592 | aom_highbd_8_sub_pixel_variance64x64, |
| 1593 | aom_highbd_8_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1594 | aom_highbd_sad64x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1595 | aom_highbd_dist_wtd_sad64x64_avg_bits8, |
| 1596 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1597 | |
| 1598 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1599 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1600 | aom_highbd_8_sub_pixel_variance16x16, |
| 1601 | aom_highbd_8_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1602 | aom_highbd_sad16x16x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1603 | aom_highbd_dist_wtd_sad16x16_avg_bits8, |
| 1604 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1605 | |
| 1606 | HIGHBD_BFP( |
| 1607 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1608 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1609 | aom_highbd_8_sub_pixel_avg_variance16x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1610 | aom_highbd_sad16x8x4d_bits8, aom_highbd_dist_wtd_sad16x8_avg_bits8, |
| 1611 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance16x8) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1612 | |
| 1613 | HIGHBD_BFP( |
| 1614 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1615 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1616 | aom_highbd_8_sub_pixel_avg_variance8x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1617 | aom_highbd_sad8x16x4d_bits8, aom_highbd_dist_wtd_sad8x16_avg_bits8, |
| 1618 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x16) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1619 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1620 | HIGHBD_BFP( |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1621 | BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8, |
| 1622 | aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8, |
| 1623 | aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x4d_bits8, |
| 1624 | aom_highbd_dist_wtd_sad8x8_avg_bits8, |
| 1625 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x8) |
| 1626 | |
| 1627 | HIGHBD_BFP( |
| 1628 | BLOCK_8X4, aom_highbd_sad8x4_bits8, aom_highbd_sad8x4_avg_bits8, |
| 1629 | aom_highbd_8_variance8x4, aom_highbd_8_sub_pixel_variance8x4, |
| 1630 | aom_highbd_8_sub_pixel_avg_variance8x4, aom_highbd_sad8x4x4d_bits8, |
| 1631 | aom_highbd_dist_wtd_sad8x4_avg_bits8, |
| 1632 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance8x4) |
| 1633 | |
| 1634 | HIGHBD_BFP( |
| 1635 | BLOCK_4X8, aom_highbd_sad4x8_bits8, aom_highbd_sad4x8_avg_bits8, |
| 1636 | aom_highbd_8_variance4x8, aom_highbd_8_sub_pixel_variance4x8, |
| 1637 | aom_highbd_8_sub_pixel_avg_variance4x8, aom_highbd_sad4x8x4d_bits8, |
| 1638 | aom_highbd_dist_wtd_sad4x8_avg_bits8, |
| 1639 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance4x8) |
| 1640 | |
| 1641 | HIGHBD_BFP( |
| 1642 | BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8, |
| 1643 | aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4, |
| 1644 | aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x4d_bits8, |
| 1645 | aom_highbd_dist_wtd_sad4x4_avg_bits8, |
| 1646 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance4x4) |
| 1647 | |
| 1648 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1649 | aom_highbd_sad128x128_avg_bits8, |
| 1650 | aom_highbd_8_variance128x128, |
| 1651 | aom_highbd_8_sub_pixel_variance128x128, |
| 1652 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1653 | aom_highbd_sad128x128x4d_bits8, |
| 1654 | aom_highbd_dist_wtd_sad128x128_avg_bits8, |
| 1655 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance128x128) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1656 | |
| 1657 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1658 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1659 | aom_highbd_8_sub_pixel_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1660 | aom_highbd_8_sub_pixel_avg_variance128x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1661 | aom_highbd_sad128x64x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1662 | aom_highbd_dist_wtd_sad128x64_avg_bits8, |
| 1663 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance128x64) |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1664 | |
| 1665 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1666 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1667 | aom_highbd_8_sub_pixel_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1668 | aom_highbd_8_sub_pixel_avg_variance64x128, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1669 | aom_highbd_sad64x128x4d_bits8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1670 | aom_highbd_dist_wtd_sad64x128_avg_bits8, |
| 1671 | aom_highbd_8_dist_wtd_sub_pixel_avg_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1672 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1673 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1674 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1675 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1676 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1677 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1678 | aom_highbd_8_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1679 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1680 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1681 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1682 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1683 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1684 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1685 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1686 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1687 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1688 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1689 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1690 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1691 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1692 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1693 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1694 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1695 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1696 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1697 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1698 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1699 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1700 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1701 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1702 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1703 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1704 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1705 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1706 | aom_highbd_8_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1707 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1708 | aom_highbd_8_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1709 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1710 | aom_highbd_8_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1711 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1712 | aom_highbd_8_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1713 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1714 | aom_highbd_8_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1715 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1716 | aom_highbd_8_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1717 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1718 | aom_highbd_obmc_variance128x128, |
| 1719 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1720 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1721 | aom_highbd_obmc_variance128x64, |
| 1722 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1723 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1724 | aom_highbd_obmc_variance64x128, |
| 1725 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1726 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1727 | aom_highbd_obmc_variance64x64, |
| 1728 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1729 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1730 | aom_highbd_obmc_variance64x32, |
| 1731 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1732 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1733 | aom_highbd_obmc_variance32x64, |
| 1734 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1735 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1736 | aom_highbd_obmc_variance32x32, |
| 1737 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1738 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1739 | aom_highbd_obmc_variance32x16, |
| 1740 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1741 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1742 | aom_highbd_obmc_variance16x32, |
| 1743 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1744 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1745 | aom_highbd_obmc_variance16x16, |
| 1746 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1747 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1748 | aom_highbd_obmc_variance8x16, |
| 1749 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1750 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1751 | aom_highbd_obmc_variance16x8, |
| 1752 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1753 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1754 | aom_highbd_obmc_variance8x8, |
| 1755 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 1756 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 1757 | aom_highbd_obmc_variance4x8, |
| 1758 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 1759 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 1760 | aom_highbd_obmc_variance8x4, |
| 1761 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 1762 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 1763 | aom_highbd_obmc_variance4x4, |
| 1764 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1765 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 1766 | aom_highbd_obmc_variance64x16, |
| 1767 | aom_highbd_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1768 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 1769 | aom_highbd_obmc_variance16x64, |
| 1770 | aom_highbd_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1771 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 1772 | aom_highbd_obmc_variance32x8, |
| 1773 | aom_highbd_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1774 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 1775 | aom_highbd_obmc_variance8x32, |
| 1776 | aom_highbd_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1777 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 1778 | aom_highbd_obmc_variance16x4, |
| 1779 | aom_highbd_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1780 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 1781 | aom_highbd_obmc_variance4x16, |
| 1782 | aom_highbd_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1783 | break; |
| 1784 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1785 | case AOM_BITS_10: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1786 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 1787 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 1788 | aom_highbd_10_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1789 | aom_highbd_10_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1790 | aom_highbd_sad64x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1791 | aom_highbd_dist_wtd_sad64x16_avg_bits10, |
| 1792 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1793 | |
| 1794 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 1795 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 1796 | aom_highbd_10_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1797 | aom_highbd_10_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1798 | aom_highbd_sad16x64x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1799 | aom_highbd_dist_wtd_sad16x64_avg_bits10, |
| 1800 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1801 | |
| 1802 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 1803 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 1804 | aom_highbd_10_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1805 | aom_highbd_10_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1806 | aom_highbd_sad32x8x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1807 | aom_highbd_dist_wtd_sad32x8_avg_bits10, |
| 1808 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1809 | |
| 1810 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 1811 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 1812 | aom_highbd_10_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1813 | aom_highbd_10_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1814 | aom_highbd_sad8x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1815 | aom_highbd_dist_wtd_sad8x32_avg_bits10, |
| 1816 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1817 | |
| 1818 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 1819 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 1820 | aom_highbd_10_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1821 | aom_highbd_10_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1822 | aom_highbd_sad16x4x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1823 | aom_highbd_dist_wtd_sad16x4_avg_bits10, |
| 1824 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1825 | |
| 1826 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 1827 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 1828 | aom_highbd_10_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1829 | aom_highbd_10_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1830 | aom_highbd_sad4x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1831 | aom_highbd_dist_wtd_sad4x16_avg_bits10, |
| 1832 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1833 | |
| 1834 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 1835 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 1836 | aom_highbd_10_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1837 | aom_highbd_10_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1838 | aom_highbd_sad32x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1839 | aom_highbd_dist_wtd_sad32x16_avg_bits10, |
| 1840 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1841 | |
| 1842 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 1843 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 1844 | aom_highbd_10_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1845 | aom_highbd_10_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1846 | aom_highbd_sad16x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1847 | aom_highbd_dist_wtd_sad16x32_avg_bits10, |
| 1848 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1849 | |
| 1850 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 1851 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 1852 | aom_highbd_10_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1853 | aom_highbd_10_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1854 | aom_highbd_sad64x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1855 | aom_highbd_dist_wtd_sad64x32_avg_bits10, |
| 1856 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1857 | |
| 1858 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 1859 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 1860 | aom_highbd_10_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1861 | aom_highbd_10_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1862 | aom_highbd_sad32x64x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1863 | aom_highbd_dist_wtd_sad32x64_avg_bits10, |
| 1864 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1865 | |
| 1866 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 1867 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 1868 | aom_highbd_10_sub_pixel_variance32x32, |
| 1869 | aom_highbd_10_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1870 | aom_highbd_sad32x32x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1871 | aom_highbd_dist_wtd_sad32x32_avg_bits10, |
| 1872 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance32x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1873 | |
| 1874 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 1875 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 1876 | aom_highbd_10_sub_pixel_variance64x64, |
| 1877 | aom_highbd_10_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1878 | aom_highbd_sad64x64x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1879 | aom_highbd_dist_wtd_sad64x64_avg_bits10, |
| 1880 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1881 | |
| 1882 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 1883 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 1884 | aom_highbd_10_sub_pixel_variance16x16, |
| 1885 | aom_highbd_10_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1886 | aom_highbd_sad16x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1887 | aom_highbd_dist_wtd_sad16x16_avg_bits10, |
| 1888 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1889 | |
| 1890 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 1891 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 1892 | aom_highbd_10_sub_pixel_variance16x8, |
| 1893 | aom_highbd_10_sub_pixel_avg_variance16x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1894 | aom_highbd_sad16x8x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1895 | aom_highbd_dist_wtd_sad16x8_avg_bits10, |
| 1896 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance16x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1897 | |
| 1898 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 1899 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 1900 | aom_highbd_10_sub_pixel_variance8x16, |
| 1901 | aom_highbd_10_sub_pixel_avg_variance8x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1902 | aom_highbd_sad8x16x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1903 | aom_highbd_dist_wtd_sad8x16_avg_bits10, |
| 1904 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1905 | |
| 1906 | HIGHBD_BFP( |
| 1907 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 1908 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1909 | aom_highbd_10_sub_pixel_avg_variance8x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1910 | aom_highbd_sad8x8x4d_bits10, aom_highbd_dist_wtd_sad8x8_avg_bits10, |
| 1911 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1912 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1913 | HIGHBD_BFP( |
| 1914 | BLOCK_8X4, aom_highbd_sad8x4_bits10, aom_highbd_sad8x4_avg_bits10, |
| 1915 | aom_highbd_10_variance8x4, aom_highbd_10_sub_pixel_variance8x4, |
| 1916 | aom_highbd_10_sub_pixel_avg_variance8x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1917 | aom_highbd_sad8x4x4d_bits10, aom_highbd_dist_wtd_sad8x4_avg_bits10, |
| 1918 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance8x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1919 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1920 | HIGHBD_BFP( |
| 1921 | BLOCK_4X8, aom_highbd_sad4x8_bits10, aom_highbd_sad4x8_avg_bits10, |
| 1922 | aom_highbd_10_variance4x8, aom_highbd_10_sub_pixel_variance4x8, |
| 1923 | aom_highbd_10_sub_pixel_avg_variance4x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1924 | aom_highbd_sad4x8x4d_bits10, aom_highbd_dist_wtd_sad4x8_avg_bits10, |
| 1925 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance4x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1926 | |
| 1927 | HIGHBD_BFP( |
| 1928 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 1929 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1930 | aom_highbd_10_sub_pixel_avg_variance4x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1931 | aom_highbd_sad4x4x4d_bits10, aom_highbd_dist_wtd_sad4x4_avg_bits10, |
| 1932 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance4x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1933 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 1934 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 1935 | aom_highbd_sad128x128_avg_bits10, |
| 1936 | aom_highbd_10_variance128x128, |
| 1937 | aom_highbd_10_sub_pixel_variance128x128, |
| 1938 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 1939 | aom_highbd_sad128x128x4d_bits10, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1940 | aom_highbd_dist_wtd_sad128x128_avg_bits10, |
| 1941 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance128x128); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1942 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1943 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 1944 | aom_highbd_sad128x64_avg_bits10, |
| 1945 | aom_highbd_10_variance128x64, |
| 1946 | aom_highbd_10_sub_pixel_variance128x64, |
| 1947 | aom_highbd_10_sub_pixel_avg_variance128x64, |
| 1948 | aom_highbd_sad128x64x4d_bits10, |
| 1949 | aom_highbd_dist_wtd_sad128x64_avg_bits10, |
| 1950 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance128x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1951 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 1952 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 1953 | aom_highbd_sad64x128_avg_bits10, |
| 1954 | aom_highbd_10_variance64x128, |
| 1955 | aom_highbd_10_sub_pixel_variance64x128, |
| 1956 | aom_highbd_10_sub_pixel_avg_variance64x128, |
| 1957 | aom_highbd_sad64x128x4d_bits10, |
| 1958 | aom_highbd_dist_wtd_sad64x128_avg_bits10, |
| 1959 | aom_highbd_10_dist_wtd_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1960 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1961 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 1962 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 1963 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 1964 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 1965 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 1966 | aom_highbd_10_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1967 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 1968 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 1969 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 1970 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 1971 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 1972 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 1973 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 1974 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 1975 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 1976 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 1977 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 1978 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 1979 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 1980 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 1981 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 1982 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 1983 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 1984 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 1985 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 1986 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 1987 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 1988 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 1989 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 1990 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 1991 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 1992 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1993 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 1994 | aom_highbd_10_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1995 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 1996 | aom_highbd_10_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1997 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 1998 | aom_highbd_10_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1999 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 2000 | aom_highbd_10_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2001 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 2002 | aom_highbd_10_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2003 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 2004 | aom_highbd_10_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2005 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 2006 | aom_highbd_10_obmc_variance128x128, |
| 2007 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 2008 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 2009 | aom_highbd_10_obmc_variance128x64, |
| 2010 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 2011 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 2012 | aom_highbd_10_obmc_variance64x128, |
| 2013 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2014 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 2015 | aom_highbd_10_obmc_variance64x64, |
| 2016 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 2017 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 2018 | aom_highbd_10_obmc_variance64x32, |
| 2019 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 2020 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 2021 | aom_highbd_10_obmc_variance32x64, |
| 2022 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 2023 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 2024 | aom_highbd_10_obmc_variance32x32, |
| 2025 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 2026 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 2027 | aom_highbd_10_obmc_variance32x16, |
| 2028 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 2029 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 2030 | aom_highbd_10_obmc_variance16x32, |
| 2031 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 2032 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 2033 | aom_highbd_10_obmc_variance16x16, |
| 2034 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 2035 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 2036 | aom_highbd_10_obmc_variance8x16, |
| 2037 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 2038 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 2039 | aom_highbd_10_obmc_variance16x8, |
| 2040 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 2041 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 2042 | aom_highbd_10_obmc_variance8x8, |
| 2043 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 2044 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 2045 | aom_highbd_10_obmc_variance4x8, |
| 2046 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 2047 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 2048 | aom_highbd_10_obmc_variance8x4, |
| 2049 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 2050 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 2051 | aom_highbd_10_obmc_variance4x4, |
| 2052 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2053 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2054 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 2055 | aom_highbd_10_obmc_variance64x16, |
| 2056 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 2057 | |
| 2058 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 2059 | aom_highbd_10_obmc_variance16x64, |
| 2060 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 2061 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2062 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 2063 | aom_highbd_10_obmc_variance32x8, |
| 2064 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 2065 | |
| 2066 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 2067 | aom_highbd_10_obmc_variance8x32, |
| 2068 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 2069 | |
| 2070 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 2071 | aom_highbd_10_obmc_variance16x4, |
| 2072 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 2073 | |
| 2074 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 2075 | aom_highbd_10_obmc_variance4x16, |
| 2076 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2077 | break; |
| 2078 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2079 | case AOM_BITS_12: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2080 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 2081 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 2082 | aom_highbd_12_sub_pixel_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2083 | aom_highbd_12_sub_pixel_avg_variance64x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2084 | aom_highbd_sad64x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2085 | aom_highbd_dist_wtd_sad64x16_avg_bits12, |
| 2086 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2087 | |
| 2088 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 2089 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 2090 | aom_highbd_12_sub_pixel_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2091 | aom_highbd_12_sub_pixel_avg_variance16x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2092 | aom_highbd_sad16x64x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2093 | aom_highbd_dist_wtd_sad16x64_avg_bits12, |
| 2094 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2095 | |
| 2096 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 2097 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 2098 | aom_highbd_12_sub_pixel_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2099 | aom_highbd_12_sub_pixel_avg_variance32x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2100 | aom_highbd_sad32x8x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2101 | aom_highbd_dist_wtd_sad32x8_avg_bits12, |
| 2102 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2103 | |
| 2104 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 2105 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 2106 | aom_highbd_12_sub_pixel_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2107 | aom_highbd_12_sub_pixel_avg_variance8x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2108 | aom_highbd_sad8x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2109 | aom_highbd_dist_wtd_sad8x32_avg_bits12, |
| 2110 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2111 | |
| 2112 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 2113 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 2114 | aom_highbd_12_sub_pixel_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2115 | aom_highbd_12_sub_pixel_avg_variance16x4, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2116 | aom_highbd_sad16x4x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2117 | aom_highbd_dist_wtd_sad16x4_avg_bits12, |
| 2118 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2119 | |
| 2120 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 2121 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 2122 | aom_highbd_12_sub_pixel_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2123 | aom_highbd_12_sub_pixel_avg_variance4x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2124 | aom_highbd_sad4x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2125 | aom_highbd_dist_wtd_sad4x16_avg_bits12, |
| 2126 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance4x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2127 | |
| 2128 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 2129 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 2130 | aom_highbd_12_sub_pixel_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2131 | aom_highbd_12_sub_pixel_avg_variance32x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2132 | aom_highbd_sad32x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2133 | aom_highbd_dist_wtd_sad32x16_avg_bits12, |
| 2134 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2135 | |
| 2136 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 2137 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 2138 | aom_highbd_12_sub_pixel_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2139 | aom_highbd_12_sub_pixel_avg_variance16x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2140 | aom_highbd_sad16x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2141 | aom_highbd_dist_wtd_sad16x32_avg_bits12, |
| 2142 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2143 | |
| 2144 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 2145 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 2146 | aom_highbd_12_sub_pixel_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2147 | aom_highbd_12_sub_pixel_avg_variance64x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2148 | aom_highbd_sad64x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2149 | aom_highbd_dist_wtd_sad64x32_avg_bits12, |
| 2150 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2151 | |
| 2152 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 2153 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 2154 | aom_highbd_12_sub_pixel_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2155 | aom_highbd_12_sub_pixel_avg_variance32x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2156 | aom_highbd_sad32x64x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2157 | aom_highbd_dist_wtd_sad32x64_avg_bits12, |
| 2158 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2159 | |
| 2160 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 2161 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 2162 | aom_highbd_12_sub_pixel_variance32x32, |
| 2163 | aom_highbd_12_sub_pixel_avg_variance32x32, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2164 | aom_highbd_sad32x32x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2165 | aom_highbd_dist_wtd_sad32x32_avg_bits12, |
| 2166 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance32x32); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2167 | |
| 2168 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2169 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2170 | aom_highbd_12_sub_pixel_variance64x64, |
| 2171 | aom_highbd_12_sub_pixel_avg_variance64x64, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2172 | aom_highbd_sad64x64x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2173 | aom_highbd_dist_wtd_sad64x64_avg_bits12, |
| 2174 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2175 | |
| 2176 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2177 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2178 | aom_highbd_12_sub_pixel_variance16x16, |
| 2179 | aom_highbd_12_sub_pixel_avg_variance16x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2180 | aom_highbd_sad16x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2181 | aom_highbd_dist_wtd_sad16x16_avg_bits12, |
| 2182 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2183 | |
| 2184 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2185 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2186 | aom_highbd_12_sub_pixel_variance16x8, |
| 2187 | aom_highbd_12_sub_pixel_avg_variance16x8, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2188 | aom_highbd_sad16x8x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2189 | aom_highbd_dist_wtd_sad16x8_avg_bits12, |
| 2190 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance16x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2191 | |
| 2192 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2193 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2194 | aom_highbd_12_sub_pixel_variance8x16, |
| 2195 | aom_highbd_12_sub_pixel_avg_variance8x16, |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2196 | aom_highbd_sad8x16x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2197 | aom_highbd_dist_wtd_sad8x16_avg_bits12, |
| 2198 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x16); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2199 | |
| 2200 | HIGHBD_BFP( |
| 2201 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2202 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2203 | aom_highbd_12_sub_pixel_avg_variance8x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2204 | aom_highbd_sad8x8x4d_bits12, aom_highbd_dist_wtd_sad8x8_avg_bits12, |
| 2205 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2206 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2207 | HIGHBD_BFP( |
| 2208 | BLOCK_8X4, aom_highbd_sad8x4_bits12, aom_highbd_sad8x4_avg_bits12, |
| 2209 | aom_highbd_12_variance8x4, aom_highbd_12_sub_pixel_variance8x4, |
| 2210 | aom_highbd_12_sub_pixel_avg_variance8x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2211 | aom_highbd_sad8x4x4d_bits12, aom_highbd_dist_wtd_sad8x4_avg_bits12, |
| 2212 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance8x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2213 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2214 | HIGHBD_BFP( |
| 2215 | BLOCK_4X8, aom_highbd_sad4x8_bits12, aom_highbd_sad4x8_avg_bits12, |
| 2216 | aom_highbd_12_variance4x8, aom_highbd_12_sub_pixel_variance4x8, |
| 2217 | aom_highbd_12_sub_pixel_avg_variance4x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2218 | aom_highbd_sad4x8x4d_bits12, aom_highbd_dist_wtd_sad4x8_avg_bits12, |
| 2219 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance4x8); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2220 | |
| 2221 | HIGHBD_BFP( |
| 2222 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2223 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2224 | aom_highbd_12_sub_pixel_avg_variance4x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2225 | aom_highbd_sad4x4x4d_bits12, aom_highbd_dist_wtd_sad4x4_avg_bits12, |
| 2226 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance4x4); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2227 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2228 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2229 | aom_highbd_sad128x128_avg_bits12, |
| 2230 | aom_highbd_12_variance128x128, |
| 2231 | aom_highbd_12_sub_pixel_variance128x128, |
| 2232 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2233 | aom_highbd_sad128x128x4d_bits12, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2234 | aom_highbd_dist_wtd_sad128x128_avg_bits12, |
| 2235 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance128x128); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2236 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2237 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2238 | aom_highbd_sad128x64_avg_bits12, |
| 2239 | aom_highbd_12_variance128x64, |
| 2240 | aom_highbd_12_sub_pixel_variance128x64, |
| 2241 | aom_highbd_12_sub_pixel_avg_variance128x64, |
| 2242 | aom_highbd_sad128x64x4d_bits12, |
| 2243 | aom_highbd_dist_wtd_sad128x64_avg_bits12, |
| 2244 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance128x64); |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2245 | |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2246 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2247 | aom_highbd_sad64x128_avg_bits12, |
| 2248 | aom_highbd_12_variance64x128, |
| 2249 | aom_highbd_12_sub_pixel_variance64x128, |
| 2250 | aom_highbd_12_sub_pixel_avg_variance64x128, |
| 2251 | aom_highbd_sad64x128x4d_bits12, |
| 2252 | aom_highbd_dist_wtd_sad64x128_avg_bits12, |
| 2253 | aom_highbd_12_dist_wtd_sub_pixel_avg_variance64x128); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2254 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2255 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2256 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2257 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2258 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2259 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2260 | aom_highbd_12_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2261 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2262 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2263 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2264 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2265 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2266 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2267 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2268 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2269 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2270 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2271 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2272 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2273 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2274 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2275 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2276 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2277 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2278 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2279 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2280 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2281 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2282 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2283 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2284 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2285 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2286 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2287 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2288 | aom_highbd_12_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2289 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2290 | aom_highbd_12_masked_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2291 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2292 | aom_highbd_12_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2293 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2294 | aom_highbd_12_masked_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2295 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2296 | aom_highbd_12_masked_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2297 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2298 | aom_highbd_12_masked_sub_pixel_variance4x16) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2299 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2300 | aom_highbd_12_obmc_variance128x128, |
| 2301 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2302 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2303 | aom_highbd_12_obmc_variance128x64, |
| 2304 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 2305 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 2306 | aom_highbd_12_obmc_variance64x128, |
| 2307 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2308 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 2309 | aom_highbd_12_obmc_variance64x64, |
| 2310 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 2311 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 2312 | aom_highbd_12_obmc_variance64x32, |
| 2313 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 2314 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 2315 | aom_highbd_12_obmc_variance32x64, |
| 2316 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 2317 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 2318 | aom_highbd_12_obmc_variance32x32, |
| 2319 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 2320 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 2321 | aom_highbd_12_obmc_variance32x16, |
| 2322 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 2323 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 2324 | aom_highbd_12_obmc_variance16x32, |
| 2325 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 2326 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 2327 | aom_highbd_12_obmc_variance16x16, |
| 2328 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 2329 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 2330 | aom_highbd_12_obmc_variance8x16, |
| 2331 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 2332 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 2333 | aom_highbd_12_obmc_variance16x8, |
| 2334 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 2335 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 2336 | aom_highbd_12_obmc_variance8x8, |
| 2337 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 2338 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 2339 | aom_highbd_12_obmc_variance4x8, |
| 2340 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 2341 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 2342 | aom_highbd_12_obmc_variance8x4, |
| 2343 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 2344 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 2345 | aom_highbd_12_obmc_variance4x4, |
| 2346 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2347 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 2348 | aom_highbd_12_obmc_variance64x16, |
| 2349 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2350 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 2351 | aom_highbd_12_obmc_variance16x64, |
| 2352 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2353 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 2354 | aom_highbd_12_obmc_variance32x8, |
| 2355 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2356 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 2357 | aom_highbd_12_obmc_variance8x32, |
| 2358 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2359 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 2360 | aom_highbd_12_obmc_variance16x4, |
| 2361 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2362 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 2363 | aom_highbd_12_obmc_variance4x16, |
| 2364 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2365 | break; |
| 2366 | |
| 2367 | default: |
| 2368 | assert(0 && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2369 | "cm->seq_params.bit_depth should be AOM_BITS_8, " |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2370 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2371 | } |
| 2372 | } |
| 2373 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2374 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2375 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 2376 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2377 | |
| 2378 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2379 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2380 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2381 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2382 | |
| 2383 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2384 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2385 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2386 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2387 | |
| 2388 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2389 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2390 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2391 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2392 | } |
| 2393 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2394 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 2395 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2396 | SequenceHeader *const seq_params = &cm->seq_params; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2397 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2398 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2399 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2400 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2401 | if (seq_params->profile != oxcf->profile) seq_params->profile = oxcf->profile; |
| 2402 | seq_params->bit_depth = oxcf->bit_depth; |
| 2403 | seq_params->color_primaries = oxcf->color_primaries; |
| 2404 | seq_params->transfer_characteristics = oxcf->transfer_characteristics; |
| 2405 | seq_params->matrix_coefficients = oxcf->matrix_coefficients; |
| 2406 | seq_params->monochrome = oxcf->monochrome; |
| 2407 | seq_params->chroma_sample_position = oxcf->chroma_sample_position; |
| 2408 | seq_params->color_range = oxcf->color_range; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2409 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2410 | assert(IMPLIES(seq_params->profile <= PROFILE_1, |
| 2411 | seq_params->bit_depth <= AOM_BITS_10)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2412 | |
Hui Su | 2aa492c | 2019-03-12 15:18:18 -0700 | [diff] [blame] | 2413 | memcpy(cpi->target_seq_level_idx, oxcf->target_seq_level_idx, |
| 2414 | sizeof(cpi->target_seq_level_idx)); |
| 2415 | cpi->keep_level_stats = 0; |
| 2416 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
| 2417 | if (cpi->target_seq_level_idx[i] < SEQ_LEVELS) { |
Hui Su | 72ff048 | 2019-05-28 14:07:37 -0700 | [diff] [blame] | 2418 | cpi->keep_level_stats |= 1u << i; |
Hui Su | c3a8d37 | 2019-05-28 15:52:45 -0700 | [diff] [blame] | 2419 | if (!cpi->level_info[i]) { |
| 2420 | CHECK_MEM_ERROR(cm, cpi->level_info[i], |
| 2421 | aom_calloc(1, sizeof(*cpi->level_info[i]))); |
| 2422 | } |
Hui Su | 2aa492c | 2019-03-12 15:18:18 -0700 | [diff] [blame] | 2423 | } |
| 2424 | } |
kyslov | abeeb7c | 2019-03-06 18:35:04 -0800 | [diff] [blame] | 2425 | |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2426 | cm->timing_info_present = oxcf->timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2427 | cm->timing_info.num_units_in_display_tick = |
| 2428 | oxcf->timing_info.num_units_in_display_tick; |
| 2429 | cm->timing_info.time_scale = oxcf->timing_info.time_scale; |
| 2430 | cm->timing_info.equal_picture_interval = |
| 2431 | oxcf->timing_info.equal_picture_interval; |
| 2432 | cm->timing_info.num_ticks_per_picture = |
| 2433 | oxcf->timing_info.num_ticks_per_picture; |
| 2434 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2435 | seq_params->display_model_info_present_flag = |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2436 | oxcf->display_model_info_present_flag; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2437 | seq_params->decoder_model_info_present_flag = |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 2438 | oxcf->decoder_model_info_present_flag; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2439 | if (oxcf->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2440 | // set the decoder model parameters in schedule mode |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2441 | cm->buffer_model.num_units_in_decoding_tick = |
| 2442 | oxcf->buffer_model.num_units_in_decoding_tick; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 2443 | cm->buffer_removal_time_present = 1; |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 2444 | av1_set_aom_dec_model_info(&cm->buffer_model); |
| 2445 | av1_set_dec_model_op_parameters(&cm->op_params[0]); |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2446 | } else if (cm->timing_info_present && |
| 2447 | cm->timing_info.equal_picture_interval && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2448 | !seq_params->decoder_model_info_present_flag) { |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2449 | // set the decoder model parameters in resource availability mode |
Yaowu Xu | eb40e47 | 2019-05-03 09:17:37 -0700 | [diff] [blame] | 2450 | av1_set_resource_availability_parameters(&cm->op_params[0]); |
Andrey Norkin | c7511de | 2018-06-22 12:31:06 -0700 | [diff] [blame] | 2451 | } else { |
| 2452 | cm->op_params[0].initial_display_delay = |
| 2453 | 10; // Default value (not signaled) |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 2454 | } |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2455 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2456 | update_film_grain_parameters(cpi, oxcf); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 2457 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2458 | cpi->oxcf = *oxcf; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 2459 | cpi->common.options = oxcf->cfg; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2460 | x->e_mbd.bd = (int)seq_params->bit_depth; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2461 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2462 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2463 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2464 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 2465 | } else { |
| 2466 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 2467 | } |
| 2468 | |
| 2469 | cpi->refresh_last_frame = 1; |
| 2470 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2471 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 2472 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2473 | |
Debargha Mukherjee | 229fdc8 | 2018-03-10 07:45:33 -0800 | [diff] [blame] | 2474 | cm->refresh_frame_context = (oxcf->frame_parallel_decoding_mode) |
| 2475 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 2476 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2477 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 2478 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2479 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 2480 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2481 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 2482 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 2483 | } |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2484 | |
| 2485 | if (x->tmp_conv_dst == NULL) { |
| 2486 | CHECK_MEM_ERROR( |
| 2487 | cm, x->tmp_conv_dst, |
| 2488 | 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] | 2489 | x->e_mbd.tmp_conv_dst = x->tmp_conv_dst; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2490 | } |
| 2491 | for (int i = 0; i < 2; ++i) { |
| 2492 | if (x->tmp_obmc_bufs[i] == NULL) { |
| 2493 | CHECK_MEM_ERROR(cm, x->tmp_obmc_bufs[i], |
wenyao.liu | 22d8ab3 | 2018-10-16 09:11:29 +0800 | [diff] [blame] | 2494 | aom_memalign(32, 2 * MAX_MB_PLANE * MAX_SB_SQUARE * |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2495 | sizeof(*x->tmp_obmc_bufs[i]))); |
Urvang Joshi | e58f6ec | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 2496 | x->e_mbd.tmp_obmc_bufs[i] = x->tmp_obmc_bufs[i]; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 2497 | } |
| 2498 | } |
| 2499 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2500 | av1_reset_segment_features(cm); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2501 | set_high_precision_mv(cpi, 1, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2502 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2503 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 2504 | |
| 2505 | // Under a configuration change, where maximum_buffer_size may change, |
| 2506 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2507 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2508 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2509 | |
| 2510 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2511 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2512 | |
| 2513 | // Set absolute upper and lower quality limits |
| 2514 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2515 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2516 | |
Urvang Joshi | b55cb5e | 2018-09-12 14:50:21 -0700 | [diff] [blame] | 2517 | cm->interp_filter = oxcf->large_scale_tile ? EIGHTTAP_REGULAR : SWITCHABLE; |
Yue Chen | 5380cb5 | 2018-02-23 15:33:21 -0800 | [diff] [blame] | 2518 | cm->switchable_motion_mode = 1; |
| 2519 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2520 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2521 | cm->render_width = cpi->oxcf.render_width; |
| 2522 | cm->render_height = cpi->oxcf.render_height; |
| 2523 | } else { |
| 2524 | cm->render_width = cpi->oxcf.width; |
| 2525 | cm->render_height = cpi->oxcf.height; |
| 2526 | } |
| 2527 | cm->width = cpi->oxcf.width; |
| 2528 | cm->height = cpi->oxcf.height; |
| 2529 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2530 | int sb_size = seq_params->sb_size; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 2531 | // Superblock size should not be updated after the first key frame. |
| 2532 | if (!cpi->seq_params_locked) { |
| 2533 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Hui Su | d909c2c | 2019-03-08 11:51:14 -0800 | [diff] [blame] | 2534 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) |
| 2535 | seq_params->tier[i] = (oxcf->tier_mask >> i) & 1; |
Urvang Joshi | e4530f8 | 2018-01-09 11:43:37 -0800 | [diff] [blame] | 2536 | } |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2537 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2538 | if (cpi->initial_width || sb_size != seq_params->sb_size) { |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 2539 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height || |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2540 | seq_params->sb_size != sb_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2541 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2542 | av1_free_pc_tree(&cpi->td, num_planes); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2543 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2544 | realloc_segmentation_maps(cpi); |
| 2545 | cpi->initial_width = cpi->initial_height = 0; |
| 2546 | } |
| 2547 | } |
| 2548 | update_frame_size(cpi); |
| 2549 | |
| 2550 | cpi->alt_ref_source = NULL; |
| 2551 | rc->is_src_frame_alt_ref = 0; |
| 2552 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2553 | set_tile_info(cpi); |
| 2554 | |
| 2555 | cpi->ext_refresh_frame_flags_pending = 0; |
| 2556 | cpi->ext_refresh_frame_context_pending = 0; |
| 2557 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2558 | highbd_set_var_fns(cpi); |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 2559 | |
Debargha Mukherjee | edd7725 | 2018-03-25 12:01:38 -0700 | [diff] [blame] | 2560 | // Init sequence level coding tools |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2561 | // This should not be called after the first key frame. |
| 2562 | if (!cpi->seq_params_locked) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2563 | seq_params->operating_points_cnt_minus_1 = |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 2564 | cm->number_spatial_layers > 1 ? cm->number_spatial_layers - 1 : 0; |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 2565 | init_seq_coding_tools(&cm->seq_params, cm, oxcf); |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2566 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2567 | } |
| 2568 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2569 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 2570 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2571 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2572 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2573 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2574 | |
| 2575 | if (!cm) return NULL; |
| 2576 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2577 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2578 | |
Wan-Teh Chang | a2fad3e | 2018-07-19 16:55:19 -0700 | [diff] [blame] | 2579 | // The jmp_buf is valid only for the duration of the function that calls |
| 2580 | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
| 2581 | // before it returns. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2582 | if (setjmp(cm->error.jmp)) { |
| 2583 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2584 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2585 | return 0; |
| 2586 | } |
| 2587 | |
| 2588 | cm->error.setjmp = 1; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2589 | cm->alloc_mi = enc_alloc_mi; |
| 2590 | cm->free_mi = enc_free_mi; |
| 2591 | cm->setup_mi = enc_setup_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2592 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2593 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2594 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 2595 | CHECK_MEM_ERROR( |
| 2596 | cm, cm->default_frame_context, |
| 2597 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->default_frame_context))); |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2598 | memset(cm->fc, 0, sizeof(*cm->fc)); |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 2599 | memset(cm->default_frame_context, 0, sizeof(*cm->default_frame_context)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2600 | |
| 2601 | cpi->resize_state = 0; |
| 2602 | cpi->resize_avg_qp = 0; |
| 2603 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2604 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2605 | cpi->common.buffer_pool = pool; |
| 2606 | |
| 2607 | init_config(cpi, oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2608 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2609 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 2610 | cm->current_frame.frame_number = 0; |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 2611 | cm->current_frame_id = -1; |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 2612 | cpi->seq_params_locked = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2613 | cpi->partition_search_skippable_frame = 0; |
| 2614 | cpi->tile_data = NULL; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 2615 | cpi->last_show_frame_buf = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2616 | realloc_segmentation_maps(cpi); |
| 2617 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 2618 | memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs)); |
| 2619 | memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp)); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2620 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2621 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 2622 | i++) { |
| 2623 | CHECK_MEM_ERROR( |
| 2624 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2625 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2628 | cpi->refresh_alt_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2629 | |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 2630 | av1_init_level_info(cpi->level_info); |
chiyotsai | d16a257 | 2019-03-05 17:48:10 -0800 | [diff] [blame] | 2631 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2632 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 2633 | #if CONFIG_INTERNAL_STATS |
| 2634 | cpi->b_calculate_blockiness = 1; |
| 2635 | cpi->b_calculate_consistency = 1; |
| 2636 | cpi->total_inconsistency = 0; |
| 2637 | cpi->psnr.worst = 100.0; |
| 2638 | cpi->worst_ssim = 100.0; |
| 2639 | |
| 2640 | cpi->count = 0; |
| 2641 | cpi->bytes = 0; |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 2642 | #if CONFIG_SPEED_STATS |
| 2643 | cpi->tx_search_count = 0; |
| 2644 | #endif // CONFIG_SPEED_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2645 | |
| 2646 | if (cpi->b_calculate_psnr) { |
| 2647 | cpi->total_sq_error = 0; |
| 2648 | cpi->total_samples = 0; |
| 2649 | cpi->tot_recode_hits = 0; |
| 2650 | cpi->summed_quality = 0; |
| 2651 | cpi->summed_weights = 0; |
| 2652 | } |
| 2653 | |
| 2654 | cpi->fastssim.worst = 100.0; |
| 2655 | cpi->psnrhvs.worst = 100.0; |
| 2656 | |
| 2657 | if (cpi->b_calculate_blockiness) { |
| 2658 | cpi->total_blockiness = 0; |
| 2659 | cpi->worst_blockiness = 0.0; |
| 2660 | } |
| 2661 | |
| 2662 | if (cpi->b_calculate_consistency) { |
| 2663 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2664 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2665 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 2666 | cpi->worst_consistency = 100.0; |
| 2667 | } |
| 2668 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2669 | #if CONFIG_ENTROPY_STATS |
| 2670 | av1_zero(aggregate_fc); |
| 2671 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2672 | |
| 2673 | cpi->first_time_stamp_ever = INT64_MAX; |
| 2674 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 2675 | cpi->td.mb.nmvcost[0] = &cpi->nmv_costs[0][MV_MAX]; |
| 2676 | cpi->td.mb.nmvcost[1] = &cpi->nmv_costs[1][MV_MAX]; |
| 2677 | cpi->td.mb.nmvcost_hp[0] = &cpi->nmv_costs_hp[0][MV_MAX]; |
| 2678 | 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] | 2679 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2680 | #ifdef OUTPUT_YUV_SKINMAP |
| 2681 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 2682 | #endif |
| 2683 | #ifdef OUTPUT_YUV_REC |
| 2684 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 2685 | #endif |
| 2686 | |
Jerome Jiang | 2612b4d | 2019-05-29 17:46:47 -0700 | [diff] [blame^] | 2687 | #if !CONFIG_REALTIME_ONLY |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2688 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2689 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2690 | } else if (oxcf->pass == 2) { |
| 2691 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 2692 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 2693 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2694 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 2695 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 2696 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 2697 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2698 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2699 | } |
Jerome Jiang | 2612b4d | 2019-05-29 17:46:47 -0700 | [diff] [blame^] | 2700 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2701 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2702 | CHECK_MEM_ERROR( |
| 2703 | cm, cpi->td.mb.above_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 2704 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 2705 | sizeof(*cpi->td.mb.above_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2706 | CHECK_MEM_ERROR( |
| 2707 | cm, cpi->td.mb.left_pred_buf, |
Yue Chen | 1a79925 | 2018-03-01 16:47:41 -0800 | [diff] [blame] | 2708 | (uint8_t *)aom_memalign(16, MAX_MB_PLANE * MAX_SB_SQUARE * |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 2709 | sizeof(*cpi->td.mb.left_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2710 | |
| 2711 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 2712 | (int32_t *)aom_memalign( |
| 2713 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 2714 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 2715 | CHECK_MEM_ERROR( |
| 2716 | cm, cpi->td.mb.inter_modes_info, |
| 2717 | (InterModesInfo *)aom_malloc(sizeof(*cpi->td.mb.inter_modes_info))); |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 2718 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 2719 | for (int x = 0; x < 2; x++) |
| 2720 | for (int y = 0; y < 2; y++) |
| 2721 | CHECK_MEM_ERROR( |
| 2722 | cm, cpi->td.mb.hash_value_buffer[x][y], |
| 2723 | (uint32_t *)aom_malloc(AOM_BUFFER_SIZE_FOR_BLOCK_HASH * |
| 2724 | sizeof(*cpi->td.mb.hash_value_buffer[0][0]))); |
| 2725 | |
| 2726 | cpi->td.mb.g_crc_initialized = 0; |
| 2727 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2728 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 2729 | (int32_t *)aom_memalign( |
| 2730 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 2731 | |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 2732 | av1_set_speed_features_framesize_independent(cpi, oxcf->speed); |
| 2733 | av1_set_speed_features_framesize_dependent(cpi, oxcf->speed); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2734 | |
Yue Chen | c9b23e0 | 2019-04-10 16:54:03 -0700 | [diff] [blame] | 2735 | for (int frame = 0; frame < MAX_LENGTH_TPL_FRAME_STATS; ++frame) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 2736 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); |
| 2737 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); |
| 2738 | |
| 2739 | CHECK_MEM_ERROR(cm, cpi->tpl_stats[frame].tpl_stats_ptr, |
| 2740 | aom_calloc(mi_rows * mi_cols, |
| 2741 | sizeof(*cpi->tpl_stats[frame].tpl_stats_ptr))); |
| 2742 | cpi->tpl_stats[frame].is_valid = 0; |
| 2743 | cpi->tpl_stats[frame].width = mi_cols; |
| 2744 | cpi->tpl_stats[frame].height = mi_rows; |
| 2745 | cpi->tpl_stats[frame].stride = mi_cols; |
| 2746 | cpi->tpl_stats[frame].mi_rows = cm->mi_rows; |
| 2747 | cpi->tpl_stats[frame].mi_cols = cm->mi_cols; |
| 2748 | } |
| 2749 | |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 2750 | #if CONFIG_COLLECT_PARTITION_STATS == 2 |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 2751 | av1_zero(cpi->partition_stats); |
| 2752 | #endif |
| 2753 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2754 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \ |
| 2755 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 2756 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 2757 | cpi->fn_ptr[BT].vf = VF; \ |
| 2758 | cpi->fn_ptr[BT].svf = SVF; \ |
| 2759 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 2760 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 2761 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2762 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2763 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2764 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2765 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2766 | aom_sad4x16x4d, aom_dist_wtd_sad4x16_avg, |
| 2767 | aom_dist_wtd_sub_pixel_avg_variance4x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2768 | |
| 2769 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2770 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2771 | aom_sad16x4x4d, aom_dist_wtd_sad16x4_avg, |
| 2772 | aom_dist_wtd_sub_pixel_avg_variance16x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2773 | |
| 2774 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2775 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2776 | aom_sad8x32x4d, aom_dist_wtd_sad8x32_avg, |
| 2777 | aom_dist_wtd_sub_pixel_avg_variance8x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2778 | |
| 2779 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2780 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2781 | aom_sad32x8x4d, aom_dist_wtd_sad32x8_avg, |
| 2782 | aom_dist_wtd_sub_pixel_avg_variance32x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2783 | |
| 2784 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2785 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2786 | aom_sad16x64x4d, aom_dist_wtd_sad16x64_avg, |
| 2787 | aom_dist_wtd_sub_pixel_avg_variance16x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2788 | |
| 2789 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2790 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2791 | aom_sad64x16x4d, aom_dist_wtd_sad64x16_avg, |
| 2792 | aom_dist_wtd_sub_pixel_avg_variance64x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2793 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2794 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 2795 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2796 | aom_sad128x128x4d, aom_dist_wtd_sad128x128_avg, |
| 2797 | aom_dist_wtd_sub_pixel_avg_variance128x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2798 | |
| 2799 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2800 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2801 | aom_sad128x64x4d, aom_dist_wtd_sad128x64_avg, |
| 2802 | aom_dist_wtd_sub_pixel_avg_variance128x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2803 | |
| 2804 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2805 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2806 | aom_sad64x128x4d, aom_dist_wtd_sad64x128_avg, |
| 2807 | aom_dist_wtd_sub_pixel_avg_variance64x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2808 | |
| 2809 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2810 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2811 | aom_sad32x16x4d, aom_dist_wtd_sad32x16_avg, |
| 2812 | aom_dist_wtd_sub_pixel_avg_variance32x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2813 | |
| 2814 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2815 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2816 | aom_sad16x32x4d, aom_dist_wtd_sad16x32_avg, |
| 2817 | aom_dist_wtd_sub_pixel_avg_variance16x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2818 | |
| 2819 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2820 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2821 | aom_sad64x32x4d, aom_dist_wtd_sad64x32_avg, |
| 2822 | aom_dist_wtd_sub_pixel_avg_variance64x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2823 | |
| 2824 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2825 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2826 | aom_sad32x64x4d, aom_dist_wtd_sad32x64_avg, |
| 2827 | aom_dist_wtd_sub_pixel_avg_variance32x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2828 | |
| 2829 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 2830 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2831 | aom_sad32x32x4d, aom_dist_wtd_sad32x32_avg, |
| 2832 | aom_dist_wtd_sub_pixel_avg_variance32x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2833 | |
| 2834 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 2835 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2836 | aom_sad64x64x4d, aom_dist_wtd_sad64x64_avg, |
| 2837 | aom_dist_wtd_sub_pixel_avg_variance64x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2838 | |
| 2839 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 2840 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2841 | aom_sad16x16x4d, aom_dist_wtd_sad16x16_avg, |
| 2842 | aom_dist_wtd_sub_pixel_avg_variance16x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2843 | |
| 2844 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2845 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2846 | aom_sad16x8x4d, aom_dist_wtd_sad16x8_avg, |
| 2847 | aom_dist_wtd_sub_pixel_avg_variance16x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2848 | |
| 2849 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2850 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2851 | aom_sad8x16x4d, aom_dist_wtd_sad8x16_avg, |
| 2852 | aom_dist_wtd_sub_pixel_avg_variance8x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2853 | |
| 2854 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2855 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2856 | aom_dist_wtd_sad8x8_avg, aom_dist_wtd_sub_pixel_avg_variance8x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2857 | |
| 2858 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2859 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, aom_sad8x4x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2860 | aom_dist_wtd_sad8x4_avg, aom_dist_wtd_sub_pixel_avg_variance8x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2861 | |
| 2862 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2863 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, aom_sad4x8x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2864 | aom_dist_wtd_sad4x8_avg, aom_dist_wtd_sub_pixel_avg_variance4x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2865 | |
| 2866 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 2867 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x4d, |
Debargha Mukherjee | 0c96c11 | 2018-12-20 16:04:18 -0800 | [diff] [blame] | 2868 | aom_dist_wtd_sad4x4_avg, aom_dist_wtd_sub_pixel_avg_variance4x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2869 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2870 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 2871 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 2872 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 2873 | cpi->fn_ptr[BT].osvf = OSVF; |
| 2874 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2875 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 2876 | aom_obmc_sub_pixel_variance128x128) |
| 2877 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 2878 | aom_obmc_sub_pixel_variance128x64) |
| 2879 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 2880 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2881 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 2882 | aom_obmc_sub_pixel_variance64x64) |
| 2883 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 2884 | aom_obmc_sub_pixel_variance64x32) |
| 2885 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 2886 | aom_obmc_sub_pixel_variance32x64) |
| 2887 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 2888 | aom_obmc_sub_pixel_variance32x32) |
| 2889 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 2890 | aom_obmc_sub_pixel_variance32x16) |
| 2891 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 2892 | aom_obmc_sub_pixel_variance16x32) |
| 2893 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 2894 | aom_obmc_sub_pixel_variance16x16) |
| 2895 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 2896 | aom_obmc_sub_pixel_variance16x8) |
| 2897 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 2898 | aom_obmc_sub_pixel_variance8x16) |
| 2899 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 2900 | aom_obmc_sub_pixel_variance8x8) |
| 2901 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 2902 | aom_obmc_sub_pixel_variance4x8) |
| 2903 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 2904 | aom_obmc_sub_pixel_variance8x4) |
| 2905 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 2906 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2907 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 2908 | aom_obmc_sub_pixel_variance4x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2909 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 2910 | aom_obmc_sub_pixel_variance16x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2911 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 2912 | aom_obmc_sub_pixel_variance8x32) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2913 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 2914 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2915 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 2916 | aom_obmc_sub_pixel_variance16x64) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2917 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 2918 | aom_obmc_sub_pixel_variance64x16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2919 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2920 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 2921 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 2922 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2923 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2924 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 2925 | aom_masked_sub_pixel_variance128x128) |
| 2926 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 2927 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2928 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 2929 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 2930 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 2931 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 2932 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 2933 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 2934 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 2935 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 2936 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 2937 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 2938 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 2939 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 2940 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2941 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2942 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 2943 | |
| 2944 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 2945 | |
| 2946 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 2947 | |
| 2948 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2949 | |
| 2950 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 2951 | |
| 2952 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2953 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2954 | highbd_set_var_fns(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2955 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2956 | /* av1_init_quantizer() is first called here. Add check in |
| 2957 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2958 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2959 | * av1_init_quantizer() for every frame. |
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 | av1_init_quantizer(cpi); |
Zoe Liu | d902b74 | 2018-02-19 17:02:41 -0800 | [diff] [blame] | 2962 | av1_qm_init(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2963 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2964 | av1_loop_filter_init(cm); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 2965 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 2966 | cm->superres_upscaled_width = oxcf->width; |
| 2967 | cm->superres_upscaled_height = oxcf->height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2968 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2969 | |
| 2970 | cm->error.setjmp = 0; |
| 2971 | |
| 2972 | return cpi; |
| 2973 | } |
| 2974 | |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 2975 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2976 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 2977 | |
| 2978 | #define SNPRINT2(H, T, V) \ |
| 2979 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 2980 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2981 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2982 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 2983 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2984 | unsigned int i; |
| 2985 | int t; |
| 2986 | |
| 2987 | if (!cpi) return; |
| 2988 | |
| 2989 | cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 2990 | const int num_planes = av1_num_planes(cm); |
| 2991 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 2992 | if (cm->current_frame.frame_number > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2993 | #if CONFIG_ENTROPY_STATS |
| 2994 | if (cpi->oxcf.pass != 1) { |
| 2995 | fprintf(stderr, "Writing counts.stt\n"); |
| 2996 | FILE *f = fopen("counts.stt", "wb"); |
| 2997 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
| 2998 | fclose(f); |
| 2999 | } |
| 3000 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3001 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3002 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3003 | |
| 3004 | if (cpi->oxcf.pass != 1) { |
| 3005 | char headings[512] = { 0 }; |
| 3006 | char results[512] = { 0 }; |
| 3007 | FILE *f = fopen("opsnr.stt", "a"); |
| 3008 | double time_encoded = |
| 3009 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 3010 | 10000000.000; |
| 3011 | double total_encode_time = |
| 3012 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 3013 | const double dr = |
| 3014 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 3015 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 3016 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 3017 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 3018 | |
| 3019 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3020 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3021 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 3022 | const double total_ssim = |
| 3023 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 3024 | snprintf(headings, sizeof(headings), |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3025 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3026 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3027 | "WstPsnr\tWstSsim\tWstFast\tWstHVS\t" |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3028 | "AVPsrnY\tAPsnrCb\tAPsnrCr"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3029 | snprintf(results, sizeof(results), |
| 3030 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 3031 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3032 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3033 | "%7.3f\t%7.3f\t%7.3f", |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 3034 | dr, cpi->psnr.stat[STAT_ALL] / cpi->count, total_psnr, |
| 3035 | cpi->psnr.stat[STAT_ALL] / cpi->count, total_psnr, total_ssim, |
| 3036 | total_ssim, cpi->fastssim.stat[STAT_ALL] / cpi->count, |
| 3037 | cpi->psnrhvs.stat[STAT_ALL] / cpi->count, cpi->psnr.worst, |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3038 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst, |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 3039 | cpi->psnr.stat[STAT_Y] / cpi->count, |
| 3040 | cpi->psnr.stat[STAT_U] / cpi->count, |
| 3041 | cpi->psnr.stat[STAT_V] / cpi->count); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3042 | |
| 3043 | if (cpi->b_calculate_blockiness) { |
| 3044 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 3045 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 3046 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 3047 | } |
| 3048 | |
| 3049 | if (cpi->b_calculate_consistency) { |
| 3050 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3051 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3052 | (double)cpi->total_inconsistency); |
| 3053 | |
| 3054 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 3055 | SNPRINT2(results, "\t%7.3f", consistency); |
| 3056 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 3057 | } |
Sarah Parker | f97b786 | 2016-08-25 17:42:57 -0700 | [diff] [blame] | 3058 | fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings); |
| 3059 | 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] | 3060 | rate_err, fabs(rate_err)); |
| 3061 | } |
| 3062 | |
| 3063 | fclose(f); |
| 3064 | } |
Urvang Joshi | ee2c811 | 2018-05-04 14:53:15 -0700 | [diff] [blame] | 3065 | #endif // CONFIG_INTERNAL_STATS |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 3066 | #if CONFIG_SPEED_STATS |
| 3067 | if (cpi->oxcf.pass != 1) { |
| 3068 | fprintf(stdout, "tx_search_count = %d\n", cpi->tx_search_count); |
| 3069 | } |
| 3070 | #endif // CONFIG_SPEED_STATS |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 3071 | |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 3072 | #if CONFIG_COLLECT_PARTITION_STATS == 2 |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 3073 | if (cpi->oxcf.pass != 1) { |
| 3074 | av1_print_partition_stats(&cpi->partition_stats); |
| 3075 | } |
| 3076 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3077 | } |
| 3078 | |
Yue Chen | c9b23e0 | 2019-04-10 16:54:03 -0700 | [diff] [blame] | 3079 | for (int frame = 0; frame < MAX_LENGTH_TPL_FRAME_STATS; ++frame) { |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 3080 | aom_free(cpi->tpl_stats[frame].tpl_stats_ptr); |
| 3081 | cpi->tpl_stats[frame].is_valid = 0; |
| 3082 | } |
| 3083 | |
Ravi Chaudhary | 1f58dd8 | 2018-12-07 17:24:15 +0530 | [diff] [blame] | 3084 | for (t = cpi->num_workers - 1; t >= 0; --t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3085 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3086 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 3087 | |
| 3088 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3089 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3090 | |
| 3091 | // Deallocate allocated thread data. |
Ravi Chaudhary | 1cf7d16 | 2018-10-09 17:00:43 +0530 | [diff] [blame] | 3092 | if (cpi->row_mt == 1) aom_free(thread_data->td->tctx); |
Ravi Chaudhary | 1f58dd8 | 2018-12-07 17:24:15 +0530 | [diff] [blame] | 3093 | if (t > 0) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3094 | aom_free(thread_data->td->palette_buffer); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3095 | aom_free(thread_data->td->tmp_conv_dst); |
| 3096 | for (int j = 0; j < 2; ++j) { |
| 3097 | aom_free(thread_data->td->tmp_obmc_bufs[j]); |
| 3098 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3099 | aom_free(thread_data->td->above_pred_buf); |
| 3100 | aom_free(thread_data->td->left_pred_buf); |
| 3101 | aom_free(thread_data->td->wsrc_buf); |
wenyao.liu | 22d8ab3 | 2018-10-16 09:11:29 +0800 | [diff] [blame] | 3102 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 3103 | aom_free(thread_data->td->inter_modes_info); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3104 | for (int x = 0; x < 2; x++) { |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3105 | for (int y = 0; y < 2; y++) { |
| 3106 | aom_free(thread_data->td->hash_value_buffer[x][y]); |
| 3107 | thread_data->td->hash_value_buffer[x][y] = NULL; |
| 3108 | } |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3109 | } |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3110 | aom_free(thread_data->td->mask_buf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3111 | aom_free(thread_data->td->counts); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3112 | av1_free_pc_tree(thread_data->td, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3113 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3114 | } |
| 3115 | } |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 3116 | #if CONFIG_MULTITHREAD |
| 3117 | if (cpi->row_mt == 1) { |
| 3118 | if (cpi->row_mt_mutex_ != NULL) { |
| 3119 | pthread_mutex_destroy(cpi->row_mt_mutex_); |
| 3120 | aom_free(cpi->row_mt_mutex_); |
| 3121 | } |
| 3122 | } |
| 3123 | #endif |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 3124 | av1_row_mt_mem_dealloc(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3125 | aom_free(cpi->tile_thr_data); |
| 3126 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3127 | |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 3128 | if (cpi->num_workers > 1) { |
| 3129 | av1_loop_filter_dealloc(&cpi->lf_row_sync); |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 3130 | av1_loop_restoration_dealloc(&cpi->lr_row_sync, cpi->num_workers); |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 3131 | } |
| 3132 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3133 | dealloc_compressor_data(cpi); |
| 3134 | |
| 3135 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 3136 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3137 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 3140 | #if CONFIG_INTERNAL_STATS |
| 3141 | aom_free(cpi->ssim_vars); |
| 3142 | cpi->ssim_vars = NULL; |
| 3143 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3144 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3145 | av1_remove_common(cm); |
RogerZhou | 80d5234 | 2017-11-20 10:56:26 -0800 | [diff] [blame] | 3146 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 3147 | av1_hash_table_destroy(&cm->buffer_pool->frame_bufs[i].hash_table); |
| 3148 | } |
Yaowu Xu | 74e6335 | 2019-05-06 09:21:33 -0700 | [diff] [blame] | 3149 | #if CONFIG_HTB_TRELLIS |
Michelle Findlay-Olynyk | dea531d | 2017-12-13 14:10:56 -0800 | [diff] [blame] | 3150 | if (cpi->sf.use_hash_based_trellis) hbt_destroy(); |
Yaowu Xu | 74e6335 | 2019-05-06 09:21:33 -0700 | [diff] [blame] | 3151 | #endif // CONFIG_HTB_TRELLIS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3152 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 3153 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3154 | |
| 3155 | #ifdef OUTPUT_YUV_SKINMAP |
| 3156 | fclose(yuv_skinmap_file); |
| 3157 | #endif |
| 3158 | #ifdef OUTPUT_YUV_REC |
| 3159 | fclose(yuv_rec_file); |
| 3160 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3161 | } |
| 3162 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3163 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 3164 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3165 | int i; |
| 3166 | PSNR_STATS psnr; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 3167 | aom_calc_highbd_psnr(cpi->source, &cpi->common.cur_frame->buf, &psnr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3168 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3169 | |
| 3170 | for (i = 0; i < 4; ++i) { |
| 3171 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 3172 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 3173 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 3174 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3175 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 3176 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3177 | } |
| 3178 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3179 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3180 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 3181 | |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 3182 | cpi->ext_ref_frame_flags = ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3183 | return 0; |
| 3184 | } |
| 3185 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3186 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3187 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3188 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3189 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3190 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3191 | aom_yv12_copy_frame(cfg, sd, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3192 | return 0; |
| 3193 | } else { |
| 3194 | return -1; |
| 3195 | } |
| 3196 | } |
| 3197 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3198 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3199 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3200 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3201 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3202 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3203 | aom_yv12_copy_frame(sd, cfg, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3204 | return 0; |
| 3205 | } else { |
| 3206 | return -1; |
| 3207 | } |
| 3208 | } |
| 3209 | |
| 3210 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3211 | cpi->ext_refresh_frame_context = update; |
| 3212 | cpi->ext_refresh_frame_context_pending = 1; |
| 3213 | return 0; |
| 3214 | } |
| 3215 | |
| 3216 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 3217 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 3218 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 3219 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 3220 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3221 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3222 | uint8_t *src = s->y_buffer; |
| 3223 | int h = s->y_height; |
| 3224 | |
| 3225 | do { |
| 3226 | fwrite(src, s->y_width, 1, f); |
| 3227 | src += s->y_stride; |
| 3228 | } while (--h); |
| 3229 | |
| 3230 | src = s->u_buffer; |
| 3231 | h = s->uv_height; |
| 3232 | |
| 3233 | do { |
| 3234 | fwrite(src, s->uv_width, 1, f); |
| 3235 | src += s->uv_stride; |
| 3236 | } while (--h); |
| 3237 | |
| 3238 | src = s->v_buffer; |
| 3239 | h = s->uv_height; |
| 3240 | |
| 3241 | do { |
| 3242 | fwrite(src, s->uv_width, 1, f); |
| 3243 | src += s->uv_stride; |
| 3244 | } while (--h); |
| 3245 | } |
| 3246 | #endif |
| 3247 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3248 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3249 | 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] | 3250 | uint8_t *src = s->y_buffer; |
| 3251 | int h = cm->height; |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3252 | if (yuv_rec_file == NULL) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3253 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 3254 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 3255 | |
| 3256 | do { |
| 3257 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 3258 | src16 += s->y_stride; |
| 3259 | } while (--h); |
| 3260 | |
| 3261 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 3262 | h = s->uv_height; |
| 3263 | |
| 3264 | do { |
| 3265 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3266 | src16 += s->uv_stride; |
| 3267 | } while (--h); |
| 3268 | |
| 3269 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 3270 | h = s->uv_height; |
| 3271 | |
| 3272 | do { |
| 3273 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3274 | src16 += s->uv_stride; |
| 3275 | } while (--h); |
| 3276 | |
| 3277 | fflush(yuv_rec_file); |
| 3278 | return; |
| 3279 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3280 | |
| 3281 | do { |
| 3282 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 3283 | src += s->y_stride; |
| 3284 | } while (--h); |
| 3285 | |
| 3286 | src = s->u_buffer; |
| 3287 | h = s->uv_height; |
| 3288 | |
| 3289 | do { |
| 3290 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3291 | src += s->uv_stride; |
| 3292 | } while (--h); |
| 3293 | |
| 3294 | src = s->v_buffer; |
| 3295 | h = s->uv_height; |
| 3296 | |
| 3297 | do { |
| 3298 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3299 | src += s->uv_stride; |
| 3300 | } while (--h); |
| 3301 | |
| 3302 | fflush(yuv_rec_file); |
| 3303 | } |
| 3304 | #endif // OUTPUT_YUV_REC |
| 3305 | |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 3306 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3307 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 3308 | int i; |
| 3309 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3310 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3311 | AV1_COMMON *const cm = &cpi->common; |
| 3312 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3313 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3314 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3315 | cpi->gmparams_cost[i]) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3316 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3317 | assert(cm->global_motion[i].wmtype == IDENTITY); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3318 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 3319 | recode = 1; |
Urvang Joshi | 02aade8 | 2017-12-18 17:18:16 -0800 | [diff] [blame] | 3320 | // TODO(sarahparker): The earlier condition for recoding here was: |
| 3321 | // "recode |= (rdc->global_motion_used[i] > 0);". Can we bring something |
| 3322 | // similar to that back to speed up global motion? |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3323 | } |
| 3324 | } |
| 3325 | return recode; |
| 3326 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3327 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3328 | // Function to test for conditions that indicate we should loop |
| 3329 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3330 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 3331 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3332 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3333 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3334 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 3335 | int force_recode = 0; |
| 3336 | |
| 3337 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 3338 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 3339 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3340 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 3341 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 3342 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 3343 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3344 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3345 | // Deal with frame undershoot and whether or not we are |
| 3346 | // below the automatically set cq level. |
| 3347 | if (q > oxcf->cq_level && |
| 3348 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 3349 | force_recode = 1; |
| 3350 | } |
| 3351 | } |
| 3352 | } |
| 3353 | return force_recode; |
| 3354 | } |
| 3355 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3356 | static void scale_references(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3357 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3358 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3359 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3360 | const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = { |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3361 | AOM_LAST_FLAG, AOM_LAST2_FLAG, AOM_LAST3_FLAG, AOM_GOLD_FLAG, |
| 3362 | AOM_BWD_FLAG, AOM_ALT2_FLAG, AOM_ALT_FLAG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3363 | }; |
| 3364 | |
| 3365 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3366 | // 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] | 3367 | if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 3368 | BufferPool *const pool = cm->buffer_pool; |
| 3369 | const YV12_BUFFER_CONFIG *const ref = |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3370 | get_ref_frame_yv12_buf(cm, ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3371 | |
| 3372 | if (ref == NULL) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3373 | cpi->scaled_ref_buf[ref_frame - 1] = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3374 | continue; |
| 3375 | } |
| 3376 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3377 | 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] | 3378 | // Replace the reference buffer with a copy having a thicker border, |
| 3379 | // if the reference buffer is higher resolution than the current |
| 3380 | // frame, and the border is thin. |
| 3381 | if ((ref->y_crop_width > cm->width || |
| 3382 | ref->y_crop_height > cm->height) && |
| 3383 | ref->border < AOM_BORDER_IN_PIXELS) { |
| 3384 | RefCntBuffer *ref_fb = get_ref_frame_buf(cm, ref_frame); |
| 3385 | if (aom_yv12_realloc_with_new_border( |
| 3386 | &ref_fb->buf, AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
| 3387 | num_planes) != 0) { |
| 3388 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3389 | "Failed to allocate frame buffer"); |
| 3390 | } |
| 3391 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3392 | int force_scaling = 0; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3393 | RefCntBuffer *new_fb = cpi->scaled_ref_buf[ref_frame - 1]; |
| 3394 | if (new_fb == NULL) { |
| 3395 | const int new_fb_idx = get_free_fb(cm); |
| 3396 | if (new_fb_idx == INVALID_IDX) { |
Wan-Teh Chang | 4a8c004 | 2018-10-05 09:41:52 -0700 | [diff] [blame] | 3397 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3398 | "Unable to find free frame buffer"); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3399 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3400 | force_scaling = 1; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3401 | new_fb = &pool->frame_bufs[new_fb_idx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3402 | } |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3403 | |
| 3404 | if (force_scaling || new_fb->buf.y_crop_width != cm->width || |
| 3405 | new_fb->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3406 | if (aom_realloc_frame_buffer( |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3407 | &new_fb->buf, cm->width, cm->height, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3408 | cm->seq_params.subsampling_x, cm->seq_params.subsampling_y, |
Debargha Mukherjee | fa946af | 2019-03-26 16:58:55 -0700 | [diff] [blame] | 3409 | cm->seq_params.use_highbitdepth, AOM_BORDER_IN_PIXELS, |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3410 | cm->byte_alignment, NULL, NULL, NULL)) { |
| 3411 | if (force_scaling) { |
| 3412 | // Release the reference acquired in the get_free_fb() call above. |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3413 | --new_fb->ref_count; |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3414 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3415 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3416 | "Failed to allocate frame buffer"); |
Wan-Teh Chang | 41d286f | 2018-10-03 11:43:03 -0700 | [diff] [blame] | 3417 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3418 | av1_resize_and_extend_frame( |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3419 | ref, &new_fb->buf, (int)cm->seq_params.bit_depth, num_planes); |
| 3420 | cpi->scaled_ref_buf[ref_frame - 1] = new_fb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3421 | alloc_frame_mvs(cm, new_fb); |
| 3422 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3423 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3424 | RefCntBuffer *buf = get_ref_frame_buf(cm, ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3425 | buf->buf.y_crop_width = ref->y_crop_width; |
| 3426 | buf->buf.y_crop_height = ref->y_crop_height; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3427 | cpi->scaled_ref_buf[ref_frame - 1] = buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3428 | ++buf->ref_count; |
| 3429 | } |
| 3430 | } else { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3431 | 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] | 3432 | } |
| 3433 | } |
| 3434 | } |
| 3435 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3436 | static void release_scaled_references(AV1_COMP *cpi) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3437 | // TODO(isbs): only refresh the necessary frames, rather than all of them |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3438 | for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
| 3439 | RefCntBuffer *const buf = cpi->scaled_ref_buf[i]; |
| 3440 | if (buf != NULL) { |
Imdad Sardharwalla | dadaba6 | 2018-02-23 12:06:56 +0000 | [diff] [blame] | 3441 | --buf->ref_count; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3442 | cpi->scaled_ref_buf[i] = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3443 | } |
| 3444 | } |
| 3445 | } |
| 3446 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3447 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 3448 | const AV1_COMMON *const cm = &cpi->common; |
| 3449 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3450 | |
| 3451 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3452 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3453 | |
| 3454 | if (cpi->sf.mv.auto_mv_step_size) { |
| 3455 | if (frame_is_intra_only(cm)) { |
| 3456 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 3457 | // after a key/intra-only frame. |
| 3458 | cpi->max_mv_magnitude = max_mv_def; |
| 3459 | } else { |
| 3460 | if (cm->show_frame) { |
| 3461 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 3462 | // in the previous frame, capped by the default max_mv_magnitude based |
| 3463 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3464 | cpi->mv_step_param = av1_init_search_range( |
| 3465 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3466 | } |
| 3467 | cpi->max_mv_magnitude = 0; |
| 3468 | } |
| 3469 | } |
| 3470 | } |
| 3471 | |
Hui Su | bdf0c99 | 2019-02-14 14:52:41 -0800 | [diff] [blame] | 3472 | static void set_screen_content_options(AV1_COMP *cpi) { |
| 3473 | AV1_COMMON *cm = &cpi->common; |
| 3474 | |
| 3475 | if (cm->seq_params.force_screen_content_tools != 2) { |
| 3476 | cm->allow_screen_content_tools = cm->allow_intrabc = |
| 3477 | cm->seq_params.force_screen_content_tools; |
| 3478 | return; |
| 3479 | } |
| 3480 | |
| 3481 | if (cpi->oxcf.content == AOM_CONTENT_SCREEN) { |
| 3482 | cm->allow_screen_content_tools = cm->allow_intrabc = 1; |
| 3483 | return; |
| 3484 | } |
| 3485 | |
| 3486 | // Estimate if the source frame is screen content, based on the portion of |
| 3487 | // blocks that have few luma colors. |
| 3488 | const uint8_t *src = cpi->source->y_buffer; |
| 3489 | assert(src != NULL); |
| 3490 | const int use_hbd = cpi->source->flags & YV12_FLAG_HIGHBITDEPTH; |
| 3491 | const int stride = cpi->source->y_stride; |
| 3492 | const int width = cpi->source->y_width; |
| 3493 | const int height = cpi->source->y_height; |
| 3494 | const int bd = cm->seq_params.bit_depth; |
| 3495 | const int blk_w = 16; |
| 3496 | const int blk_h = 16; |
| 3497 | // These threshold values are selected experimentally. |
| 3498 | const int color_thresh = 4; |
| 3499 | const unsigned int var_thresh = 0; |
| 3500 | // Counts of blocks with no more than color_thresh colors. |
| 3501 | int counts_1 = 0; |
| 3502 | // Counts of blocks with no more than color_thresh colors and variance larger |
| 3503 | // than var_thresh. |
| 3504 | int counts_2 = 0; |
| 3505 | |
| 3506 | for (int r = 0; r + blk_h <= height; r += blk_h) { |
| 3507 | for (int c = 0; c + blk_w <= width; c += blk_w) { |
| 3508 | int count_buf[1 << 12]; // Maximum (1 << 12) color levels. |
| 3509 | const uint8_t *const this_src = src + r * stride + c; |
| 3510 | const int n_colors = |
| 3511 | use_hbd ? av1_count_colors_highbd(this_src, stride, blk_w, blk_h, bd, |
| 3512 | count_buf) |
| 3513 | : av1_count_colors(this_src, stride, blk_w, blk_h, count_buf); |
| 3514 | if (n_colors > 1 && n_colors <= color_thresh) { |
| 3515 | ++counts_1; |
| 3516 | struct buf_2d buf; |
| 3517 | buf.stride = stride; |
| 3518 | buf.buf = (uint8_t *)this_src; |
| 3519 | const unsigned int var = |
| 3520 | use_hbd |
| 3521 | ? av1_high_get_sby_perpixel_variance(cpi, &buf, BLOCK_16X16, bd) |
| 3522 | : av1_get_sby_perpixel_variance(cpi, &buf, BLOCK_16X16); |
| 3523 | if (var > var_thresh) ++counts_2; |
| 3524 | } |
| 3525 | } |
| 3526 | } |
| 3527 | |
| 3528 | // The threshold values are selected experimentally. |
| 3529 | cm->allow_screen_content_tools = |
| 3530 | counts_1 * blk_h * blk_w * 10 > width * height; |
| 3531 | // IntraBC would force loop filters off, so we use more strict rules that also |
| 3532 | // requires that the block has high variance. |
| 3533 | cm->allow_intrabc = cm->allow_screen_content_tools && |
Hui Su | 64a2ffb | 2019-04-11 16:47:13 -0700 | [diff] [blame] | 3534 | counts_2 * blk_h * blk_w * 12 > width * height; |
Hui Su | bdf0c99 | 2019-02-14 14:52:41 -0800 | [diff] [blame] | 3535 | } |
| 3536 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3537 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3538 | int i; |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3539 | AV1_COMMON *cm = &cpi->common; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3540 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3541 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3542 | } |
| 3543 | cpi->global_motion_search_done = 0; |
Yunqing Wang | 9411e43 | 2019-03-14 15:53:23 -0700 | [diff] [blame] | 3544 | |
| 3545 | if (frame_is_intra_only(cm)) set_screen_content_options(cpi); |
| 3546 | cpi->is_screen_content_type = (cm->allow_screen_content_tools != 0); |
| 3547 | |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 3548 | av1_set_speed_features_framesize_independent(cpi, cpi->speed); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3549 | av1_set_rd_speed_thresholds(cpi); |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3550 | cm->interp_filter = SWITCHABLE; |
| 3551 | cm->switchable_motion_mode = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3554 | 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] | 3555 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3556 | AV1_COMMON *const cm = &cpi->common; |
| 3557 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3558 | |
| 3559 | // Setup variables that depend on the dimensions of the frame. |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 3560 | av1_set_speed_features_framesize_dependent(cpi, cpi->speed); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3561 | |
Sebastien Alaiwan | 41cae6a | 2018-01-12 12:22:29 +0100 | [diff] [blame] | 3562 | // Decide q and q bounds. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3563 | *q = av1_rc_pick_q_and_bounds(cpi, cm->width, cm->height, bottom_index, |
| 3564 | top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3565 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3566 | if (!frame_is_intra_only(cm)) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3567 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH, |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 3568 | cpi->common.cur_frame_force_integer_mv); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3569 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3570 | |
| 3571 | // Configure experimental use of segmentation for enhanced coding of |
| 3572 | // static regions if indicated. |
| 3573 | // Only allowed in the second pass of a two pass encode, as it requires |
| 3574 | // lagged coding, and if the relevant speed feature flag is set. |
| 3575 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 3576 | configure_static_seg_features(cpi); |
| 3577 | } |
| 3578 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3579 | static void init_motion_estimation(AV1_COMP *cpi) { |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 3580 | const int y_stride = cpi->scaled_source.y_stride; |
| 3581 | const int y_stride_src = (cpi->oxcf.resize_mode || cpi->oxcf.superres_mode) |
| 3582 | ? y_stride |
| 3583 | : cpi->lookahead->buf->img.y_stride; |
| 3584 | // Update if ss_cfg is uninitialized or the current frame has a new stride |
| 3585 | const int should_update = !cpi->ss_cfg[SS_CFG_SRC].stride || |
| 3586 | !cpi->ss_cfg[SS_CFG_LOOKAHEAD].stride || |
| 3587 | (y_stride != cpi->ss_cfg[SS_CFG_SRC].stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3588 | |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 3589 | if (!should_update) { |
| 3590 | return; |
| 3591 | } |
| 3592 | |
| 3593 | if (cpi->sf.mv.search_method == DIAMOND) { |
Satish Kumar Suman | e6d0be5 | 2019-02-14 14:33:28 +0530 | [diff] [blame] | 3594 | av1_init_dsmotion_compensation(&cpi->ss_cfg[SS_CFG_SRC], y_stride); |
| 3595 | av1_init_dsmotion_compensation(&cpi->ss_cfg[SS_CFG_LOOKAHEAD], |
| 3596 | y_stride_src); |
chiyotsai | 836b69b | 2019-04-09 13:41:24 -0700 | [diff] [blame] | 3597 | } else { |
| 3598 | // Update the offsets in search_sites as y_stride can change due to scaled |
| 3599 | // references. This update allows NSTEP to be used on scaled references as |
| 3600 | // long as sf.mv.search_method is not DIAMOND. Currently in the codebae, |
| 3601 | // sf.mv.search_method is never set to DIAMOND. |
| 3602 | av1_init3smotion_compensation(&cpi->ss_cfg[SS_CFG_SRC], y_stride); |
| 3603 | av1_init3smotion_compensation(&cpi->ss_cfg[SS_CFG_LOOKAHEAD], y_stride_src); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3604 | } |
| 3605 | } |
| 3606 | |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3607 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 3608 | static void set_restoration_unit_size(int width, int height, int sx, int sy, |
| 3609 | RestorationInfo *rst) { |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3610 | (void)width; |
| 3611 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3612 | (void)sx; |
| 3613 | (void)sy; |
| 3614 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3615 | int s = AOMMIN(sx, sy); |
| 3616 | #else |
| 3617 | int s = 0; |
| 3618 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3619 | |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 3620 | if (width * height > 352 * 288) |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 3621 | rst[0].restoration_unit_size = RESTORATION_UNITSIZE_MAX; |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 3622 | else |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 3623 | rst[0].restoration_unit_size = (RESTORATION_UNITSIZE_MAX >> 1); |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 3624 | rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s; |
| 3625 | rst[2].restoration_unit_size = rst[1].restoration_unit_size; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3626 | } |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3627 | |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3628 | static void init_ref_frame_bufs(AV1_COMP *cpi) { |
| 3629 | AV1_COMMON *const cm = &cpi->common; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3630 | int i; |
| 3631 | BufferPool *const pool = cm->buffer_pool; |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 3632 | cm->cur_frame = NULL; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3633 | for (i = 0; i < REF_FRAMES; ++i) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3634 | cm->ref_frame_map[i] = NULL; |
Wan-Teh Chang | d05e033 | 2018-10-03 12:00:43 -0700 | [diff] [blame] | 3635 | } |
| 3636 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3637 | pool->frame_bufs[i].ref_count = 0; |
| 3638 | } |
RogerZhou | 86902d0 | 2018-02-28 15:29:16 -0800 | [diff] [blame] | 3639 | if (cm->seq_params.force_screen_content_tools) { |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 3640 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3641 | 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] | 3642 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3643 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3644 | } |
| 3645 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 3646 | static void check_initial_width(AV1_COMP *cpi, int use_highbitdepth, |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3647 | int subsampling_x, int subsampling_y) { |
| 3648 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3649 | SequenceHeader *const seq_params = &cm->seq_params; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3650 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3651 | if (!cpi->initial_width || seq_params->use_highbitdepth != use_highbitdepth || |
| 3652 | seq_params->subsampling_x != subsampling_x || |
| 3653 | seq_params->subsampling_y != subsampling_y) { |
| 3654 | seq_params->subsampling_x = subsampling_x; |
| 3655 | seq_params->subsampling_y = subsampling_y; |
| 3656 | seq_params->use_highbitdepth = use_highbitdepth; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3657 | |
| 3658 | alloc_raw_frame_buffers(cpi); |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 3659 | init_ref_frame_bufs(cpi); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3660 | alloc_util_frame_buffers(cpi); |
| 3661 | |
| 3662 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 3663 | |
| 3664 | cpi->initial_width = cm->width; |
| 3665 | cpi->initial_height = cm->height; |
| 3666 | cpi->initial_mbs = cm->MBs; |
| 3667 | } |
| 3668 | } |
| 3669 | |
| 3670 | // Returns 1 if the assigned width or height was <= 0. |
| 3671 | static int set_size_literal(AV1_COMP *cpi, int width, int height) { |
| 3672 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3673 | const int num_planes = av1_num_planes(cm); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3674 | check_initial_width(cpi, cm->seq_params.use_highbitdepth, |
| 3675 | cm->seq_params.subsampling_x, |
| 3676 | cm->seq_params.subsampling_y); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3677 | |
| 3678 | if (width <= 0 || height <= 0) return 1; |
| 3679 | |
| 3680 | cm->width = width; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3681 | cm->height = height; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3682 | |
| 3683 | if (cpi->initial_width && cpi->initial_height && |
| 3684 | (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) { |
| 3685 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3686 | av1_free_pc_tree(&cpi->td, num_planes); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3687 | alloc_compressor_data(cpi); |
| 3688 | realloc_segmentation_maps(cpi); |
| 3689 | cpi->initial_width = cpi->initial_height = 0; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3690 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3691 | update_frame_size(cpi); |
| 3692 | |
| 3693 | return 0; |
| 3694 | } |
| 3695 | |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 3696 | void av1_set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3697 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3698 | const SequenceHeader *const seq_params = &cm->seq_params; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3699 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3700 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3701 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3702 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3703 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 3704 | // There has been a change in the encoded frame size |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3705 | set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3706 | set_mv_search_params(cpi); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 3707 | // Recalculate 'all_lossless' in case super-resolution was (un)selected. |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 3708 | cm->all_lossless = cm->coded_lossless && !av1_superres_scaled(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3709 | } |
| 3710 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3711 | if (cpi->oxcf.pass == 2) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3712 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3713 | } |
| 3714 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3715 | alloc_frame_mvs(cm, cm->cur_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3716 | |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 3717 | // Allocate above context buffers |
Cherma Rajan A | f147908 | 2018-05-09 14:26:34 +0530 | [diff] [blame] | 3718 | if (cm->num_allocated_above_context_planes < av1_num_planes(cm) || |
| 3719 | cm->num_allocated_above_context_mi_col < cm->mi_cols || |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 3720 | cm->num_allocated_above_contexts < cm->tile_rows) { |
| 3721 | av1_free_above_context_buffers(cm, cm->num_allocated_above_contexts); |
| 3722 | if (av1_alloc_above_context_buffers(cm, cm->tile_rows)) |
| 3723 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 3724 | "Failed to allocate context buffers"); |
| 3725 | } |
| 3726 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3727 | // Reset the frame pointers to the current frame size. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3728 | if (aom_realloc_frame_buffer( |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 3729 | &cm->cur_frame->buf, cm->width, cm->height, seq_params->subsampling_x, |
| 3730 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 3731 | cpi->oxcf.border_in_pixels, cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3732 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3733 | "Failed to allocate frame buffer"); |
| 3734 | |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 3735 | const int frame_width = cm->superres_upscaled_width; |
| 3736 | const int frame_height = cm->superres_upscaled_height; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3737 | set_restoration_unit_size(frame_width, frame_height, |
| 3738 | seq_params->subsampling_x, |
| 3739 | seq_params->subsampling_y, cm->rst_info); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3740 | for (int i = 0; i < num_planes; ++i) |
Rupert Swarbrick | 1a96c3f | 2017-10-24 11:55:00 +0100 | [diff] [blame] | 3741 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 3742 | |
| 3743 | av1_alloc_restoration_buffers(cm); |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3744 | alloc_util_frame_buffers(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3745 | init_motion_estimation(cpi); |
| 3746 | |
| 3747 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3748 | RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3749 | if (buf != NULL) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3750 | struct scale_factors *sf = get_ref_scale_factors(cm, ref_frame); |
| 3751 | av1_setup_scale_factors_for_frame(sf, buf->buf.y_crop_width, |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 3752 | buf->buf.y_crop_height, cm->width, |
Debargha Mukherjee | e242a81 | 2018-03-07 21:43:09 -0800 | [diff] [blame] | 3753 | cm->height); |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 3754 | 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] | 3755 | } |
| 3756 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 3757 | |
Hui Su | 5ebd870 | 2018-01-08 18:09:20 -0800 | [diff] [blame] | 3758 | 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] | 3759 | cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3760 | |
| 3761 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 3762 | } |
| 3763 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3764 | static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) { |
| 3765 | // Choose an arbitrary random number |
| 3766 | static unsigned int seed = 56789; |
| 3767 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3768 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 3769 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3770 | |
Debargha Mukherjee | 2b7c2b3 | 2018-04-10 07:35:28 -0700 | [diff] [blame] | 3771 | if (cpi->common.seq_params.reduced_still_picture_hdr) return SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3772 | switch (oxcf->resize_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3773 | case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3774 | case RESIZE_FIXED: |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 3775 | if (cpi->common.current_frame.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3776 | new_denom = oxcf->resize_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3777 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3778 | new_denom = oxcf->resize_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3779 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3780 | case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3781 | default: assert(0); |
| 3782 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3783 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3784 | } |
| 3785 | |
Debargha Mukherjee | e3cd5a5 | 2018-11-29 11:05:22 -0800 | [diff] [blame] | 3786 | #define ENERGY_BY_Q2_THRESH 0.01 |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 3787 | #define ENERGY_BY_AC_THRESH 0.2 |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3788 | |
| 3789 | 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] | 3790 | double threshq, |
| 3791 | double threshp) { |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3792 | const double q = av1_convert_qindex_to_q(qindex, AOM_BITS_8); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 3793 | const double tq = threshq * q * q; |
| 3794 | const double tp = threshp * energy[1]; |
| 3795 | const double thresh = AOMMIN(tq, tp); |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3796 | int k; |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 3797 | for (k = 16; k > 8; --k) { |
| 3798 | if (energy[k - 1] > thresh) break; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3799 | } |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 3800 | return 3 * SCALE_NUMERATOR - k; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | 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] | 3804 | double energy[16]; |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3805 | analyze_hor_freq(cpi, energy); |
Debargha Mukherjee | 21eb040 | 2018-12-03 12:10:59 -0800 | [diff] [blame] | 3806 | /* |
| 3807 | printf("\nenergy = ["); |
| 3808 | for (int k = 1; k < 16; ++k) printf("%f, ", energy[k]); |
| 3809 | printf("]\n"); |
| 3810 | */ |
| 3811 | return get_superres_denom_from_qindex_energy( |
| 3812 | qindex, energy, ENERGY_BY_Q2_THRESH, ENERGY_BY_AC_THRESH); |
Debargha Mukherjee | f48b0d2 | 2018-11-20 12:23:43 -0800 | [diff] [blame] | 3813 | } |
| 3814 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3815 | static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) { |
| 3816 | // Choose an arbitrary random number |
| 3817 | static unsigned int seed = 34567; |
| 3818 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3819 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 3820 | uint8_t new_denom = SCALE_NUMERATOR; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 3821 | |
| 3822 | // Make sure that superres mode of the frame is consistent with the |
| 3823 | // sequence-level flag. |
| 3824 | assert(IMPLIES(oxcf->superres_mode != SUPERRES_NONE, |
| 3825 | cpi->common.seq_params.enable_superres)); |
| 3826 | assert(IMPLIES(!cpi->common.seq_params.enable_superres, |
| 3827 | oxcf->superres_mode == SUPERRES_NONE)); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3828 | |
| 3829 | switch (oxcf->superres_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3830 | case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3831 | case SUPERRES_FIXED: |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 3832 | if (cpi->common.current_frame.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3833 | new_denom = oxcf->superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3834 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3835 | new_denom = oxcf->superres_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3836 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3837 | case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 3838 | case SUPERRES_QTHRESH: { |
Debargha Mukherjee | df71310 | 2018-10-02 12:33:32 -0700 | [diff] [blame] | 3839 | // Do not use superres when screen content tools are used. |
| 3840 | if (cpi->common.allow_screen_content_tools) break; |
Debargha Mukherjee | 2b2c5fd | 2018-11-14 13:21:24 -0800 | [diff] [blame] | 3841 | if (oxcf->rc_mode == AOM_VBR || oxcf->rc_mode == AOM_CQ) |
| 3842 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 3843 | int bottom_index, top_index; |
| 3844 | const int q = av1_rc_pick_q_and_bounds( |
| 3845 | cpi, cpi->oxcf.width, cpi->oxcf.height, &bottom_index, &top_index); |
Debargha Mukherjee | f48b0d2 | 2018-11-20 12:23:43 -0800 | [diff] [blame] | 3846 | |
Debargha Mukherjee | acd9b7d | 2018-11-26 15:15:05 -0800 | [diff] [blame] | 3847 | const int qthresh = (frame_is_intra_only(&cpi->common)) |
| 3848 | ? oxcf->superres_kf_qthresh |
| 3849 | : oxcf->superres_qthresh; |
Urvang Joshi | b17e0a6 | 2019-01-11 16:11:54 -0800 | [diff] [blame] | 3850 | if (q <= qthresh) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3851 | new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3852 | } else { |
Debargha Mukherjee | e3cd5a5 | 2018-11-29 11:05:22 -0800 | [diff] [blame] | 3853 | new_denom = get_superres_denom_for_qindex(cpi, q); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3854 | } |
| 3855 | break; |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 3856 | } |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 3857 | case SUPERRES_AUTO: { |
| 3858 | // Don't use when screen content tools are used. |
| 3859 | if (cpi->common.allow_screen_content_tools) break; |
| 3860 | // Don't use for inter frames. |
| 3861 | if (!frame_is_intra_only(&cpi->common)) break; |
Urvang Joshi | bf5e770 | 2019-04-01 11:55:09 -0700 | [diff] [blame] | 3862 | // Don't use for keyframes that can be used as references, except when |
| 3863 | // using AOM_Q mode. |
| 3864 | 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] | 3865 | |
| 3866 | // Now decide the use of superres based on 'q'. |
| 3867 | int bottom_index, top_index; |
| 3868 | const int q = av1_rc_pick_q_and_bounds( |
| 3869 | cpi, cpi->oxcf.width, cpi->oxcf.height, &bottom_index, &top_index); |
| 3870 | |
| 3871 | const int qthresh = 128; |
| 3872 | if (q <= qthresh) { |
| 3873 | new_denom = SCALE_NUMERATOR; |
| 3874 | } else { |
| 3875 | new_denom = get_superres_denom_for_qindex(cpi, q); |
| 3876 | } |
| 3877 | break; |
| 3878 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3879 | default: assert(0); |
| 3880 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3881 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3882 | } |
| 3883 | |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3884 | static int dimension_is_ok(int orig_dim, int resized_dim, int denom) { |
| 3885 | return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2); |
| 3886 | } |
| 3887 | |
| 3888 | 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] | 3889 | // Only need to check the width, as scaling is horizontal only. |
| 3890 | (void)oheight; |
| 3891 | return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3892 | } |
| 3893 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3894 | static int validate_size_scales(RESIZE_MODE resize_mode, |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3895 | SUPERRES_MODE superres_mode, int owidth, |
| 3896 | int oheight, size_params_type *rsz) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3897 | if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3898 | return 1; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 3901 | // Calculate current resize scale. |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3902 | int resize_denom = |
| 3903 | AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width), |
| 3904 | DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height)); |
| 3905 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3906 | if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3907 | // Alter superres scale as needed to enforce conformity. |
| 3908 | rsz->superres_denom = |
| 3909 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom; |
| 3910 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 3911 | if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3912 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3913 | } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3914 | // Alter resize scale as needed to enforce conformity. |
| 3915 | resize_denom = |
| 3916 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3917 | rsz->resize_width = owidth; |
| 3918 | rsz->resize_height = oheight; |
| 3919 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3920 | resize_denom); |
| 3921 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 3922 | if (resize_denom > SCALE_NUMERATOR) { |
| 3923 | --resize_denom; |
| 3924 | rsz->resize_width = owidth; |
| 3925 | rsz->resize_height = oheight; |
| 3926 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
| 3927 | resize_denom); |
| 3928 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3929 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3930 | } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3931 | // Alter both resize and superres scales as needed to enforce conformity. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3932 | do { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3933 | if (resize_denom > rsz->superres_denom) |
| 3934 | --resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3935 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3936 | --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3937 | rsz->resize_width = owidth; |
| 3938 | rsz->resize_height = oheight; |
| 3939 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3940 | resize_denom); |
| 3941 | } while (!dimensions_are_ok(owidth, oheight, rsz) && |
| 3942 | (resize_denom > SCALE_NUMERATOR || |
| 3943 | rsz->superres_denom > SCALE_NUMERATOR)); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 3944 | } else { // We are allowed to alter neither resize scale nor superres |
| 3945 | // scale. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3946 | return 0; |
| 3947 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3948 | return dimensions_are_ok(owidth, oheight, rsz); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3949 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3950 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3951 | // Calculates resize and superres params for next frame |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 3952 | static size_params_type calculate_next_size_params(AV1_COMP *cpi) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3953 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 3954 | size_params_type rsz = { oxcf->width, oxcf->height, SCALE_NUMERATOR }; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3955 | int resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3956 | if (oxcf->pass == 1) return rsz; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3957 | if (cpi->resize_pending_width && cpi->resize_pending_height) { |
| 3958 | rsz.resize_width = cpi->resize_pending_width; |
| 3959 | rsz.resize_height = cpi->resize_pending_height; |
| 3960 | cpi->resize_pending_width = cpi->resize_pending_height = 0; |
| 3961 | } else { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3962 | resize_denom = calculate_next_resize_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3963 | rsz.resize_width = cpi->oxcf.width; |
| 3964 | rsz.resize_height = cpi->oxcf.height; |
| 3965 | av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3966 | resize_denom); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3967 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3968 | rsz.superres_denom = calculate_next_superres_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3969 | if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width, |
| 3970 | oxcf->height, &rsz)) |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3971 | assert(0 && "Invalid scale parameters"); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3972 | return rsz; |
| 3973 | } |
| 3974 | |
Urvang Joshi | 22b150b | 2019-01-10 14:32:32 -0800 | [diff] [blame] | 3975 | static void setup_frame_size_from_params(AV1_COMP *cpi, |
| 3976 | const size_params_type *rsz) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3977 | int encode_width = rsz->resize_width; |
| 3978 | int encode_height = rsz->resize_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3979 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3980 | AV1_COMMON *cm = &cpi->common; |
| 3981 | cm->superres_upscaled_width = encode_width; |
| 3982 | cm->superres_upscaled_height = encode_height; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3983 | cm->superres_scale_denominator = rsz->superres_denom; |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 3984 | av1_calculate_scaled_superres_size(&encode_width, &encode_height, |
| 3985 | rsz->superres_denom); |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 3986 | av1_set_frame_size(cpi, encode_width, encode_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3987 | } |
| 3988 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 3989 | void av1_setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 3990 | AV1_COMMON *cm = &cpi->common; |
Urvang Joshi | 22b150b | 2019-01-10 14:32:32 -0800 | [diff] [blame] | 3991 | // Reset superres params from previous frame. |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 3992 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 3993 | const size_params_type rsz = calculate_next_size_params(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3994 | setup_frame_size_from_params(cpi, &rsz); |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 3995 | |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 3996 | assert(av1_is_min_tile_width_satisfied(cm)); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 3997 | } |
| 3998 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3999 | static void superres_post_encode(AV1_COMP *cpi) { |
| 4000 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4001 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4002 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4003 | if (!av1_superres_scaled(cm)) return; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4004 | |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 4005 | assert(cpi->oxcf.enable_superres); |
| 4006 | assert(!is_lossless_requested(&cpi->oxcf)); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4007 | assert(!cm->all_lossless); |
Urvang Joshi | d6b5d51 | 2018-03-20 13:34:38 -0700 | [diff] [blame] | 4008 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4009 | av1_superres_upscale(cm, NULL); |
| 4010 | |
| 4011 | // If regular resizing is occurring the source will need to be downscaled to |
| 4012 | // match the upscaled superres resolution. Otherwise the original source is |
| 4013 | // used. |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 4014 | if (!av1_resize_scaled(cm)) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4015 | cpi->source = cpi->unscaled_source; |
| 4016 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 4017 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 4018 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 4019 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4020 | // Do downscale. cm->(width|height) has been updated by |
| 4021 | // av1_superres_upscale |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4022 | if (aom_realloc_frame_buffer( |
| 4023 | &cpi->scaled_source, cm->superres_upscaled_width, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4024 | cm->superres_upscaled_height, cm->seq_params.subsampling_x, |
| 4025 | cm->seq_params.subsampling_y, cm->seq_params.use_highbitdepth, |
| 4026 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4027 | aom_internal_error( |
| 4028 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 4029 | "Failed to reallocate scaled source buffer for superres"); |
| 4030 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 4031 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4032 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4033 | (int)cm->seq_params.bit_depth, num_planes); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4034 | cpi->source = &cpi->scaled_source; |
| 4035 | } |
| 4036 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4037 | |
| 4038 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4039 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4040 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
Urvang Joshi | 14072aa | 2018-03-21 17:43:36 -0700 | [diff] [blame] | 4041 | |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 4042 | assert(IMPLIES(is_lossless_requested(&cpi->oxcf), |
| 4043 | cm->coded_lossless && cm->all_lossless)); |
| 4044 | |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4045 | const int use_loopfilter = !cm->coded_lossless && !cm->large_scale_tile; |
| 4046 | const int use_cdef = cm->seq_params.enable_cdef && !cm->coded_lossless && |
| 4047 | !cm->large_scale_tile; |
| 4048 | const int use_restoration = cm->seq_params.enable_restoration && |
| 4049 | !cm->all_lossless && !cm->large_scale_tile; |
Urvang Joshi | 14072aa | 2018-03-21 17:43:36 -0700 | [diff] [blame] | 4050 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4051 | struct loopfilter *lf = &cm->lf; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4052 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4053 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4054 | start_timing(cpi, loop_filter_time); |
| 4055 | #endif |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4056 | if (use_loopfilter) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4057 | aom_clear_system_state(); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4058 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4059 | } else { |
| 4060 | lf->filter_level[0] = 0; |
| 4061 | lf->filter_level[1] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4062 | } |
| 4063 | |
Debargha Mukherjee | 2382b14 | 2018-02-26 14:31:32 -0800 | [diff] [blame] | 4064 | if (lf->filter_level[0] || lf->filter_level[1]) { |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 4065 | if (cpi->num_workers > 1) |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4066 | 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] | 4067 | #if CONFIG_LPF_MASK |
Cheng Chen | e3600cd | 2018-09-21 18:45:42 -0700 | [diff] [blame] | 4068 | 0, |
| 4069 | #endif |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 4070 | cpi->workers, cpi->num_workers, |
| 4071 | &cpi->lf_row_sync); |
| 4072 | else |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4073 | av1_loop_filter_frame(&cm->cur_frame->buf, cm, xd, |
Yaowu Xu | 8e718cf | 2019-05-02 09:06:57 -0700 | [diff] [blame] | 4074 | #if CONFIG_LPF_MASK |
Cheng Chen | 84b0993 | 2018-08-12 17:35:13 -0700 | [diff] [blame] | 4075 | 0, |
Cheng Chen | 8ab1f44 | 2018-04-27 18:01:52 -0700 | [diff] [blame] | 4076 | #endif |
Cheng Chen | 84b0993 | 2018-08-12 17:35:13 -0700 | [diff] [blame] | 4077 | 0, num_planes, 0); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4078 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4079 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4080 | end_timing(cpi, loop_filter_time); |
| 4081 | #endif |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 4082 | |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4083 | if (use_restoration) |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4084 | av1_loop_restoration_save_boundary_lines(&cm->cur_frame->buf, cm, 0); |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 4085 | |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4086 | if (use_cdef) { |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4087 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4088 | start_timing(cpi, cdef_time); |
| 4089 | #endif |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 4090 | // Find CDEF parameters |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4091 | av1_cdef_search(&cm->cur_frame->buf, cpi->source, cm, xd, |
Hui Su | 805c7d2 | 2019-05-07 21:57:50 -0700 | [diff] [blame] | 4092 | cpi->sf.cdef_pick_method); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4093 | |
| 4094 | // Apply the filter |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4095 | av1_cdef_frame(&cm->cur_frame->buf, cm, xd); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4096 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4097 | end_timing(cpi, cdef_time); |
| 4098 | #endif |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4099 | } else { |
| 4100 | cm->cdef_info.cdef_bits = 0; |
| 4101 | cm->cdef_info.cdef_strengths[0] = 0; |
| 4102 | cm->cdef_info.nb_cdef_strengths = 1; |
| 4103 | cm->cdef_info.cdef_uv_strengths[0] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4104 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4105 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4106 | superres_post_encode(cpi); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4107 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4108 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4109 | start_timing(cpi, loop_restoration_time); |
| 4110 | #endif |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4111 | if (use_restoration) { |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4112 | av1_loop_restoration_save_boundary_lines(&cm->cur_frame->buf, cm, 1); |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4113 | av1_pick_filter_restoration(cpi->source, cpi); |
| 4114 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 4115 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 4116 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4117 | if (cpi->num_workers > 1) |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4118 | av1_loop_restoration_filter_frame_mt(&cm->cur_frame->buf, cm, 0, |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4119 | cpi->workers, cpi->num_workers, |
| 4120 | &cpi->lr_row_sync, &cpi->lr_ctxt); |
| 4121 | else |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4122 | av1_loop_restoration_filter_frame(&cm->cur_frame->buf, cm, 0, |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 4123 | &cpi->lr_ctxt); |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4124 | } |
logangw | f95c916 | 2019-02-20 12:02:32 -0800 | [diff] [blame] | 4125 | } else { |
| 4126 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 4127 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 4128 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4129 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4130 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4131 | end_timing(cpi, loop_restoration_time); |
| 4132 | #endif |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
David Turner | f2b334c | 2018-12-13 13:00:55 +0000 | [diff] [blame] | 4135 | static void fix_interp_filter(InterpFilter *const interp_filter, |
| 4136 | const FRAME_COUNTS *const counts) { |
| 4137 | if (*interp_filter == SWITCHABLE) { |
| 4138 | // Check to see if only one of the filters is actually used |
| 4139 | int count[SWITCHABLE_FILTERS] = { 0 }; |
| 4140 | int num_filters_used = 0; |
| 4141 | for (int i = 0; i < SWITCHABLE_FILTERS; ++i) { |
| 4142 | for (int j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) |
| 4143 | count[i] += counts->switchable_interp[j][i]; |
| 4144 | num_filters_used += (count[i] > 0); |
| 4145 | } |
| 4146 | if (num_filters_used == 1) { |
| 4147 | // Only one filter is used. So set the filter at frame level |
| 4148 | for (int i = 0; i < SWITCHABLE_FILTERS; ++i) { |
| 4149 | if (count[i]) { |
| 4150 | if (i == EIGHTTAP_REGULAR) *interp_filter = i; |
| 4151 | break; |
| 4152 | } |
| 4153 | } |
| 4154 | } |
| 4155 | } |
| 4156 | } |
| 4157 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4158 | static void finalize_encoded_frame(AV1_COMP *const cpi) { |
| 4159 | AV1_COMMON *const cm = &cpi->common; |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4160 | CurrentFrame *const current_frame = &cm->current_frame; |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4161 | |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4162 | if (!cm->seq_params.reduced_still_picture_hdr && |
| 4163 | encode_show_existing_frame(cm)) { |
| 4164 | RefCntBuffer *const frame_to_show = |
| 4165 | cm->ref_frame_map[cpi->existing_fb_idx_to_show]; |
| 4166 | |
Wan-Teh Chang | 88cd166 | 2019-01-14 12:38:41 -0800 | [diff] [blame] | 4167 | if (frame_to_show == NULL) { |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4168 | aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
| 4169 | "Buffer does not contain a reconstructed frame"); |
| 4170 | } |
Wan-Teh Chang | 88cd166 | 2019-01-14 12:38:41 -0800 | [diff] [blame] | 4171 | assert(frame_to_show->ref_count > 0); |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4172 | assign_frame_buffer_p(&cm->cur_frame, frame_to_show); |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 4173 | } |
David Turner | 08f909c | 2018-12-18 13:29:14 +0000 | [diff] [blame] | 4174 | |
| 4175 | if (!encode_show_existing_frame(cm) && |
| 4176 | cm->seq_params.film_grain_params_present && |
| 4177 | (cm->show_frame || cm->showable_frame)) { |
| 4178 | // Copy the current frame's film grain params to the its corresponding |
| 4179 | // RefCntBuffer slot. |
| 4180 | cm->cur_frame->film_grain_params = cm->film_grain_params; |
| 4181 | |
| 4182 | // We must update the parameters if this is not an INTER_FRAME |
| 4183 | if (current_frame->frame_type != INTER_FRAME) |
| 4184 | cm->cur_frame->film_grain_params.update_parameters = 1; |
| 4185 | |
| 4186 | // Iterate the random seed for the next frame. |
| 4187 | cm->film_grain_params.random_seed += 3381; |
| 4188 | if (cm->film_grain_params.random_seed == 0) |
| 4189 | cm->film_grain_params.random_seed = 7391; |
| 4190 | } |
David Turner | f2b334c | 2018-12-13 13:00:55 +0000 | [diff] [blame] | 4191 | |
| 4192 | // Initialise all tiles' contexts from the global frame context |
| 4193 | for (int tile_col = 0; tile_col < cm->tile_cols; tile_col++) { |
| 4194 | for (int tile_row = 0; tile_row < cm->tile_rows; tile_row++) { |
| 4195 | const int tile_idx = tile_row * cm->tile_cols + tile_col; |
| 4196 | cpi->tile_data[tile_idx].tctx = *cm->fc; |
| 4197 | } |
| 4198 | } |
| 4199 | |
| 4200 | fix_interp_filter(&cm->interp_filter, cpi->td.counts); |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4201 | } |
| 4202 | |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4203 | static int get_regulated_q_overshoot(AV1_COMP *const cpi, int q_low, int q_high, |
| 4204 | int top_index, int bottom_index) { |
| 4205 | const AV1_COMMON *const cm = &cpi->common; |
| 4206 | const RATE_CONTROL *const rc = &cpi->rc; |
| 4207 | |
| 4208 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4209 | |
| 4210 | int q_regulated = |
| 4211 | av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4212 | AOMMAX(q_high, top_index), cm->width, cm->height); |
| 4213 | |
| 4214 | int retries = 0; |
| 4215 | while (q_regulated < q_low && retries < 10) { |
| 4216 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4217 | q_regulated = |
| 4218 | av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4219 | AOMMAX(q_high, top_index), cm->width, cm->height); |
| 4220 | retries++; |
| 4221 | } |
| 4222 | return q_regulated; |
| 4223 | } |
| 4224 | |
| 4225 | static int get_regulated_q_undershoot(AV1_COMP *const cpi, int q_high, |
| 4226 | int top_index, int bottom_index) { |
| 4227 | const AV1_COMMON *const cm = &cpi->common; |
| 4228 | const RATE_CONTROL *const rc = &cpi->rc; |
| 4229 | |
| 4230 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4231 | int q_regulated = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4232 | top_index, cm->width, cm->height); |
| 4233 | |
| 4234 | int retries = 0; |
| 4235 | while (q_regulated > q_high && retries < 10) { |
| 4236 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4237 | q_regulated = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4238 | top_index, cm->width, cm->height); |
| 4239 | retries++; |
| 4240 | } |
| 4241 | return q_regulated; |
| 4242 | } |
| 4243 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4244 | // Called after encode_with_recode_loop() has just encoded a frame and packed |
| 4245 | // its bitstream. This function works out whether we under- or over-shot |
| 4246 | // our bitrate target and adjusts q as appropriate. Also decides whether |
| 4247 | // or not we should do another recode loop, indicated by *loop |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 4248 | static void recode_loop_update_q( |
| 4249 | AV1_COMP *const cpi, int *const loop, int *const q, int *const q_low, |
| 4250 | int *const q_high, const int top_index, const int bottom_index, |
| 4251 | int *const undershoot_seen, int *const overshoot_seen, |
| 4252 | int *const low_cr_seen, const int loop_at_this_size) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4253 | AV1_COMMON *const cm = &cpi->common; |
| 4254 | RATE_CONTROL *const rc = &cpi->rc; |
| 4255 | |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 4256 | const int min_cr = cpi->oxcf.min_cr; |
| 4257 | if (min_cr > 0) { |
| 4258 | aom_clear_system_state(); |
| 4259 | const double compression_ratio = |
| 4260 | av1_get_compression_ratio(cm, rc->projected_frame_size >> 3); |
| 4261 | const double target_cr = min_cr / 100.0; |
| 4262 | if (compression_ratio < target_cr) { |
| 4263 | *low_cr_seen = 1; |
| 4264 | if (*q < rc->worst_quality) { |
| 4265 | const double cr_ratio = target_cr / compression_ratio; |
| 4266 | const int projected_q = AOMMAX(*q + 1, (int)(*q * cr_ratio * cr_ratio)); |
| 4267 | *q = AOMMIN(AOMMIN(projected_q, *q + 32), rc->worst_quality); |
| 4268 | *q_low = AOMMAX(*q, *q_low); |
| 4269 | *q_high = AOMMAX(*q, *q_high); |
| 4270 | *loop = 1; |
| 4271 | } |
| 4272 | } |
| 4273 | if (*low_cr_seen) return; |
| 4274 | } |
| 4275 | |
| 4276 | if (cpi->oxcf.rc_mode == AOM_Q) return; |
| 4277 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4278 | int frame_over_shoot_limit = 0, frame_under_shoot_limit = 0; |
| 4279 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4280 | &frame_under_shoot_limit, |
| 4281 | &frame_over_shoot_limit); |
| 4282 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4283 | |
| 4284 | if ((cm->current_frame.frame_type == KEY_FRAME) && |
| 4285 | rc->this_key_frame_forced && |
| 4286 | (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
| 4287 | int last_q = *q; |
| 4288 | int64_t kf_err; |
| 4289 | |
| 4290 | int64_t high_err_target = cpi->ambient_err; |
| 4291 | int64_t low_err_target = cpi->ambient_err >> 1; |
| 4292 | |
| 4293 | if (cm->seq_params.use_highbitdepth) { |
| 4294 | kf_err = aom_highbd_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 4295 | } else { |
| 4296 | kf_err = aom_get_y_sse(cpi->source, &cm->cur_frame->buf); |
| 4297 | } |
| 4298 | // Prevent possible divide by zero error below for perfect KF |
| 4299 | kf_err += !kf_err; |
| 4300 | |
| 4301 | // The key frame is not good enough or we can afford |
| 4302 | // to make it better without undue risk of popping. |
| 4303 | if ((kf_err > high_err_target && |
| 4304 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4305 | (kf_err > low_err_target && |
| 4306 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4307 | // Lower q_high |
| 4308 | *q_high = *q > *q_low ? *q - 1 : *q_low; |
| 4309 | |
| 4310 | // Adjust Q |
| 4311 | *q = (int)((*q * high_err_target) / kf_err); |
| 4312 | *q = AOMMIN(*q, (*q_high + *q_low) >> 1); |
| 4313 | } else if (kf_err < low_err_target && |
| 4314 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4315 | // The key frame is much better than the previous frame |
| 4316 | // Raise q_low |
| 4317 | *q_low = *q < *q_high ? *q + 1 : *q_high; |
| 4318 | |
| 4319 | // Adjust Q |
| 4320 | *q = (int)((*q * low_err_target) / kf_err); |
| 4321 | *q = AOMMIN(*q, (*q_high + *q_low + 1) >> 1); |
| 4322 | } |
| 4323 | |
| 4324 | // Clamp Q to upper and lower limits: |
| 4325 | *q = clamp(*q, *q_low, *q_high); |
| 4326 | |
| 4327 | *loop = *q != last_q; |
| 4328 | } else if (recode_loop_test(cpi, frame_over_shoot_limit, |
| 4329 | frame_under_shoot_limit, *q, |
| 4330 | AOMMAX(*q_high, top_index), bottom_index)) { |
| 4331 | // Is the projected frame size out of range and are we allowed |
| 4332 | // to attempt to recode. |
| 4333 | int last_q = *q; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4334 | |
| 4335 | // Frame size out of permitted range: |
| 4336 | // Update correction factor & compute new Q to try... |
| 4337 | // Frame is too large |
| 4338 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 4339 | // Special case if the projected size is > the max allowed. |
| 4340 | if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
| 4341 | *q_high = rc->worst_quality; |
| 4342 | |
| 4343 | // Raise Qlow as to at least the current value |
| 4344 | *q_low = *q < *q_high ? *q + 1 : *q_high; |
| 4345 | |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4346 | if (*undershoot_seen || loop_at_this_size > 2 || |
| 4347 | (loop_at_this_size == 2 && !frame_is_intra_only(cm))) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4348 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4349 | |
| 4350 | *q = (*q_high + *q_low + 1) / 2; |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4351 | } else if (loop_at_this_size == 2 && frame_is_intra_only(cm)) { |
| 4352 | const int q_mid = (*q_high + *q_low + 1) / 2; |
| 4353 | const int q_regulated = get_regulated_q_overshoot( |
| 4354 | cpi, *q_low, *q_high, top_index, bottom_index); |
| 4355 | // Get 'q' in-between 'q_mid' and 'q_regulated' for a smooth |
| 4356 | // transition between loop_at_this_size < 2 and loop_at_this_size > 2. |
| 4357 | *q = (q_mid + q_regulated + 1) / 2; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4358 | } else { |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4359 | *q = get_regulated_q_overshoot(cpi, *q_low, *q_high, top_index, |
| 4360 | bottom_index); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | *overshoot_seen = 1; |
| 4364 | } else { |
| 4365 | // Frame is too small |
| 4366 | *q_high = *q > *q_low ? *q - 1 : *q_low; |
| 4367 | |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4368 | if (*overshoot_seen || loop_at_this_size > 2 || |
| 4369 | (loop_at_this_size == 2 && !frame_is_intra_only(cm))) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4370 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
| 4371 | *q = (*q_high + *q_low) / 2; |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4372 | } else if (loop_at_this_size == 2 && frame_is_intra_only(cm)) { |
| 4373 | const int q_mid = (*q_high + *q_low) / 2; |
| 4374 | const int q_regulated = |
| 4375 | get_regulated_q_undershoot(cpi, *q_high, top_index, bottom_index); |
| 4376 | // Get 'q' in-between 'q_mid' and 'q_regulated' for a smooth |
| 4377 | // transition between loop_at_this_size < 2 and loop_at_this_size > 2. |
| 4378 | *q = (q_mid + q_regulated) / 2; |
| 4379 | |
| 4380 | // Special case reset for qlow for constrained quality. |
| 4381 | // This should only trigger where there is very substantial |
| 4382 | // undershoot on a frame and the auto cq level is above |
| 4383 | // the user passsed in value. |
| 4384 | if (cpi->oxcf.rc_mode == AOM_CQ && q_regulated < *q_low) { |
| 4385 | *q_low = *q; |
| 4386 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4387 | } else { |
Urvang Joshi | 5764337 | 2019-02-21 11:10:57 -0800 | [diff] [blame] | 4388 | *q = get_regulated_q_undershoot(cpi, *q_high, top_index, bottom_index); |
| 4389 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4390 | // Special case reset for qlow for constrained quality. |
| 4391 | // This should only trigger where there is very substantial |
| 4392 | // undershoot on a frame and the auto cq level is above |
| 4393 | // the user passsed in value. |
| 4394 | if (cpi->oxcf.rc_mode == AOM_CQ && *q < *q_low) { |
| 4395 | *q_low = *q; |
| 4396 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4397 | } |
| 4398 | |
| 4399 | *undershoot_seen = 1; |
| 4400 | } |
| 4401 | |
| 4402 | // Clamp Q to upper and lower limits: |
| 4403 | *q = clamp(*q, *q_low, *q_high); |
| 4404 | |
| 4405 | *loop = (*q != last_q); |
| 4406 | } else { |
| 4407 | *loop = 0; |
| 4408 | } |
| 4409 | } |
| 4410 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4411 | 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] | 4412 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4413 | RATE_CONTROL *const rc = &cpi->rc; |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 4414 | const int allow_recode = (cpi->sf.recode_loop != DISALLOW_RECODE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4415 | |
| 4416 | set_size_independent_vars(cpi); |
| 4417 | |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4418 | cpi->source->buf_8bit_valid = 0; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4419 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 4420 | av1_setup_frame_size(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4421 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4422 | int top_index = 0, bottom_index = 0; |
| 4423 | int q = 0, q_low = 0, q_high = 0; |
| 4424 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4425 | q_low = bottom_index; |
| 4426 | q_high = top_index; |
| 4427 | |
| 4428 | // Loop variables |
| 4429 | int loop_count = 0; |
| 4430 | int loop_at_this_size = 0; |
| 4431 | int loop = 0; |
| 4432 | int overshoot_seen = 0; |
| 4433 | int undershoot_seen = 0; |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 4434 | int low_cr_seen = 0; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4435 | |
| 4436 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4437 | printf("\n Encoding a frame:"); |
| 4438 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4439 | do { |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 4440 | loop = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4441 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4442 | |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 4443 | // if frame was scaled calculate global_motion_search again if already |
| 4444 | // done |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4445 | if (loop_count > 0 && cpi->source && cpi->global_motion_search_done) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4446 | if (cpi->source->y_crop_width != cm->width || |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4447 | cpi->source->y_crop_height != cm->height) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4448 | cpi->global_motion_search_done = 0; |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4449 | } |
| 4450 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4451 | cpi->source = |
| 4452 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4453 | if (cpi->unscaled_last_source != NULL) { |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4454 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4455 | &cpi->scaled_last_source); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4456 | } |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4457 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4458 | if (!frame_is_intra_only(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4459 | if (loop_count > 0) { |
| 4460 | release_scaled_references(cpi); |
| 4461 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4462 | scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4463 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4464 | av1_set_quantizer(cm, q); |
Yue Chen | a7d8048 | 2019-01-31 09:48:09 -0800 | [diff] [blame] | 4465 | av1_init_quantizer(cpi); |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 4466 | |
| 4467 | av1_set_variance_partition_thresholds(cpi, q, 0); |
| 4468 | |
Debargha Mukherjee | f48b0d2 | 2018-11-20 12:23:43 -0800 | [diff] [blame] | 4469 | // printf("Frame %d/%d: q = %d, frame_type = %d superres_denom = %d\n", |
| 4470 | // cm->current_frame.frame_number, cm->show_frame, q, |
| 4471 | // cm->current_frame.frame_type, cm->superres_scale_denominator); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4472 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4473 | if (loop_count == 0) { |
| 4474 | setup_frame(cpi); |
| 4475 | } else if (get_primary_ref_frame_buf(cm) == NULL) { |
| 4476 | // Base q-index may have changed, so we need to assign proper default coef |
| 4477 | // probs before every iteration. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4478 | av1_default_coef_probs(cm); |
Hui Su | 3694c83 | 2017-11-10 14:15:58 -0800 | [diff] [blame] | 4479 | av1_setup_frame_contexts(cm); |
David Barker | fc91b39 | 2018-03-09 15:32:03 +0000 | [diff] [blame] | 4480 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4481 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4482 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4483 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4484 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4485 | av1_setup_in_frame_q_adj(cpi); |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4486 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && !allow_recode) { |
| 4487 | suppress_active_map(cpi); |
| 4488 | av1_cyclic_refresh_setup(cpi); |
| 4489 | apply_active_map(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4490 | } |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4491 | |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4492 | if (cm->seg.enabled) { |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4493 | if (!cm->seg.update_data && cm->prev_frame) { |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4494 | segfeatures_copy(&cm->seg, &cm->prev_frame->seg); |
David Barker | 11c9356 | 2018-06-05 12:00:07 +0100 | [diff] [blame] | 4495 | } else { |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 4496 | av1_calculate_segdata(&cm->seg); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 4497 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4498 | } else { |
| 4499 | memset(&cm->seg, 0, sizeof(cm->seg)); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 4500 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 4501 | segfeatures_copy(&cm->cur_frame->seg, &cm->seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4502 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4503 | if (allow_recode) save_coding_context(cpi); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4504 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4505 | start_timing(cpi, av1_encode_frame_time); |
| 4506 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4507 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4508 | av1_encode_frame(cpi); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4509 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4510 | end_timing(cpi, av1_encode_frame_time); |
| 4511 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4512 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4513 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4514 | |
| 4515 | // Dummy pack of the bitstream using up to date stats to get an |
| 4516 | // accurate estimate of output frame size to determine if we need |
| 4517 | // to recode. |
| 4518 | if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4519 | restore_coding_context(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4520 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4521 | finalize_encoded_frame(cpi); |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 4522 | int largest_tile_id = 0; // Output from bitstream: unused here |
| 4523 | 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] | 4524 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4525 | |
| 4526 | rc->projected_frame_size = (int)(*size) << 3; |
| 4527 | restore_coding_context(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4528 | } |
| 4529 | |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 4530 | if (allow_recode) { |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4531 | // Update q and decide whether to do a recode loop |
| 4532 | recode_loop_update_q(cpi, &loop, &q, &q_low, &q_high, top_index, |
| 4533 | bottom_index, &undershoot_seen, &overshoot_seen, |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 4534 | &low_cr_seen, loop_at_this_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4535 | } |
| 4536 | |
| 4537 | // Special case for overlay frame. |
| 4538 | if (rc->is_src_frame_alt_ref && |
| 4539 | rc->projected_frame_size < rc->max_frame_bandwidth) |
| 4540 | loop = 0; |
| 4541 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 4542 | if (allow_recode && !cpi->sf.gm_disable_recode && |
| 4543 | recode_loop_test_global_motion(cpi)) { |
| 4544 | loop = 1; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4545 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4546 | |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 4547 | if (cpi->tpl_model_pass == 1) { |
| 4548 | assert(cpi->oxcf.enable_tpl_model == 2); |
Debargha Mukherjee | 347c64d | 2019-05-08 13:53:46 -0700 | [diff] [blame] | 4549 | av1_tpl_setup_forward_stats(cpi); |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 4550 | cpi->tpl_model_pass = 0; |
| 4551 | loop = 1; |
| 4552 | } |
| 4553 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4554 | if (loop) { |
| 4555 | ++loop_count; |
| 4556 | ++loop_at_this_size; |
| 4557 | |
| 4558 | #if CONFIG_INTERNAL_STATS |
| 4559 | ++cpi->tot_recode_hits; |
| 4560 | #endif |
| 4561 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4562 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4563 | if (loop) printf("\n Recoding:"); |
| 4564 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4565 | } while (loop); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4566 | |
| 4567 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4568 | } |
| 4569 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4570 | #define DUMP_RECON_FRAMES 0 |
| 4571 | |
| 4572 | #if DUMP_RECON_FRAMES == 1 |
| 4573 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4574 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 4575 | AV1_COMMON *const cm = &cpi->common; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4576 | const CurrentFrame *const current_frame = &cm->current_frame; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 4577 | const YV12_BUFFER_CONFIG *recon_buf = &cm->cur_frame->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4578 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4579 | if (recon_buf == NULL) { |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4580 | printf("Frame %d is not ready.\n", current_frame->frame_number); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4581 | return; |
| 4582 | } |
| 4583 | |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 4584 | static const int flag_list[REF_FRAMES] = { 0, |
| 4585 | AOM_LAST_FLAG, |
| 4586 | AOM_LAST2_FLAG, |
| 4587 | AOM_LAST3_FLAG, |
| 4588 | AOM_GOLD_FLAG, |
| 4589 | AOM_BWD_FLAG, |
| 4590 | AOM_ALT2_FLAG, |
| 4591 | AOM_ALT_FLAG }; |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4592 | printf( |
| 4593 | "\n***Frame=%d (frame_offset=%d, show_frame=%d, " |
| 4594 | "show_existing_frame=%d) " |
| 4595 | "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[", |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4596 | current_frame->frame_number, current_frame->order_hint, cm->show_frame, |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4597 | cm->show_existing_frame); |
| 4598 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4599 | const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame); |
| 4600 | const int ref_offset = buf != NULL ? (int)buf->order_hint : -1; |
Urvang Joshi | b6f1767 | 2019-03-05 11:51:02 -0800 | [diff] [blame] | 4601 | printf(" %d(%c)", ref_offset, |
| 4602 | (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N'); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4603 | } |
| 4604 | printf(" ]\n"); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4605 | |
| 4606 | if (!cm->show_frame) { |
| 4607 | 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] | 4608 | current_frame->frame_number); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4609 | return; |
| 4610 | } |
| 4611 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4612 | int h; |
| 4613 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 4614 | FILE *f_recon = NULL; |
| 4615 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4616 | if (current_frame->frame_number == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4617 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 4618 | printf("Unable to open file %s to write.\n", file_name); |
| 4619 | return; |
| 4620 | } |
| 4621 | } else { |
| 4622 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 4623 | printf("Unable to open file %s to append.\n", file_name); |
| 4624 | return; |
| 4625 | } |
| 4626 | } |
| 4627 | printf( |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4628 | "\nFrame=%5d, encode_update_type[%5d]=%1d, frame_offset=%d, " |
| 4629 | "show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, " |
Urvang Joshi | 7a89023 | 2019-03-22 17:00:31 -0700 | [diff] [blame] | 4630 | "refresh_alt_ref_frame=%d, " |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4631 | "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] | 4632 | current_frame->frame_number, cpi->twopass.gf_group.index, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4633 | cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4634 | current_frame->order_hint, cm->show_frame, cm->show_existing_frame, |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4635 | cpi->rc.source_alt_ref_active, cpi->refresh_alt_ref_frame, |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 4636 | recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4637 | #if 0 |
| 4638 | int ref_frame; |
| 4639 | printf("get_ref_frame_map_idx: ["); |
| 4640 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4641 | printf(" %d", get_ref_frame_map_idx(cm, ref_frame)); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4642 | printf(" ]\n"); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4643 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4644 | |
| 4645 | // --- Y --- |
| 4646 | for (h = 0; h < cm->height; ++h) { |
| 4647 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 4648 | f_recon); |
| 4649 | } |
| 4650 | // --- U --- |
| 4651 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4652 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4653 | f_recon); |
| 4654 | } |
| 4655 | // --- V --- |
| 4656 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4657 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4658 | f_recon); |
| 4659 | } |
| 4660 | |
| 4661 | fclose(f_recon); |
| 4662 | } |
| 4663 | #endif // DUMP_RECON_FRAMES |
| 4664 | |
David Turner | bc0993e | 2019-02-15 14:42:23 +0000 | [diff] [blame] | 4665 | static int get_interp_filter_selected(const AV1_COMMON *const cm, |
| 4666 | MV_REFERENCE_FRAME ref, |
| 4667 | InterpFilters ifilter) { |
| 4668 | const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref); |
| 4669 | if (buf == NULL) return 0; |
| 4670 | return buf->interp_filter_selected[ifilter]; |
| 4671 | } |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 4672 | |
David Turner | bc0993e | 2019-02-15 14:42:23 +0000 | [diff] [blame] | 4673 | static int setup_interp_filter_search_mask(AV1_COMP *cpi) { |
| 4674 | const AV1_COMMON *const cm = &cpi->common; |
| 4675 | int ref_total[REF_FRAMES] = { 0 }; |
| 4676 | |
| 4677 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame) |
| 4678 | return 0; |
| 4679 | |
| 4680 | for (MV_REFERENCE_FRAME ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) { |
| 4681 | for (InterpFilters ifilter = EIGHTTAP_REGULAR; ifilter <= MULTITAP_SHARP; |
| 4682 | ++ifilter) { |
| 4683 | ref_total[ref] += get_interp_filter_selected(cm, ref, ifilter); |
| 4684 | } |
| 4685 | } |
| 4686 | int ref_total_total = (ref_total[LAST2_FRAME] + ref_total[LAST3_FRAME] + |
| 4687 | ref_total[GOLDEN_FRAME] + ref_total[BWDREF_FRAME] + |
| 4688 | ref_total[ALTREF2_FRAME] + ref_total[ALTREF_FRAME]); |
| 4689 | |
| 4690 | int mask = 0; |
| 4691 | for (InterpFilters ifilter = EIGHTTAP_REGULAR; ifilter <= MULTITAP_SHARP; |
| 4692 | ++ifilter) { |
| 4693 | int last_score = get_interp_filter_selected(cm, LAST_FRAME, ifilter) * 30; |
| 4694 | if (ref_total[LAST_FRAME] && last_score <= ref_total[LAST_FRAME]) { |
| 4695 | int filter_score = |
| 4696 | get_interp_filter_selected(cm, LAST2_FRAME, ifilter) * 20 + |
| 4697 | get_interp_filter_selected(cm, LAST3_FRAME, ifilter) * 20 + |
| 4698 | get_interp_filter_selected(cm, GOLDEN_FRAME, ifilter) * 20 + |
| 4699 | get_interp_filter_selected(cm, BWDREF_FRAME, ifilter) * 10 + |
| 4700 | get_interp_filter_selected(cm, ALTREF2_FRAME, ifilter) * 10 + |
| 4701 | get_interp_filter_selected(cm, ALTREF_FRAME, ifilter) * 10; |
| 4702 | if (filter_score < ref_total_total) mask |= 1 << ifilter; |
| 4703 | } |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 4704 | } |
| 4705 | return mask; |
| 4706 | } |
| 4707 | |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 4708 | static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture, |
| 4709 | const YV12_BUFFER_CONFIG *last_picture, |
| 4710 | hash_table *last_hash_table) { |
| 4711 | aom_clear_system_state(); |
| 4712 | // check use hash ME |
| 4713 | int k; |
| 4714 | uint32_t hash_value_1; |
| 4715 | uint32_t hash_value_2; |
| 4716 | |
| 4717 | const int block_size = 8; |
| 4718 | const double threshold_current = 0.8; |
| 4719 | const double threshold_average = 0.95; |
| 4720 | const int max_history_size = 32; |
| 4721 | int T = 0; // total block |
| 4722 | int C = 0; // match with collocated block |
| 4723 | int S = 0; // smooth region but not match with collocated block |
| 4724 | int M = 0; // match with other block |
| 4725 | |
| 4726 | const int pic_width = cur_picture->y_width; |
| 4727 | const int pic_height = cur_picture->y_height; |
| 4728 | for (int i = 0; i + block_size <= pic_height; i += block_size) { |
| 4729 | for (int j = 0; j + block_size <= pic_width; j += block_size) { |
| 4730 | const int x_pos = j; |
| 4731 | const int y_pos = i; |
| 4732 | int match = 1; |
| 4733 | T++; |
| 4734 | |
| 4735 | // check whether collocated block match with current |
| 4736 | uint8_t *p_cur = cur_picture->y_buffer; |
| 4737 | uint8_t *p_ref = last_picture->y_buffer; |
| 4738 | int stride_cur = cur_picture->y_stride; |
| 4739 | int stride_ref = last_picture->y_stride; |
| 4740 | p_cur += (y_pos * stride_cur + x_pos); |
| 4741 | p_ref += (y_pos * stride_ref + x_pos); |
| 4742 | |
| 4743 | if (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 4744 | uint16_t *p16_cur = CONVERT_TO_SHORTPTR(p_cur); |
| 4745 | uint16_t *p16_ref = CONVERT_TO_SHORTPTR(p_ref); |
| 4746 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 4747 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 4748 | if (p16_cur[tmpX] != p16_ref[tmpX]) { |
| 4749 | match = 0; |
| 4750 | } |
| 4751 | } |
| 4752 | p16_cur += stride_cur; |
| 4753 | p16_ref += stride_ref; |
| 4754 | } |
| 4755 | } else { |
| 4756 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 4757 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 4758 | if (p_cur[tmpX] != p_ref[tmpX]) { |
| 4759 | match = 0; |
| 4760 | } |
| 4761 | } |
| 4762 | p_cur += stride_cur; |
| 4763 | p_ref += stride_ref; |
| 4764 | } |
| 4765 | } |
| 4766 | |
| 4767 | if (match) { |
| 4768 | C++; |
| 4769 | continue; |
| 4770 | } |
| 4771 | |
| 4772 | if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos, |
| 4773 | y_pos) || |
| 4774 | av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) { |
| 4775 | S++; |
| 4776 | continue; |
| 4777 | } |
| 4778 | |
| 4779 | av1_get_block_hash_value( |
| 4780 | cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur, |
| 4781 | block_size, &hash_value_1, &hash_value_2, |
| 4782 | (cur_picture->flags & YV12_FLAG_HIGHBITDEPTH), &cpi->td.mb); |
| 4783 | // Hashing does not work for highbitdepth currently. |
| 4784 | // TODO(Roger): Make it work for highbitdepth. |
| 4785 | if (av1_use_hash_me(&cpi->common)) { |
| 4786 | if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) { |
| 4787 | M++; |
| 4788 | } |
| 4789 | } |
| 4790 | } |
| 4791 | } |
| 4792 | |
| 4793 | assert(T > 0); |
| 4794 | double csm_rate = ((double)(C + S + M)) / ((double)(T)); |
| 4795 | double m_rate = ((double)(M)) / ((double)(T)); |
| 4796 | |
| 4797 | cpi->csm_rate_array[cpi->rate_index] = csm_rate; |
| 4798 | cpi->m_rate_array[cpi->rate_index] = m_rate; |
| 4799 | |
| 4800 | cpi->rate_index = (cpi->rate_index + 1) % max_history_size; |
| 4801 | cpi->rate_size++; |
| 4802 | cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size); |
| 4803 | |
| 4804 | if (csm_rate < threshold_current) { |
| 4805 | return 0; |
| 4806 | } |
| 4807 | |
| 4808 | if (C == T) { |
| 4809 | return 1; |
| 4810 | } |
| 4811 | |
| 4812 | double csm_average = 0.0; |
| 4813 | double m_average = 0.0; |
| 4814 | |
| 4815 | for (k = 0; k < cpi->rate_size; k++) { |
| 4816 | csm_average += cpi->csm_rate_array[k]; |
| 4817 | m_average += cpi->m_rate_array[k]; |
| 4818 | } |
| 4819 | csm_average /= cpi->rate_size; |
| 4820 | m_average /= cpi->rate_size; |
| 4821 | |
| 4822 | if (csm_average < threshold_average) { |
| 4823 | return 0; |
| 4824 | } |
| 4825 | |
| 4826 | if (M > (T - C - S) / 3) { |
| 4827 | return 1; |
| 4828 | } |
| 4829 | |
| 4830 | if (csm_rate > 0.99 && m_rate > 0.01) { |
| 4831 | return 1; |
| 4832 | } |
| 4833 | |
| 4834 | if (csm_average + m_average > 1.01) { |
| 4835 | return 1; |
| 4836 | } |
| 4837 | |
| 4838 | return 0; |
| 4839 | } |
| 4840 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 4841 | // Refresh reference frame buffers according to refresh_frame_flags. |
| 4842 | static void refresh_reference_frames(AV1_COMP *cpi) { |
| 4843 | AV1_COMMON *const cm = &cpi->common; |
| 4844 | // All buffers are refreshed for shown keyframes and S-frames. |
| 4845 | |
| 4846 | for (int ref_frame = 0; ref_frame < REF_FRAMES; ref_frame++) { |
| 4847 | if (((cm->current_frame.refresh_frame_flags >> ref_frame) & 1) == 1) { |
| 4848 | assign_frame_buffer_p(&cm->ref_frame_map[ref_frame], cm->cur_frame); |
| 4849 | } |
| 4850 | } |
| 4851 | } |
| 4852 | |
| 4853 | static int encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, |
| 4854 | uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4855 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4856 | SequenceHeader *const seq_params = &cm->seq_params; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4857 | CurrentFrame *const current_frame = &cm->current_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4858 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4859 | struct segmentation *const seg = &cm->seg; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 4860 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 4861 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 4862 | start_timing(cpi, encode_frame_to_data_rate_time); |
| 4863 | #endif |
| 4864 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 4865 | // frame type has been decided outside of this function call |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4866 | cm->cur_frame->frame_type = current_frame->frame_type; |
Debargha Mukherjee | 07a7c1f | 2018-03-21 17:39:13 -0700 | [diff] [blame] | 4867 | |
Yunqing Wang | 9612d55 | 2018-05-15 14:58:30 -0700 | [diff] [blame] | 4868 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 4869 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Yunqing Wang | 9612d55 | 2018-05-15 14:58:30 -0700 | [diff] [blame] | 4870 | |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 4871 | cm->allow_ref_frame_mvs &= frame_might_allow_ref_frame_mvs(cm); |
Yunqing Wang | d48fb16 | 2018-06-15 10:55:28 -0700 | [diff] [blame] | 4872 | // cm->allow_ref_frame_mvs needs to be written into the frame header while |
| 4873 | // cm->large_scale_tile is 1, therefore, "cm->large_scale_tile=1" case is |
| 4874 | // separated from frame_might_allow_ref_frame_mvs(). |
| 4875 | cm->allow_ref_frame_mvs &= !cm->large_scale_tile; |
| 4876 | |
Debargha Mukherjee | 1d7217e | 2018-03-26 13:32:13 -0700 | [diff] [blame] | 4877 | cm->allow_warped_motion = |
Debargha Mukherjee | a5b810a | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 4878 | cpi->oxcf.allow_warped_motion && frame_might_allow_warped_motion(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4879 | |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 4880 | cm->last_frame_type = current_frame->frame_type; |
| 4881 | if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search) |
| 4882 | cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi); |
| 4883 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 4884 | if (encode_show_existing_frame(cm)) { |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4885 | restore_coding_context(cpi); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 4886 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4887 | finalize_encoded_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4888 | // Build the bitstream |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 4889 | int largest_tile_id = 0; // Output from bitstream: unused here |
| 4890 | 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] | 4891 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4892 | |
David Turner | 9031186 | 2018-11-29 13:34:36 +0000 | [diff] [blame] | 4893 | if (seq_params->frame_id_numbers_present_flag && |
| 4894 | current_frame->frame_type == KEY_FRAME) { |
| 4895 | // Displaying a forward key-frame, so reset the ref buffer IDs |
| 4896 | int display_frame_id = cm->ref_frame_id[cpi->existing_fb_idx_to_show]; |
| 4897 | for (int i = 0; i < REF_FRAMES; i++) |
| 4898 | cm->ref_frame_id[i] = display_frame_id; |
| 4899 | } |
| 4900 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 4901 | cpi->seq_params_locked = 1; |
| 4902 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4903 | #if DUMP_RECON_FRAMES == 1 |
| 4904 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 4905 | dump_filtered_recon_frames(cpi); |
| 4906 | #endif // DUMP_RECON_FRAMES |
| 4907 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 4908 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 4909 | // for the purpose to verify no mismatch between encoder and decoder. |
| 4910 | if (cm->show_frame) cpi->last_show_frame_buf = cm->cur_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4911 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 4912 | refresh_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4913 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4914 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 4915 | // to do post-encoding update accordingly. |
| 4916 | if (cpi->rc.is_src_frame_alt_ref) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4917 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4918 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4919 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4920 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4921 | ++current_frame->frame_number; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4922 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4923 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4924 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4925 | |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 4926 | // Work out whether to force_integer_mv this frame |
| 4927 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools && |
| 4928 | !frame_is_intra_only(cm)) { |
| 4929 | if (cpi->common.seq_params.force_integer_mv == 2) { |
| 4930 | // Adaptive mode: see what previous frame encoded did |
| 4931 | if (cpi->unscaled_last_source != NULL) { |
| 4932 | cm->cur_frame_force_integer_mv = |
| 4933 | is_integer_mv(cpi, cpi->source, cpi->unscaled_last_source, |
| 4934 | cpi->previous_hash_table); |
| 4935 | } else { |
| 4936 | cpi->common.cur_frame_force_integer_mv = 0; |
| 4937 | } |
| 4938 | } else { |
| 4939 | cpi->common.cur_frame_force_integer_mv = |
| 4940 | cpi->common.seq_params.force_integer_mv; |
| 4941 | } |
| 4942 | } else { |
| 4943 | cpi->common.cur_frame_force_integer_mv = 0; |
| 4944 | } |
| 4945 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4946 | // Set default state for segment based loop filter update flags. |
| 4947 | cm->lf.mode_ref_delta_update = 0; |
| 4948 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4949 | // 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] | 4950 | if (frame_is_intra_only(cm) || frame_is_sframe(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4951 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4952 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4953 | |
| 4954 | // If segmentation is enabled force a map update for key frames. |
| 4955 | if (seg->enabled) { |
| 4956 | seg->update_map = 1; |
| 4957 | seg->update_data = 1; |
| 4958 | } |
| 4959 | |
| 4960 | // The alternate reference frame cannot be active for a key frame. |
| 4961 | cpi->rc.source_alt_ref_active = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4962 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4963 | if (cpi->oxcf.mtu == 0) { |
| 4964 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 4965 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 4966 | // Use a default value for the purposes of weighting costs in probability |
| 4967 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4968 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 4969 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4970 | |
| 4971 | // For 1 pass CBR, check if we are dropping this frame. |
| 4972 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4973 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4974 | current_frame->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4975 | if (av1_rc_drop_frame(cpi)) { |
| 4976 | av1_rc_postencode_update_drop_frame(cpi); |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 4977 | release_scaled_references(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 4978 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4979 | } |
| 4980 | } |
| 4981 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4982 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4983 | |
| 4984 | #if CONFIG_INTERNAL_STATS |
| 4985 | memset(cpi->mode_chosen_counts, 0, |
| 4986 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 4987 | #endif |
| 4988 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4989 | if (seq_params->frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4990 | /* Non-normative definition of current_frame_id ("frame counter" with |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 4991 | * wraparound) */ |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4992 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4993 | int lsb, msb; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 4994 | /* quasi-random initialization of current_frame_id for a key frame */ |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4995 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 4996 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 4997 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4998 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4999 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 5000 | msb = cpi->source->y_buffer[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5001 | } |
David Turner | 760a2f4 | 2018-12-07 15:25:36 +0000 | [diff] [blame] | 5002 | cm->current_frame_id = |
| 5003 | ((msb << 8) + lsb) % (1 << seq_params->frame_id_length); |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 5004 | |
| 5005 | // S_frame is meant for stitching different streams of different |
| 5006 | // resolutions together, so current_frame_id must be the |
| 5007 | // same across different streams of the same content current_frame_id |
| 5008 | // should be the same and not random. 0x37 is a chosen number as start |
| 5009 | // point |
| 5010 | if (cpi->oxcf.sframe_enabled) cm->current_frame_id = 0x37; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5011 | } else { |
| 5012 | cm->current_frame_id = |
David Turner | 760a2f4 | 2018-12-07 15:25:36 +0000 | [diff] [blame] | 5013 | (cm->current_frame_id + 1 + (1 << seq_params->frame_id_length)) % |
| 5014 | (1 << seq_params->frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5015 | } |
| 5016 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5017 | |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 5018 | switch (cpi->oxcf.cdf_update_mode) { |
| 5019 | case 0: // No CDF update for any frames(4~6% compression loss). |
| 5020 | cm->disable_cdf_update = 1; |
| 5021 | break; |
| 5022 | case 1: // Enable CDF update for all frames. |
| 5023 | cm->disable_cdf_update = 0; |
| 5024 | break; |
| 5025 | case 2: |
| 5026 | // Strategically determine at which frames to do CDF update. |
| 5027 | // Currently only enable CDF update for all-intra and no-show frames(1.5% |
| 5028 | // compression loss). |
| 5029 | // TODO(huisu@google.com): design schemes for various trade-offs between |
| 5030 | // compression quality and decoding speed. |
Hui Su | b1b76b3 | 2018-02-27 15:24:48 -0800 | [diff] [blame] | 5031 | cm->disable_cdf_update = |
| 5032 | (frame_is_intra_only(cm) || !cm->show_frame) ? 0 : 1; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 5033 | break; |
| 5034 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5035 | cm->timing_info_present &= !seq_params->reduced_still_picture_hdr; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 5036 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5037 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5038 | start_timing(cpi, encode_with_recode_loop_time); |
| 5039 | #endif |
Debargha Mukherjee | 9b70d1f | 2019-05-07 18:34:45 -0700 | [diff] [blame] | 5040 | |
| 5041 | if (cpi->oxcf.pass == 2 && cpi->oxcf.enable_tpl_model == 2 && |
| 5042 | current_frame->frame_type == INTER_FRAME) { |
| 5043 | if (!cm->show_frame) { |
| 5044 | assert(cpi->tpl_model_pass == 0); |
| 5045 | cpi->tpl_model_pass = 1; |
| 5046 | } |
| 5047 | } |
| 5048 | |
David Turner | 2f3b5df | 2019-01-02 14:30:50 +0000 | [diff] [blame] | 5049 | if (encode_with_recode_loop(cpi, size, dest) != AOM_CODEC_OK) |
| 5050 | return AOM_CODEC_ERROR; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5051 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5052 | end_timing(cpi, encode_with_recode_loop_time); |
| 5053 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5054 | |
| 5055 | #ifdef OUTPUT_YUV_SKINMAP |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5056 | if (cpi->common.current_frame.frame_number > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5057 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5058 | } |
| 5059 | #endif // OUTPUT_YUV_SKINMAP |
| 5060 | |
| 5061 | // Special case code to reduce pulsing when key frames are forced at a |
| 5062 | // fixed interval. Note the reconstruction error if it is the frame before |
| 5063 | // the force key frame |
| 5064 | 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] | 5065 | if (seq_params->use_highbitdepth) { |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 5066 | 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] | 5067 | } else { |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 5068 | 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] | 5069 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5070 | } |
| 5071 | |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5072 | cm->cur_frame->buf.color_primaries = seq_params->color_primaries; |
| 5073 | cm->cur_frame->buf.transfer_characteristics = |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5074 | seq_params->transfer_characteristics; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5075 | cm->cur_frame->buf.matrix_coefficients = seq_params->matrix_coefficients; |
| 5076 | cm->cur_frame->buf.monochrome = seq_params->monochrome; |
| 5077 | cm->cur_frame->buf.chroma_sample_position = |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5078 | seq_params->chroma_sample_position; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5079 | cm->cur_frame->buf.color_range = seq_params->color_range; |
| 5080 | cm->cur_frame->buf.render_width = cm->render_width; |
| 5081 | cm->cur_frame->buf.render_height = cm->render_height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5082 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5083 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 5084 | // off. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5085 | |
| 5086 | // Pick the loop filter level for the frame. |
Cheng Chen | 68dc914 | 2018-05-02 17:46:28 -0700 | [diff] [blame] | 5087 | if (!cm->allow_intrabc) { |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 5088 | loopfilter_frame(cpi, cm); |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5089 | } else { |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5090 | cm->lf.filter_level[0] = 0; |
| 5091 | cm->lf.filter_level[1] = 0; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 5092 | cm->cdef_info.cdef_bits = 0; |
| 5093 | cm->cdef_info.cdef_strengths[0] = 0; |
| 5094 | cm->cdef_info.nb_cdef_strengths = 1; |
| 5095 | cm->cdef_info.cdef_uv_strengths[0] = 0; |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5096 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 5097 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 5098 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
Hui Su | 06463e4 | 2018-02-23 22:17:36 -0800 | [diff] [blame] | 5099 | } |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 5100 | |
| 5101 | // TODO(debargha): Fix mv search range on encoder side |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5102 | // aom_extend_frame_inner_borders(&cm->cur_frame->buf, av1_num_planes(cm)); |
| 5103 | aom_extend_frame_borders(&cm->cur_frame->buf, av1_num_planes(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5104 | |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 5105 | #ifdef OUTPUT_YUV_REC |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5106 | aom_write_one_yuv_frame(cm, &cm->cur_frame->buf); |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 5107 | #endif |
| 5108 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 5109 | finalize_encoded_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5110 | // Build the bitstream |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 5111 | int largest_tile_id = 0; // Output from pack_bitstream |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5112 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5113 | start_timing(cpi, av1_pack_bitstream_final_time); |
| 5114 | #endif |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 5115 | 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] | 5116 | return AOM_CODEC_ERROR; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5117 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5118 | end_timing(cpi, av1_pack_bitstream_final_time); |
| 5119 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5120 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 5121 | cpi->seq_params_locked = 1; |
| 5122 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 5123 | // Update reference frame ids for reference frames this frame will overwrite |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5124 | if (seq_params->frame_id_numbers_present_flag) { |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 5125 | for (int i = 0; i < REF_FRAMES; i++) { |
| 5126 | if ((current_frame->refresh_frame_flags >> i) & 1) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5127 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 5128 | } |
| 5129 | } |
| 5130 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5131 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5132 | #if DUMP_RECON_FRAMES == 1 |
| 5133 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5134 | dump_filtered_recon_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5135 | #endif // DUMP_RECON_FRAMES |
| 5136 | |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 5137 | if (cm->seg.enabled) { |
| 5138 | if (cm->seg.update_map) { |
| 5139 | update_reference_segmentation_map(cpi); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 5140 | } else if (cm->last_frame_seg_map) { |
David Turner | b757ce0 | 2018-11-12 15:01:28 +0000 | [diff] [blame] | 5141 | memcpy(cm->cur_frame->seg_map, cm->last_frame_seg_map, |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 5142 | cm->mi_cols * cm->mi_rows * sizeof(uint8_t)); |
| 5143 | } |
| 5144 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5145 | |
| 5146 | if (frame_is_intra_only(cm) == 0) { |
| 5147 | release_scaled_references(cpi); |
| 5148 | } |
| 5149 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 5150 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 5151 | // for the purpose to verify no mismatch between encoder and decoder. |
| 5152 | if (cm->show_frame) cpi->last_show_frame_buf = cm->cur_frame; |
| 5153 | |
| 5154 | refresh_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5155 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5156 | #if CONFIG_ENTROPY_STATS |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 5157 | av1_accumulate_frame_counts(&aggregate_fc, &cpi->counts); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5158 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5159 | |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 5160 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
David Turner | 35cba13 | 2018-12-10 15:48:15 +0000 | [diff] [blame] | 5161 | *cm->fc = cpi->tile_data[largest_tile_id].tctx; |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 5162 | av1_reset_cdf_symbol_counters(cm->fc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5163 | } |
David Turner | a4c9625 | 2019-01-11 16:36:39 +0000 | [diff] [blame] | 5164 | if (!cm->large_scale_tile) { |
| 5165 | cm->cur_frame->frame_context = *cm->fc; |
| 5166 | } |
| 5167 | #define EXT_TILE_DEBUG 0 |
| 5168 | #if EXT_TILE_DEBUG |
| 5169 | if (cm->large_scale_tile && oxcf->pass == 2) { |
| 5170 | char fn[20] = "./fc"; |
| 5171 | fn[4] = current_frame->frame_number / 100 + '0'; |
| 5172 | fn[5] = (current_frame->frame_number % 100) / 10 + '0'; |
| 5173 | fn[6] = (current_frame->frame_number % 10) + '0'; |
| 5174 | fn[7] = '\0'; |
| 5175 | av1_print_frame_contexts(cm->fc, fn); |
| 5176 | } |
| 5177 | #endif // EXT_TILE_DEBUG |
| 5178 | #undef EXT_TILE_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5179 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5180 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 5181 | end_timing(cpi, encode_frame_to_data_rate_time); |
| 5182 | |
| 5183 | // Print out timing information. |
| 5184 | int i; |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 5185 | 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] | 5186 | cm->current_frame.frame_number, |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 5187 | get_frame_type_enum(cm->current_frame.frame_type), cm->show_frame); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5188 | for (i = 0; i < kTimingComponents; i++) { |
| 5189 | cpi->component_time[i] += cpi->frame_component_time[i]; |
| 5190 | fprintf(stderr, " %s: %" PRId64 " us (total: %" PRId64 " us)\n", |
| 5191 | get_component_name(i), cpi->frame_component_time[i], |
| 5192 | cpi->component_time[i]); |
| 5193 | cpi->frame_component_time[i] = 0; |
| 5194 | } |
| 5195 | #endif |
| 5196 | |
Sachin Kumar Garg | fd39b23 | 2019-01-03 17:41:09 +0530 | [diff] [blame] | 5197 | cm->last_frame_type = current_frame->frame_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5198 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5199 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5200 | |
David Turner | efed637 | 2019-01-11 15:14:11 +0000 | [diff] [blame] | 5201 | // Store encoded frame's hash table for is_integer_mv() next time |
| 5202 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
| 5203 | cpi->previous_hash_table = &cm->cur_frame->hash_table; |
| 5204 | } |
| 5205 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5206 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 5207 | // filter deltas. |
| 5208 | cm->seg.update_map = 0; |
| 5209 | cm->seg.update_data = 0; |
| 5210 | cm->lf.mode_ref_delta_update = 0; |
| 5211 | |
Wei-Ting Lin | fb7dc06 | 2018-06-28 18:26:13 -0700 | [diff] [blame] | 5212 | // A droppable frame might not be shown but it always |
| 5213 | // takes a space in the gf group. Therefore, even when |
| 5214 | // it is not shown, we still need update the count down. |
| 5215 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5216 | if (cm->show_frame) { |
Urvang Joshi | f1fa686 | 2018-01-08 16:39:33 -0800 | [diff] [blame] | 5217 | // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that |
| 5218 | // are |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5219 | // being used as reference. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5220 | swap_mi_and_prev_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5221 | // Don't increment frame counters if this was an altref buffer |
| 5222 | // update not a real frame |
Wei-Ting Lin | 96ee0eb | 2018-06-22 15:27:22 -0700 | [diff] [blame] | 5223 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5224 | ++current_frame->frame_number; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5225 | } |
| 5226 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5227 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5228 | } |
| 5229 | |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 5230 | int av1_encode(AV1_COMP *const cpi, uint8_t *const dest, |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 5231 | const EncodeFrameInput *const frame_input, |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 5232 | const EncodeFrameParams *const frame_params, |
| 5233 | EncodeFrameResults *const frame_results) { |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 5234 | AV1_COMMON *const cm = &cpi->common; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 5235 | CurrentFrame *const current_frame = &cm->current_frame; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 5236 | |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 5237 | cpi->unscaled_source = frame_input->source; |
| 5238 | cpi->source = frame_input->source; |
| 5239 | cpi->unscaled_last_source = frame_input->last_source; |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 5240 | |
David Turner | 6e8b4d9 | 2019-02-18 15:01:33 +0000 | [diff] [blame] | 5241 | current_frame->refresh_frame_flags = frame_params->refresh_frame_flags; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 5242 | cm->error_resilient_mode = frame_params->error_resilient_mode; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 5243 | cm->primary_ref_frame = frame_params->primary_ref_frame; |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 5244 | cm->current_frame.frame_type = frame_params->frame_type; |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 5245 | cm->show_frame = frame_params->show_frame; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 5246 | cpi->ref_frame_flags = frame_params->ref_frame_flags; |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 5247 | cpi->speed = frame_params->speed; |
David Turner | e86ee0d | 2019-02-18 17:16:28 +0000 | [diff] [blame] | 5248 | cm->show_existing_frame = frame_params->show_existing_frame; |
| 5249 | 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] | 5250 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 5251 | memcpy(cm->remapped_ref_idx, frame_params->remapped_ref_idx, |
| 5252 | REF_FRAMES * sizeof(*cm->remapped_ref_idx)); |
| 5253 | |
David Turner | fe3aecb | 2019-02-06 14:42:42 +0000 | [diff] [blame] | 5254 | cpi->refresh_last_frame = frame_params->refresh_last_frame; |
| 5255 | cpi->refresh_golden_frame = frame_params->refresh_golden_frame; |
| 5256 | cpi->refresh_bwd_ref_frame = frame_params->refresh_bwd_ref_frame; |
| 5257 | cpi->refresh_alt2_ref_frame = frame_params->refresh_alt2_ref_frame; |
| 5258 | cpi->refresh_alt_ref_frame = frame_params->refresh_alt_ref_frame; |
| 5259 | |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 5260 | if (current_frame->frame_type == KEY_FRAME && cm->show_frame) |
| 5261 | current_frame->frame_number = 0; |
| 5262 | |
| 5263 | if (cm->show_existing_frame) { |
| 5264 | current_frame->order_hint = cm->cur_frame->order_hint; |
| 5265 | } else { |
| 5266 | current_frame->order_hint = |
| 5267 | current_frame->frame_number + frame_params->order_offset; |
| 5268 | current_frame->order_hint %= |
| 5269 | (1 << (cm->seq_params.order_hint_info.order_hint_bits_minus_1 + 1)); |
| 5270 | } |
| 5271 | |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 5272 | if (cpi->oxcf.pass == 1) { |
Jerome Jiang | 2612b4d | 2019-05-29 17:46:47 -0700 | [diff] [blame^] | 5273 | #if !CONFIG_REALTIME_ONLY |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 5274 | av1_first_pass(cpi, frame_input->ts_duration); |
Jerome Jiang | 2612b4d | 2019-05-29 17:46:47 -0700 | [diff] [blame^] | 5275 | #endif |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 5276 | } else if (cpi->oxcf.pass == 0 || cpi->oxcf.pass == 2) { |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 5277 | if (encode_frame_to_data_rate(cpi, &frame_results->size, dest) != |
| 5278 | AOM_CODEC_OK) { |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 5279 | return AOM_CODEC_ERROR; |
| 5280 | } |
| 5281 | } else { |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 5282 | return AOM_CODEC_ERROR; |
| 5283 | } |
| 5284 | |
| 5285 | return AOM_CODEC_OK; |
| 5286 | } |
| 5287 | |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 5288 | #if CONFIG_DENOISE |
| 5289 | static int apply_denoise_2d(AV1_COMP *cpi, YV12_BUFFER_CONFIG *sd, |
| 5290 | int block_size, float noise_level, |
| 5291 | int64_t time_stamp, int64_t end_time) { |
| 5292 | AV1_COMMON *const cm = &cpi->common; |
| 5293 | if (!cpi->denoise_and_model) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5294 | cpi->denoise_and_model = aom_denoise_and_model_alloc( |
| 5295 | cm->seq_params.bit_depth, block_size, noise_level); |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 5296 | if (!cpi->denoise_and_model) { |
| 5297 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 5298 | "Error allocating denoise and model"); |
| 5299 | return -1; |
| 5300 | } |
| 5301 | } |
| 5302 | if (!cpi->film_grain_table) { |
| 5303 | cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table)); |
| 5304 | if (!cpi->film_grain_table) { |
| 5305 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 5306 | "Error allocating grain table"); |
| 5307 | return -1; |
| 5308 | } |
| 5309 | memset(cpi->film_grain_table, 0, sizeof(*cpi->film_grain_table)); |
| 5310 | } |
| 5311 | if (aom_denoise_and_model_run(cpi->denoise_and_model, sd, |
| 5312 | &cm->film_grain_params)) { |
| 5313 | if (cm->film_grain_params.apply_grain) { |
| 5314 | aom_film_grain_table_append(cpi->film_grain_table, time_stamp, end_time, |
| 5315 | &cm->film_grain_params); |
| 5316 | } |
| 5317 | } |
| 5318 | return 0; |
| 5319 | } |
| 5320 | #endif |
| 5321 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 5322 | 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] | 5323 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 5324 | int64_t end_time) { |
| 5325 | AV1_COMMON *const cm = &cpi->common; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5326 | const SequenceHeader *const seq_params = &cm->seq_params; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5327 | int res = 0; |
| 5328 | const int subsampling_x = sd->subsampling_x; |
| 5329 | const int subsampling_y = sd->subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5330 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5331 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5332 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5333 | |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5334 | #if CONFIG_INTERNAL_STATS |
| 5335 | struct aom_usec_timer timer; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5336 | aom_usec_timer_start(&timer); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5337 | #endif |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 5338 | #if CONFIG_DENOISE |
| 5339 | if (cpi->oxcf.noise_level > 0) |
| 5340 | if (apply_denoise_2d(cpi, sd, cpi->oxcf.noise_block_size, |
| 5341 | cpi->oxcf.noise_level, time_stamp, end_time) < 0) |
| 5342 | res = -1; |
| 5343 | #endif // CONFIG_DENOISE |
| 5344 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5345 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5346 | use_highbitdepth, frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5347 | res = -1; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5348 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5349 | aom_usec_timer_mark(&timer); |
| 5350 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5351 | #endif |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5352 | if ((seq_params->profile == PROFILE_0) && !seq_params->monochrome && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5353 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5354 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5355 | "Non-4:2:0 color format requires profile 1 or 2"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5356 | res = -1; |
| 5357 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5358 | if ((seq_params->profile == PROFILE_1) && |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5359 | !(subsampling_x == 0 && subsampling_y == 0)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5360 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5361 | "Profile 1 requires 4:4:4 color format"); |
| 5362 | res = -1; |
| 5363 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5364 | if ((seq_params->profile == PROFILE_2) && |
| 5365 | (seq_params->bit_depth <= AOM_BITS_10) && |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 5366 | !(subsampling_x == 1 && subsampling_y == 0)) { |
| 5367 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
| 5368 | "Profile 2 bit-depth < 10 requires 4:2:2 color format"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5369 | res = -1; |
| 5370 | } |
| 5371 | |
| 5372 | return res; |
| 5373 | } |
| 5374 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5375 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5376 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 5377 | const unsigned char *img2, int img2_pitch, |
| 5378 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5379 | |
| 5380 | static void adjust_image_stat(double y, double u, double v, double all, |
| 5381 | ImageStat *s) { |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 5382 | s->stat[STAT_Y] += y; |
| 5383 | s->stat[STAT_U] += u; |
| 5384 | s->stat[STAT_V] += v; |
| 5385 | s->stat[STAT_ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5386 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5387 | } |
| 5388 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5389 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5390 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5391 | double samples = 0.0; |
| 5392 | uint32_t in_bit_depth = 8; |
| 5393 | uint32_t bit_depth = 8; |
| 5394 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5395 | #if CONFIG_INTER_STATS_ONLY |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5396 | if (cm->current_frame.frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5397 | #endif |
| 5398 | cpi->bytes += frame_bytes; |
| 5399 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5400 | if (cm->seq_params.use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5401 | in_bit_depth = cpi->oxcf.input_bit_depth; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5402 | bit_depth = cm->seq_params.bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5403 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5404 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5405 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5406 | const YV12_BUFFER_CONFIG *recon = &cpi->common.cur_frame->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5407 | double y, u, v, frame_all; |
| 5408 | |
| 5409 | cpi->count++; |
| 5410 | if (cpi->b_calculate_psnr) { |
| 5411 | PSNR_STATS psnr; |
| 5412 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5413 | aom_clear_system_state(); |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5414 | // TODO(yaowu): unify these two versions into one. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5415 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5416 | |
| 5417 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 5418 | &cpi->psnr); |
| 5419 | cpi->total_sq_error += psnr.sse[0]; |
| 5420 | cpi->total_samples += psnr.samples[0]; |
| 5421 | samples = psnr.samples[0]; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5422 | // TODO(yaowu): unify these two versions into one. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5423 | if (cm->seq_params.use_highbitdepth) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5424 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5425 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5426 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5427 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5428 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5429 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5430 | cpi->summed_quality += frame_ssim2 * weight; |
| 5431 | cpi->summed_weights += weight; |
| 5432 | |
| 5433 | #if 0 |
| 5434 | { |
| 5435 | FILE *f = fopen("q_used.stt", "a"); |
Zoe Liu | ee202be | 2017-11-17 12:14:33 -0800 | [diff] [blame] | 5436 | double y2 = psnr.psnr[1]; |
| 5437 | double u2 = psnr.psnr[2]; |
| 5438 | double v2 = psnr.psnr[3]; |
| 5439 | double frame_psnr2 = psnr.psnr[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5440 | 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] | 5441 | cm->current_frame.frame_number, y2, u2, v2, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5442 | frame_psnr2, frame_ssim2); |
| 5443 | fclose(f); |
| 5444 | } |
| 5445 | #endif |
| 5446 | } |
| 5447 | if (cpi->b_calculate_blockiness) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5448 | if (!cm->seq_params.use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5449 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5450 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 5451 | recon->y_stride, orig->y_width, orig->y_height); |
| 5452 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5453 | cpi->total_blockiness += frame_blockiness; |
| 5454 | } |
| 5455 | |
| 5456 | if (cpi->b_calculate_consistency) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5457 | if (!cm->seq_params.use_highbitdepth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5458 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5459 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 5460 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 5461 | |
| 5462 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 5463 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5464 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5465 | if (consistency > 0.0) |
| 5466 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5467 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5468 | cpi->total_inconsistency += this_inconsistency; |
| 5469 | } |
| 5470 | } |
| 5471 | } |
| 5472 | |
| 5473 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5474 | 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] | 5475 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5476 | 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] | 5477 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 5478 | } |
| 5479 | } |
| 5480 | #endif // CONFIG_INTERNAL_STATS |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 5481 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 5482 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 5483 | int64_t *time_end, int flush, |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 5484 | const aom_rational64_t *timestamp_ratio) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5485 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 5486 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5487 | |
| 5488 | #if CONFIG_BITSTREAM_DEBUG |
| 5489 | assert(cpi->oxcf.max_threads == 0 && |
| 5490 | "bitstream debug tool does not support multithreading"); |
| 5491 | bitstream_queue_record_write(); |
Yaowu Xu | 63f2ea3 | 2019-04-29 10:47:42 -0700 | [diff] [blame] | 5492 | aom_bitstream_queue_set_frame_write(cm->current_frame.frame_number * 2 + |
| 5493 | cm->show_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5494 | #endif |
| 5495 | |
Sarah Parker | 740e839 | 2019-01-23 15:47:53 -0800 | [diff] [blame] | 5496 | // Indicates whether or not to use an adaptive quantize b rather than |
| 5497 | // the traditional version |
| 5498 | cm->use_quant_b_adapt = cpi->oxcf.quant_b_adapt; |
| 5499 | |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 5500 | cm->showable_frame = 0; |
David Turner | e43f7fe | 2019-01-15 14:58:00 +0000 | [diff] [blame] | 5501 | *size = 0; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5502 | #if CONFIG_INTERNAL_STATS |
| 5503 | struct aom_usec_timer cmptimer; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5504 | aom_usec_timer_start(&cmptimer); |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5505 | #endif |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 5506 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5507 | |
Debargha Mukherjee | ba7b8fe | 2018-03-15 23:10:07 -0700 | [diff] [blame] | 5508 | // Normal defaults |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5509 | cm->refresh_frame_context = oxcf->frame_parallel_decoding_mode |
| 5510 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 5511 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 5512 | if (oxcf->large_scale_tile) |
James Zern | f34dfc8 | 2018-02-23 16:53:33 -0800 | [diff] [blame] | 5513 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5514 | |
Sarah Parker | b904161 | 2018-05-22 19:06:47 -0700 | [diff] [blame] | 5515 | // Initialize fields related to forward keyframes |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 5516 | cpi->no_show_kf = 0; |
Zoe Liu | b499120 | 2017-12-21 15:31:06 -0800 | [diff] [blame] | 5517 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 5518 | if (assign_cur_frame_new_fb(cm) == NULL) return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5519 | |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 5520 | const int result = |
| 5521 | av1_encode_strategy(cpi, size, dest, frame_flags, time_stamp, time_end, |
| 5522 | timestamp_ratio, flush); |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 5523 | if (result != AOM_CODEC_OK && result != -1) { |
David Turner | 1539bb0 | 2019-01-24 15:28:13 +0000 | [diff] [blame] | 5524 | return AOM_CODEC_ERROR; |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 5525 | } else if (result == -1) { |
| 5526 | // Returning -1 indicates no frame encoded; more input is required |
| 5527 | return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5528 | } |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 5529 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5530 | aom_usec_timer_mark(&cmptimer); |
| 5531 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 5532 | #endif // CONFIG_INTERNAL_STATS |
David Turner | c4bf8c7 | 2019-01-15 13:14:37 +0000 | [diff] [blame] | 5533 | if (cpi->b_calculate_psnr) { |
| 5534 | if (cm->show_existing_frame || (oxcf->pass != 1 && cm->show_frame)) { |
| 5535 | generate_psnr_packet(cpi); |
| 5536 | } |
| 5537 | } |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 5538 | |
| 5539 | if (cpi->keep_level_stats && oxcf->pass != 1) { |
| 5540 | // Initialize level info. at the beginning of each sequence. |
| 5541 | if (cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) { |
| 5542 | av1_init_level_info(cpi->level_info); |
| 5543 | } |
kyslov | abeeb7c | 2019-03-06 18:35:04 -0800 | [diff] [blame] | 5544 | av1_update_level_info(cpi, *size, *time_stamp, *time_end); |
Hui Su | 8ea8732 | 2019-03-29 14:44:32 -0700 | [diff] [blame] | 5545 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5546 | |
| 5547 | #if CONFIG_INTERNAL_STATS |
| 5548 | if (oxcf->pass != 1) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5549 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5550 | } |
| 5551 | #endif // CONFIG_INTERNAL_STATS |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 5552 | #if CONFIG_SPEED_STATS |
David Turner | c4bf8c7 | 2019-01-15 13:14:37 +0000 | [diff] [blame] | 5553 | if (cpi->oxcf.pass != 1 && !cm->show_existing_frame) { |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 5554 | cpi->tx_search_count += cpi->td.mb.tx_search_count; |
| 5555 | cpi->td.mb.tx_search_count = 0; |
| 5556 | } |
| 5557 | #endif // CONFIG_SPEED_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5558 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5559 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5560 | |
| 5561 | return 0; |
| 5562 | } |
| 5563 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5564 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 5565 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5566 | if (!cm->show_frame) { |
| 5567 | return -1; |
| 5568 | } else { |
| 5569 | int ret; |
David Turner | c29e1a9 | 2018-12-06 14:10:14 +0000 | [diff] [blame] | 5570 | if (cm->cur_frame != NULL) { |
| 5571 | *dest = cm->cur_frame->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5572 | dest->y_width = cm->width; |
| 5573 | dest->y_height = cm->height; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5574 | dest->uv_width = cm->width >> cm->seq_params.subsampling_x; |
| 5575 | dest->uv_height = cm->height >> cm->seq_params.subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5576 | ret = 0; |
| 5577 | } else { |
| 5578 | ret = -1; |
| 5579 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5580 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5581 | return ret; |
| 5582 | } |
| 5583 | } |
| 5584 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5585 | 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] | 5586 | if (cpi->last_show_frame_buf == NULL) return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5587 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 5588 | *frame = cpi->last_show_frame_buf->buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5589 | return 0; |
| 5590 | } |
| 5591 | |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 5592 | static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a, |
| 5593 | const YV12_BUFFER_CONFIG *b) { |
| 5594 | return a->y_height == b->y_height && a->y_width == b->y_width && |
| 5595 | a->uv_height == b->uv_height && a->uv_width == b->uv_width && |
| 5596 | a->y_stride == b->y_stride && a->uv_stride == b->uv_stride && |
| 5597 | a->border == b->border && |
| 5598 | (a->flags & YV12_FLAG_HIGHBITDEPTH) == |
| 5599 | (b->flags & YV12_FLAG_HIGHBITDEPTH); |
| 5600 | } |
| 5601 | |
Yunqing Wang | 93b18f3 | 2018-06-08 21:08:29 -0700 | [diff] [blame] | 5602 | aom_codec_err_t av1_copy_new_frame_enc(AV1_COMMON *cm, |
| 5603 | YV12_BUFFER_CONFIG *new_frame, |
| 5604 | YV12_BUFFER_CONFIG *sd) { |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 5605 | const int num_planes = av1_num_planes(cm); |
| 5606 | if (!equal_dimensions_and_border(new_frame, sd)) |
| 5607 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, |
| 5608 | "Incorrect buffer dimensions"); |
| 5609 | else |
| 5610 | aom_yv12_copy_frame(new_frame, sd, num_planes); |
| 5611 | |
| 5612 | return cm->error.error_code; |
| 5613 | } |
| 5614 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5615 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 5616 | AOM_SCALING vert_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5617 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 5618 | |
| 5619 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 5620 | |
| 5621 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 5622 | Scale2Ratio(vert_mode, &vr, &vs); |
| 5623 | |
| 5624 | // always go to the next whole number |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5625 | cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 5626 | cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5627 | |
| 5628 | return 0; |
| 5629 | } |
| 5630 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5631 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5632 | |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 5633 | int av1_convert_sect5obus_to_annexb(uint8_t *buffer, size_t *frame_size) { |
| 5634 | size_t output_size = 0; |
| 5635 | size_t total_bytes_read = 0; |
| 5636 | size_t remaining_size = *frame_size; |
| 5637 | uint8_t *buff_ptr = buffer; |
| 5638 | |
| 5639 | // go through each OBUs |
| 5640 | while (total_bytes_read < *frame_size) { |
| 5641 | uint8_t saved_obu_header[2]; |
| 5642 | uint64_t obu_payload_size; |
| 5643 | size_t length_of_payload_size; |
| 5644 | size_t length_of_obu_size; |
| 5645 | uint32_t obu_header_size = (buff_ptr[0] >> 2) & 0x1 ? 2 : 1; |
| 5646 | size_t obu_bytes_read = obu_header_size; // bytes read for current obu |
| 5647 | |
| 5648 | // save the obu header (1 or 2 bytes) |
| 5649 | memmove(saved_obu_header, buff_ptr, obu_header_size); |
| 5650 | // clear the obu_has_size_field |
| 5651 | saved_obu_header[0] = saved_obu_header[0] & (~0x2); |
| 5652 | |
| 5653 | // get the payload_size and length of payload_size |
| 5654 | if (aom_uleb_decode(buff_ptr + obu_header_size, remaining_size, |
| 5655 | &obu_payload_size, &length_of_payload_size) != 0) { |
| 5656 | return AOM_CODEC_ERROR; |
| 5657 | } |
| 5658 | obu_bytes_read += length_of_payload_size; |
| 5659 | |
| 5660 | // calculate the length of size of the obu header plus payload |
| 5661 | length_of_obu_size = |
| 5662 | aom_uleb_size_in_bytes((uint64_t)(obu_header_size + obu_payload_size)); |
| 5663 | |
| 5664 | // move the rest of data to new location |
| 5665 | memmove(buff_ptr + length_of_obu_size + obu_header_size, |
| 5666 | buff_ptr + obu_bytes_read, remaining_size - obu_bytes_read); |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 5667 | obu_bytes_read += (size_t)obu_payload_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 5668 | |
| 5669 | // write the new obu size |
| 5670 | const uint64_t obu_size = obu_header_size + obu_payload_size; |
| 5671 | size_t coded_obu_size; |
| 5672 | if (aom_uleb_encode(obu_size, sizeof(obu_size), buff_ptr, |
| 5673 | &coded_obu_size) != 0) { |
| 5674 | return AOM_CODEC_ERROR; |
| 5675 | } |
| 5676 | |
| 5677 | // write the saved (modified) obu_header following obu size |
| 5678 | memmove(buff_ptr + length_of_obu_size, saved_obu_header, obu_header_size); |
| 5679 | |
| 5680 | total_bytes_read += obu_bytes_read; |
| 5681 | remaining_size -= obu_bytes_read; |
| 5682 | buff_ptr += length_of_obu_size + obu_size; |
Yaowu Xu | 9e49420 | 2018-04-03 11:19:49 -0700 | [diff] [blame] | 5683 | output_size += length_of_obu_size + (size_t)obu_size; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | *frame_size = output_size; |
| 5687 | return AOM_CODEC_OK; |
| 5688 | } |
| 5689 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5690 | 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] | 5691 | // TODO(yunqingwang): For what references to use, external encoding flags |
| 5692 | // should be consistent with internal reference frame selection. Need to |
| 5693 | // ensure that there is not conflict between the two. In AV1 encoder, the |
| 5694 | // priority rank for 7 reference frames are: LAST, ALTREF, LAST2, LAST3, |
| 5695 | // GOLDEN, BWDREF, ALTREF2. If only one reference frame is used, it must be |
| 5696 | // LAST. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 5697 | cpi->ext_ref_frame_flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5698 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5699 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | |
| 5700 | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD | |
| 5701 | AOM_EFLAG_NO_REF_ARF2)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5702 | if (flags & AOM_EFLAG_NO_REF_LAST) { |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 5703 | cpi->ext_ref_frame_flags = 0; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5704 | } else { |
| 5705 | int ref = AOM_REFFRAME_ALL; |
| 5706 | |
| 5707 | if (flags & AOM_EFLAG_NO_REF_LAST2) ref ^= AOM_LAST2_FLAG; |
| 5708 | if (flags & AOM_EFLAG_NO_REF_LAST3) ref ^= AOM_LAST3_FLAG; |
| 5709 | |
| 5710 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
| 5711 | |
| 5712 | if (flags & AOM_EFLAG_NO_REF_ARF) { |
| 5713 | ref ^= AOM_ALT_FLAG; |
| 5714 | ref ^= AOM_BWD_FLAG; |
| 5715 | ref ^= AOM_ALT2_FLAG; |
| 5716 | } else { |
| 5717 | if (flags & AOM_EFLAG_NO_REF_BWD) ref ^= AOM_BWD_FLAG; |
| 5718 | if (flags & AOM_EFLAG_NO_REF_ARF2) ref ^= AOM_ALT2_FLAG; |
| 5719 | } |
| 5720 | |
| 5721 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5722 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5723 | } |
| 5724 | |
| 5725 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5726 | (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] | 5727 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5728 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5729 | // Refreshing LAST/LAST2/LAST3 is handled by 1 common flag. |
| 5730 | if (flags & AOM_EFLAG_NO_UPD_LAST) upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5731 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5732 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5733 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5734 | if (flags & AOM_EFLAG_NO_UPD_ARF) { |
| 5735 | upd ^= AOM_ALT_FLAG; |
| 5736 | upd ^= AOM_BWD_FLAG; |
| 5737 | upd ^= AOM_ALT2_FLAG; |
| 5738 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5739 | |
David Turner | ce9b590 | 2019-01-23 17:25:47 +0000 | [diff] [blame] | 5740 | cpi->ext_refresh_last_frame = (upd & AOM_LAST_FLAG) != 0; |
| 5741 | cpi->ext_refresh_golden_frame = (upd & AOM_GOLD_FLAG) != 0; |
| 5742 | cpi->ext_refresh_alt_ref_frame = (upd & AOM_ALT_FLAG) != 0; |
| 5743 | cpi->ext_refresh_bwd_ref_frame = (upd & AOM_BWD_FLAG) != 0; |
| 5744 | cpi->ext_refresh_alt2_ref_frame = (upd & AOM_ALT2_FLAG) != 0; |
| 5745 | cpi->ext_refresh_frame_flags_pending = 1; |
David Turner | 4f1f181 | 2019-01-24 17:00:24 +0000 | [diff] [blame] | 5746 | } else { |
| 5747 | cpi->ext_refresh_frame_flags_pending = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5748 | } |
| 5749 | |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5750 | cpi->ext_use_ref_frame_mvs = cpi->oxcf.allow_ref_frame_mvs & |
| 5751 | ((flags & AOM_EFLAG_NO_REF_FRAME_MVS) == 0); |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5752 | cpi->ext_use_error_resilient = cpi->oxcf.error_resilient_mode | |
| 5753 | ((flags & AOM_EFLAG_ERROR_RESILIENT) != 0); |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 5754 | cpi->ext_use_s_frame = |
| 5755 | cpi->oxcf.s_frame_mode | ((flags & AOM_EFLAG_SET_S_FRAME) != 0); |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 5756 | 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] | 5757 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5758 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 5759 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5760 | } |
| 5761 | } |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 5762 | |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 5763 | aom_fixed_buf_t *av1_get_global_headers(AV1_COMP *cpi) { |
| 5764 | if (!cpi) return NULL; |
| 5765 | |
| 5766 | uint8_t header_buf[512] = { 0 }; |
| 5767 | const uint32_t sequence_header_size = |
Yaowu Xu | 797674b | 2019-05-01 17:38:11 -0700 | [diff] [blame] | 5768 | av1_write_sequence_header_obu(cpi, &header_buf[0]); |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 5769 | assert(sequence_header_size <= sizeof(header_buf)); |
| 5770 | if (sequence_header_size == 0) return NULL; |
| 5771 | |
| 5772 | const size_t obu_header_size = 1; |
| 5773 | const size_t size_field_size = aom_uleb_size_in_bytes(sequence_header_size); |
| 5774 | const size_t payload_offset = obu_header_size + size_field_size; |
| 5775 | |
| 5776 | if (payload_offset + sequence_header_size > sizeof(header_buf)) return NULL; |
| 5777 | memmove(&header_buf[payload_offset], &header_buf[0], sequence_header_size); |
| 5778 | |
Hui Su | 4fd1176 | 2019-03-26 16:05:07 -0700 | [diff] [blame] | 5779 | 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] | 5780 | obu_header_size) { |
| 5781 | return NULL; |
| 5782 | } |
| 5783 | |
| 5784 | size_t coded_size_field_size = 0; |
| 5785 | if (aom_uleb_encode(sequence_header_size, size_field_size, |
| 5786 | &header_buf[obu_header_size], |
| 5787 | &coded_size_field_size) != 0) { |
| 5788 | return NULL; |
| 5789 | } |
| 5790 | assert(coded_size_field_size == size_field_size); |
| 5791 | |
| 5792 | aom_fixed_buf_t *global_headers = |
| 5793 | (aom_fixed_buf_t *)malloc(sizeof(*global_headers)); |
| 5794 | if (!global_headers) return NULL; |
| 5795 | |
| 5796 | const size_t global_header_buf_size = |
| 5797 | obu_header_size + size_field_size + sequence_header_size; |
| 5798 | |
| 5799 | global_headers->buf = malloc(global_header_buf_size); |
| 5800 | if (!global_headers->buf) { |
| 5801 | free(global_headers); |
| 5802 | return NULL; |
| 5803 | } |
| 5804 | |
| 5805 | memcpy(global_headers->buf, &header_buf[0], global_header_buf_size); |
| 5806 | global_headers->sz = global_header_buf_size; |
| 5807 | return global_headers; |
| 5808 | } |