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" |
Jean-Marc Valin | 0143513 | 2017-02-18 14:12:53 -0500 | [diff] [blame] | 19 | #if CONFIG_CDEF |
Steinar Midtskogen | a9d41e8 | 2017-03-17 12:48:15 +0100 | [diff] [blame] | 20 | #include "av1/common/cdef.h" |
Jean-Marc Valin | 0143513 | 2017-02-18 14:12:53 -0500 | [diff] [blame] | 21 | #endif // CONFIG_CDEF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 22 | #include "av1/common/filter.h" |
| 23 | #include "av1/common/idct.h" |
| 24 | #include "av1/common/reconinter.h" |
| 25 | #include "av1/common/reconintra.h" |
Fergus Simpson | d056500 | 2017-03-27 16:51:52 -0700 | [diff] [blame] | 26 | #include "av1/common/resize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | #include "av1/common/tile_common.h" |
| 28 | |
| 29 | #include "av1/encoder/aq_complexity.h" |
| 30 | #include "av1/encoder/aq_cyclicrefresh.h" |
| 31 | #include "av1/encoder/aq_variance.h" |
| 32 | #include "av1/encoder/bitstream.h" |
Todd Nguyen | 302d097 | 2017-06-16 16:16:29 -0700 | [diff] [blame] | 33 | #if CONFIG_BGSPRITE |
| 34 | #include "av1/encoder/bgsprite.h" |
| 35 | #endif // CONFIG_BGSPRITE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 36 | #if CONFIG_ANS |
Alex Converse | 1ac1ae7 | 2016-09-17 15:11:16 -0700 | [diff] [blame] | 37 | #include "aom_dsp/buf_ans.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 38 | #endif |
| 39 | #include "av1/encoder/context_tree.h" |
| 40 | #include "av1/encoder/encodeframe.h" |
| 41 | #include "av1/encoder/encodemv.h" |
| 42 | #include "av1/encoder/encoder.h" |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 43 | #if CONFIG_LV_MAP |
| 44 | #include "av1/encoder/encodetxb.h" |
| 45 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 46 | #include "av1/encoder/ethread.h" |
| 47 | #include "av1/encoder/firstpass.h" |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 48 | #if CONFIG_HASH_ME |
| 49 | #include "av1/encoder/hash_motion.h" |
| 50 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 51 | #include "av1/encoder/mbgraph.h" |
| 52 | #include "av1/encoder/picklpf.h" |
| 53 | #if CONFIG_LOOP_RESTORATION |
| 54 | #include "av1/encoder/pickrst.h" |
| 55 | #endif // CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 56 | #include "av1/encoder/random.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 57 | #include "av1/encoder/ratectrl.h" |
| 58 | #include "av1/encoder/rd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 59 | #include "av1/encoder/segmentation.h" |
| 60 | #include "av1/encoder/speed_features.h" |
| 61 | #include "av1/encoder/temporal_filter.h" |
| 62 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 63 | #include "./av1_rtcd.h" |
| 64 | #include "./aom_dsp_rtcd.h" |
| 65 | #include "./aom_scale_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | #include "aom_dsp/psnr.h" |
| 67 | #if CONFIG_INTERNAL_STATS |
| 68 | #include "aom_dsp/ssim.h" |
| 69 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 70 | #include "aom_dsp/aom_dsp_common.h" |
| 71 | #include "aom_dsp/aom_filter.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 72 | #include "aom_ports/aom_timer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 73 | #include "aom_ports/mem.h" |
| 74 | #include "aom_ports/system_state.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 75 | #include "aom_scale/aom_scale.h" |
Angie Chiang | 6062a8b | 2016-09-21 16:01:04 -0700 | [diff] [blame] | 76 | #if CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 77 | #include "aom_util/debug_util.h" |
Angie Chiang | 6062a8b | 2016-09-21 16:01:04 -0700 | [diff] [blame] | 78 | #endif // CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 79 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 80 | #if CONFIG_ENTROPY_STATS |
| 81 | FRAME_COUNTS aggregate_fc; |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 82 | // Aggregate frame counts per frame context type |
| 83 | FRAME_COUNTS aggregate_fc_per_type[FRAME_CONTEXTS]; |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 84 | #endif // CONFIG_ENTROPY_STATS |
| 85 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 86 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 87 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 88 | |
| 89 | #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ |
| 90 | |
| 91 | #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv |
| 92 | // for altref computation. |
| 93 | #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision |
| 94 | // mv. Choose a very high value for |
| 95 | // now so that HIGH_PRECISION is always |
| 96 | // chosen. |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 97 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 98 | // #define OUTPUT_YUV_REC |
| 99 | #ifdef OUTPUT_YUV_DENOISED |
| 100 | FILE *yuv_denoised_file = NULL; |
| 101 | #endif |
| 102 | #ifdef OUTPUT_YUV_SKINMAP |
| 103 | FILE *yuv_skinmap_file = NULL; |
| 104 | #endif |
| 105 | #ifdef OUTPUT_YUV_REC |
| 106 | FILE *yuv_rec_file; |
| 107 | #define FILE_NAME_LEN 100 |
| 108 | #endif |
| 109 | |
| 110 | #if 0 |
| 111 | FILE *framepsnr; |
| 112 | FILE *kf_list; |
| 113 | FILE *keyfile; |
| 114 | #endif |
| 115 | |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 116 | #if CONFIG_CFL |
| 117 | CFL_CTX NULL_CFL; |
| 118 | #endif |
| 119 | |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 120 | #if CONFIG_INTERNAL_STATS |
| 121 | typedef enum { Y, U, V, ALL } STAT_TYPE; |
| 122 | #endif // CONFIG_INTERNAL_STATS |
| 123 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 124 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 125 | switch (mode) { |
| 126 | case NORMAL: |
| 127 | *hr = 1; |
| 128 | *hs = 1; |
| 129 | break; |
| 130 | case FOURFIVE: |
| 131 | *hr = 4; |
| 132 | *hs = 5; |
| 133 | break; |
| 134 | case THREEFIVE: |
| 135 | *hr = 3; |
| 136 | *hs = 5; |
| 137 | break; |
| 138 | case ONETWO: |
| 139 | *hr = 1; |
| 140 | *hs = 2; |
| 141 | break; |
| 142 | default: |
| 143 | *hr = 1; |
| 144 | *hs = 1; |
| 145 | assert(0); |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 151 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 152 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 153 | unsigned char *const seg_map = cpi->segmentation_map; |
| 154 | int i; |
| 155 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 156 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 157 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 158 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 159 | } |
| 160 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 161 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 162 | struct segmentation *const seg = &cpi->common.seg; |
| 163 | unsigned char *const seg_map = cpi->segmentation_map; |
| 164 | const unsigned char *const active_map = cpi->active_map.map; |
| 165 | int i; |
| 166 | |
| 167 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 168 | |
| 169 | if (frame_is_intra_only(&cpi->common)) { |
| 170 | cpi->active_map.enabled = 0; |
| 171 | cpi->active_map.update = 1; |
| 172 | } |
| 173 | |
| 174 | if (cpi->active_map.update) { |
| 175 | if (cpi->active_map.enabled) { |
| 176 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 177 | 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] | 178 | av1_enable_segmentation(seg); |
| 179 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 180 | #if CONFIG_LOOPFILTER_LEVEL |
| 181 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 182 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 183 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 184 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 185 | |
| 186 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H, |
| 187 | -MAX_LOOP_FILTER); |
| 188 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V, |
| 189 | -MAX_LOOP_FILTER); |
| 190 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U, |
| 191 | -MAX_LOOP_FILTER); |
| 192 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V, |
| 193 | -MAX_LOOP_FILTER); |
| 194 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 195 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 196 | // 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] | 197 | // filter level being zero. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 198 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF, |
| 199 | -MAX_LOOP_FILTER); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 200 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 201 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 202 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 203 | #if CONFIG_LOOPFILTER_LEVEL |
| 204 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 205 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 206 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 207 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 208 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 209 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 210 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 211 | if (seg->enabled) { |
| 212 | seg->update_data = 1; |
| 213 | seg->update_map = 1; |
| 214 | } |
| 215 | } |
| 216 | cpi->active_map.update = 0; |
| 217 | } |
| 218 | } |
| 219 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 220 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 221 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 222 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 223 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 224 | const int mi_rows = cpi->common.mi_rows; |
| 225 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 226 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 227 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 228 | cpi->active_map.update = 1; |
| 229 | if (new_map_16x16) { |
| 230 | int r, c; |
| 231 | for (r = 0; r < mi_rows; ++r) { |
| 232 | for (c = 0; c < mi_cols; ++c) { |
| 233 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 234 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 235 | ? AM_SEGMENT_ID_ACTIVE |
| 236 | : AM_SEGMENT_ID_INACTIVE; |
| 237 | } |
| 238 | } |
| 239 | cpi->active_map.enabled = 1; |
| 240 | } else { |
| 241 | cpi->active_map.enabled = 0; |
| 242 | } |
| 243 | return 0; |
| 244 | } else { |
| 245 | return -1; |
| 246 | } |
| 247 | } |
| 248 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 249 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 250 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 251 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 252 | new_map_16x16) { |
| 253 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 254 | const int mi_rows = cpi->common.mi_rows; |
| 255 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 256 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 257 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 258 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 259 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 260 | if (cpi->active_map.enabled) { |
| 261 | int r, c; |
| 262 | for (r = 0; r < mi_rows; ++r) { |
| 263 | for (c = 0; c < mi_cols; ++c) { |
| 264 | // Cyclic refresh segments are considered active despite not having |
| 265 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 266 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 267 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | return 0; |
| 272 | } else { |
| 273 | return -1; |
| 274 | } |
| 275 | } |
| 276 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 277 | static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv |
| 278 | #if CONFIG_AMVR |
| 279 | , |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 280 | int cur_frame_force_integer_mv |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 281 | #endif |
| 282 | ) { |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 283 | MACROBLOCK *const mb = &cpi->td.mb; |
| 284 | cpi->common.allow_high_precision_mv = allow_high_precision_mv; |
| 285 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 286 | #if CONFIG_AMVR |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 287 | if (cpi->common.allow_high_precision_mv && cur_frame_force_integer_mv == 0) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 288 | #else |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 289 | if (cpi->common.allow_high_precision_mv) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 290 | #endif |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 291 | int i; |
| 292 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 293 | mb->mv_cost_stack[i] = mb->nmvcost_hp[i]; |
| 294 | } |
| 295 | } else { |
| 296 | int i; |
| 297 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 298 | mb->mv_cost_stack[i] = mb->nmvcost[i]; |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 303 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 304 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 305 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 306 | return BLOCK_64X64; |
| 307 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 308 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 309 | return BLOCK_128X128; |
| 310 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 311 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 312 | |
| 313 | assert(IMPLIES(cpi->common.tile_cols > 1, |
| 314 | cpi->common.tile_width % MAX_MIB_SIZE == 0)); |
| 315 | assert(IMPLIES(cpi->common.tile_rows > 1, |
| 316 | cpi->common.tile_height % MAX_MIB_SIZE == 0)); |
| 317 | |
| 318 | // TODO(any): Possibly could improve this with a heuristic. |
| 319 | return BLOCK_128X128; |
| 320 | #else |
| 321 | (void)cpi; |
| 322 | return BLOCK_64X64; |
| 323 | #endif // CONFIG_EXT_PARTITION |
| 324 | } |
| 325 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 326 | static void setup_frame(AV1_COMP *cpi) { |
| 327 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 328 | // Set up entropy context depending on frame type. The decoder mandates |
| 329 | // the use of the default context, index 0, for keyframes and inter |
| 330 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 331 | // other inter-frames the encoder currently uses only two contexts; |
| 332 | // context 1 for ALTREF frames and context 0 for the others. |
| 333 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 334 | av1_setup_past_independence(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 335 | } else { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 336 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 337 | // Just use frame context from first signaled reference frame. |
| 338 | // This will always be LAST_FRAME for now. |
| 339 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 340 | const GF_GROUP *gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 341 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 342 | cm->frame_context_idx = EXT_ARF_FRAME; |
| 343 | else if (cpi->refresh_alt_ref_frame) |
| 344 | cm->frame_context_idx = ARF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 345 | else if (cpi->rc.is_src_frame_alt_ref) |
| 346 | cm->frame_context_idx = OVERLAY_FRAME; |
| 347 | else if (cpi->refresh_golden_frame) |
| 348 | cm->frame_context_idx = GLD_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 349 | else if (cpi->refresh_bwd_ref_frame) |
| 350 | cm->frame_context_idx = BRF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 351 | else |
| 352 | cm->frame_context_idx = REGULAR_FRAME; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 353 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | if (cm->frame_type == KEY_FRAME) { |
| 357 | cpi->refresh_golden_frame = 1; |
| 358 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 359 | av1_zero(cpi->interp_filter_selected); |
Debargha Mukherjee | d2630fa | 2017-09-22 10:32:51 -0700 | [diff] [blame] | 360 | set_sb_size(cm, select_sb_size(cpi)); |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 361 | #if CONFIG_REFERENCE_BUFFER |
| 362 | set_use_reference_buffer(cm, 0); |
| 363 | #endif // CONFIG_REFERENCE_BUFFER |
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 |
| 366 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
| 367 | cm->frame_refs[0].idx < 0) { |
| 368 | *cm->fc = cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 369 | } else { |
| 370 | *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx]; |
| 371 | } |
| 372 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 373 | *cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 374 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 375 | av1_zero(cpi->interp_filter_selected[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 376 | } |
Zoe Liu | c01dddb | 2017-11-07 08:44:06 -0800 | [diff] [blame] | 377 | #if !CONFIG_EXT_COMP_REFS // No change to bitstream |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 378 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 379 | cpi->refresh_bwd_ref_frame = cpi->refresh_last_frame; |
| 380 | cpi->rc.is_bipred_frame = 1; |
| 381 | } |
Zoe Liu | c01dddb | 2017-11-07 08:44:06 -0800 | [diff] [blame] | 382 | #endif // !CONFIG_EXT_COMP_REFS |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 383 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 384 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
| 385 | cm->frame_refs[0].idx < 0) { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 386 | // use default frame context values |
| 387 | cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 388 | } else { |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 389 | *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 390 | cm->pre_fc = &cm->frame_contexts[cm->frame_refs[0].idx]; |
| 391 | } |
| 392 | #else |
Thomas Daede | 10e1da9 | 2017-04-26 13:22:21 -0700 | [diff] [blame] | 393 | cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 394 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 395 | |
| 396 | cpi->vaq_refresh = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 399 | static void enc_setup_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 400 | int i; |
| 401 | cm->mi = cm->mip + cm->mi_stride + 1; |
| 402 | memset(cm->mip, 0, cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip)); |
| 403 | cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 404 | // Clear top border row |
| 405 | memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride); |
| 406 | // Clear left border column |
| 407 | for (i = 1; i < cm->mi_rows + 1; ++i) |
| 408 | memset(&cm->prev_mip[i * cm->mi_stride], 0, sizeof(*cm->prev_mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 409 | cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; |
| 410 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; |
| 411 | |
| 412 | memset(cm->mi_grid_base, 0, |
| 413 | cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mi_grid_base)); |
| 414 | } |
| 415 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 416 | static int enc_alloc_mi(AV1_COMMON *cm, int mi_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 417 | cm->mip = aom_calloc(mi_size, sizeof(*cm->mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 418 | if (!cm->mip) return 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 419 | cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 420 | if (!cm->prev_mip) return 1; |
| 421 | cm->mi_alloc_size = mi_size; |
| 422 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 423 | 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] | 424 | if (!cm->mi_grid_base) return 1; |
| 425 | cm->prev_mi_grid_base = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 426 | (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 427 | if (!cm->prev_mi_grid_base) return 1; |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 432 | static void enc_free_mi(AV1_COMMON *cm) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 433 | aom_free(cm->mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 434 | cm->mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 435 | aom_free(cm->prev_mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 436 | cm->prev_mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 437 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 438 | cm->mi_grid_base = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 439 | aom_free(cm->prev_mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 440 | cm->prev_mi_grid_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 441 | cm->mi_alloc_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 444 | static void swap_mi_and_prev_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 445 | // Current mip will be the prev_mip for the next frame. |
| 446 | MODE_INFO **temp_base = cm->prev_mi_grid_base; |
| 447 | MODE_INFO *temp = cm->prev_mip; |
| 448 | cm->prev_mip = cm->mip; |
| 449 | cm->mip = temp; |
| 450 | |
| 451 | // Update the upper left visible macroblock ptrs. |
| 452 | cm->mi = cm->mip + cm->mi_stride + 1; |
| 453 | cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 454 | |
| 455 | cm->prev_mi_grid_base = cm->mi_grid_base; |
| 456 | cm->mi_grid_base = temp_base; |
| 457 | cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; |
| 458 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; |
| 459 | } |
| 460 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 461 | void av1_initialize_enc(void) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 462 | static volatile int init_done = 0; |
| 463 | |
| 464 | if (!init_done) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 465 | av1_rtcd(); |
| 466 | aom_dsp_rtcd(); |
| 467 | aom_scale_rtcd(); |
| 468 | av1_init_intra_predictors(); |
| 469 | av1_init_me_luts(); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 470 | #if !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 471 | av1_rc_init_minq_luts(); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 472 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 473 | av1_entropy_mv_init(); |
| 474 | av1_encode_token_init(); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 475 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 476 | init_done = 1; |
| 477 | } |
| 478 | } |
| 479 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 480 | static void dealloc_context_buffers_ext(AV1_COMP *cpi) { |
| 481 | if (cpi->mbmi_ext_base) { |
| 482 | aom_free(cpi->mbmi_ext_base); |
| 483 | cpi->mbmi_ext_base = NULL; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
| 488 | AV1_COMMON *cm = &cpi->common; |
| 489 | int mi_size = cm->mi_cols * cm->mi_rows; |
| 490 | |
| 491 | dealloc_context_buffers_ext(cpi); |
| 492 | CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, |
| 493 | aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); |
| 494 | } |
| 495 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 496 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 497 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 498 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 499 | dealloc_context_buffers_ext(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 500 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 501 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 502 | cpi->tile_data = NULL; |
| 503 | |
| 504 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 505 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 506 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 507 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 508 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 509 | cpi->cyclic_refresh = NULL; |
| 510 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 511 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 512 | cpi->active_map.map = NULL; |
| 513 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 514 | aom_free(cpi->td.mb.above_pred_buf); |
| 515 | cpi->td.mb.above_pred_buf = NULL; |
| 516 | |
| 517 | aom_free(cpi->td.mb.left_pred_buf); |
| 518 | cpi->td.mb.left_pred_buf = NULL; |
| 519 | |
| 520 | aom_free(cpi->td.mb.wsrc_buf); |
| 521 | cpi->td.mb.wsrc_buf = NULL; |
| 522 | |
| 523 | aom_free(cpi->td.mb.mask_buf); |
| 524 | cpi->td.mb.mask_buf = NULL; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 525 | |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 526 | #if CONFIG_MFMV |
| 527 | aom_free(cm->tpl_mvs); |
| 528 | cm->tpl_mvs = NULL; |
| 529 | #endif |
| 530 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 531 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 532 | #if CONFIG_LV_MAP |
| 533 | av1_free_txb_buf(cpi); |
| 534 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 535 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 536 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 537 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 538 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 539 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 540 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 541 | #endif // CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 542 | aom_free_frame_buffer(&cpi->scaled_source); |
| 543 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 544 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 545 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 546 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 547 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 548 | cpi->tile_tok[0][0] = 0; |
| 549 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 550 | av1_free_pc_tree(&cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 551 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 552 | aom_free(cpi->td.mb.palette_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 553 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 554 | #if CONFIG_ANS |
Alex Converse | 1ac1ae7 | 2016-09-17 15:11:16 -0700 | [diff] [blame] | 555 | aom_buf_ans_free(&cpi->buf_ans); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 556 | #endif // CONFIG_ANS |
| 557 | } |
| 558 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 559 | static void save_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 560 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 561 | AV1_COMMON *cm = &cpi->common; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 562 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 563 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 564 | // Stores a snapshot of key state variables which can subsequently be |
| 565 | // restored with a call to av1_restore_coding_context. These functions are |
| 566 | // intended for use in a re-code loop in av1_compress_frame where the |
| 567 | // quantizer value is adjusted between loop iterations. |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 568 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 569 | av1_copy(cc->nmv_vec_cost[i], cpi->td.mb.nmv_vec_cost[i]); |
| 570 | av1_copy(cc->nmv_costs, cpi->nmv_costs); |
| 571 | av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp); |
| 572 | } |
| 573 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 574 | av1_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); |
| 575 | av1_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 576 | |
| 577 | cc->fc = *cm->fc; |
| 578 | } |
| 579 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 580 | static void restore_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 581 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 582 | AV1_COMMON *cm = &cpi->common; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 583 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 584 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 585 | // Restore key state variables to the snapshot state stored in the |
| 586 | // previous call to av1_save_coding_context. |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 587 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 588 | av1_copy(cpi->td.mb.nmv_vec_cost[i], cc->nmv_vec_cost[i]); |
| 589 | av1_copy(cpi->nmv_costs, cc->nmv_costs); |
| 590 | av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp); |
| 591 | } |
| 592 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 593 | av1_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); |
| 594 | av1_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 595 | |
| 596 | *cm->fc = cc->fc; |
| 597 | } |
| 598 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 599 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 600 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 601 | const RATE_CONTROL *const rc = &cpi->rc; |
| 602 | struct segmentation *const seg = &cm->seg; |
| 603 | |
| 604 | int high_q = (int)(rc->avg_q > 48.0); |
| 605 | int qi_delta; |
| 606 | |
| 607 | // Disable and clear down for KF |
| 608 | if (cm->frame_type == KEY_FRAME) { |
| 609 | // Clear down the global segmentation map |
| 610 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 611 | seg->update_map = 0; |
| 612 | seg->update_data = 0; |
| 613 | cpi->static_mb_pct = 0; |
| 614 | |
| 615 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 616 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 617 | |
| 618 | // Clear down the segment features. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 619 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 620 | } else if (cpi->refresh_alt_ref_frame) { |
| 621 | // If this is an alt ref frame |
| 622 | // Clear down the global segmentation map |
| 623 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 624 | seg->update_map = 0; |
| 625 | seg->update_data = 0; |
| 626 | cpi->static_mb_pct = 0; |
| 627 | |
| 628 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 629 | av1_disable_segmentation(seg); |
| 630 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 631 | |
| 632 | // Scan frames from current to arf frame. |
| 633 | // This function re-enables segmentation if appropriate. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 634 | av1_update_mbgraph_stats(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 635 | |
| 636 | // If segmentation was enabled set those features needed for the |
| 637 | // arf itself. |
| 638 | if (seg->enabled) { |
| 639 | seg->update_map = 1; |
| 640 | seg->update_data = 1; |
| 641 | |
| 642 | qi_delta = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 643 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, cm->bit_depth); |
| 644 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 645 | #if CONFIG_LOOPFILTER_LEVEL |
| 646 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 647 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 648 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 649 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 650 | |
| 651 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 652 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 653 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 654 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
| 655 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 656 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 657 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
| 658 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 659 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 660 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 661 | } |
| 662 | } else if (seg->enabled) { |
| 663 | // All other frames if segmentation has been enabled |
| 664 | |
| 665 | // First normal frame in a valid gf or alt ref group |
| 666 | if (rc->frames_since_golden == 0) { |
| 667 | // Set up segment features for normal frames in an arf group |
| 668 | if (rc->source_alt_ref_active) { |
| 669 | seg->update_map = 0; |
| 670 | seg->update_data = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 671 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 672 | qi_delta = |
| 673 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, cm->bit_depth); |
| 674 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 675 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 676 | |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 677 | #if CONFIG_LOOPFILTER_LEVEL |
| 678 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 679 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 680 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 681 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 682 | |
| 683 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 684 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 685 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 686 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
| 687 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 688 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
| 689 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 690 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 691 | |
| 692 | // Segment coding disabled for compred testing |
| 693 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 694 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 695 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 696 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 697 | } |
| 698 | } else { |
| 699 | // Disable segmentation and clear down features if alt ref |
| 700 | // is not active for this group |
| 701 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 702 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 703 | |
| 704 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 705 | |
| 706 | seg->update_map = 0; |
| 707 | seg->update_data = 0; |
| 708 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 709 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 710 | } |
| 711 | } else if (rc->is_src_frame_alt_ref) { |
| 712 | // Special case where we are coding over the top of a previous |
| 713 | // alt ref frame. |
| 714 | // Segment coding disabled for compred testing |
| 715 | |
| 716 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 717 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 718 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 719 | |
| 720 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 721 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 722 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 723 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 724 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 725 | |
| 726 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 727 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 728 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 729 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 730 | } |
| 731 | // Enable data update |
| 732 | seg->update_data = 1; |
| 733 | } else { |
| 734 | // All other frames. |
| 735 | |
| 736 | // No updates.. leave things as they are. |
| 737 | seg->update_map = 0; |
| 738 | seg->update_data = 0; |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 743 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 744 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 745 | MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible; |
| 746 | uint8_t *cache_ptr = cm->last_frame_seg_map; |
| 747 | int row, col; |
| 748 | |
| 749 | for (row = 0; row < cm->mi_rows; row++) { |
| 750 | MODE_INFO **mi_8x8 = mi_8x8_ptr; |
| 751 | uint8_t *cache = cache_ptr; |
| 752 | for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) |
| 753 | cache[0] = mi_8x8[0]->mbmi.segment_id; |
| 754 | mi_8x8_ptr += cm->mi_stride; |
| 755 | cache_ptr += cm->mi_cols; |
| 756 | } |
| 757 | } |
| 758 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 759 | static void alloc_raw_frame_buffers(AV1_COMP *cpi) { |
| 760 | AV1_COMMON *cm = &cpi->common; |
| 761 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 762 | |
| 763 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 764 | cpi->lookahead = av1_lookahead_init(oxcf->width, oxcf->height, |
| 765 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 766 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 767 | cm->use_highbitdepth, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 768 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 769 | oxcf->lag_in_frames); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 770 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 771 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 772 | "Failed to allocate lag buffers"); |
| 773 | |
| 774 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 775 | 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] | 776 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 777 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 778 | cm->use_highbitdepth, |
| 779 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 780 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 781 | NULL, NULL)) |
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 altref buffer"); |
| 784 | } |
| 785 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 786 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 787 | AV1_COMMON *const cm = &cpi->common; |
| 788 | 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] | 789 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 790 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 791 | cm->use_highbitdepth, |
| 792 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 793 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 794 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 795 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 796 | "Failed to allocate last frame buffer"); |
| 797 | |
| 798 | #if CONFIG_LOOP_RESTORATION |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 799 | if (aom_realloc_frame_buffer( |
| 800 | &cpi->trial_frame_rst, |
| 801 | #if CONFIG_FRAME_SUPERRES |
| 802 | cm->superres_upscaled_width, cm->superres_upscaled_height, |
| 803 | #else |
| 804 | cm->width, cm->height, |
| 805 | #endif // CONFIG_FRAME_SUPERRES |
| 806 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 807 | #if CONFIG_HIGHBITDEPTH |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 808 | cm->use_highbitdepth, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 809 | #endif |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 810 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 811 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 812 | "Failed to allocate trial restored frame buffer"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 813 | #endif // CONFIG_LOOP_RESTORATION |
| 814 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 815 | if (aom_realloc_frame_buffer(&cpi->scaled_source, cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 816 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 817 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 818 | cm->use_highbitdepth, |
| 819 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 820 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 821 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 822 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 823 | "Failed to allocate scaled source buffer"); |
| 824 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 825 | 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] | 826 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 827 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 828 | cm->use_highbitdepth, |
| 829 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 830 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 831 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 832 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 833 | "Failed to allocate scaled last source buffer"); |
| 834 | } |
| 835 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 836 | static void alloc_compressor_data(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 837 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 838 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 839 | av1_alloc_context_buffers(cm, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 840 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 841 | #if CONFIG_LV_MAP |
| 842 | av1_alloc_txb_buf(cpi); |
| 843 | #endif |
| 844 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 845 | alloc_context_buffers_ext(cpi); |
| 846 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 847 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 848 | |
| 849 | { |
Yaowu Xu | e39b3b8 | 2017-10-31 16:11:59 -0700 | [diff] [blame] | 850 | unsigned int tokens = |
| 851 | get_token_alloc(cm->mb_rows, cm->mb_cols, MAX_SB_SIZE_LOG2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 852 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 853 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 854 | } |
| 855 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 856 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 859 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 860 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 861 | #if CONFIG_XIPHRC |
| 862 | if (!cpi->od_rc.cur_frame) return; |
| 863 | cpi->od_rc.framerate = cpi->framerate; |
| 864 | od_enc_rc_resize(&cpi->od_rc); |
| 865 | #else |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 866 | av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 867 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 870 | #if CONFIG_MAX_TILE |
| 871 | |
| 872 | static void set_tile_info_max_tile(AV1_COMP *cpi) { |
| 873 | AV1_COMMON *const cm = &cpi->common; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 874 | int i, start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 875 | |
| 876 | av1_get_tile_limits(cm); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 877 | |
| 878 | // configure tile columns |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 879 | 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] | 880 | cm->uniform_tile_spacing_flag = 1; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 881 | cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols); |
| 882 | 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] | 883 | } else { |
Yaowu Xu | 81d458b | 2017-11-07 15:30:13 -0800 | [diff] [blame] | 884 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); |
| 885 | int sb_cols = mi_cols >> MAX_MIB_SIZE_LOG2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 886 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 887 | cm->uniform_tile_spacing_flag = 0; |
| 888 | for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) { |
| 889 | cm->tile_col_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 890 | size_sb = cpi->oxcf.tile_widths[j++]; |
| 891 | if (j >= cpi->oxcf.tile_width_count) j = 0; |
| 892 | start_sb += AOMMIN(size_sb, MAX_TILE_WIDTH_SB); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 893 | } |
| 894 | cm->tile_cols = i; |
| 895 | cm->tile_col_start_sb[i] = sb_cols; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 896 | } |
| 897 | av1_calculate_tile_cols(cm); |
| 898 | |
| 899 | // configure tile rows |
| 900 | if (cm->uniform_tile_spacing_flag) { |
| 901 | cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows); |
| 902 | 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] | 903 | } else { |
Yaowu Xu | 81d458b | 2017-11-07 15:30:13 -0800 | [diff] [blame] | 904 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); |
| 905 | int sb_rows = mi_rows >> MAX_MIB_SIZE_LOG2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 906 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 907 | for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) { |
| 908 | cm->tile_row_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 909 | size_sb = cpi->oxcf.tile_heights[j++]; |
| 910 | if (j >= cpi->oxcf.tile_height_count) j = 0; |
| 911 | start_sb += AOMMIN(size_sb, cm->max_tile_height_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 912 | } |
| 913 | cm->tile_rows = i; |
| 914 | cm->tile_row_start_sb[i] = sb_rows; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 915 | } |
| 916 | av1_calculate_tile_rows(cm); |
| 917 | } |
| 918 | |
| 919 | #endif |
| 920 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 921 | static void set_tile_info(AV1_COMP *cpi) { |
| 922 | AV1_COMMON *const cm = &cpi->common; |
Thomas Davies | b25ba50 | 2017-07-18 10:18:24 +0100 | [diff] [blame] | 923 | #if CONFIG_DEPENDENT_HORZTILES |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 924 | int tile_row, tile_col, num_tiles_in_tg; |
| 925 | int tg_row_start, tg_col_start; |
| 926 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 927 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 928 | if (cpi->oxcf.large_scale_tile) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 929 | #if CONFIG_EXT_PARTITION |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 930 | if (cpi->oxcf.superblock_size != AOM_SUPERBLOCK_SIZE_64X64) { |
| 931 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 32); |
| 932 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 32); |
| 933 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 934 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
| 935 | } else { |
| 936 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 937 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
| 938 | cm->tile_width <<= MAX_MIB_SIZE_LOG2 - 1; |
| 939 | cm->tile_height <<= MAX_MIB_SIZE_LOG2 - 1; |
| 940 | } |
| 941 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 942 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 943 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 944 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 945 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 946 | #endif // CONFIG_EXT_PARTITION |
| 947 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 948 | cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols); |
| 949 | cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 950 | |
Yaowu Xu | 8d0039c | 2017-10-13 07:51:46 -0700 | [diff] [blame] | 951 | assert(cm->tile_width >> MAX_MIB_SIZE_LOG2 <= 32); |
| 952 | assert(cm->tile_height >> MAX_MIB_SIZE_LOG2 <= 32); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 953 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 954 | // Get the number of tiles |
| 955 | cm->tile_cols = 1; |
| 956 | 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] | 957 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 958 | cm->tile_rows = 1; |
| 959 | while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows; |
| 960 | } else { |
| 961 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 962 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 963 | #if CONFIG_MAX_TILE |
| 964 | set_tile_info_max_tile(cpi); |
| 965 | #else |
| 966 | int min_log2_tile_cols, max_log2_tile_cols; |
| 967 | 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] | 968 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 969 | cm->log2_tile_cols = |
| 970 | clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols); |
| 971 | cm->log2_tile_rows = cpi->oxcf.tile_rows; |
Rupert Swarbrick | 940942b | 2017-09-01 12:05:55 +0100 | [diff] [blame] | 972 | |
Rupert Swarbrick | 5a010aa | 2017-09-26 16:16:48 +0100 | [diff] [blame] | 973 | cm->tile_width = |
| 974 | get_tile_size(cm->mi_cols, cm->log2_tile_cols, &cm->tile_cols); |
| 975 | cm->tile_height = |
| 976 | 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] | 977 | #endif // CONFIG_MAX_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 978 | #if CONFIG_EXT_TILE |
| 979 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 980 | #endif // CONFIG_EXT_TILE |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 981 | |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 982 | #if CONFIG_DEPENDENT_HORZTILES |
| 983 | cm->dependent_horz_tiles = cpi->oxcf.dependent_horz_tiles; |
Fangwen Fu | 70bcb89 | 2017-05-06 17:05:19 -0700 | [diff] [blame] | 984 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 985 | if (cm->large_scale_tile) { |
| 986 | // May not needed since cpi->oxcf.dependent_horz_tiles is already adjusted. |
| 987 | cm->dependent_horz_tiles = 0; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 988 | } else { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 989 | #endif // CONFIG_EXT_TILE |
| 990 | if (cm->log2_tile_rows == 0) cm->dependent_horz_tiles = 0; |
| 991 | #if CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 992 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 993 | #endif // CONFIG_EXT_TILE |
| 994 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 995 | #if CONFIG_EXT_TILE |
| 996 | if (!cm->large_scale_tile) { |
| 997 | #endif // CONFIG_EXT_TILE |
| 998 | if (cpi->oxcf.mtu == 0) { |
| 999 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 1000 | } else { |
| 1001 | // Use a default value for the purposes of weighting costs in probability |
| 1002 | // updates |
| 1003 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1004 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1005 | num_tiles_in_tg = |
| 1006 | (cm->tile_cols * cm->tile_rows + cm->num_tg - 1) / cm->num_tg; |
| 1007 | tg_row_start = 0; |
| 1008 | tg_col_start = 0; |
| 1009 | for (tile_row = 0; tile_row < cm->tile_rows; ++tile_row) { |
| 1010 | for (tile_col = 0; tile_col < cm->tile_cols; ++tile_col) { |
| 1011 | if ((tile_row * cm->tile_cols + tile_col) % num_tiles_in_tg == 0) { |
| 1012 | tg_row_start = tile_row; |
| 1013 | tg_col_start = tile_col; |
| 1014 | } |
| 1015 | cm->tile_group_start_row[tile_row][tile_col] = tg_row_start; |
| 1016 | cm->tile_group_start_col[tile_row][tile_col] = tg_col_start; |
| 1017 | } |
| 1018 | } |
| 1019 | #if CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1020 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1021 | #endif // CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1022 | #endif |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 1023 | |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 1024 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 1025 | cm->loop_filter_across_tiles_enabled = |
| 1026 | cpi->oxcf.loop_filter_across_tiles_enabled; |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 1027 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1030 | static void update_frame_size(AV1_COMP *cpi) { |
| 1031 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1032 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 1033 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1034 | av1_set_mb_mi(cm, cm->width, cm->height); |
| 1035 | av1_init_context_buffers(cm); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1036 | av1_init_macroblockd(cm, xd, |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 1037 | #if CONFIG_CFL |
| 1038 | &NULL_CFL, |
| 1039 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1040 | NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1041 | memset(cpi->mbmi_ext_base, 0, |
| 1042 | cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1043 | set_tile_info(cpi); |
| 1044 | } |
| 1045 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1046 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1047 | int fb_idx; |
| 1048 | for (fb_idx = 0; fb_idx < LAST_REF_FRAMES; ++fb_idx) |
| 1049 | cpi->lst_fb_idxes[fb_idx] = fb_idx; |
| 1050 | cpi->gld_fb_idx = LAST_REF_FRAMES; |
| 1051 | cpi->bwd_fb_idx = LAST_REF_FRAMES + 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1052 | cpi->alt2_fb_idx = LAST_REF_FRAMES + 2; |
| 1053 | cpi->alt_fb_idx = LAST_REF_FRAMES + 3; |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 1054 | cpi->ext_fb_idx = LAST_REF_FRAMES + 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1055 | for (fb_idx = 0; fb_idx < MAX_EXT_ARFS + 1; ++fb_idx) |
| 1056 | cpi->arf_map[fb_idx] = LAST_REF_FRAMES + 2 + fb_idx; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1057 | #if CONFIG_AMVR |
| 1058 | cpi->rate_index = 0; |
| 1059 | cpi->rate_size = 0; |
| 1060 | cpi->cur_poc = -1; |
| 1061 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1064 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 1065 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1066 | |
| 1067 | cpi->oxcf = *oxcf; |
| 1068 | cpi->framerate = oxcf->init_framerate; |
| 1069 | |
| 1070 | cm->profile = oxcf->profile; |
| 1071 | cm->bit_depth = oxcf->bit_depth; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1072 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1073 | cm->use_highbitdepth = oxcf->use_highbitdepth; |
| 1074 | #endif |
| 1075 | cm->color_space = oxcf->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 1076 | #if CONFIG_COLORSPACE_HEADERS |
| 1077 | cm->transfer_function = oxcf->transfer_function; |
| 1078 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
| 1079 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1080 | cm->color_range = oxcf->color_range; |
| 1081 | |
| 1082 | cm->width = oxcf->width; |
| 1083 | cm->height = oxcf->height; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 1084 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1085 | |
| 1086 | // Single thread case: use counts in common. |
| 1087 | cpi->td.counts = &cm->counts; |
| 1088 | |
| 1089 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1090 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1091 | |
| 1092 | cpi->static_mb_pct = 0; |
| 1093 | cpi->ref_frame_flags = 0; |
| 1094 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 1095 | // Reset resize pending flags |
| 1096 | cpi->resize_pending_width = 0; |
| 1097 | cpi->resize_pending_height = 0; |
| 1098 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1099 | init_buffer_indices(cpi); |
| 1100 | } |
| 1101 | |
| 1102 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1103 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1104 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 1105 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 1106 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 1107 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 1108 | |
| 1109 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 1110 | rc->optimal_buffer_level = |
| 1111 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1112 | rc->maximum_buffer_size = |
| 1113 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1114 | } |
| 1115 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1116 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1117 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 1118 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1119 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1120 | cpi->fn_ptr[BT].vf = VF; \ |
| 1121 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1122 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1123 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 1124 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 1125 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
| 1126 | |
| 1127 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1128 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1129 | int source_stride, \ |
| 1130 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1131 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1132 | } \ |
| 1133 | static unsigned int fnname##_bits10( \ |
| 1134 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1135 | int ref_stride) { \ |
| 1136 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1137 | } \ |
| 1138 | static unsigned int fnname##_bits12( \ |
| 1139 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1140 | int ref_stride) { \ |
| 1141 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1142 | } |
| 1143 | |
| 1144 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1145 | static unsigned int fnname##_bits8( \ |
| 1146 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1147 | int ref_stride, const uint8_t *second_pred) { \ |
| 1148 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1149 | } \ |
| 1150 | static unsigned int fnname##_bits10( \ |
| 1151 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1152 | int ref_stride, const uint8_t *second_pred) { \ |
| 1153 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1154 | 2; \ |
| 1155 | } \ |
| 1156 | static unsigned int fnname##_bits12( \ |
| 1157 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1158 | int ref_stride, const uint8_t *second_pred) { \ |
| 1159 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1160 | 4; \ |
| 1161 | } |
| 1162 | |
| 1163 | #define MAKE_BFP_SAD3_WRAPPER(fnname) \ |
| 1164 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1165 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1166 | unsigned int *sad_array) { \ |
| 1167 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1168 | } \ |
| 1169 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1170 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1171 | unsigned int *sad_array) { \ |
| 1172 | int i; \ |
| 1173 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1174 | for (i = 0; i < 3; i++) sad_array[i] >>= 2; \ |
| 1175 | } \ |
| 1176 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1177 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1178 | unsigned int *sad_array) { \ |
| 1179 | int i; \ |
| 1180 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1181 | for (i = 0; i < 3; i++) sad_array[i] >>= 4; \ |
| 1182 | } |
| 1183 | |
| 1184 | #define MAKE_BFP_SAD8_WRAPPER(fnname) \ |
| 1185 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1186 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1187 | unsigned int *sad_array) { \ |
| 1188 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1189 | } \ |
| 1190 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1191 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1192 | unsigned int *sad_array) { \ |
| 1193 | int i; \ |
| 1194 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1195 | for (i = 0; i < 8; i++) sad_array[i] >>= 2; \ |
| 1196 | } \ |
| 1197 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1198 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1199 | unsigned int *sad_array) { \ |
| 1200 | int i; \ |
| 1201 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1202 | for (i = 0; i < 8; i++) sad_array[i] >>= 4; \ |
| 1203 | } |
| 1204 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1205 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1206 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1207 | unsigned int *sad_array) { \ |
| 1208 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1209 | } \ |
| 1210 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1211 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1212 | unsigned int *sad_array) { \ |
| 1213 | int i; \ |
| 1214 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1215 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1216 | } \ |
| 1217 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1218 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1219 | unsigned int *sad_array) { \ |
| 1220 | int i; \ |
| 1221 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1222 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1223 | } |
| 1224 | |
| 1225 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1226 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1227 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
| 1228 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad128x128x3) |
| 1229 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad128x128x8) |
| 1230 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1231 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1232 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1233 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1234 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1235 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1236 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1237 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1238 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1239 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1240 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1241 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1242 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1243 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1244 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1245 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1246 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1247 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1248 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1249 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1250 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1251 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
| 1252 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad32x32x3) |
| 1253 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad32x32x8) |
| 1254 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1255 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1256 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
| 1257 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad64x64x3) |
| 1258 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad64x64x8) |
| 1259 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1260 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1261 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
| 1262 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x16x3) |
| 1263 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x16x8) |
| 1264 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1265 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1266 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
| 1267 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x8x3) |
| 1268 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x8x8) |
| 1269 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1270 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1271 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
| 1272 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x16x3) |
| 1273 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x16x8) |
| 1274 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1275 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1276 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
| 1277 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x8x3) |
| 1278 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x8x8) |
| 1279 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1280 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1281 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
| 1282 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x4x8) |
| 1283 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1284 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1285 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
| 1286 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x8x8) |
| 1287 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1288 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1289 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
| 1290 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad4x4x3) |
| 1291 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x4x8) |
| 1292 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1293 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1294 | #if CONFIG_EXT_PARTITION_TYPES |
| 1295 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16) |
| 1296 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg) |
| 1297 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d) |
| 1298 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4) |
| 1299 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg) |
| 1300 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d) |
| 1301 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32) |
| 1302 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg) |
| 1303 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d) |
| 1304 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8) |
| 1305 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg) |
| 1306 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1307 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64) |
| 1308 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg) |
| 1309 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d) |
| 1310 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16) |
| 1311 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg) |
| 1312 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1313 | #if CONFIG_EXT_PARTITION |
| 1314 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x128) |
| 1315 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x128_avg) |
| 1316 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x128x4d) |
| 1317 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x32) |
| 1318 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x32_avg) |
| 1319 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x32x4d) |
| 1320 | #endif // CONFIG_EXT_PARTITION |
| 1321 | #endif // CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1322 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1323 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1324 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1325 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1326 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1327 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1328 | static unsigned int fnname##_bits8( \ |
| 1329 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1330 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1331 | int m_stride, int invert_mask) { \ |
| 1332 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1333 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1334 | } \ |
| 1335 | static unsigned int fnname##_bits10( \ |
| 1336 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1337 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1338 | int m_stride, int invert_mask) { \ |
| 1339 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1340 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1341 | 2; \ |
| 1342 | } \ |
| 1343 | static unsigned int fnname##_bits12( \ |
| 1344 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1345 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1346 | int m_stride, int invert_mask) { \ |
| 1347 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1348 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1349 | 4; \ |
| 1350 | } |
| 1351 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1352 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1353 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1354 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1355 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1356 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1357 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1358 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1359 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1360 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1361 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1362 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1363 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1364 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1365 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1366 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1367 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1368 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1369 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1370 | |
| 1371 | #if CONFIG_EXT_PARTITION_TYPES |
| 1372 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1373 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1374 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1375 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1376 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1377 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1378 | #if CONFIG_EXT_PARTITION |
| 1379 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x128) |
| 1380 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x32) |
| 1381 | #endif // CONFIG_EXT_PARTITION |
| 1382 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1383 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1384 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1385 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1386 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1387 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1388 | |
| 1389 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1390 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1391 | const int32_t *wsrc, \ |
| 1392 | const int32_t *msk) { \ |
| 1393 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1394 | } \ |
| 1395 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1396 | const int32_t *wsrc, \ |
| 1397 | const int32_t *msk) { \ |
| 1398 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1399 | } \ |
| 1400 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1401 | const int32_t *wsrc, \ |
| 1402 | const int32_t *msk) { \ |
| 1403 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1404 | } |
| 1405 | |
| 1406 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1407 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1408 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1409 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1410 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1411 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1412 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1413 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1414 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1415 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1416 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1417 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1418 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1419 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1420 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1421 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1422 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1423 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1424 | |
| 1425 | #if CONFIG_EXT_PARTITION_TYPES |
| 1426 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1427 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1428 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1429 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1430 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1431 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1432 | #if CONFIG_EXT_PARTITION |
| 1433 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x128) |
| 1434 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x32) |
| 1435 | #endif // CONFIG_EXT_PARTITION |
| 1436 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1437 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1438 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1439 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1440 | if (cm->use_highbitdepth) { |
| 1441 | switch (cm->bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1442 | case AOM_BITS_8: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1443 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1444 | #if CONFIG_EXT_PARTITION |
| 1445 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits8, |
| 1446 | aom_highbd_sad128x32_avg_bits8, aom_highbd_8_variance128x32, |
| 1447 | aom_highbd_8_sub_pixel_variance128x32, |
| 1448 | aom_highbd_8_sub_pixel_avg_variance128x32, NULL, NULL, |
| 1449 | aom_highbd_sad128x32x4d_bits8) |
| 1450 | |
| 1451 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits8, |
| 1452 | aom_highbd_sad32x128_avg_bits8, aom_highbd_8_variance32x128, |
| 1453 | aom_highbd_8_sub_pixel_variance32x128, |
| 1454 | aom_highbd_8_sub_pixel_avg_variance32x128, NULL, NULL, |
| 1455 | aom_highbd_sad32x128x4d_bits8) |
| 1456 | #endif // CONFIG_EXT_PARTITION |
| 1457 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1458 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1459 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1460 | aom_highbd_8_sub_pixel_variance64x16, |
| 1461 | aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1462 | aom_highbd_sad64x16x4d_bits8) |
| 1463 | |
| 1464 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1465 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1466 | aom_highbd_8_sub_pixel_variance16x64, |
| 1467 | aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1468 | aom_highbd_sad16x64x4d_bits8) |
| 1469 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1470 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits8, |
| 1471 | aom_highbd_sad32x8_avg_bits8, aom_highbd_8_variance32x8, |
| 1472 | aom_highbd_8_sub_pixel_variance32x8, |
| 1473 | aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1474 | aom_highbd_sad32x8x4d_bits8) |
| 1475 | |
| 1476 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits8, |
| 1477 | aom_highbd_sad8x32_avg_bits8, aom_highbd_8_variance8x32, |
| 1478 | aom_highbd_8_sub_pixel_variance8x32, |
| 1479 | aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1480 | aom_highbd_sad8x32x4d_bits8) |
| 1481 | |
| 1482 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits8, |
| 1483 | aom_highbd_sad16x4_avg_bits8, aom_highbd_8_variance16x4, |
| 1484 | aom_highbd_8_sub_pixel_variance16x4, |
| 1485 | aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1486 | aom_highbd_sad16x4x4d_bits8) |
| 1487 | |
| 1488 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits8, |
| 1489 | aom_highbd_sad4x16_avg_bits8, aom_highbd_8_variance4x16, |
| 1490 | aom_highbd_8_sub_pixel_variance4x16, |
| 1491 | aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1492 | aom_highbd_sad4x16x4d_bits8) |
| 1493 | #endif |
| 1494 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1495 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1496 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1497 | aom_highbd_8_sub_pixel_variance32x16, |
| 1498 | aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1499 | aom_highbd_sad32x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1500 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1501 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1502 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1503 | aom_highbd_8_sub_pixel_variance16x32, |
| 1504 | aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1505 | aom_highbd_sad16x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1506 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1507 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1508 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1509 | aom_highbd_8_sub_pixel_variance64x32, |
| 1510 | aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1511 | aom_highbd_sad64x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1512 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1513 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1514 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1515 | aom_highbd_8_sub_pixel_variance32x64, |
| 1516 | aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1517 | aom_highbd_sad32x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1518 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1519 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1520 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1521 | aom_highbd_8_sub_pixel_variance32x32, |
| 1522 | aom_highbd_8_sub_pixel_avg_variance32x32, |
| 1523 | aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8, |
| 1524 | aom_highbd_sad32x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1525 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1526 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1527 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1528 | aom_highbd_8_sub_pixel_variance64x64, |
| 1529 | aom_highbd_8_sub_pixel_avg_variance64x64, |
| 1530 | aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8, |
| 1531 | aom_highbd_sad64x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1532 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1533 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1534 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1535 | aom_highbd_8_sub_pixel_variance16x16, |
| 1536 | aom_highbd_8_sub_pixel_avg_variance16x16, |
| 1537 | aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8, |
| 1538 | aom_highbd_sad16x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1539 | |
| 1540 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1541 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1542 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
| 1543 | aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8, |
| 1544 | aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1545 | |
| 1546 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1547 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1548 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
| 1549 | aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8, |
| 1550 | aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1551 | |
| 1552 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1553 | BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8, |
| 1554 | aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8, |
| 1555 | aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits8, |
| 1556 | aom_highbd_sad8x8x8_bits8, aom_highbd_sad8x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1557 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1558 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8, |
| 1559 | aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4, |
| 1560 | aom_highbd_8_sub_pixel_variance8x4, |
| 1561 | aom_highbd_8_sub_pixel_avg_variance8x4, NULL, |
| 1562 | aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1563 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1564 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8, |
| 1565 | aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8, |
| 1566 | aom_highbd_8_sub_pixel_variance4x8, |
| 1567 | aom_highbd_8_sub_pixel_avg_variance4x8, NULL, |
| 1568 | aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1569 | |
| 1570 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1571 | BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8, |
| 1572 | aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4, |
| 1573 | aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits8, |
| 1574 | aom_highbd_sad4x4x8_bits8, aom_highbd_sad4x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1575 | |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1576 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_8_variance2x2, NULL, NULL, |
| 1577 | NULL, NULL, NULL) |
| 1578 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_8_variance4x2, NULL, NULL, |
| 1579 | NULL, NULL, NULL) |
| 1580 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_8_variance2x4, NULL, NULL, |
| 1581 | NULL, NULL, NULL) |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1582 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1583 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1584 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1585 | aom_highbd_sad128x128_avg_bits8, |
| 1586 | aom_highbd_8_variance128x128, |
| 1587 | aom_highbd_8_sub_pixel_variance128x128, |
| 1588 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1589 | aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8, |
| 1590 | aom_highbd_sad128x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1591 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1592 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1593 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1594 | aom_highbd_8_sub_pixel_variance128x64, |
| 1595 | aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1596 | aom_highbd_sad128x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1597 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1598 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1599 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1600 | aom_highbd_8_sub_pixel_variance64x128, |
| 1601 | aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1602 | aom_highbd_sad64x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1603 | #endif // CONFIG_EXT_PARTITION |
| 1604 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1605 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1606 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1607 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1608 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1609 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1610 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1611 | aom_highbd_8_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1612 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1613 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1614 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1615 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1616 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1617 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1618 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1619 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1620 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1621 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1622 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1623 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1624 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1625 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1626 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1627 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1628 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1629 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1630 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1631 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1632 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1633 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1634 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1635 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1636 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1637 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1638 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1639 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1640 | #if CONFIG_EXT_PARTITION |
| 1641 | HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits8, |
| 1642 | aom_highbd_8_masked_sub_pixel_variance128x32) |
| 1643 | |
| 1644 | HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits8, |
| 1645 | aom_highbd_8_masked_sub_pixel_variance32x128) |
| 1646 | #endif // CONFIG_EXT_PARTITION |
| 1647 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1648 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1649 | aom_highbd_8_masked_sub_pixel_variance64x16) |
| 1650 | |
| 1651 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1652 | aom_highbd_8_masked_sub_pixel_variance16x64) |
| 1653 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1654 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1655 | aom_highbd_8_masked_sub_pixel_variance32x8) |
| 1656 | |
| 1657 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1658 | aom_highbd_8_masked_sub_pixel_variance8x32) |
| 1659 | |
| 1660 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1661 | aom_highbd_8_masked_sub_pixel_variance16x4) |
| 1662 | |
| 1663 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1664 | aom_highbd_8_masked_sub_pixel_variance4x16) |
| 1665 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1666 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1667 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1668 | aom_highbd_obmc_variance128x128, |
| 1669 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1670 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1671 | aom_highbd_obmc_variance128x64, |
| 1672 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1673 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1674 | aom_highbd_obmc_variance64x128, |
| 1675 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1676 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1677 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1678 | aom_highbd_obmc_variance64x64, |
| 1679 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1680 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1681 | aom_highbd_obmc_variance64x32, |
| 1682 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1683 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1684 | aom_highbd_obmc_variance32x64, |
| 1685 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1686 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1687 | aom_highbd_obmc_variance32x32, |
| 1688 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1689 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1690 | aom_highbd_obmc_variance32x16, |
| 1691 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1692 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1693 | aom_highbd_obmc_variance16x32, |
| 1694 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1695 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1696 | aom_highbd_obmc_variance16x16, |
| 1697 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1698 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1699 | aom_highbd_obmc_variance8x16, |
| 1700 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1701 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1702 | aom_highbd_obmc_variance16x8, |
| 1703 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1704 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1705 | aom_highbd_obmc_variance8x8, |
| 1706 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 1707 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 1708 | aom_highbd_obmc_variance4x8, |
| 1709 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 1710 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 1711 | aom_highbd_obmc_variance8x4, |
| 1712 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 1713 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 1714 | aom_highbd_obmc_variance4x4, |
| 1715 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1716 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1717 | #if CONFIG_EXT_PARTITION |
| 1718 | HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits8, |
| 1719 | aom_highbd_obmc_variance128x32, |
| 1720 | aom_highbd_obmc_sub_pixel_variance128x32) |
| 1721 | |
| 1722 | HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits8, |
| 1723 | aom_highbd_obmc_variance32x128, |
| 1724 | aom_highbd_obmc_sub_pixel_variance32x128) |
| 1725 | #endif // CONFIG_EXT_PARTITION |
| 1726 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1727 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 1728 | aom_highbd_obmc_variance64x16, |
| 1729 | aom_highbd_obmc_sub_pixel_variance64x16) |
| 1730 | |
| 1731 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 1732 | aom_highbd_obmc_variance16x64, |
| 1733 | aom_highbd_obmc_sub_pixel_variance16x64) |
| 1734 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1735 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 1736 | aom_highbd_obmc_variance32x8, |
| 1737 | aom_highbd_obmc_sub_pixel_variance32x8) |
| 1738 | |
| 1739 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 1740 | aom_highbd_obmc_variance8x32, |
| 1741 | aom_highbd_obmc_sub_pixel_variance8x32) |
| 1742 | |
| 1743 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 1744 | aom_highbd_obmc_variance16x4, |
| 1745 | aom_highbd_obmc_sub_pixel_variance16x4) |
| 1746 | |
| 1747 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 1748 | aom_highbd_obmc_variance4x16, |
| 1749 | aom_highbd_obmc_sub_pixel_variance4x16) |
| 1750 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1751 | break; |
| 1752 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1753 | case AOM_BITS_10: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1754 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1755 | #if CONFIG_EXT_PARTITION |
| 1756 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits10, |
| 1757 | aom_highbd_sad128x32_avg_bits10, |
| 1758 | aom_highbd_10_variance128x32, |
| 1759 | aom_highbd_10_sub_pixel_variance128x32, |
| 1760 | aom_highbd_10_sub_pixel_avg_variance128x32, NULL, NULL, |
| 1761 | aom_highbd_sad128x32x4d_bits10) |
| 1762 | |
| 1763 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits10, |
| 1764 | aom_highbd_sad32x128_avg_bits10, |
| 1765 | aom_highbd_10_variance32x128, |
| 1766 | aom_highbd_10_sub_pixel_variance32x128, |
| 1767 | aom_highbd_10_sub_pixel_avg_variance32x128, NULL, NULL, |
| 1768 | aom_highbd_sad32x128x4d_bits10) |
| 1769 | #endif // CONFIG_EXT_PARTITION |
| 1770 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1771 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 1772 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 1773 | aom_highbd_10_sub_pixel_variance64x16, |
| 1774 | aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1775 | aom_highbd_sad64x16x4d_bits10) |
| 1776 | |
| 1777 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 1778 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 1779 | aom_highbd_10_sub_pixel_variance16x64, |
| 1780 | aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1781 | aom_highbd_sad16x64x4d_bits10) |
| 1782 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1783 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 1784 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 1785 | aom_highbd_10_sub_pixel_variance32x8, |
| 1786 | aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1787 | aom_highbd_sad32x8x4d_bits10) |
| 1788 | |
| 1789 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 1790 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 1791 | aom_highbd_10_sub_pixel_variance8x32, |
| 1792 | aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1793 | aom_highbd_sad8x32x4d_bits10) |
| 1794 | |
| 1795 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 1796 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 1797 | aom_highbd_10_sub_pixel_variance16x4, |
| 1798 | aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1799 | aom_highbd_sad16x4x4d_bits10) |
| 1800 | |
| 1801 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 1802 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 1803 | aom_highbd_10_sub_pixel_variance4x16, |
| 1804 | aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1805 | aom_highbd_sad4x16x4d_bits10) |
| 1806 | #endif |
| 1807 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1808 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 1809 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 1810 | aom_highbd_10_sub_pixel_variance32x16, |
| 1811 | aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1812 | aom_highbd_sad32x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1813 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1814 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 1815 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 1816 | aom_highbd_10_sub_pixel_variance16x32, |
| 1817 | aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1818 | aom_highbd_sad16x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1819 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1820 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 1821 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 1822 | aom_highbd_10_sub_pixel_variance64x32, |
| 1823 | aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1824 | aom_highbd_sad64x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1825 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1826 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 1827 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 1828 | aom_highbd_10_sub_pixel_variance32x64, |
| 1829 | aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1830 | aom_highbd_sad32x64x4d_bits10) |
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_32X32, aom_highbd_sad32x32_bits10, |
| 1833 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 1834 | aom_highbd_10_sub_pixel_variance32x32, |
| 1835 | aom_highbd_10_sub_pixel_avg_variance32x32, |
| 1836 | aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10, |
| 1837 | aom_highbd_sad32x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1838 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1839 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 1840 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 1841 | aom_highbd_10_sub_pixel_variance64x64, |
| 1842 | aom_highbd_10_sub_pixel_avg_variance64x64, |
| 1843 | aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10, |
| 1844 | aom_highbd_sad64x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1845 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1846 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 1847 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 1848 | aom_highbd_10_sub_pixel_variance16x16, |
| 1849 | aom_highbd_10_sub_pixel_avg_variance16x16, |
| 1850 | aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10, |
| 1851 | aom_highbd_sad16x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1852 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1853 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 1854 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 1855 | aom_highbd_10_sub_pixel_variance16x8, |
| 1856 | aom_highbd_10_sub_pixel_avg_variance16x8, |
| 1857 | aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10, |
| 1858 | aom_highbd_sad16x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1859 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1860 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 1861 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 1862 | aom_highbd_10_sub_pixel_variance8x16, |
| 1863 | aom_highbd_10_sub_pixel_avg_variance8x16, |
| 1864 | aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10, |
| 1865 | aom_highbd_sad8x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1866 | |
| 1867 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1868 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 1869 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
| 1870 | aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10, |
| 1871 | aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1872 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1873 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10, |
| 1874 | aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4, |
| 1875 | aom_highbd_10_sub_pixel_variance8x4, |
| 1876 | aom_highbd_10_sub_pixel_avg_variance8x4, NULL, |
| 1877 | aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1878 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1879 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10, |
| 1880 | aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8, |
| 1881 | aom_highbd_10_sub_pixel_variance4x8, |
| 1882 | aom_highbd_10_sub_pixel_avg_variance4x8, NULL, |
| 1883 | aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1884 | |
| 1885 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1886 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 1887 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
| 1888 | aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10, |
| 1889 | aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1890 | |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1891 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_10_variance2x2, NULL, NULL, |
| 1892 | NULL, NULL, NULL) |
| 1893 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_10_variance4x2, NULL, NULL, |
| 1894 | NULL, NULL, NULL) |
| 1895 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_10_variance2x4, NULL, NULL, |
| 1896 | NULL, NULL, NULL) |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1897 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1898 | #if CONFIG_EXT_PARTITION |
| 1899 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1900 | BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 1901 | aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128, |
| 1902 | aom_highbd_10_sub_pixel_variance128x128, |
| 1903 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 1904 | aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10, |
| 1905 | aom_highbd_sad128x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1906 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1907 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 1908 | aom_highbd_sad128x64_avg_bits10, |
| 1909 | aom_highbd_10_variance128x64, |
| 1910 | aom_highbd_10_sub_pixel_variance128x64, |
| 1911 | aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1912 | aom_highbd_sad128x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1913 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1914 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 1915 | aom_highbd_sad64x128_avg_bits10, |
| 1916 | aom_highbd_10_variance64x128, |
| 1917 | aom_highbd_10_sub_pixel_variance64x128, |
| 1918 | aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1919 | aom_highbd_sad64x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1920 | #endif // CONFIG_EXT_PARTITION |
| 1921 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1922 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1923 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 1924 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 1925 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 1926 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 1927 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 1928 | aom_highbd_10_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1929 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1930 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 1931 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 1932 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 1933 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 1934 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 1935 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 1936 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 1937 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 1938 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 1939 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 1940 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 1941 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 1942 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 1943 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 1944 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 1945 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 1946 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 1947 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 1948 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 1949 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 1950 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 1951 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 1952 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 1953 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 1954 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 1955 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1956 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1957 | #if CONFIG_EXT_PARTITION |
| 1958 | HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits10, |
| 1959 | aom_highbd_10_masked_sub_pixel_variance128x32) |
| 1960 | |
| 1961 | HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits10, |
| 1962 | aom_highbd_10_masked_sub_pixel_variance32x128) |
| 1963 | #endif // CONFIG_EXT_PARTITION |
| 1964 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1965 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 1966 | aom_highbd_10_masked_sub_pixel_variance64x16) |
| 1967 | |
| 1968 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 1969 | aom_highbd_10_masked_sub_pixel_variance16x64) |
| 1970 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1971 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 1972 | aom_highbd_10_masked_sub_pixel_variance32x8) |
| 1973 | |
| 1974 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 1975 | aom_highbd_10_masked_sub_pixel_variance8x32) |
| 1976 | |
| 1977 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 1978 | aom_highbd_10_masked_sub_pixel_variance16x4) |
| 1979 | |
| 1980 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 1981 | aom_highbd_10_masked_sub_pixel_variance4x16) |
| 1982 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1983 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1984 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 1985 | aom_highbd_10_obmc_variance128x128, |
| 1986 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 1987 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 1988 | aom_highbd_10_obmc_variance128x64, |
| 1989 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 1990 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 1991 | aom_highbd_10_obmc_variance64x128, |
| 1992 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1993 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1994 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 1995 | aom_highbd_10_obmc_variance64x64, |
| 1996 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 1997 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 1998 | aom_highbd_10_obmc_variance64x32, |
| 1999 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 2000 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 2001 | aom_highbd_10_obmc_variance32x64, |
| 2002 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 2003 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 2004 | aom_highbd_10_obmc_variance32x32, |
| 2005 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 2006 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 2007 | aom_highbd_10_obmc_variance32x16, |
| 2008 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 2009 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 2010 | aom_highbd_10_obmc_variance16x32, |
| 2011 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 2012 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 2013 | aom_highbd_10_obmc_variance16x16, |
| 2014 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 2015 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 2016 | aom_highbd_10_obmc_variance8x16, |
| 2017 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 2018 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 2019 | aom_highbd_10_obmc_variance16x8, |
| 2020 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 2021 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 2022 | aom_highbd_10_obmc_variance8x8, |
| 2023 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 2024 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 2025 | aom_highbd_10_obmc_variance4x8, |
| 2026 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 2027 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 2028 | aom_highbd_10_obmc_variance8x4, |
| 2029 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 2030 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 2031 | aom_highbd_10_obmc_variance4x4, |
| 2032 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2033 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2034 | #if CONFIG_EXT_PARTITION |
| 2035 | HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits10, |
| 2036 | aom_highbd_10_obmc_variance128x32, |
| 2037 | aom_highbd_10_obmc_sub_pixel_variance128x32) |
| 2038 | |
| 2039 | HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits10, |
| 2040 | aom_highbd_10_obmc_variance32x128, |
| 2041 | aom_highbd_10_obmc_sub_pixel_variance32x128) |
| 2042 | #endif // CONFIG_EXT_PARTITION |
| 2043 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2044 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 2045 | aom_highbd_10_obmc_variance64x16, |
| 2046 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 2047 | |
| 2048 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 2049 | aom_highbd_10_obmc_variance16x64, |
| 2050 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 2051 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2052 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 2053 | aom_highbd_10_obmc_variance32x8, |
| 2054 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 2055 | |
| 2056 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 2057 | aom_highbd_10_obmc_variance8x32, |
| 2058 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 2059 | |
| 2060 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 2061 | aom_highbd_10_obmc_variance16x4, |
| 2062 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 2063 | |
| 2064 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 2065 | aom_highbd_10_obmc_variance4x16, |
| 2066 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
| 2067 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2068 | break; |
| 2069 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2070 | case AOM_BITS_12: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2071 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2072 | #if CONFIG_EXT_PARTITION |
| 2073 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits12, |
| 2074 | aom_highbd_sad128x32_avg_bits12, |
| 2075 | aom_highbd_12_variance128x32, |
| 2076 | aom_highbd_12_sub_pixel_variance128x32, |
| 2077 | aom_highbd_12_sub_pixel_avg_variance128x32, NULL, NULL, |
| 2078 | aom_highbd_sad128x32x4d_bits12) |
| 2079 | |
| 2080 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits12, |
| 2081 | aom_highbd_sad32x128_avg_bits12, |
| 2082 | aom_highbd_12_variance32x128, |
| 2083 | aom_highbd_12_sub_pixel_variance32x128, |
| 2084 | aom_highbd_12_sub_pixel_avg_variance32x128, NULL, NULL, |
| 2085 | aom_highbd_sad32x128x4d_bits12) |
| 2086 | #endif // CONFIG_EXT_PARTITION |
| 2087 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2088 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 2089 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 2090 | aom_highbd_12_sub_pixel_variance64x16, |
| 2091 | aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2092 | aom_highbd_sad64x16x4d_bits12) |
| 2093 | |
| 2094 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 2095 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 2096 | aom_highbd_12_sub_pixel_variance16x64, |
| 2097 | aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2098 | aom_highbd_sad16x64x4d_bits12) |
| 2099 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2100 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 2101 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 2102 | aom_highbd_12_sub_pixel_variance32x8, |
| 2103 | aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2104 | aom_highbd_sad32x8x4d_bits12) |
| 2105 | |
| 2106 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 2107 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 2108 | aom_highbd_12_sub_pixel_variance8x32, |
| 2109 | aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2110 | aom_highbd_sad8x32x4d_bits12) |
| 2111 | |
| 2112 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 2113 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 2114 | aom_highbd_12_sub_pixel_variance16x4, |
| 2115 | aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2116 | aom_highbd_sad16x4x4d_bits12) |
| 2117 | |
| 2118 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 2119 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 2120 | aom_highbd_12_sub_pixel_variance4x16, |
| 2121 | aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2122 | aom_highbd_sad4x16x4d_bits12) |
| 2123 | #endif |
| 2124 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2125 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 2126 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 2127 | aom_highbd_12_sub_pixel_variance32x16, |
| 2128 | aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2129 | aom_highbd_sad32x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2130 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2131 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 2132 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 2133 | aom_highbd_12_sub_pixel_variance16x32, |
| 2134 | aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2135 | aom_highbd_sad16x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2136 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2137 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 2138 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 2139 | aom_highbd_12_sub_pixel_variance64x32, |
| 2140 | aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2141 | aom_highbd_sad64x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2142 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2143 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 2144 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 2145 | aom_highbd_12_sub_pixel_variance32x64, |
| 2146 | aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2147 | aom_highbd_sad32x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2148 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2149 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 2150 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 2151 | aom_highbd_12_sub_pixel_variance32x32, |
| 2152 | aom_highbd_12_sub_pixel_avg_variance32x32, |
| 2153 | aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12, |
| 2154 | aom_highbd_sad32x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2155 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2156 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2157 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2158 | aom_highbd_12_sub_pixel_variance64x64, |
| 2159 | aom_highbd_12_sub_pixel_avg_variance64x64, |
| 2160 | aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12, |
| 2161 | aom_highbd_sad64x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2162 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2163 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2164 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2165 | aom_highbd_12_sub_pixel_variance16x16, |
| 2166 | aom_highbd_12_sub_pixel_avg_variance16x16, |
| 2167 | aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12, |
| 2168 | aom_highbd_sad16x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2169 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2170 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2171 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2172 | aom_highbd_12_sub_pixel_variance16x8, |
| 2173 | aom_highbd_12_sub_pixel_avg_variance16x8, |
| 2174 | aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12, |
| 2175 | aom_highbd_sad16x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2176 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2177 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2178 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2179 | aom_highbd_12_sub_pixel_variance8x16, |
| 2180 | aom_highbd_12_sub_pixel_avg_variance8x16, |
| 2181 | aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12, |
| 2182 | aom_highbd_sad8x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2183 | |
| 2184 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2185 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2186 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
| 2187 | aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12, |
| 2188 | aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2189 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2190 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12, |
| 2191 | aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4, |
| 2192 | aom_highbd_12_sub_pixel_variance8x4, |
| 2193 | aom_highbd_12_sub_pixel_avg_variance8x4, NULL, |
| 2194 | aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2195 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2196 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12, |
| 2197 | aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8, |
| 2198 | aom_highbd_12_sub_pixel_variance4x8, |
| 2199 | aom_highbd_12_sub_pixel_avg_variance4x8, NULL, |
| 2200 | aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2201 | |
| 2202 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2203 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2204 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
| 2205 | aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12, |
| 2206 | aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2207 | |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 2208 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_12_variance2x2, NULL, NULL, |
| 2209 | NULL, NULL, NULL) |
| 2210 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_12_variance4x2, NULL, NULL, |
| 2211 | NULL, NULL, NULL) |
| 2212 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_12_variance2x4, NULL, NULL, |
| 2213 | NULL, NULL, NULL) |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 2214 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2215 | #if CONFIG_EXT_PARTITION |
| 2216 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2217 | BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2218 | aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128, |
| 2219 | aom_highbd_12_sub_pixel_variance128x128, |
| 2220 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2221 | aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12, |
| 2222 | aom_highbd_sad128x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2223 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2224 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2225 | aom_highbd_sad128x64_avg_bits12, |
| 2226 | aom_highbd_12_variance128x64, |
| 2227 | aom_highbd_12_sub_pixel_variance128x64, |
| 2228 | aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL, |
| 2229 | aom_highbd_sad128x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2230 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2231 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2232 | aom_highbd_sad64x128_avg_bits12, |
| 2233 | aom_highbd_12_variance64x128, |
| 2234 | aom_highbd_12_sub_pixel_variance64x128, |
| 2235 | aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL, |
| 2236 | aom_highbd_sad64x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2237 | #endif // CONFIG_EXT_PARTITION |
| 2238 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2239 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2240 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2241 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2242 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2243 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2244 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2245 | aom_highbd_12_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2246 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2247 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2248 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2249 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2250 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2251 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2252 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2253 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2254 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2255 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2256 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2257 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2258 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2259 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2260 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2261 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2262 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2263 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2264 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2265 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2266 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2267 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2268 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2269 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2270 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2271 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2272 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2273 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2274 | #if CONFIG_EXT_PARTITION |
| 2275 | HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits12, |
| 2276 | aom_highbd_12_masked_sub_pixel_variance128x32) |
| 2277 | |
| 2278 | HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits12, |
| 2279 | aom_highbd_12_masked_sub_pixel_variance32x128) |
| 2280 | #endif // CONFIG_EXT_PARTITION |
| 2281 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2282 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2283 | aom_highbd_12_masked_sub_pixel_variance64x16) |
| 2284 | |
| 2285 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2286 | aom_highbd_12_masked_sub_pixel_variance16x64) |
| 2287 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2288 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2289 | aom_highbd_12_masked_sub_pixel_variance32x8) |
| 2290 | |
| 2291 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2292 | aom_highbd_12_masked_sub_pixel_variance8x32) |
| 2293 | |
| 2294 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2295 | aom_highbd_12_masked_sub_pixel_variance16x4) |
| 2296 | |
| 2297 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2298 | aom_highbd_12_masked_sub_pixel_variance4x16) |
| 2299 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2300 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2301 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2302 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2303 | aom_highbd_12_obmc_variance128x128, |
| 2304 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2305 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2306 | aom_highbd_12_obmc_variance128x64, |
| 2307 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 2308 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 2309 | aom_highbd_12_obmc_variance64x128, |
| 2310 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2311 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2312 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 2313 | aom_highbd_12_obmc_variance64x64, |
| 2314 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 2315 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 2316 | aom_highbd_12_obmc_variance64x32, |
| 2317 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 2318 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 2319 | aom_highbd_12_obmc_variance32x64, |
| 2320 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 2321 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 2322 | aom_highbd_12_obmc_variance32x32, |
| 2323 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 2324 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 2325 | aom_highbd_12_obmc_variance32x16, |
| 2326 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 2327 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 2328 | aom_highbd_12_obmc_variance16x32, |
| 2329 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 2330 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 2331 | aom_highbd_12_obmc_variance16x16, |
| 2332 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 2333 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 2334 | aom_highbd_12_obmc_variance8x16, |
| 2335 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 2336 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 2337 | aom_highbd_12_obmc_variance16x8, |
| 2338 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 2339 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 2340 | aom_highbd_12_obmc_variance8x8, |
| 2341 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 2342 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 2343 | aom_highbd_12_obmc_variance4x8, |
| 2344 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 2345 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 2346 | aom_highbd_12_obmc_variance8x4, |
| 2347 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 2348 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 2349 | aom_highbd_12_obmc_variance4x4, |
| 2350 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2351 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2352 | #if CONFIG_EXT_PARTITION |
| 2353 | HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits12, |
| 2354 | aom_highbd_12_obmc_variance128x32, |
| 2355 | aom_highbd_12_obmc_sub_pixel_variance128x32) |
| 2356 | |
| 2357 | HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits12, |
| 2358 | aom_highbd_12_obmc_variance32x128, |
| 2359 | aom_highbd_12_obmc_sub_pixel_variance32x128) |
| 2360 | #endif // CONFIG_EXT_PARTITION |
| 2361 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2362 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 2363 | aom_highbd_12_obmc_variance64x16, |
| 2364 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
| 2365 | |
| 2366 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 2367 | aom_highbd_12_obmc_variance16x64, |
| 2368 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
| 2369 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2370 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 2371 | aom_highbd_12_obmc_variance32x8, |
| 2372 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
| 2373 | |
| 2374 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 2375 | aom_highbd_12_obmc_variance8x32, |
| 2376 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
| 2377 | |
| 2378 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 2379 | aom_highbd_12_obmc_variance16x4, |
| 2380 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
| 2381 | |
| 2382 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 2383 | aom_highbd_12_obmc_variance4x16, |
| 2384 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
| 2385 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2386 | break; |
| 2387 | |
| 2388 | default: |
| 2389 | assert(0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2390 | "cm->bit_depth should be AOM_BITS_8, " |
| 2391 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2392 | } |
| 2393 | } |
| 2394 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2395 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2396 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2397 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 2398 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2399 | |
| 2400 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2401 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2402 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2403 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2404 | |
| 2405 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2406 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2407 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2408 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2409 | |
| 2410 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2411 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2412 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2413 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2416 | void set_compound_tools(AV1_COMMON *cm) { |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2417 | cm->allow_interintra_compound = 1; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2418 | cm->allow_masked_compound = 1; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2419 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2420 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2421 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 2422 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2423 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2424 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2425 | |
| 2426 | if (cm->profile != oxcf->profile) cm->profile = oxcf->profile; |
| 2427 | cm->bit_depth = oxcf->bit_depth; |
| 2428 | cm->color_space = oxcf->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 2429 | #if CONFIG_COLORSPACE_HEADERS |
| 2430 | cm->transfer_function = oxcf->transfer_function; |
| 2431 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
| 2432 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2433 | cm->color_range = oxcf->color_range; |
| 2434 | |
| 2435 | if (cm->profile <= PROFILE_1) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2436 | assert(cm->bit_depth == AOM_BITS_8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2437 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2438 | assert(cm->bit_depth > AOM_BITS_8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2439 | |
| 2440 | cpi->oxcf = *oxcf; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2441 | x->e_mbd.bd = (int)cm->bit_depth; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2442 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2443 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2444 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2445 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 2446 | } else { |
| 2447 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 2448 | } |
| 2449 | |
| 2450 | cpi->refresh_last_frame = 1; |
| 2451 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2452 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 2453 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2454 | |
| 2455 | cm->refresh_frame_context = |
| 2456 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 2457 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 2458 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2459 | #if CONFIG_EXT_TILE |
| 2460 | if (oxcf->large_scale_tile) |
| 2461 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 2462 | #endif // CONFIG_EXT_TILE |
| 2463 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 2464 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2465 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 2466 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2467 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 2468 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2469 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 2470 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 2471 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2472 | set_compound_tools(cm); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2473 | av1_reset_segment_features(cm); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2474 | #if CONFIG_AMVR |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2475 | set_high_precision_mv(cpi, 1, 0); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2476 | #else |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2477 | set_high_precision_mv(cpi, 1); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2478 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2479 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2480 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 2481 | |
| 2482 | // Under a configuration change, where maximum_buffer_size may change, |
| 2483 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2484 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2485 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2486 | |
| 2487 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2488 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2489 | |
| 2490 | // Set absolute upper and lower quality limits |
| 2491 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2492 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2493 | |
| 2494 | cm->interp_filter = cpi->sf.default_interp_filter; |
| 2495 | |
| 2496 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2497 | cm->render_width = cpi->oxcf.render_width; |
| 2498 | cm->render_height = cpi->oxcf.render_height; |
| 2499 | } else { |
| 2500 | cm->render_width = cpi->oxcf.width; |
| 2501 | cm->render_height = cpi->oxcf.height; |
| 2502 | } |
| 2503 | cm->width = cpi->oxcf.width; |
| 2504 | cm->height = cpi->oxcf.height; |
| 2505 | |
| 2506 | if (cpi->initial_width) { |
| 2507 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2508 | av1_free_context_buffers(cm); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 2509 | av1_free_pc_tree(&cpi->td); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2510 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2511 | realloc_segmentation_maps(cpi); |
| 2512 | cpi->initial_width = cpi->initial_height = 0; |
| 2513 | } |
| 2514 | } |
| 2515 | update_frame_size(cpi); |
| 2516 | |
| 2517 | cpi->alt_ref_source = NULL; |
| 2518 | rc->is_src_frame_alt_ref = 0; |
| 2519 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2520 | rc->is_bwd_ref_frame = 0; |
| 2521 | rc->is_last_bipred_frame = 0; |
| 2522 | rc->is_bipred_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2523 | |
| 2524 | #if 0 |
| 2525 | // Experimental RD Code |
| 2526 | cpi->frame_distortion = 0; |
| 2527 | cpi->last_frame_distortion = 0; |
| 2528 | #endif |
| 2529 | |
| 2530 | set_tile_info(cpi); |
| 2531 | |
| 2532 | cpi->ext_refresh_frame_flags_pending = 0; |
| 2533 | cpi->ext_refresh_frame_context_pending = 0; |
| 2534 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2535 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2536 | highbd_set_var_fns(cpi); |
| 2537 | #endif |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2538 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 2539 | cpi->common.ans_window_size_log2 = cpi->oxcf.ans_window_size_log2; |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2540 | #endif // CONFIG_ANS && ANS_MAX_SYMBOLS |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2541 | #if CONFIG_AMVR |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 2542 | cm->seq_force_integer_mv = 2; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2543 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2546 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 2547 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2548 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2549 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2550 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2551 | |
| 2552 | if (!cm) return NULL; |
| 2553 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2554 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2555 | |
| 2556 | if (setjmp(cm->error.jmp)) { |
| 2557 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2558 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2559 | return 0; |
| 2560 | } |
| 2561 | |
| 2562 | cm->error.setjmp = 1; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2563 | cm->alloc_mi = enc_alloc_mi; |
| 2564 | cm->free_mi = enc_free_mi; |
| 2565 | cm->setup_mi = enc_setup_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2566 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2567 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2568 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
| 2569 | CHECK_MEM_ERROR(cm, cm->frame_contexts, |
| 2570 | (FRAME_CONTEXT *)aom_memalign( |
| 2571 | 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts))); |
| 2572 | memset(cm->fc, 0, sizeof(*cm->fc)); |
| 2573 | memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2574 | |
| 2575 | cpi->resize_state = 0; |
| 2576 | cpi->resize_avg_qp = 0; |
| 2577 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2578 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2579 | cpi->common.buffer_pool = pool; |
| 2580 | |
| 2581 | init_config(cpi, oxcf); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2582 | #if CONFIG_XIPHRC |
| 2583 | cpi->od_rc.framerate = cpi->framerate; |
| 2584 | cpi->od_rc.frame_width = cm->render_width; |
| 2585 | cpi->od_rc.frame_height = cm->render_height; |
| 2586 | cpi->od_rc.keyframe_rate = oxcf->key_freq; |
| 2587 | cpi->od_rc.goldenframe_rate = FIXED_GF_INTERVAL; |
| 2588 | cpi->od_rc.altref_rate = 25; |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2589 | cpi->od_rc.firstpass_quant = 1; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2590 | cpi->od_rc.bit_depth = cm->bit_depth; |
| 2591 | cpi->od_rc.minq = oxcf->best_allowed_q; |
| 2592 | cpi->od_rc.maxq = oxcf->worst_allowed_q; |
| 2593 | if (cpi->oxcf.rc_mode == AOM_CQ) cpi->od_rc.minq = cpi->od_rc.quality; |
| 2594 | cpi->od_rc.quality = cpi->oxcf.rc_mode == AOM_Q ? oxcf->cq_level : -1; |
| 2595 | cpi->od_rc.periodic_boosts = oxcf->frame_periodic_boost; |
| 2596 | od_enc_rc_init(&cpi->od_rc, |
| 2597 | cpi->oxcf.rc_mode == AOM_Q ? -1 : oxcf->target_bandwidth, |
| 2598 | oxcf->maximum_buffer_size_ms); |
| 2599 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2600 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2601 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2602 | |
| 2603 | cm->current_video_frame = 0; |
| 2604 | cpi->partition_search_skippable_frame = 0; |
| 2605 | cpi->tile_data = NULL; |
| 2606 | cpi->last_show_frame_buf_idx = INVALID_IDX; |
| 2607 | |
| 2608 | realloc_segmentation_maps(cpi); |
| 2609 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2610 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 2611 | memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs)); |
| 2612 | memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp)); |
| 2613 | } |
| 2614 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2615 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 2616 | i++) { |
| 2617 | CHECK_MEM_ERROR( |
| 2618 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2619 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2620 | } |
| 2621 | |
| 2622 | #if CONFIG_FP_MB_STATS |
| 2623 | cpi->use_fp_mb_stats = 0; |
| 2624 | if (cpi->use_fp_mb_stats) { |
| 2625 | // a place holder used to store the first pass mb stats in the first pass |
| 2626 | CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2627 | aom_calloc(cm->MBs * sizeof(uint8_t), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2628 | } else { |
| 2629 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2630 | } |
| 2631 | #endif |
| 2632 | |
| 2633 | cpi->refresh_alt_ref_frame = 0; |
| 2634 | cpi->multi_arf_last_grp_enabled = 0; |
| 2635 | |
| 2636 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 2637 | #if CONFIG_INTERNAL_STATS |
| 2638 | cpi->b_calculate_blockiness = 1; |
| 2639 | cpi->b_calculate_consistency = 1; |
| 2640 | cpi->total_inconsistency = 0; |
| 2641 | cpi->psnr.worst = 100.0; |
| 2642 | cpi->worst_ssim = 100.0; |
| 2643 | |
| 2644 | cpi->count = 0; |
| 2645 | cpi->bytes = 0; |
| 2646 | |
| 2647 | if (cpi->b_calculate_psnr) { |
| 2648 | cpi->total_sq_error = 0; |
| 2649 | cpi->total_samples = 0; |
| 2650 | cpi->tot_recode_hits = 0; |
| 2651 | cpi->summed_quality = 0; |
| 2652 | cpi->summed_weights = 0; |
| 2653 | } |
| 2654 | |
| 2655 | cpi->fastssim.worst = 100.0; |
| 2656 | cpi->psnrhvs.worst = 100.0; |
| 2657 | |
| 2658 | if (cpi->b_calculate_blockiness) { |
| 2659 | cpi->total_blockiness = 0; |
| 2660 | cpi->worst_blockiness = 0.0; |
| 2661 | } |
| 2662 | |
| 2663 | if (cpi->b_calculate_consistency) { |
| 2664 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2665 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2666 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 2667 | cpi->worst_consistency = 100.0; |
| 2668 | } |
| 2669 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2670 | #if CONFIG_ENTROPY_STATS |
| 2671 | av1_zero(aggregate_fc); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 2672 | av1_zero_array(aggregate_fc_per_type, FRAME_CONTEXTS); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2673 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2674 | |
| 2675 | cpi->first_time_stamp_ever = INT64_MAX; |
| 2676 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2677 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 2678 | cpi->td.mb.nmvcost[i][0] = &cpi->nmv_costs[i][0][MV_MAX]; |
| 2679 | cpi->td.mb.nmvcost[i][1] = &cpi->nmv_costs[i][1][MV_MAX]; |
| 2680 | cpi->td.mb.nmvcost_hp[i][0] = &cpi->nmv_costs_hp[i][0][MV_MAX]; |
| 2681 | cpi->td.mb.nmvcost_hp[i][1] = &cpi->nmv_costs_hp[i][1][MV_MAX]; |
| 2682 | } |
| 2683 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2684 | #ifdef OUTPUT_YUV_SKINMAP |
| 2685 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 2686 | #endif |
| 2687 | #ifdef OUTPUT_YUV_REC |
| 2688 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 2689 | #endif |
| 2690 | |
| 2691 | #if 0 |
| 2692 | framepsnr = fopen("framepsnr.stt", "a"); |
| 2693 | kf_list = fopen("kf_list.stt", "w"); |
| 2694 | #endif |
| 2695 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2696 | #if CONFIG_XIPHRC |
| 2697 | if (oxcf->pass == 2) { |
| 2698 | cpi->od_rc.twopass_allframes_buf = oxcf->two_pass_stats_in.buf; |
| 2699 | cpi->od_rc.twopass_allframes_buf_size = oxcf->two_pass_stats_in.sz; |
| 2700 | } |
| 2701 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2702 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2703 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2704 | } else if (oxcf->pass == 2) { |
| 2705 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 2706 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 2707 | |
| 2708 | #if CONFIG_FP_MB_STATS |
| 2709 | if (cpi->use_fp_mb_stats) { |
| 2710 | const size_t psz = cpi->common.MBs * sizeof(uint8_t); |
| 2711 | const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz); |
| 2712 | |
| 2713 | cpi->twopass.firstpass_mb_stats.mb_stats_start = |
| 2714 | oxcf->firstpass_mb_stats_in.buf; |
| 2715 | cpi->twopass.firstpass_mb_stats.mb_stats_end = |
| 2716 | cpi->twopass.firstpass_mb_stats.mb_stats_start + |
| 2717 | (ps - 1) * cpi->common.MBs * sizeof(uint8_t); |
| 2718 | } |
| 2719 | #endif |
| 2720 | |
| 2721 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 2722 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 2723 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 2724 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2725 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2726 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2727 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2728 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2729 | #if CONFIG_HIGHBITDEPTH |
| 2730 | int buf_scaler = 2; |
| 2731 | #else |
| 2732 | int buf_scaler = 1; |
| 2733 | #endif |
| 2734 | CHECK_MEM_ERROR( |
| 2735 | cm, cpi->td.mb.above_pred_buf, |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 2736 | (uint8_t *)aom_memalign(16, |
| 2737 | buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2738 | sizeof(*cpi->td.mb.above_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2739 | CHECK_MEM_ERROR( |
| 2740 | cm, cpi->td.mb.left_pred_buf, |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 2741 | (uint8_t *)aom_memalign(16, |
| 2742 | buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2743 | sizeof(*cpi->td.mb.left_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2744 | |
| 2745 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 2746 | (int32_t *)aom_memalign( |
| 2747 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 2748 | |
| 2749 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 2750 | (int32_t *)aom_memalign( |
| 2751 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 2752 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2753 | av1_set_speed_features_framesize_independent(cpi); |
| 2754 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2755 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2756 | #if CONFIG_JNT_COMP |
| 2757 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF, JSDAF, JSVAF) \ |
| 2758 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 2759 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 2760 | cpi->fn_ptr[BT].vf = VF; \ |
| 2761 | cpi->fn_ptr[BT].svf = SVF; \ |
| 2762 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 2763 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 2764 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 2765 | cpi->fn_ptr[BT].sdx4df = SDX4DF; \ |
| 2766 | cpi->fn_ptr[BT].jsdaf = JSDAF; \ |
| 2767 | cpi->fn_ptr[BT].jsvaf = JSVAF; |
| 2768 | #else // CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2769 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 2770 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 2771 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 2772 | cpi->fn_ptr[BT].vf = VF; \ |
| 2773 | cpi->fn_ptr[BT].svf = SVF; \ |
| 2774 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 2775 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 2776 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 2777 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2778 | #endif // CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2779 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2780 | #if CONFIG_JNT_COMP |
| 2781 | #if CONFIG_EXT_PARTITION_TYPES |
| 2782 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
| 2783 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2784 | aom_sad4x16x4d, aom_jnt_sad4x16_avg_c, |
| 2785 | aom_jnt_sub_pixel_avg_variance4x16_c) |
| 2786 | |
| 2787 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
| 2788 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2789 | aom_sad16x4x4d, aom_jnt_sad16x4_avg_c, |
| 2790 | aom_jnt_sub_pixel_avg_variance16x4_c) |
| 2791 | |
| 2792 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
| 2793 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2794 | aom_sad8x32x4d, aom_jnt_sad8x32_avg_c, |
| 2795 | aom_jnt_sub_pixel_avg_variance8x32_c) |
| 2796 | |
| 2797 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
| 2798 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2799 | aom_sad32x8x4d, aom_jnt_sad32x8_avg_c, |
| 2800 | aom_jnt_sub_pixel_avg_variance32x8_c) |
| 2801 | |
| 2802 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
| 2803 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2804 | aom_sad16x64x4d, aom_jnt_sad16x64_avg_c, |
| 2805 | aom_jnt_sub_pixel_avg_variance16x64_c) |
| 2806 | |
| 2807 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
| 2808 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2809 | aom_sad64x16x4d, aom_jnt_sad64x16_avg_c, |
| 2810 | aom_jnt_sub_pixel_avg_variance64x16_c) |
| 2811 | |
| 2812 | #if CONFIG_EXT_PARTITION |
| 2813 | BFP(BLOCK_32X128, aom_sad32x128, aom_sad32x128_avg, aom_variance32x128, |
| 2814 | aom_sub_pixel_variance32x128, aom_sub_pixel_avg_variance32x128, NULL, |
| 2815 | NULL, aom_sad32x128x4d, aom_jnt_sad32x128_avg_c, |
| 2816 | aom_jnt_sub_pixel_avg_variance32x128_c) |
| 2817 | |
| 2818 | BFP(BLOCK_128X32, aom_sad128x32, aom_sad128x32_avg, aom_variance128x32, |
| 2819 | aom_sub_pixel_variance128x32, aom_sub_pixel_avg_variance128x32, NULL, |
| 2820 | NULL, aom_sad128x32x4d, aom_jnt_sad128x32_avg_c, |
| 2821 | aom_jnt_sub_pixel_avg_variance128x32_c) |
| 2822 | #endif // CONFIG_EXT_PARTITION |
| 2823 | #endif // CONFIG_EXT_PARTITION_TYPES |
| 2824 | |
| 2825 | #if CONFIG_EXT_PARTITION |
| 2826 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 2827 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
| 2828 | aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d, |
| 2829 | aom_jnt_sad128x128_avg_c, aom_jnt_sub_pixel_avg_variance128x128_c) |
| 2830 | |
| 2831 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
| 2832 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL, |
| 2833 | NULL, aom_sad128x64x4d, aom_jnt_sad128x64_avg_c, |
| 2834 | aom_jnt_sub_pixel_avg_variance128x64_c) |
| 2835 | |
| 2836 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
| 2837 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL, |
| 2838 | NULL, aom_sad64x128x4d, aom_jnt_sad64x128_avg_c, |
| 2839 | aom_jnt_sub_pixel_avg_variance64x128_c) |
| 2840 | #endif // CONFIG_EXT_PARTITION |
| 2841 | |
| 2842 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
| 2843 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2844 | aom_sad32x16x4d, aom_jnt_sad32x16_avg_c, |
| 2845 | aom_jnt_sub_pixel_avg_variance32x16_c) |
| 2846 | |
| 2847 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
| 2848 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2849 | aom_sad16x32x4d, aom_jnt_sad16x32_avg_c, |
| 2850 | aom_jnt_sub_pixel_avg_variance16x32_c) |
| 2851 | |
| 2852 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
| 2853 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2854 | aom_sad64x32x4d, aom_jnt_sad64x32_avg_c, |
| 2855 | aom_jnt_sub_pixel_avg_variance64x32_c) |
| 2856 | |
| 2857 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
| 2858 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2859 | aom_sad32x64x4d, aom_jnt_sad32x64_avg_c, |
| 2860 | aom_jnt_sub_pixel_avg_variance32x64_c) |
| 2861 | |
| 2862 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 2863 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
| 2864 | aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d, aom_jnt_sad32x32_avg_c, |
| 2865 | aom_jnt_sub_pixel_avg_variance32x32_c) |
| 2866 | |
| 2867 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 2868 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
| 2869 | aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d, aom_jnt_sad64x64_avg_c, |
| 2870 | aom_jnt_sub_pixel_avg_variance64x64_c) |
| 2871 | |
| 2872 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 2873 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
| 2874 | aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d, aom_jnt_sad16x16_avg_c, |
| 2875 | aom_jnt_sub_pixel_avg_variance16x16_c) |
| 2876 | |
| 2877 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
| 2878 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3, |
| 2879 | aom_sad16x8x8, aom_sad16x8x4d, aom_jnt_sad16x8_avg_c, |
| 2880 | aom_jnt_sub_pixel_avg_variance16x8_c) |
| 2881 | |
| 2882 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
| 2883 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3, |
| 2884 | aom_sad8x16x8, aom_sad8x16x4d, aom_jnt_sad8x16_avg_c, |
| 2885 | aom_jnt_sub_pixel_avg_variance8x16_c) |
| 2886 | |
| 2887 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
| 2888 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3, |
| 2889 | aom_sad8x8x8, aom_sad8x8x4d, aom_jnt_sad8x8_avg_c, |
| 2890 | aom_jnt_sub_pixel_avg_variance8x8_c) |
| 2891 | |
| 2892 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
| 2893 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL, |
| 2894 | aom_sad8x4x8, aom_sad8x4x4d, aom_jnt_sad8x4_avg_c, |
| 2895 | aom_jnt_sub_pixel_avg_variance8x4_c) |
| 2896 | |
| 2897 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
| 2898 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL, |
| 2899 | aom_sad4x8x8, aom_sad4x8x4d, aom_jnt_sad4x8_avg_c, |
| 2900 | aom_jnt_sub_pixel_avg_variance4x8_c) |
| 2901 | |
| 2902 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
| 2903 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3, |
| 2904 | aom_sad4x4x8, aom_sad4x4x4d, aom_jnt_sad4x4_avg_c, |
| 2905 | aom_jnt_sub_pixel_avg_variance4x4_c) |
| 2906 | |
| 2907 | BFP(BLOCK_2X2, NULL, NULL, aom_variance2x2, NULL, NULL, NULL, NULL, NULL, |
| 2908 | NULL, NULL) |
| 2909 | BFP(BLOCK_2X4, NULL, NULL, aom_variance2x4, NULL, NULL, NULL, NULL, NULL, |
| 2910 | NULL, NULL) |
| 2911 | BFP(BLOCK_4X2, NULL, NULL, aom_variance4x2, NULL, NULL, NULL, NULL, NULL, |
| 2912 | NULL, NULL) |
| 2913 | #else // CONFIG_JNT_COMP |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2914 | #if CONFIG_EXT_PARTITION_TYPES |
| 2915 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
| 2916 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2917 | aom_sad4x16x4d) |
| 2918 | |
| 2919 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
| 2920 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2921 | aom_sad16x4x4d) |
| 2922 | |
| 2923 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
| 2924 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2925 | aom_sad8x32x4d) |
| 2926 | |
| 2927 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
| 2928 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2929 | aom_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2930 | |
| 2931 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
| 2932 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2933 | aom_sad16x64x4d) |
| 2934 | |
| 2935 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
| 2936 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2937 | aom_sad64x16x4d) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2938 | |
| 2939 | #if CONFIG_EXT_PARTITION |
| 2940 | BFP(BLOCK_32X128, aom_sad32x128, aom_sad32x128_avg, aom_variance32x128, |
| 2941 | aom_sub_pixel_variance32x128, aom_sub_pixel_avg_variance32x128, NULL, |
| 2942 | NULL, aom_sad32x128x4d) |
| 2943 | |
| 2944 | BFP(BLOCK_128X32, aom_sad128x32, aom_sad128x32_avg, aom_variance128x32, |
| 2945 | aom_sub_pixel_variance128x32, aom_sub_pixel_avg_variance128x32, NULL, |
| 2946 | NULL, aom_sad128x32x4d) |
| 2947 | #endif // CONFIG_EXT_PARTITION |
| 2948 | #endif // CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2949 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2950 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2951 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 2952 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
| 2953 | aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2954 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2955 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
| 2956 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL, |
| 2957 | NULL, aom_sad128x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2958 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2959 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
| 2960 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL, |
| 2961 | NULL, aom_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2962 | #endif // CONFIG_EXT_PARTITION |
| 2963 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2964 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
| 2965 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2966 | aom_sad32x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2967 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2968 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
| 2969 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2970 | aom_sad16x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2971 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2972 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
| 2973 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2974 | aom_sad64x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2975 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2976 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
| 2977 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2978 | aom_sad32x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2979 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2980 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 2981 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
| 2982 | aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2983 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2984 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 2985 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
| 2986 | aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2987 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2988 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 2989 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
| 2990 | aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2991 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2992 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
| 2993 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3, |
| 2994 | aom_sad16x8x8, aom_sad16x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2995 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2996 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
| 2997 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3, |
| 2998 | aom_sad8x16x8, aom_sad8x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2999 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3000 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
| 3001 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3, |
| 3002 | aom_sad8x8x8, aom_sad8x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3003 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3004 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
| 3005 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL, |
| 3006 | aom_sad8x4x8, aom_sad8x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3007 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3008 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
| 3009 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL, |
| 3010 | aom_sad4x8x8, aom_sad4x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3011 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3012 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
| 3013 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3, |
| 3014 | aom_sad4x4x8, aom_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3015 | |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 3016 | BFP(BLOCK_2X2, NULL, NULL, aom_variance2x2, NULL, NULL, NULL, NULL, NULL) |
Jingning Han | e2ffaf8 | 2016-12-14 15:26:30 -0800 | [diff] [blame] | 3017 | BFP(BLOCK_2X4, NULL, NULL, aom_variance2x4, NULL, NULL, NULL, NULL, NULL) |
| 3018 | BFP(BLOCK_4X2, NULL, NULL, aom_variance4x2, NULL, NULL, NULL, NULL, NULL) |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 3019 | #endif // CONFIG_JNT_COMP |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 3020 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3021 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 3022 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 3023 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 3024 | cpi->fn_ptr[BT].osvf = OSVF; |
| 3025 | |
| 3026 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3027 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 3028 | aom_obmc_sub_pixel_variance128x128) |
| 3029 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 3030 | aom_obmc_sub_pixel_variance128x64) |
| 3031 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 3032 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3033 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3034 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 3035 | aom_obmc_sub_pixel_variance64x64) |
| 3036 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 3037 | aom_obmc_sub_pixel_variance64x32) |
| 3038 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 3039 | aom_obmc_sub_pixel_variance32x64) |
| 3040 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 3041 | aom_obmc_sub_pixel_variance32x32) |
| 3042 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 3043 | aom_obmc_sub_pixel_variance32x16) |
| 3044 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 3045 | aom_obmc_sub_pixel_variance16x32) |
| 3046 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 3047 | aom_obmc_sub_pixel_variance16x16) |
| 3048 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 3049 | aom_obmc_sub_pixel_variance16x8) |
| 3050 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 3051 | aom_obmc_sub_pixel_variance8x16) |
| 3052 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 3053 | aom_obmc_sub_pixel_variance8x8) |
| 3054 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 3055 | aom_obmc_sub_pixel_variance4x8) |
| 3056 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 3057 | aom_obmc_sub_pixel_variance8x4) |
| 3058 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 3059 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3060 | |
| 3061 | #if CONFIG_EXT_PARTITION_TYPES |
| 3062 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 3063 | aom_obmc_sub_pixel_variance4x16) |
| 3064 | |
| 3065 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 3066 | aom_obmc_sub_pixel_variance16x4) |
| 3067 | |
| 3068 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 3069 | aom_obmc_sub_pixel_variance8x32) |
| 3070 | |
| 3071 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 3072 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3073 | |
| 3074 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 3075 | aom_obmc_sub_pixel_variance16x64) |
| 3076 | |
| 3077 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 3078 | aom_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 3079 | |
| 3080 | #if CONFIG_EXT_PARTITION |
| 3081 | OBFP(BLOCK_32X128, aom_obmc_sad32x128, aom_obmc_variance32x128, |
| 3082 | aom_obmc_sub_pixel_variance32x128) |
| 3083 | |
| 3084 | OBFP(BLOCK_128X32, aom_obmc_sad128x32, aom_obmc_variance128x32, |
| 3085 | aom_obmc_sub_pixel_variance128x32) |
| 3086 | #endif // CONFIG_EXT_PARTITION |
| 3087 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3088 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3089 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 3090 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 3091 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3092 | |
| 3093 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3094 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 3095 | aom_masked_sub_pixel_variance128x128) |
| 3096 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 3097 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3098 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3099 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 3100 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 3101 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 3102 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 3103 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 3104 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 3105 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 3106 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 3107 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 3108 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 3109 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 3110 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 3111 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3112 | |
| 3113 | #if CONFIG_EXT_PARTITION_TYPES |
| 3114 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 3115 | |
| 3116 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 3117 | |
| 3118 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 3119 | |
| 3120 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3121 | |
| 3122 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 3123 | |
| 3124 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 3125 | |
| 3126 | #if CONFIG_EXT_PARTITION |
| 3127 | MBFP(BLOCK_32X128, aom_masked_sad32x128, aom_masked_sub_pixel_variance32x128) |
| 3128 | |
| 3129 | MBFP(BLOCK_128X32, aom_masked_sad128x32, aom_masked_sub_pixel_variance128x32) |
| 3130 | #endif // CONFIG_EXT_PARTITION |
| 3131 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3132 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3133 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3134 | highbd_set_var_fns(cpi); |
| 3135 | #endif |
| 3136 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3137 | /* av1_init_quantizer() is first called here. Add check in |
| 3138 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3139 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3140 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3141 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3142 | av1_init_quantizer(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3143 | #if CONFIG_AOM_QM |
| 3144 | aom_qm_init(cm); |
| 3145 | #endif |
| 3146 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3147 | av1_loop_filter_init(cm); |
Fergus Simpson | dac6aff | 2017-05-18 15:11:38 -0700 | [diff] [blame] | 3148 | #if CONFIG_FRAME_SUPERRES |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3149 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 3150 | cm->superres_upscaled_width = oxcf->width; |
| 3151 | cm->superres_upscaled_height = oxcf->height; |
Fergus Simpson | dac6aff | 2017-05-18 15:11:38 -0700 | [diff] [blame] | 3152 | #endif // CONFIG_FRAME_SUPERRES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3153 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3154 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3155 | #endif // CONFIG_LOOP_RESTORATION |
| 3156 | |
| 3157 | cm->error.setjmp = 0; |
| 3158 | |
| 3159 | return cpi; |
| 3160 | } |
| 3161 | |
| 3162 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 3163 | |
| 3164 | #define SNPRINT2(H, T, V) \ |
| 3165 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
| 3166 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3167 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 3168 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3169 | unsigned int i; |
| 3170 | int t; |
| 3171 | |
| 3172 | if (!cpi) return; |
| 3173 | |
| 3174 | cm = &cpi->common; |
| 3175 | if (cm->current_video_frame > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3176 | #if CONFIG_ENTROPY_STATS |
| 3177 | if (cpi->oxcf.pass != 1) { |
| 3178 | fprintf(stderr, "Writing counts.stt\n"); |
| 3179 | FILE *f = fopen("counts.stt", "wb"); |
| 3180 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 3181 | fwrite(aggregate_fc_per_type, sizeof(aggregate_fc_per_type[0]), |
| 3182 | FRAME_CONTEXTS, f); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3183 | fclose(f); |
| 3184 | } |
| 3185 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3186 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3187 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3188 | |
| 3189 | if (cpi->oxcf.pass != 1) { |
| 3190 | char headings[512] = { 0 }; |
| 3191 | char results[512] = { 0 }; |
| 3192 | FILE *f = fopen("opsnr.stt", "a"); |
| 3193 | double time_encoded = |
| 3194 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 3195 | 10000000.000; |
| 3196 | double total_encode_time = |
| 3197 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 3198 | const double dr = |
| 3199 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 3200 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 3201 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 3202 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 3203 | |
| 3204 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3205 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3206 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 3207 | const double total_ssim = |
| 3208 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 3209 | snprintf(headings, sizeof(headings), |
| 3210 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3211 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3212 | "WstPsnr\tWstSsim\tWstFast\tWstHVS"); |
| 3213 | snprintf(results, sizeof(results), |
| 3214 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 3215 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 3216 | "%7.3f\t%7.3f\t%7.3f\t%7.3f", |
| 3217 | dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr, |
| 3218 | cpi->psnr.stat[ALL] / cpi->count, total_psnr, total_ssim, |
| 3219 | total_ssim, cpi->fastssim.stat[ALL] / cpi->count, |
| 3220 | cpi->psnrhvs.stat[ALL] / cpi->count, cpi->psnr.worst, |
| 3221 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst); |
| 3222 | |
| 3223 | if (cpi->b_calculate_blockiness) { |
| 3224 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 3225 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 3226 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 3227 | } |
| 3228 | |
| 3229 | if (cpi->b_calculate_consistency) { |
| 3230 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3231 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3232 | (double)cpi->total_inconsistency); |
| 3233 | |
| 3234 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 3235 | SNPRINT2(results, "\t%7.3f", consistency); |
| 3236 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 3237 | } |
Sarah Parker | f97b786 | 2016-08-25 17:42:57 -0700 | [diff] [blame] | 3238 | fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings); |
| 3239 | 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] | 3240 | rate_err, fabs(rate_err)); |
| 3241 | } |
| 3242 | |
| 3243 | fclose(f); |
| 3244 | } |
| 3245 | |
| 3246 | #endif |
| 3247 | |
| 3248 | #if 0 |
| 3249 | { |
| 3250 | printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); |
| 3251 | printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); |
| 3252 | printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, |
| 3253 | cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, |
| 3254 | cpi->time_compress_data / 1000, |
| 3255 | (cpi->time_receive_data + cpi->time_compress_data) / 1000); |
| 3256 | } |
| 3257 | #endif |
| 3258 | } |
| 3259 | |
| 3260 | for (t = 0; t < cpi->num_workers; ++t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3261 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3262 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 3263 | |
| 3264 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3265 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3266 | |
| 3267 | // Deallocate allocated thread data. |
| 3268 | if (t < cpi->num_workers - 1) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3269 | aom_free(thread_data->td->palette_buffer); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3270 | aom_free(thread_data->td->above_pred_buf); |
| 3271 | aom_free(thread_data->td->left_pred_buf); |
| 3272 | aom_free(thread_data->td->wsrc_buf); |
| 3273 | aom_free(thread_data->td->mask_buf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3274 | aom_free(thread_data->td->counts); |
| 3275 | av1_free_pc_tree(thread_data->td); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3276 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3277 | } |
| 3278 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3279 | aom_free(cpi->tile_thr_data); |
| 3280 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3281 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3282 | 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] | 3283 | |
| 3284 | dealloc_compressor_data(cpi); |
| 3285 | |
| 3286 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 3287 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3288 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | #if CONFIG_FP_MB_STATS |
| 3292 | if (cpi->use_fp_mb_stats) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3293 | aom_free(cpi->twopass.frame_mb_stats_buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3294 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 3295 | } |
| 3296 | #endif |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 3297 | #if CONFIG_INTERNAL_STATS |
| 3298 | aom_free(cpi->ssim_vars); |
| 3299 | cpi->ssim_vars = NULL; |
| 3300 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3301 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3302 | av1_remove_common(cm); |
| 3303 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 3304 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3305 | |
| 3306 | #ifdef OUTPUT_YUV_SKINMAP |
| 3307 | fclose(yuv_skinmap_file); |
| 3308 | #endif |
| 3309 | #ifdef OUTPUT_YUV_REC |
| 3310 | fclose(yuv_rec_file); |
| 3311 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3312 | #if 0 |
| 3313 | |
| 3314 | if (keyfile) |
| 3315 | fclose(keyfile); |
| 3316 | |
| 3317 | if (framepsnr) |
| 3318 | fclose(framepsnr); |
| 3319 | |
| 3320 | if (kf_list) |
| 3321 | fclose(kf_list); |
| 3322 | |
| 3323 | #endif |
| 3324 | } |
| 3325 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3326 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 3327 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3328 | int i; |
| 3329 | PSNR_STATS psnr; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3330 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3331 | aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3332 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
| 3333 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3334 | aom_calc_psnr(cpi->source, cpi->common.frame_to_show, &psnr); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3335 | #endif |
| 3336 | |
| 3337 | for (i = 0; i < 4; ++i) { |
| 3338 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 3339 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 3340 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 3341 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3342 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 3343 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3344 | } |
| 3345 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3346 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3347 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 3348 | |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 3349 | cpi->ext_ref_frame_flags = ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3350 | return 0; |
| 3351 | } |
| 3352 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 3353 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_upd_flags) { |
| 3354 | cpi->ext_refresh_last_frame = (ref_frame_upd_flags & AOM_LAST_FLAG) != 0; |
| 3355 | cpi->ext_refresh_golden_frame = (ref_frame_upd_flags & AOM_GOLD_FLAG) != 0; |
| 3356 | cpi->ext_refresh_alt_ref_frame = (ref_frame_upd_flags & AOM_ALT_FLAG) != 0; |
| 3357 | cpi->ext_refresh_bwd_ref_frame = (ref_frame_upd_flags & AOM_BWD_FLAG) != 0; |
| 3358 | 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] | 3359 | cpi->ext_refresh_frame_flags_pending = 1; |
| 3360 | } |
| 3361 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3362 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3363 | AV1_COMMON *const cm = &cpi->common; |
| 3364 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3365 | if (cfg) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3366 | aom_yv12_copy_frame(cfg, sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3367 | return 0; |
| 3368 | } else { |
| 3369 | return -1; |
| 3370 | } |
| 3371 | } |
| 3372 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3373 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3374 | AV1_COMMON *const cm = &cpi->common; |
| 3375 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3376 | if (cfg) { |
| 3377 | aom_yv12_copy_frame(sd, cfg); |
| 3378 | return 0; |
| 3379 | } else { |
| 3380 | return -1; |
| 3381 | } |
| 3382 | } |
| 3383 | |
| 3384 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3385 | cpi->ext_refresh_frame_context = update; |
| 3386 | cpi->ext_refresh_frame_context_pending = 1; |
| 3387 | return 0; |
| 3388 | } |
| 3389 | |
| 3390 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 3391 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 3392 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 3393 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 3394 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3395 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3396 | uint8_t *src = s->y_buffer; |
| 3397 | int h = s->y_height; |
| 3398 | |
| 3399 | do { |
| 3400 | fwrite(src, s->y_width, 1, f); |
| 3401 | src += s->y_stride; |
| 3402 | } while (--h); |
| 3403 | |
| 3404 | src = s->u_buffer; |
| 3405 | h = s->uv_height; |
| 3406 | |
| 3407 | do { |
| 3408 | fwrite(src, s->uv_width, 1, f); |
| 3409 | src += s->uv_stride; |
| 3410 | } while (--h); |
| 3411 | |
| 3412 | src = s->v_buffer; |
| 3413 | h = s->uv_height; |
| 3414 | |
| 3415 | do { |
| 3416 | fwrite(src, s->uv_width, 1, f); |
| 3417 | src += s->uv_stride; |
| 3418 | } while (--h); |
| 3419 | } |
| 3420 | #endif |
| 3421 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3422 | #if !CONFIG_XIPHRC |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3423 | #if USE_GF16_MULTI_LAYER |
| 3424 | static void check_show_existing_frame_gf16(AV1_COMP *cpi) { |
| 3425 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3426 | AV1_COMMON *const cm = &cpi->common; |
| 3427 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 3428 | gf_group->update_type[gf_group->index]; |
| 3429 | |
| 3430 | if (cm->show_existing_frame == 1) { |
| 3431 | cm->show_existing_frame = 0; |
| 3432 | } else if (cpi->rc.is_last_bipred_frame) { |
| 3433 | cpi->rc.is_last_bipred_frame = 0; |
| 3434 | cm->show_existing_frame = 1; |
| 3435 | cpi->existing_fb_idx_to_show = cpi->bwd_fb_idx; |
| 3436 | } else if (next_frame_update_type == OVERLAY_UPDATE || |
| 3437 | next_frame_update_type == INTNL_OVERLAY_UPDATE) { |
| 3438 | // Check the temporal filtering status for the next OVERLAY frame |
| 3439 | const int num_arfs_in_gf = cpi->num_extra_arfs + 1; |
| 3440 | int which_arf = 0, arf_idx; |
| 3441 | // Identify the index to the next overlay frame. |
| 3442 | for (arf_idx = 0; arf_idx < num_arfs_in_gf; arf_idx++) { |
| 3443 | if (gf_group->index == cpi->arf_pos_for_ovrly[arf_idx]) { |
| 3444 | which_arf = arf_idx; |
| 3445 | break; |
| 3446 | } |
| 3447 | } |
| 3448 | assert(arf_idx < num_arfs_in_gf); |
| 3449 | if (cpi->is_arf_filter_off[which_arf]) { |
| 3450 | cm->show_existing_frame = 1; |
| 3451 | cpi->rc.is_src_frame_alt_ref = 1; |
| 3452 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
| 3453 | ? cpi->alt_fb_idx |
| 3454 | : cpi->bwd_fb_idx; |
| 3455 | cpi->is_arf_filter_off[which_arf] = 0; |
| 3456 | } |
| 3457 | } |
| 3458 | cpi->rc.is_src_frame_ext_arf = 0; |
| 3459 | } |
| 3460 | #endif // USE_GF16_MULTI_LAYER |
| 3461 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3462 | static void check_show_existing_frame(AV1_COMP *cpi) { |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3463 | #if USE_GF16_MULTI_LAYER |
| 3464 | if (cpi->rc.baseline_gf_interval == 16) { |
| 3465 | check_show_existing_frame_gf16(cpi); |
| 3466 | return; |
| 3467 | } |
| 3468 | #endif // USE_GF16_MULTI_LAYER |
| 3469 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3470 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3471 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3472 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 3473 | gf_group->update_type[gf_group->index]; |
| 3474 | const int which_arf = gf_group->arf_update_idx[gf_group->index]; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3475 | |
| 3476 | if (cm->show_existing_frame == 1) { |
| 3477 | cm->show_existing_frame = 0; |
| 3478 | } else if (cpi->rc.is_last_bipred_frame) { |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3479 | // NOTE: If the current frame is a last bi-predictive frame, it is |
| 3480 | // needed next to show the BWDREF_FRAME, which is pointed by |
| 3481 | // the last_fb_idxes[0] after reference frame buffer update |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3482 | cpi->rc.is_last_bipred_frame = 0; |
| 3483 | cm->show_existing_frame = 1; |
| 3484 | cpi->existing_fb_idx_to_show = cpi->lst_fb_idxes[0]; |
| 3485 | } else if (cpi->is_arf_filter_off[which_arf] && |
| 3486 | (next_frame_update_type == OVERLAY_UPDATE || |
| 3487 | next_frame_update_type == INTNL_OVERLAY_UPDATE)) { |
| 3488 | // Other parameters related to OVERLAY_UPDATE will be taken care of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3489 | // in av1_rc_get_second_pass_params(cpi) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3490 | cm->show_existing_frame = 1; |
| 3491 | cpi->rc.is_src_frame_alt_ref = 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3492 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
| 3493 | ? cpi->alt_fb_idx |
| 3494 | : cpi->alt2_fb_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3495 | cpi->is_arf_filter_off[which_arf] = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3496 | } |
| 3497 | cpi->rc.is_src_frame_ext_arf = 0; |
| 3498 | } |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3499 | #endif // !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3500 | |
| 3501 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3502 | 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] | 3503 | uint8_t *src = s->y_buffer; |
| 3504 | int h = cm->height; |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3505 | if (yuv_rec_file == NULL) return; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3506 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3507 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 3508 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 3509 | |
| 3510 | do { |
| 3511 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 3512 | src16 += s->y_stride; |
| 3513 | } while (--h); |
| 3514 | |
| 3515 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 3516 | h = s->uv_height; |
| 3517 | |
| 3518 | do { |
| 3519 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3520 | src16 += s->uv_stride; |
| 3521 | } while (--h); |
| 3522 | |
| 3523 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 3524 | h = s->uv_height; |
| 3525 | |
| 3526 | do { |
| 3527 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3528 | src16 += s->uv_stride; |
| 3529 | } while (--h); |
| 3530 | |
| 3531 | fflush(yuv_rec_file); |
| 3532 | return; |
| 3533 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3534 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3535 | |
| 3536 | do { |
| 3537 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 3538 | src += s->y_stride; |
| 3539 | } while (--h); |
| 3540 | |
| 3541 | src = s->u_buffer; |
| 3542 | h = s->uv_height; |
| 3543 | |
| 3544 | do { |
| 3545 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3546 | src += s->uv_stride; |
| 3547 | } while (--h); |
| 3548 | |
| 3549 | src = s->v_buffer; |
| 3550 | h = s->uv_height; |
| 3551 | |
| 3552 | do { |
| 3553 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3554 | src += s->uv_stride; |
| 3555 | } while (--h); |
| 3556 | |
| 3557 | fflush(yuv_rec_file); |
| 3558 | } |
| 3559 | #endif // OUTPUT_YUV_REC |
| 3560 | |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 3561 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3562 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 3563 | int i; |
| 3564 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3565 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3566 | AV1_COMMON *const cm = &cpi->common; |
| 3567 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3568 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3569 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3570 | cpi->gmparams_cost[i]) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3571 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3572 | assert(cm->global_motion[i].wmtype == IDENTITY); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3573 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 3574 | recode = 1; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3575 | recode |= (rdc->global_motion_used[i] > 0); |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3576 | } |
| 3577 | } |
| 3578 | return recode; |
| 3579 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3580 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3581 | // Function to test for conditions that indicate we should loop |
| 3582 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3583 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 3584 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3585 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3586 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3587 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 3588 | int force_recode = 0; |
| 3589 | |
| 3590 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 3591 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 3592 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3593 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 3594 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 3595 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 3596 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3597 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3598 | // Deal with frame undershoot and whether or not we are |
| 3599 | // below the automatically set cq level. |
| 3600 | if (q > oxcf->cq_level && |
| 3601 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 3602 | force_recode = 1; |
| 3603 | } |
| 3604 | } |
| 3605 | } |
| 3606 | return force_recode; |
| 3607 | } |
| 3608 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3609 | #define DUMP_REF_FRAME_IMAGES 0 |
| 3610 | |
| 3611 | #if DUMP_REF_FRAME_IMAGES == 1 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3612 | static int dump_one_image(AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3613 | const YV12_BUFFER_CONFIG *const ref_buf, |
| 3614 | char *file_name) { |
| 3615 | int h; |
| 3616 | FILE *f_ref = NULL; |
| 3617 | |
| 3618 | if (ref_buf == NULL) { |
| 3619 | printf("Frame data buffer is NULL.\n"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3620 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | if ((f_ref = fopen(file_name, "wb")) == NULL) { |
| 3624 | printf("Unable to open file %s to write.\n", file_name); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3625 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3626 | } |
| 3627 | |
| 3628 | // --- Y --- |
| 3629 | for (h = 0; h < cm->height; ++h) { |
| 3630 | fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref); |
| 3631 | } |
| 3632 | // --- U --- |
| 3633 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3634 | fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3635 | f_ref); |
| 3636 | } |
| 3637 | // --- V --- |
| 3638 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3639 | fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3640 | f_ref); |
| 3641 | } |
| 3642 | |
| 3643 | fclose(f_ref); |
| 3644 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3645 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3646 | } |
| 3647 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3648 | static void dump_ref_frame_images(AV1_COMP *cpi) { |
| 3649 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3650 | MV_REFERENCE_FRAME ref_frame; |
| 3651 | |
| 3652 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3653 | char file_name[256] = ""; |
| 3654 | snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv", |
| 3655 | cm->current_video_frame, ref_frame); |
| 3656 | dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name); |
| 3657 | } |
| 3658 | } |
| 3659 | #endif // DUMP_REF_FRAME_IMAGES == 1 |
| 3660 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3661 | // This function is used to shift the virtual indices of last reference frames |
| 3662 | // as follows: |
| 3663 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3664 | // when the LAST_FRAME is updated. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3665 | static INLINE void shift_last_ref_frames(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3666 | int ref_frame; |
| 3667 | for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) { |
| 3668 | cpi->lst_fb_idxes[ref_frame] = cpi->lst_fb_idxes[ref_frame - 1]; |
| 3669 | |
| 3670 | // [0] is allocated to the current coded frame. The statistics for the |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3671 | // reference frames start at [LAST_FRAME], i.e. [1]. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3672 | if (!cpi->rc.is_src_frame_alt_ref) { |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3673 | memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME], |
| 3674 | cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME], |
| 3675 | sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3676 | } |
| 3677 | } |
| 3678 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3679 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3680 | #if USE_GF16_MULTI_LAYER |
| 3681 | static void update_reference_frames_gf16(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3682 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3683 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3684 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3685 | if (cm->frame_type == KEY_FRAME) { |
| 3686 | for (int ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) { |
| 3687 | ref_cnt_fb(pool->frame_bufs, |
| 3688 | &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]], |
| 3689 | cm->new_fb_idx); |
| 3690 | } |
| 3691 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3692 | cm->new_fb_idx); |
| 3693 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3694 | cm->new_fb_idx); |
| 3695 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3696 | cm->new_fb_idx); |
| 3697 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3698 | cm->new_fb_idx); |
| 3699 | } else { |
| 3700 | if (cpi->refresh_last_frame || cpi->refresh_golden_frame || |
| 3701 | cpi->refresh_bwd_ref_frame || cpi->refresh_alt2_ref_frame || |
| 3702 | cpi->refresh_alt_ref_frame) { |
| 3703 | assert(cpi->refresh_fb_idx >= 0 && cpi->refresh_fb_idx < REF_FRAMES); |
| 3704 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->refresh_fb_idx], |
| 3705 | cm->new_fb_idx); |
| 3706 | } |
| 3707 | |
| 3708 | // TODO(zoeliu): To handle cpi->interp_filter_selected[]. |
| 3709 | |
| 3710 | // For GF of 16, an additional ref frame index mapping needs to be handled |
| 3711 | // if this is the last frame to encode in the current GF group. |
| 3712 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3713 | if (gf_group->update_type[gf_group->index + 1] == OVERLAY_UPDATE) |
| 3714 | av1_ref_frame_map_idx_updates(cpi, gf_group->index + 1); |
| 3715 | } |
| 3716 | |
| 3717 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3718 | // Dump out all reference frame images. |
| 3719 | dump_ref_frame_images(cpi); |
| 3720 | #endif // DUMP_REF_FRAME_IMAGES |
| 3721 | } |
| 3722 | #endif // USE_GF16_MULTI_LAYER |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3723 | |
| 3724 | static void update_reference_frames(AV1_COMP *cpi) { |
| 3725 | AV1_COMMON *const cm = &cpi->common; |
| 3726 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3727 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 3728 | // for the purpose to verify no mismatch between encoder and decoder. |
| 3729 | if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx; |
| 3730 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3731 | #if USE_GF16_MULTI_LAYER |
| 3732 | if (cpi->rc.baseline_gf_interval == 16) { |
| 3733 | update_reference_frames_gf16(cpi); |
| 3734 | return; |
| 3735 | } |
| 3736 | #endif // USE_GF16_MULTI_LAYER |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3737 | |
| 3738 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3739 | // At this point the new frame has been encoded. |
| 3740 | // If any buffer copy / swapping is signaled it should be done here. |
| 3741 | if (cm->frame_type == KEY_FRAME) { |
| 3742 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3743 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3744 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3745 | cm->new_fb_idx); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3746 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3747 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3748 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3749 | cm->new_fb_idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3750 | } else if (av1_preserve_existing_gf(cpi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3751 | // We have decided to preserve the previously existing golden frame as our |
| 3752 | // new ARF frame. However, in the short term in function |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3753 | // 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] | 3754 | // we're updating the GF with the current decoded frame, we save it to the |
| 3755 | // ARF slot instead. |
| 3756 | // We now have to update the ARF with the current frame and swap gld_fb_idx |
| 3757 | // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF |
| 3758 | // slot and, if we're updating the GF, the current frame becomes the new GF. |
| 3759 | int tmp; |
| 3760 | |
| 3761 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3762 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3763 | tmp = cpi->alt_fb_idx; |
| 3764 | cpi->alt_fb_idx = cpi->gld_fb_idx; |
| 3765 | cpi->gld_fb_idx = tmp; |
| 3766 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3767 | // We need to modify the mapping accordingly |
| 3768 | cpi->arf_map[0] = cpi->alt_fb_idx; |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3769 | // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to |
| 3770 | // cpi->interp_filter_selected[GOLDEN_FRAME]? |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3771 | } else if (cpi->rc.is_src_frame_ext_arf && cm->show_existing_frame) { |
| 3772 | // Deal with the special case for showing existing internal ALTREF_FRAME |
| 3773 | // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME |
| 3774 | // by updating the virtual indices. |
| 3775 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3776 | const int which_arf = gf_group->arf_ref_idx[gf_group->index]; |
| 3777 | assert(gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3778 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3779 | const int tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3780 | shift_last_ref_frames(cpi); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3781 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3782 | cpi->lst_fb_idxes[0] = cpi->alt2_fb_idx; |
| 3783 | cpi->alt2_fb_idx = tmp; |
| 3784 | // We need to modify the mapping accordingly |
| 3785 | cpi->arf_map[which_arf] = cpi->alt2_fb_idx; |
| 3786 | |
| 3787 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3788 | cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3789 | sizeof(cpi->interp_filter_selected[ALTREF2_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3790 | } else { /* For non key/golden frames */ |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3791 | // === ALTREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3792 | if (cpi->refresh_alt_ref_frame) { |
| 3793 | int arf_idx = cpi->alt_fb_idx; |
| 3794 | int which_arf = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3795 | 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] | 3796 | |
| 3797 | memcpy(cpi->interp_filter_selected[ALTREF_FRAME + which_arf], |
| 3798 | cpi->interp_filter_selected[0], |
| 3799 | sizeof(cpi->interp_filter_selected[0])); |
| 3800 | } |
| 3801 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3802 | // === GOLDEN_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3803 | if (cpi->refresh_golden_frame) { |
| 3804 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3805 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3806 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3807 | memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], |
| 3808 | cpi->interp_filter_selected[0], |
| 3809 | sizeof(cpi->interp_filter_selected[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3810 | } |
| 3811 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3812 | // === BWDREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3813 | if (cpi->refresh_bwd_ref_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3814 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3815 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3816 | |
| 3817 | memcpy(cpi->interp_filter_selected[BWDREF_FRAME], |
| 3818 | cpi->interp_filter_selected[0], |
| 3819 | sizeof(cpi->interp_filter_selected[0])); |
| 3820 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3821 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3822 | // === ALTREF2_FRAME === |
| 3823 | if (cpi->refresh_alt2_ref_frame) { |
| 3824 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3825 | cm->new_fb_idx); |
| 3826 | |
| 3827 | memcpy(cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3828 | cpi->interp_filter_selected[0], |
| 3829 | sizeof(cpi->interp_filter_selected[0])); |
| 3830 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | if (cpi->refresh_last_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3834 | // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame |
| 3835 | // reference to the reference frame buffer virtual index; and then (2) from |
| 3836 | // the virtual index to the reference frame buffer physical index: |
| 3837 | // |
| 3838 | // LAST_FRAME, ..., LAST3_FRAME, ..., ALTREF_FRAME |
| 3839 | // | | | |
| 3840 | // v v v |
| 3841 | // lst_fb_idxes[0], ..., lst_fb_idxes[2], ..., alt_fb_idx |
| 3842 | // | | | |
| 3843 | // v v v |
| 3844 | // ref_frame_map[], ..., ref_frame_map[], ..., ref_frame_map[] |
| 3845 | // |
| 3846 | // When refresh_last_frame is set, it is intended to retire LAST3_FRAME, |
| 3847 | // have the other 2 LAST reference frames shifted as follows: |
| 3848 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3849 | // , and then have LAST_FRAME refreshed by the newly coded frame. |
| 3850 | // |
| 3851 | // To fulfill it, the decoder will be notified to execute following 2 steps: |
| 3852 | // |
| 3853 | // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME |
| 3854 | // to point to the newly coded frame, i.e. |
| 3855 | // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx; |
| 3856 | // |
| 3857 | // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the |
| 3858 | // original virtual index of LAST3_FRAME and have the other mappings |
| 3859 | // shifted as follows: |
| 3860 | // LAST_FRAME, LAST2_FRAME, LAST3_FRAME |
| 3861 | // | | | |
| 3862 | // v v v |
| 3863 | // lst_fb_idxes[2], lst_fb_idxes[0], lst_fb_idxes[1] |
| 3864 | int ref_frame; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3865 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3866 | if (cm->frame_type == KEY_FRAME) { |
| 3867 | for (ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) { |
| 3868 | ref_cnt_fb(pool->frame_bufs, |
| 3869 | &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]], |
| 3870 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3871 | } |
| 3872 | } else { |
| 3873 | int tmp; |
| 3874 | |
| 3875 | ref_cnt_fb(pool->frame_bufs, |
| 3876 | &cm->ref_frame_map[cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]], |
| 3877 | cm->new_fb_idx); |
| 3878 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3879 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3880 | |
| 3881 | shift_last_ref_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3882 | cpi->lst_fb_idxes[0] = tmp; |
| 3883 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3884 | assert(cm->show_existing_frame == 0); |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3885 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3886 | cpi->interp_filter_selected[0], |
| 3887 | sizeof(cpi->interp_filter_selected[0])); |
Zoe Liu | aff92d5 | 2017-07-11 21:35:08 -0700 | [diff] [blame] | 3888 | |
| 3889 | if (cpi->rc.is_last_bipred_frame) { |
| 3890 | // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the |
| 3891 | // LAST3_FRAME by updating the virtual indices. |
| 3892 | // |
| 3893 | // NOTE: The source frame for BWDREF does not have a holding position as |
| 3894 | // the OVERLAY frame for ALTREF's. Hence, to resolve the reference |
| 3895 | // virtual index reshuffling for BWDREF, the encoder always |
| 3896 | // specifies a LAST_BIPRED right before BWDREF and completes the |
| 3897 | // reshuffling job accordingly. |
| 3898 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3899 | |
| 3900 | shift_last_ref_frames(cpi); |
| 3901 | cpi->lst_fb_idxes[0] = cpi->bwd_fb_idx; |
| 3902 | cpi->bwd_fb_idx = tmp; |
| 3903 | |
| 3904 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3905 | cpi->interp_filter_selected[BWDREF_FRAME], |
| 3906 | sizeof(cpi->interp_filter_selected[BWDREF_FRAME])); |
| 3907 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3908 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3912 | // Dump out all reference frame images. |
| 3913 | dump_ref_frame_images(cpi); |
| 3914 | #endif // DUMP_REF_FRAME_IMAGES |
| 3915 | } |
| 3916 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3917 | 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] | 3918 | assert(buffer_idx != INVALID_IDX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3919 | RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 3920 | ensure_mv_buffer(new_fb_ptr, cm); |
| 3921 | new_fb_ptr->width = cm->width; |
| 3922 | new_fb_ptr->height = cm->height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3925 | static void scale_references(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3926 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3927 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3928 | const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = { |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3929 | AOM_LAST_FLAG, AOM_LAST2_FLAG, AOM_LAST3_FLAG, AOM_GOLD_FLAG, |
| 3930 | AOM_BWD_FLAG, AOM_ALT2_FLAG, AOM_ALT_FLAG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3931 | }; |
| 3932 | |
| 3933 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3934 | // 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] | 3935 | if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 3936 | BufferPool *const pool = cm->buffer_pool; |
| 3937 | const YV12_BUFFER_CONFIG *const ref = |
| 3938 | get_ref_frame_buffer(cpi, ref_frame); |
| 3939 | |
| 3940 | if (ref == NULL) { |
| 3941 | cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3942 | continue; |
| 3943 | } |
| 3944 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3945 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3946 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3947 | RefCntBuffer *new_fb_ptr = NULL; |
| 3948 | int force_scaling = 0; |
| 3949 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3950 | if (new_fb == INVALID_IDX) { |
| 3951 | new_fb = get_free_fb(cm); |
| 3952 | force_scaling = 1; |
| 3953 | } |
| 3954 | if (new_fb == INVALID_IDX) return; |
| 3955 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3956 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3957 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3958 | if (aom_realloc_frame_buffer( |
| 3959 | &new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x, |
| 3960 | cm->subsampling_y, cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 3961 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3962 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3963 | "Failed to allocate frame buffer"); |
Debargha Mukherjee | 405c857 | 2017-07-10 09:29:17 -0700 | [diff] [blame] | 3964 | av1_resize_and_extend_frame(ref, &new_fb_ptr->buf, |
| 3965 | (int)cm->bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3966 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3967 | alloc_frame_mvs(cm, new_fb); |
| 3968 | } |
| 3969 | #else |
| 3970 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3971 | RefCntBuffer *new_fb_ptr = NULL; |
| 3972 | int force_scaling = 0; |
| 3973 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3974 | if (new_fb == INVALID_IDX) { |
| 3975 | new_fb = get_free_fb(cm); |
| 3976 | force_scaling = 1; |
| 3977 | } |
| 3978 | if (new_fb == INVALID_IDX) return; |
| 3979 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3980 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3981 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3982 | if (aom_realloc_frame_buffer(&new_fb_ptr->buf, cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3983 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3984 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
| 3985 | NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3986 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3987 | "Failed to allocate frame buffer"); |
Debargha Mukherjee | 405c857 | 2017-07-10 09:29:17 -0700 | [diff] [blame] | 3988 | av1_resize_and_extend_frame(ref, &new_fb_ptr->buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3989 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3990 | alloc_frame_mvs(cm, new_fb); |
| 3991 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3992 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3993 | } else { |
| 3994 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3995 | RefCntBuffer *const buf = &pool->frame_bufs[buf_idx]; |
| 3996 | buf->buf.y_crop_width = ref->y_crop_width; |
| 3997 | buf->buf.y_crop_height = ref->y_crop_height; |
| 3998 | cpi->scaled_ref_idx[ref_frame - 1] = buf_idx; |
| 3999 | ++buf->ref_count; |
| 4000 | } |
| 4001 | } else { |
| 4002 | if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 4003 | } |
| 4004 | } |
| 4005 | } |
| 4006 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4007 | static void release_scaled_references(AV1_COMP *cpi) { |
| 4008 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4009 | int i; |
| 4010 | if (cpi->oxcf.pass == 0) { |
| 4011 | // Only release scaled references under certain conditions: |
| 4012 | // if reference will be updated, or if scaled reference has same resolution. |
| 4013 | int refresh[INTER_REFS_PER_FRAME]; |
| 4014 | refresh[0] = (cpi->refresh_last_frame) ? 1 : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4015 | refresh[1] = refresh[2] = 0; |
| 4016 | refresh[3] = (cpi->refresh_golden_frame) ? 1 : 0; |
| 4017 | refresh[4] = (cpi->refresh_bwd_ref_frame) ? 1 : 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4018 | refresh[5] = (cpi->refresh_alt2_ref_frame) ? 1 : 0; |
| 4019 | refresh[6] = (cpi->refresh_alt_ref_frame) ? 1 : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4020 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 4021 | const int idx = cpi->scaled_ref_idx[i - 1]; |
| 4022 | RefCntBuffer *const buf = |
| 4023 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 4024 | const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, i); |
| 4025 | if (buf != NULL && |
| 4026 | (refresh[i - 1] || (buf->buf.y_crop_width == ref->y_crop_width && |
| 4027 | buf->buf.y_crop_height == ref->y_crop_height))) { |
| 4028 | --buf->ref_count; |
| 4029 | cpi->scaled_ref_idx[i - 1] = INVALID_IDX; |
| 4030 | } |
| 4031 | } |
| 4032 | } else { |
| 4033 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) { |
| 4034 | const int idx = cpi->scaled_ref_idx[i]; |
| 4035 | RefCntBuffer *const buf = |
| 4036 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 4037 | if (buf != NULL) { |
| 4038 | --buf->ref_count; |
| 4039 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 4040 | } |
| 4041 | } |
| 4042 | } |
| 4043 | } |
| 4044 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4045 | #if 0 && CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4046 | static void output_frame_level_debug_stats(AV1_COMP *cpi) { |
| 4047 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4048 | FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); |
| 4049 | int64_t recon_err; |
| 4050 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4051 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4052 | |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4053 | recon_err = aom_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4054 | |
| 4055 | if (cpi->twopass.total_left_stats.coded_error != 0.0) |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 4056 | fprintf(f, "%10u %dx%d %d %d %10d %10d %10d %10d" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4057 | "%10"PRId64" %10"PRId64" %5d %5d %10"PRId64" " |
| 4058 | "%10"PRId64" %10"PRId64" %10d " |
| 4059 | "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" |
| 4060 | "%6d %6d %5d %5d %5d " |
| 4061 | "%10"PRId64" %10.3lf" |
| 4062 | "%10lf %8u %10"PRId64" %10d %10d %10d\n", |
| 4063 | cpi->common.current_video_frame, |
| 4064 | cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4065 | cpi->rc.source_alt_ref_pending, |
| 4066 | cpi->rc.source_alt_ref_active, |
| 4067 | cpi->rc.this_frame_target, |
| 4068 | cpi->rc.projected_frame_size, |
| 4069 | cpi->rc.projected_frame_size / cpi->common.MBs, |
| 4070 | (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), |
| 4071 | cpi->rc.vbr_bits_off_target, |
| 4072 | cpi->rc.vbr_bits_off_target_fast, |
| 4073 | cpi->twopass.extend_minq, |
| 4074 | cpi->twopass.extend_minq_fast, |
| 4075 | cpi->rc.total_target_vs_actual, |
| 4076 | (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), |
| 4077 | cpi->rc.total_actual_bits, cm->base_qindex, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4078 | av1_convert_qindex_to_q(cm->base_qindex, cm->bit_depth), |
| 4079 | (double)av1_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0, |
| 4080 | av1_convert_qindex_to_q(cpi->twopass.active_worst_quality, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4081 | cm->bit_depth), |
| 4082 | cpi->rc.avg_q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4083 | av1_convert_qindex_to_q(cpi->oxcf.cq_level, cm->bit_depth), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4084 | cpi->refresh_last_frame, cpi->refresh_golden_frame, |
| 4085 | cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, |
| 4086 | cpi->twopass.bits_left, |
| 4087 | cpi->twopass.total_left_stats.coded_error, |
| 4088 | cpi->twopass.bits_left / |
| 4089 | (1 + cpi->twopass.total_left_stats.coded_error), |
| 4090 | cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost, |
| 4091 | cpi->twopass.kf_zeromotion_pct, |
| 4092 | cpi->twopass.fr_content_type); |
| 4093 | |
| 4094 | fclose(f); |
| 4095 | |
| 4096 | if (0) { |
| 4097 | FILE *const fmodes = fopen("Modes.stt", "a"); |
| 4098 | int i; |
| 4099 | |
| 4100 | fprintf(fmodes, "%6d:%1d:%1d:%1d ", cpi->common.current_video_frame, |
| 4101 | cm->frame_type, cpi->refresh_golden_frame, |
| 4102 | cpi->refresh_alt_ref_frame); |
| 4103 | |
| 4104 | for (i = 0; i < MAX_MODES; ++i) |
| 4105 | fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]); |
| 4106 | |
| 4107 | fprintf(fmodes, "\n"); |
| 4108 | |
| 4109 | fclose(fmodes); |
| 4110 | } |
| 4111 | } |
| 4112 | #endif |
| 4113 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4114 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 4115 | const AV1_COMMON *const cm = &cpi->common; |
| 4116 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4117 | |
| 4118 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4119 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4120 | |
| 4121 | if (cpi->sf.mv.auto_mv_step_size) { |
| 4122 | if (frame_is_intra_only(cm)) { |
| 4123 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 4124 | // after a key/intra-only frame. |
| 4125 | cpi->max_mv_magnitude = max_mv_def; |
| 4126 | } else { |
| 4127 | if (cm->show_frame) { |
| 4128 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 4129 | // in the previous frame, capped by the default max_mv_magnitude based |
| 4130 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4131 | cpi->mv_step_param = av1_init_search_range( |
| 4132 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4133 | } |
| 4134 | cpi->max_mv_magnitude = 0; |
| 4135 | } |
| 4136 | } |
| 4137 | } |
| 4138 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4139 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4140 | int i; |
| 4141 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 4142 | cpi->common.global_motion[i] = default_warp_params; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4143 | } |
| 4144 | cpi->global_motion_search_done = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4145 | av1_set_speed_features_framesize_independent(cpi); |
| 4146 | av1_set_rd_speed_thresholds(cpi); |
| 4147 | av1_set_rd_speed_thresholds_sub8x8(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4148 | cpi->common.interp_filter = cpi->sf.default_interp_filter; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 4149 | if (!frame_is_intra_only(&cpi->common)) set_compound_tools(&cpi->common); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4150 | } |
| 4151 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4152 | 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] | 4153 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4154 | AV1_COMMON *const cm = &cpi->common; |
| 4155 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4156 | |
| 4157 | // Setup variables that depend on the dimensions of the frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4158 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4159 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4160 | // Decide q and q bounds. |
| 4161 | #if CONFIG_XIPHRC |
| 4162 | int frame_type = cm->frame_type == KEY_FRAME ? OD_I_FRAME : OD_P_FRAME; |
| 4163 | *q = od_enc_rc_select_quantizers_and_lambdas( |
| 4164 | &cpi->od_rc, cpi->refresh_golden_frame, cpi->refresh_alt_ref_frame, |
| 4165 | frame_type, bottom_index, top_index); |
| 4166 | #else |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4167 | *q = av1_rc_pick_q_and_bounds(cpi, cm->width, cm->height, bottom_index, |
| 4168 | top_index); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4169 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4170 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 4171 | if (!frame_is_intra_only(cm)) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4172 | #if CONFIG_AMVR |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 4173 | #if CONFIG_EIGHTH_PEL_MV_ONLY |
| 4174 | set_high_precision_mv(cpi, 1, cpi->common.cur_frame_force_integer_mv); |
| 4175 | #else |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4176 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH, |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 4177 | cpi->common.cur_frame_force_integer_mv); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 4178 | #endif // CONFIG_EIGHTH_PEL_MV_ONLY |
| 4179 | #else |
| 4180 | #if CONFIG_EIGHTH_PEL_MV_ONLY |
| 4181 | set_high_precision_mv(cpi, 1); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4182 | #else |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4183 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 4184 | #endif // CONFIG_EIGHTH_PEL_MV_ONLY |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4185 | #endif |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 4186 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4187 | |
| 4188 | // Configure experimental use of segmentation for enhanced coding of |
| 4189 | // static regions if indicated. |
| 4190 | // Only allowed in the second pass of a two pass encode, as it requires |
| 4191 | // lagged coding, and if the relevant speed feature flag is set. |
| 4192 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 4193 | configure_static_seg_features(cpi); |
| 4194 | } |
| 4195 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4196 | static void init_motion_estimation(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4197 | int y_stride = cpi->scaled_source.y_stride; |
| 4198 | |
| 4199 | if (cpi->sf.mv.search_method == NSTEP) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4200 | av1_init3smotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4201 | } else if (cpi->sf.mv.search_method == DIAMOND) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4202 | av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4203 | } |
| 4204 | } |
| 4205 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4206 | #if CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4207 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4208 | static void set_restoration_unit_size(int width, int height, int sx, int sy, |
| 4209 | RestorationInfo *rst) { |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4210 | (void)width; |
| 4211 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4212 | (void)sx; |
| 4213 | (void)sy; |
| 4214 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 4215 | int s = AOMMIN(sx, sy); |
| 4216 | #else |
| 4217 | int s = 0; |
| 4218 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 4219 | |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4220 | rst[0].restoration_unit_size = (RESTORATION_TILESIZE_MAX >> 1); |
| 4221 | rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s; |
| 4222 | rst[2].restoration_unit_size = rst[1].restoration_unit_size; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4223 | } |
| 4224 | #endif // CONFIG_LOOP_RESTORATION |
| 4225 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4226 | static void init_ref_frame_bufs(AV1_COMMON *cm) { |
| 4227 | int i; |
| 4228 | BufferPool *const pool = cm->buffer_pool; |
| 4229 | cm->new_fb_idx = INVALID_IDX; |
| 4230 | for (i = 0; i < REF_FRAMES; ++i) { |
| 4231 | cm->ref_frame_map[i] = INVALID_IDX; |
| 4232 | pool->frame_bufs[i].ref_count = 0; |
| 4233 | } |
| 4234 | #if CONFIG_HASH_ME |
| 4235 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 4236 | av1_hash_table_init(&pool->frame_bufs[i].hash_table); |
| 4237 | } |
| 4238 | #endif |
| 4239 | } |
| 4240 | |
| 4241 | static void check_initial_width(AV1_COMP *cpi, |
| 4242 | #if CONFIG_HIGHBITDEPTH |
| 4243 | int use_highbitdepth, |
| 4244 | #endif |
| 4245 | int subsampling_x, int subsampling_y) { |
| 4246 | AV1_COMMON *const cm = &cpi->common; |
| 4247 | |
| 4248 | if (!cpi->initial_width || |
| 4249 | #if CONFIG_HIGHBITDEPTH |
| 4250 | cm->use_highbitdepth != use_highbitdepth || |
| 4251 | #endif |
| 4252 | cm->subsampling_x != subsampling_x || |
| 4253 | cm->subsampling_y != subsampling_y) { |
| 4254 | cm->subsampling_x = subsampling_x; |
| 4255 | cm->subsampling_y = subsampling_y; |
| 4256 | #if CONFIG_HIGHBITDEPTH |
| 4257 | cm->use_highbitdepth = use_highbitdepth; |
| 4258 | #endif |
| 4259 | |
| 4260 | alloc_raw_frame_buffers(cpi); |
| 4261 | init_ref_frame_bufs(cm); |
| 4262 | alloc_util_frame_buffers(cpi); |
| 4263 | |
| 4264 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 4265 | |
| 4266 | cpi->initial_width = cm->width; |
| 4267 | cpi->initial_height = cm->height; |
| 4268 | cpi->initial_mbs = cm->MBs; |
| 4269 | } |
| 4270 | } |
| 4271 | |
| 4272 | // Returns 1 if the assigned width or height was <= 0. |
| 4273 | static int set_size_literal(AV1_COMP *cpi, int width, int height) { |
| 4274 | AV1_COMMON *cm = &cpi->common; |
| 4275 | #if CONFIG_HIGHBITDEPTH |
| 4276 | check_initial_width(cpi, cm->use_highbitdepth, cm->subsampling_x, |
| 4277 | cm->subsampling_y); |
| 4278 | #else |
| 4279 | check_initial_width(cpi, cm->subsampling_x, cm->subsampling_y); |
| 4280 | #endif // CONFIG_HIGHBITDEPTH |
| 4281 | |
| 4282 | if (width <= 0 || height <= 0) return 1; |
| 4283 | |
| 4284 | cm->width = width; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4285 | cm->height = height; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4286 | |
| 4287 | if (cpi->initial_width && cpi->initial_height && |
| 4288 | (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) { |
| 4289 | av1_free_context_buffers(cm); |
| 4290 | av1_free_pc_tree(&cpi->td); |
| 4291 | alloc_compressor_data(cpi); |
| 4292 | realloc_segmentation_maps(cpi); |
| 4293 | cpi->initial_width = cpi->initial_height = 0; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4294 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4295 | update_frame_size(cpi); |
| 4296 | |
| 4297 | return 0; |
| 4298 | } |
| 4299 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4300 | static void set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4301 | AV1_COMMON *const cm = &cpi->common; |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4302 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4303 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4304 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4305 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 4306 | // There has been a change in the encoded frame size |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4307 | set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4308 | set_mv_search_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4309 | } |
| 4310 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 4311 | #if !CONFIG_XIPHRC |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4312 | if (cpi->oxcf.pass == 2) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4313 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4314 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 4315 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4316 | |
| 4317 | alloc_frame_mvs(cm, cm->new_fb_idx); |
| 4318 | |
| 4319 | // Reset the frame pointers to the current frame size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4320 | 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] | 4321 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4322 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4323 | cm->use_highbitdepth, |
| 4324 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 4325 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 4326 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4327 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4328 | "Failed to allocate frame buffer"); |
| 4329 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4330 | #if CONFIG_LOOP_RESTORATION |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4331 | #if CONFIG_FRAME_SUPERRES |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4332 | const int frame_width = cm->superres_upscaled_width; |
| 4333 | const int frame_height = cm->superres_upscaled_height; |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4334 | #else |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4335 | const int frame_width = cm->width; |
| 4336 | const int frame_height = cm->height; |
| 4337 | #endif |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4338 | set_restoration_unit_size(frame_width, frame_height, cm->subsampling_x, |
| 4339 | cm->subsampling_y, cm->rst_info); |
Rupert Swarbrick | 1a96c3f | 2017-10-24 11:55:00 +0100 | [diff] [blame] | 4340 | for (int i = 0; i < MAX_MB_PLANE; ++i) |
| 4341 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4342 | |
| 4343 | av1_alloc_restoration_buffers(cm); |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4344 | #endif // CONFIG_LOOP_RESTORATION |
| 4345 | alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4346 | init_motion_estimation(cpi); |
| 4347 | |
| 4348 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4349 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 4350 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 4351 | |
| 4352 | ref_buf->idx = buf_idx; |
| 4353 | |
| 4354 | if (buf_idx != INVALID_IDX) { |
| 4355 | YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf; |
| 4356 | ref_buf->buf = buf; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4357 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4358 | av1_setup_scale_factors_for_frame( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4359 | &ref_buf->sf, buf->y_crop_width, buf->y_crop_height, cm->width, |
| 4360 | cm->height, (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0); |
| 4361 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4362 | av1_setup_scale_factors_for_frame(&ref_buf->sf, buf->y_crop_width, |
| 4363 | buf->y_crop_height, cm->width, |
| 4364 | cm->height); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4365 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4366 | if (av1_is_scaled(&ref_buf->sf)) aom_extend_frame_borders(buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4367 | } else { |
| 4368 | ref_buf->buf = NULL; |
| 4369 | } |
| 4370 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 4371 | |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 4372 | #if CONFIG_INTRABC |
| 4373 | #if CONFIG_HIGHBITDEPTH |
Sebastien Alaiwan | 1dcb707 | 2017-05-12 11:13:05 +0200 | [diff] [blame] | 4374 | av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height, |
| 4375 | cm->width, cm->height, |
| 4376 | cm->use_highbitdepth); |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 4377 | #else |
| 4378 | av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height, |
| 4379 | cm->width, cm->height); |
| 4380 | #endif // CONFIG_HIGHBITDEPTH |
| 4381 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4382 | |
| 4383 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 4384 | } |
| 4385 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4386 | static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) { |
| 4387 | // Choose an arbitrary random number |
| 4388 | static unsigned int seed = 56789; |
| 4389 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4390 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 4391 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4392 | |
| 4393 | switch (oxcf->resize_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4394 | case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4395 | case RESIZE_FIXED: |
| 4396 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4397 | new_denom = oxcf->resize_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4398 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4399 | new_denom = oxcf->resize_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4400 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4401 | case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4402 | default: assert(0); |
| 4403 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4404 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | #if CONFIG_FRAME_SUPERRES |
Urvang Joshi | e58b564 | 2017-10-05 17:59:43 -0700 | [diff] [blame] | 4408 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4409 | static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) { |
| 4410 | // Choose an arbitrary random number |
| 4411 | static unsigned int seed = 34567; |
| 4412 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4413 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 4414 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4415 | int bottom_index, top_index, q, qthresh; |
| 4416 | |
| 4417 | switch (oxcf->superres_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4418 | case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4419 | case SUPERRES_FIXED: |
| 4420 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4421 | new_denom = oxcf->superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4422 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4423 | new_denom = oxcf->superres_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4424 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4425 | case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4426 | case SUPERRES_QTHRESH: |
| 4427 | qthresh = (cpi->common.frame_type == KEY_FRAME ? oxcf->superres_kf_qthresh |
| 4428 | : oxcf->superres_qthresh); |
| 4429 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
| 4430 | q = av1_rc_pick_q_and_bounds(cpi, cpi->oxcf.width, cpi->oxcf.height, |
| 4431 | &bottom_index, &top_index); |
| 4432 | if (q < qthresh) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4433 | new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4434 | } else { |
Urvang Joshi | 28983f7 | 2017-10-25 14:41:06 -0700 | [diff] [blame] | 4435 | const uint8_t min_denom = SCALE_NUMERATOR + 1; |
| 4436 | const uint8_t denom_step = (MAXQ - qthresh + 1) >> 3; |
| 4437 | const uint8_t additional_denom = (q - qthresh) / denom_step; |
| 4438 | new_denom = AOMMIN(min_denom + additional_denom, SCALE_NUMERATOR << 1); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4439 | } |
| 4440 | break; |
| 4441 | default: assert(0); |
| 4442 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4443 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4444 | } |
| 4445 | |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4446 | static int dimension_is_ok(int orig_dim, int resized_dim, int denom) { |
| 4447 | return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2); |
| 4448 | } |
| 4449 | |
| 4450 | static int dimensions_are_ok(int owidth, int oheight, size_params_type *rsz) { |
| 4451 | return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom) && |
Urvang Joshi | 3d8bcb2 | 2017-10-09 12:18:59 -0700 | [diff] [blame] | 4452 | (CONFIG_HORZONLY_FRAME_SUPERRES || |
Urvang Joshi | e58b564 | 2017-10-05 17:59:43 -0700 | [diff] [blame] | 4453 | dimension_is_ok(oheight, rsz->resize_height, rsz->superres_denom)); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4454 | } |
| 4455 | |
| 4456 | #define DIVIDE_AND_ROUND(x, y) (((x) + ((y) >> 1)) / (y)) |
| 4457 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4458 | static int validate_size_scales(RESIZE_MODE resize_mode, |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4459 | SUPERRES_MODE superres_mode, int owidth, |
| 4460 | int oheight, size_params_type *rsz) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4461 | if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4462 | return 1; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4463 | } |
| 4464 | |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 4465 | // Calculate current resize scale. |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4466 | int resize_denom = |
| 4467 | AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width), |
| 4468 | DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height)); |
| 4469 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4470 | if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4471 | // Alter superres scale as needed to enforce conformity. |
| 4472 | rsz->superres_denom = |
| 4473 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom; |
| 4474 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4475 | if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4476 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4477 | } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4478 | // Alter resize scale as needed to enforce conformity. |
| 4479 | resize_denom = |
| 4480 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4481 | rsz->resize_width = owidth; |
| 4482 | rsz->resize_height = oheight; |
| 4483 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4484 | resize_denom); |
| 4485 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4486 | if (resize_denom > SCALE_NUMERATOR) { |
| 4487 | --resize_denom; |
| 4488 | rsz->resize_width = owidth; |
| 4489 | rsz->resize_height = oheight; |
| 4490 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
| 4491 | resize_denom); |
| 4492 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4493 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4494 | } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4495 | // Alter both resize and superres scales as needed to enforce conformity. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4496 | do { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4497 | if (resize_denom > rsz->superres_denom) |
| 4498 | --resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4499 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4500 | --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4501 | rsz->resize_width = owidth; |
| 4502 | rsz->resize_height = oheight; |
| 4503 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4504 | resize_denom); |
| 4505 | } while (!dimensions_are_ok(owidth, oheight, rsz) && |
| 4506 | (resize_denom > SCALE_NUMERATOR || |
| 4507 | rsz->superres_denom > SCALE_NUMERATOR)); |
| 4508 | } else { // We are allowed to alter neither resize scale nor superres scale. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4509 | return 0; |
| 4510 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4511 | return dimensions_are_ok(owidth, oheight, rsz); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4512 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4513 | #undef DIVIDE_AND_ROUND |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4514 | #endif // CONFIG_FRAME_SUPERRES |
| 4515 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4516 | // Calculates resize and superres params for next frame |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4517 | size_params_type av1_calculate_next_size_params(AV1_COMP *cpi) { |
| 4518 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
| 4519 | size_params_type rsz = { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4520 | oxcf->width, |
| 4521 | oxcf->height, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4522 | #if CONFIG_FRAME_SUPERRES |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4523 | SCALE_NUMERATOR |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4524 | #endif // CONFIG_FRAME_SUPERRES |
| 4525 | }; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4526 | int resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4527 | if (oxcf->pass == 1) return rsz; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4528 | if (cpi->resize_pending_width && cpi->resize_pending_height) { |
| 4529 | rsz.resize_width = cpi->resize_pending_width; |
| 4530 | rsz.resize_height = cpi->resize_pending_height; |
| 4531 | cpi->resize_pending_width = cpi->resize_pending_height = 0; |
| 4532 | } else { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4533 | resize_denom = calculate_next_resize_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4534 | rsz.resize_width = cpi->oxcf.width; |
| 4535 | rsz.resize_height = cpi->oxcf.height; |
| 4536 | av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4537 | resize_denom); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4538 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4539 | #if CONFIG_FRAME_SUPERRES |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4540 | rsz.superres_denom = calculate_next_superres_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4541 | if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width, |
| 4542 | oxcf->height, &rsz)) |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4543 | assert(0 && "Invalid scale parameters"); |
| 4544 | #endif // CONFIG_FRAME_SUPERRES |
| 4545 | return rsz; |
| 4546 | } |
| 4547 | |
| 4548 | 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] | 4549 | int encode_width = rsz->resize_width; |
| 4550 | int encode_height = rsz->resize_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4551 | |
| 4552 | #if CONFIG_FRAME_SUPERRES |
| 4553 | AV1_COMMON *cm = &cpi->common; |
| 4554 | cm->superres_upscaled_width = encode_width; |
| 4555 | cm->superres_upscaled_height = encode_height; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4556 | cm->superres_scale_denominator = rsz->superres_denom; |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 4557 | av1_calculate_scaled_superres_size(&encode_width, &encode_height, |
| 4558 | rsz->superres_denom); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4559 | #endif // CONFIG_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4560 | set_frame_size(cpi, encode_width, encode_height); |
| 4561 | } |
| 4562 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4563 | static void setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4564 | size_params_type rsz = av1_calculate_next_size_params(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4565 | setup_frame_size_from_params(cpi, &rsz); |
| 4566 | } |
| 4567 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4568 | #if CONFIG_FRAME_SUPERRES |
| 4569 | static void superres_post_encode(AV1_COMP *cpi) { |
| 4570 | AV1_COMMON *cm = &cpi->common; |
| 4571 | |
| 4572 | if (av1_superres_unscaled(cm)) return; |
| 4573 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4574 | av1_superres_upscale(cm, NULL); |
| 4575 | |
| 4576 | // If regular resizing is occurring the source will need to be downscaled to |
| 4577 | // match the upscaled superres resolution. Otherwise the original source is |
| 4578 | // used. |
| 4579 | if (av1_resize_unscaled(cm)) { |
| 4580 | cpi->source = cpi->unscaled_source; |
| 4581 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 4582 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 4583 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 4584 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4585 | // Do downscale. cm->(width|height) has been updated by av1_superres_upscale |
| 4586 | if (aom_realloc_frame_buffer( |
| 4587 | &cpi->scaled_source, cm->superres_upscaled_width, |
| 4588 | cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y, |
| 4589 | #if CONFIG_HIGHBITDEPTH |
| 4590 | cm->use_highbitdepth, |
| 4591 | #endif // CONFIG_HIGHBITDEPTH |
| 4592 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
| 4593 | aom_internal_error( |
| 4594 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 4595 | "Failed to reallocate scaled source buffer for superres"); |
| 4596 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 4597 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
| 4598 | #if CONFIG_HIGHBITDEPTH |
| 4599 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
| 4600 | (int)cm->bit_depth); |
| 4601 | #else |
| 4602 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source); |
| 4603 | #endif // CONFIG_HIGHBITDEPTH |
| 4604 | cpi->source = &cpi->scaled_source; |
| 4605 | } |
| 4606 | } |
| 4607 | #endif // CONFIG_FRAME_SUPERRES |
| 4608 | |
| 4609 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
| 4610 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
| 4611 | struct loopfilter *lf = &cm->lf; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4612 | int no_loopfilter = 0; |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4613 | #if CONFIG_CDEF |
| 4614 | int no_cdef = 0; |
| 4615 | #endif |
| 4616 | #if CONFIG_LOOP_RESTORATION |
| 4617 | int no_restoration = 0; |
| 4618 | #endif |
| 4619 | if (is_lossless_requested(&cpi->oxcf) |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4620 | #if CONFIG_EXT_TILE |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4621 | || cm->single_tile_decoding |
| 4622 | #endif |
| 4623 | ) { |
| 4624 | no_loopfilter = 1; |
| 4625 | #if CONFIG_CDEF |
| 4626 | no_cdef = 1; |
| 4627 | #endif |
| 4628 | #if CONFIG_LOOP_RESTORATION |
| 4629 | no_restoration = 1; |
| 4630 | #endif |
| 4631 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4632 | |
| 4633 | if (no_loopfilter) { |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4634 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4635 | lf->filter_level[0] = 0; |
| 4636 | lf->filter_level[1] = 0; |
| 4637 | #else |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4638 | lf->filter_level = 0; |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4639 | #endif |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4640 | } else { |
| 4641 | struct aom_usec_timer timer; |
| 4642 | |
| 4643 | aom_clear_system_state(); |
| 4644 | |
| 4645 | aom_usec_timer_start(&timer); |
| 4646 | |
| 4647 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
| 4648 | |
| 4649 | aom_usec_timer_mark(&timer); |
| 4650 | cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer); |
| 4651 | } |
| 4652 | |
Cheng Chen | 5ad5b28 | 2017-10-05 16:36:06 -0700 | [diff] [blame] | 4653 | #if CONFIG_INTRABC |
| 4654 | // When intraBC is on, do loop filtering per superblock, |
| 4655 | // instead of do it after the whole frame has been encoded, |
| 4656 | // as is in the else branch |
| 4657 | #else |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 4658 | #if !CONFIG_LPF_SB |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4659 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4660 | if (lf->filter_level[0] || lf->filter_level[1]) |
| 4661 | #else |
| 4662 | if (lf->filter_level > 0) |
| 4663 | #endif |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 4664 | #endif // CONFIG_LPF_SB |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4665 | { |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 4666 | #if CONFIG_LPF_SB |
| 4667 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0, 0, |
| 4668 | 0); |
| 4669 | #else |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4670 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4671 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level[0], |
| 4672 | lf->filter_level[1], 0, 0); |
| 4673 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_u, |
| 4674 | lf->filter_level_u, 1, 0); |
| 4675 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_v, |
| 4676 | lf->filter_level_v, 2, 0); |
| 4677 | |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 4678 | #else |
| 4679 | 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] | 4680 | #endif // CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 4681 | #endif // CONFIG_LPF_SB |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4682 | } |
Cheng Chen | 5ad5b28 | 2017-10-05 16:36:06 -0700 | [diff] [blame] | 4683 | #endif // CONFIG_INTRABC |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 4684 | |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 4685 | #if CONFIG_STRIPED_LOOP_RESTORATION |
Rupert Swarbrick | 76c7800 | 2017-11-02 17:26:35 +0000 | [diff] [blame] | 4686 | #if CONFIG_FRAME_SUPERRES && CONFIG_HORZONLY_FRAME_SUPERRES |
Rupert Swarbrick | 8ce049e | 2017-11-06 16:47:47 +0000 | [diff] [blame] | 4687 | if (!av1_superres_unscaled(cm)) aom_extend_frame_borders(cm->frame_to_show); |
Rupert Swarbrick | 76c7800 | 2017-11-02 17:26:35 +0000 | [diff] [blame] | 4688 | #endif |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4689 | if (!no_restoration) |
| 4690 | av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 0); |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 4691 | #endif |
| 4692 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4693 | #if CONFIG_CDEF |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4694 | if (no_cdef) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4695 | cm->cdef_bits = 0; |
| 4696 | cm->cdef_strengths[0] = 0; |
| 4697 | cm->nb_cdef_strengths = 1; |
| 4698 | } else { |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 4699 | // Find CDEF parameters |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4700 | av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd, |
Debargha Mukherjee | d7338aa | 2017-11-04 07:34:50 -0700 | [diff] [blame] | 4701 | cpi->sf.fast_cdef_search); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4702 | |
| 4703 | // Apply the filter |
| 4704 | av1_cdef_frame(cm->frame_to_show, cm, xd); |
| 4705 | } |
| 4706 | #endif |
| 4707 | |
| 4708 | #if CONFIG_FRAME_SUPERRES |
| 4709 | superres_post_encode(cpi); |
| 4710 | #endif // CONFIG_FRAME_SUPERRES |
| 4711 | |
| 4712 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 4713 | if (no_restoration) { |
| 4714 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 4715 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 4716 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
| 4717 | } else { |
| 4718 | av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm, 1); |
| 4719 | av1_pick_filter_restoration(cpi->source, cpi); |
| 4720 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 4721 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 4722 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
| 4723 | av1_loop_restoration_filter_frame(cm->frame_to_show, cm, cm->rst_info, 7, |
| 4724 | NULL); |
| 4725 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4726 | } |
| 4727 | #endif // CONFIG_LOOP_RESTORATION |
| 4728 | // TODO(debargha): Fix mv search range on encoder side |
| 4729 | // aom_extend_frame_inner_borders(cm->frame_to_show); |
| 4730 | aom_extend_frame_borders(cm->frame_to_show); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4731 | } |
| 4732 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4733 | static void encode_without_recode_loop(AV1_COMP *cpi) { |
| 4734 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4735 | int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4736 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4737 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4738 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4739 | set_size_independent_vars(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4740 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4741 | setup_frame_size(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4742 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4743 | assert(cm->width == cpi->scaled_source.y_crop_width); |
| 4744 | assert(cm->height == cpi->scaled_source.y_crop_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 4745 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4746 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4747 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4748 | cpi->source = |
| 4749 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
| 4750 | if (cpi->unscaled_last_source != NULL) |
| 4751 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4752 | &cpi->scaled_last_source); |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 4753 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4754 | cpi->source->buf_8bit_valid = 0; |
| 4755 | #endif |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4756 | |
| 4757 | if (frame_is_intra_only(cm) == 0) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4758 | scale_references(cpi); |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4759 | } |
| 4760 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4761 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4762 | setup_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4763 | suppress_active_map(cpi); |
hui su | ed5a30f | 2017-04-27 16:02:49 -0700 | [diff] [blame] | 4764 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4765 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4766 | // exclusive. |
| 4767 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4768 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4769 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4770 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4771 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4772 | av1_cyclic_refresh_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4773 | } |
| 4774 | apply_active_map(cpi); |
| 4775 | |
| 4776 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4777 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4778 | |
| 4779 | // Update some stats from cyclic refresh, and check if we should not update |
| 4780 | // golden reference, for 1 pass CBR. |
| 4781 | 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] | 4782 | (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR)) |
| 4783 | av1_cyclic_refresh_check_golden_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4784 | |
| 4785 | // Update the skip mb flag probabilities based on the distribution |
| 4786 | // seen in the last encoder iteration. |
| 4787 | // update_base_skip_probs(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4788 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4789 | } |
| 4790 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4791 | static void encode_with_recode_loop(AV1_COMP *cpi, size_t *size, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4792 | uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4793 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4794 | RATE_CONTROL *const rc = &cpi->rc; |
| 4795 | int bottom_index, top_index; |
| 4796 | int loop_count = 0; |
| 4797 | int loop_at_this_size = 0; |
| 4798 | int loop = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4799 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4800 | int overshoot_seen = 0; |
| 4801 | int undershoot_seen = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4802 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4803 | int frame_over_shoot_limit; |
| 4804 | int frame_under_shoot_limit; |
| 4805 | int q = 0, q_low = 0, q_high = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4806 | |
| 4807 | set_size_independent_vars(cpi); |
| 4808 | |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 4809 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4810 | cpi->source->buf_8bit_valid = 0; |
| 4811 | #endif |
| 4812 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4813 | aom_clear_system_state(); |
| 4814 | setup_frame_size(cpi); |
| 4815 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4816 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4817 | do { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4818 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4819 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4820 | if (loop_count == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4821 | // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. |
| 4822 | set_mv_search_params(cpi); |
| 4823 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4824 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4825 | // Reset the loop state for new frame size. |
| 4826 | overshoot_seen = 0; |
| 4827 | undershoot_seen = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4828 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4829 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4830 | q_low = bottom_index; |
| 4831 | q_high = top_index; |
| 4832 | |
| 4833 | loop_at_this_size = 0; |
| 4834 | } |
| 4835 | |
| 4836 | // Decide frame size bounds first time through. |
| 4837 | if (loop_count == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4838 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4839 | &frame_under_shoot_limit, |
| 4840 | &frame_over_shoot_limit); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4841 | } |
| 4842 | |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4843 | // if frame was scaled calculate global_motion_search again if already done |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4844 | if (loop_count > 0 && cpi->source && cpi->global_motion_search_done) |
| 4845 | if (cpi->source->y_crop_width != cm->width || |
| 4846 | cpi->source->y_crop_height != cm->height) |
| 4847 | cpi->global_motion_search_done = 0; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4848 | cpi->source = |
| 4849 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4850 | if (cpi->unscaled_last_source != NULL) |
| 4851 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4852 | &cpi->scaled_last_source); |
| 4853 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4854 | if (frame_is_intra_only(cm) == 0) { |
| 4855 | if (loop_count > 0) { |
| 4856 | release_scaled_references(cpi); |
| 4857 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4858 | scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4859 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4860 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4861 | |
| 4862 | if (loop_count == 0) setup_frame(cpi); |
| 4863 | |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 4864 | #if CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4865 | // Base q-index may have changed, so we need to assign proper default coef |
| 4866 | // probs before every iteration. |
| 4867 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
| 4868 | int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4869 | av1_default_coef_probs(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4870 | if (cm->frame_type == KEY_FRAME || cm->error_resilient_mode || |
| 4871 | cm->reset_frame_context == RESET_FRAME_CONTEXT_ALL) { |
| 4872 | for (i = 0; i < FRAME_CONTEXTS; ++i) cm->frame_contexts[i] = *cm->fc; |
| 4873 | } else if (cm->reset_frame_context == RESET_FRAME_CONTEXT_CURRENT) { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 4874 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 4875 | if (cm->frame_refs[0].idx >= 0) { |
| 4876 | cm->frame_contexts[cm->frame_refs[0].idx] = *cm->fc; |
| 4877 | } |
| 4878 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4879 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 4880 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4881 | } |
| 4882 | } |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 4883 | #endif // CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4884 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4885 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4886 | // exclusive. |
| 4887 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4888 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4889 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4890 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4891 | } |
| 4892 | |
| 4893 | // transform / motion compensation build reconstruction frame |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4894 | save_coding_context(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4895 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4896 | |
| 4897 | // Update the skip mb flag probabilities based on the distribution |
| 4898 | // seen in the last encoder iteration. |
| 4899 | // update_base_skip_probs(cpi); |
| 4900 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4901 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4902 | |
| 4903 | // Dummy pack of the bitstream using up to date stats to get an |
| 4904 | // accurate estimate of output frame size to determine if we need |
| 4905 | // to recode. |
| 4906 | if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4907 | restore_coding_context(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4908 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4909 | |
| 4910 | rc->projected_frame_size = (int)(*size) << 3; |
| 4911 | restore_coding_context(cpi); |
| 4912 | |
| 4913 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4914 | } |
| 4915 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4916 | if (cpi->oxcf.rc_mode == AOM_Q) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4917 | loop = 0; |
| 4918 | } else { |
| 4919 | if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced && |
| 4920 | (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
| 4921 | int last_q = q; |
| 4922 | int64_t kf_err; |
| 4923 | |
| 4924 | int64_t high_err_target = cpi->ambient_err; |
| 4925 | int64_t low_err_target = cpi->ambient_err >> 1; |
| 4926 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4927 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4928 | if (cm->use_highbitdepth) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4929 | 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] | 4930 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4931 | 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] | 4932 | } |
| 4933 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4934 | kf_err = aom_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4935 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4936 | |
| 4937 | // Prevent possible divide by zero error below for perfect KF |
| 4938 | kf_err += !kf_err; |
| 4939 | |
| 4940 | // The key frame is not good enough or we can afford |
| 4941 | // to make it better without undue risk of popping. |
| 4942 | if ((kf_err > high_err_target && |
| 4943 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4944 | (kf_err > low_err_target && |
| 4945 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4946 | // Lower q_high |
| 4947 | q_high = q > q_low ? q - 1 : q_low; |
| 4948 | |
| 4949 | // Adjust Q |
| 4950 | q = (int)((q * high_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4951 | q = AOMMIN(q, (q_high + q_low) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4952 | } else if (kf_err < low_err_target && |
| 4953 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4954 | // The key frame is much better than the previous frame |
| 4955 | // Raise q_low |
| 4956 | q_low = q < q_high ? q + 1 : q_high; |
| 4957 | |
| 4958 | // Adjust Q |
| 4959 | q = (int)((q * low_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4960 | q = AOMMIN(q, (q_high + q_low + 1) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | // Clamp Q to upper and lower limits: |
| 4964 | q = clamp(q, q_low, q_high); |
| 4965 | |
| 4966 | loop = q != last_q; |
| 4967 | } else if (recode_loop_test(cpi, frame_over_shoot_limit, |
| 4968 | frame_under_shoot_limit, q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4969 | AOMMAX(q_high, top_index), bottom_index)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4970 | // Is the projected frame size out of range and are we allowed |
| 4971 | // to attempt to recode. |
| 4972 | int last_q = q; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4973 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4974 | int retries = 0; |
| 4975 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4976 | // Frame size out of permitted range: |
| 4977 | // Update correction factor & compute new Q to try... |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4978 | // Frame is too large |
| 4979 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 4980 | // Special case if the projected size is > the max allowed. |
| 4981 | if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
| 4982 | q_high = rc->worst_quality; |
| 4983 | |
| 4984 | // Raise Qlow as to at least the current value |
| 4985 | q_low = q < q_high ? q + 1 : q_high; |
| 4986 | |
| 4987 | if (undershoot_seen || loop_at_this_size > 1) { |
| 4988 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4989 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4990 | |
| 4991 | q = (q_high + q_low + 1) / 2; |
| 4992 | } else { |
| 4993 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4994 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4995 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4996 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4997 | AOMMAX(q_high, top_index), cm->width, |
| 4998 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4999 | |
| 5000 | while (q < q_low && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5001 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5002 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5003 | AOMMAX(q_high, top_index), cm->width, |
| 5004 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5005 | retries++; |
| 5006 | } |
| 5007 | } |
| 5008 | |
| 5009 | overshoot_seen = 1; |
| 5010 | } else { |
| 5011 | // Frame is too small |
| 5012 | q_high = q > q_low ? q - 1 : q_low; |
| 5013 | |
| 5014 | if (overshoot_seen || loop_at_this_size > 1) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5015 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5016 | q = (q_high + q_low) / 2; |
| 5017 | } else { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5018 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5019 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5020 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5021 | // Special case reset for qlow for constrained quality. |
| 5022 | // This should only trigger where there is very substantial |
| 5023 | // undershoot on a frame and the auto cq level is above |
| 5024 | // the user passsed in value. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5025 | if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5026 | q_low = q; |
| 5027 | } |
| 5028 | |
| 5029 | while (q > q_high && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5030 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5031 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5032 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5033 | retries++; |
| 5034 | } |
| 5035 | } |
| 5036 | |
| 5037 | undershoot_seen = 1; |
| 5038 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5039 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5040 | |
| 5041 | // Clamp Q to upper and lower limits: |
| 5042 | q = clamp(q, q_low, q_high); |
| 5043 | |
| 5044 | loop = (q != last_q); |
| 5045 | } else { |
| 5046 | loop = 0; |
| 5047 | } |
| 5048 | } |
| 5049 | |
| 5050 | // Special case for overlay frame. |
| 5051 | if (rc->is_src_frame_alt_ref && |
| 5052 | rc->projected_frame_size < rc->max_frame_bandwidth) |
| 5053 | loop = 0; |
| 5054 | |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 5055 | if (recode_loop_test_global_motion(cpi)) { |
| 5056 | loop = 1; |
| 5057 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 5058 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5059 | if (loop) { |
| 5060 | ++loop_count; |
| 5061 | ++loop_at_this_size; |
| 5062 | |
| 5063 | #if CONFIG_INTERNAL_STATS |
| 5064 | ++cpi->tot_recode_hits; |
| 5065 | #endif |
| 5066 | } |
| 5067 | } while (loop); |
| 5068 | } |
| 5069 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5070 | static int get_ref_frame_flags(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5071 | const int *const map = cpi->common.ref_frame_map; |
| 5072 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5073 | // No.1 Priority: LAST_FRAME |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5074 | const int last2_is_last = |
| 5075 | map[cpi->lst_fb_idxes[1]] == map[cpi->lst_fb_idxes[0]]; |
| 5076 | const int last3_is_last = |
| 5077 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[0]]; |
| 5078 | const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 5079 | 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] | 5080 | 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] | 5081 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 5082 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5083 | // No.2 Priority: ALTREF_FRAME |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5084 | const int last2_is_alt = map[cpi->lst_fb_idxes[1]] == map[cpi->alt_fb_idx]; |
| 5085 | const int last3_is_alt = map[cpi->lst_fb_idxes[2]] == map[cpi->alt_fb_idx]; |
| 5086 | const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 5087 | 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] | 5088 | 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] | 5089 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5090 | // No.3 Priority: LAST2_FRAME |
| 5091 | const int last3_is_last2 = |
| 5092 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]]; |
| 5093 | const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 5094 | const int bwd_is_last2 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 5095 | 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] | 5096 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5097 | // No.4 Priority: LAST3_FRAME |
| 5098 | const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 5099 | const int bwd_is_last3 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 5100 | const int alt2_is_last3 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 5101 | |
| 5102 | // No.5 Priority: GOLDEN_FRAME |
| 5103 | const int bwd_is_gld = map[cpi->bwd_fb_idx] == map[cpi->gld_fb_idx]; |
| 5104 | const int alt2_is_gld = map[cpi->alt2_fb_idx] == map[cpi->gld_fb_idx]; |
| 5105 | |
| 5106 | // No.6 Priority: BWDREF_FRAME |
| 5107 | const int alt2_is_bwd = map[cpi->alt2_fb_idx] == map[cpi->bwd_fb_idx]; |
| 5108 | |
| 5109 | // No.7 Priority: ALTREF2_FRAME |
| 5110 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5111 | // After av1_apply_encoding_flags() is called, cpi->ref_frame_flags might be |
| 5112 | // adjusted according to external encoder flags. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 5113 | int flags = cpi->ext_ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5114 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5115 | 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] | 5116 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5117 | if (alt_is_last) flags &= ~AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5118 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5119 | if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5120 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5121 | 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] | 5122 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5123 | if (gld_is_last || gld_is_alt || gld_is_last2 || gld_is_last3) |
| 5124 | flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5125 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5126 | if ((bwd_is_last || bwd_is_alt || bwd_is_last2 || bwd_is_last3 || |
| 5127 | bwd_is_gld) && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5128 | (flags & AOM_BWD_FLAG)) |
| 5129 | flags &= ~AOM_BWD_FLAG; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5130 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5131 | if ((alt2_is_last || alt2_is_alt || alt2_is_last2 || alt2_is_last3 || |
| 5132 | alt2_is_gld || alt2_is_bwd) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5133 | (flags & AOM_ALT2_FLAG)) |
| 5134 | flags &= ~AOM_ALT2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5135 | |
| 5136 | return flags; |
| 5137 | } |
| 5138 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5139 | static void set_ext_overrides(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5140 | // Overrides the defaults with the externally supplied values with |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5141 | // av1_update_reference() and av1_update_entropy() calls |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5142 | // Note: The overrides are valid only for the next frame passed |
| 5143 | // to encode_frame_to_data_rate() function |
| 5144 | if (cpi->ext_refresh_frame_context_pending) { |
| 5145 | cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context; |
| 5146 | cpi->ext_refresh_frame_context_pending = 0; |
| 5147 | } |
| 5148 | if (cpi->ext_refresh_frame_flags_pending) { |
| 5149 | cpi->refresh_last_frame = cpi->ext_refresh_last_frame; |
| 5150 | cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame; |
| 5151 | cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 5152 | cpi->refresh_bwd_ref_frame = cpi->ext_refresh_bwd_ref_frame; |
| 5153 | cpi->refresh_alt2_ref_frame = cpi->ext_refresh_alt2_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5154 | cpi->ext_refresh_frame_flags_pending = 0; |
| 5155 | } |
| 5156 | } |
| 5157 | |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 5158 | #if !CONFIG_FRAME_SIGN_BIAS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5159 | static void set_arf_sign_bias(AV1_COMP *cpi) { |
| 5160 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5161 | int arf_sign_bias; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5162 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5163 | // The arf_sign_bias will be one for internal ARFs' |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5164 | arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 5165 | (!cpi->refresh_alt_ref_frame || |
| 5166 | gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE); |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 5167 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5168 | cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5169 | cm->ref_frame_sign_bias[BWDREF_FRAME] = cm->ref_frame_sign_bias[ALTREF_FRAME]; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5170 | cm->ref_frame_sign_bias[ALTREF2_FRAME] = |
| 5171 | cm->ref_frame_sign_bias[ALTREF_FRAME]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5172 | } |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 5173 | #endif // !CONFIG_FRAME_SIGN_BIAS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5174 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5175 | static int setup_interp_filter_search_mask(AV1_COMP *cpi) { |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 5176 | InterpFilter ifilter; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5177 | int ref_total[TOTAL_REFS_PER_FRAME] = { 0 }; |
| 5178 | MV_REFERENCE_FRAME ref; |
| 5179 | int mask = 0; |
| 5180 | int arf_idx = ALTREF_FRAME; |
| 5181 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5182 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame || |
| 5183 | cpi->refresh_alt2_ref_frame) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5184 | return mask; |
| 5185 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5186 | for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) |
| 5187 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) |
| 5188 | ref_total[ref] += cpi->interp_filter_selected[ref][ifilter]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5189 | |
| 5190 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) { |
| 5191 | if ((ref_total[LAST_FRAME] && |
| 5192 | cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5193 | (ref_total[LAST2_FRAME] == 0 || |
| 5194 | cpi->interp_filter_selected[LAST2_FRAME][ifilter] * 50 < |
| 5195 | ref_total[LAST2_FRAME]) && |
| 5196 | (ref_total[LAST3_FRAME] == 0 || |
| 5197 | cpi->interp_filter_selected[LAST3_FRAME][ifilter] * 50 < |
| 5198 | ref_total[LAST3_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5199 | (ref_total[GOLDEN_FRAME] == 0 || |
| 5200 | cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50 < |
| 5201 | ref_total[GOLDEN_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5202 | (ref_total[BWDREF_FRAME] == 0 || |
| 5203 | cpi->interp_filter_selected[BWDREF_FRAME][ifilter] * 50 < |
| 5204 | ref_total[BWDREF_FRAME]) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5205 | (ref_total[ALTREF2_FRAME] == 0 || |
| 5206 | cpi->interp_filter_selected[ALTREF2_FRAME][ifilter] * 50 < |
| 5207 | ref_total[ALTREF2_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5208 | (ref_total[ALTREF_FRAME] == 0 || |
| 5209 | cpi->interp_filter_selected[arf_idx][ifilter] * 50 < |
| 5210 | ref_total[ALTREF_FRAME])) |
| 5211 | mask |= 1 << ifilter; |
| 5212 | } |
| 5213 | return mask; |
| 5214 | } |
| 5215 | |
| 5216 | #define DUMP_RECON_FRAMES 0 |
| 5217 | |
| 5218 | #if DUMP_RECON_FRAMES == 1 |
| 5219 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5220 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 5221 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5222 | const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5223 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5224 | if (recon_buf == NULL) { |
| 5225 | printf("Frame %d is not ready.\n", cm->current_video_frame); |
| 5226 | return; |
| 5227 | } |
| 5228 | |
| 5229 | #if CONFIG_FRAME_MARKER |
| 5230 | static const int flag_list[TOTAL_REFS_PER_FRAME] = { 0, |
| 5231 | AOM_LAST_FLAG, |
| 5232 | AOM_LAST2_FLAG, |
| 5233 | AOM_LAST3_FLAG, |
| 5234 | AOM_GOLD_FLAG, |
| 5235 | AOM_BWD_FLAG, |
| 5236 | AOM_ALT2_FLAG, |
| 5237 | AOM_ALT_FLAG }; |
| 5238 | printf( |
| 5239 | "\n***Frame=%d (frame_offset=%d, show_frame=%d, " |
| 5240 | "show_existing_frame=%d) " |
| 5241 | "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[", |
| 5242 | cm->current_video_frame, cm->frame_offset, cm->show_frame, |
| 5243 | cm->show_existing_frame); |
| 5244 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 5245 | const int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx; |
| 5246 | const int ref_offset = |
| 5247 | (buf_idx >= 0) |
| 5248 | ? (int)cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset |
| 5249 | : -1; |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 5250 | printf( |
| 5251 | " %d(%c-%d-%4.2f)", ref_offset, |
| 5252 | (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N', |
| 5253 | (buf_idx >= 0) ? (int)cpi->frame_rf_level[buf_idx] : -1, |
| 5254 | (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] | 5255 | } |
| 5256 | printf(" ]\n"); |
| 5257 | #endif // CONFIG_FRAME_MARKER |
| 5258 | |
| 5259 | if (!cm->show_frame) { |
| 5260 | 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] | 5261 | cm->current_video_frame); |
| 5262 | return; |
| 5263 | } |
| 5264 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5265 | int h; |
| 5266 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 5267 | FILE *f_recon = NULL; |
| 5268 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5269 | if (cm->current_video_frame == 0) { |
| 5270 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 5271 | printf("Unable to open file %s to write.\n", file_name); |
| 5272 | return; |
| 5273 | } |
| 5274 | } else { |
| 5275 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 5276 | printf("Unable to open file %s to append.\n", file_name); |
| 5277 | return; |
| 5278 | } |
| 5279 | } |
| 5280 | printf( |
| 5281 | "\nFrame=%5d, encode_update_type[%5d]=%1d, show_existing_frame=%d, " |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 5282 | "source_alt_ref_active=%d, refresh_alt_ref_frame=%d, rf_level=%d, " |
| 5283 | "y_stride=%4d, uv_stride=%4d, cm->width=%4d, cm->height=%4d\n", |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5284 | cm->current_video_frame, cpi->twopass.gf_group.index, |
| 5285 | cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 5286 | cm->show_existing_frame, cpi->rc.source_alt_ref_active, |
| 5287 | cpi->refresh_alt_ref_frame, |
| 5288 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index], |
| 5289 | recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5290 | #if 0 |
| 5291 | int ref_frame; |
| 5292 | printf("get_ref_frame_map_idx: ["); |
| 5293 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
| 5294 | printf(" %d", get_ref_frame_map_idx(cpi, ref_frame)); |
| 5295 | printf(" ]\n"); |
| 5296 | printf("cm->new_fb_idx = %d\n", cm->new_fb_idx); |
| 5297 | printf("cm->ref_frame_map = ["); |
| 5298 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 5299 | printf(" %d", cm->ref_frame_map[ref_frame - LAST_FRAME]); |
| 5300 | } |
| 5301 | printf(" ]\n"); |
| 5302 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5303 | |
| 5304 | // --- Y --- |
| 5305 | for (h = 0; h < cm->height; ++h) { |
| 5306 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 5307 | f_recon); |
| 5308 | } |
| 5309 | // --- U --- |
| 5310 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 5311 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 5312 | f_recon); |
| 5313 | } |
| 5314 | // --- V --- |
| 5315 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 5316 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 5317 | f_recon); |
| 5318 | } |
| 5319 | |
| 5320 | fclose(f_recon); |
| 5321 | } |
| 5322 | #endif // DUMP_RECON_FRAMES |
| 5323 | |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5324 | static void make_update_tile_list_enc(AV1_COMP *cpi, const int start_tile, |
| 5325 | const int num_tiles, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5326 | FRAME_CONTEXT *ec_ctxs[]) { |
| 5327 | int i; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5328 | for (i = start_tile; i < start_tile + num_tiles; ++i) |
| 5329 | ec_ctxs[i - start_tile] = &cpi->tile_data[i].tctx; |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5330 | } |
| 5331 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5332 | static void encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5333 | uint8_t *dest, int skip_adapt, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5334 | unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5335 | AV1_COMMON *const cm = &cpi->common; |
| 5336 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5337 | struct segmentation *const seg = &cm->seg; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5338 | #if CONFIG_SIMPLE_BWD_ADAPT |
| 5339 | const int num_bwd_ctxs = 1; |
| 5340 | #else |
| 5341 | const int num_bwd_ctxs = cm->tile_rows * cm->tile_cols; |
| 5342 | #endif |
| 5343 | |
| 5344 | FRAME_CONTEXT **tile_ctxs = |
| 5345 | aom_malloc(num_bwd_ctxs * sizeof(&cpi->tile_data[0].tctx)); |
| 5346 | aom_cdf_prob **cdf_ptrs = aom_malloc( |
| 5347 | num_bwd_ctxs * sizeof(&cpi->tile_data[0].tctx.partition_cdf[0][0])); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5348 | #if CONFIG_XIPHRC |
| 5349 | int frame_type; |
| 5350 | int drop_this_frame = 0; |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5351 | #endif // CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5352 | set_ext_overrides(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5353 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5354 | |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 5355 | #if !CONFIG_FRAME_SIGN_BIAS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5356 | // Set the arf sign bias for this frame. |
| 5357 | set_arf_sign_bias(cpi); |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 5358 | #endif // !CONFIG_FRAME_SIGN_BIAS |
| 5359 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 5360 | #if CONFIG_TEMPMV_SIGNALING |
| 5361 | // frame type has been decided outside of this function call |
| 5362 | cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only; |
Jingning Han | e17ebe9 | 2017-11-03 15:25:42 -0700 | [diff] [blame] | 5363 | cm->use_ref_frame_mvs = |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 5364 | !cpi->oxcf.disable_tempmv && !cm->cur_frame->intra_only; |
Jingning Han | e17ebe9 | 2017-11-03 15:25:42 -0700 | [diff] [blame] | 5365 | cm->use_prev_frame_mvs = cm->use_ref_frame_mvs; |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 5366 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5367 | |
Jingning Han | d8a15a6 | 2017-10-30 10:53:42 -0700 | [diff] [blame] | 5368 | // Reset the frame packet stamp index. |
| 5369 | if (cm->frame_type == KEY_FRAME) cm->current_video_frame = 0; |
| 5370 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5371 | // NOTE: |
| 5372 | // (1) Move the setup of the ref_frame_flags upfront as it would be |
| 5373 | // determined by the current frame properties; |
| 5374 | // (2) The setup of the ref_frame_flags applies to both show_existing_frame's |
| 5375 | // and the other cases. |
| 5376 | if (cm->current_video_frame > 0) |
| 5377 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 5378 | |
| 5379 | if (cm->show_existing_frame) { |
| 5380 | // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current |
| 5381 | // BWDREF_FRAME in the reference frame buffer. |
| 5382 | cm->frame_type = INTER_FRAME; |
| 5383 | cm->show_frame = 1; |
| 5384 | cpi->frame_flags = *frame_flags; |
| 5385 | |
| 5386 | // In the case of show_existing frame, we will not send fresh flag |
| 5387 | // to decoder. Any change in the reference frame buffer can be done by |
| 5388 | // switching the virtual indices. |
| 5389 | |
| 5390 | cpi->refresh_last_frame = 0; |
| 5391 | cpi->refresh_golden_frame = 0; |
| 5392 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5393 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5394 | cpi->refresh_alt_ref_frame = 0; |
| 5395 | |
| 5396 | cpi->rc.is_bwd_ref_frame = 0; |
| 5397 | cpi->rc.is_last_bipred_frame = 0; |
| 5398 | cpi->rc.is_bipred_frame = 0; |
| 5399 | |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 5400 | restore_coding_context(cpi); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5401 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5402 | // Build the bitstream |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5403 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5404 | |
| 5405 | // Set up frame to show to get ready for stats collection. |
| 5406 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 5407 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5408 | #if CONFIG_FRAME_MARKER |
| 5409 | // Update current frame offset. |
| 5410 | cm->frame_offset = |
| 5411 | cm->buffer_pool->frame_bufs[cm->new_fb_idx].cur_frame_offset; |
| 5412 | #endif // CONFIG_FRAME_MARKER |
| 5413 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5414 | #if DUMP_RECON_FRAMES == 1 |
| 5415 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 5416 | dump_filtered_recon_frames(cpi); |
| 5417 | #endif // DUMP_RECON_FRAMES |
| 5418 | |
| 5419 | // Update the LAST_FRAME in the reference frame buffer. |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5420 | // NOTE: |
| 5421 | // (1) For BWDREF_FRAME as the show_existing_frame, the reference frame |
| 5422 | // update has been done previously when handling the LAST_BIPRED_FRAME |
| 5423 | // right before BWDREF_FRAME (in the display order); |
| 5424 | // (2) For INTNL_OVERLAY as the show_existing_frame, the reference frame |
| 5425 | // update will be done when the following is called, which will exchange |
| 5426 | // the virtual indexes between LAST_FRAME and ALTREF2_FRAME, so that |
| 5427 | // LAST3 will get retired, LAST2 becomes LAST3, LAST becomes LAST2, and |
| 5428 | // ALTREF2_FRAME will serve as the new LAST_FRAME. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5429 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5430 | |
| 5431 | // Update frame flags |
| 5432 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 5433 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 5434 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 5435 | |
| 5436 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5437 | |
| 5438 | // Update the frame type |
| 5439 | cm->last_frame_type = cm->frame_type; |
| 5440 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5441 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 5442 | // to do post-encoding update accordingly. |
| 5443 | if (cpi->rc.is_src_frame_alt_ref) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5444 | av1_set_target_rate(cpi, cm->width, cm->height); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5445 | #if CONFIG_XIPHRC |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5446 | frame_type = cm->frame_type == INTER_FRAME ? OD_P_FRAME : OD_I_FRAME; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5447 | drop_this_frame = od_enc_rc_update_state( |
| 5448 | &cpi->od_rc, *size << 3, cpi->refresh_golden_frame, |
| 5449 | cpi->refresh_alt_ref_frame, frame_type, cpi->droppable); |
| 5450 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5451 | av1_rc_postencode_update(cpi, *size); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5452 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5453 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5454 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5455 | ++cm->current_video_frame; |
| 5456 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5457 | aom_free(tile_ctxs); |
| 5458 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5459 | return; |
| 5460 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5461 | |
| 5462 | // Set default state for segment based loop filter update flags. |
| 5463 | cm->lf.mode_ref_delta_update = 0; |
| 5464 | |
| 5465 | if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search) |
| 5466 | cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi); |
| 5467 | |
| 5468 | // Set various flags etc to special state if it is a key frame. |
| 5469 | if (frame_is_intra_only(cm)) { |
| 5470 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5471 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5472 | |
| 5473 | // If segmentation is enabled force a map update for key frames. |
| 5474 | if (seg->enabled) { |
| 5475 | seg->update_map = 1; |
| 5476 | seg->update_data = 1; |
| 5477 | } |
| 5478 | |
| 5479 | // The alternate reference frame cannot be active for a key frame. |
| 5480 | cpi->rc.source_alt_ref_active = 0; |
| 5481 | |
| 5482 | cm->error_resilient_mode = oxcf->error_resilient_mode; |
| 5483 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 5484 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5485 | // By default, encoder assumes decoder can use prev_mi. |
| 5486 | if (cm->error_resilient_mode) { |
| 5487 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
| 5488 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 5489 | } else if (cm->intra_only) { |
| 5490 | // Only reset the current context. |
| 5491 | cm->reset_frame_context = RESET_FRAME_CONTEXT_CURRENT; |
| 5492 | } |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 5493 | #if CONFIG_EXT_TILE |
| 5494 | if (cpi->oxcf.large_scale_tile) |
| 5495 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 5496 | #endif // CONFIG_EXT_TILE |
| 5497 | #endif // !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5498 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5499 | if (cpi->oxcf.mtu == 0) { |
| 5500 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 5501 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 5502 | // Use a default value for the purposes of weighting costs in probability |
| 5503 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5504 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 5505 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5506 | |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 5507 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 5508 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 5509 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 5510 | #endif // CONFIG_EXT_TILE |
| 5511 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5512 | #if CONFIG_XIPHRC |
| 5513 | if (drop_this_frame) { |
| 5514 | av1_rc_postencode_update_drop_frame(cpi); |
| 5515 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5516 | aom_free(tile_ctxs); |
| 5517 | aom_free(cdf_ptrs); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5518 | return; |
| 5519 | } |
| 5520 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5521 | // For 1 pass CBR, check if we are dropping this frame. |
| 5522 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5523 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5524 | cm->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5525 | if (av1_rc_drop_frame(cpi)) { |
| 5526 | av1_rc_postencode_update_drop_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5527 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5528 | aom_free(tile_ctxs); |
| 5529 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5530 | return; |
| 5531 | } |
| 5532 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5533 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5534 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5535 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5536 | |
| 5537 | #if CONFIG_INTERNAL_STATS |
| 5538 | memset(cpi->mode_chosen_counts, 0, |
| 5539 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 5540 | #endif |
| 5541 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5542 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 5543 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5544 | /* Non-normative definition of current_frame_id ("frame counter" with |
| 5545 | * wraparound) */ |
Sebastien Alaiwan | d418f68 | 2017-10-19 15:06:52 +0200 | [diff] [blame] | 5546 | const int frame_id_length = FRAME_ID_LENGTH; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5547 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5548 | int lsb, msb; |
Arild Fuldseth (arilfuld) | bac17c1 | 2016-12-02 12:01:06 +0100 | [diff] [blame] | 5549 | /* quasi-random initialization of current_frame_id for a key frame */ |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5550 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5551 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 5552 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 5553 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5554 | } else { |
| 5555 | #endif |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5556 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 5557 | msb = cpi->source->y_buffer[1] & 0xff; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5558 | #if CONFIG_HIGHBITDEPTH |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5559 | } |
Arild Fuldseth (arilfuld) | bac17c1 | 2016-12-02 12:01:06 +0100 | [diff] [blame] | 5560 | #endif |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5561 | cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5562 | } else { |
| 5563 | cm->current_frame_id = |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5564 | (cm->current_frame_id + 1 + (1 << frame_id_length)) % |
| 5565 | (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5566 | } |
| 5567 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 5568 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5569 | |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 5570 | #if CONFIG_EXT_DELTA_Q |
| 5571 | cm->delta_q_present_flag = cpi->oxcf.deltaq_mode != NO_DELTA_Q; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 5572 | cm->delta_lf_present_flag = cpi->oxcf.deltaq_mode == DELTA_Q_LF; |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 5573 | #if CONFIG_LOOPFILTER_LEVEL |
| 5574 | cm->delta_lf_multi = DEFAULT_DELTA_LF_MULTI; |
| 5575 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 5576 | #endif |
| 5577 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5578 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 5579 | encode_without_recode_loop(cpi); |
| 5580 | } else { |
| 5581 | encode_with_recode_loop(cpi, size, dest); |
| 5582 | } |
| 5583 | |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5584 | cm->last_tile_cols = cm->tile_cols; |
| 5585 | cm->last_tile_rows = cm->tile_rows; |
| 5586 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5587 | #ifdef OUTPUT_YUV_SKINMAP |
| 5588 | if (cpi->common.current_video_frame > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5589 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5590 | } |
| 5591 | #endif // OUTPUT_YUV_SKINMAP |
| 5592 | |
| 5593 | // Special case code to reduce pulsing when key frames are forced at a |
| 5594 | // fixed interval. Note the reconstruction error if it is the frame before |
| 5595 | // the force key frame |
| 5596 | if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5597 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5598 | if (cm->use_highbitdepth) { |
| 5599 | cpi->ambient_err = |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5600 | aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5601 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5602 | 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] | 5603 | } |
| 5604 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5605 | cpi->ambient_err = aom_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5606 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5607 | } |
| 5608 | |
| 5609 | // If the encoder forced a KEY_FRAME decision |
| 5610 | if (cm->frame_type == KEY_FRAME) { |
| 5611 | cpi->refresh_last_frame = 1; |
| 5612 | } |
| 5613 | |
| 5614 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 5615 | cm->frame_to_show->color_space = cm->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 5616 | #if CONFIG_COLORSPACE_HEADERS |
| 5617 | cm->frame_to_show->transfer_function = cm->transfer_function; |
| 5618 | cm->frame_to_show->chroma_sample_position = cm->chroma_sample_position; |
| 5619 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5620 | cm->frame_to_show->color_range = cm->color_range; |
| 5621 | cm->frame_to_show->render_width = cm->render_width; |
| 5622 | cm->frame_to_show->render_height = cm->render_height; |
| 5623 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5624 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 5625 | // off. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5626 | |
| 5627 | // Pick the loop filter level for the frame. |
| 5628 | loopfilter_frame(cpi, cm); |
| 5629 | |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 5630 | #ifdef OUTPUT_YUV_REC |
| 5631 | aom_write_one_yuv_frame(cm, cm->frame_to_show); |
| 5632 | #endif |
| 5633 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5634 | // Build the bitstream |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5635 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5636 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5637 | if (skip_adapt) { |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5638 | aom_free(tile_ctxs); |
| 5639 | aom_free(cdf_ptrs); |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5640 | return; |
| 5641 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5642 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5643 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 5644 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5645 | int i; |
| 5646 | /* Update reference frame id values based on the value of refresh_mask */ |
| 5647 | for (i = 0; i < REF_FRAMES; i++) { |
| 5648 | if ((cm->refresh_mask >> i) & 1) { |
| 5649 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 5650 | } |
| 5651 | } |
| 5652 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 5653 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5654 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5655 | #if DUMP_RECON_FRAMES == 1 |
| 5656 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame] | 5657 | dump_filtered_recon_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5658 | #endif // DUMP_RECON_FRAMES |
| 5659 | |
| 5660 | if (cm->seg.update_map) update_reference_segmentation_map(cpi); |
| 5661 | |
| 5662 | if (frame_is_intra_only(cm) == 0) { |
| 5663 | release_scaled_references(cpi); |
| 5664 | } |
| 5665 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5666 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5667 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5668 | #if CONFIG_ENTROPY_STATS |
| 5669 | av1_accumulate_frame_counts(&aggregate_fc, &cm->counts); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 5670 | assert(cm->frame_context_idx < FRAME_CONTEXTS); |
| 5671 | av1_accumulate_frame_counts(&aggregate_fc_per_type[cm->frame_context_idx], |
| 5672 | &cm->counts); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5673 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5674 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5675 | av1_adapt_intra_frame_probs(cm); |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5676 | #if CONFIG_SIMPLE_BWD_ADAPT |
| 5677 | make_update_tile_list_enc(cpi, cm->largest_tile_id, 1, tile_ctxs); |
| 5678 | #else |
| 5679 | make_update_tile_list_enc(cpi, 0, num_bwd_ctxs, tile_ctxs); |
| 5680 | #endif |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5681 | av1_average_tile_coef_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5682 | num_bwd_ctxs); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5683 | av1_average_tile_intra_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5684 | num_bwd_ctxs); |
Debargha Mukherjee | 43061b3 | 2017-10-13 16:50:17 -0700 | [diff] [blame] | 5685 | av1_average_tile_loopfilter_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
| 5686 | num_bwd_ctxs); |
hui su | ff0da2b | 2017-03-07 15:51:37 -0800 | [diff] [blame] | 5687 | #if CONFIG_ADAPT_SCAN |
| 5688 | av1_adapt_scan_order(cm); |
| 5689 | #endif // CONFIG_ADAPT_SCAN |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5690 | } |
| 5691 | |
| 5692 | if (!frame_is_intra_only(cm)) { |
| 5693 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5694 | av1_adapt_inter_frame_probs(cm); |
| 5695 | av1_adapt_mv_probs(cm, cm->allow_high_precision_mv); |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5696 | av1_average_tile_inter_cdfs(&cpi->common, cpi->common.fc, tile_ctxs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5697 | cdf_ptrs, num_bwd_ctxs); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5698 | av1_average_tile_mv_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5699 | num_bwd_ctxs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | if (cpi->refresh_golden_frame == 1) |
| 5704 | cpi->frame_flags |= FRAMEFLAGS_GOLDEN; |
| 5705 | else |
| 5706 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 5707 | |
| 5708 | if (cpi->refresh_alt_ref_frame == 1) |
| 5709 | cpi->frame_flags |= FRAMEFLAGS_ALTREF; |
| 5710 | else |
| 5711 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 5712 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5713 | if (cpi->refresh_bwd_ref_frame == 1) |
| 5714 | cpi->frame_flags |= FRAMEFLAGS_BWDREF; |
| 5715 | else |
| 5716 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5717 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5718 | cm->last_frame_type = cm->frame_type; |
| 5719 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5720 | #if CONFIG_XIPHRC |
| 5721 | frame_type = cm->frame_type == KEY_FRAME ? OD_I_FRAME : OD_P_FRAME; |
| 5722 | |
| 5723 | drop_this_frame = |
| 5724 | od_enc_rc_update_state(&cpi->od_rc, *size << 3, cpi->refresh_golden_frame, |
| 5725 | cpi->refresh_alt_ref_frame, frame_type, 0); |
| 5726 | if (drop_this_frame) { |
| 5727 | av1_rc_postencode_update_drop_frame(cpi); |
| 5728 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5729 | aom_free(tile_ctxs); |
| 5730 | aom_free(cdf_ptrs); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5731 | return; |
| 5732 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5733 | #else // !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5734 | av1_rc_postencode_update(cpi, *size); |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5735 | #endif // CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5736 | |
| 5737 | #if 0 |
| 5738 | output_frame_level_debug_stats(cpi); |
| 5739 | #endif |
| 5740 | |
| 5741 | if (cm->frame_type == KEY_FRAME) { |
| 5742 | // Tell the caller that the frame was coded as a key frame |
| 5743 | *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY; |
| 5744 | } else { |
| 5745 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5746 | } |
| 5747 | |
| 5748 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 5749 | // filter deltas. |
| 5750 | cm->seg.update_map = 0; |
| 5751 | cm->seg.update_data = 0; |
| 5752 | cm->lf.mode_ref_delta_update = 0; |
| 5753 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5754 | if (cm->show_frame) { |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5755 | // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that are |
| 5756 | // being used as reference. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5757 | swap_mi_and_prev_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5758 | // Don't increment frame counters if this was an altref buffer |
| 5759 | // update not a real frame |
| 5760 | ++cm->current_video_frame; |
| 5761 | } |
| 5762 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5763 | // NOTE: Shall not refer to any frame not used as reference. |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5764 | if (cm->is_reference_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5765 | cm->prev_frame = cm->cur_frame; |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5766 | // keep track of the last coded dimensions |
| 5767 | cm->last_width = cm->width; |
| 5768 | cm->last_height = cm->height; |
| 5769 | |
| 5770 | // reset to normal state now that we are done. |
| 5771 | cm->last_show_frame = cm->show_frame; |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5772 | } |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5773 | |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5774 | aom_free(tile_ctxs); |
| 5775 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5776 | } |
| 5777 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5778 | static void Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5779 | int skip_adapt, unsigned int *frame_flags) { |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5780 | #if CONFIG_XIPHRC |
| 5781 | int64_t ip_count; |
| 5782 | int frame_type, is_golden, is_altref; |
| 5783 | |
| 5784 | /* Not updated during init so update it here */ |
| 5785 | if (cpi->oxcf.rc_mode == AOM_Q) cpi->od_rc.quality = cpi->oxcf.cq_level; |
| 5786 | |
| 5787 | frame_type = od_frame_type(&cpi->od_rc, cpi->od_rc.cur_frame, &is_golden, |
| 5788 | &is_altref, &ip_count); |
| 5789 | |
| 5790 | if (frame_type == OD_I_FRAME) { |
| 5791 | frame_type = KEY_FRAME; |
| 5792 | cpi->frame_flags &= FRAMEFLAGS_KEY; |
| 5793 | } else if (frame_type == OD_P_FRAME) { |
| 5794 | frame_type = INTER_FRAME; |
| 5795 | } |
| 5796 | |
| 5797 | if (is_altref) { |
| 5798 | cpi->refresh_alt_ref_frame = 1; |
| 5799 | cpi->rc.source_alt_ref_active = 1; |
| 5800 | } |
| 5801 | |
| 5802 | cpi->refresh_golden_frame = is_golden; |
| 5803 | cpi->common.frame_type = frame_type; |
| 5804 | if (is_golden) cpi->frame_flags &= FRAMEFLAGS_GOLDEN; |
| 5805 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5806 | if (cpi->oxcf.rc_mode == AOM_CBR) { |
| 5807 | av1_rc_get_one_pass_cbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5808 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5809 | av1_rc_get_one_pass_vbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5810 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5811 | #endif |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5812 | encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5813 | } |
| 5814 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5815 | #if !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5816 | static void Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5817 | unsigned int *frame_flags) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5818 | encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5819 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5820 | // Do not do post-encoding update for those frames that do not have a spot in |
| 5821 | // a gf group, but note that an OVERLAY frame always has a spot in a gf group, |
| 5822 | // even when show_existing_frame is used. |
| 5823 | 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] | 5824 | av1_twopass_postencode_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5825 | } |
| 5826 | check_show_existing_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5827 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5828 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5829 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 5830 | 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] | 5831 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 5832 | int64_t end_time) { |
| 5833 | AV1_COMMON *const cm = &cpi->common; |
| 5834 | struct aom_usec_timer timer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5835 | int res = 0; |
| 5836 | const int subsampling_x = sd->subsampling_x; |
| 5837 | const int subsampling_y = sd->subsampling_y; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5838 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5839 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
| 5840 | #endif |
| 5841 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5842 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5843 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
| 5844 | #else |
| 5845 | check_initial_width(cpi, subsampling_x, subsampling_y); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5846 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5847 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5848 | aom_usec_timer_start(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5849 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5850 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5851 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5852 | use_highbitdepth, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5853 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5854 | frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5855 | res = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5856 | aom_usec_timer_mark(&timer); |
| 5857 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5858 | |
| 5859 | if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && |
| 5860 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5861 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5862 | "Non-4:2:0 color format requires profile 1 or 3"); |
| 5863 | res = -1; |
| 5864 | } |
| 5865 | if ((cm->profile == PROFILE_1 || cm->profile == PROFILE_3) && |
| 5866 | (subsampling_x == 1 && subsampling_y == 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5867 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5868 | "4:2:0 color format requires profile 0 or 2"); |
| 5869 | res = -1; |
| 5870 | } |
| 5871 | |
| 5872 | return res; |
| 5873 | } |
| 5874 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5875 | static int frame_is_reference(const AV1_COMP *cpi) { |
| 5876 | const AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5877 | |
| 5878 | return cm->frame_type == KEY_FRAME || cpi->refresh_last_frame || |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5879 | cpi->refresh_golden_frame || cpi->refresh_bwd_ref_frame || |
| 5880 | cpi->refresh_alt2_ref_frame || cpi->refresh_alt_ref_frame || |
| 5881 | !cm->error_resilient_mode || cm->lf.mode_ref_delta_update || |
| 5882 | cm->seg.update_map || cm->seg.update_data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5883 | } |
| 5884 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5885 | static void adjust_frame_rate(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5886 | const struct lookahead_entry *source) { |
| 5887 | int64_t this_duration; |
| 5888 | int step = 0; |
| 5889 | |
| 5890 | if (source->ts_start == cpi->first_time_stamp_ever) { |
| 5891 | this_duration = source->ts_end - source->ts_start; |
| 5892 | step = 1; |
| 5893 | } else { |
| 5894 | int64_t last_duration = |
| 5895 | cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen; |
| 5896 | |
| 5897 | this_duration = source->ts_end - cpi->last_end_time_stamp_seen; |
| 5898 | |
| 5899 | // do a step update if the duration changes by 10% |
| 5900 | if (last_duration) |
| 5901 | step = (int)((this_duration - last_duration) * 10 / last_duration); |
| 5902 | } |
| 5903 | |
| 5904 | if (this_duration) { |
| 5905 | if (step) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5906 | av1_new_framerate(cpi, 10000000.0 / this_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5907 | } else { |
| 5908 | // Average this frame's rate into the last second's average |
| 5909 | // frame rate. If we haven't seen 1 second yet, then average |
| 5910 | // over the whole interval seen. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5911 | const double interval = AOMMIN( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5912 | (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0); |
| 5913 | double avg_duration = 10000000.0 / cpi->framerate; |
| 5914 | avg_duration *= (interval - avg_duration + this_duration); |
| 5915 | avg_duration /= interval; |
| 5916 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5917 | av1_new_framerate(cpi, 10000000.0 / avg_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5918 | } |
| 5919 | } |
| 5920 | cpi->last_time_stamp_seen = source->ts_start; |
| 5921 | cpi->last_end_time_stamp_seen = source->ts_end; |
| 5922 | } |
| 5923 | |
| 5924 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5925 | // used as the arf midpoint. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5926 | static int get_arf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5927 | RATE_CONTROL *const rc = &cpi->rc; |
| 5928 | int arf_src_index = 0; |
| 5929 | if (is_altref_enabled(cpi)) { |
| 5930 | if (cpi->oxcf.pass == 2) { |
| 5931 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5932 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 5933 | arf_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5934 | } |
| 5935 | } else if (rc->source_alt_ref_pending) { |
| 5936 | arf_src_index = rc->frames_till_gf_update_due; |
| 5937 | } |
| 5938 | } |
| 5939 | return arf_src_index; |
| 5940 | } |
| 5941 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5942 | static int get_brf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5943 | int brf_src_index = 0; |
| 5944 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5945 | |
| 5946 | // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup |
| 5947 | // flag. |
| 5948 | if (gf_group->bidir_pred_enabled[gf_group->index]) { |
| 5949 | if (cpi->oxcf.pass == 2) { |
| 5950 | if (gf_group->update_type[gf_group->index] == BRF_UPDATE) |
| 5951 | brf_src_index = gf_group->brf_src_offset[gf_group->index]; |
| 5952 | } else { |
| 5953 | // TODO(zoeliu): To re-visit the setup for this scenario |
| 5954 | brf_src_index = cpi->rc.bipred_group_interval - 1; |
| 5955 | } |
| 5956 | } |
| 5957 | |
| 5958 | return brf_src_index; |
| 5959 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5960 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5961 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5962 | // used as the arf midpoint. |
| 5963 | static int get_arf2_src_index(AV1_COMP *cpi) { |
| 5964 | int arf2_src_index = 0; |
| 5965 | if (is_altref_enabled(cpi) && cpi->num_extra_arfs) { |
| 5966 | if (cpi->oxcf.pass == 2) { |
| 5967 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5968 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) { |
| 5969 | arf2_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5970 | } |
| 5971 | } |
| 5972 | } |
| 5973 | return arf2_src_index; |
| 5974 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5975 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5976 | static void check_src_altref(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5977 | const struct lookahead_entry *source) { |
| 5978 | RATE_CONTROL *const rc = &cpi->rc; |
| 5979 | |
| 5980 | // If pass == 2, the parameters set here will be reset in |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5981 | // av1_rc_get_second_pass_params() |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5982 | |
| 5983 | if (cpi->oxcf.pass == 2) { |
| 5984 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5985 | rc->is_src_frame_alt_ref = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5986 | (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) || |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5987 | (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5988 | rc->is_src_frame_ext_arf = |
| 5989 | gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5990 | } else { |
| 5991 | rc->is_src_frame_alt_ref = |
| 5992 | cpi->alt_ref_source && (source == cpi->alt_ref_source); |
| 5993 | } |
| 5994 | |
| 5995 | if (rc->is_src_frame_alt_ref) { |
| 5996 | // Current frame is an ARF overlay frame. |
| 5997 | cpi->alt_ref_source = NULL; |
| 5998 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5999 | if (rc->is_src_frame_ext_arf && !cpi->common.show_existing_frame) { |
| 6000 | // For INTNL_OVERLAY, when show_existing_frame == 0, they do need to |
| 6001 | // refresh the LAST_FRAME, i.e. LAST3 gets retired, LAST2 becomes LAST3, |
| 6002 | // LAST becomes LAST2, and INTNL_OVERLAY becomes LAST. |
| 6003 | cpi->refresh_last_frame = 1; |
| 6004 | } else { |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6005 | // Don't refresh the last buffer for an ARF overlay frame. It will |
| 6006 | // become the GF so preserve last as an alternative prediction option. |
| 6007 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6008 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6009 | } |
| 6010 | } |
| 6011 | |
| 6012 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6013 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 6014 | const unsigned char *img2, int img2_pitch, |
| 6015 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6016 | |
| 6017 | static void adjust_image_stat(double y, double u, double v, double all, |
| 6018 | ImageStat *s) { |
| 6019 | s->stat[Y] += y; |
| 6020 | s->stat[U] += u; |
| 6021 | s->stat[V] += v; |
| 6022 | s->stat[ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6023 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6024 | } |
| 6025 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6026 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6027 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6028 | double samples = 0.0; |
| 6029 | uint32_t in_bit_depth = 8; |
| 6030 | uint32_t bit_depth = 8; |
| 6031 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6032 | #if CONFIG_INTER_STATS_ONLY |
Yaowu Xu | 1b4ffc4 | 2017-07-26 09:54:07 -0700 | [diff] [blame] | 6033 | if (cm->frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6034 | #endif |
| 6035 | cpi->bytes += frame_bytes; |
| 6036 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6037 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6038 | if (cm->use_highbitdepth) { |
| 6039 | in_bit_depth = cpi->oxcf.input_bit_depth; |
| 6040 | bit_depth = cm->bit_depth; |
| 6041 | } |
| 6042 | #endif |
| 6043 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6044 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6045 | const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; |
| 6046 | double y, u, v, frame_all; |
| 6047 | |
| 6048 | cpi->count++; |
| 6049 | if (cpi->b_calculate_psnr) { |
| 6050 | PSNR_STATS psnr; |
| 6051 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6052 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6053 | // TODO(yaowu): unify these two versions into one. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6054 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6055 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6056 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6057 | aom_calc_psnr(orig, recon, &psnr); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6058 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6059 | |
| 6060 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 6061 | &cpi->psnr); |
| 6062 | cpi->total_sq_error += psnr.sse[0]; |
| 6063 | cpi->total_samples += psnr.samples[0]; |
| 6064 | samples = psnr.samples[0]; |
| 6065 | // TODO(yaowu): unify these two versions into one. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6066 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6067 | if (cm->use_highbitdepth) |
| 6068 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6069 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6070 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6071 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6072 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6073 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6074 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6075 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6076 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6077 | cpi->summed_quality += frame_ssim2 * weight; |
| 6078 | cpi->summed_weights += weight; |
| 6079 | |
| 6080 | #if 0 |
| 6081 | { |
| 6082 | FILE *f = fopen("q_used.stt", "a"); |
| 6083 | fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", |
| 6084 | cpi->common.current_video_frame, y2, u2, v2, |
| 6085 | frame_psnr2, frame_ssim2); |
| 6086 | fclose(f); |
| 6087 | } |
| 6088 | #endif |
| 6089 | } |
| 6090 | if (cpi->b_calculate_blockiness) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6091 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6092 | if (!cm->use_highbitdepth) |
| 6093 | #endif |
| 6094 | { |
| 6095 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6096 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 6097 | recon->y_stride, orig->y_width, orig->y_height); |
| 6098 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6099 | cpi->total_blockiness += frame_blockiness; |
| 6100 | } |
| 6101 | |
| 6102 | if (cpi->b_calculate_consistency) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6103 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6104 | if (!cm->use_highbitdepth) |
| 6105 | #endif |
| 6106 | { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6107 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6108 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 6109 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 6110 | |
| 6111 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 6112 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6113 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6114 | if (consistency > 0.0) |
| 6115 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6116 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6117 | cpi->total_inconsistency += this_inconsistency; |
| 6118 | } |
| 6119 | } |
| 6120 | } |
| 6121 | |
| 6122 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6123 | 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] | 6124 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6125 | 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] | 6126 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 6127 | } |
| 6128 | } |
| 6129 | #endif // CONFIG_INTERNAL_STATS |
| 6130 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6131 | #if CONFIG_AMVR |
| 6132 | static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture, |
| 6133 | const YV12_BUFFER_CONFIG *last_picture, |
| 6134 | hash_table *last_hash_table) { |
| 6135 | aom_clear_system_state(); |
| 6136 | // check use hash ME |
| 6137 | int k; |
| 6138 | uint32_t hash_value_1; |
| 6139 | uint32_t hash_value_2; |
| 6140 | |
| 6141 | const int block_size = 8; |
| 6142 | const double threshold_current = 0.8; |
| 6143 | const double threshold_average = 0.95; |
| 6144 | const int max_history_size = 32; |
| 6145 | int T = 0; // total block |
| 6146 | int C = 0; // match with collocated block |
| 6147 | int S = 0; // smooth region but not match with collocated block |
| 6148 | int M = 0; // match with other block |
| 6149 | |
| 6150 | const int pic_width = cur_picture->y_width; |
| 6151 | const int pic_height = cur_picture->y_height; |
| 6152 | for (int i = 0; i + block_size <= pic_height; i += block_size) { |
| 6153 | for (int j = 0; j + block_size <= pic_width; j += block_size) { |
| 6154 | const int x_pos = j; |
| 6155 | const int y_pos = i; |
| 6156 | int match = 1; |
| 6157 | T++; |
| 6158 | |
| 6159 | // check whether collocated block match with current |
| 6160 | uint8_t *p_cur = cur_picture->y_buffer; |
| 6161 | uint8_t *p_ref = last_picture->y_buffer; |
| 6162 | int stride_cur = cur_picture->y_stride; |
| 6163 | int stride_ref = last_picture->y_stride; |
| 6164 | p_cur += (y_pos * stride_cur + x_pos); |
| 6165 | p_ref += (y_pos * stride_ref + x_pos); |
| 6166 | |
| 6167 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 6168 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 6169 | if (p_cur[tmpX] != p_ref[tmpX]) { |
| 6170 | match = 0; |
| 6171 | } |
| 6172 | } |
| 6173 | p_cur += stride_cur; |
| 6174 | p_ref += stride_ref; |
| 6175 | } |
| 6176 | |
| 6177 | if (match) { |
| 6178 | C++; |
| 6179 | continue; |
| 6180 | } |
| 6181 | |
| 6182 | if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos, |
| 6183 | y_pos) || |
| 6184 | av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) { |
| 6185 | S++; |
| 6186 | continue; |
| 6187 | } |
| 6188 | |
| 6189 | av1_get_block_hash_value( |
| 6190 | cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur, |
| 6191 | block_size, &hash_value_1, &hash_value_2); |
| 6192 | |
| 6193 | if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) { |
| 6194 | M++; |
| 6195 | } |
| 6196 | } |
| 6197 | } |
| 6198 | |
| 6199 | assert(T > 0); |
| 6200 | double csm_rate = ((double)(C + S + M)) / ((double)(T)); |
| 6201 | double m_rate = ((double)(M)) / ((double)(T)); |
| 6202 | |
| 6203 | cpi->csm_rate_array[cpi->rate_index] = csm_rate; |
| 6204 | cpi->m_rate_array[cpi->rate_index] = m_rate; |
| 6205 | |
| 6206 | cpi->rate_index = (cpi->rate_index + 1) % max_history_size; |
| 6207 | cpi->rate_size++; |
| 6208 | cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size); |
| 6209 | |
| 6210 | if (csm_rate < threshold_current) { |
| 6211 | return 0; |
| 6212 | } |
| 6213 | |
| 6214 | if (C == T) { |
| 6215 | return 1; |
| 6216 | } |
| 6217 | |
| 6218 | double csm_average = 0.0; |
| 6219 | double m_average = 0.0; |
| 6220 | |
| 6221 | for (k = 0; k < cpi->rate_size; k++) { |
| 6222 | csm_average += cpi->csm_rate_array[k]; |
| 6223 | m_average += cpi->m_rate_array[k]; |
| 6224 | } |
| 6225 | csm_average /= cpi->rate_size; |
| 6226 | m_average /= cpi->rate_size; |
| 6227 | |
| 6228 | if (csm_average < threshold_average) { |
| 6229 | return 0; |
| 6230 | } |
| 6231 | |
| 6232 | if (M > (T - C - S) / 3) { |
| 6233 | return 1; |
| 6234 | } |
| 6235 | |
| 6236 | if (csm_rate > 0.99 && m_rate > 0.01) { |
| 6237 | return 1; |
| 6238 | } |
| 6239 | |
| 6240 | if (csm_average + m_average > 1.01) { |
| 6241 | return 1; |
| 6242 | } |
| 6243 | |
| 6244 | return 0; |
| 6245 | } |
| 6246 | #endif |
| 6247 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6248 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 6249 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 6250 | int64_t *time_end, int flush) { |
| 6251 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 6252 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6253 | BufferPool *const pool = cm->buffer_pool; |
| 6254 | RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6255 | struct aom_usec_timer cmptimer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6256 | YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
| 6257 | struct lookahead_entry *last_source = NULL; |
| 6258 | struct lookahead_entry *source = NULL; |
| 6259 | int arf_src_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6260 | int brf_src_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6261 | int i; |
| 6262 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 6263 | #if CONFIG_XIPHRC |
| 6264 | cpi->od_rc.end_of_input = flush; |
| 6265 | #endif |
| 6266 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6267 | #if CONFIG_BITSTREAM_DEBUG |
| 6268 | assert(cpi->oxcf.max_threads == 0 && |
| 6269 | "bitstream debug tool does not support multithreading"); |
| 6270 | bitstream_queue_record_write(); |
Angie Chiang | cb9a9eb | 2016-09-01 16:10:50 -0700 | [diff] [blame] | 6271 | 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] | 6272 | #endif |
| 6273 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6274 | aom_usec_timer_start(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6275 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6276 | #if CONFIG_AMVR |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 6277 | #if CONFIG_EIGHTH_PEL_MV_ONLY |
| 6278 | set_high_precision_mv(cpi, 1, 0); |
| 6279 | #else |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6280 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 6281 | #endif // CONFIG_EIGHTH_PEL_MV_ONLY |
| 6282 | #else |
| 6283 | #if CONFIG_EIGHTH_PEL_MV_ONLY |
| 6284 | set_high_precision_mv(cpi, 1); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6285 | #else |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 6286 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 6287 | #endif // CONFIG_EIGHTH_PEL_MV_ONLY |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6288 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6289 | |
| 6290 | // Is multi-arf enabled. |
| 6291 | // Note that at the moment multi_arf is only configured for 2 pass VBR |
| 6292 | if ((oxcf->pass == 2) && (cpi->oxcf.enable_auto_arf > 1)) |
| 6293 | cpi->multi_arf_allowed = 1; |
| 6294 | else |
| 6295 | cpi->multi_arf_allowed = 0; |
| 6296 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 6297 | // Normal defaults |
| 6298 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6299 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 6300 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6301 | cm->refresh_frame_context = |
| 6302 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 6303 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 6304 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 6305 | #if CONFIG_EXT_TILE |
| 6306 | if (oxcf->large_scale_tile) |
| 6307 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 6308 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6309 | |
| 6310 | cpi->refresh_last_frame = 1; |
| 6311 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6312 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6313 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6314 | cpi->refresh_alt_ref_frame = 0; |
| 6315 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 6316 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6317 | if (oxcf->pass == 2 && cm->show_existing_frame) { |
| 6318 | // Manage the source buffer and flush out the source frame that has been |
| 6319 | // coded already; Also get prepared for PSNR calculation if needed. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6320 | if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6321 | *size = 0; |
| 6322 | return -1; |
| 6323 | } |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6324 | cpi->source = &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6325 | // TODO(zoeliu): To track down to determine whether it's needed to adjust |
| 6326 | // the frame rate. |
| 6327 | *time_stamp = source->ts_start; |
| 6328 | *time_end = source->ts_end; |
| 6329 | |
| 6330 | // We need to adjust frame rate for an overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 6331 | 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] | 6332 | |
| 6333 | // Find a free buffer for the new frame, releasing the reference previously |
| 6334 | // held. |
| 6335 | if (cm->new_fb_idx != INVALID_IDX) { |
| 6336 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 6337 | } |
| 6338 | cm->new_fb_idx = get_free_fb(cm); |
| 6339 | |
| 6340 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 6341 | |
| 6342 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6343 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6344 | |
| 6345 | // Start with a 0 size frame. |
| 6346 | *size = 0; |
| 6347 | |
| 6348 | // We need to update the gf_group for show_existing overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 6349 | 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] | 6350 | |
| 6351 | Pass2Encode(cpi, size, dest, frame_flags); |
| 6352 | |
| 6353 | if (cpi->b_calculate_psnr) generate_psnr_packet(cpi); |
| 6354 | |
| 6355 | #if CONFIG_INTERNAL_STATS |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6356 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6357 | #endif // CONFIG_INTERNAL_STATS |
| 6358 | |
| 6359 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6360 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6361 | |
| 6362 | cm->show_existing_frame = 0; |
| 6363 | return 0; |
| 6364 | } |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 6365 | #endif // !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6366 | |
| 6367 | // Should we encode an arf frame. |
| 6368 | arf_src_index = get_arf_src_index(cpi); |
| 6369 | if (arf_src_index) { |
| 6370 | for (i = 0; i <= arf_src_index; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6371 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6372 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 6373 | if (e == NULL) { |
| 6374 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6375 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6376 | arf_src_index = 0; |
| 6377 | flush = 1; |
| 6378 | break; |
| 6379 | } |
| 6380 | } |
| 6381 | } |
| 6382 | |
| 6383 | if (arf_src_index) { |
| 6384 | assert(arf_src_index <= rc->frames_to_key); |
| 6385 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6386 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6387 | cpi->alt_ref_source = source; |
| 6388 | |
| 6389 | if (oxcf->arnr_max_frames > 0) { |
Todd Nguyen | 302d097 | 2017-06-16 16:16:29 -0700 | [diff] [blame] | 6390 | // Produce the filtered ARF frame. |
| 6391 | #if CONFIG_BGSPRITE |
| 6392 | int bgsprite_ret = av1_background_sprite(cpi, arf_src_index); |
Todd Nguyen | 2fc2309 | 2017-07-11 12:00:36 -0700 | [diff] [blame] | 6393 | // Do temporal filter if bgsprite not generated. |
| 6394 | if (bgsprite_ret != 0) |
Todd Nguyen | 302d097 | 2017-06-16 16:16:29 -0700 | [diff] [blame] | 6395 | #endif // CONFIG_BGSPRITE |
Todd Nguyen | 8493f91 | 2017-07-20 12:45:12 -0700 | [diff] [blame] | 6396 | av1_temporal_filter(cpi, |
| 6397 | #if CONFIG_BGSPRITE |
Todd Nguyen | 1fd99c2 | 2017-07-31 17:50:41 -0700 | [diff] [blame] | 6398 | NULL, &cpi->alt_ref_buffer, |
Todd Nguyen | 8493f91 | 2017-07-20 12:45:12 -0700 | [diff] [blame] | 6399 | #endif // CONFIG_BGSPRITE |
| 6400 | arf_src_index); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6401 | aom_extend_frame_borders(&cpi->alt_ref_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6402 | force_src_buffer = &cpi->alt_ref_buffer; |
| 6403 | } |
| 6404 | |
| 6405 | cm->show_frame = 0; |
| 6406 | cm->intra_only = 0; |
| 6407 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6408 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6409 | cpi->refresh_golden_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6410 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6411 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6412 | rc->is_src_frame_alt_ref = 0; |
| 6413 | } |
| 6414 | rc->source_alt_ref_pending = 0; |
| 6415 | } |
| 6416 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6417 | // Should we encode an arf2 frame. |
| 6418 | arf_src_index = get_arf2_src_index(cpi); |
| 6419 | if (arf_src_index) { |
| 6420 | for (i = 0; i <= arf_src_index; ++i) { |
| 6421 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
| 6422 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 6423 | if (e == NULL) { |
| 6424 | break; |
| 6425 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
| 6426 | arf_src_index = 0; |
| 6427 | flush = 1; |
| 6428 | break; |
| 6429 | } |
| 6430 | } |
| 6431 | } |
| 6432 | |
| 6433 | if (arf_src_index) { |
| 6434 | assert(arf_src_index <= rc->frames_to_key); |
| 6435 | |
| 6436 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
| 6437 | cpi->alt_ref_source = source; |
| 6438 | |
| 6439 | if (oxcf->arnr_max_frames > 0) { |
| 6440 | // Produce the filtered ARF frame. |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 6441 | av1_temporal_filter(cpi, |
| 6442 | #if CONFIG_BGSPRITE |
| 6443 | NULL, NULL, |
| 6444 | #endif // CONFIG_BGSPRITE |
| 6445 | arf_src_index); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6446 | aom_extend_frame_borders(&cpi->alt_ref_buffer); |
| 6447 | force_src_buffer = &cpi->alt_ref_buffer; |
| 6448 | } |
| 6449 | |
| 6450 | cm->show_frame = 0; |
| 6451 | cm->intra_only = 0; |
| 6452 | cpi->refresh_alt2_ref_frame = 1; |
| 6453 | cpi->refresh_last_frame = 0; |
| 6454 | cpi->refresh_golden_frame = 0; |
| 6455 | cpi->refresh_bwd_ref_frame = 0; |
| 6456 | cpi->refresh_alt_ref_frame = 0; |
| 6457 | rc->is_src_frame_alt_ref = 0; |
| 6458 | rc->is_src_frame_ext_arf = 0; |
| 6459 | } |
| 6460 | rc->source_alt_ref_pending = 0; |
| 6461 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6462 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6463 | rc->is_bwd_ref_frame = 0; |
| 6464 | brf_src_index = get_brf_src_index(cpi); |
| 6465 | if (brf_src_index) { |
| 6466 | assert(brf_src_index <= rc->frames_to_key); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6467 | if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6468 | cm->show_frame = 0; |
| 6469 | cm->intra_only = 0; |
| 6470 | |
| 6471 | cpi->refresh_bwd_ref_frame = 1; |
| 6472 | cpi->refresh_last_frame = 0; |
| 6473 | cpi->refresh_golden_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6474 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6475 | cpi->refresh_alt_ref_frame = 0; |
| 6476 | |
| 6477 | rc->is_bwd_ref_frame = 1; |
| 6478 | } |
| 6479 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6480 | |
| 6481 | if (!source) { |
| 6482 | // Get last frame source. |
| 6483 | if (cm->current_video_frame > 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6484 | if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6485 | return -1; |
| 6486 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 6487 | if (cm->current_video_frame > 0) assert(last_source != NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6488 | // Read in the source frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6489 | source = av1_lookahead_pop(cpi->lookahead, flush); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6490 | |
| 6491 | if (source != NULL) { |
| 6492 | cm->show_frame = 1; |
| 6493 | cm->intra_only = 0; |
| 6494 | |
| 6495 | // Check to see if the frame should be encoded as an arf overlay. |
| 6496 | check_src_altref(cpi, source); |
| 6497 | } |
| 6498 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6499 | if (source) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 6500 | cpi->unscaled_source = cpi->source = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6501 | force_src_buffer ? force_src_buffer : &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6502 | cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL; |
| 6503 | |
| 6504 | *time_stamp = source->ts_start; |
| 6505 | *time_end = source->ts_end; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6506 | *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6507 | |
| 6508 | } else { |
| 6509 | *size = 0; |
| 6510 | if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6511 | #if CONFIG_XIPHRC |
| 6512 | od_enc_rc_2pass_out(&cpi->od_rc, cpi->output_pkt_list, 1); |
| 6513 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6514 | av1_end_first_pass(cpi); /* get last stats packet */ |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 6515 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6516 | cpi->twopass.first_pass_done = 1; |
| 6517 | } |
| 6518 | return -1; |
| 6519 | } |
| 6520 | |
| 6521 | if (source->ts_start < cpi->first_time_stamp_ever) { |
| 6522 | cpi->first_time_stamp_ever = source->ts_start; |
| 6523 | cpi->last_end_time_stamp_seen = source->ts_start; |
| 6524 | } |
| 6525 | |
| 6526 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6527 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6528 | |
| 6529 | // adjust frame rates based on timestamps given |
| 6530 | if (cm->show_frame) adjust_frame_rate(cpi, source); |
| 6531 | |
| 6532 | // Find a free buffer for the new frame, releasing the reference previously |
| 6533 | // held. |
| 6534 | if (cm->new_fb_idx != INVALID_IDX) { |
| 6535 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 6536 | } |
| 6537 | cm->new_fb_idx = get_free_fb(cm); |
| 6538 | |
| 6539 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 6540 | |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 6541 | #if CONFIG_FRAME_MARKER |
| 6542 | // Retain the RF_LEVEL for the current newly coded frame. |
| 6543 | cpi->frame_rf_level[cm->new_fb_idx] = |
| 6544 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index]; |
| 6545 | #endif // CONFIG_FRAME_MARKER |
| 6546 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6547 | cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 6548 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 6549 | cm->cur_frame->buf.buf_8bit_valid = 0; |
| 6550 | #endif |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 6551 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6552 | // Start with a 0 size frame. |
| 6553 | *size = 0; |
| 6554 | |
| 6555 | cpi->frame_flags = *frame_flags; |
| 6556 | |
| 6557 | if (oxcf->pass == 2) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6558 | #if CONFIG_XIPHRC |
| 6559 | if (od_enc_rc_2pass_in(&cpi->od_rc) < 0) return -1; |
| 6560 | } |
| 6561 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6562 | av1_rc_get_second_pass_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6563 | } else if (oxcf->pass == 1) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 6564 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6565 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6566 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6567 | |
| 6568 | if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) { |
| 6569 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) |
| 6570 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 6571 | } |
| 6572 | |
| 6573 | #if CONFIG_AOM_QM |
| 6574 | cm->using_qmatrix = cpi->oxcf.using_qm; |
| 6575 | cm->min_qmlevel = cpi->oxcf.qm_minlevel; |
| 6576 | cm->max_qmlevel = cpi->oxcf.qm_maxlevel; |
| 6577 | #endif |
| 6578 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6579 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 6580 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 6581 | if (*time_stamp == 0) { |
| 6582 | cpi->common.current_frame_id = -1; |
| 6583 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6584 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 6585 | #endif // CONFIG_REFERENCE_BUFFER |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6586 | #if CONFIG_AMVR |
| 6587 | cpi->cur_poc++; |
| 6588 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 6589 | if (cpi->common.seq_force_integer_mv == 2) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6590 | struct lookahead_entry *previous_entry = |
| 6591 | cpi->lookahead->buf + cpi->previsous_index; |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 6592 | cpi->common.cur_frame_force_integer_mv = is_integer_mv( |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6593 | cpi, cpi->source, &previous_entry->img, cpi->previsou_hash_table); |
| 6594 | } else { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 6595 | cpi->common.cur_frame_force_integer_mv = cpi->common.seq_force_integer_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6596 | } |
| 6597 | } else { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 6598 | cpi->common.cur_frame_force_integer_mv = 0; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6599 | } |
| 6600 | #endif |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6601 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6602 | #if CONFIG_XIPHRC |
| 6603 | if (oxcf->pass == 1) { |
| 6604 | size_t tmp; |
| 6605 | if (cpi->od_rc.cur_frame == 0) Pass0Encode(cpi, &tmp, dest, 1, frame_flags); |
| 6606 | cpi->od_rc.firstpass_quant = cpi->od_rc.target_quantizer; |
| 6607 | Pass0Encode(cpi, &tmp, dest, 0, frame_flags); |
| 6608 | od_enc_rc_2pass_out(&cpi->od_rc, cpi->output_pkt_list, 0); |
| 6609 | } else if (oxcf->pass == 2) { |
| 6610 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
| 6611 | } else { |
| 6612 | if (cpi->od_rc.cur_frame == 0) { |
| 6613 | size_t tmp; |
| 6614 | Pass0Encode(cpi, &tmp, dest, 1, frame_flags); |
| 6615 | } |
| 6616 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
| 6617 | } |
| 6618 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6619 | if (oxcf->pass == 1) { |
| 6620 | cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6621 | av1_first_pass(cpi, source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6622 | } else if (oxcf->pass == 2) { |
| 6623 | Pass2Encode(cpi, size, dest, frame_flags); |
| 6624 | } else { |
| 6625 | // One pass encode |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6626 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6627 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6628 | #endif |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 6629 | #if CONFIG_HASH_ME |
| 6630 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6631 | #if CONFIG_AMVR |
| 6632 | cpi->previsou_hash_table = &cm->cur_frame->hash_table; |
| 6633 | { |
| 6634 | int l; |
| 6635 | for (l = -MAX_PRE_FRAMES; l < cpi->lookahead->max_sz; l++) { |
| 6636 | if ((cpi->lookahead->buf + l) == source) { |
| 6637 | cpi->previsous_index = l; |
| 6638 | break; |
| 6639 | } |
| 6640 | } |
| 6641 | |
| 6642 | if (l == cpi->lookahead->max_sz) { |
| 6643 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 6644 | "Failed to find last frame original buffer"); |
| 6645 | } |
| 6646 | } |
| 6647 | #endif |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 6648 | } |
| 6649 | |
| 6650 | #endif |
| 6651 | |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame^] | 6652 | #if CONFIG_EXT_TILE |
| 6653 | if (!cm->large_scale_tile) { |
| 6654 | #endif // CONFIG_EXT_TILE |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 6655 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame^] | 6656 | cm->frame_contexts[cm->new_fb_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 6657 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6658 | if (!cm->error_resilient_mode) |
| 6659 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 6660 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yunqing Wang | 267e327 | 2017-11-09 14:23:22 -0800 | [diff] [blame^] | 6661 | #if CONFIG_EXT_TILE |
| 6662 | } |
| 6663 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6664 | |
| 6665 | // No frame encoded, or frame was dropped, release scaled references. |
| 6666 | if ((*size == 0) && (frame_is_intra_only(cm) == 0)) { |
| 6667 | release_scaled_references(cpi); |
| 6668 | } |
| 6669 | |
| 6670 | if (*size > 0) { |
| 6671 | cpi->droppable = !frame_is_reference(cpi); |
| 6672 | } |
| 6673 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6674 | aom_usec_timer_mark(&cmptimer); |
| 6675 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6676 | |
| 6677 | if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame) |
| 6678 | generate_psnr_packet(cpi); |
| 6679 | |
| 6680 | #if CONFIG_INTERNAL_STATS |
| 6681 | if (oxcf->pass != 1) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6682 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6683 | } |
| 6684 | #endif // CONFIG_INTERNAL_STATS |
| 6685 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 6686 | #if CONFIG_XIPHRC |
| 6687 | cpi->od_rc.cur_frame++; |
| 6688 | #endif |
| 6689 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6690 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6691 | |
| 6692 | return 0; |
| 6693 | } |
| 6694 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6695 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 6696 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6697 | if (!cm->show_frame) { |
| 6698 | return -1; |
| 6699 | } else { |
| 6700 | int ret; |
| 6701 | if (cm->frame_to_show) { |
| 6702 | *dest = *cm->frame_to_show; |
| 6703 | dest->y_width = cm->width; |
| 6704 | dest->y_height = cm->height; |
| 6705 | dest->uv_width = cm->width >> cm->subsampling_x; |
| 6706 | dest->uv_height = cm->height >> cm->subsampling_y; |
| 6707 | ret = 0; |
| 6708 | } else { |
| 6709 | ret = -1; |
| 6710 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6711 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6712 | return ret; |
| 6713 | } |
| 6714 | } |
| 6715 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6716 | 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] | 6717 | if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1; |
| 6718 | |
| 6719 | *frame = |
| 6720 | cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf; |
| 6721 | return 0; |
| 6722 | } |
| 6723 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6724 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 6725 | AOM_SCALING vert_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6726 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 6727 | |
| 6728 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 6729 | |
| 6730 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 6731 | Scale2Ratio(vert_mode, &vr, &vs); |
| 6732 | |
| 6733 | // always go to the next whole number |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 6734 | cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 6735 | cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6736 | |
| 6737 | return 0; |
| 6738 | } |
| 6739 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6740 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6741 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6742 | 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] | 6743 | // TODO(yunqingwang): For what references to use, external encoding flags |
| 6744 | // should be consistent with internal reference frame selection. Need to |
| 6745 | // ensure that there is not conflict between the two. In AV1 encoder, the |
| 6746 | // priority rank for 7 reference frames are: LAST, ALTREF, LAST2, LAST3, |
| 6747 | // GOLDEN, BWDREF, ALTREF2. If only one reference frame is used, it must be |
| 6748 | // LAST. |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 6749 | cpi->ext_ref_frame_flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6750 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6751 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 | |
| 6752 | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD | |
| 6753 | AOM_EFLAG_NO_REF_ARF2)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6754 | if (flags & AOM_EFLAG_NO_REF_LAST) { |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 6755 | cpi->ext_ref_frame_flags = 0; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6756 | } else { |
| 6757 | int ref = AOM_REFFRAME_ALL; |
| 6758 | |
| 6759 | if (flags & AOM_EFLAG_NO_REF_LAST2) ref ^= AOM_LAST2_FLAG; |
| 6760 | if (flags & AOM_EFLAG_NO_REF_LAST3) ref ^= AOM_LAST3_FLAG; |
| 6761 | |
| 6762 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
| 6763 | |
| 6764 | if (flags & AOM_EFLAG_NO_REF_ARF) { |
| 6765 | ref ^= AOM_ALT_FLAG; |
| 6766 | ref ^= AOM_BWD_FLAG; |
| 6767 | ref ^= AOM_ALT2_FLAG; |
| 6768 | } else { |
| 6769 | if (flags & AOM_EFLAG_NO_REF_BWD) ref ^= AOM_BWD_FLAG; |
| 6770 | if (flags & AOM_EFLAG_NO_REF_ARF2) ref ^= AOM_ALT2_FLAG; |
| 6771 | } |
| 6772 | |
| 6773 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6774 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6775 | } |
| 6776 | |
| 6777 | if (flags & |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6778 | (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] | 6779 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6780 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6781 | // Refreshing LAST/LAST2/LAST3 is handled by 1 common flag. |
| 6782 | if (flags & AOM_EFLAG_NO_UPD_LAST) upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6783 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6784 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6785 | |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 6786 | if (flags & AOM_EFLAG_NO_UPD_ARF) { |
| 6787 | upd ^= AOM_ALT_FLAG; |
| 6788 | upd ^= AOM_BWD_FLAG; |
| 6789 | upd ^= AOM_ALT2_FLAG; |
| 6790 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6791 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6792 | av1_update_reference(cpi, upd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6793 | } |
| 6794 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6795 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 6796 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6797 | } |
| 6798 | } |