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 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | #include "./aom_config.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | |
| 18 | #include "av1/common/alloccommon.h" |
Steinar Midtskogen | a9d41e8 | 2017-03-17 12:48:15 +0100 | [diff] [blame] | 19 | #include "av1/common/cdef.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | #include "av1/common/filter.h" |
| 21 | #include "av1/common/idct.h" |
| 22 | #include "av1/common/reconinter.h" |
| 23 | #include "av1/common/reconintra.h" |
Fergus Simpson | d056500 | 2017-03-27 16:51:52 -0700 | [diff] [blame] | 24 | #include "av1/common/resize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | #include "av1/common/tile_common.h" |
| 26 | |
| 27 | #include "av1/encoder/aq_complexity.h" |
| 28 | #include "av1/encoder/aq_cyclicrefresh.h" |
| 29 | #include "av1/encoder/aq_variance.h" |
| 30 | #include "av1/encoder/bitstream.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 31 | #include "av1/encoder/context_tree.h" |
| 32 | #include "av1/encoder/encodeframe.h" |
| 33 | #include "av1/encoder/encodemv.h" |
| 34 | #include "av1/encoder/encoder.h" |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 35 | #include "av1/encoder/encodetxb.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 36 | #include "av1/encoder/ethread.h" |
| 37 | #include "av1/encoder/firstpass.h" |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 38 | #if CONFIG_HASH_ME |
| 39 | #include "av1/encoder/hash_motion.h" |
| 40 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 41 | #include "av1/encoder/mbgraph.h" |
| 42 | #include "av1/encoder/picklpf.h" |
| 43 | #if CONFIG_LOOP_RESTORATION |
| 44 | #include "av1/encoder/pickrst.h" |
| 45 | #endif // CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 46 | #include "av1/encoder/random.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 47 | #include "av1/encoder/ratectrl.h" |
| 48 | #include "av1/encoder/rd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 49 | #include "av1/encoder/segmentation.h" |
| 50 | #include "av1/encoder/speed_features.h" |
| 51 | #include "av1/encoder/temporal_filter.h" |
| 52 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 53 | #include "./av1_rtcd.h" |
| 54 | #include "./aom_dsp_rtcd.h" |
| 55 | #include "./aom_scale_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 56 | #include "aom_dsp/psnr.h" |
| 57 | #if CONFIG_INTERNAL_STATS |
| 58 | #include "aom_dsp/ssim.h" |
| 59 | #endif |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 60 | #if CONFIG_FILM_GRAIN |
| 61 | #include "av1/encoder/grain_test_vectors.h" |
| 62 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 63 | #include "aom_dsp/aom_dsp_common.h" |
| 64 | #include "aom_dsp/aom_filter.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 65 | #include "aom_ports/aom_timer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | #include "aom_ports/mem.h" |
| 67 | #include "aom_ports/system_state.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 68 | #include "aom_scale/aom_scale.h" |
Angie Chiang | 5b5f4df | 2017-12-06 10:41:12 -0800 | [diff] [blame] | 69 | #if CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 70 | #include "aom_util/debug_util.h" |
Angie Chiang | 5b5f4df | 2017-12-06 10:41:12 -0800 | [diff] [blame] | 71 | #endif // CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 72 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 73 | #if CONFIG_ENTROPY_STATS |
| 74 | FRAME_COUNTS aggregate_fc; |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 75 | // Aggregate frame counts per frame context type |
| 76 | FRAME_COUNTS aggregate_fc_per_type[FRAME_CONTEXTS]; |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 77 | #endif // CONFIG_ENTROPY_STATS |
| 78 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 79 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 80 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 81 | |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 82 | // Whether to use high precision mv for altref computation. |
| 83 | #define ALTREF_HIGH_PRECISION_MV 1 |
| 84 | |
| 85 | // Q threshold for high precision mv. Choose a very high value for now so that |
| 86 | // HIGH_PRECISION is always chosen. |
| 87 | #define HIGH_PRECISION_MV_QTHRESH 200 |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 88 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 89 | // #define OUTPUT_YUV_REC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 90 | #ifdef OUTPUT_YUV_SKINMAP |
| 91 | FILE *yuv_skinmap_file = NULL; |
| 92 | #endif |
| 93 | #ifdef OUTPUT_YUV_REC |
| 94 | FILE *yuv_rec_file; |
| 95 | #define FILE_NAME_LEN 100 |
| 96 | #endif |
| 97 | |
| 98 | #if 0 |
| 99 | FILE *framepsnr; |
| 100 | FILE *kf_list; |
| 101 | FILE *keyfile; |
| 102 | #endif |
| 103 | |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 104 | #if CONFIG_INTERNAL_STATS |
| 105 | typedef enum { Y, U, V, ALL } STAT_TYPE; |
| 106 | #endif // CONFIG_INTERNAL_STATS |
| 107 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 108 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 109 | switch (mode) { |
| 110 | case NORMAL: |
| 111 | *hr = 1; |
| 112 | *hs = 1; |
| 113 | break; |
| 114 | case FOURFIVE: |
| 115 | *hr = 4; |
| 116 | *hs = 5; |
| 117 | break; |
| 118 | case THREEFIVE: |
| 119 | *hr = 3; |
| 120 | *hs = 5; |
| 121 | break; |
| 122 | case ONETWO: |
| 123 | *hr = 1; |
| 124 | *hs = 2; |
| 125 | break; |
| 126 | default: |
| 127 | *hr = 1; |
| 128 | *hs = 1; |
| 129 | assert(0); |
| 130 | break; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 135 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 136 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 137 | unsigned char *const seg_map = cpi->segmentation_map; |
| 138 | int i; |
| 139 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 140 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 141 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 142 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 143 | } |
| 144 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 145 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 146 | struct segmentation *const seg = &cpi->common.seg; |
| 147 | unsigned char *const seg_map = cpi->segmentation_map; |
| 148 | const unsigned char *const active_map = cpi->active_map.map; |
| 149 | int i; |
| 150 | |
| 151 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 152 | |
| 153 | if (frame_is_intra_only(&cpi->common)) { |
| 154 | cpi->active_map.enabled = 0; |
| 155 | cpi->active_map.update = 1; |
| 156 | } |
| 157 | |
| 158 | if (cpi->active_map.update) { |
| 159 | if (cpi->active_map.enabled) { |
| 160 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 161 | 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] | 162 | av1_enable_segmentation(seg); |
| 163 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 164 | #if CONFIG_LOOPFILTER_LEVEL |
| 165 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 166 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 167 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 168 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 169 | |
| 170 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H, |
| 171 | -MAX_LOOP_FILTER); |
| 172 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V, |
| 173 | -MAX_LOOP_FILTER); |
| 174 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U, |
| 175 | -MAX_LOOP_FILTER); |
| 176 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V, |
| 177 | -MAX_LOOP_FILTER); |
| 178 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 179 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 180 | // Setting the data to -MAX_LOOP_FILTER will result in the computed loop |
Yushin Cho | d728c21 | 2017-11-03 12:30:24 -0700 | [diff] [blame] | 181 | // filter level being zero. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 182 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF, |
| 183 | -MAX_LOOP_FILTER); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 184 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 185 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 186 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 187 | #if CONFIG_LOOPFILTER_LEVEL |
| 188 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 189 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 190 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 191 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 192 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 193 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 194 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 195 | if (seg->enabled) { |
| 196 | seg->update_data = 1; |
| 197 | seg->update_map = 1; |
| 198 | } |
| 199 | } |
| 200 | cpi->active_map.update = 0; |
| 201 | } |
| 202 | } |
| 203 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 204 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 205 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 206 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 207 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 208 | const int mi_rows = cpi->common.mi_rows; |
| 209 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 210 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 211 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 212 | cpi->active_map.update = 1; |
| 213 | if (new_map_16x16) { |
| 214 | int r, c; |
| 215 | for (r = 0; r < mi_rows; ++r) { |
| 216 | for (c = 0; c < mi_cols; ++c) { |
| 217 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 218 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 219 | ? AM_SEGMENT_ID_ACTIVE |
| 220 | : AM_SEGMENT_ID_INACTIVE; |
| 221 | } |
| 222 | } |
| 223 | cpi->active_map.enabled = 1; |
| 224 | } else { |
| 225 | cpi->active_map.enabled = 0; |
| 226 | } |
| 227 | return 0; |
| 228 | } else { |
| 229 | return -1; |
| 230 | } |
| 231 | } |
| 232 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 233 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 234 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 235 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 236 | new_map_16x16) { |
| 237 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 238 | const int mi_rows = cpi->common.mi_rows; |
| 239 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 240 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 241 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 242 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 243 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 244 | if (cpi->active_map.enabled) { |
| 245 | int r, c; |
| 246 | for (r = 0; r < mi_rows; ++r) { |
| 247 | for (c = 0; c < mi_cols; ++c) { |
| 248 | // Cyclic refresh segments are considered active despite not having |
| 249 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 250 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 251 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | return 0; |
| 256 | } else { |
| 257 | return -1; |
| 258 | } |
| 259 | } |
| 260 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 261 | static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv |
| 262 | #if CONFIG_AMVR |
| 263 | , |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 264 | int cur_frame_force_integer_mv |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 265 | #endif |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 266 | ) { |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 267 | MACROBLOCK *const mb = &cpi->td.mb; |
| 268 | cpi->common.allow_high_precision_mv = allow_high_precision_mv; |
| 269 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 270 | #if CONFIG_AMVR |
Rupert Swarbrick | a84faf2 | 2017-12-11 13:56:40 +0000 | [diff] [blame] | 271 | const int copy_hp = |
| 272 | cpi->common.allow_high_precision_mv && cur_frame_force_integer_mv == 0; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 273 | #else |
Rupert Swarbrick | a84faf2 | 2017-12-11 13:56:40 +0000 | [diff] [blame] | 274 | const int copy_hp = cpi->common.allow_high_precision_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 275 | #endif |
Rupert Swarbrick | a84faf2 | 2017-12-11 13:56:40 +0000 | [diff] [blame] | 276 | int *(*src)[2] = copy_hp ? mb->nmvcost_hp : mb->nmvcost; |
| 277 | for (int i = 0; i < NMV_CONTEXTS; ++i) { |
| 278 | mb->mv_cost_stack[i] = src[i]; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 282 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 283 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 284 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 285 | return BLOCK_64X64; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 286 | #if CONFIG_FILEOPTIONS |
| 287 | if (cpi->common.options && cpi->common.options->ext_partition) |
| 288 | #endif |
| 289 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
| 290 | return BLOCK_128X128; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 291 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 292 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 293 | |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 294 | #if !CONFIG_MAX_TILE |
| 295 | // for the max_tile experiment there is no common tile_width, tile_height |
| 296 | // max_tile assumes tile dimensions are in superblocks (not 64x64 units) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 297 | assert(IMPLIES(cpi->common.tile_cols > 1, |
| 298 | cpi->common.tile_width % MAX_MIB_SIZE == 0)); |
| 299 | assert(IMPLIES(cpi->common.tile_rows > 1, |
| 300 | cpi->common.tile_height % MAX_MIB_SIZE == 0)); |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 301 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 302 | |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 303 | // TODO(any): Possibly could improve this with a heuristic. |
| 304 | #if CONFIG_FILEOPTIONS |
| 305 | if (cpi->common.options && !cpi->common.options->ext_partition) |
| 306 | return BLOCK_64X64; |
| 307 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 308 | return BLOCK_128X128; |
| 309 | #else |
| 310 | (void)cpi; |
| 311 | return BLOCK_64X64; |
| 312 | #endif // CONFIG_EXT_PARTITION |
| 313 | } |
| 314 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 315 | static void setup_frame(AV1_COMP *cpi) { |
| 316 | AV1_COMMON *const cm = &cpi->common; |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 317 | // Set up entropy context depending on frame type. The decoder mandates |
| 318 | // the use of the default context, index 0, for keyframes and inter |
| 319 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 320 | // other inter-frames the encoder currently uses only two contexts; |
| 321 | // context 1 for ALTREF frames and context 0 for the others. |
Soo-Chul Han | 85e8c79 | 2018-01-21 01:58:15 -0500 | [diff] [blame] | 322 | |
| 323 | #if CONFIG_SEGMENT_PRED_LAST |
| 324 | if (cm->prev_frame) cm->last_frame_seg_map = cm->prev_frame->seg_map; |
| 325 | cm->current_frame_seg_map = cm->cur_frame->seg_map; |
| 326 | #endif |
| 327 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 328 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 329 | av1_setup_past_independence(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 330 | } else { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 331 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 332 | // Just use frame context from first signaled reference frame. |
| 333 | // This will always be LAST_FRAME for now. |
| 334 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 335 | const GF_GROUP *gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 336 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 337 | cm->frame_context_idx = EXT_ARF_FRAME; |
| 338 | else if (cpi->refresh_alt_ref_frame) |
| 339 | cm->frame_context_idx = ARF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 340 | else if (cpi->rc.is_src_frame_alt_ref) |
| 341 | cm->frame_context_idx = OVERLAY_FRAME; |
| 342 | else if (cpi->refresh_golden_frame) |
| 343 | cm->frame_context_idx = GLD_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 344 | else if (cpi->refresh_bwd_ref_frame) |
| 345 | cm->frame_context_idx = BRF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 346 | else |
| 347 | cm->frame_context_idx = REGULAR_FRAME; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 348 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | if (cm->frame_type == KEY_FRAME) { |
| 352 | cpi->refresh_golden_frame = 1; |
| 353 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 354 | av1_zero(cpi->interp_filter_selected); |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 355 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 356 | #if CONFIG_REFERENCE_BUFFER |
| 357 | set_use_reference_buffer(cm, 0); |
| 358 | #endif // CONFIG_REFERENCE_BUFFER |
David Barker | 11eac7b | 2017-12-07 12:22:36 +0000 | [diff] [blame] | 359 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 360 | cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 361 | #else |
| 362 | cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx]; |
| 363 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 364 | } else { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 365 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
David Barker | 11eac7b | 2017-12-07 12:22:36 +0000 | [diff] [blame] | 366 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 367 | *cm->fc = cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
David Barker | 11eac7b | 2017-12-07 12:22:36 +0000 | [diff] [blame] | 368 | cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 369 | } else { |
David Barker | 11eac7b | 2017-12-07 12:22:36 +0000 | [diff] [blame] | 370 | assert(cm->frame_refs[0].idx >= 0); |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 371 | *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx]; |
David Barker | 11eac7b | 2017-12-07 12:22:36 +0000 | [diff] [blame] | 372 | cm->pre_fc = &cm->frame_contexts[cm->frame_refs[0].idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 373 | } |
| 374 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 375 | *cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
David Barker | 11eac7b | 2017-12-07 12:22:36 +0000 | [diff] [blame] | 376 | cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 377 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 378 | av1_zero(cpi->interp_filter_selected[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 379 | } |
Zoe Liu | c01dddb | 2017-11-07 08:44:06 -0800 | [diff] [blame] | 380 | #if !CONFIG_EXT_COMP_REFS // No change to bitstream |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 381 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 382 | cpi->refresh_bwd_ref_frame = cpi->refresh_last_frame; |
| 383 | cpi->rc.is_bipred_frame = 1; |
| 384 | } |
Zoe Liu | c01dddb | 2017-11-07 08:44:06 -0800 | [diff] [blame] | 385 | #endif // !CONFIG_EXT_COMP_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 386 | |
| 387 | cpi->vaq_refresh = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 390 | static void enc_setup_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 391 | int i; |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 392 | cm->mi = cm->mip; |
| 393 | memset(cm->mip, 0, cm->mi_stride * cm->mi_rows * sizeof(*cm->mip)); |
| 394 | cm->prev_mi = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 395 | // Clear top border row |
| 396 | memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride); |
| 397 | // Clear left border column |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 398 | for (i = 0; i < cm->mi_rows; ++i) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 399 | memset(&cm->prev_mip[i * cm->mi_stride], 0, sizeof(*cm->prev_mip)); |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 400 | cm->mi_grid_visible = cm->mi_grid_base; |
| 401 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 402 | |
| 403 | memset(cm->mi_grid_base, 0, |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 404 | cm->mi_stride * cm->mi_rows * sizeof(*cm->mi_grid_base)); |
Frank Bossen | 4ef06b5 | 2018-01-18 19:51:15 -0500 | [diff] [blame] | 405 | |
| 406 | memset(cm->boundary_info, 0, |
| 407 | cm->boundary_info_alloc_size * sizeof(*cm->boundary_info)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 410 | static int enc_alloc_mi(AV1_COMMON *cm, int mi_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 411 | cm->mip = aom_calloc(mi_size, sizeof(*cm->mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 412 | if (!cm->mip) return 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 413 | cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 414 | if (!cm->prev_mip) return 1; |
| 415 | cm->mi_alloc_size = mi_size; |
| 416 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 417 | cm->mi_grid_base = (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 418 | if (!cm->mi_grid_base) return 1; |
| 419 | cm->prev_mi_grid_base = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 420 | (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 421 | if (!cm->prev_mi_grid_base) return 1; |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 426 | static void enc_free_mi(AV1_COMMON *cm) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 427 | aom_free(cm->mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 428 | cm->mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 429 | aom_free(cm->prev_mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 430 | cm->prev_mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 431 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 432 | cm->mi_grid_base = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 433 | aom_free(cm->prev_mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 434 | cm->prev_mi_grid_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 435 | cm->mi_alloc_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 438 | static void swap_mi_and_prev_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 439 | // Current mip will be the prev_mip for the next frame. |
| 440 | MODE_INFO **temp_base = cm->prev_mi_grid_base; |
| 441 | MODE_INFO *temp = cm->prev_mip; |
| 442 | cm->prev_mip = cm->mip; |
| 443 | cm->mip = temp; |
| 444 | |
| 445 | // Update the upper left visible macroblock ptrs. |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 446 | cm->mi = cm->mip; |
| 447 | cm->prev_mi = cm->prev_mip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 448 | |
| 449 | cm->prev_mi_grid_base = cm->mi_grid_base; |
| 450 | cm->mi_grid_base = temp_base; |
Yunqing Wang | 19b9f72 | 2018-02-20 16:22:01 -0800 | [diff] [blame] | 451 | cm->mi_grid_visible = cm->mi_grid_base; |
| 452 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 455 | void av1_initialize_enc(void) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 456 | static volatile int init_done = 0; |
| 457 | |
| 458 | if (!init_done) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 459 | av1_rtcd(); |
| 460 | aom_dsp_rtcd(); |
| 461 | aom_scale_rtcd(); |
| 462 | av1_init_intra_predictors(); |
| 463 | av1_init_me_luts(); |
| 464 | av1_rc_init_minq_luts(); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 465 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 466 | init_done = 1; |
| 467 | } |
| 468 | } |
| 469 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 470 | static void dealloc_context_buffers_ext(AV1_COMP *cpi) { |
| 471 | if (cpi->mbmi_ext_base) { |
| 472 | aom_free(cpi->mbmi_ext_base); |
| 473 | cpi->mbmi_ext_base = NULL; |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
| 478 | AV1_COMMON *cm = &cpi->common; |
| 479 | int mi_size = cm->mi_cols * cm->mi_rows; |
| 480 | |
| 481 | dealloc_context_buffers_ext(cpi); |
| 482 | CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, |
| 483 | aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); |
| 484 | } |
| 485 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 486 | #if CONFIG_FILM_GRAIN |
| 487 | static void update_film_grain_parameters(struct AV1_COMP *cpi, |
| 488 | const AV1EncoderConfig *oxcf) { |
| 489 | AV1_COMMON *const cm = &cpi->common; |
| 490 | cpi->oxcf = *oxcf; |
| 491 | |
| 492 | if (oxcf->film_grain_test_vector) { |
| 493 | cm->film_grain_params_present = 1; |
| 494 | if (cm->frame_type == KEY_FRAME) { |
| 495 | memcpy(&cm->film_grain_params, |
| 496 | film_grain_test_vectors + oxcf->film_grain_test_vector - 1, |
| 497 | sizeof(cm->film_grain_params)); |
| 498 | |
| 499 | cm->film_grain_params.bit_depth = cm->bit_depth; |
| 500 | if (cm->color_range == AOM_CR_FULL_RANGE) { |
| 501 | cm->film_grain_params.clip_to_restricted_range = 0; |
| 502 | } |
| 503 | } |
| 504 | } else { |
| 505 | cm->film_grain_params_present = 0; |
| 506 | memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params)); |
| 507 | } |
| 508 | } |
| 509 | #endif |
| 510 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 511 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 512 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 513 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 514 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 515 | dealloc_context_buffers_ext(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 516 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 517 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 518 | cpi->tile_data = NULL; |
| 519 | |
| 520 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 521 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 522 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 523 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 524 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 525 | cpi->cyclic_refresh = NULL; |
| 526 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 527 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 528 | cpi->active_map.map = NULL; |
| 529 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 530 | aom_free(cpi->td.mb.above_pred_buf); |
| 531 | cpi->td.mb.above_pred_buf = NULL; |
| 532 | |
| 533 | aom_free(cpi->td.mb.left_pred_buf); |
| 534 | cpi->td.mb.left_pred_buf = NULL; |
| 535 | |
| 536 | aom_free(cpi->td.mb.wsrc_buf); |
| 537 | cpi->td.mb.wsrc_buf = NULL; |
| 538 | |
| 539 | aom_free(cpi->td.mb.mask_buf); |
| 540 | cpi->td.mb.mask_buf = NULL; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 541 | |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 542 | #if CONFIG_MFMV |
| 543 | aom_free(cm->tpl_mvs); |
| 544 | cm->tpl_mvs = NULL; |
| 545 | #endif |
| 546 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 547 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 548 | av1_free_txb_buf(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 549 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 550 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 551 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 552 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 553 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 554 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 555 | #endif // CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 556 | aom_free_frame_buffer(&cpi->scaled_source); |
| 557 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 558 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 559 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 560 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 561 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 562 | cpi->tile_tok[0][0] = 0; |
| 563 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 564 | av1_free_pc_tree(&cpi->td, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 565 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 566 | aom_free(cpi->td.mb.palette_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 569 | static void save_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 570 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 571 | AV1_COMMON *cm = &cpi->common; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 572 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 573 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 574 | // Stores a snapshot of key state variables which can subsequently be |
| 575 | // restored with a call to av1_restore_coding_context. These functions are |
| 576 | // intended for use in a re-code loop in av1_compress_frame where the |
| 577 | // quantizer value is adjusted between loop iterations. |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 578 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 579 | av1_copy(cc->nmv_vec_cost[i], cpi->td.mb.nmv_vec_cost[i]); |
| 580 | av1_copy(cc->nmv_costs, cpi->nmv_costs); |
| 581 | av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp); |
| 582 | } |
| 583 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 584 | av1_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); |
| 585 | av1_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 586 | |
| 587 | cc->fc = *cm->fc; |
| 588 | } |
| 589 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 590 | static void restore_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 591 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 592 | AV1_COMMON *cm = &cpi->common; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 593 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 594 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 595 | // Restore key state variables to the snapshot state stored in the |
| 596 | // previous call to av1_save_coding_context. |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 597 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 598 | av1_copy(cpi->td.mb.nmv_vec_cost[i], cc->nmv_vec_cost[i]); |
| 599 | av1_copy(cpi->nmv_costs, cc->nmv_costs); |
| 600 | av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp); |
| 601 | } |
| 602 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 603 | av1_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); |
| 604 | av1_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 605 | |
| 606 | *cm->fc = cc->fc; |
| 607 | } |
| 608 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 609 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 610 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 611 | const RATE_CONTROL *const rc = &cpi->rc; |
| 612 | struct segmentation *const seg = &cm->seg; |
| 613 | |
| 614 | int high_q = (int)(rc->avg_q > 48.0); |
| 615 | int qi_delta; |
| 616 | |
| 617 | // Disable and clear down for KF |
| 618 | if (cm->frame_type == KEY_FRAME) { |
| 619 | // Clear down the global segmentation map |
| 620 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 621 | seg->update_map = 0; |
| 622 | seg->update_data = 0; |
| 623 | cpi->static_mb_pct = 0; |
| 624 | |
| 625 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 626 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 627 | |
| 628 | // Clear down the segment features. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 629 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 630 | } else if (cpi->refresh_alt_ref_frame) { |
| 631 | // If this is an alt ref frame |
| 632 | // Clear down the global segmentation map |
| 633 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 634 | seg->update_map = 0; |
| 635 | seg->update_data = 0; |
| 636 | cpi->static_mb_pct = 0; |
| 637 | |
| 638 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 639 | av1_disable_segmentation(seg); |
| 640 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 641 | |
| 642 | // Scan frames from current to arf frame. |
| 643 | // This function re-enables segmentation if appropriate. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 644 | av1_update_mbgraph_stats(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 645 | |
| 646 | // If segmentation was enabled set those features needed for the |
| 647 | // arf itself. |
| 648 | if (seg->enabled) { |
| 649 | seg->update_map = 1; |
| 650 | seg->update_data = 1; |
| 651 | |
| 652 | qi_delta = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 653 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, cm->bit_depth); |
| 654 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 655 | #if CONFIG_LOOPFILTER_LEVEL |
| 656 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 657 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 658 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 659 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 660 | |
| 661 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 662 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 663 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 664 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
| 665 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 666 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 667 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
| 668 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 669 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 670 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 671 | } |
| 672 | } else if (seg->enabled) { |
| 673 | // All other frames if segmentation has been enabled |
| 674 | |
| 675 | // First normal frame in a valid gf or alt ref group |
| 676 | if (rc->frames_since_golden == 0) { |
| 677 | // Set up segment features for normal frames in an arf group |
| 678 | if (rc->source_alt_ref_active) { |
| 679 | seg->update_map = 0; |
| 680 | seg->update_data = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 681 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 682 | qi_delta = |
| 683 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, cm->bit_depth); |
| 684 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 685 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 686 | |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 687 | #if CONFIG_LOOPFILTER_LEVEL |
| 688 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 689 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 690 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 691 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 692 | |
| 693 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 694 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 695 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 696 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
| 697 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 698 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
| 699 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 700 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 701 | |
| 702 | // Segment coding disabled for compred testing |
| 703 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 704 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 705 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 706 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 707 | } |
| 708 | } else { |
| 709 | // Disable segmentation and clear down features if alt ref |
| 710 | // is not active for this group |
| 711 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 712 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 713 | |
| 714 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 715 | |
| 716 | seg->update_map = 0; |
| 717 | seg->update_data = 0; |
| 718 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 719 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 720 | } |
| 721 | } else if (rc->is_src_frame_alt_ref) { |
| 722 | // Special case where we are coding over the top of a previous |
| 723 | // alt ref frame. |
| 724 | // Segment coding disabled for compred testing |
| 725 | |
| 726 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 727 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 728 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 729 | |
| 730 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 731 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 732 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 733 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 734 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 735 | |
| 736 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 737 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 738 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 739 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 740 | } |
| 741 | // Enable data update |
| 742 | seg->update_data = 1; |
| 743 | } else { |
| 744 | // All other frames. |
| 745 | |
| 746 | // No updates.. leave things as they are. |
| 747 | seg->update_map = 0; |
| 748 | seg->update_data = 0; |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 753 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 754 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 755 | MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible; |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 756 | #if CONFIG_SEGMENT_PRED_LAST |
| 757 | uint8_t *cache_ptr = cm->current_frame_seg_map; |
| 758 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 759 | uint8_t *cache_ptr = cm->last_frame_seg_map; |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 760 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 761 | int row, col; |
| 762 | |
| 763 | for (row = 0; row < cm->mi_rows; row++) { |
| 764 | MODE_INFO **mi_8x8 = mi_8x8_ptr; |
| 765 | uint8_t *cache = cache_ptr; |
| 766 | for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) |
| 767 | cache[0] = mi_8x8[0]->mbmi.segment_id; |
| 768 | mi_8x8_ptr += cm->mi_stride; |
| 769 | cache_ptr += cm->mi_cols; |
| 770 | } |
| 771 | } |
| 772 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 773 | static void alloc_raw_frame_buffers(AV1_COMP *cpi) { |
| 774 | AV1_COMMON *cm = &cpi->common; |
| 775 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 776 | |
| 777 | if (!cpi->lookahead) |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 778 | cpi->lookahead = av1_lookahead_init( |
| 779 | oxcf->width, oxcf->height, cm->subsampling_x, cm->subsampling_y, |
| 780 | cm->use_highbitdepth, oxcf->lag_in_frames); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 781 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 782 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 783 | "Failed to allocate lag buffers"); |
| 784 | |
| 785 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 786 | if (aom_realloc_frame_buffer(&cpi->alt_ref_buffer, oxcf->width, oxcf->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 787 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 788 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 789 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 790 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 791 | "Failed to allocate altref buffer"); |
| 792 | } |
| 793 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 794 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 795 | AV1_COMMON *const cm = &cpi->common; |
| 796 | if (aom_realloc_frame_buffer(&cpi->last_frame_uf, cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 797 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 798 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 799 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 800 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 801 | "Failed to allocate last frame buffer"); |
| 802 | |
| 803 | #if CONFIG_LOOP_RESTORATION |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 804 | if (aom_realloc_frame_buffer( |
| 805 | &cpi->trial_frame_rst, |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 806 | #if CONFIG_HORZONLY_FRAME_SUPERRES |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 807 | cm->superres_upscaled_width, cm->superres_upscaled_height, |
| 808 | #else |
| 809 | cm->width, cm->height, |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 810 | #endif // CONFIG_HORZONLY_FRAME_SUPERRES |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 811 | cm->subsampling_x, cm->subsampling_y, cm->use_highbitdepth, |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 812 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 813 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 814 | "Failed to allocate trial restored frame buffer"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 815 | #endif // CONFIG_LOOP_RESTORATION |
| 816 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 817 | if (aom_realloc_frame_buffer(&cpi->scaled_source, cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 818 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 819 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 820 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 821 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 822 | "Failed to allocate scaled source buffer"); |
| 823 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 824 | if (aom_realloc_frame_buffer(&cpi->scaled_last_source, cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 825 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 826 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 827 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 828 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 829 | "Failed to allocate scaled last source buffer"); |
| 830 | } |
| 831 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 832 | static void alloc_compressor_data(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 833 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 834 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 835 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 836 | av1_alloc_context_buffers(cm, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 837 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 838 | av1_alloc_txb_buf(cpi); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 839 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 840 | alloc_context_buffers_ext(cpi); |
| 841 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 842 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 843 | |
| 844 | { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 845 | unsigned int tokens = |
| 846 | 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] | 847 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 848 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 851 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 852 | } |
| 853 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 854 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 855 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 856 | av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 859 | #if CONFIG_MAX_TILE |
| 860 | |
| 861 | static void set_tile_info_max_tile(AV1_COMP *cpi) { |
| 862 | AV1_COMMON *const cm = &cpi->common; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 863 | int i, start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 864 | |
| 865 | av1_get_tile_limits(cm); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 866 | |
| 867 | // configure tile columns |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 868 | 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] | 869 | cm->uniform_tile_spacing_flag = 1; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 870 | cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols); |
| 871 | 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] | 872 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 873 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->seq_params.mib_size_log2); |
| 874 | int sb_cols = mi_cols >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 875 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 876 | cm->uniform_tile_spacing_flag = 0; |
| 877 | for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) { |
| 878 | cm->tile_col_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 879 | size_sb = cpi->oxcf.tile_widths[j++]; |
| 880 | if (j >= cpi->oxcf.tile_width_count) j = 0; |
| 881 | start_sb += AOMMIN(size_sb, MAX_TILE_WIDTH_SB); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 882 | } |
| 883 | cm->tile_cols = i; |
| 884 | cm->tile_col_start_sb[i] = sb_cols; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 885 | } |
| 886 | av1_calculate_tile_cols(cm); |
| 887 | |
| 888 | // configure tile rows |
| 889 | if (cm->uniform_tile_spacing_flag) { |
| 890 | cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows); |
| 891 | 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] | 892 | } else { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 893 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->seq_params.mib_size_log2); |
| 894 | int sb_rows = mi_rows >> cm->seq_params.mib_size_log2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 895 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 896 | for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) { |
| 897 | cm->tile_row_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 898 | size_sb = cpi->oxcf.tile_heights[j++]; |
| 899 | if (j >= cpi->oxcf.tile_height_count) j = 0; |
| 900 | start_sb += AOMMIN(size_sb, cm->max_tile_height_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 901 | } |
| 902 | cm->tile_rows = i; |
| 903 | cm->tile_row_start_sb[i] = sb_rows; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 904 | } |
| 905 | av1_calculate_tile_rows(cm); |
| 906 | } |
| 907 | |
| 908 | #endif |
| 909 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 910 | static void set_tile_info(AV1_COMP *cpi) { |
| 911 | AV1_COMMON *const cm = &cpi->common; |
Yue Chen | 4eba69b | 2017-11-09 22:37:35 -0800 | [diff] [blame] | 912 | (void)cm; |
Thomas Davies | b25ba50 | 2017-07-18 10:18:24 +0100 | [diff] [blame] | 913 | #if CONFIG_DEPENDENT_HORZTILES |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 914 | int tile_row, tile_col, num_tiles_in_tg; |
| 915 | int tg_row_start, tg_col_start; |
| 916 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 917 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 918 | if (cpi->oxcf.large_scale_tile) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 919 | #if CONFIG_EXT_PARTITION |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 920 | if (cpi->oxcf.superblock_size != AOM_SUPERBLOCK_SIZE_64X64) { |
| 921 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 32); |
| 922 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 32); |
| 923 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 924 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
| 925 | } else { |
| 926 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 927 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
| 928 | cm->tile_width <<= MAX_MIB_SIZE_LOG2 - 1; |
| 929 | cm->tile_height <<= MAX_MIB_SIZE_LOG2 - 1; |
| 930 | } |
| 931 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 932 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 933 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 934 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 935 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 936 | #endif // CONFIG_EXT_PARTITION |
| 937 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 938 | cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols); |
| 939 | cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 940 | |
Yaowu Xu | 8d0039c | 2017-10-13 07:51:46 -0700 | [diff] [blame] | 941 | assert(cm->tile_width >> MAX_MIB_SIZE_LOG2 <= 32); |
| 942 | assert(cm->tile_height >> MAX_MIB_SIZE_LOG2 <= 32); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 943 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 944 | // Get the number of tiles |
| 945 | cm->tile_cols = 1; |
| 946 | while (cm->tile_cols * cm->tile_width < cm->mi_cols) ++cm->tile_cols; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 947 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 948 | cm->tile_rows = 1; |
| 949 | while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows; |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 950 | #if CONFIG_MAX_TILE |
| 951 | int i; |
| 952 | for (i = 0; i <= cm->tile_cols; i++) { |
| 953 | cm->tile_col_start_sb[i] = |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 954 | ((i * cm->tile_width - 1) >> cm->seq_params.mib_size_log2) + 1; |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 955 | } |
| 956 | for (i = 0; i <= cm->tile_rows; i++) { |
| 957 | cm->tile_row_start_sb[i] = |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 958 | ((i * cm->tile_height - 1) >> cm->seq_params.mib_size_log2) + 1; |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 959 | } |
| 960 | #endif // CONFIG_MAX_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 961 | } else { |
| 962 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 963 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 964 | #if CONFIG_MAX_TILE |
| 965 | set_tile_info_max_tile(cpi); |
Sebastien Alaiwan | 619f417 | 2017-11-13 17:13:42 +0100 | [diff] [blame] | 966 | (void)cm; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 967 | #else |
| 968 | int min_log2_tile_cols, max_log2_tile_cols; |
| 969 | av1_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 970 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 971 | cm->log2_tile_cols = |
| 972 | clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols); |
| 973 | cm->log2_tile_rows = cpi->oxcf.tile_rows; |
Rupert Swarbrick | 940942b | 2017-09-01 12:05:55 +0100 | [diff] [blame] | 974 | |
Rupert Swarbrick | 5a010aa | 2017-09-26 16:16:48 +0100 | [diff] [blame] | 975 | cm->tile_width = |
| 976 | get_tile_size(cm->mi_cols, cm->log2_tile_cols, &cm->tile_cols); |
| 977 | cm->tile_height = |
| 978 | get_tile_size(cm->mi_rows, cm->log2_tile_rows, &cm->tile_rows); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 979 | #endif // CONFIG_MAX_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 980 | #if CONFIG_EXT_TILE |
| 981 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 982 | #endif // CONFIG_EXT_TILE |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 983 | |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 984 | #if CONFIG_DEPENDENT_HORZTILES |
| 985 | cm->dependent_horz_tiles = cpi->oxcf.dependent_horz_tiles; |
Fangwen Fu | 70bcb89 | 2017-05-06 17:05:19 -0700 | [diff] [blame] | 986 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 987 | if (cm->large_scale_tile) { |
| 988 | // May not needed since cpi->oxcf.dependent_horz_tiles is already adjusted. |
| 989 | cm->dependent_horz_tiles = 0; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 990 | } else { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 991 | #endif // CONFIG_EXT_TILE |
| 992 | if (cm->log2_tile_rows == 0) cm->dependent_horz_tiles = 0; |
| 993 | #if CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 994 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 995 | #endif // CONFIG_EXT_TILE |
| 996 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 997 | #if CONFIG_EXT_TILE |
| 998 | if (!cm->large_scale_tile) { |
| 999 | #endif // CONFIG_EXT_TILE |
| 1000 | if (cpi->oxcf.mtu == 0) { |
| 1001 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 1002 | } else { |
| 1003 | // Use a default value for the purposes of weighting costs in probability |
| 1004 | // updates |
| 1005 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1006 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1007 | num_tiles_in_tg = |
| 1008 | (cm->tile_cols * cm->tile_rows + cm->num_tg - 1) / cm->num_tg; |
| 1009 | tg_row_start = 0; |
| 1010 | tg_col_start = 0; |
| 1011 | for (tile_row = 0; tile_row < cm->tile_rows; ++tile_row) { |
| 1012 | for (tile_col = 0; tile_col < cm->tile_cols; ++tile_col) { |
| 1013 | if ((tile_row * cm->tile_cols + tile_col) % num_tiles_in_tg == 0) { |
| 1014 | tg_row_start = tile_row; |
| 1015 | tg_col_start = tile_col; |
| 1016 | } |
| 1017 | cm->tile_group_start_row[tile_row][tile_col] = tg_row_start; |
| 1018 | cm->tile_group_start_col[tile_row][tile_col] = tg_col_start; |
| 1019 | } |
| 1020 | } |
| 1021 | #if CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1022 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1023 | #endif // CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1024 | #endif |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 1025 | |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 1026 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Lei | 7bb501d | 2017-12-13 15:10:34 -0800 | [diff] [blame] | 1027 | #if CONFIG_LOOPFILTERING_ACROSS_TILES_EXT |
| 1028 | cm->loop_filter_across_tiles_v_enabled = |
| 1029 | cpi->oxcf.loop_filter_across_tiles_v_enabled; |
| 1030 | cm->loop_filter_across_tiles_h_enabled = |
| 1031 | cpi->oxcf.loop_filter_across_tiles_h_enabled; |
| 1032 | #else |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 1033 | cm->loop_filter_across_tiles_enabled = |
| 1034 | cpi->oxcf.loop_filter_across_tiles_enabled; |
Lei | 7bb501d | 2017-12-13 15:10:34 -0800 | [diff] [blame] | 1035 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES_EXT |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 1036 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1039 | static void update_frame_size(AV1_COMP *cpi) { |
| 1040 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1041 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 1042 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1043 | av1_set_mb_mi(cm, cm->width, cm->height); |
| 1044 | av1_init_context_buffers(cm); |
Luc Trudeau | 1e84af5 | 2017-11-25 15:00:28 -0500 | [diff] [blame] | 1045 | av1_init_macroblockd(cm, xd, NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1046 | memset(cpi->mbmi_ext_base, 0, |
| 1047 | cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1048 | set_tile_info(cpi); |
| 1049 | } |
| 1050 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1051 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1052 | int fb_idx; |
| 1053 | for (fb_idx = 0; fb_idx < LAST_REF_FRAMES; ++fb_idx) |
| 1054 | cpi->lst_fb_idxes[fb_idx] = fb_idx; |
| 1055 | cpi->gld_fb_idx = LAST_REF_FRAMES; |
| 1056 | cpi->bwd_fb_idx = LAST_REF_FRAMES + 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1057 | cpi->alt2_fb_idx = LAST_REF_FRAMES + 2; |
| 1058 | cpi->alt_fb_idx = LAST_REF_FRAMES + 3; |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 1059 | cpi->ext_fb_idx = LAST_REF_FRAMES + 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1060 | for (fb_idx = 0; fb_idx < MAX_EXT_ARFS + 1; ++fb_idx) |
| 1061 | cpi->arf_map[fb_idx] = LAST_REF_FRAMES + 2 + fb_idx; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1062 | #if CONFIG_AMVR |
| 1063 | cpi->rate_index = 0; |
| 1064 | cpi->rate_size = 0; |
| 1065 | cpi->cur_poc = -1; |
| 1066 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1069 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 1070 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1071 | |
| 1072 | cpi->oxcf = *oxcf; |
| 1073 | cpi->framerate = oxcf->init_framerate; |
| 1074 | |
| 1075 | cm->profile = oxcf->profile; |
| 1076 | cm->bit_depth = oxcf->bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1077 | cm->use_highbitdepth = oxcf->use_highbitdepth; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 1078 | #if CONFIG_CICP |
| 1079 | cm->color_primaries = oxcf->color_primaries; |
| 1080 | cm->transfer_characteristics = oxcf->transfer_characteristics; |
| 1081 | cm->matrix_coefficients = oxcf->matrix_coefficients; |
| 1082 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1083 | cm->color_space = oxcf->color_space; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 1084 | #endif // CONFIG_CICP |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 1085 | #if CONFIG_MONO_VIDEO |
| 1086 | cm->seq_params.monochrome = oxcf->monochrome; |
| 1087 | #endif // CONFIG_MONO_VIDEO |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 1088 | #if CONFIG_COLORSPACE_HEADERS |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 1089 | #if !CONFIG_CICP |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 1090 | cm->transfer_function = oxcf->transfer_function; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 1091 | #endif |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 1092 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
| 1093 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1094 | cm->color_range = oxcf->color_range; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 1095 | #if CONFIG_TIMING_INFO_IN_SEQ_HEADERS |
| 1096 | cm->timing_info_present = oxcf->timing_info_present; |
| 1097 | cm->num_units_in_tick = oxcf->num_units_in_tick; |
| 1098 | cm->time_scale = oxcf->time_scale; |
| 1099 | cm->equal_picture_interval = oxcf->equal_picture_interval; |
| 1100 | cm->num_ticks_per_picture = oxcf->num_ticks_per_picture; |
| 1101 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1102 | |
| 1103 | cm->width = oxcf->width; |
| 1104 | cm->height = oxcf->height; |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 1105 | set_sb_size(&cm->seq_params, |
| 1106 | select_sb_size(cpi)); // set sb size before allocations |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 1107 | alloc_compressor_data(cpi); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 1108 | #if CONFIG_FILM_GRAIN |
| 1109 | update_film_grain_parameters(cpi, oxcf); |
| 1110 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1111 | |
| 1112 | // Single thread case: use counts in common. |
| 1113 | cpi->td.counts = &cm->counts; |
| 1114 | |
| 1115 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1116 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1117 | |
| 1118 | cpi->static_mb_pct = 0; |
| 1119 | cpi->ref_frame_flags = 0; |
| 1120 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 1121 | // Reset resize pending flags |
| 1122 | cpi->resize_pending_width = 0; |
| 1123 | cpi->resize_pending_height = 0; |
| 1124 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1125 | init_buffer_indices(cpi); |
| 1126 | } |
| 1127 | |
| 1128 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1129 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1130 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 1131 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 1132 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 1133 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 1134 | |
| 1135 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 1136 | rc->optimal_buffer_level = |
| 1137 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1138 | rc->maximum_buffer_size = |
| 1139 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1140 | } |
| 1141 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1142 | #if CONFIG_JNT_COMP |
| 1143 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF, JSDAF, \ |
| 1144 | JSVAF) \ |
| 1145 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1146 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1147 | cpi->fn_ptr[BT].vf = VF; \ |
| 1148 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1149 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1150 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 1151 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 1152 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 1153 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
| 1154 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
| 1155 | #else // CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1156 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 1157 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1158 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1159 | cpi->fn_ptr[BT].vf = VF; \ |
| 1160 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1161 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1162 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 1163 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 1164 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1165 | #endif // CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1166 | |
| 1167 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1168 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1169 | int source_stride, \ |
| 1170 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1171 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1172 | } \ |
| 1173 | static unsigned int fnname##_bits10( \ |
| 1174 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1175 | int ref_stride) { \ |
| 1176 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1177 | } \ |
| 1178 | static unsigned int fnname##_bits12( \ |
| 1179 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1180 | int ref_stride) { \ |
| 1181 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1182 | } |
| 1183 | |
| 1184 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1185 | static unsigned int fnname##_bits8( \ |
| 1186 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1187 | int ref_stride, const uint8_t *second_pred) { \ |
| 1188 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1189 | } \ |
| 1190 | static unsigned int fnname##_bits10( \ |
| 1191 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1192 | int ref_stride, const uint8_t *second_pred) { \ |
| 1193 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1194 | 2; \ |
| 1195 | } \ |
| 1196 | static unsigned int fnname##_bits12( \ |
| 1197 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1198 | int ref_stride, const uint8_t *second_pred) { \ |
| 1199 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1200 | 4; \ |
| 1201 | } |
| 1202 | |
| 1203 | #define MAKE_BFP_SAD3_WRAPPER(fnname) \ |
| 1204 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1205 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1206 | unsigned int *sad_array) { \ |
| 1207 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1208 | } \ |
| 1209 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1210 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1211 | unsigned int *sad_array) { \ |
| 1212 | int i; \ |
| 1213 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1214 | for (i = 0; i < 3; i++) sad_array[i] >>= 2; \ |
| 1215 | } \ |
| 1216 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1217 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1218 | unsigned int *sad_array) { \ |
| 1219 | int i; \ |
| 1220 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1221 | for (i = 0; i < 3; i++) sad_array[i] >>= 4; \ |
| 1222 | } |
| 1223 | |
| 1224 | #define MAKE_BFP_SAD8_WRAPPER(fnname) \ |
| 1225 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1226 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1227 | unsigned int *sad_array) { \ |
| 1228 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1229 | } \ |
| 1230 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1231 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1232 | unsigned int *sad_array) { \ |
| 1233 | int i; \ |
| 1234 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1235 | for (i = 0; i < 8; i++) sad_array[i] >>= 2; \ |
| 1236 | } \ |
| 1237 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1238 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1239 | unsigned int *sad_array) { \ |
| 1240 | int i; \ |
| 1241 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1242 | for (i = 0; i < 8; i++) sad_array[i] >>= 4; \ |
| 1243 | } |
| 1244 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1245 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1246 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1247 | unsigned int *sad_array) { \ |
| 1248 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1249 | } \ |
| 1250 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1251 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1252 | unsigned int *sad_array) { \ |
| 1253 | int i; \ |
| 1254 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1255 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1256 | } \ |
| 1257 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1258 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1259 | unsigned int *sad_array) { \ |
| 1260 | int i; \ |
| 1261 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1262 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1263 | } |
| 1264 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1265 | #if CONFIG_JNT_COMP |
| 1266 | #define MAKE_BFP_JSADAVG_WRAPPER(fnname) \ |
| 1267 | static unsigned int fnname##_bits8( \ |
| 1268 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1269 | int ref_stride, const uint8_t *second_pred, \ |
| 1270 | const JNT_COMP_PARAMS *jcp_param) { \ |
| 1271 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1272 | jcp_param); \ |
| 1273 | } \ |
| 1274 | static unsigned int fnname##_bits10( \ |
| 1275 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1276 | int ref_stride, const uint8_t *second_pred, \ |
| 1277 | const JNT_COMP_PARAMS *jcp_param) { \ |
| 1278 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1279 | jcp_param) >> \ |
| 1280 | 2; \ |
| 1281 | } \ |
| 1282 | static unsigned int fnname##_bits12( \ |
| 1283 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1284 | int ref_stride, const uint8_t *second_pred, \ |
| 1285 | const JNT_COMP_PARAMS *jcp_param) { \ |
| 1286 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \ |
| 1287 | jcp_param) >> \ |
| 1288 | 4; \ |
| 1289 | } |
| 1290 | #endif // CONFIG_JNT_COMP |
| 1291 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1292 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1293 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1294 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
| 1295 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad128x128x3) |
| 1296 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad128x128x8) |
| 1297 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1298 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1299 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1300 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1301 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1302 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1303 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1304 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1305 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1306 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1307 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1308 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1309 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1310 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1311 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1312 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1313 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1314 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1315 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1316 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1317 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1318 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
| 1319 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad32x32x3) |
| 1320 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad32x32x8) |
| 1321 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1322 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1323 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
| 1324 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad64x64x3) |
| 1325 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad64x64x8) |
| 1326 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1327 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1328 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
| 1329 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x16x3) |
| 1330 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x16x8) |
| 1331 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1332 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1333 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
| 1334 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x8x3) |
| 1335 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x8x8) |
| 1336 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1337 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1338 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
| 1339 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x16x3) |
| 1340 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x16x8) |
| 1341 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1342 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1343 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
| 1344 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x8x3) |
| 1345 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x8x8) |
| 1346 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1347 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1348 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
| 1349 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x4x8) |
| 1350 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1351 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1352 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
| 1353 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x8x8) |
| 1354 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1355 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1356 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
| 1357 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad4x4x3) |
| 1358 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x4x8) |
| 1359 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1360 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1361 | #if CONFIG_EXT_PARTITION_TYPES |
| 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 | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1380 | #if CONFIG_EXT_PARTITION |
| 1381 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x128) |
| 1382 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x128_avg) |
| 1383 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x128x4d) |
| 1384 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x32) |
| 1385 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x32_avg) |
| 1386 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x32x4d) |
| 1387 | #endif // CONFIG_EXT_PARTITION |
| 1388 | #endif // CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1389 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1390 | #if CONFIG_JNT_COMP |
| 1391 | #if CONFIG_EXT_PARTITION |
| 1392 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x128_avg) |
| 1393 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x64_avg) |
| 1394 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x128_avg) |
| 1395 | #endif // CONFIG_EXT_PARTITION |
| 1396 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x16_avg) |
| 1397 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x32_avg) |
| 1398 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x32_avg) |
| 1399 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x64_avg) |
| 1400 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x32_avg) |
| 1401 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x64_avg) |
| 1402 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x16_avg) |
| 1403 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x8_avg) |
| 1404 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x16_avg) |
| 1405 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x8_avg) |
| 1406 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x4_avg) |
| 1407 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x8_avg) |
| 1408 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x4_avg) |
| 1409 | #if CONFIG_EXT_PARTITION_TYPES |
| 1410 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad4x16_avg) |
| 1411 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x4_avg) |
| 1412 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad8x32_avg) |
| 1413 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x8_avg) |
| 1414 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad16x64_avg) |
| 1415 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad64x16_avg) |
| 1416 | #if CONFIG_EXT_PARTITION |
| 1417 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad32x128_avg) |
| 1418 | MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_jnt_sad128x32_avg) |
| 1419 | #endif // CONFIG_EXT_PARTITION |
| 1420 | #endif // CONFIG_EXT_PARTITION_TYPES |
| 1421 | #endif // CONFIG_JNT_COMP |
| 1422 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1423 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1424 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1425 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1426 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1427 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1428 | static unsigned int fnname##_bits8( \ |
| 1429 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1430 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1431 | int m_stride, int invert_mask) { \ |
| 1432 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1433 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1434 | } \ |
| 1435 | static unsigned int fnname##_bits10( \ |
| 1436 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1437 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1438 | int m_stride, int invert_mask) { \ |
| 1439 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1440 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1441 | 2; \ |
| 1442 | } \ |
| 1443 | static unsigned int fnname##_bits12( \ |
| 1444 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1445 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1446 | int m_stride, int invert_mask) { \ |
| 1447 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1448 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1449 | 4; \ |
| 1450 | } |
| 1451 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1452 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1453 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1454 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1455 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1456 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1457 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1458 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1459 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1460 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1461 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1462 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1463 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1464 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1465 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1466 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1467 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1468 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1469 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1470 | |
| 1471 | #if CONFIG_EXT_PARTITION_TYPES |
| 1472 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1473 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1474 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1475 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1476 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1477 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1478 | #if CONFIG_EXT_PARTITION |
| 1479 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x128) |
| 1480 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x32) |
| 1481 | #endif // CONFIG_EXT_PARTITION |
| 1482 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1483 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1484 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1485 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1486 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1487 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1488 | |
| 1489 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1490 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1491 | const int32_t *wsrc, \ |
| 1492 | const int32_t *msk) { \ |
| 1493 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1494 | } \ |
| 1495 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1496 | const int32_t *wsrc, \ |
| 1497 | const int32_t *msk) { \ |
| 1498 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1499 | } \ |
| 1500 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1501 | const int32_t *wsrc, \ |
| 1502 | const int32_t *msk) { \ |
| 1503 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1504 | } |
| 1505 | |
| 1506 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1507 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1508 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1509 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1510 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1511 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1512 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1513 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1514 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1515 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1516 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1517 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1518 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1519 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1520 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1521 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1522 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1523 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1524 | |
| 1525 | #if CONFIG_EXT_PARTITION_TYPES |
| 1526 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1527 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1528 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1529 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1530 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1531 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1532 | #if CONFIG_EXT_PARTITION |
| 1533 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x128) |
| 1534 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x32) |
| 1535 | #endif // CONFIG_EXT_PARTITION |
| 1536 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1537 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1538 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1539 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1540 | if (cm->use_highbitdepth) { |
| 1541 | switch (cm->bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1542 | case AOM_BITS_8: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1543 | #if CONFIG_JNT_COMP |
| 1544 | #if CONFIG_EXT_PARTITION_TYPES |
| 1545 | #if CONFIG_EXT_PARTITION |
| 1546 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits8, |
| 1547 | aom_highbd_sad128x32_avg_bits8, aom_highbd_8_variance128x32, |
| 1548 | aom_highbd_8_sub_pixel_variance128x32, |
| 1549 | aom_highbd_8_sub_pixel_avg_variance128x32, NULL, NULL, |
| 1550 | aom_highbd_sad128x32x4d_bits8, |
| 1551 | aom_highbd_jnt_sad128x32_avg_bits8, |
| 1552 | aom_highbd_8_jnt_sub_pixel_avg_variance128x32) |
| 1553 | |
| 1554 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits8, |
| 1555 | aom_highbd_sad32x128_avg_bits8, aom_highbd_8_variance32x128, |
| 1556 | aom_highbd_8_sub_pixel_variance32x128, |
| 1557 | aom_highbd_8_sub_pixel_avg_variance32x128, NULL, NULL, |
| 1558 | aom_highbd_sad32x128x4d_bits8, |
| 1559 | aom_highbd_jnt_sad32x128_avg_bits8, |
| 1560 | aom_highbd_8_jnt_sub_pixel_avg_variance32x128) |
| 1561 | #endif // CONFIG_EXT_PARTITION |
| 1562 | |
| 1563 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1564 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1565 | aom_highbd_8_sub_pixel_variance64x16, |
| 1566 | aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1567 | aom_highbd_sad64x16x4d_bits8, |
| 1568 | aom_highbd_jnt_sad64x16_avg_bits8, |
| 1569 | aom_highbd_8_jnt_sub_pixel_avg_variance64x16) |
| 1570 | |
| 1571 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1572 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1573 | aom_highbd_8_sub_pixel_variance16x64, |
| 1574 | aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1575 | aom_highbd_sad16x64x4d_bits8, |
| 1576 | aom_highbd_jnt_sad16x64_avg_bits8, |
| 1577 | aom_highbd_8_jnt_sub_pixel_avg_variance16x64) |
| 1578 | |
| 1579 | HIGHBD_BFP( |
| 1580 | BLOCK_32X8, aom_highbd_sad32x8_bits8, aom_highbd_sad32x8_avg_bits8, |
| 1581 | aom_highbd_8_variance32x8, aom_highbd_8_sub_pixel_variance32x8, |
| 1582 | aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1583 | aom_highbd_sad32x8x4d_bits8, aom_highbd_jnt_sad32x8_avg_bits8, |
| 1584 | aom_highbd_8_jnt_sub_pixel_avg_variance32x8) |
| 1585 | |
| 1586 | HIGHBD_BFP( |
| 1587 | BLOCK_8X32, aom_highbd_sad8x32_bits8, aom_highbd_sad8x32_avg_bits8, |
| 1588 | aom_highbd_8_variance8x32, aom_highbd_8_sub_pixel_variance8x32, |
| 1589 | aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1590 | aom_highbd_sad8x32x4d_bits8, aom_highbd_jnt_sad8x32_avg_bits8, |
| 1591 | aom_highbd_8_jnt_sub_pixel_avg_variance8x32) |
| 1592 | |
| 1593 | HIGHBD_BFP( |
| 1594 | BLOCK_16X4, aom_highbd_sad16x4_bits8, aom_highbd_sad16x4_avg_bits8, |
| 1595 | aom_highbd_8_variance16x4, aom_highbd_8_sub_pixel_variance16x4, |
| 1596 | aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1597 | aom_highbd_sad16x4x4d_bits8, aom_highbd_jnt_sad16x4_avg_bits8, |
| 1598 | aom_highbd_8_jnt_sub_pixel_avg_variance16x4) |
| 1599 | |
| 1600 | HIGHBD_BFP( |
| 1601 | BLOCK_4X16, aom_highbd_sad4x16_bits8, aom_highbd_sad4x16_avg_bits8, |
| 1602 | aom_highbd_8_variance4x16, aom_highbd_8_sub_pixel_variance4x16, |
| 1603 | aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1604 | aom_highbd_sad4x16x4d_bits8, aom_highbd_jnt_sad4x16_avg_bits8, |
| 1605 | aom_highbd_8_jnt_sub_pixel_avg_variance4x16) |
| 1606 | #endif |
| 1607 | |
| 1608 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1609 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1610 | aom_highbd_8_sub_pixel_variance32x16, |
| 1611 | aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1612 | aom_highbd_sad32x16x4d_bits8, |
| 1613 | aom_highbd_jnt_sad32x16_avg_bits8, |
| 1614 | aom_highbd_8_jnt_sub_pixel_avg_variance32x16) |
| 1615 | |
| 1616 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1617 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1618 | aom_highbd_8_sub_pixel_variance16x32, |
| 1619 | aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1620 | aom_highbd_sad16x32x4d_bits8, |
| 1621 | aom_highbd_jnt_sad16x32_avg_bits8, |
| 1622 | aom_highbd_8_jnt_sub_pixel_avg_variance16x32) |
| 1623 | |
| 1624 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1625 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1626 | aom_highbd_8_sub_pixel_variance64x32, |
| 1627 | aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1628 | aom_highbd_sad64x32x4d_bits8, |
| 1629 | aom_highbd_jnt_sad64x32_avg_bits8, |
| 1630 | aom_highbd_8_jnt_sub_pixel_avg_variance64x32) |
| 1631 | |
| 1632 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1633 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1634 | aom_highbd_8_sub_pixel_variance32x64, |
| 1635 | aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1636 | aom_highbd_sad32x64x4d_bits8, |
| 1637 | aom_highbd_jnt_sad32x64_avg_bits8, |
| 1638 | aom_highbd_8_jnt_sub_pixel_avg_variance32x64) |
| 1639 | |
| 1640 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1641 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1642 | aom_highbd_8_sub_pixel_variance32x32, |
| 1643 | aom_highbd_8_sub_pixel_avg_variance32x32, |
| 1644 | aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8, |
| 1645 | aom_highbd_sad32x32x4d_bits8, |
| 1646 | aom_highbd_jnt_sad32x32_avg_bits8, |
| 1647 | aom_highbd_8_jnt_sub_pixel_avg_variance32x32) |
| 1648 | |
| 1649 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1650 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1651 | aom_highbd_8_sub_pixel_variance64x64, |
| 1652 | aom_highbd_8_sub_pixel_avg_variance64x64, |
| 1653 | aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8, |
| 1654 | aom_highbd_sad64x64x4d_bits8, |
| 1655 | aom_highbd_jnt_sad64x64_avg_bits8, |
| 1656 | aom_highbd_8_jnt_sub_pixel_avg_variance64x64) |
| 1657 | |
| 1658 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1659 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1660 | aom_highbd_8_sub_pixel_variance16x16, |
| 1661 | aom_highbd_8_sub_pixel_avg_variance16x16, |
| 1662 | aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8, |
| 1663 | aom_highbd_sad16x16x4d_bits8, |
| 1664 | aom_highbd_jnt_sad16x16_avg_bits8, |
| 1665 | aom_highbd_8_jnt_sub_pixel_avg_variance16x16) |
| 1666 | |
| 1667 | HIGHBD_BFP( |
| 1668 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1669 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
| 1670 | aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8, |
| 1671 | aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8, |
| 1672 | aom_highbd_jnt_sad16x8_avg_bits8, |
| 1673 | aom_highbd_8_jnt_sub_pixel_avg_variance16x8) |
| 1674 | |
| 1675 | HIGHBD_BFP( |
| 1676 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1677 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
| 1678 | aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8, |
| 1679 | aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8, |
| 1680 | aom_highbd_jnt_sad8x16_avg_bits8, |
| 1681 | aom_highbd_8_jnt_sub_pixel_avg_variance8x16) |
| 1682 | |
| 1683 | HIGHBD_BFP(BLOCK_8X8, aom_highbd_sad8x8_bits8, |
| 1684 | aom_highbd_sad8x8_avg_bits8, aom_highbd_8_variance8x8, |
| 1685 | aom_highbd_8_sub_pixel_variance8x8, |
| 1686 | aom_highbd_8_sub_pixel_avg_variance8x8, |
| 1687 | aom_highbd_sad8x8x3_bits8, aom_highbd_sad8x8x8_bits8, |
| 1688 | aom_highbd_sad8x8x4d_bits8, aom_highbd_jnt_sad8x8_avg_bits8, |
| 1689 | aom_highbd_8_jnt_sub_pixel_avg_variance8x8) |
| 1690 | |
| 1691 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8, |
| 1692 | aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4, |
| 1693 | aom_highbd_8_sub_pixel_variance8x4, |
| 1694 | aom_highbd_8_sub_pixel_avg_variance8x4, NULL, |
| 1695 | aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8, |
| 1696 | aom_highbd_jnt_sad8x4_avg_bits8, |
| 1697 | aom_highbd_8_jnt_sub_pixel_avg_variance8x4) |
| 1698 | |
| 1699 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8, |
| 1700 | aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8, |
| 1701 | aom_highbd_8_sub_pixel_variance4x8, |
| 1702 | aom_highbd_8_sub_pixel_avg_variance4x8, NULL, |
| 1703 | aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8, |
| 1704 | aom_highbd_jnt_sad4x8_avg_bits8, |
| 1705 | aom_highbd_8_jnt_sub_pixel_avg_variance4x8) |
| 1706 | |
| 1707 | HIGHBD_BFP(BLOCK_4X4, aom_highbd_sad4x4_bits8, |
| 1708 | aom_highbd_sad4x4_avg_bits8, aom_highbd_8_variance4x4, |
| 1709 | aom_highbd_8_sub_pixel_variance4x4, |
| 1710 | aom_highbd_8_sub_pixel_avg_variance4x4, |
| 1711 | aom_highbd_sad4x4x3_bits8, aom_highbd_sad4x4x8_bits8, |
| 1712 | aom_highbd_sad4x4x4d_bits8, aom_highbd_jnt_sad4x4_avg_bits8, |
| 1713 | aom_highbd_8_jnt_sub_pixel_avg_variance4x4) |
| 1714 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1715 | #if CONFIG_EXT_PARTITION |
| 1716 | HIGHBD_BFP( |
| 1717 | BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1718 | aom_highbd_sad128x128_avg_bits8, aom_highbd_8_variance128x128, |
| 1719 | aom_highbd_8_sub_pixel_variance128x128, |
| 1720 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1721 | aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8, |
| 1722 | aom_highbd_sad128x128x4d_bits8, aom_highbd_jnt_sad128x128_avg_bits8, |
| 1723 | aom_highbd_8_jnt_sub_pixel_avg_variance128x128) |
| 1724 | |
| 1725 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1726 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1727 | aom_highbd_8_sub_pixel_variance128x64, |
| 1728 | aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1729 | aom_highbd_sad128x64x4d_bits8, |
| 1730 | aom_highbd_jnt_sad128x64_avg_bits8, |
| 1731 | aom_highbd_8_jnt_sub_pixel_avg_variance128x64) |
| 1732 | |
| 1733 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1734 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1735 | aom_highbd_8_sub_pixel_variance64x128, |
| 1736 | aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1737 | aom_highbd_sad64x128x4d_bits8, |
| 1738 | aom_highbd_jnt_sad64x128_avg_bits8, |
| 1739 | aom_highbd_8_jnt_sub_pixel_avg_variance64x128) |
| 1740 | #endif // CONFIG_EXT_PARTITION |
| 1741 | #else // CONFIG_JNT_COMP |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1742 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1743 | #if CONFIG_EXT_PARTITION |
| 1744 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits8, |
| 1745 | aom_highbd_sad128x32_avg_bits8, aom_highbd_8_variance128x32, |
| 1746 | aom_highbd_8_sub_pixel_variance128x32, |
| 1747 | aom_highbd_8_sub_pixel_avg_variance128x32, NULL, NULL, |
| 1748 | aom_highbd_sad128x32x4d_bits8) |
| 1749 | |
| 1750 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits8, |
| 1751 | aom_highbd_sad32x128_avg_bits8, aom_highbd_8_variance32x128, |
| 1752 | aom_highbd_8_sub_pixel_variance32x128, |
| 1753 | aom_highbd_8_sub_pixel_avg_variance32x128, NULL, NULL, |
| 1754 | aom_highbd_sad32x128x4d_bits8) |
| 1755 | #endif // CONFIG_EXT_PARTITION |
| 1756 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1757 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1758 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1759 | aom_highbd_8_sub_pixel_variance64x16, |
| 1760 | aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1761 | aom_highbd_sad64x16x4d_bits8) |
| 1762 | |
| 1763 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1764 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1765 | aom_highbd_8_sub_pixel_variance16x64, |
| 1766 | aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1767 | aom_highbd_sad16x64x4d_bits8) |
| 1768 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1769 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits8, |
| 1770 | aom_highbd_sad32x8_avg_bits8, aom_highbd_8_variance32x8, |
| 1771 | aom_highbd_8_sub_pixel_variance32x8, |
| 1772 | aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1773 | aom_highbd_sad32x8x4d_bits8) |
| 1774 | |
| 1775 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits8, |
| 1776 | aom_highbd_sad8x32_avg_bits8, aom_highbd_8_variance8x32, |
| 1777 | aom_highbd_8_sub_pixel_variance8x32, |
| 1778 | aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1779 | aom_highbd_sad8x32x4d_bits8) |
| 1780 | |
| 1781 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits8, |
| 1782 | aom_highbd_sad16x4_avg_bits8, aom_highbd_8_variance16x4, |
| 1783 | aom_highbd_8_sub_pixel_variance16x4, |
| 1784 | aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1785 | aom_highbd_sad16x4x4d_bits8) |
| 1786 | |
| 1787 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits8, |
| 1788 | aom_highbd_sad4x16_avg_bits8, aom_highbd_8_variance4x16, |
| 1789 | aom_highbd_8_sub_pixel_variance4x16, |
| 1790 | aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1791 | aom_highbd_sad4x16x4d_bits8) |
| 1792 | #endif |
| 1793 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1794 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1795 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1796 | aom_highbd_8_sub_pixel_variance32x16, |
| 1797 | aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1798 | aom_highbd_sad32x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1799 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1800 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1801 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1802 | aom_highbd_8_sub_pixel_variance16x32, |
| 1803 | aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1804 | aom_highbd_sad16x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1805 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1806 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1807 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1808 | aom_highbd_8_sub_pixel_variance64x32, |
| 1809 | aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1810 | aom_highbd_sad64x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1811 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1812 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1813 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1814 | aom_highbd_8_sub_pixel_variance32x64, |
| 1815 | aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1816 | aom_highbd_sad32x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1817 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1818 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1819 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1820 | aom_highbd_8_sub_pixel_variance32x32, |
| 1821 | aom_highbd_8_sub_pixel_avg_variance32x32, |
| 1822 | aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8, |
| 1823 | aom_highbd_sad32x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1824 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1825 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1826 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1827 | aom_highbd_8_sub_pixel_variance64x64, |
| 1828 | aom_highbd_8_sub_pixel_avg_variance64x64, |
| 1829 | aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8, |
| 1830 | aom_highbd_sad64x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1831 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1832 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1833 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1834 | aom_highbd_8_sub_pixel_variance16x16, |
| 1835 | aom_highbd_8_sub_pixel_avg_variance16x16, |
| 1836 | aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8, |
| 1837 | aom_highbd_sad16x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1838 | |
| 1839 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1840 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1841 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
| 1842 | aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8, |
| 1843 | aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1844 | |
| 1845 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1846 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1847 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
| 1848 | aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8, |
| 1849 | aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1850 | |
| 1851 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1852 | BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8, |
| 1853 | aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8, |
| 1854 | aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits8, |
| 1855 | aom_highbd_sad8x8x8_bits8, aom_highbd_sad8x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1856 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1857 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8, |
| 1858 | aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4, |
| 1859 | aom_highbd_8_sub_pixel_variance8x4, |
| 1860 | aom_highbd_8_sub_pixel_avg_variance8x4, NULL, |
| 1861 | aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1862 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1863 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8, |
| 1864 | aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8, |
| 1865 | aom_highbd_8_sub_pixel_variance4x8, |
| 1866 | aom_highbd_8_sub_pixel_avg_variance4x8, NULL, |
| 1867 | aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1868 | |
| 1869 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1870 | BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8, |
| 1871 | aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4, |
| 1872 | aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits8, |
| 1873 | aom_highbd_sad4x4x8_bits8, aom_highbd_sad4x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1874 | |
| 1875 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1876 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1877 | aom_highbd_sad128x128_avg_bits8, |
| 1878 | aom_highbd_8_variance128x128, |
| 1879 | aom_highbd_8_sub_pixel_variance128x128, |
| 1880 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1881 | aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8, |
| 1882 | aom_highbd_sad128x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1883 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1884 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1885 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1886 | aom_highbd_8_sub_pixel_variance128x64, |
| 1887 | aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1888 | aom_highbd_sad128x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1889 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1890 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1891 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1892 | aom_highbd_8_sub_pixel_variance64x128, |
| 1893 | aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1894 | aom_highbd_sad64x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1895 | #endif // CONFIG_EXT_PARTITION |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 1896 | #endif // CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1897 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1898 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1899 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1900 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1901 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1902 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1903 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1904 | aom_highbd_8_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1905 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1906 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1907 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1908 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1909 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1910 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1911 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1912 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1913 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1914 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1915 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1916 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1917 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1918 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1919 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1920 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1921 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1922 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1923 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1924 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1925 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1926 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1927 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1928 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1929 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1930 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1931 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1932 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1933 | #if CONFIG_EXT_PARTITION |
| 1934 | HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits8, |
| 1935 | aom_highbd_8_masked_sub_pixel_variance128x32) |
| 1936 | |
| 1937 | HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits8, |
| 1938 | aom_highbd_8_masked_sub_pixel_variance32x128) |
| 1939 | #endif // CONFIG_EXT_PARTITION |
| 1940 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1941 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1942 | aom_highbd_8_masked_sub_pixel_variance64x16) |
| 1943 | |
| 1944 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1945 | aom_highbd_8_masked_sub_pixel_variance16x64) |
| 1946 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1947 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1948 | aom_highbd_8_masked_sub_pixel_variance32x8) |
| 1949 | |
| 1950 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1951 | aom_highbd_8_masked_sub_pixel_variance8x32) |
| 1952 | |
| 1953 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1954 | aom_highbd_8_masked_sub_pixel_variance16x4) |
| 1955 | |
| 1956 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1957 | aom_highbd_8_masked_sub_pixel_variance4x16) |
| 1958 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1959 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1960 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1961 | aom_highbd_obmc_variance128x128, |
| 1962 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1963 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1964 | aom_highbd_obmc_variance128x64, |
| 1965 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1966 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1967 | aom_highbd_obmc_variance64x128, |
| 1968 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1969 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1970 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1971 | aom_highbd_obmc_variance64x64, |
| 1972 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1973 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1974 | aom_highbd_obmc_variance64x32, |
| 1975 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1976 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1977 | aom_highbd_obmc_variance32x64, |
| 1978 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1979 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1980 | aom_highbd_obmc_variance32x32, |
| 1981 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1982 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1983 | aom_highbd_obmc_variance32x16, |
| 1984 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1985 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1986 | aom_highbd_obmc_variance16x32, |
| 1987 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1988 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1989 | aom_highbd_obmc_variance16x16, |
| 1990 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1991 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1992 | aom_highbd_obmc_variance8x16, |
| 1993 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1994 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1995 | aom_highbd_obmc_variance16x8, |
| 1996 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1997 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1998 | aom_highbd_obmc_variance8x8, |
| 1999 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 2000 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 2001 | aom_highbd_obmc_variance4x8, |
| 2002 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 2003 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 2004 | aom_highbd_obmc_variance8x4, |
| 2005 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 2006 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 2007 | aom_highbd_obmc_variance4x4, |
| 2008 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2009 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2010 | #if CONFIG_EXT_PARTITION |
| 2011 | HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits8, |
| 2012 | aom_highbd_obmc_variance128x32, |
| 2013 | aom_highbd_obmc_sub_pixel_variance128x32) |
| 2014 | |
| 2015 | HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits8, |
| 2016 | aom_highbd_obmc_variance32x128, |
| 2017 | aom_highbd_obmc_sub_pixel_variance32x128) |
| 2018 | #endif // CONFIG_EXT_PARTITION |
| 2019 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2020 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 2021 | aom_highbd_obmc_variance64x16, |
| 2022 | aom_highbd_obmc_sub_pixel_variance64x16) |
| 2023 | |
| 2024 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 2025 | aom_highbd_obmc_variance16x64, |
| 2026 | aom_highbd_obmc_sub_pixel_variance16x64) |
| 2027 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2028 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 2029 | aom_highbd_obmc_variance32x8, |
| 2030 | aom_highbd_obmc_sub_pixel_variance32x8) |
| 2031 | |
| 2032 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 2033 | aom_highbd_obmc_variance8x32, |
| 2034 | aom_highbd_obmc_sub_pixel_variance8x32) |
| 2035 | |
| 2036 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 2037 | aom_highbd_obmc_variance16x4, |
| 2038 | aom_highbd_obmc_sub_pixel_variance16x4) |
| 2039 | |
| 2040 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 2041 | aom_highbd_obmc_variance4x16, |
| 2042 | aom_highbd_obmc_sub_pixel_variance4x16) |
| 2043 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2044 | break; |
| 2045 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2046 | case AOM_BITS_10: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2047 | #if CONFIG_JNT_COMP |
| 2048 | #if CONFIG_EXT_PARTITION_TYPES |
| 2049 | #if CONFIG_EXT_PARTITION |
| 2050 | HIGHBD_BFP( |
| 2051 | BLOCK_128X32, aom_highbd_sad128x32_bits10, |
| 2052 | aom_highbd_sad128x32_avg_bits10, aom_highbd_10_variance128x32, |
| 2053 | aom_highbd_10_sub_pixel_variance128x32, |
| 2054 | aom_highbd_10_sub_pixel_avg_variance128x32, NULL, NULL, |
| 2055 | aom_highbd_sad128x32x4d_bits10, aom_highbd_jnt_sad128x32_avg_bits10, |
| 2056 | aom_highbd_10_jnt_sub_pixel_avg_variance128x32); |
| 2057 | |
| 2058 | HIGHBD_BFP( |
| 2059 | BLOCK_32X128, aom_highbd_sad32x128_bits10, |
| 2060 | aom_highbd_sad32x128_avg_bits10, aom_highbd_10_variance32x128, |
| 2061 | aom_highbd_10_sub_pixel_variance32x128, |
| 2062 | aom_highbd_10_sub_pixel_avg_variance32x128, NULL, NULL, |
| 2063 | aom_highbd_sad32x128x4d_bits10, aom_highbd_jnt_sad32x128_avg_bits10, |
| 2064 | aom_highbd_10_jnt_sub_pixel_avg_variance32x128); |
| 2065 | #endif // CONFIG_EXT_PARTITION |
| 2066 | |
| 2067 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 2068 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 2069 | aom_highbd_10_sub_pixel_variance64x16, |
| 2070 | aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2071 | aom_highbd_sad64x16x4d_bits10, |
| 2072 | aom_highbd_jnt_sad64x16_avg_bits10, |
| 2073 | aom_highbd_10_jnt_sub_pixel_avg_variance64x16); |
| 2074 | |
| 2075 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 2076 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 2077 | aom_highbd_10_sub_pixel_variance16x64, |
| 2078 | aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2079 | aom_highbd_sad16x64x4d_bits10, |
| 2080 | aom_highbd_jnt_sad16x64_avg_bits10, |
| 2081 | aom_highbd_10_jnt_sub_pixel_avg_variance16x64); |
| 2082 | |
| 2083 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 2084 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 2085 | aom_highbd_10_sub_pixel_variance32x8, |
| 2086 | aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2087 | aom_highbd_sad32x8x4d_bits10, |
| 2088 | aom_highbd_jnt_sad32x8_avg_bits10, |
| 2089 | aom_highbd_10_jnt_sub_pixel_avg_variance32x8); |
| 2090 | |
| 2091 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 2092 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 2093 | aom_highbd_10_sub_pixel_variance8x32, |
| 2094 | aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2095 | aom_highbd_sad8x32x4d_bits10, |
| 2096 | aom_highbd_jnt_sad8x32_avg_bits10, |
| 2097 | aom_highbd_10_jnt_sub_pixel_avg_variance8x32); |
| 2098 | |
| 2099 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 2100 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 2101 | aom_highbd_10_sub_pixel_variance16x4, |
| 2102 | aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2103 | aom_highbd_sad16x4x4d_bits10, |
| 2104 | aom_highbd_jnt_sad16x4_avg_bits10, |
| 2105 | aom_highbd_10_jnt_sub_pixel_avg_variance16x4); |
| 2106 | |
| 2107 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 2108 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 2109 | aom_highbd_10_sub_pixel_variance4x16, |
| 2110 | aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2111 | aom_highbd_sad4x16x4d_bits10, |
| 2112 | aom_highbd_jnt_sad4x16_avg_bits10, |
| 2113 | aom_highbd_10_jnt_sub_pixel_avg_variance4x16); |
| 2114 | #endif |
| 2115 | |
| 2116 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 2117 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 2118 | aom_highbd_10_sub_pixel_variance32x16, |
| 2119 | aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2120 | aom_highbd_sad32x16x4d_bits10, |
| 2121 | aom_highbd_jnt_sad32x16_avg_bits10, |
| 2122 | aom_highbd_10_jnt_sub_pixel_avg_variance32x16); |
| 2123 | |
| 2124 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 2125 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 2126 | aom_highbd_10_sub_pixel_variance16x32, |
| 2127 | aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2128 | aom_highbd_sad16x32x4d_bits10, |
| 2129 | aom_highbd_jnt_sad16x32_avg_bits10, |
| 2130 | aom_highbd_10_jnt_sub_pixel_avg_variance16x32); |
| 2131 | |
| 2132 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 2133 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 2134 | aom_highbd_10_sub_pixel_variance64x32, |
| 2135 | aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2136 | aom_highbd_sad64x32x4d_bits10, |
| 2137 | aom_highbd_jnt_sad64x32_avg_bits10, |
| 2138 | aom_highbd_10_jnt_sub_pixel_avg_variance64x32); |
| 2139 | |
| 2140 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 2141 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 2142 | aom_highbd_10_sub_pixel_variance32x64, |
| 2143 | aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2144 | aom_highbd_sad32x64x4d_bits10, |
| 2145 | aom_highbd_jnt_sad32x64_avg_bits10, |
| 2146 | aom_highbd_10_jnt_sub_pixel_avg_variance32x64); |
| 2147 | |
| 2148 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 2149 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 2150 | aom_highbd_10_sub_pixel_variance32x32, |
| 2151 | aom_highbd_10_sub_pixel_avg_variance32x32, |
| 2152 | aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10, |
| 2153 | aom_highbd_sad32x32x4d_bits10, |
| 2154 | aom_highbd_jnt_sad32x32_avg_bits10, |
| 2155 | aom_highbd_10_jnt_sub_pixel_avg_variance32x32); |
| 2156 | |
| 2157 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 2158 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 2159 | aom_highbd_10_sub_pixel_variance64x64, |
| 2160 | aom_highbd_10_sub_pixel_avg_variance64x64, |
| 2161 | aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10, |
| 2162 | aom_highbd_sad64x64x4d_bits10, |
| 2163 | aom_highbd_jnt_sad64x64_avg_bits10, |
| 2164 | aom_highbd_10_jnt_sub_pixel_avg_variance64x64); |
| 2165 | |
| 2166 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 2167 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 2168 | aom_highbd_10_sub_pixel_variance16x16, |
| 2169 | aom_highbd_10_sub_pixel_avg_variance16x16, |
| 2170 | aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10, |
| 2171 | aom_highbd_sad16x16x4d_bits10, |
| 2172 | aom_highbd_jnt_sad16x16_avg_bits10, |
| 2173 | aom_highbd_10_jnt_sub_pixel_avg_variance16x16); |
| 2174 | |
| 2175 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 2176 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 2177 | aom_highbd_10_sub_pixel_variance16x8, |
| 2178 | aom_highbd_10_sub_pixel_avg_variance16x8, |
| 2179 | aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10, |
| 2180 | aom_highbd_sad16x8x4d_bits10, |
| 2181 | aom_highbd_jnt_sad16x8_avg_bits10, |
| 2182 | aom_highbd_10_jnt_sub_pixel_avg_variance16x8); |
| 2183 | |
| 2184 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 2185 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 2186 | aom_highbd_10_sub_pixel_variance8x16, |
| 2187 | aom_highbd_10_sub_pixel_avg_variance8x16, |
| 2188 | aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10, |
| 2189 | aom_highbd_sad8x16x4d_bits10, |
| 2190 | aom_highbd_jnt_sad8x16_avg_bits10, |
| 2191 | aom_highbd_10_jnt_sub_pixel_avg_variance8x16); |
| 2192 | |
| 2193 | HIGHBD_BFP( |
| 2194 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 2195 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
| 2196 | aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10, |
| 2197 | aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10, |
| 2198 | aom_highbd_jnt_sad8x8_avg_bits10, |
| 2199 | aom_highbd_10_jnt_sub_pixel_avg_variance8x8); |
| 2200 | |
| 2201 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10, |
| 2202 | aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4, |
| 2203 | aom_highbd_10_sub_pixel_variance8x4, |
| 2204 | aom_highbd_10_sub_pixel_avg_variance8x4, NULL, |
| 2205 | aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10, |
| 2206 | aom_highbd_jnt_sad8x4_avg_bits10, |
| 2207 | aom_highbd_10_jnt_sub_pixel_avg_variance8x4); |
| 2208 | |
| 2209 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10, |
| 2210 | aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8, |
| 2211 | aom_highbd_10_sub_pixel_variance4x8, |
| 2212 | aom_highbd_10_sub_pixel_avg_variance4x8, NULL, |
| 2213 | aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10, |
| 2214 | aom_highbd_jnt_sad4x8_avg_bits10, |
| 2215 | aom_highbd_10_jnt_sub_pixel_avg_variance4x8); |
| 2216 | |
| 2217 | HIGHBD_BFP( |
| 2218 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 2219 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
| 2220 | aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10, |
| 2221 | aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10, |
| 2222 | aom_highbd_jnt_sad4x4_avg_bits10, |
| 2223 | aom_highbd_10_jnt_sub_pixel_avg_variance4x4); |
| 2224 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2225 | #if CONFIG_EXT_PARTITION |
| 2226 | HIGHBD_BFP( |
| 2227 | BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 2228 | aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128, |
| 2229 | aom_highbd_10_sub_pixel_variance128x128, |
| 2230 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 2231 | aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10, |
| 2232 | aom_highbd_sad128x128x4d_bits10, |
| 2233 | aom_highbd_jnt_sad128x128_avg_bits10, |
| 2234 | aom_highbd_10_jnt_sub_pixel_avg_variance128x128); |
| 2235 | |
| 2236 | HIGHBD_BFP( |
| 2237 | BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 2238 | aom_highbd_sad128x64_avg_bits10, aom_highbd_10_variance128x64, |
| 2239 | aom_highbd_10_sub_pixel_variance128x64, |
| 2240 | aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL, |
| 2241 | aom_highbd_sad128x64x4d_bits10, aom_highbd_jnt_sad128x64_avg_bits10, |
| 2242 | aom_highbd_10_jnt_sub_pixel_avg_variance128x64); |
| 2243 | |
| 2244 | HIGHBD_BFP( |
| 2245 | BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 2246 | aom_highbd_sad64x128_avg_bits10, aom_highbd_10_variance64x128, |
| 2247 | aom_highbd_10_sub_pixel_variance64x128, |
| 2248 | aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL, |
| 2249 | aom_highbd_sad64x128x4d_bits10, aom_highbd_jnt_sad64x128_avg_bits10, |
| 2250 | aom_highbd_10_jnt_sub_pixel_avg_variance64x128); |
| 2251 | #endif // CONFIG_EXT_PARTITION |
| 2252 | #else // CONFIG_JNT_COMP |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2253 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2254 | #if CONFIG_EXT_PARTITION |
| 2255 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits10, |
| 2256 | aom_highbd_sad128x32_avg_bits10, |
| 2257 | aom_highbd_10_variance128x32, |
| 2258 | aom_highbd_10_sub_pixel_variance128x32, |
| 2259 | aom_highbd_10_sub_pixel_avg_variance128x32, NULL, NULL, |
| 2260 | aom_highbd_sad128x32x4d_bits10) |
| 2261 | |
| 2262 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits10, |
| 2263 | aom_highbd_sad32x128_avg_bits10, |
| 2264 | aom_highbd_10_variance32x128, |
| 2265 | aom_highbd_10_sub_pixel_variance32x128, |
| 2266 | aom_highbd_10_sub_pixel_avg_variance32x128, NULL, NULL, |
| 2267 | aom_highbd_sad32x128x4d_bits10) |
| 2268 | #endif // CONFIG_EXT_PARTITION |
| 2269 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2270 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 2271 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 2272 | aom_highbd_10_sub_pixel_variance64x16, |
| 2273 | aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2274 | aom_highbd_sad64x16x4d_bits10) |
| 2275 | |
| 2276 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 2277 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 2278 | aom_highbd_10_sub_pixel_variance16x64, |
| 2279 | aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2280 | aom_highbd_sad16x64x4d_bits10) |
| 2281 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2282 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 2283 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 2284 | aom_highbd_10_sub_pixel_variance32x8, |
| 2285 | aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2286 | aom_highbd_sad32x8x4d_bits10) |
| 2287 | |
| 2288 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 2289 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 2290 | aom_highbd_10_sub_pixel_variance8x32, |
| 2291 | aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2292 | aom_highbd_sad8x32x4d_bits10) |
| 2293 | |
| 2294 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 2295 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 2296 | aom_highbd_10_sub_pixel_variance16x4, |
| 2297 | aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2298 | aom_highbd_sad16x4x4d_bits10) |
| 2299 | |
| 2300 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 2301 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 2302 | aom_highbd_10_sub_pixel_variance4x16, |
| 2303 | aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2304 | aom_highbd_sad4x16x4d_bits10) |
| 2305 | #endif |
| 2306 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2307 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 2308 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 2309 | aom_highbd_10_sub_pixel_variance32x16, |
| 2310 | aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2311 | aom_highbd_sad32x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2312 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2313 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 2314 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 2315 | aom_highbd_10_sub_pixel_variance16x32, |
| 2316 | aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2317 | aom_highbd_sad16x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2318 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2319 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 2320 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 2321 | aom_highbd_10_sub_pixel_variance64x32, |
| 2322 | aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2323 | aom_highbd_sad64x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2324 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2325 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 2326 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 2327 | aom_highbd_10_sub_pixel_variance32x64, |
| 2328 | aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2329 | aom_highbd_sad32x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2330 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2331 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 2332 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 2333 | aom_highbd_10_sub_pixel_variance32x32, |
| 2334 | aom_highbd_10_sub_pixel_avg_variance32x32, |
| 2335 | aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10, |
| 2336 | aom_highbd_sad32x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2337 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2338 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 2339 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 2340 | aom_highbd_10_sub_pixel_variance64x64, |
| 2341 | aom_highbd_10_sub_pixel_avg_variance64x64, |
| 2342 | aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10, |
| 2343 | aom_highbd_sad64x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2344 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2345 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 2346 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 2347 | aom_highbd_10_sub_pixel_variance16x16, |
| 2348 | aom_highbd_10_sub_pixel_avg_variance16x16, |
| 2349 | aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10, |
| 2350 | aom_highbd_sad16x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2351 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2352 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 2353 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 2354 | aom_highbd_10_sub_pixel_variance16x8, |
| 2355 | aom_highbd_10_sub_pixel_avg_variance16x8, |
| 2356 | aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10, |
| 2357 | aom_highbd_sad16x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2358 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2359 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 2360 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 2361 | aom_highbd_10_sub_pixel_variance8x16, |
| 2362 | aom_highbd_10_sub_pixel_avg_variance8x16, |
| 2363 | aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10, |
| 2364 | aom_highbd_sad8x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2365 | |
| 2366 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2367 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 2368 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
| 2369 | aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10, |
| 2370 | aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2371 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2372 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10, |
| 2373 | aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4, |
| 2374 | aom_highbd_10_sub_pixel_variance8x4, |
| 2375 | aom_highbd_10_sub_pixel_avg_variance8x4, NULL, |
| 2376 | aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2377 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2378 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10, |
| 2379 | aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8, |
| 2380 | aom_highbd_10_sub_pixel_variance4x8, |
| 2381 | aom_highbd_10_sub_pixel_avg_variance4x8, NULL, |
| 2382 | aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2383 | |
| 2384 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2385 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 2386 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
| 2387 | aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10, |
| 2388 | aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2389 | |
| 2390 | #if CONFIG_EXT_PARTITION |
| 2391 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2392 | BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 2393 | aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128, |
| 2394 | aom_highbd_10_sub_pixel_variance128x128, |
| 2395 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 2396 | aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10, |
| 2397 | aom_highbd_sad128x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2398 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2399 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 2400 | aom_highbd_sad128x64_avg_bits10, |
| 2401 | aom_highbd_10_variance128x64, |
| 2402 | aom_highbd_10_sub_pixel_variance128x64, |
| 2403 | aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL, |
| 2404 | aom_highbd_sad128x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2405 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2406 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 2407 | aom_highbd_sad64x128_avg_bits10, |
| 2408 | aom_highbd_10_variance64x128, |
| 2409 | aom_highbd_10_sub_pixel_variance64x128, |
| 2410 | aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL, |
| 2411 | aom_highbd_sad64x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2412 | #endif // CONFIG_EXT_PARTITION |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2413 | #endif // CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2414 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2415 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2416 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 2417 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 2418 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 2419 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 2420 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 2421 | aom_highbd_10_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2422 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2423 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 2424 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 2425 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 2426 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 2427 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 2428 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 2429 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 2430 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 2431 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 2432 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 2433 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 2434 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 2435 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 2436 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 2437 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 2438 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 2439 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 2440 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 2441 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 2442 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 2443 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 2444 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 2445 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 2446 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 2447 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 2448 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2449 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2450 | #if CONFIG_EXT_PARTITION |
| 2451 | HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits10, |
| 2452 | aom_highbd_10_masked_sub_pixel_variance128x32) |
| 2453 | |
| 2454 | HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits10, |
| 2455 | aom_highbd_10_masked_sub_pixel_variance32x128) |
| 2456 | #endif // CONFIG_EXT_PARTITION |
| 2457 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2458 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 2459 | aom_highbd_10_masked_sub_pixel_variance64x16) |
| 2460 | |
| 2461 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 2462 | aom_highbd_10_masked_sub_pixel_variance16x64) |
| 2463 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2464 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 2465 | aom_highbd_10_masked_sub_pixel_variance32x8) |
| 2466 | |
| 2467 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 2468 | aom_highbd_10_masked_sub_pixel_variance8x32) |
| 2469 | |
| 2470 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 2471 | aom_highbd_10_masked_sub_pixel_variance16x4) |
| 2472 | |
| 2473 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 2474 | aom_highbd_10_masked_sub_pixel_variance4x16) |
| 2475 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2476 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2477 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 2478 | aom_highbd_10_obmc_variance128x128, |
| 2479 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 2480 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 2481 | aom_highbd_10_obmc_variance128x64, |
| 2482 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 2483 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 2484 | aom_highbd_10_obmc_variance64x128, |
| 2485 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2486 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2487 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 2488 | aom_highbd_10_obmc_variance64x64, |
| 2489 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 2490 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 2491 | aom_highbd_10_obmc_variance64x32, |
| 2492 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 2493 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 2494 | aom_highbd_10_obmc_variance32x64, |
| 2495 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 2496 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 2497 | aom_highbd_10_obmc_variance32x32, |
| 2498 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 2499 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 2500 | aom_highbd_10_obmc_variance32x16, |
| 2501 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 2502 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 2503 | aom_highbd_10_obmc_variance16x32, |
| 2504 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 2505 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 2506 | aom_highbd_10_obmc_variance16x16, |
| 2507 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 2508 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 2509 | aom_highbd_10_obmc_variance8x16, |
| 2510 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 2511 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 2512 | aom_highbd_10_obmc_variance16x8, |
| 2513 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 2514 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 2515 | aom_highbd_10_obmc_variance8x8, |
| 2516 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 2517 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 2518 | aom_highbd_10_obmc_variance4x8, |
| 2519 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 2520 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 2521 | aom_highbd_10_obmc_variance8x4, |
| 2522 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 2523 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 2524 | aom_highbd_10_obmc_variance4x4, |
| 2525 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2526 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2527 | #if CONFIG_EXT_PARTITION |
| 2528 | HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits10, |
| 2529 | aom_highbd_10_obmc_variance128x32, |
| 2530 | aom_highbd_10_obmc_sub_pixel_variance128x32) |
| 2531 | |
| 2532 | HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits10, |
| 2533 | aom_highbd_10_obmc_variance32x128, |
| 2534 | aom_highbd_10_obmc_sub_pixel_variance32x128) |
| 2535 | #endif // CONFIG_EXT_PARTITION |
| 2536 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2537 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 2538 | aom_highbd_10_obmc_variance64x16, |
| 2539 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 2540 | |
| 2541 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 2542 | aom_highbd_10_obmc_variance16x64, |
| 2543 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 2544 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2545 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 2546 | aom_highbd_10_obmc_variance32x8, |
| 2547 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 2548 | |
| 2549 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 2550 | aom_highbd_10_obmc_variance8x32, |
| 2551 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 2552 | |
| 2553 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 2554 | aom_highbd_10_obmc_variance16x4, |
| 2555 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 2556 | |
| 2557 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 2558 | aom_highbd_10_obmc_variance4x16, |
| 2559 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
| 2560 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2561 | break; |
| 2562 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2563 | case AOM_BITS_12: |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2564 | #if CONFIG_JNT_COMP |
| 2565 | #if CONFIG_EXT_PARTITION_TYPES |
| 2566 | #if CONFIG_EXT_PARTITION |
| 2567 | HIGHBD_BFP( |
| 2568 | BLOCK_128X32, aom_highbd_sad128x32_bits12, |
| 2569 | aom_highbd_sad128x32_avg_bits12, aom_highbd_12_variance128x32, |
| 2570 | aom_highbd_12_sub_pixel_variance128x32, |
| 2571 | aom_highbd_12_sub_pixel_avg_variance128x32, NULL, NULL, |
| 2572 | aom_highbd_sad128x32x4d_bits12, aom_highbd_jnt_sad128x32_avg_bits12, |
| 2573 | aom_highbd_12_jnt_sub_pixel_avg_variance128x32); |
| 2574 | |
| 2575 | HIGHBD_BFP( |
| 2576 | BLOCK_32X128, aom_highbd_sad32x128_bits12, |
| 2577 | aom_highbd_sad32x128_avg_bits12, aom_highbd_12_variance32x128, |
| 2578 | aom_highbd_12_sub_pixel_variance32x128, |
| 2579 | aom_highbd_12_sub_pixel_avg_variance32x128, NULL, NULL, |
| 2580 | aom_highbd_sad32x128x4d_bits12, aom_highbd_jnt_sad32x128_avg_bits12, |
| 2581 | aom_highbd_12_jnt_sub_pixel_avg_variance32x128); |
| 2582 | #endif // CONFIG_EXT_PARTITION |
| 2583 | |
| 2584 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 2585 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 2586 | aom_highbd_12_sub_pixel_variance64x16, |
| 2587 | aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2588 | aom_highbd_sad64x16x4d_bits12, |
| 2589 | aom_highbd_jnt_sad64x16_avg_bits12, |
| 2590 | aom_highbd_12_jnt_sub_pixel_avg_variance64x16); |
| 2591 | |
| 2592 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 2593 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 2594 | aom_highbd_12_sub_pixel_variance16x64, |
| 2595 | aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2596 | aom_highbd_sad16x64x4d_bits12, |
| 2597 | aom_highbd_jnt_sad16x64_avg_bits12, |
| 2598 | aom_highbd_12_jnt_sub_pixel_avg_variance16x64); |
| 2599 | |
| 2600 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 2601 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 2602 | aom_highbd_12_sub_pixel_variance32x8, |
| 2603 | aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2604 | aom_highbd_sad32x8x4d_bits12, |
| 2605 | aom_highbd_jnt_sad32x8_avg_bits12, |
| 2606 | aom_highbd_12_jnt_sub_pixel_avg_variance32x8); |
| 2607 | |
| 2608 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 2609 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 2610 | aom_highbd_12_sub_pixel_variance8x32, |
| 2611 | aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2612 | aom_highbd_sad8x32x4d_bits12, |
| 2613 | aom_highbd_jnt_sad8x32_avg_bits12, |
| 2614 | aom_highbd_12_jnt_sub_pixel_avg_variance8x32); |
| 2615 | |
| 2616 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 2617 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 2618 | aom_highbd_12_sub_pixel_variance16x4, |
| 2619 | aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2620 | aom_highbd_sad16x4x4d_bits12, |
| 2621 | aom_highbd_jnt_sad16x4_avg_bits12, |
| 2622 | aom_highbd_12_jnt_sub_pixel_avg_variance16x4); |
| 2623 | |
| 2624 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 2625 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 2626 | aom_highbd_12_sub_pixel_variance4x16, |
| 2627 | aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2628 | aom_highbd_sad4x16x4d_bits12, |
| 2629 | aom_highbd_jnt_sad4x16_avg_bits12, |
| 2630 | aom_highbd_12_jnt_sub_pixel_avg_variance4x16); |
| 2631 | #endif |
| 2632 | |
| 2633 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 2634 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 2635 | aom_highbd_12_sub_pixel_variance32x16, |
| 2636 | aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2637 | aom_highbd_sad32x16x4d_bits12, |
| 2638 | aom_highbd_jnt_sad32x16_avg_bits12, |
| 2639 | aom_highbd_12_jnt_sub_pixel_avg_variance32x16); |
| 2640 | |
| 2641 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 2642 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 2643 | aom_highbd_12_sub_pixel_variance16x32, |
| 2644 | aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2645 | aom_highbd_sad16x32x4d_bits12, |
| 2646 | aom_highbd_jnt_sad16x32_avg_bits12, |
| 2647 | aom_highbd_12_jnt_sub_pixel_avg_variance16x32); |
| 2648 | |
| 2649 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 2650 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 2651 | aom_highbd_12_sub_pixel_variance64x32, |
| 2652 | aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2653 | aom_highbd_sad64x32x4d_bits12, |
| 2654 | aom_highbd_jnt_sad64x32_avg_bits12, |
| 2655 | aom_highbd_12_jnt_sub_pixel_avg_variance64x32); |
| 2656 | |
| 2657 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 2658 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 2659 | aom_highbd_12_sub_pixel_variance32x64, |
| 2660 | aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2661 | aom_highbd_sad32x64x4d_bits12, |
| 2662 | aom_highbd_jnt_sad32x64_avg_bits12, |
| 2663 | aom_highbd_12_jnt_sub_pixel_avg_variance32x64); |
| 2664 | |
| 2665 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 2666 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 2667 | aom_highbd_12_sub_pixel_variance32x32, |
| 2668 | aom_highbd_12_sub_pixel_avg_variance32x32, |
| 2669 | aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12, |
| 2670 | aom_highbd_sad32x32x4d_bits12, |
| 2671 | aom_highbd_jnt_sad32x32_avg_bits12, |
| 2672 | aom_highbd_12_jnt_sub_pixel_avg_variance32x32); |
| 2673 | |
| 2674 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2675 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2676 | aom_highbd_12_sub_pixel_variance64x64, |
| 2677 | aom_highbd_12_sub_pixel_avg_variance64x64, |
| 2678 | aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12, |
| 2679 | aom_highbd_sad64x64x4d_bits12, |
| 2680 | aom_highbd_jnt_sad64x64_avg_bits12, |
| 2681 | aom_highbd_12_jnt_sub_pixel_avg_variance64x64); |
| 2682 | |
| 2683 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2684 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2685 | aom_highbd_12_sub_pixel_variance16x16, |
| 2686 | aom_highbd_12_sub_pixel_avg_variance16x16, |
| 2687 | aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12, |
| 2688 | aom_highbd_sad16x16x4d_bits12, |
| 2689 | aom_highbd_jnt_sad16x16_avg_bits12, |
| 2690 | aom_highbd_12_jnt_sub_pixel_avg_variance16x16); |
| 2691 | |
| 2692 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2693 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2694 | aom_highbd_12_sub_pixel_variance16x8, |
| 2695 | aom_highbd_12_sub_pixel_avg_variance16x8, |
| 2696 | aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12, |
| 2697 | aom_highbd_sad16x8x4d_bits12, |
| 2698 | aom_highbd_jnt_sad16x8_avg_bits12, |
| 2699 | aom_highbd_12_jnt_sub_pixel_avg_variance16x8); |
| 2700 | |
| 2701 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2702 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2703 | aom_highbd_12_sub_pixel_variance8x16, |
| 2704 | aom_highbd_12_sub_pixel_avg_variance8x16, |
| 2705 | aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12, |
| 2706 | aom_highbd_sad8x16x4d_bits12, |
| 2707 | aom_highbd_jnt_sad8x16_avg_bits12, |
| 2708 | aom_highbd_12_jnt_sub_pixel_avg_variance8x16); |
| 2709 | |
| 2710 | HIGHBD_BFP( |
| 2711 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2712 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
| 2713 | aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12, |
| 2714 | aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12, |
| 2715 | aom_highbd_jnt_sad8x8_avg_bits12, |
| 2716 | aom_highbd_12_jnt_sub_pixel_avg_variance8x8); |
| 2717 | |
| 2718 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12, |
| 2719 | aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4, |
| 2720 | aom_highbd_12_sub_pixel_variance8x4, |
| 2721 | aom_highbd_12_sub_pixel_avg_variance8x4, NULL, |
| 2722 | aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12, |
| 2723 | aom_highbd_jnt_sad8x4_avg_bits12, |
| 2724 | aom_highbd_12_jnt_sub_pixel_avg_variance8x4); |
| 2725 | |
| 2726 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12, |
| 2727 | aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8, |
| 2728 | aom_highbd_12_sub_pixel_variance4x8, |
| 2729 | aom_highbd_12_sub_pixel_avg_variance4x8, NULL, |
| 2730 | aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12, |
| 2731 | aom_highbd_jnt_sad4x8_avg_bits12, |
| 2732 | aom_highbd_12_jnt_sub_pixel_avg_variance4x8); |
| 2733 | |
| 2734 | HIGHBD_BFP( |
| 2735 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2736 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
| 2737 | aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12, |
| 2738 | aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12, |
| 2739 | aom_highbd_jnt_sad4x4_avg_bits12, |
| 2740 | aom_highbd_12_jnt_sub_pixel_avg_variance4x4); |
| 2741 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2742 | #if CONFIG_EXT_PARTITION |
| 2743 | HIGHBD_BFP( |
| 2744 | BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2745 | aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128, |
| 2746 | aom_highbd_12_sub_pixel_variance128x128, |
| 2747 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2748 | aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12, |
| 2749 | aom_highbd_sad128x128x4d_bits12, |
| 2750 | aom_highbd_jnt_sad128x128_avg_bits12, |
| 2751 | aom_highbd_12_jnt_sub_pixel_avg_variance128x128); |
| 2752 | |
| 2753 | HIGHBD_BFP( |
| 2754 | BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2755 | aom_highbd_sad128x64_avg_bits12, aom_highbd_12_variance128x64, |
| 2756 | aom_highbd_12_sub_pixel_variance128x64, |
| 2757 | aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL, |
| 2758 | aom_highbd_sad128x64x4d_bits12, aom_highbd_jnt_sad128x64_avg_bits12, |
| 2759 | aom_highbd_12_jnt_sub_pixel_avg_variance128x64); |
| 2760 | |
| 2761 | HIGHBD_BFP( |
| 2762 | BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2763 | aom_highbd_sad64x128_avg_bits12, aom_highbd_12_variance64x128, |
| 2764 | aom_highbd_12_sub_pixel_variance64x128, |
| 2765 | aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL, |
| 2766 | aom_highbd_sad64x128x4d_bits12, aom_highbd_jnt_sad64x128_avg_bits12, |
| 2767 | aom_highbd_12_jnt_sub_pixel_avg_variance64x128); |
| 2768 | #endif // CONFIG_EXT_PARTITION |
| 2769 | #else // CONFIG_JNT_COMP |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2770 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2771 | #if CONFIG_EXT_PARTITION |
| 2772 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits12, |
| 2773 | aom_highbd_sad128x32_avg_bits12, |
| 2774 | aom_highbd_12_variance128x32, |
| 2775 | aom_highbd_12_sub_pixel_variance128x32, |
| 2776 | aom_highbd_12_sub_pixel_avg_variance128x32, NULL, NULL, |
| 2777 | aom_highbd_sad128x32x4d_bits12) |
| 2778 | |
| 2779 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits12, |
| 2780 | aom_highbd_sad32x128_avg_bits12, |
| 2781 | aom_highbd_12_variance32x128, |
| 2782 | aom_highbd_12_sub_pixel_variance32x128, |
| 2783 | aom_highbd_12_sub_pixel_avg_variance32x128, NULL, NULL, |
| 2784 | aom_highbd_sad32x128x4d_bits12) |
| 2785 | #endif // CONFIG_EXT_PARTITION |
| 2786 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2787 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 2788 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 2789 | aom_highbd_12_sub_pixel_variance64x16, |
| 2790 | aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2791 | aom_highbd_sad64x16x4d_bits12) |
| 2792 | |
| 2793 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 2794 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 2795 | aom_highbd_12_sub_pixel_variance16x64, |
| 2796 | aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2797 | aom_highbd_sad16x64x4d_bits12) |
| 2798 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2799 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 2800 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 2801 | aom_highbd_12_sub_pixel_variance32x8, |
| 2802 | aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2803 | aom_highbd_sad32x8x4d_bits12) |
| 2804 | |
| 2805 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 2806 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 2807 | aom_highbd_12_sub_pixel_variance8x32, |
| 2808 | aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2809 | aom_highbd_sad8x32x4d_bits12) |
| 2810 | |
| 2811 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 2812 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 2813 | aom_highbd_12_sub_pixel_variance16x4, |
| 2814 | aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2815 | aom_highbd_sad16x4x4d_bits12) |
| 2816 | |
| 2817 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 2818 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 2819 | aom_highbd_12_sub_pixel_variance4x16, |
| 2820 | aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2821 | aom_highbd_sad4x16x4d_bits12) |
| 2822 | #endif |
| 2823 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2824 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 2825 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 2826 | aom_highbd_12_sub_pixel_variance32x16, |
| 2827 | aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2828 | aom_highbd_sad32x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2829 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2830 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 2831 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 2832 | aom_highbd_12_sub_pixel_variance16x32, |
| 2833 | aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2834 | aom_highbd_sad16x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2835 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2836 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 2837 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 2838 | aom_highbd_12_sub_pixel_variance64x32, |
| 2839 | aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2840 | aom_highbd_sad64x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2841 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2842 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 2843 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 2844 | aom_highbd_12_sub_pixel_variance32x64, |
| 2845 | aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2846 | aom_highbd_sad32x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2847 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2848 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 2849 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 2850 | aom_highbd_12_sub_pixel_variance32x32, |
| 2851 | aom_highbd_12_sub_pixel_avg_variance32x32, |
| 2852 | aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12, |
| 2853 | aom_highbd_sad32x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2854 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2855 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2856 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2857 | aom_highbd_12_sub_pixel_variance64x64, |
| 2858 | aom_highbd_12_sub_pixel_avg_variance64x64, |
| 2859 | aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12, |
| 2860 | aom_highbd_sad64x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2861 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2862 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2863 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2864 | aom_highbd_12_sub_pixel_variance16x16, |
| 2865 | aom_highbd_12_sub_pixel_avg_variance16x16, |
| 2866 | aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12, |
| 2867 | aom_highbd_sad16x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2868 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2869 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2870 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2871 | aom_highbd_12_sub_pixel_variance16x8, |
| 2872 | aom_highbd_12_sub_pixel_avg_variance16x8, |
| 2873 | aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12, |
| 2874 | aom_highbd_sad16x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2875 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2876 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2877 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2878 | aom_highbd_12_sub_pixel_variance8x16, |
| 2879 | aom_highbd_12_sub_pixel_avg_variance8x16, |
| 2880 | aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12, |
| 2881 | aom_highbd_sad8x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2882 | |
| 2883 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2884 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2885 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
| 2886 | aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12, |
| 2887 | aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2888 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2889 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12, |
| 2890 | aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4, |
| 2891 | aom_highbd_12_sub_pixel_variance8x4, |
| 2892 | aom_highbd_12_sub_pixel_avg_variance8x4, NULL, |
| 2893 | aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2894 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2895 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12, |
| 2896 | aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8, |
| 2897 | aom_highbd_12_sub_pixel_variance4x8, |
| 2898 | aom_highbd_12_sub_pixel_avg_variance4x8, NULL, |
| 2899 | aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2900 | |
| 2901 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2902 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2903 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
| 2904 | aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12, |
| 2905 | aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2906 | |
| 2907 | #if CONFIG_EXT_PARTITION |
| 2908 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2909 | BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2910 | aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128, |
| 2911 | aom_highbd_12_sub_pixel_variance128x128, |
| 2912 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2913 | aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12, |
| 2914 | aom_highbd_sad128x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2915 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2916 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2917 | aom_highbd_sad128x64_avg_bits12, |
| 2918 | aom_highbd_12_variance128x64, |
| 2919 | aom_highbd_12_sub_pixel_variance128x64, |
| 2920 | aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL, |
| 2921 | aom_highbd_sad128x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2922 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2923 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2924 | aom_highbd_sad64x128_avg_bits12, |
| 2925 | aom_highbd_12_variance64x128, |
| 2926 | aom_highbd_12_sub_pixel_variance64x128, |
| 2927 | aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL, |
| 2928 | aom_highbd_sad64x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2929 | #endif // CONFIG_EXT_PARTITION |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 2930 | #endif // CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2931 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2932 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2933 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2934 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2935 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2936 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2937 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2938 | aom_highbd_12_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2939 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2940 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2941 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2942 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2943 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2944 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2945 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2946 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2947 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2948 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2949 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2950 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2951 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2952 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2953 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2954 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2955 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2956 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2957 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2958 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2959 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2960 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2961 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2962 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2963 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2964 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2965 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2966 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2967 | #if CONFIG_EXT_PARTITION |
| 2968 | HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits12, |
| 2969 | aom_highbd_12_masked_sub_pixel_variance128x32) |
| 2970 | |
| 2971 | HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits12, |
| 2972 | aom_highbd_12_masked_sub_pixel_variance32x128) |
| 2973 | #endif // CONFIG_EXT_PARTITION |
| 2974 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2975 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2976 | aom_highbd_12_masked_sub_pixel_variance64x16) |
| 2977 | |
| 2978 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2979 | aom_highbd_12_masked_sub_pixel_variance16x64) |
| 2980 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2981 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2982 | aom_highbd_12_masked_sub_pixel_variance32x8) |
| 2983 | |
| 2984 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2985 | aom_highbd_12_masked_sub_pixel_variance8x32) |
| 2986 | |
| 2987 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2988 | aom_highbd_12_masked_sub_pixel_variance16x4) |
| 2989 | |
| 2990 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2991 | aom_highbd_12_masked_sub_pixel_variance4x16) |
| 2992 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2993 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2994 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2995 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2996 | aom_highbd_12_obmc_variance128x128, |
| 2997 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2998 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2999 | aom_highbd_12_obmc_variance128x64, |
| 3000 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 3001 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 3002 | aom_highbd_12_obmc_variance64x128, |
| 3003 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3004 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3005 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 3006 | aom_highbd_12_obmc_variance64x64, |
| 3007 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 3008 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 3009 | aom_highbd_12_obmc_variance64x32, |
| 3010 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 3011 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 3012 | aom_highbd_12_obmc_variance32x64, |
| 3013 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 3014 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 3015 | aom_highbd_12_obmc_variance32x32, |
| 3016 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 3017 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 3018 | aom_highbd_12_obmc_variance32x16, |
| 3019 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 3020 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 3021 | aom_highbd_12_obmc_variance16x32, |
| 3022 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 3023 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 3024 | aom_highbd_12_obmc_variance16x16, |
| 3025 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 3026 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 3027 | aom_highbd_12_obmc_variance8x16, |
| 3028 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 3029 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 3030 | aom_highbd_12_obmc_variance16x8, |
| 3031 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 3032 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 3033 | aom_highbd_12_obmc_variance8x8, |
| 3034 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 3035 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 3036 | aom_highbd_12_obmc_variance4x8, |
| 3037 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 3038 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 3039 | aom_highbd_12_obmc_variance8x4, |
| 3040 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 3041 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 3042 | aom_highbd_12_obmc_variance4x4, |
| 3043 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3044 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 3045 | #if CONFIG_EXT_PARTITION |
| 3046 | HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits12, |
| 3047 | aom_highbd_12_obmc_variance128x32, |
| 3048 | aom_highbd_12_obmc_sub_pixel_variance128x32) |
| 3049 | |
| 3050 | HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits12, |
| 3051 | aom_highbd_12_obmc_variance32x128, |
| 3052 | aom_highbd_12_obmc_sub_pixel_variance32x128) |
| 3053 | #endif // CONFIG_EXT_PARTITION |
| 3054 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3055 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 3056 | aom_highbd_12_obmc_variance64x16, |
| 3057 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
| 3058 | |
| 3059 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 3060 | aom_highbd_12_obmc_variance16x64, |
| 3061 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
| 3062 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3063 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 3064 | aom_highbd_12_obmc_variance32x8, |
| 3065 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
| 3066 | |
| 3067 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 3068 | aom_highbd_12_obmc_variance8x32, |
| 3069 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
| 3070 | |
| 3071 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 3072 | aom_highbd_12_obmc_variance16x4, |
| 3073 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
| 3074 | |
| 3075 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 3076 | aom_highbd_12_obmc_variance4x16, |
| 3077 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
| 3078 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3079 | break; |
| 3080 | |
| 3081 | default: |
| 3082 | assert(0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3083 | "cm->bit_depth should be AOM_BITS_8, " |
| 3084 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3085 | } |
| 3086 | } |
| 3087 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3088 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3089 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 3090 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3091 | |
| 3092 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3093 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3094 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3095 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3096 | |
| 3097 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3098 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3099 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3100 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3101 | |
| 3102 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3103 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3104 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3105 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3106 | } |
| 3107 | |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3108 | void set_compound_tools(AV1_COMMON *cm) { |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3109 | cm->allow_interintra_compound = 1; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3110 | cm->allow_masked_compound = 1; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3111 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3112 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3113 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 3114 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3115 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3116 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3117 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3118 | |
| 3119 | if (cm->profile != oxcf->profile) cm->profile = oxcf->profile; |
| 3120 | cm->bit_depth = oxcf->bit_depth; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 3121 | #if CONFIG_CICP |
| 3122 | cm->color_primaries = oxcf->color_primaries; |
| 3123 | cm->transfer_characteristics = oxcf->transfer_characteristics; |
| 3124 | cm->matrix_coefficients = oxcf->matrix_coefficients; |
| 3125 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3126 | cm->color_space = oxcf->color_space; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 3127 | #endif |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 3128 | #if CONFIG_MONO_VIDEO |
| 3129 | cm->seq_params.monochrome = oxcf->monochrome; |
| 3130 | #endif // CONFIG_MONO_VIDEO |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 3131 | #if CONFIG_COLORSPACE_HEADERS |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 3132 | #if !CONFIG_CICP |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 3133 | cm->transfer_function = oxcf->transfer_function; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 3134 | #endif |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 3135 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
| 3136 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3137 | cm->color_range = oxcf->color_range; |
| 3138 | |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 3139 | assert(IMPLIES(cm->profile <= PROFILE_1, cm->bit_depth <= AOM_BITS_10)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3140 | |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 3141 | #if CONFIG_TIMING_INFO_IN_SEQ_HEADERS |
| 3142 | cm->timing_info_present = oxcf->timing_info_present; |
| 3143 | cm->num_units_in_tick = oxcf->num_units_in_tick; |
| 3144 | cm->time_scale = oxcf->time_scale; |
| 3145 | cm->equal_picture_interval = oxcf->equal_picture_interval; |
| 3146 | cm->num_ticks_per_picture = oxcf->num_ticks_per_picture; |
| 3147 | #endif |
| 3148 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3149 | #if CONFIG_FILM_GRAIN |
| 3150 | update_film_grain_parameters(cpi, oxcf); |
| 3151 | #endif |
| 3152 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3153 | cpi->oxcf = *oxcf; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 3154 | cpi->common.options = oxcf->cfg; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3155 | x->e_mbd.bd = (int)cm->bit_depth; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3156 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3157 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3158 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3159 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 3160 | } else { |
| 3161 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 3162 | } |
| 3163 | |
| 3164 | cpi->refresh_last_frame = 1; |
| 3165 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3166 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3167 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3168 | |
| 3169 | cm->refresh_frame_context = |
| 3170 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 3171 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 3172 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 3173 | #if CONFIG_EXT_TILE |
| 3174 | if (oxcf->large_scale_tile) |
| 3175 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 3176 | #endif // CONFIG_EXT_TILE |
| 3177 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 3178 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3179 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 3180 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3181 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 3182 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3183 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 3184 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 3185 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3186 | set_compound_tools(cm); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3187 | av1_reset_segment_features(cm); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3188 | #if CONFIG_AMVR |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 3189 | set_high_precision_mv(cpi, 1, 0); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3190 | #else |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 3191 | set_high_precision_mv(cpi, 1); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3192 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3193 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3194 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 3195 | |
| 3196 | // Under a configuration change, where maximum_buffer_size may change, |
| 3197 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3198 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 3199 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3200 | |
| 3201 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3202 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3203 | |
| 3204 | // Set absolute upper and lower quality limits |
| 3205 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 3206 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 3207 | |
Yunqing Wang | b6e23bc | 2017-11-15 13:18:55 -0800 | [diff] [blame] | 3208 | #if CONFIG_EXT_TILE |
| 3209 | if (!oxcf->large_scale_tile) |
| 3210 | #endif // CONFIG_EXT_TILE |
| 3211 | cm->interp_filter = cpi->sf.default_interp_filter; |
| 3212 | #if CONFIG_EXT_TILE |
| 3213 | else |
| 3214 | cm->interp_filter = EIGHTTAP_REGULAR; |
| 3215 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3216 | |
| 3217 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 3218 | cm->render_width = cpi->oxcf.render_width; |
| 3219 | cm->render_height = cpi->oxcf.render_height; |
| 3220 | } else { |
| 3221 | cm->render_width = cpi->oxcf.width; |
| 3222 | cm->render_height = cpi->oxcf.height; |
| 3223 | } |
| 3224 | cm->width = cpi->oxcf.width; |
| 3225 | cm->height = cpi->oxcf.height; |
| 3226 | |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 3227 | int sb_size = cm->seq_params.sb_size; |
| 3228 | set_sb_size(&cm->seq_params, select_sb_size(cpi)); |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 3229 | |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 3230 | if (cpi->initial_width || sb_size != cm->seq_params.sb_size) { |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 3231 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height || |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 3232 | cm->seq_params.sb_size != sb_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3233 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3234 | av1_free_pc_tree(&cpi->td, num_planes); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3235 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3236 | realloc_segmentation_maps(cpi); |
| 3237 | cpi->initial_width = cpi->initial_height = 0; |
| 3238 | } |
| 3239 | } |
| 3240 | update_frame_size(cpi); |
| 3241 | |
| 3242 | cpi->alt_ref_source = NULL; |
| 3243 | rc->is_src_frame_alt_ref = 0; |
| 3244 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3245 | rc->is_bwd_ref_frame = 0; |
| 3246 | rc->is_last_bipred_frame = 0; |
| 3247 | rc->is_bipred_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3248 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3249 | set_tile_info(cpi); |
| 3250 | |
| 3251 | cpi->ext_refresh_frame_flags_pending = 0; |
| 3252 | cpi->ext_refresh_frame_context_pending = 0; |
| 3253 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3254 | highbd_set_var_fns(cpi); |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 3255 | |
| 3256 | cm->seq_params.force_screen_content_tools = 2; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3257 | #if CONFIG_AMVR |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 3258 | cm->seq_params.force_integer_mv = 2; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3259 | #endif |
Joe Young | db5eb4c | 2018-02-16 17:30:40 -0800 | [diff] [blame] | 3260 | #if CONFIG_INTRA_EDGE2 |
| 3261 | cm->disable_intra_edge_filter = 0; |
| 3262 | #endif // CONFIG_INTRA_EDGE2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3265 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 3266 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3267 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3268 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 3269 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3270 | |
| 3271 | if (!cm) return NULL; |
| 3272 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3273 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3274 | |
| 3275 | if (setjmp(cm->error.jmp)) { |
| 3276 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3277 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3278 | return 0; |
| 3279 | } |
| 3280 | |
| 3281 | cm->error.setjmp = 1; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3282 | cm->alloc_mi = enc_alloc_mi; |
| 3283 | cm->free_mi = enc_free_mi; |
| 3284 | cm->setup_mi = enc_setup_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3285 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 3286 | CHECK_MEM_ERROR(cm, cm->fc, |
| 3287 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
| 3288 | CHECK_MEM_ERROR(cm, cm->frame_contexts, |
| 3289 | (FRAME_CONTEXT *)aom_memalign( |
| 3290 | 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts))); |
| 3291 | memset(cm->fc, 0, sizeof(*cm->fc)); |
| 3292 | memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3293 | |
| 3294 | cpi->resize_state = 0; |
| 3295 | cpi->resize_avg_qp = 0; |
| 3296 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 3297 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3298 | cpi->common.buffer_pool = pool; |
| 3299 | |
| 3300 | init_config(cpi, oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3301 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3302 | |
| 3303 | cm->current_video_frame = 0; |
| 3304 | cpi->partition_search_skippable_frame = 0; |
| 3305 | cpi->tile_data = NULL; |
| 3306 | cpi->last_show_frame_buf_idx = INVALID_IDX; |
| 3307 | |
| 3308 | realloc_segmentation_maps(cpi); |
| 3309 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3310 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 3311 | memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs)); |
| 3312 | memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp)); |
| 3313 | } |
| 3314 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3315 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 3316 | i++) { |
| 3317 | CHECK_MEM_ERROR( |
| 3318 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3319 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | #if CONFIG_FP_MB_STATS |
| 3323 | cpi->use_fp_mb_stats = 0; |
| 3324 | if (cpi->use_fp_mb_stats) { |
| 3325 | // a place holder used to store the first pass mb stats in the first pass |
| 3326 | CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3327 | aom_calloc(cm->MBs * sizeof(uint8_t), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3328 | } else { |
| 3329 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 3330 | } |
| 3331 | #endif |
| 3332 | |
| 3333 | cpi->refresh_alt_ref_frame = 0; |
| 3334 | cpi->multi_arf_last_grp_enabled = 0; |
| 3335 | |
| 3336 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 3337 | #if CONFIG_INTERNAL_STATS |
| 3338 | cpi->b_calculate_blockiness = 1; |
| 3339 | cpi->b_calculate_consistency = 1; |
| 3340 | cpi->total_inconsistency = 0; |
| 3341 | cpi->psnr.worst = 100.0; |
| 3342 | cpi->worst_ssim = 100.0; |
| 3343 | |
| 3344 | cpi->count = 0; |
| 3345 | cpi->bytes = 0; |
| 3346 | |
| 3347 | if (cpi->b_calculate_psnr) { |
| 3348 | cpi->total_sq_error = 0; |
| 3349 | cpi->total_samples = 0; |
| 3350 | cpi->tot_recode_hits = 0; |
| 3351 | cpi->summed_quality = 0; |
| 3352 | cpi->summed_weights = 0; |
| 3353 | } |
| 3354 | |
| 3355 | cpi->fastssim.worst = 100.0; |
| 3356 | cpi->psnrhvs.worst = 100.0; |
| 3357 | |
| 3358 | if (cpi->b_calculate_blockiness) { |
| 3359 | cpi->total_blockiness = 0; |
| 3360 | cpi->worst_blockiness = 0.0; |
| 3361 | } |
| 3362 | |
| 3363 | if (cpi->b_calculate_consistency) { |
| 3364 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3365 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3366 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 3367 | cpi->worst_consistency = 100.0; |
| 3368 | } |
| 3369 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3370 | #if CONFIG_ENTROPY_STATS |
| 3371 | av1_zero(aggregate_fc); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 3372 | av1_zero_array(aggregate_fc_per_type, FRAME_CONTEXTS); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3373 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3374 | |
| 3375 | cpi->first_time_stamp_ever = INT64_MAX; |
| 3376 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3377 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 3378 | cpi->td.mb.nmvcost[i][0] = &cpi->nmv_costs[i][0][MV_MAX]; |
| 3379 | cpi->td.mb.nmvcost[i][1] = &cpi->nmv_costs[i][1][MV_MAX]; |
| 3380 | cpi->td.mb.nmvcost_hp[i][0] = &cpi->nmv_costs_hp[i][0][MV_MAX]; |
| 3381 | cpi->td.mb.nmvcost_hp[i][1] = &cpi->nmv_costs_hp[i][1][MV_MAX]; |
| 3382 | } |
| 3383 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3384 | #ifdef OUTPUT_YUV_SKINMAP |
| 3385 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 3386 | #endif |
| 3387 | #ifdef OUTPUT_YUV_REC |
| 3388 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 3389 | #endif |
| 3390 | |
| 3391 | #if 0 |
| 3392 | framepsnr = fopen("framepsnr.stt", "a"); |
| 3393 | kf_list = fopen("kf_list.stt", "w"); |
| 3394 | #endif |
| 3395 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3396 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3397 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3398 | } else if (oxcf->pass == 2) { |
| 3399 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 3400 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 3401 | |
| 3402 | #if CONFIG_FP_MB_STATS |
| 3403 | if (cpi->use_fp_mb_stats) { |
| 3404 | const size_t psz = cpi->common.MBs * sizeof(uint8_t); |
| 3405 | const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz); |
| 3406 | |
| 3407 | cpi->twopass.firstpass_mb_stats.mb_stats_start = |
| 3408 | oxcf->firstpass_mb_stats_in.buf; |
| 3409 | cpi->twopass.firstpass_mb_stats.mb_stats_end = |
| 3410 | cpi->twopass.firstpass_mb_stats.mb_stats_start + |
| 3411 | (ps - 1) * cpi->common.MBs * sizeof(uint8_t); |
| 3412 | } |
| 3413 | #endif |
| 3414 | |
| 3415 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 3416 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 3417 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 3418 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3419 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3420 | } |
| 3421 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3422 | int buf_scaler = 2; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3423 | CHECK_MEM_ERROR( |
| 3424 | cm, cpi->td.mb.above_pred_buf, |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 3425 | (uint8_t *)aom_memalign(16, buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 3426 | sizeof(*cpi->td.mb.above_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3427 | CHECK_MEM_ERROR( |
| 3428 | cm, cpi->td.mb.left_pred_buf, |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 3429 | (uint8_t *)aom_memalign(16, buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 3430 | sizeof(*cpi->td.mb.left_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3431 | |
| 3432 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 3433 | (int32_t *)aom_memalign( |
| 3434 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 3435 | |
| 3436 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 3437 | (int32_t *)aom_memalign( |
| 3438 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 3439 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3440 | av1_set_speed_features_framesize_independent(cpi); |
| 3441 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3442 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3443 | #if CONFIG_JNT_COMP |
| 3444 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF, JSDAF, JSVAF) \ |
| 3445 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 3446 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 3447 | cpi->fn_ptr[BT].vf = VF; \ |
| 3448 | cpi->fn_ptr[BT].svf = SVF; \ |
| 3449 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 3450 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 3451 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 3452 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 3453 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
| 3454 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
| 3455 | #else // CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3456 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 3457 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 3458 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 3459 | cpi->fn_ptr[BT].vf = VF; \ |
| 3460 | cpi->fn_ptr[BT].svf = SVF; \ |
| 3461 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 3462 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 3463 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 3464 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3465 | #endif // CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3466 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3467 | #if CONFIG_JNT_COMP |
| 3468 | #if CONFIG_EXT_PARTITION_TYPES |
| 3469 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
| 3470 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3471 | aom_sad4x16x4d, aom_jnt_sad4x16_avg, aom_jnt_sub_pixel_avg_variance4x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3472 | |
| 3473 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
| 3474 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3475 | aom_sad16x4x4d, aom_jnt_sad16x4_avg, aom_jnt_sub_pixel_avg_variance16x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3476 | |
| 3477 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
| 3478 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3479 | aom_sad8x32x4d, aom_jnt_sad8x32_avg, aom_jnt_sub_pixel_avg_variance8x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3480 | |
| 3481 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
| 3482 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3483 | aom_sad32x8x4d, aom_jnt_sad32x8_avg, aom_jnt_sub_pixel_avg_variance32x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3484 | |
| 3485 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
| 3486 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3487 | aom_sad16x64x4d, aom_jnt_sad16x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3488 | aom_jnt_sub_pixel_avg_variance16x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3489 | |
| 3490 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
| 3491 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3492 | aom_sad64x16x4d, aom_jnt_sad64x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3493 | aom_jnt_sub_pixel_avg_variance64x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3494 | |
| 3495 | #if CONFIG_EXT_PARTITION |
| 3496 | BFP(BLOCK_32X128, aom_sad32x128, aom_sad32x128_avg, aom_variance32x128, |
| 3497 | aom_sub_pixel_variance32x128, aom_sub_pixel_avg_variance32x128, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3498 | NULL, aom_sad32x128x4d, aom_jnt_sad32x128_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3499 | aom_jnt_sub_pixel_avg_variance32x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3500 | |
| 3501 | BFP(BLOCK_128X32, aom_sad128x32, aom_sad128x32_avg, aom_variance128x32, |
| 3502 | aom_sub_pixel_variance128x32, aom_sub_pixel_avg_variance128x32, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3503 | NULL, aom_sad128x32x4d, aom_jnt_sad128x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3504 | aom_jnt_sub_pixel_avg_variance128x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3505 | #endif // CONFIG_EXT_PARTITION |
| 3506 | #endif // CONFIG_EXT_PARTITION_TYPES |
| 3507 | |
| 3508 | #if CONFIG_EXT_PARTITION |
| 3509 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 3510 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
| 3511 | aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3512 | aom_jnt_sad128x128_avg, aom_jnt_sub_pixel_avg_variance128x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3513 | |
| 3514 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
| 3515 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3516 | NULL, aom_sad128x64x4d, aom_jnt_sad128x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3517 | aom_jnt_sub_pixel_avg_variance128x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3518 | |
| 3519 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
| 3520 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3521 | NULL, aom_sad64x128x4d, aom_jnt_sad64x128_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3522 | aom_jnt_sub_pixel_avg_variance64x128) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3523 | #endif // CONFIG_EXT_PARTITION |
| 3524 | |
| 3525 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
| 3526 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3527 | aom_sad32x16x4d, aom_jnt_sad32x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3528 | aom_jnt_sub_pixel_avg_variance32x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3529 | |
| 3530 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
| 3531 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3532 | aom_sad16x32x4d, aom_jnt_sad16x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3533 | aom_jnt_sub_pixel_avg_variance16x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3534 | |
| 3535 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
| 3536 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3537 | aom_sad64x32x4d, aom_jnt_sad64x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3538 | aom_jnt_sub_pixel_avg_variance64x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3539 | |
| 3540 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
| 3541 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3542 | aom_sad32x64x4d, aom_jnt_sad32x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3543 | aom_jnt_sub_pixel_avg_variance32x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3544 | |
| 3545 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 3546 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3547 | aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d, aom_jnt_sad32x32_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3548 | aom_jnt_sub_pixel_avg_variance32x32) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3549 | |
| 3550 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 3551 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3552 | aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d, aom_jnt_sad64x64_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3553 | aom_jnt_sub_pixel_avg_variance64x64) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3554 | |
| 3555 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 3556 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3557 | aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d, aom_jnt_sad16x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3558 | aom_jnt_sub_pixel_avg_variance16x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3559 | |
| 3560 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
| 3561 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3562 | aom_sad16x8x8, aom_sad16x8x4d, aom_jnt_sad16x8_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3563 | aom_jnt_sub_pixel_avg_variance16x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3564 | |
| 3565 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
| 3566 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3567 | aom_sad8x16x8, aom_sad8x16x4d, aom_jnt_sad8x16_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3568 | aom_jnt_sub_pixel_avg_variance8x16) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3569 | |
| 3570 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
| 3571 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3572 | aom_sad8x8x8, aom_sad8x8x4d, aom_jnt_sad8x8_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3573 | aom_jnt_sub_pixel_avg_variance8x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3574 | |
| 3575 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
| 3576 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3577 | aom_sad8x4x8, aom_sad8x4x4d, aom_jnt_sad8x4_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3578 | aom_jnt_sub_pixel_avg_variance8x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3579 | |
| 3580 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
| 3581 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3582 | aom_sad4x8x8, aom_sad4x8x4d, aom_jnt_sad4x8_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3583 | aom_jnt_sub_pixel_avg_variance4x8) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3584 | |
| 3585 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
| 3586 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3, |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 3587 | aom_sad4x4x8, aom_sad4x4x4d, aom_jnt_sad4x4_avg, |
Cheng Chen | d286443 | 2017-11-17 17:59:24 -0800 | [diff] [blame] | 3588 | aom_jnt_sub_pixel_avg_variance4x4) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3589 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3590 | #else // CONFIG_JNT_COMP |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3591 | #if CONFIG_EXT_PARTITION_TYPES |
| 3592 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
| 3593 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL, |
| 3594 | aom_sad4x16x4d) |
| 3595 | |
| 3596 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
| 3597 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL, |
| 3598 | aom_sad16x4x4d) |
| 3599 | |
| 3600 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
| 3601 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL, |
| 3602 | aom_sad8x32x4d) |
| 3603 | |
| 3604 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
| 3605 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL, |
| 3606 | aom_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3607 | |
| 3608 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
| 3609 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL, |
| 3610 | aom_sad16x64x4d) |
| 3611 | |
| 3612 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
| 3613 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL, |
| 3614 | aom_sad64x16x4d) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 3615 | |
| 3616 | #if CONFIG_EXT_PARTITION |
| 3617 | BFP(BLOCK_32X128, aom_sad32x128, aom_sad32x128_avg, aom_variance32x128, |
| 3618 | aom_sub_pixel_variance32x128, aom_sub_pixel_avg_variance32x128, NULL, |
| 3619 | NULL, aom_sad32x128x4d) |
| 3620 | |
| 3621 | BFP(BLOCK_128X32, aom_sad128x32, aom_sad128x32_avg, aom_variance128x32, |
| 3622 | aom_sub_pixel_variance128x32, aom_sub_pixel_avg_variance128x32, NULL, |
| 3623 | NULL, aom_sad128x32x4d) |
| 3624 | #endif // CONFIG_EXT_PARTITION |
| 3625 | #endif // CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3626 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3627 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3628 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 3629 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
| 3630 | aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3631 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3632 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
| 3633 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL, |
| 3634 | NULL, aom_sad128x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3635 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3636 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
| 3637 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL, |
| 3638 | NULL, aom_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3639 | #endif // CONFIG_EXT_PARTITION |
| 3640 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3641 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
| 3642 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL, |
| 3643 | aom_sad32x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3644 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3645 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
| 3646 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL, |
| 3647 | aom_sad16x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3648 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3649 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
| 3650 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL, |
| 3651 | aom_sad64x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3652 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3653 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
| 3654 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL, |
| 3655 | aom_sad32x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3656 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3657 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 3658 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
| 3659 | aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3660 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3661 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 3662 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
| 3663 | aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3664 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3665 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 3666 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
| 3667 | aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3668 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3669 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
| 3670 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3, |
| 3671 | aom_sad16x8x8, aom_sad16x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3672 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3673 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
| 3674 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3, |
| 3675 | aom_sad8x16x8, aom_sad8x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3676 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3677 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
| 3678 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3, |
| 3679 | aom_sad8x8x8, aom_sad8x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3680 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3681 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
| 3682 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL, |
| 3683 | aom_sad8x4x8, aom_sad8x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3684 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3685 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
| 3686 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL, |
| 3687 | aom_sad4x8x8, aom_sad4x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3688 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3689 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
| 3690 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3, |
| 3691 | aom_sad4x4x8, aom_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3692 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3693 | #endif // CONFIG_JNT_COMP |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 3694 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3695 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 3696 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 3697 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 3698 | cpi->fn_ptr[BT].osvf = OSVF; |
| 3699 | |
| 3700 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3701 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 3702 | aom_obmc_sub_pixel_variance128x128) |
| 3703 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 3704 | aom_obmc_sub_pixel_variance128x64) |
| 3705 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 3706 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3707 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3708 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 3709 | aom_obmc_sub_pixel_variance64x64) |
| 3710 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 3711 | aom_obmc_sub_pixel_variance64x32) |
| 3712 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 3713 | aom_obmc_sub_pixel_variance32x64) |
| 3714 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 3715 | aom_obmc_sub_pixel_variance32x32) |
| 3716 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 3717 | aom_obmc_sub_pixel_variance32x16) |
| 3718 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 3719 | aom_obmc_sub_pixel_variance16x32) |
| 3720 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 3721 | aom_obmc_sub_pixel_variance16x16) |
| 3722 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 3723 | aom_obmc_sub_pixel_variance16x8) |
| 3724 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 3725 | aom_obmc_sub_pixel_variance8x16) |
| 3726 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 3727 | aom_obmc_sub_pixel_variance8x8) |
| 3728 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 3729 | aom_obmc_sub_pixel_variance4x8) |
| 3730 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 3731 | aom_obmc_sub_pixel_variance8x4) |
| 3732 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 3733 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3734 | |
| 3735 | #if CONFIG_EXT_PARTITION_TYPES |
| 3736 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 3737 | aom_obmc_sub_pixel_variance4x16) |
| 3738 | |
| 3739 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 3740 | aom_obmc_sub_pixel_variance16x4) |
| 3741 | |
| 3742 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 3743 | aom_obmc_sub_pixel_variance8x32) |
| 3744 | |
| 3745 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 3746 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3747 | |
| 3748 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 3749 | aom_obmc_sub_pixel_variance16x64) |
| 3750 | |
| 3751 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 3752 | aom_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 3753 | |
| 3754 | #if CONFIG_EXT_PARTITION |
| 3755 | OBFP(BLOCK_32X128, aom_obmc_sad32x128, aom_obmc_variance32x128, |
| 3756 | aom_obmc_sub_pixel_variance32x128) |
| 3757 | |
| 3758 | OBFP(BLOCK_128X32, aom_obmc_sad128x32, aom_obmc_variance128x32, |
| 3759 | aom_obmc_sub_pixel_variance128x32) |
| 3760 | #endif // CONFIG_EXT_PARTITION |
| 3761 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3762 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3763 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 3764 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 3765 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3766 | |
| 3767 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3768 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 3769 | aom_masked_sub_pixel_variance128x128) |
| 3770 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 3771 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3772 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3773 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 3774 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 3775 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 3776 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 3777 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 3778 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 3779 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 3780 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 3781 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 3782 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 3783 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 3784 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 3785 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3786 | |
| 3787 | #if CONFIG_EXT_PARTITION_TYPES |
| 3788 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 3789 | |
| 3790 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 3791 | |
| 3792 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 3793 | |
| 3794 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3795 | |
| 3796 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 3797 | |
| 3798 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 3799 | |
| 3800 | #if CONFIG_EXT_PARTITION |
| 3801 | MBFP(BLOCK_32X128, aom_masked_sad32x128, aom_masked_sub_pixel_variance32x128) |
| 3802 | |
| 3803 | MBFP(BLOCK_128X32, aom_masked_sad128x32, aom_masked_sub_pixel_variance128x32) |
| 3804 | #endif // CONFIG_EXT_PARTITION |
| 3805 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3806 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3807 | highbd_set_var_fns(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3808 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3809 | /* av1_init_quantizer() is first called here. Add check in |
| 3810 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3811 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3812 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3813 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3814 | av1_init_quantizer(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3815 | #if CONFIG_AOM_QM |
Zoe Liu | d902b74 | 2018-02-19 17:02:41 -0800 | [diff] [blame] | 3816 | av1_qm_init(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3817 | #endif |
| 3818 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3819 | av1_loop_filter_init(cm); |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 3820 | #if CONFIG_HORZONLY_FRAME_SUPERRES |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3821 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 3822 | cm->superres_upscaled_width = oxcf->width; |
| 3823 | cm->superres_upscaled_height = oxcf->height; |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 3824 | #endif // CONFIG_HORZONLY_FRAME_SUPERRES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3825 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3826 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3827 | #endif // CONFIG_LOOP_RESTORATION |
| 3828 | |
| 3829 | cm->error.setjmp = 0; |
| 3830 | |
| 3831 | return cpi; |
| 3832 | } |
| 3833 | |
| 3834 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 3835 | |
| 3836 | #define SNPRINT2(H, T, V) \ |
| 3837 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
| 3838 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3839 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 3840 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3841 | unsigned int i; |
| 3842 | int t; |
| 3843 | |
| 3844 | if (!cpi) return; |
| 3845 | |
| 3846 | cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3847 | const int num_planes = av1_num_planes(cm); |
| 3848 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3849 | if (cm->current_video_frame > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3850 | #if CONFIG_ENTROPY_STATS |
| 3851 | if (cpi->oxcf.pass != 1) { |
| 3852 | fprintf(stderr, "Writing counts.stt\n"); |
| 3853 | FILE *f = fopen("counts.stt", "wb"); |
| 3854 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 3855 | fwrite(aggregate_fc_per_type, sizeof(aggregate_fc_per_type[0]), |
| 3856 | FRAME_CONTEXTS, f); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3857 | fclose(f); |
| 3858 | } |
| 3859 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3860 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3861 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3862 | |
| 3863 | if (cpi->oxcf.pass != 1) { |
| 3864 | char headings[512] = { 0 }; |
| 3865 | char results[512] = { 0 }; |
| 3866 | FILE *f = fopen("opsnr.stt", "a"); |
| 3867 | double time_encoded = |
| 3868 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 3869 | 10000000.000; |
| 3870 | double total_encode_time = |
| 3871 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 3872 | const double dr = |
| 3873 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 3874 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 3875 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 3876 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 3877 | |
| 3878 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3879 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3880 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 3881 | const double total_ssim = |
| 3882 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 3883 | snprintf(headings, sizeof(headings), |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3884 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3885 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3886 | "WstPsnr\tWstSsim\tWstFast\tWstHVS\t" |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3887 | "AVPsrnY\tAPsnrCb\tAPsnrCr"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3888 | snprintf(results, sizeof(results), |
| 3889 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 3890 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3891 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3892 | "%7.3f\t%7.3f\t%7.3f", |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3893 | dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr, |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3894 | cpi->psnr.stat[ALL] / cpi->count, total_psnr, total_ssim, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3895 | total_ssim, cpi->fastssim.stat[ALL] / cpi->count, |
| 3896 | cpi->psnrhvs.stat[ALL] / cpi->count, cpi->psnr.worst, |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3897 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst, |
Jingning Han | 87651b2 | 2017-11-28 20:02:26 -0800 | [diff] [blame] | 3898 | cpi->psnr.stat[Y] / cpi->count, cpi->psnr.stat[U] / cpi->count, |
Jingning Han | be1ae3f | 2017-11-27 10:27:56 -0800 | [diff] [blame] | 3899 | cpi->psnr.stat[V] / cpi->count); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3900 | |
| 3901 | if (cpi->b_calculate_blockiness) { |
| 3902 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 3903 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 3904 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 3905 | } |
| 3906 | |
| 3907 | if (cpi->b_calculate_consistency) { |
| 3908 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3909 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3910 | (double)cpi->total_inconsistency); |
| 3911 | |
| 3912 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 3913 | SNPRINT2(results, "\t%7.3f", consistency); |
| 3914 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 3915 | } |
Sarah Parker | f97b786 | 2016-08-25 17:42:57 -0700 | [diff] [blame] | 3916 | fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings); |
| 3917 | 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] | 3918 | rate_err, fabs(rate_err)); |
| 3919 | } |
| 3920 | |
| 3921 | fclose(f); |
| 3922 | } |
| 3923 | |
| 3924 | #endif |
| 3925 | |
| 3926 | #if 0 |
| 3927 | { |
| 3928 | printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); |
| 3929 | printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); |
| 3930 | printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, |
| 3931 | cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, |
| 3932 | cpi->time_compress_data / 1000, |
| 3933 | (cpi->time_receive_data + cpi->time_compress_data) / 1000); |
| 3934 | } |
| 3935 | #endif |
| 3936 | } |
| 3937 | |
| 3938 | for (t = 0; t < cpi->num_workers; ++t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3939 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3940 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 3941 | |
| 3942 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3943 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3944 | |
| 3945 | // Deallocate allocated thread data. |
| 3946 | if (t < cpi->num_workers - 1) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3947 | aom_free(thread_data->td->palette_buffer); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3948 | aom_free(thread_data->td->above_pred_buf); |
| 3949 | aom_free(thread_data->td->left_pred_buf); |
| 3950 | aom_free(thread_data->td->wsrc_buf); |
| 3951 | aom_free(thread_data->td->mask_buf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3952 | aom_free(thread_data->td->counts); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 3953 | av1_free_pc_tree(thread_data->td, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3954 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3955 | } |
| 3956 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3957 | aom_free(cpi->tile_thr_data); |
| 3958 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3959 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3960 | if (cpi->num_workers > 1) av1_loop_filter_dealloc(&cpi->lf_row_sync); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3961 | |
| 3962 | dealloc_compressor_data(cpi); |
| 3963 | |
| 3964 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 3965 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3966 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3967 | } |
| 3968 | |
| 3969 | #if CONFIG_FP_MB_STATS |
| 3970 | if (cpi->use_fp_mb_stats) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3971 | aom_free(cpi->twopass.frame_mb_stats_buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3972 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 3973 | } |
| 3974 | #endif |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 3975 | #if CONFIG_INTERNAL_STATS |
| 3976 | aom_free(cpi->ssim_vars); |
| 3977 | cpi->ssim_vars = NULL; |
| 3978 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3979 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3980 | av1_remove_common(cm); |
RogerZhou | 80d5234 | 2017-11-20 10:56:26 -0800 | [diff] [blame] | 3981 | #if CONFIG_HASH_ME |
| 3982 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 3983 | av1_hash_table_destroy(&cm->buffer_pool->frame_bufs[i].hash_table); |
| 3984 | } |
Michelle Findlay-Olynyk | dea531d | 2017-12-13 14:10:56 -0800 | [diff] [blame] | 3985 | if (cpi->sf.use_hash_based_trellis) hbt_destroy(); |
RogerZhou | 80d5234 | 2017-11-20 10:56:26 -0800 | [diff] [blame] | 3986 | #endif // CONFIG_HASH_ME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3987 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 3988 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3989 | |
| 3990 | #ifdef OUTPUT_YUV_SKINMAP |
| 3991 | fclose(yuv_skinmap_file); |
| 3992 | #endif |
| 3993 | #ifdef OUTPUT_YUV_REC |
| 3994 | fclose(yuv_rec_file); |
| 3995 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3996 | #if 0 |
| 3997 | |
| 3998 | if (keyfile) |
| 3999 | fclose(keyfile); |
| 4000 | |
| 4001 | if (framepsnr) |
| 4002 | fclose(framepsnr); |
| 4003 | |
| 4004 | if (kf_list) |
| 4005 | fclose(kf_list); |
| 4006 | |
| 4007 | #endif |
| 4008 | } |
| 4009 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4010 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 4011 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4012 | int i; |
| 4013 | PSNR_STATS psnr; |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4014 | aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4015 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4016 | |
| 4017 | for (i = 0; i < 4; ++i) { |
| 4018 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 4019 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 4020 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 4021 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4022 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 4023 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4024 | } |
| 4025 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4026 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4027 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 4028 | |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 4029 | cpi->ext_ref_frame_flags = ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4030 | return 0; |
| 4031 | } |
| 4032 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 4033 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_upd_flags) { |
| 4034 | cpi->ext_refresh_last_frame = (ref_frame_upd_flags & AOM_LAST_FLAG) != 0; |
| 4035 | cpi->ext_refresh_golden_frame = (ref_frame_upd_flags & AOM_GOLD_FLAG) != 0; |
| 4036 | cpi->ext_refresh_alt_ref_frame = (ref_frame_upd_flags & AOM_ALT_FLAG) != 0; |
| 4037 | cpi->ext_refresh_bwd_ref_frame = (ref_frame_upd_flags & AOM_BWD_FLAG) != 0; |
| 4038 | cpi->ext_refresh_alt2_ref_frame = (ref_frame_upd_flags & AOM_ALT2_FLAG) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4039 | cpi->ext_refresh_frame_flags_pending = 1; |
| 4040 | } |
| 4041 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 4042 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 4043 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4044 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 4045 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4046 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4047 | aom_yv12_copy_frame(cfg, sd, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4048 | return 0; |
| 4049 | } else { |
| 4050 | return -1; |
| 4051 | } |
| 4052 | } |
| 4053 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 4054 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 4055 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4056 | const int num_planes = av1_num_planes(cm); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 4057 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4058 | if (cfg) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4059 | aom_yv12_copy_frame(sd, cfg, num_planes); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4060 | return 0; |
| 4061 | } else { |
| 4062 | return -1; |
| 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4067 | cpi->ext_refresh_frame_context = update; |
| 4068 | cpi->ext_refresh_frame_context_pending = 1; |
| 4069 | return 0; |
| 4070 | } |
| 4071 | |
| 4072 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 4073 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 4074 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 4075 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 4076 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4077 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4078 | uint8_t *src = s->y_buffer; |
| 4079 | int h = s->y_height; |
| 4080 | |
| 4081 | do { |
| 4082 | fwrite(src, s->y_width, 1, f); |
| 4083 | src += s->y_stride; |
| 4084 | } while (--h); |
| 4085 | |
| 4086 | src = s->u_buffer; |
| 4087 | h = s->uv_height; |
| 4088 | |
| 4089 | do { |
| 4090 | fwrite(src, s->uv_width, 1, f); |
| 4091 | src += s->uv_stride; |
| 4092 | } while (--h); |
| 4093 | |
| 4094 | src = s->v_buffer; |
| 4095 | h = s->uv_height; |
| 4096 | |
| 4097 | do { |
| 4098 | fwrite(src, s->uv_width, 1, f); |
| 4099 | src += s->uv_stride; |
| 4100 | } while (--h); |
| 4101 | } |
| 4102 | #endif |
| 4103 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 4104 | #if USE_GF16_MULTI_LAYER |
| 4105 | static void check_show_existing_frame_gf16(AV1_COMP *cpi) { |
| 4106 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 4107 | AV1_COMMON *const cm = &cpi->common; |
| 4108 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 4109 | gf_group->update_type[gf_group->index]; |
| 4110 | |
| 4111 | if (cm->show_existing_frame == 1) { |
| 4112 | cm->show_existing_frame = 0; |
| 4113 | } else if (cpi->rc.is_last_bipred_frame) { |
| 4114 | cpi->rc.is_last_bipred_frame = 0; |
| 4115 | cm->show_existing_frame = 1; |
| 4116 | cpi->existing_fb_idx_to_show = cpi->bwd_fb_idx; |
| 4117 | } else if (next_frame_update_type == OVERLAY_UPDATE || |
| 4118 | next_frame_update_type == INTNL_OVERLAY_UPDATE) { |
| 4119 | // Check the temporal filtering status for the next OVERLAY frame |
| 4120 | const int num_arfs_in_gf = cpi->num_extra_arfs + 1; |
| 4121 | int which_arf = 0, arf_idx; |
| 4122 | // Identify the index to the next overlay frame. |
| 4123 | for (arf_idx = 0; arf_idx < num_arfs_in_gf; arf_idx++) { |
| 4124 | if (gf_group->index == cpi->arf_pos_for_ovrly[arf_idx]) { |
| 4125 | which_arf = arf_idx; |
| 4126 | break; |
| 4127 | } |
| 4128 | } |
| 4129 | assert(arf_idx < num_arfs_in_gf); |
| 4130 | if (cpi->is_arf_filter_off[which_arf]) { |
| 4131 | cm->show_existing_frame = 1; |
| 4132 | cpi->rc.is_src_frame_alt_ref = 1; |
| 4133 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
| 4134 | ? cpi->alt_fb_idx |
| 4135 | : cpi->bwd_fb_idx; |
| 4136 | cpi->is_arf_filter_off[which_arf] = 0; |
| 4137 | } |
| 4138 | } |
| 4139 | cpi->rc.is_src_frame_ext_arf = 0; |
| 4140 | } |
| 4141 | #endif // USE_GF16_MULTI_LAYER |
| 4142 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4143 | static void check_show_existing_frame(AV1_COMP *cpi) { |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 4144 | #if USE_GF16_MULTI_LAYER |
| 4145 | if (cpi->rc.baseline_gf_interval == 16) { |
| 4146 | check_show_existing_frame_gf16(cpi); |
| 4147 | return; |
| 4148 | } |
| 4149 | #endif // USE_GF16_MULTI_LAYER |
| 4150 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4151 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4152 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4153 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 4154 | gf_group->update_type[gf_group->index]; |
| 4155 | const int which_arf = gf_group->arf_update_idx[gf_group->index]; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 4156 | |
| 4157 | if (cm->show_existing_frame == 1) { |
| 4158 | cm->show_existing_frame = 0; |
| 4159 | } else if (cpi->rc.is_last_bipred_frame) { |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 4160 | // NOTE: If the current frame is a last bi-predictive frame, it is |
| 4161 | // needed next to show the BWDREF_FRAME, which is pointed by |
| 4162 | // the last_fb_idxes[0] after reference frame buffer update |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4163 | cpi->rc.is_last_bipred_frame = 0; |
| 4164 | cm->show_existing_frame = 1; |
| 4165 | cpi->existing_fb_idx_to_show = cpi->lst_fb_idxes[0]; |
| 4166 | } else if (cpi->is_arf_filter_off[which_arf] && |
| 4167 | (next_frame_update_type == OVERLAY_UPDATE || |
| 4168 | next_frame_update_type == INTNL_OVERLAY_UPDATE)) { |
| 4169 | // Other parameters related to OVERLAY_UPDATE will be taken care of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4170 | // in av1_rc_get_second_pass_params(cpi) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4171 | cm->show_existing_frame = 1; |
| 4172 | cpi->rc.is_src_frame_alt_ref = 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4173 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
| 4174 | ? cpi->alt_fb_idx |
| 4175 | : cpi->alt2_fb_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4176 | cpi->is_arf_filter_off[which_arf] = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4177 | } |
| 4178 | cpi->rc.is_src_frame_ext_arf = 0; |
| 4179 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4180 | |
| 4181 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4182 | 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] | 4183 | uint8_t *src = s->y_buffer; |
| 4184 | int h = cm->height; |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 4185 | if (yuv_rec_file == NULL) return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4186 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 4187 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 4188 | |
| 4189 | do { |
| 4190 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 4191 | src16 += s->y_stride; |
| 4192 | } while (--h); |
| 4193 | |
| 4194 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 4195 | h = s->uv_height; |
| 4196 | |
| 4197 | do { |
| 4198 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 4199 | src16 += s->uv_stride; |
| 4200 | } while (--h); |
| 4201 | |
| 4202 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 4203 | h = s->uv_height; |
| 4204 | |
| 4205 | do { |
| 4206 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 4207 | src16 += s->uv_stride; |
| 4208 | } while (--h); |
| 4209 | |
| 4210 | fflush(yuv_rec_file); |
| 4211 | return; |
| 4212 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4213 | |
| 4214 | do { |
| 4215 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 4216 | src += s->y_stride; |
| 4217 | } while (--h); |
| 4218 | |
| 4219 | src = s->u_buffer; |
| 4220 | h = s->uv_height; |
| 4221 | |
| 4222 | do { |
| 4223 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 4224 | src += s->uv_stride; |
| 4225 | } while (--h); |
| 4226 | |
| 4227 | src = s->v_buffer; |
| 4228 | h = s->uv_height; |
| 4229 | |
| 4230 | do { |
| 4231 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 4232 | src += s->uv_stride; |
| 4233 | } while (--h); |
| 4234 | |
| 4235 | fflush(yuv_rec_file); |
| 4236 | } |
| 4237 | #endif // OUTPUT_YUV_REC |
| 4238 | |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 4239 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4240 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 4241 | int i; |
| 4242 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 4243 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4244 | AV1_COMMON *const cm = &cpi->common; |
| 4245 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 4246 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 4247 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 4248 | cpi->gmparams_cost[i]) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 4249 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4250 | assert(cm->global_motion[i].wmtype == IDENTITY); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 4251 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 4252 | recode = 1; |
Urvang Joshi | 02aade8 | 2017-12-18 17:18:16 -0800 | [diff] [blame] | 4253 | // TODO(sarahparker): The earlier condition for recoding here was: |
| 4254 | // "recode |= (rdc->global_motion_used[i] > 0);". Can we bring something |
| 4255 | // similar to that back to speed up global motion? |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4256 | } |
| 4257 | } |
| 4258 | return recode; |
| 4259 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4260 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4261 | // Function to test for conditions that indicate we should loop |
| 4262 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4263 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 4264 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4265 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4266 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4267 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 4268 | int force_recode = 0; |
| 4269 | |
| 4270 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 4271 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 4272 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4273 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 4274 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 4275 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 4276 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4277 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4278 | // Deal with frame undershoot and whether or not we are |
| 4279 | // below the automatically set cq level. |
| 4280 | if (q > oxcf->cq_level && |
| 4281 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 4282 | force_recode = 1; |
| 4283 | } |
| 4284 | } |
| 4285 | } |
| 4286 | return force_recode; |
| 4287 | } |
| 4288 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4289 | #define DUMP_REF_FRAME_IMAGES 0 |
| 4290 | |
| 4291 | #if DUMP_REF_FRAME_IMAGES == 1 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4292 | static int dump_one_image(AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4293 | const YV12_BUFFER_CONFIG *const ref_buf, |
| 4294 | char *file_name) { |
| 4295 | int h; |
| 4296 | FILE *f_ref = NULL; |
| 4297 | |
| 4298 | if (ref_buf == NULL) { |
| 4299 | printf("Frame data buffer is NULL.\n"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4300 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4301 | } |
| 4302 | |
| 4303 | if ((f_ref = fopen(file_name, "wb")) == NULL) { |
| 4304 | printf("Unable to open file %s to write.\n", file_name); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4305 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4306 | } |
| 4307 | |
| 4308 | // --- Y --- |
| 4309 | for (h = 0; h < cm->height; ++h) { |
| 4310 | fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref); |
| 4311 | } |
| 4312 | // --- U --- |
| 4313 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4314 | fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 4315 | f_ref); |
| 4316 | } |
| 4317 | // --- V --- |
| 4318 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4319 | fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 4320 | f_ref); |
| 4321 | } |
| 4322 | |
| 4323 | fclose(f_ref); |
| 4324 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4325 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4326 | } |
| 4327 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4328 | static void dump_ref_frame_images(AV1_COMP *cpi) { |
| 4329 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4330 | MV_REFERENCE_FRAME ref_frame; |
| 4331 | |
| 4332 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4333 | char file_name[256] = ""; |
| 4334 | snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv", |
| 4335 | cm->current_video_frame, ref_frame); |
| 4336 | dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name); |
| 4337 | } |
| 4338 | } |
| 4339 | #endif // DUMP_REF_FRAME_IMAGES == 1 |
| 4340 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4341 | // This function is used to shift the virtual indices of last reference frames |
| 4342 | // as follows: |
| 4343 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 4344 | // when the LAST_FRAME is updated. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4345 | static INLINE void shift_last_ref_frames(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4346 | int ref_frame; |
| 4347 | for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) { |
| 4348 | cpi->lst_fb_idxes[ref_frame] = cpi->lst_fb_idxes[ref_frame - 1]; |
| 4349 | |
| 4350 | // [0] is allocated to the current coded frame. The statistics for the |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 4351 | // reference frames start at [LAST_FRAME], i.e. [1]. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4352 | if (!cpi->rc.is_src_frame_alt_ref) { |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 4353 | memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME], |
| 4354 | cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME], |
| 4355 | sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4356 | } |
| 4357 | } |
| 4358 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4359 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 4360 | #if USE_GF16_MULTI_LAYER |
| 4361 | static void update_reference_frames_gf16(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4362 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4363 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4364 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 4365 | if (cm->frame_type == KEY_FRAME) { |
| 4366 | for (int ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) { |
| 4367 | ref_cnt_fb(pool->frame_bufs, |
| 4368 | &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]], |
| 4369 | cm->new_fb_idx); |
| 4370 | } |
| 4371 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 4372 | cm->new_fb_idx); |
| 4373 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 4374 | cm->new_fb_idx); |
| 4375 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 4376 | cm->new_fb_idx); |
| 4377 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 4378 | cm->new_fb_idx); |
| 4379 | } else { |
| 4380 | if (cpi->refresh_last_frame || cpi->refresh_golden_frame || |
| 4381 | cpi->refresh_bwd_ref_frame || cpi->refresh_alt2_ref_frame || |
| 4382 | cpi->refresh_alt_ref_frame) { |
| 4383 | assert(cpi->refresh_fb_idx >= 0 && cpi->refresh_fb_idx < REF_FRAMES); |
| 4384 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->refresh_fb_idx], |
| 4385 | cm->new_fb_idx); |
| 4386 | } |
| 4387 | |
| 4388 | // TODO(zoeliu): To handle cpi->interp_filter_selected[]. |
| 4389 | |
| 4390 | // For GF of 16, an additional ref frame index mapping needs to be handled |
| 4391 | // if this is the last frame to encode in the current GF group. |
| 4392 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 4393 | if (gf_group->update_type[gf_group->index + 1] == OVERLAY_UPDATE) |
| 4394 | av1_ref_frame_map_idx_updates(cpi, gf_group->index + 1); |
| 4395 | } |
| 4396 | |
| 4397 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 4398 | // Dump out all reference frame images. |
| 4399 | dump_ref_frame_images(cpi); |
| 4400 | #endif // DUMP_REF_FRAME_IMAGES |
| 4401 | } |
| 4402 | #endif // USE_GF16_MULTI_LAYER |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 4403 | |
| 4404 | static void update_reference_frames(AV1_COMP *cpi) { |
| 4405 | AV1_COMMON *const cm = &cpi->common; |
| 4406 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4407 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 4408 | // for the purpose to verify no mismatch between encoder and decoder. |
| 4409 | if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx; |
| 4410 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 4411 | #if USE_GF16_MULTI_LAYER |
| 4412 | if (cpi->rc.baseline_gf_interval == 16) { |
| 4413 | update_reference_frames_gf16(cpi); |
| 4414 | return; |
| 4415 | } |
| 4416 | #endif // USE_GF16_MULTI_LAYER |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 4417 | |
| 4418 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4419 | // At this point the new frame has been encoded. |
| 4420 | // If any buffer copy / swapping is signaled it should be done here. |
| 4421 | if (cm->frame_type == KEY_FRAME) { |
| 4422 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 4423 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4424 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 4425 | cm->new_fb_idx); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4426 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 4427 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4428 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 4429 | cm->new_fb_idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4430 | } else if (av1_preserve_existing_gf(cpi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4431 | // We have decided to preserve the previously existing golden frame as our |
| 4432 | // new ARF frame. However, in the short term in function |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4433 | // av1_bitstream.c::get_refresh_mask() we left it in the GF slot and, if |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4434 | // we're updating the GF with the current decoded frame, we save it to the |
| 4435 | // ARF slot instead. |
| 4436 | // We now have to update the ARF with the current frame and swap gld_fb_idx |
| 4437 | // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF |
| 4438 | // slot and, if we're updating the GF, the current frame becomes the new GF. |
| 4439 | int tmp; |
| 4440 | |
| 4441 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 4442 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4443 | tmp = cpi->alt_fb_idx; |
| 4444 | cpi->alt_fb_idx = cpi->gld_fb_idx; |
| 4445 | cpi->gld_fb_idx = tmp; |
| 4446 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4447 | // We need to modify the mapping accordingly |
| 4448 | cpi->arf_map[0] = cpi->alt_fb_idx; |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 4449 | // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to |
| 4450 | // cpi->interp_filter_selected[GOLDEN_FRAME]? |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4451 | } else if (cpi->rc.is_src_frame_ext_arf && cm->show_existing_frame) { |
| 4452 | // Deal with the special case for showing existing internal ALTREF_FRAME |
| 4453 | // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME |
| 4454 | // by updating the virtual indices. |
| 4455 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4456 | const int which_arf = gf_group->arf_ref_idx[gf_group->index]; |
| 4457 | assert(gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4458 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4459 | const int tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4460 | shift_last_ref_frames(cpi); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4461 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4462 | cpi->lst_fb_idxes[0] = cpi->alt2_fb_idx; |
| 4463 | cpi->alt2_fb_idx = tmp; |
| 4464 | // We need to modify the mapping accordingly |
| 4465 | cpi->arf_map[which_arf] = cpi->alt2_fb_idx; |
| 4466 | |
| 4467 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 4468 | cpi->interp_filter_selected[ALTREF2_FRAME], |
| 4469 | sizeof(cpi->interp_filter_selected[ALTREF2_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4470 | } else { /* For non key/golden frames */ |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4471 | // === ALTREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4472 | if (cpi->refresh_alt_ref_frame) { |
| 4473 | int arf_idx = cpi->alt_fb_idx; |
| 4474 | int which_arf = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4475 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[arf_idx], cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4476 | |
| 4477 | memcpy(cpi->interp_filter_selected[ALTREF_FRAME + which_arf], |
| 4478 | cpi->interp_filter_selected[0], |
| 4479 | sizeof(cpi->interp_filter_selected[0])); |
| 4480 | } |
| 4481 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4482 | // === GOLDEN_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4483 | if (cpi->refresh_golden_frame) { |
| 4484 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 4485 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4486 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 4487 | memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], |
| 4488 | cpi->interp_filter_selected[0], |
| 4489 | sizeof(cpi->interp_filter_selected[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4490 | } |
| 4491 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4492 | // === BWDREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4493 | if (cpi->refresh_bwd_ref_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4494 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 4495 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4496 | |
| 4497 | memcpy(cpi->interp_filter_selected[BWDREF_FRAME], |
| 4498 | cpi->interp_filter_selected[0], |
| 4499 | sizeof(cpi->interp_filter_selected[0])); |
| 4500 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4501 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4502 | // === ALTREF2_FRAME === |
| 4503 | if (cpi->refresh_alt2_ref_frame) { |
| 4504 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 4505 | cm->new_fb_idx); |
| 4506 | |
| 4507 | memcpy(cpi->interp_filter_selected[ALTREF2_FRAME], |
| 4508 | cpi->interp_filter_selected[0], |
| 4509 | sizeof(cpi->interp_filter_selected[0])); |
| 4510 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | if (cpi->refresh_last_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4514 | // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame |
| 4515 | // reference to the reference frame buffer virtual index; and then (2) from |
| 4516 | // the virtual index to the reference frame buffer physical index: |
| 4517 | // |
| 4518 | // LAST_FRAME, ..., LAST3_FRAME, ..., ALTREF_FRAME |
| 4519 | // | | | |
| 4520 | // v v v |
| 4521 | // lst_fb_idxes[0], ..., lst_fb_idxes[2], ..., alt_fb_idx |
| 4522 | // | | | |
| 4523 | // v v v |
| 4524 | // ref_frame_map[], ..., ref_frame_map[], ..., ref_frame_map[] |
| 4525 | // |
| 4526 | // When refresh_last_frame is set, it is intended to retire LAST3_FRAME, |
| 4527 | // have the other 2 LAST reference frames shifted as follows: |
| 4528 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 4529 | // , and then have LAST_FRAME refreshed by the newly coded frame. |
| 4530 | // |
| 4531 | // To fulfill it, the decoder will be notified to execute following 2 steps: |
| 4532 | // |
| 4533 | // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME |
| 4534 | // to point to the newly coded frame, i.e. |
| 4535 | // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx; |
| 4536 | // |
| 4537 | // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the |
| 4538 | // original virtual index of LAST3_FRAME and have the other mappings |
| 4539 | // shifted as follows: |
| 4540 | // LAST_FRAME, LAST2_FRAME, LAST3_FRAME |
| 4541 | // | | | |
| 4542 | // v v v |
| 4543 | // lst_fb_idxes[2], lst_fb_idxes[0], lst_fb_idxes[1] |
| 4544 | int ref_frame; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 4545 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4546 | if (cm->frame_type == KEY_FRAME) { |
| 4547 | for (ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) { |
| 4548 | ref_cnt_fb(pool->frame_bufs, |
| 4549 | &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]], |
| 4550 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4551 | } |
| 4552 | } else { |
| 4553 | int tmp; |
| 4554 | |
| 4555 | ref_cnt_fb(pool->frame_bufs, |
| 4556 | &cm->ref_frame_map[cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]], |
| 4557 | cm->new_fb_idx); |
| 4558 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4559 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 4560 | |
| 4561 | shift_last_ref_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4562 | cpi->lst_fb_idxes[0] = tmp; |
| 4563 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 4564 | assert(cm->show_existing_frame == 0); |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 4565 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 4566 | cpi->interp_filter_selected[0], |
| 4567 | sizeof(cpi->interp_filter_selected[0])); |
Zoe Liu | aff92d5 | 2017-07-11 21:35:08 -0700 | [diff] [blame] | 4568 | |
| 4569 | if (cpi->rc.is_last_bipred_frame) { |
| 4570 | // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the |
| 4571 | // LAST3_FRAME by updating the virtual indices. |
| 4572 | // |
| 4573 | // NOTE: The source frame for BWDREF does not have a holding position as |
| 4574 | // the OVERLAY frame for ALTREF's. Hence, to resolve the reference |
| 4575 | // virtual index reshuffling for BWDREF, the encoder always |
| 4576 | // specifies a LAST_BIPRED right before BWDREF and completes the |
| 4577 | // reshuffling job accordingly. |
| 4578 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 4579 | |
| 4580 | shift_last_ref_frames(cpi); |
| 4581 | cpi->lst_fb_idxes[0] = cpi->bwd_fb_idx; |
| 4582 | cpi->bwd_fb_idx = tmp; |
| 4583 | |
| 4584 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 4585 | cpi->interp_filter_selected[BWDREF_FRAME], |
| 4586 | sizeof(cpi->interp_filter_selected[BWDREF_FRAME])); |
| 4587 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4588 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 4592 | // Dump out all reference frame images. |
| 4593 | dump_ref_frame_images(cpi); |
| 4594 | #endif // DUMP_REF_FRAME_IMAGES |
| 4595 | } |
| 4596 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4597 | static INLINE void alloc_frame_mvs(AV1_COMMON *const cm, int buffer_idx) { |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4598 | assert(buffer_idx != INVALID_IDX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4599 | RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 4600 | ensure_mv_buffer(new_fb_ptr, cm); |
| 4601 | new_fb_ptr->width = cm->width; |
| 4602 | new_fb_ptr->height = cm->height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4603 | } |
| 4604 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4605 | static void scale_references(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4606 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4607 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4608 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4609 | const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = { |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 4610 | AOM_LAST_FLAG, AOM_LAST2_FLAG, AOM_LAST3_FLAG, AOM_GOLD_FLAG, |
| 4611 | AOM_BWD_FLAG, AOM_ALT2_FLAG, AOM_ALT_FLAG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4612 | }; |
| 4613 | |
| 4614 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4615 | // 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] | 4616 | if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 4617 | BufferPool *const pool = cm->buffer_pool; |
| 4618 | const YV12_BUFFER_CONFIG *const ref = |
| 4619 | get_ref_frame_buffer(cpi, ref_frame); |
| 4620 | |
| 4621 | if (ref == NULL) { |
| 4622 | cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 4623 | continue; |
| 4624 | } |
| 4625 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4626 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 4627 | RefCntBuffer *new_fb_ptr = NULL; |
| 4628 | int force_scaling = 0; |
| 4629 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 4630 | if (new_fb == INVALID_IDX) { |
| 4631 | new_fb = get_free_fb(cm); |
| 4632 | force_scaling = 1; |
| 4633 | } |
| 4634 | if (new_fb == INVALID_IDX) return; |
| 4635 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 4636 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 4637 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 4638 | if (aom_realloc_frame_buffer( |
| 4639 | &new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x, |
| 4640 | cm->subsampling_y, cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 4641 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4642 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4643 | "Failed to allocate frame buffer"); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4644 | av1_resize_and_extend_frame(ref, &new_fb_ptr->buf, (int)cm->bit_depth, |
| 4645 | num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4646 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 4647 | alloc_frame_mvs(cm, new_fb); |
| 4648 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4649 | } else { |
| 4650 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 4651 | RefCntBuffer *const buf = &pool->frame_bufs[buf_idx]; |
| 4652 | buf->buf.y_crop_width = ref->y_crop_width; |
| 4653 | buf->buf.y_crop_height = ref->y_crop_height; |
| 4654 | cpi->scaled_ref_idx[ref_frame - 1] = buf_idx; |
| 4655 | ++buf->ref_count; |
| 4656 | } |
| 4657 | } else { |
| 4658 | if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 4659 | } |
| 4660 | } |
| 4661 | } |
| 4662 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4663 | static void release_scaled_references(AV1_COMP *cpi) { |
| 4664 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4665 | int i; |
| 4666 | if (cpi->oxcf.pass == 0) { |
| 4667 | // Only release scaled references under certain conditions: |
| 4668 | // if reference will be updated, or if scaled reference has same resolution. |
| 4669 | int refresh[INTER_REFS_PER_FRAME]; |
| 4670 | refresh[0] = (cpi->refresh_last_frame) ? 1 : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4671 | refresh[1] = refresh[2] = 0; |
| 4672 | refresh[3] = (cpi->refresh_golden_frame) ? 1 : 0; |
| 4673 | refresh[4] = (cpi->refresh_bwd_ref_frame) ? 1 : 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4674 | refresh[5] = (cpi->refresh_alt2_ref_frame) ? 1 : 0; |
| 4675 | refresh[6] = (cpi->refresh_alt_ref_frame) ? 1 : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4676 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 4677 | const int idx = cpi->scaled_ref_idx[i - 1]; |
| 4678 | RefCntBuffer *const buf = |
| 4679 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 4680 | const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, i); |
| 4681 | if (buf != NULL && |
| 4682 | (refresh[i - 1] || (buf->buf.y_crop_width == ref->y_crop_width && |
| 4683 | buf->buf.y_crop_height == ref->y_crop_height))) { |
| 4684 | --buf->ref_count; |
| 4685 | cpi->scaled_ref_idx[i - 1] = INVALID_IDX; |
| 4686 | } |
| 4687 | } |
| 4688 | } else { |
| 4689 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) { |
| 4690 | const int idx = cpi->scaled_ref_idx[i]; |
| 4691 | RefCntBuffer *const buf = |
| 4692 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 4693 | if (buf != NULL) { |
| 4694 | --buf->ref_count; |
| 4695 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 4696 | } |
| 4697 | } |
| 4698 | } |
| 4699 | } |
| 4700 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4701 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 4702 | const AV1_COMMON *const cm = &cpi->common; |
| 4703 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4704 | |
| 4705 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4706 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4707 | |
| 4708 | if (cpi->sf.mv.auto_mv_step_size) { |
| 4709 | if (frame_is_intra_only(cm)) { |
| 4710 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 4711 | // after a key/intra-only frame. |
| 4712 | cpi->max_mv_magnitude = max_mv_def; |
| 4713 | } else { |
| 4714 | if (cm->show_frame) { |
| 4715 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 4716 | // in the previous frame, capped by the default max_mv_magnitude based |
| 4717 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4718 | cpi->mv_step_param = av1_init_search_range( |
| 4719 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4720 | } |
| 4721 | cpi->max_mv_magnitude = 0; |
| 4722 | } |
| 4723 | } |
| 4724 | } |
| 4725 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4726 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4727 | int i; |
| 4728 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 4729 | cpi->common.global_motion[i] = default_warp_params; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4730 | } |
| 4731 | cpi->global_motion_search_done = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4732 | av1_set_speed_features_framesize_independent(cpi); |
| 4733 | av1_set_rd_speed_thresholds(cpi); |
| 4734 | av1_set_rd_speed_thresholds_sub8x8(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4735 | cpi->common.interp_filter = cpi->sf.default_interp_filter; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 4736 | if (!frame_is_intra_only(&cpi->common)) set_compound_tools(&cpi->common); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4737 | } |
| 4738 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4739 | 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] | 4740 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4741 | AV1_COMMON *const cm = &cpi->common; |
| 4742 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4743 | |
| 4744 | // Setup variables that depend on the dimensions of the frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4745 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4746 | |
Sebastien Alaiwan | 41cae6a | 2018-01-12 12:22:29 +0100 | [diff] [blame] | 4747 | // Decide q and q bounds. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4748 | *q = av1_rc_pick_q_and_bounds(cpi, cm->width, cm->height, bottom_index, |
| 4749 | top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4750 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 4751 | if (!frame_is_intra_only(cm)) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4752 | #if CONFIG_AMVR |
| 4753 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH, |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 4754 | cpi->common.cur_frame_force_integer_mv); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4755 | #else |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4756 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4757 | #endif |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 4758 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4759 | |
| 4760 | // Configure experimental use of segmentation for enhanced coding of |
| 4761 | // static regions if indicated. |
| 4762 | // Only allowed in the second pass of a two pass encode, as it requires |
| 4763 | // lagged coding, and if the relevant speed feature flag is set. |
| 4764 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 4765 | configure_static_seg_features(cpi); |
| 4766 | } |
| 4767 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4768 | static void init_motion_estimation(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4769 | int y_stride = cpi->scaled_source.y_stride; |
| 4770 | |
| 4771 | if (cpi->sf.mv.search_method == NSTEP) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4772 | av1_init3smotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4773 | } else if (cpi->sf.mv.search_method == DIAMOND) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4774 | av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4775 | } |
| 4776 | } |
| 4777 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4778 | #if CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4779 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4780 | static void set_restoration_unit_size(int width, int height, int sx, int sy, |
| 4781 | RestorationInfo *rst) { |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4782 | (void)width; |
| 4783 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4784 | (void)sx; |
| 4785 | (void)sy; |
| 4786 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 4787 | int s = AOMMIN(sx, sy); |
| 4788 | #else |
| 4789 | int s = 0; |
| 4790 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 4791 | |
Debargha Mukherjee | 5f7f367 | 2017-08-12 10:22:49 -0700 | [diff] [blame] | 4792 | if (width * height > 352 * 288) |
| 4793 | rst[0].restoration_unit_size = RESTORATION_TILESIZE_MAX; |
| 4794 | else |
| 4795 | rst[0].restoration_unit_size = (RESTORATION_TILESIZE_MAX >> 1); |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4796 | rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s; |
| 4797 | rst[2].restoration_unit_size = rst[1].restoration_unit_size; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4798 | } |
| 4799 | #endif // CONFIG_LOOP_RESTORATION |
| 4800 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4801 | static void init_ref_frame_bufs(AV1_COMMON *cm) { |
| 4802 | int i; |
| 4803 | BufferPool *const pool = cm->buffer_pool; |
| 4804 | cm->new_fb_idx = INVALID_IDX; |
| 4805 | for (i = 0; i < REF_FRAMES; ++i) { |
| 4806 | cm->ref_frame_map[i] = INVALID_IDX; |
| 4807 | pool->frame_bufs[i].ref_count = 0; |
| 4808 | } |
| 4809 | #if CONFIG_HASH_ME |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 4810 | if (av1_use_hash_me(cm)) { |
| 4811 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 4812 | av1_hash_table_init(&pool->frame_bufs[i].hash_table); |
| 4813 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4814 | } |
| 4815 | #endif |
| 4816 | } |
| 4817 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 4818 | static void check_initial_width(AV1_COMP *cpi, int use_highbitdepth, |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4819 | int subsampling_x, int subsampling_y) { |
| 4820 | AV1_COMMON *const cm = &cpi->common; |
| 4821 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 4822 | if (!cpi->initial_width || cm->use_highbitdepth != use_highbitdepth || |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4823 | cm->subsampling_x != subsampling_x || |
| 4824 | cm->subsampling_y != subsampling_y) { |
| 4825 | cm->subsampling_x = subsampling_x; |
| 4826 | cm->subsampling_y = subsampling_y; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4827 | cm->use_highbitdepth = use_highbitdepth; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4828 | |
| 4829 | alloc_raw_frame_buffers(cpi); |
| 4830 | init_ref_frame_bufs(cm); |
| 4831 | alloc_util_frame_buffers(cpi); |
| 4832 | |
| 4833 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 4834 | |
| 4835 | cpi->initial_width = cm->width; |
| 4836 | cpi->initial_height = cm->height; |
| 4837 | cpi->initial_mbs = cm->MBs; |
| 4838 | } |
| 4839 | } |
| 4840 | |
| 4841 | // Returns 1 if the assigned width or height was <= 0. |
| 4842 | static int set_size_literal(AV1_COMP *cpi, int width, int height) { |
| 4843 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4844 | const int num_planes = av1_num_planes(cm); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4845 | check_initial_width(cpi, cm->use_highbitdepth, cm->subsampling_x, |
| 4846 | cm->subsampling_y); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4847 | |
| 4848 | if (width <= 0 || height <= 0) return 1; |
| 4849 | |
| 4850 | cm->width = width; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4851 | cm->height = height; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4852 | |
| 4853 | if (cpi->initial_width && cpi->initial_height && |
| 4854 | (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) { |
| 4855 | av1_free_context_buffers(cm); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4856 | av1_free_pc_tree(&cpi->td, num_planes); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4857 | alloc_compressor_data(cpi); |
| 4858 | realloc_segmentation_maps(cpi); |
| 4859 | cpi->initial_width = cpi->initial_height = 0; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4860 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4861 | update_frame_size(cpi); |
| 4862 | |
| 4863 | return 0; |
| 4864 | } |
| 4865 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4866 | static void set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4867 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4868 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4869 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4870 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4871 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4872 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 4873 | // There has been a change in the encoded frame size |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4874 | set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4875 | set_mv_search_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4876 | } |
| 4877 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4878 | if (cpi->oxcf.pass == 2) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4879 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | alloc_frame_mvs(cm, cm->new_fb_idx); |
| 4883 | |
| 4884 | // Reset the frame pointers to the current frame size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4885 | if (aom_realloc_frame_buffer(get_frame_new_buffer(cm), cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4886 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 4887 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 4888 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4889 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4890 | "Failed to allocate frame buffer"); |
| 4891 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4892 | #if CONFIG_LOOP_RESTORATION |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 4893 | #if CONFIG_HORZONLY_FRAME_SUPERRES |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4894 | const int frame_width = cm->superres_upscaled_width; |
| 4895 | const int frame_height = cm->superres_upscaled_height; |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4896 | #else |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4897 | const int frame_width = cm->width; |
| 4898 | const int frame_height = cm->height; |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 4899 | #endif // CONFIG_HORZONLY_FRAME_SUPERRES |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4900 | set_restoration_unit_size(frame_width, frame_height, cm->subsampling_x, |
| 4901 | cm->subsampling_y, cm->rst_info); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4902 | for (int i = 0; i < num_planes; ++i) |
Rupert Swarbrick | 1a96c3f | 2017-10-24 11:55:00 +0100 | [diff] [blame] | 4903 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4904 | |
| 4905 | av1_alloc_restoration_buffers(cm); |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4906 | #endif // CONFIG_LOOP_RESTORATION |
| 4907 | alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4908 | init_motion_estimation(cpi); |
| 4909 | |
| 4910 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4911 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 4912 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 4913 | |
| 4914 | ref_buf->idx = buf_idx; |
| 4915 | |
| 4916 | if (buf_idx != INVALID_IDX) { |
| 4917 | YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf; |
| 4918 | ref_buf->buf = buf; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4919 | av1_setup_scale_factors_for_frame( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4920 | &ref_buf->sf, buf->y_crop_width, buf->y_crop_height, cm->width, |
| 4921 | cm->height, (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 4922 | if (av1_is_scaled(&ref_buf->sf)) |
| 4923 | aom_extend_frame_borders(buf, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4924 | } else { |
| 4925 | ref_buf->buf = NULL; |
| 4926 | } |
| 4927 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 4928 | |
Hui Su | 5ebd870 | 2018-01-08 18:09:20 -0800 | [diff] [blame] | 4929 | av1_setup_scale_factors_for_frame(&cm->sf_identity, cm->width, cm->height, |
Sebastien Alaiwan | 1dcb707 | 2017-05-12 11:13:05 +0200 | [diff] [blame] | 4930 | cm->width, cm->height, |
| 4931 | cm->use_highbitdepth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4932 | |
| 4933 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 4934 | } |
| 4935 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4936 | static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) { |
| 4937 | // Choose an arbitrary random number |
| 4938 | static unsigned int seed = 56789; |
| 4939 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4940 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 4941 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4942 | |
| 4943 | switch (oxcf->resize_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4944 | case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4945 | case RESIZE_FIXED: |
| 4946 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4947 | new_denom = oxcf->resize_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4948 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4949 | new_denom = oxcf->resize_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4950 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4951 | case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4952 | default: assert(0); |
| 4953 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4954 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4955 | } |
| 4956 | |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 4957 | #if CONFIG_HORZONLY_FRAME_SUPERRES |
Urvang Joshi | e58b564 | 2017-10-05 17:59:43 -0700 | [diff] [blame] | 4958 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4959 | static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) { |
| 4960 | // Choose an arbitrary random number |
| 4961 | static unsigned int seed = 34567; |
| 4962 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4963 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 4964 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4965 | int bottom_index, top_index, q, qthresh; |
| 4966 | |
| 4967 | switch (oxcf->superres_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4968 | case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4969 | case SUPERRES_FIXED: |
| 4970 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4971 | new_denom = oxcf->superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4972 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4973 | new_denom = oxcf->superres_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4974 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4975 | case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4976 | case SUPERRES_QTHRESH: |
| 4977 | qthresh = (cpi->common.frame_type == KEY_FRAME ? oxcf->superres_kf_qthresh |
| 4978 | : oxcf->superres_qthresh); |
| 4979 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
| 4980 | q = av1_rc_pick_q_and_bounds(cpi, cpi->oxcf.width, cpi->oxcf.height, |
| 4981 | &bottom_index, &top_index); |
| 4982 | if (q < qthresh) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4983 | new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4984 | } else { |
Urvang Joshi | 28983f7 | 2017-10-25 14:41:06 -0700 | [diff] [blame] | 4985 | const uint8_t min_denom = SCALE_NUMERATOR + 1; |
| 4986 | const uint8_t denom_step = (MAXQ - qthresh + 1) >> 3; |
| 4987 | const uint8_t additional_denom = (q - qthresh) / denom_step; |
| 4988 | new_denom = AOMMIN(min_denom + additional_denom, SCALE_NUMERATOR << 1); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4989 | } |
| 4990 | break; |
| 4991 | default: assert(0); |
| 4992 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4993 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4994 | } |
| 4995 | |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4996 | static int dimension_is_ok(int orig_dim, int resized_dim, int denom) { |
| 4997 | return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2); |
| 4998 | } |
| 4999 | |
| 5000 | 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] | 5001 | // Only need to check the width, as scaling is horizontal only. |
| 5002 | (void)oheight; |
| 5003 | return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5004 | } |
| 5005 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5006 | static int validate_size_scales(RESIZE_MODE resize_mode, |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5007 | SUPERRES_MODE superres_mode, int owidth, |
| 5008 | int oheight, size_params_type *rsz) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5009 | if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5010 | return 1; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5011 | } |
| 5012 | |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 5013 | // Calculate current resize scale. |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5014 | int resize_denom = |
| 5015 | AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width), |
| 5016 | DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height)); |
| 5017 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5018 | if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5019 | // Alter superres scale as needed to enforce conformity. |
| 5020 | rsz->superres_denom = |
| 5021 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom; |
| 5022 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 5023 | if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5024 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5025 | } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5026 | // Alter resize scale as needed to enforce conformity. |
| 5027 | resize_denom = |
| 5028 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5029 | rsz->resize_width = owidth; |
| 5030 | rsz->resize_height = oheight; |
| 5031 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5032 | resize_denom); |
| 5033 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 5034 | if (resize_denom > SCALE_NUMERATOR) { |
| 5035 | --resize_denom; |
| 5036 | rsz->resize_width = owidth; |
| 5037 | rsz->resize_height = oheight; |
| 5038 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
| 5039 | resize_denom); |
| 5040 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5041 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5042 | } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5043 | // Alter both resize and superres scales as needed to enforce conformity. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5044 | do { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5045 | if (resize_denom > rsz->superres_denom) |
| 5046 | --resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5047 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5048 | --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5049 | rsz->resize_width = owidth; |
| 5050 | rsz->resize_height = oheight; |
| 5051 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5052 | resize_denom); |
| 5053 | } while (!dimensions_are_ok(owidth, oheight, rsz) && |
| 5054 | (resize_denom > SCALE_NUMERATOR || |
| 5055 | rsz->superres_denom > SCALE_NUMERATOR)); |
| 5056 | } else { // We are allowed to alter neither resize scale nor superres scale. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5057 | return 0; |
| 5058 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5059 | return dimensions_are_ok(owidth, oheight, rsz); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5060 | } |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 5061 | #endif // CONFIG_HORZONLY_FRAME_SUPERRES |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5062 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5063 | // Calculates resize and superres params for next frame |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5064 | size_params_type av1_calculate_next_size_params(AV1_COMP *cpi) { |
| 5065 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
| 5066 | size_params_type rsz = { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5067 | oxcf->width, |
| 5068 | oxcf->height, |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 5069 | #if CONFIG_HORZONLY_FRAME_SUPERRES |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5070 | SCALE_NUMERATOR |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 5071 | #endif // CONFIG_HORZONLY_FRAME_SUPERRES |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5072 | }; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5073 | int resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5074 | if (oxcf->pass == 1) return rsz; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5075 | if (cpi->resize_pending_width && cpi->resize_pending_height) { |
| 5076 | rsz.resize_width = cpi->resize_pending_width; |
| 5077 | rsz.resize_height = cpi->resize_pending_height; |
| 5078 | cpi->resize_pending_width = cpi->resize_pending_height = 0; |
| 5079 | } else { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5080 | resize_denom = calculate_next_resize_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5081 | rsz.resize_width = cpi->oxcf.width; |
| 5082 | rsz.resize_height = cpi->oxcf.height; |
| 5083 | av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5084 | resize_denom); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5085 | } |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 5086 | #if CONFIG_HORZONLY_FRAME_SUPERRES |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5087 | rsz.superres_denom = calculate_next_superres_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5088 | if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width, |
| 5089 | oxcf->height, &rsz)) |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5090 | assert(0 && "Invalid scale parameters"); |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 5091 | #endif // CONFIG_HORZONLY_FRAME_SUPERRES |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5092 | return rsz; |
| 5093 | } |
| 5094 | |
| 5095 | static void setup_frame_size_from_params(AV1_COMP *cpi, size_params_type *rsz) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5096 | int encode_width = rsz->resize_width; |
| 5097 | int encode_height = rsz->resize_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5098 | |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 5099 | #if CONFIG_HORZONLY_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5100 | AV1_COMMON *cm = &cpi->common; |
| 5101 | cm->superres_upscaled_width = encode_width; |
| 5102 | cm->superres_upscaled_height = encode_height; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 5103 | cm->superres_scale_denominator = rsz->superres_denom; |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 5104 | av1_calculate_scaled_superres_size(&encode_width, &encode_height, |
| 5105 | rsz->superres_denom); |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 5106 | #endif // CONFIG_HORZONLY_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5107 | set_frame_size(cpi, encode_width, encode_height); |
| 5108 | } |
| 5109 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5110 | static void setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5111 | size_params_type rsz = av1_calculate_next_size_params(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5112 | setup_frame_size_from_params(cpi, &rsz); |
| 5113 | } |
| 5114 | |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 5115 | #if CONFIG_HORZONLY_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5116 | static void superres_post_encode(AV1_COMP *cpi) { |
| 5117 | AV1_COMMON *cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 5118 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5119 | |
| 5120 | if (av1_superres_unscaled(cm)) return; |
| 5121 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5122 | av1_superres_upscale(cm, NULL); |
| 5123 | |
| 5124 | // If regular resizing is occurring the source will need to be downscaled to |
| 5125 | // match the upscaled superres resolution. Otherwise the original source is |
| 5126 | // used. |
| 5127 | if (av1_resize_unscaled(cm)) { |
| 5128 | cpi->source = cpi->unscaled_source; |
| 5129 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 5130 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 5131 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 5132 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5133 | // Do downscale. cm->(width|height) has been updated by av1_superres_upscale |
| 5134 | if (aom_realloc_frame_buffer( |
| 5135 | &cpi->scaled_source, cm->superres_upscaled_width, |
| 5136 | cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 5137 | cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
| 5138 | NULL, NULL, NULL)) |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5139 | aom_internal_error( |
| 5140 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 5141 | "Failed to reallocate scaled source buffer for superres"); |
| 5142 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 5143 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5144 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 5145 | (int)cm->bit_depth, num_planes); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5146 | cpi->source = &cpi->scaled_source; |
| 5147 | } |
| 5148 | } |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 5149 | #endif // CONFIG_HORZONLY_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5150 | |
| 5151 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 5152 | const int num_planes = av1_num_planes(cm); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5153 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
| 5154 | struct loopfilter *lf = &cm->lf; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 5155 | int no_loopfilter = 0; |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 5156 | #if CONFIG_LOOP_RESTORATION |
Sebastien Alaiwan | 1ed2024 | 2018-02-20 14:47:18 +0100 | [diff] [blame] | 5157 | int no_restoration = !cpi->oxcf.using_restoration; |
Hui Su | 27a4fb6 | 2017-11-10 16:03:50 -0800 | [diff] [blame] | 5158 | #endif // CONFIG_LOOP_RESTORATION |
| 5159 | |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 5160 | if (is_lossless_requested(&cpi->oxcf) |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 5161 | #if CONFIG_EXT_TILE |
Jingning Han | da11e69 | 2017-12-19 08:45:08 -0800 | [diff] [blame] | 5162 | || cm->large_scale_tile |
Hui Su | 27df834 | 2017-11-07 15:16:05 -0800 | [diff] [blame] | 5163 | #endif // CONFIG_EXT_TILE |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 5164 | ) { |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 5165 | no_loopfilter = 1; |
Hui Su | 27a4fb6 | 2017-11-10 16:03:50 -0800 | [diff] [blame] | 5166 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 5167 | no_restoration = 1; |
Hui Su | 27a4fb6 | 2017-11-10 16:03:50 -0800 | [diff] [blame] | 5168 | #endif // CONFIG_LOOP_RESTORATION |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 5169 | } |
Steinar Midtskogen | e44c622 | 2017-11-09 13:22:09 +0100 | [diff] [blame] | 5170 | |
Hui Su | 27a4fb6 | 2017-11-10 16:03:50 -0800 | [diff] [blame] | 5171 | int no_cdef = 0; |
Steinar Midtskogen | e44c622 | 2017-11-09 13:22:09 +0100 | [diff] [blame] | 5172 | if (is_lossless_requested(&cpi->oxcf) || !cpi->oxcf.using_cdef |
| 5173 | #if CONFIG_EXT_TILE |
Jingning Han | da11e69 | 2017-12-19 08:45:08 -0800 | [diff] [blame] | 5174 | || cm->large_scale_tile |
Steinar Midtskogen | e44c622 | 2017-11-09 13:22:09 +0100 | [diff] [blame] | 5175 | #endif |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 5176 | ) { |
Steinar Midtskogen | e44c622 | 2017-11-09 13:22:09 +0100 | [diff] [blame] | 5177 | no_cdef = 1; |
| 5178 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 5179 | |
| 5180 | if (no_loopfilter) { |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 5181 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 5182 | lf->filter_level[0] = 0; |
| 5183 | lf->filter_level[1] = 0; |
| 5184 | #else |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5185 | lf->filter_level = 0; |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 5186 | #endif |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5187 | } else { |
| 5188 | struct aom_usec_timer timer; |
| 5189 | |
| 5190 | aom_clear_system_state(); |
| 5191 | |
| 5192 | aom_usec_timer_start(&timer); |
| 5193 | |
| 5194 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
| 5195 | |
| 5196 | aom_usec_timer_mark(&timer); |
| 5197 | cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer); |
| 5198 | } |
| 5199 | |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 5200 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 5201 | if (lf->filter_level[0] || lf->filter_level[1]) |
| 5202 | #else |
| 5203 | if (lf->filter_level > 0) |
| 5204 | #endif |
| 5205 | { |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 5206 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 5207 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level[0], |
| 5208 | lf->filter_level[1], 0, 0); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 5209 | if (num_planes > 1) { |
| 5210 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_u, |
| 5211 | lf->filter_level_u, 1, 0); |
| 5212 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_v, |
| 5213 | lf->filter_level_v, 2, 0); |
| 5214 | } |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 5215 | |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 5216 | #else |
| 5217 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0); |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 5218 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5219 | } |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 5220 | |
Debargha Mukherjee | a78c8f5 | 2018-01-31 11:14:38 -0800 | [diff] [blame] | 5221 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 5222 | if (!no_restoration) |
| 5223 | av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 0); |
Debargha Mukherjee | a78c8f5 | 2018-01-31 11:14:38 -0800 | [diff] [blame] | 5224 | #endif // CONFIG_LOOP_RESTORATION |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 5225 | |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 5226 | if (no_cdef) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5227 | cm->cdef_bits = 0; |
| 5228 | cm->cdef_strengths[0] = 0; |
| 5229 | cm->nb_cdef_strengths = 1; |
Yunqing Wang | dad63d4 | 2017-12-08 12:45:07 -0800 | [diff] [blame] | 5230 | cm->cdef_uv_strengths[0] = 0; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5231 | } else { |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 5232 | // Find CDEF parameters |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5233 | av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd, |
Debargha Mukherjee | d7338aa | 2017-11-04 07:34:50 -0700 | [diff] [blame] | 5234 | cpi->sf.fast_cdef_search); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5235 | |
| 5236 | // Apply the filter |
| 5237 | av1_cdef_frame(cm->frame_to_show, cm, xd); |
| 5238 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5239 | |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 5240 | #if CONFIG_HORZONLY_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5241 | superres_post_encode(cpi); |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 5242 | #endif // CONFIG_HORZONLY_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5243 | |
| 5244 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 5245 | if (no_restoration) { |
| 5246 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 5247 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 5248 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
| 5249 | } else { |
| 5250 | av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 1); |
| 5251 | av1_pick_filter_restoration(cpi->source, cpi); |
| 5252 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 5253 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 5254 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
Rupert Swarbrick | 70c399e | 2017-12-12 09:47:49 +0000 | [diff] [blame] | 5255 | av1_loop_restoration_filter_frame(cm->frame_to_show, cm); |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 5256 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5257 | } |
| 5258 | #endif // CONFIG_LOOP_RESTORATION |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 5259 | } |
| 5260 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5261 | static void encode_without_recode_loop(AV1_COMP *cpi) { |
| 5262 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5263 | int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5264 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5265 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5266 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 5267 | set_size_independent_vars(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5268 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 5269 | setup_frame_size(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5270 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5271 | assert(cm->width == cpi->scaled_source.y_crop_width); |
| 5272 | assert(cm->height == cpi->scaled_source.y_crop_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 5273 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5274 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 5275 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 5276 | cpi->source = |
| 5277 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
| 5278 | if (cpi->unscaled_last_source != NULL) |
| 5279 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 5280 | &cpi->scaled_last_source); |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 5281 | cpi->source->buf_8bit_valid = 0; |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 5282 | if (frame_is_intra_only(cm) == 0) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5283 | scale_references(cpi); |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 5284 | } |
| 5285 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5286 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5287 | setup_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5288 | suppress_active_map(cpi); |
hui su | ed5a30f | 2017-04-27 16:02:49 -0700 | [diff] [blame] | 5289 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5290 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 5291 | // exclusive. |
| 5292 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5293 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5294 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5295 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5296 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5297 | av1_cyclic_refresh_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5298 | } |
| 5299 | apply_active_map(cpi); |
| 5300 | |
| 5301 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5302 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5303 | |
| 5304 | // Update some stats from cyclic refresh, and check if we should not update |
| 5305 | // golden reference, for 1 pass CBR. |
| 5306 | if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->frame_type != KEY_FRAME && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5307 | (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR)) |
| 5308 | av1_cyclic_refresh_check_golden_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5309 | |
| 5310 | // Update the skip mb flag probabilities based on the distribution |
| 5311 | // seen in the last encoder iteration. |
| 5312 | // update_base_skip_probs(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5313 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5314 | } |
| 5315 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5316 | 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] | 5317 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5318 | RATE_CONTROL *const rc = &cpi->rc; |
| 5319 | int bottom_index, top_index; |
| 5320 | int loop_count = 0; |
| 5321 | int loop_at_this_size = 0; |
| 5322 | int loop = 0; |
| 5323 | int overshoot_seen = 0; |
| 5324 | int undershoot_seen = 0; |
| 5325 | int frame_over_shoot_limit; |
| 5326 | int frame_under_shoot_limit; |
| 5327 | int q = 0, q_low = 0, q_high = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5328 | |
| 5329 | set_size_independent_vars(cpi); |
| 5330 | |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 5331 | cpi->source->buf_8bit_valid = 0; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 5332 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5333 | aom_clear_system_state(); |
| 5334 | setup_frame_size(cpi); |
| 5335 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 5336 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5337 | do { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5338 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5339 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5340 | if (loop_count == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5341 | // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. |
| 5342 | set_mv_search_params(cpi); |
| 5343 | |
| 5344 | // Reset the loop state for new frame size. |
| 5345 | overshoot_seen = 0; |
| 5346 | undershoot_seen = 0; |
| 5347 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5348 | q_low = bottom_index; |
| 5349 | q_high = top_index; |
| 5350 | |
| 5351 | loop_at_this_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5352 | |
Urvang Joshi | 2a74cf2 | 2017-12-18 17:21:41 -0800 | [diff] [blame] | 5353 | // Decide frame size bounds first time through. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5354 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 5355 | &frame_under_shoot_limit, |
| 5356 | &frame_over_shoot_limit); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5357 | } |
| 5358 | |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 5359 | // if frame was scaled calculate global_motion_search again if already done |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5360 | if (loop_count > 0 && cpi->source && cpi->global_motion_search_done) |
| 5361 | if (cpi->source->y_crop_width != cm->width || |
| 5362 | cpi->source->y_crop_height != cm->height) |
| 5363 | cpi->global_motion_search_done = 0; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 5364 | cpi->source = |
| 5365 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 5366 | if (cpi->unscaled_last_source != NULL) |
| 5367 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 5368 | &cpi->scaled_last_source); |
| 5369 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5370 | if (frame_is_intra_only(cm) == 0) { |
| 5371 | if (loop_count > 0) { |
| 5372 | release_scaled_references(cpi); |
| 5373 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5374 | scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5375 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5376 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5377 | |
| 5378 | if (loop_count == 0) setup_frame(cpi); |
| 5379 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5380 | // Base q-index may have changed, so we need to assign proper default coef |
| 5381 | // probs before every iteration. |
| 5382 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5383 | av1_default_coef_probs(cm); |
Hui Su | 3694c83 | 2017-11-10 14:15:58 -0800 | [diff] [blame] | 5384 | av1_setup_frame_contexts(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5385 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5386 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5387 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 5388 | // exclusive. |
| 5389 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5390 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5391 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5392 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | // transform / motion compensation build reconstruction frame |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 5396 | save_coding_context(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5397 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5398 | |
| 5399 | // Update the skip mb flag probabilities based on the distribution |
| 5400 | // seen in the last encoder iteration. |
| 5401 | // update_base_skip_probs(cpi); |
| 5402 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5403 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5404 | |
| 5405 | // Dummy pack of the bitstream using up to date stats to get an |
| 5406 | // accurate estimate of output frame size to determine if we need |
| 5407 | // to recode. |
| 5408 | if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 5409 | restore_coding_context(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5410 | |
| 5411 | if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK) |
| 5412 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5413 | |
| 5414 | rc->projected_frame_size = (int)(*size) << 3; |
| 5415 | restore_coding_context(cpi); |
| 5416 | |
| 5417 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 5418 | } |
| 5419 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5420 | if (cpi->oxcf.rc_mode == AOM_Q) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5421 | loop = 0; |
| 5422 | } else { |
| 5423 | if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced && |
| 5424 | (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
| 5425 | int last_q = q; |
| 5426 | int64_t kf_err; |
| 5427 | |
| 5428 | int64_t high_err_target = cpi->ambient_err; |
| 5429 | int64_t low_err_target = cpi->ambient_err >> 1; |
| 5430 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5431 | if (cm->use_highbitdepth) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5432 | kf_err = aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5433 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5434 | kf_err = aom_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5435 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5436 | // Prevent possible divide by zero error below for perfect KF |
| 5437 | kf_err += !kf_err; |
| 5438 | |
| 5439 | // The key frame is not good enough or we can afford |
| 5440 | // to make it better without undue risk of popping. |
| 5441 | if ((kf_err > high_err_target && |
| 5442 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 5443 | (kf_err > low_err_target && |
| 5444 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 5445 | // Lower q_high |
| 5446 | q_high = q > q_low ? q - 1 : q_low; |
| 5447 | |
| 5448 | // Adjust Q |
| 5449 | q = (int)((q * high_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5450 | q = AOMMIN(q, (q_high + q_low) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5451 | } else if (kf_err < low_err_target && |
| 5452 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 5453 | // The key frame is much better than the previous frame |
| 5454 | // Raise q_low |
| 5455 | q_low = q < q_high ? q + 1 : q_high; |
| 5456 | |
| 5457 | // Adjust Q |
| 5458 | q = (int)((q * low_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5459 | q = AOMMIN(q, (q_high + q_low + 1) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5460 | } |
| 5461 | |
| 5462 | // Clamp Q to upper and lower limits: |
| 5463 | q = clamp(q, q_low, q_high); |
| 5464 | |
| 5465 | loop = q != last_q; |
| 5466 | } else if (recode_loop_test(cpi, frame_over_shoot_limit, |
| 5467 | frame_under_shoot_limit, q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5468 | AOMMAX(q_high, top_index), bottom_index)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5469 | // Is the projected frame size out of range and are we allowed |
| 5470 | // to attempt to recode. |
| 5471 | int last_q = q; |
| 5472 | int retries = 0; |
| 5473 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5474 | // Frame size out of permitted range: |
| 5475 | // Update correction factor & compute new Q to try... |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5476 | // Frame is too large |
| 5477 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 5478 | // Special case if the projected size is > the max allowed. |
| 5479 | if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
| 5480 | q_high = rc->worst_quality; |
| 5481 | |
| 5482 | // Raise Qlow as to at least the current value |
| 5483 | q_low = q < q_high ? q + 1 : q_high; |
| 5484 | |
| 5485 | if (undershoot_seen || loop_at_this_size > 1) { |
| 5486 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5487 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5488 | |
| 5489 | q = (q_high + q_low + 1) / 2; |
| 5490 | } else { |
| 5491 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5492 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5493 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5494 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5495 | AOMMAX(q_high, top_index), cm->width, |
| 5496 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5497 | |
| 5498 | while (q < q_low && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5499 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5500 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5501 | AOMMAX(q_high, top_index), cm->width, |
| 5502 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5503 | retries++; |
| 5504 | } |
| 5505 | } |
| 5506 | |
| 5507 | overshoot_seen = 1; |
| 5508 | } else { |
| 5509 | // Frame is too small |
| 5510 | q_high = q > q_low ? q - 1 : q_low; |
| 5511 | |
| 5512 | if (overshoot_seen || loop_at_this_size > 1) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5513 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5514 | q = (q_high + q_low) / 2; |
| 5515 | } else { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5516 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5517 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5518 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5519 | // Special case reset for qlow for constrained quality. |
| 5520 | // This should only trigger where there is very substantial |
| 5521 | // undershoot on a frame and the auto cq level is above |
| 5522 | // the user passsed in value. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5523 | if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5524 | q_low = q; |
| 5525 | } |
| 5526 | |
| 5527 | while (q > q_high && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5528 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5529 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5530 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5531 | retries++; |
| 5532 | } |
| 5533 | } |
| 5534 | |
| 5535 | undershoot_seen = 1; |
| 5536 | } |
| 5537 | |
| 5538 | // Clamp Q to upper and lower limits: |
| 5539 | q = clamp(q, q_low, q_high); |
| 5540 | |
| 5541 | loop = (q != last_q); |
| 5542 | } else { |
| 5543 | loop = 0; |
| 5544 | } |
| 5545 | } |
| 5546 | |
| 5547 | // Special case for overlay frame. |
| 5548 | if (rc->is_src_frame_alt_ref && |
| 5549 | rc->projected_frame_size < rc->max_frame_bandwidth) |
| 5550 | loop = 0; |
| 5551 | |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 5552 | if (recode_loop_test_global_motion(cpi)) { |
| 5553 | loop = 1; |
| 5554 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 5555 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5556 | if (loop) { |
| 5557 | ++loop_count; |
| 5558 | ++loop_at_this_size; |
| 5559 | |
| 5560 | #if CONFIG_INTERNAL_STATS |
| 5561 | ++cpi->tot_recode_hits; |
| 5562 | #endif |
| 5563 | } |
| 5564 | } while (loop); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5565 | |
| 5566 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5567 | } |
| 5568 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5569 | static int get_ref_frame_flags(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5570 | const int *const map = cpi->common.ref_frame_map; |
| 5571 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5572 | // No.1 Priority: LAST_FRAME |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5573 | const int last2_is_last = |
| 5574 | map[cpi->lst_fb_idxes[1]] == map[cpi->lst_fb_idxes[0]]; |
| 5575 | const int last3_is_last = |
| 5576 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[0]]; |
| 5577 | const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 5578 | const int bwd_is_last = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5579 | const int alt2_is_last = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5580 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 5581 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5582 | // No.2 Priority: ALTREF_FRAME |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5583 | const int last2_is_alt = map[cpi->lst_fb_idxes[1]] == map[cpi->alt_fb_idx]; |
| 5584 | const int last3_is_alt = map[cpi->lst_fb_idxes[2]] == map[cpi->alt_fb_idx]; |
| 5585 | const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 5586 | const int bwd_is_alt = map[cpi->bwd_fb_idx] == map[cpi->alt_fb_idx]; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5587 | const int alt2_is_alt = map[cpi->alt2_fb_idx] == map[cpi->alt_fb_idx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5588 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5589 | // No.3 Priority: LAST2_FRAME |
| 5590 | const int last3_is_last2 = |
| 5591 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]]; |
| 5592 | const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 5593 | const int bwd_is_last2 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 5594 | const int alt2_is_last2 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5595 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5596 | // No.4 Priority: LAST3_FRAME |
| 5597 | const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 5598 | const int bwd_is_last3 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 5599 | const int alt2_is_last3 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 5600 | |
| 5601 | // No.5 Priority: GOLDEN_FRAME |
| 5602 | const int bwd_is_gld = map[cpi->bwd_fb_idx] == map[cpi->gld_fb_idx]; |
| 5603 | const int alt2_is_gld = map[cpi->alt2_fb_idx] == map[cpi->gld_fb_idx]; |
| 5604 | |
| 5605 | // No.6 Priority: BWDREF_FRAME |
| 5606 | const int alt2_is_bwd = map[cpi->alt2_fb_idx] == map[cpi->bwd_fb_idx]; |
| 5607 | |
| 5608 | // No.7 Priority: ALTREF2_FRAME |
| 5609 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5610 | // After av1_apply_encoding_flags() is called, cpi->ref_frame_flags might be |
| 5611 | // adjusted according to external encoder flags. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 5612 | int flags = cpi->ext_ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5613 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5614 | if (cpi->rc.frames_till_gf_update_due == INT_MAX) flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5615 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5616 | if (alt_is_last) flags &= ~AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5617 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5618 | if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5619 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5620 | if (last3_is_last || last3_is_alt || last3_is_last2) flags &= ~AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5621 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5622 | if (gld_is_last || gld_is_alt || gld_is_last2 || gld_is_last3) |
| 5623 | flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5624 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5625 | if ((bwd_is_last || bwd_is_alt || bwd_is_last2 || bwd_is_last3 || |
| 5626 | bwd_is_gld) && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5627 | (flags & AOM_BWD_FLAG)) |
| 5628 | flags &= ~AOM_BWD_FLAG; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5629 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5630 | if ((alt2_is_last || alt2_is_alt || alt2_is_last2 || alt2_is_last3 || |
| 5631 | alt2_is_gld || alt2_is_bwd) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5632 | (flags & AOM_ALT2_FLAG)) |
| 5633 | flags &= ~AOM_ALT2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5634 | |
| 5635 | return flags; |
| 5636 | } |
| 5637 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5638 | static void set_ext_overrides(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5639 | // Overrides the defaults with the externally supplied values with |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5640 | // av1_update_reference() and av1_update_entropy() calls |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5641 | // Note: The overrides are valid only for the next frame passed |
| 5642 | // to encode_frame_to_data_rate() function |
| 5643 | if (cpi->ext_refresh_frame_context_pending) { |
| 5644 | cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context; |
| 5645 | cpi->ext_refresh_frame_context_pending = 0; |
| 5646 | } |
| 5647 | if (cpi->ext_refresh_frame_flags_pending) { |
| 5648 | cpi->refresh_last_frame = cpi->ext_refresh_last_frame; |
| 5649 | cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame; |
| 5650 | cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5651 | cpi->refresh_bwd_ref_frame = cpi->ext_refresh_bwd_ref_frame; |
| 5652 | cpi->refresh_alt2_ref_frame = cpi->ext_refresh_alt2_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5653 | cpi->ext_refresh_frame_flags_pending = 0; |
| 5654 | } |
| 5655 | } |
| 5656 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5657 | static int setup_interp_filter_search_mask(AV1_COMP *cpi) { |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 5658 | InterpFilter ifilter; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5659 | int ref_total[TOTAL_REFS_PER_FRAME] = { 0 }; |
| 5660 | MV_REFERENCE_FRAME ref; |
| 5661 | int mask = 0; |
| 5662 | int arf_idx = ALTREF_FRAME; |
| 5663 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5664 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame || |
| 5665 | cpi->refresh_alt2_ref_frame) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5666 | return mask; |
| 5667 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5668 | for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) |
| 5669 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) |
| 5670 | ref_total[ref] += cpi->interp_filter_selected[ref][ifilter]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5671 | |
| 5672 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) { |
| 5673 | if ((ref_total[LAST_FRAME] && |
| 5674 | cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5675 | (ref_total[LAST2_FRAME] == 0 || |
| 5676 | cpi->interp_filter_selected[LAST2_FRAME][ifilter] * 50 < |
| 5677 | ref_total[LAST2_FRAME]) && |
| 5678 | (ref_total[LAST3_FRAME] == 0 || |
| 5679 | cpi->interp_filter_selected[LAST3_FRAME][ifilter] * 50 < |
| 5680 | ref_total[LAST3_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5681 | (ref_total[GOLDEN_FRAME] == 0 || |
| 5682 | cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50 < |
| 5683 | ref_total[GOLDEN_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5684 | (ref_total[BWDREF_FRAME] == 0 || |
| 5685 | cpi->interp_filter_selected[BWDREF_FRAME][ifilter] * 50 < |
| 5686 | ref_total[BWDREF_FRAME]) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5687 | (ref_total[ALTREF2_FRAME] == 0 || |
| 5688 | cpi->interp_filter_selected[ALTREF2_FRAME][ifilter] * 50 < |
| 5689 | ref_total[ALTREF2_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5690 | (ref_total[ALTREF_FRAME] == 0 || |
| 5691 | cpi->interp_filter_selected[arf_idx][ifilter] * 50 < |
| 5692 | ref_total[ALTREF_FRAME])) |
| 5693 | mask |= 1 << ifilter; |
| 5694 | } |
| 5695 | return mask; |
| 5696 | } |
| 5697 | |
| 5698 | #define DUMP_RECON_FRAMES 0 |
| 5699 | |
| 5700 | #if DUMP_RECON_FRAMES == 1 |
| 5701 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5702 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 5703 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5704 | const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5705 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5706 | if (recon_buf == NULL) { |
| 5707 | printf("Frame %d is not ready.\n", cm->current_video_frame); |
| 5708 | return; |
| 5709 | } |
| 5710 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5711 | static const int flag_list[TOTAL_REFS_PER_FRAME] = { 0, |
| 5712 | AOM_LAST_FLAG, |
| 5713 | AOM_LAST2_FLAG, |
| 5714 | AOM_LAST3_FLAG, |
| 5715 | AOM_GOLD_FLAG, |
| 5716 | AOM_BWD_FLAG, |
| 5717 | AOM_ALT2_FLAG, |
| 5718 | AOM_ALT_FLAG }; |
| 5719 | printf( |
| 5720 | "\n***Frame=%d (frame_offset=%d, show_frame=%d, " |
| 5721 | "show_existing_frame=%d) " |
| 5722 | "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[", |
| 5723 | cm->current_video_frame, cm->frame_offset, cm->show_frame, |
| 5724 | cm->show_existing_frame); |
| 5725 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 5726 | const int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx; |
| 5727 | const int ref_offset = |
| 5728 | (buf_idx >= 0) |
| 5729 | ? (int)cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset |
| 5730 | : -1; |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 5731 | printf( |
| 5732 | " %d(%c-%d-%4.2f)", ref_offset, |
| 5733 | (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N', |
| 5734 | (buf_idx >= 0) ? (int)cpi->frame_rf_level[buf_idx] : -1, |
| 5735 | (buf_idx >= 0) ? rate_factor_deltas[cpi->frame_rf_level[buf_idx]] : -1); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5736 | } |
| 5737 | printf(" ]\n"); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5738 | |
| 5739 | if (!cm->show_frame) { |
| 5740 | printf("Frame %d is a no show frame, so no image dump.\n", |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5741 | cm->current_video_frame); |
| 5742 | return; |
| 5743 | } |
| 5744 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5745 | int h; |
| 5746 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 5747 | FILE *f_recon = NULL; |
| 5748 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5749 | if (cm->current_video_frame == 0) { |
| 5750 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 5751 | printf("Unable to open file %s to write.\n", file_name); |
| 5752 | return; |
| 5753 | } |
| 5754 | } else { |
| 5755 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 5756 | printf("Unable to open file %s to append.\n", file_name); |
| 5757 | return; |
| 5758 | } |
| 5759 | } |
| 5760 | printf( |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 5761 | "\nFrame=%5d, encode_update_type[%5d]=%1d, frame_offset=%d, " |
| 5762 | "show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, " |
| 5763 | "refresh_alt_ref_frame=%d, rf_level=%d, " |
| 5764 | "y_stride=%4d, uv_stride=%4d, cm->width=%4d, cm->height=%4d\n\n", |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5765 | cm->current_video_frame, cpi->twopass.gf_group.index, |
| 5766 | cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 5767 | cm->frame_offset, cm->show_frame, cm->show_existing_frame, |
| 5768 | cpi->rc.source_alt_ref_active, cpi->refresh_alt_ref_frame, |
| 5769 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index], |
| 5770 | recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5771 | #if 0 |
| 5772 | int ref_frame; |
| 5773 | printf("get_ref_frame_map_idx: ["); |
| 5774 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
| 5775 | printf(" %d", get_ref_frame_map_idx(cpi, ref_frame)); |
| 5776 | printf(" ]\n"); |
| 5777 | printf("cm->new_fb_idx = %d\n", cm->new_fb_idx); |
| 5778 | printf("cm->ref_frame_map = ["); |
| 5779 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 5780 | printf(" %d", cm->ref_frame_map[ref_frame - LAST_FRAME]); |
| 5781 | } |
| 5782 | printf(" ]\n"); |
| 5783 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5784 | |
| 5785 | // --- Y --- |
| 5786 | for (h = 0; h < cm->height; ++h) { |
| 5787 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 5788 | f_recon); |
| 5789 | } |
| 5790 | // --- U --- |
| 5791 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 5792 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 5793 | f_recon); |
| 5794 | } |
| 5795 | // --- V --- |
| 5796 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 5797 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 5798 | f_recon); |
| 5799 | } |
| 5800 | |
| 5801 | fclose(f_recon); |
| 5802 | } |
| 5803 | #endif // DUMP_RECON_FRAMES |
| 5804 | |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5805 | static void make_update_tile_list_enc(AV1_COMP *cpi, const int start_tile, |
| 5806 | const int num_tiles, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5807 | FRAME_CONTEXT *ec_ctxs[]) { |
| 5808 | int i; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5809 | for (i = start_tile; i < start_tile + num_tiles; ++i) |
| 5810 | ec_ctxs[i - start_tile] = &cpi->tile_data[i].tctx; |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5811 | } |
| 5812 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5813 | static int encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
| 5814 | int skip_adapt, |
| 5815 | unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5816 | AV1_COMMON *const cm = &cpi->common; |
| 5817 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5818 | struct segmentation *const seg = &cm->seg; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5819 | const int num_bwd_ctxs = 1; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5820 | |
| 5821 | FRAME_CONTEXT **tile_ctxs = |
| 5822 | aom_malloc(num_bwd_ctxs * sizeof(&cpi->tile_data[0].tctx)); |
| 5823 | aom_cdf_prob **cdf_ptrs = aom_malloc( |
| 5824 | num_bwd_ctxs * sizeof(&cpi->tile_data[0].tctx.partition_cdf[0][0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5825 | set_ext_overrides(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5826 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5827 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 5828 | // frame type has been decided outside of this function call |
| 5829 | cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only; |
Jingning Han | 2830fd9 | 2018-01-10 10:06:26 -0800 | [diff] [blame] | 5830 | cm->use_ref_frame_mvs = !cpi->oxcf.disable_tempmv && |
| 5831 | !cm->cur_frame->intra_only && |
| 5832 | frame_might_use_prev_frame_mvs(cm); |
Jingning Han | e17ebe9 | 2017-11-03 15:25:42 -0700 | [diff] [blame] | 5833 | cm->use_prev_frame_mvs = cm->use_ref_frame_mvs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5834 | |
Jingning Han | d8a15a6 | 2017-10-30 10:53:42 -0700 | [diff] [blame] | 5835 | // Reset the frame packet stamp index. |
| 5836 | if (cm->frame_type == KEY_FRAME) cm->current_video_frame = 0; |
| 5837 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5838 | // NOTE: |
| 5839 | // (1) Move the setup of the ref_frame_flags upfront as it would be |
| 5840 | // determined by the current frame properties; |
| 5841 | // (2) The setup of the ref_frame_flags applies to both show_existing_frame's |
| 5842 | // and the other cases. |
| 5843 | if (cm->current_video_frame > 0) |
| 5844 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 5845 | |
| 5846 | if (cm->show_existing_frame) { |
| 5847 | // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current |
| 5848 | // BWDREF_FRAME in the reference frame buffer. |
| 5849 | cm->frame_type = INTER_FRAME; |
| 5850 | cm->show_frame = 1; |
| 5851 | cpi->frame_flags = *frame_flags; |
| 5852 | |
| 5853 | // In the case of show_existing frame, we will not send fresh flag |
| 5854 | // to decoder. Any change in the reference frame buffer can be done by |
| 5855 | // switching the virtual indices. |
| 5856 | |
| 5857 | cpi->refresh_last_frame = 0; |
| 5858 | cpi->refresh_golden_frame = 0; |
| 5859 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5860 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5861 | cpi->refresh_alt_ref_frame = 0; |
| 5862 | |
| 5863 | cpi->rc.is_bwd_ref_frame = 0; |
| 5864 | cpi->rc.is_last_bipred_frame = 0; |
| 5865 | cpi->rc.is_bipred_frame = 0; |
| 5866 | |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 5867 | restore_coding_context(cpi); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5868 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5869 | // Build the bitstream |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5870 | if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK) |
| 5871 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5872 | |
| 5873 | // Set up frame to show to get ready for stats collection. |
| 5874 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 5875 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5876 | // Update current frame offset. |
| 5877 | cm->frame_offset = |
| 5878 | cm->buffer_pool->frame_bufs[cm->new_fb_idx].cur_frame_offset; |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5879 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5880 | #if DUMP_RECON_FRAMES == 1 |
| 5881 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 5882 | dump_filtered_recon_frames(cpi); |
| 5883 | #endif // DUMP_RECON_FRAMES |
| 5884 | |
| 5885 | // Update the LAST_FRAME in the reference frame buffer. |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5886 | // NOTE: |
| 5887 | // (1) For BWDREF_FRAME as the show_existing_frame, the reference frame |
| 5888 | // update has been done previously when handling the LAST_BIPRED_FRAME |
| 5889 | // right before BWDREF_FRAME (in the display order); |
| 5890 | // (2) For INTNL_OVERLAY as the show_existing_frame, the reference frame |
| 5891 | // update will be done when the following is called, which will exchange |
| 5892 | // the virtual indexes between LAST_FRAME and ALTREF2_FRAME, so that |
| 5893 | // LAST3 will get retired, LAST2 becomes LAST3, LAST becomes LAST2, and |
| 5894 | // ALTREF2_FRAME will serve as the new LAST_FRAME. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5895 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5896 | |
| 5897 | // Update frame flags |
| 5898 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 5899 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 5900 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 5901 | |
| 5902 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5903 | |
| 5904 | // Update the frame type |
| 5905 | cm->last_frame_type = cm->frame_type; |
| 5906 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5907 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 5908 | // to do post-encoding update accordingly. |
| 5909 | if (cpi->rc.is_src_frame_alt_ref) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5910 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5911 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5912 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5913 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5914 | ++cm->current_video_frame; |
| 5915 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5916 | aom_free(tile_ctxs); |
| 5917 | aom_free(cdf_ptrs); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5918 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5919 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5920 | |
| 5921 | // Set default state for segment based loop filter update flags. |
| 5922 | cm->lf.mode_ref_delta_update = 0; |
| 5923 | |
| 5924 | if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search) |
| 5925 | cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi); |
| 5926 | |
| 5927 | // Set various flags etc to special state if it is a key frame. |
| 5928 | if (frame_is_intra_only(cm)) { |
| 5929 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5930 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5931 | |
| 5932 | // If segmentation is enabled force a map update for key frames. |
| 5933 | if (seg->enabled) { |
| 5934 | seg->update_map = 1; |
| 5935 | seg->update_data = 1; |
| 5936 | } |
| 5937 | |
| 5938 | // The alternate reference frame cannot be active for a key frame. |
| 5939 | cpi->rc.source_alt_ref_active = 0; |
| 5940 | |
| 5941 | cm->error_resilient_mode = oxcf->error_resilient_mode; |
| 5942 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 5943 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5944 | // By default, encoder assumes decoder can use prev_mi. |
| 5945 | if (cm->error_resilient_mode) { |
| 5946 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
| 5947 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 5948 | } else if (cm->intra_only) { |
| 5949 | // Only reset the current context. |
| 5950 | cm->reset_frame_context = RESET_FRAME_CONTEXT_CURRENT; |
| 5951 | } |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 5952 | #if CONFIG_EXT_TILE |
| 5953 | if (cpi->oxcf.large_scale_tile) |
| 5954 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 5955 | #endif // CONFIG_EXT_TILE |
| 5956 | #endif // !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5957 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5958 | if (cpi->oxcf.mtu == 0) { |
| 5959 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 5960 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 5961 | // Use a default value for the purposes of weighting costs in probability |
| 5962 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5963 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 5964 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5965 | |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 5966 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 5967 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 5968 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Yunqing Wang | b6e23bc | 2017-11-15 13:18:55 -0800 | [diff] [blame] | 5969 | #if CONFIG_REFERENCE_BUFFER |
| 5970 | if (cm->large_scale_tile) cm->seq_params.frame_id_numbers_present_flag = 0; |
| 5971 | #endif // CONFIG_REFERENCE_BUFFER |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 5972 | #endif // CONFIG_EXT_TILE |
| 5973 | |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 5974 | #if CONFIG_MONO_VIDEO |
| 5975 | cm->seq_params.monochrome = oxcf->monochrome; |
| 5976 | #endif // CONFIG_MONO_VIDEO |
| 5977 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5978 | // For 1 pass CBR, check if we are dropping this frame. |
| 5979 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5980 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5981 | cm->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5982 | if (av1_rc_drop_frame(cpi)) { |
| 5983 | av1_rc_postencode_update_drop_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5984 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5985 | aom_free(tile_ctxs); |
| 5986 | aom_free(cdf_ptrs); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 5987 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5988 | } |
| 5989 | } |
| 5990 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5991 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5992 | |
| 5993 | #if CONFIG_INTERNAL_STATS |
| 5994 | memset(cpi->mode_chosen_counts, 0, |
| 5995 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 5996 | #endif |
| 5997 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5998 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 5999 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6000 | /* Non-normative definition of current_frame_id ("frame counter" with |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 6001 | * wraparound) */ |
Sebastien Alaiwan | d418f68 | 2017-10-19 15:06:52 +0200 | [diff] [blame] | 6002 | const int frame_id_length = FRAME_ID_LENGTH; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6003 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 6004 | int lsb, msb; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 6005 | /* quasi-random initialization of current_frame_id for a key frame */ |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6006 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 6007 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 6008 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 6009 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6010 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 6011 | msb = cpi->source->y_buffer[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 6012 | } |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 6013 | cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6014 | } else { |
| 6015 | cm->current_frame_id = |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 6016 | (cm->current_frame_id + 1 + (1 << frame_id_length)) % |
| 6017 | (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6018 | } |
| 6019 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 6020 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6021 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6022 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 6023 | encode_without_recode_loop(cpi); |
| 6024 | } else { |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6025 | if (encode_with_recode_loop(cpi, size, dest) != AOM_CODEC_OK) |
| 6026 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6027 | } |
| 6028 | |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 6029 | cm->last_tile_cols = cm->tile_cols; |
| 6030 | cm->last_tile_rows = cm->tile_rows; |
| 6031 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6032 | #ifdef OUTPUT_YUV_SKINMAP |
| 6033 | if (cpi->common.current_video_frame > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6034 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6035 | } |
| 6036 | #endif // OUTPUT_YUV_SKINMAP |
| 6037 | |
| 6038 | // Special case code to reduce pulsing when key frames are forced at a |
| 6039 | // fixed interval. Note the reconstruction error if it is the frame before |
| 6040 | // the force key frame |
| 6041 | if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6042 | if (cm->use_highbitdepth) { |
| 6043 | cpi->ambient_err = |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6044 | aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6045 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6046 | cpi->ambient_err = aom_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6047 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6048 | } |
| 6049 | |
| 6050 | // If the encoder forced a KEY_FRAME decision |
| 6051 | if (cm->frame_type == KEY_FRAME) { |
| 6052 | cpi->refresh_last_frame = 1; |
| 6053 | } |
| 6054 | |
| 6055 | cm->frame_to_show = get_frame_new_buffer(cm); |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 6056 | #if CONFIG_CICP |
| 6057 | cm->frame_to_show->color_primaries = cm->color_primaries; |
| 6058 | cm->frame_to_show->transfer_characteristics = cm->transfer_characteristics; |
| 6059 | cm->frame_to_show->matrix_coefficients = cm->matrix_coefficients; |
| 6060 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6061 | cm->frame_to_show->color_space = cm->color_space; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 6062 | #endif |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 6063 | #if CONFIG_MONO_VIDEO |
| 6064 | cm->frame_to_show->monochrome = cm->seq_params.monochrome; |
| 6065 | #endif // CONFIG_MONO_VIDEO |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 6066 | #if CONFIG_COLORSPACE_HEADERS |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 6067 | #if !CONFIG_CICP |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 6068 | cm->frame_to_show->transfer_function = cm->transfer_function; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 6069 | #endif |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 6070 | cm->frame_to_show->chroma_sample_position = cm->chroma_sample_position; |
| 6071 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6072 | cm->frame_to_show->color_range = cm->color_range; |
| 6073 | cm->frame_to_show->render_width = cm->render_width; |
| 6074 | cm->frame_to_show->render_height = cm->render_height; |
| 6075 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 6076 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 6077 | // off. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6078 | |
| 6079 | // Pick the loop filter level for the frame. |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 6080 | #if CONFIG_INTRABC |
| 6081 | if (!(cm->allow_intrabc && NO_FILTER_FOR_IBC)) |
| 6082 | #endif |
| 6083 | loopfilter_frame(cpi, cm); |
| 6084 | |
| 6085 | // TODO(debargha): Fix mv search range on encoder side |
| 6086 | // aom_extend_frame_inner_borders(cm->frame_to_show, av1_num_planes(cm)); |
| 6087 | aom_extend_frame_borders(cm->frame_to_show, av1_num_planes(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6088 | |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 6089 | #ifdef OUTPUT_YUV_REC |
| 6090 | aom_write_one_yuv_frame(cm, cm->frame_to_show); |
| 6091 | #endif |
| 6092 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6093 | // Build the bitstream |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6094 | if (av1_pack_bitstream(cpi, dest, size) != AOM_CODEC_OK) |
| 6095 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6096 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 6097 | if (skip_adapt) { |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 6098 | aom_free(tile_ctxs); |
| 6099 | aom_free(cdf_ptrs); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6100 | return AOM_CODEC_OK; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 6101 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6102 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6103 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 6104 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6105 | int i; |
| 6106 | /* Update reference frame id values based on the value of refresh_mask */ |
| 6107 | for (i = 0; i < REF_FRAMES; i++) { |
| 6108 | if ((cm->refresh_mask >> i) & 1) { |
| 6109 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 6110 | } |
| 6111 | } |
| 6112 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 6113 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6114 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6115 | #if DUMP_RECON_FRAMES == 1 |
| 6116 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 6117 | dump_filtered_recon_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6118 | #endif // DUMP_RECON_FRAMES |
| 6119 | |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 6120 | #if CONFIG_SEGMENT_PRED_LAST |
| 6121 | if (cm->seg.enabled) { |
| 6122 | if (cm->seg.update_map) { |
| 6123 | update_reference_segmentation_map(cpi); |
| 6124 | } else { |
| 6125 | memcpy(cm->current_frame_seg_map, cm->last_frame_seg_map, |
| 6126 | cm->mi_cols * cm->mi_rows * sizeof(uint8_t)); |
| 6127 | } |
| 6128 | } |
| 6129 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6130 | if (cm->seg.update_map) update_reference_segmentation_map(cpi); |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 6131 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6132 | |
| 6133 | if (frame_is_intra_only(cm) == 0) { |
| 6134 | release_scaled_references(cpi); |
| 6135 | } |
| 6136 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 6137 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6138 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 6139 | #if CONFIG_ENTROPY_STATS |
| 6140 | av1_accumulate_frame_counts(&aggregate_fc, &cm->counts); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 6141 | assert(cm->frame_context_idx < FRAME_CONTEXTS); |
| 6142 | av1_accumulate_frame_counts(&aggregate_fc_per_type[cm->frame_context_idx], |
| 6143 | &cm->counts); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 6144 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6145 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 6146 | make_update_tile_list_enc(cpi, cm->largest_tile_id, 1, tile_ctxs); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 6147 | av1_average_tile_coef_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 6148 | num_bwd_ctxs); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 6149 | av1_average_tile_intra_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 6150 | num_bwd_ctxs); |
Debargha Mukherjee | 43061b3 | 2017-10-13 16:50:17 -0700 | [diff] [blame] | 6151 | av1_average_tile_loopfilter_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
| 6152 | num_bwd_ctxs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | if (!frame_is_intra_only(cm)) { |
| 6156 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 6157 | av1_average_tile_inter_cdfs(&cpi->common, cpi->common.fc, tile_ctxs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 6158 | cdf_ptrs, num_bwd_ctxs); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 6159 | av1_average_tile_mv_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 6160 | num_bwd_ctxs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6161 | } |
| 6162 | } |
| 6163 | |
| 6164 | if (cpi->refresh_golden_frame == 1) |
| 6165 | cpi->frame_flags |= FRAMEFLAGS_GOLDEN; |
| 6166 | else |
| 6167 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 6168 | |
| 6169 | if (cpi->refresh_alt_ref_frame == 1) |
| 6170 | cpi->frame_flags |= FRAMEFLAGS_ALTREF; |
| 6171 | else |
| 6172 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 6173 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6174 | if (cpi->refresh_bwd_ref_frame == 1) |
| 6175 | cpi->frame_flags |= FRAMEFLAGS_BWDREF; |
| 6176 | else |
| 6177 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6178 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6179 | cm->last_frame_type = cm->frame_type; |
| 6180 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6181 | av1_rc_postencode_update(cpi, *size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6182 | |
| 6183 | #if 0 |
| 6184 | output_frame_level_debug_stats(cpi); |
| 6185 | #endif |
| 6186 | |
| 6187 | if (cm->frame_type == KEY_FRAME) { |
| 6188 | // Tell the caller that the frame was coded as a key frame |
| 6189 | *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY; |
| 6190 | } else { |
| 6191 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 6192 | } |
| 6193 | |
| 6194 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 6195 | // filter deltas. |
| 6196 | cm->seg.update_map = 0; |
| 6197 | cm->seg.update_data = 0; |
| 6198 | cm->lf.mode_ref_delta_update = 0; |
| 6199 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6200 | if (cm->show_frame) { |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 6201 | // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that are |
| 6202 | // being used as reference. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 6203 | swap_mi_and_prev_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6204 | // Don't increment frame counters if this was an altref buffer |
| 6205 | // update not a real frame |
| 6206 | ++cm->current_video_frame; |
| 6207 | } |
| 6208 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6209 | // NOTE: Shall not refer to any frame not used as reference. |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 6210 | if (cm->is_reference_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6211 | cm->prev_frame = cm->cur_frame; |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 6212 | // keep track of the last coded dimensions |
| 6213 | cm->last_width = cm->width; |
| 6214 | cm->last_height = cm->height; |
| 6215 | |
| 6216 | // reset to normal state now that we are done. |
| 6217 | cm->last_show_frame = cm->show_frame; |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 6218 | } |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 6219 | |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 6220 | aom_free(tile_ctxs); |
| 6221 | aom_free(cdf_ptrs); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6222 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6223 | } |
| 6224 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6225 | static int Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
| 6226 | int skip_adapt, unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6227 | if (cpi->oxcf.rc_mode == AOM_CBR) { |
| 6228 | av1_rc_get_one_pass_cbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6229 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6230 | av1_rc_get_one_pass_vbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6231 | } |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6232 | return encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6233 | } |
| 6234 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6235 | static int Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
| 6236 | unsigned int *frame_flags) { |
Angie Chiang | 5b5f4df | 2017-12-06 10:41:12 -0800 | [diff] [blame] | 6237 | #if CONFIG_MISMATCH_DEBUG |
| 6238 | mismatch_move_frame_idx_w(); |
| 6239 | #endif |
Angie Chiang | 4d55d76 | 2017-12-13 16:18:37 -0800 | [diff] [blame] | 6240 | #if TXCOEFF_COST_TIMER |
| 6241 | AV1_COMMON *cm = &cpi->common; |
| 6242 | cm->txcoeff_cost_timer = 0; |
| 6243 | cm->txcoeff_cost_count = 0; |
| 6244 | #endif |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6245 | |
| 6246 | if (encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags) != |
| 6247 | AOM_CODEC_OK) { |
| 6248 | return AOM_CODEC_ERROR; |
| 6249 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6250 | |
Angie Chiang | 4d55d76 | 2017-12-13 16:18:37 -0800 | [diff] [blame] | 6251 | #if TXCOEFF_COST_TIMER |
| 6252 | cm->cum_txcoeff_cost_timer += cm->txcoeff_cost_timer; |
| 6253 | fprintf(stderr, |
| 6254 | "\ntxb coeff cost block number: %ld, frame time: %ld, cum time %ld " |
| 6255 | "in us\n", |
| 6256 | cm->txcoeff_cost_count, cm->txcoeff_cost_timer, |
| 6257 | cm->cum_txcoeff_cost_timer); |
| 6258 | #endif |
| 6259 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6260 | // Do not do post-encoding update for those frames that do not have a spot in |
| 6261 | // a gf group, but note that an OVERLAY frame always has a spot in a gf group, |
| 6262 | // even when show_existing_frame is used. |
| 6263 | if (!cpi->common.show_existing_frame || cpi->rc.is_src_frame_alt_ref) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6264 | av1_twopass_postencode_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6265 | } |
| 6266 | check_show_existing_frame(cpi); |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6267 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6268 | } |
| 6269 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 6270 | 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] | 6271 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 6272 | int64_t end_time) { |
| 6273 | AV1_COMMON *const cm = &cpi->common; |
| 6274 | struct aom_usec_timer timer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6275 | int res = 0; |
| 6276 | const int subsampling_x = sd->subsampling_x; |
| 6277 | const int subsampling_y = sd->subsampling_y; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6278 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6279 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6280 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6281 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6282 | aom_usec_timer_start(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6283 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6284 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 6285 | use_highbitdepth, frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6286 | res = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6287 | aom_usec_timer_mark(&timer); |
| 6288 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6289 | |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 6290 | if ((cm->profile == PROFILE_0) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6291 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6292 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 6293 | "Non-4:2:0 color format requires profile 1 or 2"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6294 | res = -1; |
| 6295 | } |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 6296 | if ((cm->profile == PROFILE_1) && |
| 6297 | !(subsampling_x == 0 && subsampling_y == 0)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6298 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 6299 | "Profile 1 requires 4:4:4 color format"); |
| 6300 | res = -1; |
| 6301 | } |
| 6302 | if ((cm->profile == PROFILE_2) && (cm->bit_depth <= AOM_BITS_10) && |
| 6303 | !(subsampling_x == 1 && subsampling_y == 0)) { |
| 6304 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
| 6305 | "Profile 2 bit-depth < 10 requires 4:2:2 color format"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6306 | res = -1; |
| 6307 | } |
| 6308 | |
| 6309 | return res; |
| 6310 | } |
| 6311 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6312 | static int frame_is_reference(const AV1_COMP *cpi) { |
| 6313 | const AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6314 | |
| 6315 | return cm->frame_type == KEY_FRAME || cpi->refresh_last_frame || |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 6316 | cpi->refresh_golden_frame || cpi->refresh_bwd_ref_frame || |
| 6317 | cpi->refresh_alt2_ref_frame || cpi->refresh_alt_ref_frame || |
| 6318 | !cm->error_resilient_mode || cm->lf.mode_ref_delta_update || |
| 6319 | cm->seg.update_map || cm->seg.update_data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6320 | } |
| 6321 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6322 | static void adjust_frame_rate(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6323 | const struct lookahead_entry *source) { |
| 6324 | int64_t this_duration; |
| 6325 | int step = 0; |
| 6326 | |
| 6327 | if (source->ts_start == cpi->first_time_stamp_ever) { |
| 6328 | this_duration = source->ts_end - source->ts_start; |
| 6329 | step = 1; |
| 6330 | } else { |
| 6331 | int64_t last_duration = |
| 6332 | cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen; |
| 6333 | |
| 6334 | this_duration = source->ts_end - cpi->last_end_time_stamp_seen; |
| 6335 | |
| 6336 | // do a step update if the duration changes by 10% |
| 6337 | if (last_duration) |
| 6338 | step = (int)((this_duration - last_duration) * 10 / last_duration); |
| 6339 | } |
| 6340 | |
| 6341 | if (this_duration) { |
| 6342 | if (step) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6343 | av1_new_framerate(cpi, 10000000.0 / this_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6344 | } else { |
| 6345 | // Average this frame's rate into the last second's average |
| 6346 | // frame rate. If we haven't seen 1 second yet, then average |
| 6347 | // over the whole interval seen. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6348 | const double interval = AOMMIN( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6349 | (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0); |
| 6350 | double avg_duration = 10000000.0 / cpi->framerate; |
| 6351 | avg_duration *= (interval - avg_duration + this_duration); |
| 6352 | avg_duration /= interval; |
| 6353 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6354 | av1_new_framerate(cpi, 10000000.0 / avg_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6355 | } |
| 6356 | } |
| 6357 | cpi->last_time_stamp_seen = source->ts_start; |
| 6358 | cpi->last_end_time_stamp_seen = source->ts_end; |
| 6359 | } |
| 6360 | |
| 6361 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 6362 | // used as the arf midpoint. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6363 | static int get_arf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6364 | RATE_CONTROL *const rc = &cpi->rc; |
| 6365 | int arf_src_index = 0; |
| 6366 | if (is_altref_enabled(cpi)) { |
| 6367 | if (cpi->oxcf.pass == 2) { |
| 6368 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 6369 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 6370 | arf_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 6371 | } |
| 6372 | } else if (rc->source_alt_ref_pending) { |
| 6373 | arf_src_index = rc->frames_till_gf_update_due; |
| 6374 | } |
| 6375 | } |
| 6376 | return arf_src_index; |
| 6377 | } |
| 6378 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6379 | static int get_brf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6380 | int brf_src_index = 0; |
| 6381 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 6382 | |
| 6383 | // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup |
| 6384 | // flag. |
| 6385 | if (gf_group->bidir_pred_enabled[gf_group->index]) { |
| 6386 | if (cpi->oxcf.pass == 2) { |
| 6387 | if (gf_group->update_type[gf_group->index] == BRF_UPDATE) |
| 6388 | brf_src_index = gf_group->brf_src_offset[gf_group->index]; |
| 6389 | } else { |
| 6390 | // TODO(zoeliu): To re-visit the setup for this scenario |
| 6391 | brf_src_index = cpi->rc.bipred_group_interval - 1; |
| 6392 | } |
| 6393 | } |
| 6394 | |
| 6395 | return brf_src_index; |
| 6396 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6397 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6398 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 6399 | // used as the arf midpoint. |
| 6400 | static int get_arf2_src_index(AV1_COMP *cpi) { |
| 6401 | int arf2_src_index = 0; |
| 6402 | if (is_altref_enabled(cpi) && cpi->num_extra_arfs) { |
| 6403 | if (cpi->oxcf.pass == 2) { |
| 6404 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 6405 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) { |
| 6406 | arf2_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 6407 | } |
| 6408 | } |
| 6409 | } |
| 6410 | return arf2_src_index; |
| 6411 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6412 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6413 | static void check_src_altref(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6414 | const struct lookahead_entry *source) { |
| 6415 | RATE_CONTROL *const rc = &cpi->rc; |
| 6416 | |
| 6417 | // If pass == 2, the parameters set here will be reset in |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6418 | // av1_rc_get_second_pass_params() |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6419 | |
| 6420 | if (cpi->oxcf.pass == 2) { |
| 6421 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 6422 | rc->is_src_frame_alt_ref = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6423 | (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) || |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6424 | (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6425 | rc->is_src_frame_ext_arf = |
| 6426 | gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6427 | } else { |
| 6428 | rc->is_src_frame_alt_ref = |
| 6429 | cpi->alt_ref_source && (source == cpi->alt_ref_source); |
| 6430 | } |
| 6431 | |
| 6432 | if (rc->is_src_frame_alt_ref) { |
| 6433 | // Current frame is an ARF overlay frame. |
| 6434 | cpi->alt_ref_source = NULL; |
| 6435 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6436 | if (rc->is_src_frame_ext_arf && !cpi->common.show_existing_frame) { |
| 6437 | // For INTNL_OVERLAY, when show_existing_frame == 0, they do need to |
| 6438 | // refresh the LAST_FRAME, i.e. LAST3 gets retired, LAST2 becomes LAST3, |
| 6439 | // LAST becomes LAST2, and INTNL_OVERLAY becomes LAST. |
| 6440 | cpi->refresh_last_frame = 1; |
| 6441 | } else { |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6442 | // Don't refresh the last buffer for an ARF overlay frame. It will |
| 6443 | // become the GF so preserve last as an alternative prediction option. |
| 6444 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6445 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6446 | } |
| 6447 | } |
| 6448 | |
| 6449 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6450 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 6451 | const unsigned char *img2, int img2_pitch, |
| 6452 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6453 | |
| 6454 | static void adjust_image_stat(double y, double u, double v, double all, |
| 6455 | ImageStat *s) { |
| 6456 | s->stat[Y] += y; |
| 6457 | s->stat[U] += u; |
| 6458 | s->stat[V] += v; |
| 6459 | s->stat[ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6460 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6461 | } |
| 6462 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6463 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6464 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6465 | double samples = 0.0; |
| 6466 | uint32_t in_bit_depth = 8; |
| 6467 | uint32_t bit_depth = 8; |
| 6468 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6469 | #if CONFIG_INTER_STATS_ONLY |
Yaowu Xu | 1b4ffc4 | 2017-07-26 09:54:07 -0700 | [diff] [blame] | 6470 | if (cm->frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6471 | #endif |
| 6472 | cpi->bytes += frame_bytes; |
| 6473 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6474 | if (cm->use_highbitdepth) { |
| 6475 | in_bit_depth = cpi->oxcf.input_bit_depth; |
| 6476 | bit_depth = cm->bit_depth; |
| 6477 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6478 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6479 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6480 | const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; |
| 6481 | double y, u, v, frame_all; |
| 6482 | |
| 6483 | cpi->count++; |
| 6484 | if (cpi->b_calculate_psnr) { |
| 6485 | PSNR_STATS psnr; |
| 6486 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6487 | aom_clear_system_state(); |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 6488 | // TODO(yaowu): unify these two versions into one. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6489 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6490 | |
| 6491 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 6492 | &cpi->psnr); |
| 6493 | cpi->total_sq_error += psnr.sse[0]; |
| 6494 | cpi->total_samples += psnr.samples[0]; |
| 6495 | samples = psnr.samples[0]; |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 6496 | // TODO(yaowu): unify these two versions into one. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6497 | if (cm->use_highbitdepth) |
| 6498 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6499 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6500 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6501 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6502 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6503 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6504 | cpi->summed_quality += frame_ssim2 * weight; |
| 6505 | cpi->summed_weights += weight; |
| 6506 | |
| 6507 | #if 0 |
| 6508 | { |
| 6509 | FILE *f = fopen("q_used.stt", "a"); |
Zoe Liu | ee202be | 2017-11-17 12:14:33 -0800 | [diff] [blame] | 6510 | double y2 = psnr.psnr[1]; |
| 6511 | double u2 = psnr.psnr[2]; |
| 6512 | double v2 = psnr.psnr[3]; |
| 6513 | double frame_psnr2 = psnr.psnr[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6514 | fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", |
Zoe Liu | ee202be | 2017-11-17 12:14:33 -0800 | [diff] [blame] | 6515 | cm->current_video_frame, y2, u2, v2, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6516 | frame_psnr2, frame_ssim2); |
| 6517 | fclose(f); |
| 6518 | } |
| 6519 | #endif |
| 6520 | } |
| 6521 | if (cpi->b_calculate_blockiness) { |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 6522 | if (!cm->use_highbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6523 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6524 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 6525 | recon->y_stride, orig->y_width, orig->y_height); |
| 6526 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6527 | cpi->total_blockiness += frame_blockiness; |
| 6528 | } |
| 6529 | |
| 6530 | if (cpi->b_calculate_consistency) { |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 6531 | if (!cm->use_highbitdepth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6532 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6533 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 6534 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 6535 | |
| 6536 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 6537 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6538 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6539 | if (consistency > 0.0) |
| 6540 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6541 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6542 | cpi->total_inconsistency += this_inconsistency; |
| 6543 | } |
| 6544 | } |
| 6545 | } |
| 6546 | |
| 6547 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6548 | 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] | 6549 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6550 | 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] | 6551 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 6552 | } |
| 6553 | } |
| 6554 | #endif // CONFIG_INTERNAL_STATS |
| 6555 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6556 | #if CONFIG_AMVR |
| 6557 | static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture, |
| 6558 | const YV12_BUFFER_CONFIG *last_picture, |
| 6559 | hash_table *last_hash_table) { |
| 6560 | aom_clear_system_state(); |
| 6561 | // check use hash ME |
| 6562 | int k; |
| 6563 | uint32_t hash_value_1; |
| 6564 | uint32_t hash_value_2; |
| 6565 | |
| 6566 | const int block_size = 8; |
| 6567 | const double threshold_current = 0.8; |
| 6568 | const double threshold_average = 0.95; |
| 6569 | const int max_history_size = 32; |
| 6570 | int T = 0; // total block |
| 6571 | int C = 0; // match with collocated block |
| 6572 | int S = 0; // smooth region but not match with collocated block |
| 6573 | int M = 0; // match with other block |
| 6574 | |
| 6575 | const int pic_width = cur_picture->y_width; |
| 6576 | const int pic_height = cur_picture->y_height; |
| 6577 | for (int i = 0; i + block_size <= pic_height; i += block_size) { |
| 6578 | for (int j = 0; j + block_size <= pic_width; j += block_size) { |
| 6579 | const int x_pos = j; |
| 6580 | const int y_pos = i; |
| 6581 | int match = 1; |
| 6582 | T++; |
| 6583 | |
| 6584 | // check whether collocated block match with current |
| 6585 | uint8_t *p_cur = cur_picture->y_buffer; |
| 6586 | uint8_t *p_ref = last_picture->y_buffer; |
| 6587 | int stride_cur = cur_picture->y_stride; |
| 6588 | int stride_ref = last_picture->y_stride; |
| 6589 | p_cur += (y_pos * stride_cur + x_pos); |
| 6590 | p_ref += (y_pos * stride_ref + x_pos); |
| 6591 | |
| 6592 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 6593 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 6594 | if (p_cur[tmpX] != p_ref[tmpX]) { |
| 6595 | match = 0; |
| 6596 | } |
| 6597 | } |
| 6598 | p_cur += stride_cur; |
| 6599 | p_ref += stride_ref; |
| 6600 | } |
| 6601 | |
| 6602 | if (match) { |
| 6603 | C++; |
| 6604 | continue; |
| 6605 | } |
| 6606 | |
| 6607 | if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos, |
| 6608 | y_pos) || |
| 6609 | av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) { |
| 6610 | S++; |
| 6611 | continue; |
| 6612 | } |
| 6613 | |
| 6614 | av1_get_block_hash_value( |
| 6615 | cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur, |
| 6616 | block_size, &hash_value_1, &hash_value_2); |
| 6617 | |
| 6618 | if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) { |
| 6619 | M++; |
| 6620 | } |
| 6621 | } |
| 6622 | } |
| 6623 | |
| 6624 | assert(T > 0); |
| 6625 | double csm_rate = ((double)(C + S + M)) / ((double)(T)); |
| 6626 | double m_rate = ((double)(M)) / ((double)(T)); |
| 6627 | |
| 6628 | cpi->csm_rate_array[cpi->rate_index] = csm_rate; |
| 6629 | cpi->m_rate_array[cpi->rate_index] = m_rate; |
| 6630 | |
| 6631 | cpi->rate_index = (cpi->rate_index + 1) % max_history_size; |
| 6632 | cpi->rate_size++; |
| 6633 | cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size); |
| 6634 | |
| 6635 | if (csm_rate < threshold_current) { |
| 6636 | return 0; |
| 6637 | } |
| 6638 | |
| 6639 | if (C == T) { |
| 6640 | return 1; |
| 6641 | } |
| 6642 | |
| 6643 | double csm_average = 0.0; |
| 6644 | double m_average = 0.0; |
| 6645 | |
| 6646 | for (k = 0; k < cpi->rate_size; k++) { |
| 6647 | csm_average += cpi->csm_rate_array[k]; |
| 6648 | m_average += cpi->m_rate_array[k]; |
| 6649 | } |
| 6650 | csm_average /= cpi->rate_size; |
| 6651 | m_average /= cpi->rate_size; |
| 6652 | |
| 6653 | if (csm_average < threshold_average) { |
| 6654 | return 0; |
| 6655 | } |
| 6656 | |
| 6657 | if (M > (T - C - S) / 3) { |
| 6658 | return 1; |
| 6659 | } |
| 6660 | |
| 6661 | if (csm_rate > 0.99 && m_rate > 0.01) { |
| 6662 | return 1; |
| 6663 | } |
| 6664 | |
| 6665 | if (csm_average + m_average > 1.01) { |
| 6666 | return 1; |
| 6667 | } |
| 6668 | |
| 6669 | return 0; |
| 6670 | } |
| 6671 | #endif |
| 6672 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6673 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 6674 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 6675 | int64_t *time_end, int flush) { |
| 6676 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 6677 | AV1_COMMON *const cm = &cpi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 6678 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6679 | BufferPool *const pool = cm->buffer_pool; |
| 6680 | RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6681 | struct aom_usec_timer cmptimer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6682 | YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
| 6683 | struct lookahead_entry *last_source = NULL; |
| 6684 | struct lookahead_entry *source = NULL; |
| 6685 | int arf_src_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6686 | int brf_src_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6687 | int i; |
| 6688 | |
| 6689 | #if CONFIG_BITSTREAM_DEBUG |
| 6690 | assert(cpi->oxcf.max_threads == 0 && |
| 6691 | "bitstream debug tool does not support multithreading"); |
| 6692 | bitstream_queue_record_write(); |
Angie Chiang | cb9a9eb | 2016-09-01 16:10:50 -0700 | [diff] [blame] | 6693 | bitstream_queue_set_frame_write(cm->current_video_frame * 2 + cm->show_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6694 | #endif |
| 6695 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6696 | aom_usec_timer_start(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6697 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6698 | #if CONFIG_AMVR |
| 6699 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0); |
| 6700 | #else |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 6701 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6702 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6703 | |
| 6704 | // Is multi-arf enabled. |
| 6705 | // Note that at the moment multi_arf is only configured for 2 pass VBR |
| 6706 | if ((oxcf->pass == 2) && (cpi->oxcf.enable_auto_arf > 1)) |
| 6707 | cpi->multi_arf_allowed = 1; |
| 6708 | else |
| 6709 | cpi->multi_arf_allowed = 0; |
| 6710 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 6711 | // Normal defaults |
| 6712 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6713 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 6714 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6715 | cm->refresh_frame_context = |
| 6716 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 6717 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 6718 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 6719 | #if CONFIG_EXT_TILE |
| 6720 | if (oxcf->large_scale_tile) |
| 6721 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 6722 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6723 | |
| 6724 | cpi->refresh_last_frame = 1; |
| 6725 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6726 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6727 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6728 | cpi->refresh_alt_ref_frame = 0; |
| 6729 | |
Zoe Liu | b499120 | 2017-12-21 15:31:06 -0800 | [diff] [blame] | 6730 | #if CONFIG_FWD_KF |
| 6731 | // TODO(zoeliu@gmail.com): To support forward-KEY_FRAME and set up the |
| 6732 | // following flag accordingly. |
| 6733 | cm->reset_decoder_state = 0; |
| 6734 | #endif // CONFIG_FWD_KF |
| 6735 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6736 | if (oxcf->pass == 2 && cm->show_existing_frame) { |
| 6737 | // Manage the source buffer and flush out the source frame that has been |
| 6738 | // coded already; Also get prepared for PSNR calculation if needed. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6739 | if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6740 | *size = 0; |
| 6741 | return -1; |
| 6742 | } |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6743 | cpi->source = &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6744 | // TODO(zoeliu): To track down to determine whether it's needed to adjust |
| 6745 | // the frame rate. |
| 6746 | *time_stamp = source->ts_start; |
| 6747 | *time_end = source->ts_end; |
| 6748 | |
| 6749 | // We need to adjust frame rate for an overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 6750 | if (cpi->rc.is_src_frame_alt_ref) adjust_frame_rate(cpi, source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6751 | |
| 6752 | // Find a free buffer for the new frame, releasing the reference previously |
| 6753 | // held. |
| 6754 | if (cm->new_fb_idx != INVALID_IDX) { |
| 6755 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 6756 | } |
| 6757 | cm->new_fb_idx = get_free_fb(cm); |
| 6758 | |
| 6759 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 6760 | |
| 6761 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6762 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6763 | |
| 6764 | // Start with a 0 size frame. |
| 6765 | *size = 0; |
| 6766 | |
| 6767 | // We need to update the gf_group for show_existing overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 6768 | if (cpi->rc.is_src_frame_alt_ref) av1_rc_get_second_pass_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6769 | |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 6770 | if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK) |
| 6771 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6772 | |
| 6773 | if (cpi->b_calculate_psnr) generate_psnr_packet(cpi); |
| 6774 | |
| 6775 | #if CONFIG_INTERNAL_STATS |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6776 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6777 | #endif // CONFIG_INTERNAL_STATS |
| 6778 | |
| 6779 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6780 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6781 | |
| 6782 | cm->show_existing_frame = 0; |
| 6783 | return 0; |
| 6784 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6785 | |
| 6786 | // Should we encode an arf frame. |
| 6787 | arf_src_index = get_arf_src_index(cpi); |
| 6788 | if (arf_src_index) { |
| 6789 | for (i = 0; i <= arf_src_index; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6790 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6791 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 6792 | if (e == NULL) { |
| 6793 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6794 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6795 | arf_src_index = 0; |
| 6796 | flush = 1; |
| 6797 | break; |
| 6798 | } |
| 6799 | } |
| 6800 | } |
| 6801 | |
| 6802 | if (arf_src_index) { |
| 6803 | assert(arf_src_index <= rc->frames_to_key); |
| 6804 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6805 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6806 | cpi->alt_ref_source = source; |
| 6807 | |
| 6808 | if (oxcf->arnr_max_frames > 0) { |
Sebastien Alaiwan | 6697acf | 2018-02-21 16:59:17 +0100 | [diff] [blame] | 6809 | // Produce the filtered ARF frame. |
| 6810 | av1_temporal_filter(cpi, arf_src_index); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 6811 | aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6812 | force_src_buffer = &cpi->alt_ref_buffer; |
| 6813 | } |
| 6814 | |
| 6815 | cm->show_frame = 0; |
| 6816 | cm->intra_only = 0; |
| 6817 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6818 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6819 | cpi->refresh_golden_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6820 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6821 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6822 | rc->is_src_frame_alt_ref = 0; |
| 6823 | } |
| 6824 | rc->source_alt_ref_pending = 0; |
| 6825 | } |
| 6826 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6827 | // Should we encode an arf2 frame. |
| 6828 | arf_src_index = get_arf2_src_index(cpi); |
| 6829 | if (arf_src_index) { |
| 6830 | for (i = 0; i <= arf_src_index; ++i) { |
| 6831 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
| 6832 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 6833 | if (e == NULL) { |
| 6834 | break; |
| 6835 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
| 6836 | arf_src_index = 0; |
| 6837 | flush = 1; |
| 6838 | break; |
| 6839 | } |
| 6840 | } |
| 6841 | } |
| 6842 | |
| 6843 | if (arf_src_index) { |
| 6844 | assert(arf_src_index <= rc->frames_to_key); |
| 6845 | |
| 6846 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
| 6847 | cpi->alt_ref_source = source; |
| 6848 | |
| 6849 | if (oxcf->arnr_max_frames > 0) { |
| 6850 | // Produce the filtered ARF frame. |
Sebastien Alaiwan | 6697acf | 2018-02-21 16:59:17 +0100 | [diff] [blame] | 6851 | av1_temporal_filter(cpi, arf_src_index); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 6852 | aom_extend_frame_borders(&cpi->alt_ref_buffer, num_planes); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6853 | force_src_buffer = &cpi->alt_ref_buffer; |
| 6854 | } |
| 6855 | |
| 6856 | cm->show_frame = 0; |
| 6857 | cm->intra_only = 0; |
| 6858 | cpi->refresh_alt2_ref_frame = 1; |
| 6859 | cpi->refresh_last_frame = 0; |
| 6860 | cpi->refresh_golden_frame = 0; |
| 6861 | cpi->refresh_bwd_ref_frame = 0; |
| 6862 | cpi->refresh_alt_ref_frame = 0; |
| 6863 | rc->is_src_frame_alt_ref = 0; |
| 6864 | rc->is_src_frame_ext_arf = 0; |
| 6865 | } |
| 6866 | rc->source_alt_ref_pending = 0; |
| 6867 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6868 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6869 | rc->is_bwd_ref_frame = 0; |
| 6870 | brf_src_index = get_brf_src_index(cpi); |
| 6871 | if (brf_src_index) { |
| 6872 | assert(brf_src_index <= rc->frames_to_key); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6873 | if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6874 | cm->show_frame = 0; |
| 6875 | cm->intra_only = 0; |
| 6876 | |
| 6877 | cpi->refresh_bwd_ref_frame = 1; |
| 6878 | cpi->refresh_last_frame = 0; |
| 6879 | cpi->refresh_golden_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6880 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6881 | cpi->refresh_alt_ref_frame = 0; |
| 6882 | |
| 6883 | rc->is_bwd_ref_frame = 1; |
| 6884 | } |
| 6885 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6886 | |
| 6887 | if (!source) { |
| 6888 | // Get last frame source. |
| 6889 | if (cm->current_video_frame > 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6890 | if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6891 | return -1; |
| 6892 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 6893 | if (cm->current_video_frame > 0) assert(last_source != NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6894 | // Read in the source frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6895 | source = av1_lookahead_pop(cpi->lookahead, flush); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6896 | |
| 6897 | if (source != NULL) { |
| 6898 | cm->show_frame = 1; |
| 6899 | cm->intra_only = 0; |
| 6900 | |
| 6901 | // Check to see if the frame should be encoded as an arf overlay. |
| 6902 | check_src_altref(cpi, source); |
| 6903 | } |
| 6904 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6905 | if (source) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 6906 | cpi->unscaled_source = cpi->source = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6907 | force_src_buffer ? force_src_buffer : &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6908 | cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL; |
| 6909 | |
| 6910 | *time_stamp = source->ts_start; |
| 6911 | *time_end = source->ts_end; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6912 | *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6913 | |
| 6914 | } else { |
| 6915 | *size = 0; |
| 6916 | if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6917 | av1_end_first_pass(cpi); /* get last stats packet */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6918 | cpi->twopass.first_pass_done = 1; |
| 6919 | } |
| 6920 | return -1; |
| 6921 | } |
| 6922 | |
| 6923 | if (source->ts_start < cpi->first_time_stamp_ever) { |
| 6924 | cpi->first_time_stamp_ever = source->ts_start; |
| 6925 | cpi->last_end_time_stamp_seen = source->ts_start; |
| 6926 | } |
| 6927 | |
| 6928 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6929 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6930 | |
| 6931 | // adjust frame rates based on timestamps given |
| 6932 | if (cm->show_frame) adjust_frame_rate(cpi, source); |
| 6933 | |
| 6934 | // Find a free buffer for the new frame, releasing the reference previously |
| 6935 | // held. |
| 6936 | if (cm->new_fb_idx != INVALID_IDX) { |
| 6937 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 6938 | } |
| 6939 | cm->new_fb_idx = get_free_fb(cm); |
| 6940 | |
| 6941 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 6942 | |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 6943 | // Retain the RF_LEVEL for the current newly coded frame. |
| 6944 | cpi->frame_rf_level[cm->new_fb_idx] = |
| 6945 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index]; |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 6946 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6947 | cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 6948 | cm->cur_frame->buf.buf_8bit_valid = 0; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 6949 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6950 | // Start with a 0 size frame. |
| 6951 | *size = 0; |
| 6952 | |
| 6953 | cpi->frame_flags = *frame_flags; |
| 6954 | |
| 6955 | if (oxcf->pass == 2) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6956 | av1_rc_get_second_pass_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6957 | } else if (oxcf->pass == 1) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 6958 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6959 | } |
| 6960 | |
| 6961 | if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) { |
| 6962 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) |
| 6963 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 6964 | } |
| 6965 | |
| 6966 | #if CONFIG_AOM_QM |
| 6967 | cm->using_qmatrix = cpi->oxcf.using_qm; |
| 6968 | cm->min_qmlevel = cpi->oxcf.qm_minlevel; |
| 6969 | cm->max_qmlevel = cpi->oxcf.qm_maxlevel; |
| 6970 | #endif |
| 6971 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6972 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 6973 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 6974 | if (*time_stamp == 0) { |
| 6975 | cpi->common.current_frame_id = -1; |
| 6976 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6977 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 6978 | #endif // CONFIG_REFERENCE_BUFFER |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6979 | #if CONFIG_AMVR |
| 6980 | cpi->cur_poc++; |
| 6981 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 6982 | if (cpi->common.seq_params.force_integer_mv == 2) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6983 | struct lookahead_entry *previous_entry = |
| 6984 | cpi->lookahead->buf + cpi->previsous_index; |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 6985 | cpi->common.cur_frame_force_integer_mv = is_integer_mv( |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6986 | cpi, cpi->source, &previous_entry->img, cpi->previsou_hash_table); |
| 6987 | } else { |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 6988 | cpi->common.cur_frame_force_integer_mv = |
| 6989 | cpi->common.seq_params.force_integer_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6990 | } |
| 6991 | } else { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 6992 | cpi->common.cur_frame_force_integer_mv = 0; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6993 | } |
| 6994 | #endif |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6995 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6996 | if (oxcf->pass == 1) { |
| 6997 | cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6998 | av1_first_pass(cpi, source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6999 | } else if (oxcf->pass == 2) { |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 7000 | if (Pass2Encode(cpi, size, dest, frame_flags) != AOM_CODEC_OK) |
| 7001 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7002 | } else { |
| 7003 | // One pass encode |
Tom Finegan | e4099e3 | 2018-01-23 12:01:51 -0800 | [diff] [blame] | 7004 | if (Pass0Encode(cpi, size, dest, 0, frame_flags) != AOM_CODEC_OK) |
| 7005 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7006 | } |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 7007 | #if CONFIG_HASH_ME |
| 7008 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 7009 | #if CONFIG_AMVR |
| 7010 | cpi->previsou_hash_table = &cm->cur_frame->hash_table; |
| 7011 | { |
| 7012 | int l; |
| 7013 | for (l = -MAX_PRE_FRAMES; l < cpi->lookahead->max_sz; l++) { |
| 7014 | if ((cpi->lookahead->buf + l) == source) { |
| 7015 | cpi->previsous_index = l; |
| 7016 | break; |
| 7017 | } |
| 7018 | } |
| 7019 | |
| 7020 | if (l == cpi->lookahead->max_sz) { |
| 7021 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 7022 | "Failed to find last frame original buffer"); |
| 7023 | } |
| 7024 | } |
| 7025 | #endif |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 7026 | } |
| 7027 | |
| 7028 | #endif |
| 7029 | |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame] | 7030 | #if CONFIG_EXT_TILE |
| 7031 | if (!cm->large_scale_tile) { |
| 7032 | #endif // CONFIG_EXT_TILE |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 7033 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame] | 7034 | cm->frame_contexts[cm->new_fb_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 7035 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7036 | if (!cm->error_resilient_mode) |
| 7037 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 7038 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame] | 7039 | #if CONFIG_EXT_TILE |
| 7040 | } |
| 7041 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7042 | |
Yunqing Wang | b041d8a | 2017-11-15 12:31:18 -0800 | [diff] [blame] | 7043 | #if CONFIG_EXT_TILE |
| 7044 | #define EXT_TILE_DEBUG 0 |
| 7045 | #if EXT_TILE_DEBUG |
| 7046 | if (cm->large_scale_tile && oxcf->pass == 2) { |
| 7047 | char fn[20] = "./fc"; |
| 7048 | fn[4] = cm->current_video_frame / 100 + '0'; |
| 7049 | fn[5] = (cm->current_video_frame % 100) / 10 + '0'; |
| 7050 | fn[6] = (cm->current_video_frame % 10) + '0'; |
| 7051 | fn[7] = '\0'; |
| 7052 | av1_print_frame_contexts(cm->fc, fn); |
| 7053 | } |
| 7054 | #endif // EXT_TILE_DEBUG |
| 7055 | #undef EXT_TILE_DEBUG |
| 7056 | #endif // CONFIG_EXT_TILE |
| 7057 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7058 | // No frame encoded, or frame was dropped, release scaled references. |
| 7059 | if ((*size == 0) && (frame_is_intra_only(cm) == 0)) { |
| 7060 | release_scaled_references(cpi); |
| 7061 | } |
| 7062 | |
| 7063 | if (*size > 0) { |
| 7064 | cpi->droppable = !frame_is_reference(cpi); |
| 7065 | } |
| 7066 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7067 | aom_usec_timer_mark(&cmptimer); |
| 7068 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7069 | |
| 7070 | if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame) |
| 7071 | generate_psnr_packet(cpi); |
| 7072 | |
| 7073 | #if CONFIG_INTERNAL_STATS |
| 7074 | if (oxcf->pass != 1) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 7075 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7076 | } |
| 7077 | #endif // CONFIG_INTERNAL_STATS |
| 7078 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7079 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7080 | |
| 7081 | return 0; |
| 7082 | } |
| 7083 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7084 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 7085 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7086 | if (!cm->show_frame) { |
| 7087 | return -1; |
| 7088 | } else { |
| 7089 | int ret; |
| 7090 | if (cm->frame_to_show) { |
| 7091 | *dest = *cm->frame_to_show; |
| 7092 | dest->y_width = cm->width; |
| 7093 | dest->y_height = cm->height; |
| 7094 | dest->uv_width = cm->width >> cm->subsampling_x; |
| 7095 | dest->uv_height = cm->height >> cm->subsampling_y; |
| 7096 | ret = 0; |
| 7097 | } else { |
| 7098 | ret = -1; |
| 7099 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7100 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7101 | return ret; |
| 7102 | } |
| 7103 | } |
| 7104 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7105 | int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7106 | if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1; |
| 7107 | |
| 7108 | *frame = |
| 7109 | cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf; |
| 7110 | return 0; |
| 7111 | } |
| 7112 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7113 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 7114 | AOM_SCALING vert_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7115 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 7116 | |
| 7117 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 7118 | |
| 7119 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 7120 | Scale2Ratio(vert_mode, &vr, &vs); |
| 7121 | |
| 7122 | // always go to the next whole number |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 7123 | cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 7124 | cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7125 | |
| 7126 | return 0; |
| 7127 | } |
| 7128 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7129 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7130 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7131 | 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] | 7132 | // TODO(yunqingwang): For what references to use, external encoding flags |
| 7133 | // should be consistent with internal reference frame selection. Need to |
| 7134 | // ensure that there is not conflict between the two. In AV1 encoder, the |
| 7135 | // priority rank for 7 reference frames are: LAST, ALTREF, LAST2, LAST3, |
| 7136 | // GOLDEN, BWDREF, ALTREF2. If only one reference frame is used, it must be |
| 7137 | // LAST. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 7138 | cpi->ext_ref_frame_flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7139 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 7140 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | |
| 7141 | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD | |
| 7142 | AOM_EFLAG_NO_REF_ARF2)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7143 | if (flags & AOM_EFLAG_NO_REF_LAST) { |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 7144 | cpi->ext_ref_frame_flags = 0; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 7145 | } else { |
| 7146 | int ref = AOM_REFFRAME_ALL; |
| 7147 | |
| 7148 | if (flags & AOM_EFLAG_NO_REF_LAST2) ref ^= AOM_LAST2_FLAG; |
| 7149 | if (flags & AOM_EFLAG_NO_REF_LAST3) ref ^= AOM_LAST3_FLAG; |
| 7150 | |
| 7151 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
| 7152 | |
| 7153 | if (flags & AOM_EFLAG_NO_REF_ARF) { |
| 7154 | ref ^= AOM_ALT_FLAG; |
| 7155 | ref ^= AOM_BWD_FLAG; |
| 7156 | ref ^= AOM_ALT2_FLAG; |
| 7157 | } else { |
| 7158 | if (flags & AOM_EFLAG_NO_REF_BWD) ref ^= AOM_BWD_FLAG; |
| 7159 | if (flags & AOM_EFLAG_NO_REF_ARF2) ref ^= AOM_ALT2_FLAG; |
| 7160 | } |
| 7161 | |
| 7162 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7163 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7164 | } |
| 7165 | |
| 7166 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 7167 | (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] | 7168 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7169 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 7170 | // Refreshing LAST/LAST2/LAST3 is handled by 1 common flag. |
| 7171 | if (flags & AOM_EFLAG_NO_UPD_LAST) upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7172 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7173 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7174 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 7175 | if (flags & AOM_EFLAG_NO_UPD_ARF) { |
| 7176 | upd ^= AOM_ALT_FLAG; |
| 7177 | upd ^= AOM_BWD_FLAG; |
| 7178 | upd ^= AOM_ALT2_FLAG; |
| 7179 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7180 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7181 | av1_update_reference(cpi, upd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7182 | } |
| 7183 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 7184 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 7185 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 7186 | } |
| 7187 | } |