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" |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 52 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 53 | #include "av1/common/ncobmc_kernels.h" |
| 54 | #endif // CONFIG_NCOBMC_ADAPT_WEIGHT |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 55 | #include "av1/encoder/picklpf.h" |
| 56 | #if CONFIG_LOOP_RESTORATION |
| 57 | #include "av1/encoder/pickrst.h" |
| 58 | #endif // CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 59 | #include "av1/encoder/random.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 60 | #include "av1/encoder/ratectrl.h" |
| 61 | #include "av1/encoder/rd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 62 | #include "av1/encoder/segmentation.h" |
| 63 | #include "av1/encoder/speed_features.h" |
| 64 | #include "av1/encoder/temporal_filter.h" |
| 65 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 66 | #include "./av1_rtcd.h" |
| 67 | #include "./aom_dsp_rtcd.h" |
| 68 | #include "./aom_scale_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 69 | #include "aom_dsp/psnr.h" |
| 70 | #if CONFIG_INTERNAL_STATS |
| 71 | #include "aom_dsp/ssim.h" |
| 72 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 73 | #include "aom_dsp/aom_dsp_common.h" |
| 74 | #include "aom_dsp/aom_filter.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 75 | #include "aom_ports/aom_timer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 76 | #include "aom_ports/mem.h" |
| 77 | #include "aom_ports/system_state.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 78 | #include "aom_scale/aom_scale.h" |
Angie Chiang | 6062a8b | 2016-09-21 16:01:04 -0700 | [diff] [blame] | 79 | #if CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 80 | #include "aom_util/debug_util.h" |
Angie Chiang | 6062a8b | 2016-09-21 16:01:04 -0700 | [diff] [blame] | 81 | #endif // CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 82 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 83 | #if CONFIG_ENTROPY_STATS |
| 84 | FRAME_COUNTS aggregate_fc; |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 85 | // Aggregate frame counts per frame context type |
| 86 | FRAME_COUNTS aggregate_fc_per_type[FRAME_CONTEXTS]; |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 87 | #endif // CONFIG_ENTROPY_STATS |
| 88 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 89 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 90 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 91 | |
| 92 | #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ |
| 93 | |
| 94 | #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv |
| 95 | // for altref computation. |
| 96 | #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision |
| 97 | // mv. Choose a very high value for |
| 98 | // now so that HIGH_PRECISION is always |
| 99 | // chosen. |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 100 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 101 | // #define OUTPUT_YUV_REC |
| 102 | #ifdef OUTPUT_YUV_DENOISED |
| 103 | FILE *yuv_denoised_file = NULL; |
| 104 | #endif |
| 105 | #ifdef OUTPUT_YUV_SKINMAP |
| 106 | FILE *yuv_skinmap_file = NULL; |
| 107 | #endif |
| 108 | #ifdef OUTPUT_YUV_REC |
| 109 | FILE *yuv_rec_file; |
| 110 | #define FILE_NAME_LEN 100 |
| 111 | #endif |
| 112 | |
| 113 | #if 0 |
| 114 | FILE *framepsnr; |
| 115 | FILE *kf_list; |
| 116 | FILE *keyfile; |
| 117 | #endif |
| 118 | |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 119 | #if CONFIG_CFL |
| 120 | CFL_CTX NULL_CFL; |
| 121 | #endif |
| 122 | |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 123 | #if CONFIG_INTERNAL_STATS |
| 124 | typedef enum { Y, U, V, ALL } STAT_TYPE; |
| 125 | #endif // CONFIG_INTERNAL_STATS |
| 126 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 127 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 128 | switch (mode) { |
| 129 | case NORMAL: |
| 130 | *hr = 1; |
| 131 | *hs = 1; |
| 132 | break; |
| 133 | case FOURFIVE: |
| 134 | *hr = 4; |
| 135 | *hs = 5; |
| 136 | break; |
| 137 | case THREEFIVE: |
| 138 | *hr = 3; |
| 139 | *hs = 5; |
| 140 | break; |
| 141 | case ONETWO: |
| 142 | *hr = 1; |
| 143 | *hs = 2; |
| 144 | break; |
| 145 | default: |
| 146 | *hr = 1; |
| 147 | *hs = 1; |
| 148 | assert(0); |
| 149 | break; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 154 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 155 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 156 | unsigned char *const seg_map = cpi->segmentation_map; |
| 157 | int i; |
| 158 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 159 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 160 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 161 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 162 | } |
| 163 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 164 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 165 | struct segmentation *const seg = &cpi->common.seg; |
| 166 | unsigned char *const seg_map = cpi->segmentation_map; |
| 167 | const unsigned char *const active_map = cpi->active_map.map; |
| 168 | int i; |
| 169 | |
| 170 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 171 | |
| 172 | if (frame_is_intra_only(&cpi->common)) { |
| 173 | cpi->active_map.enabled = 0; |
| 174 | cpi->active_map.update = 1; |
| 175 | } |
| 176 | |
| 177 | if (cpi->active_map.update) { |
| 178 | if (cpi->active_map.enabled) { |
| 179 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 180 | 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] | 181 | av1_enable_segmentation(seg); |
| 182 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 183 | #if CONFIG_LOOPFILTER_LEVEL |
| 184 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 185 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 186 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 187 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 188 | |
| 189 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H, |
| 190 | -MAX_LOOP_FILTER); |
| 191 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V, |
| 192 | -MAX_LOOP_FILTER); |
| 193 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U, |
| 194 | -MAX_LOOP_FILTER); |
| 195 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V, |
| 196 | -MAX_LOOP_FILTER); |
| 197 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 198 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 199 | // Setting the data to -MAX_LOOP_FILTER will result in the computed loop |
| 200 | // filter level being zero regardless of the value of seg->abs_delta. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 201 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF, |
| 202 | -MAX_LOOP_FILTER); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 203 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 204 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 205 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 206 | #if CONFIG_LOOPFILTER_LEVEL |
| 207 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 208 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 209 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 210 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 211 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 212 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 213 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 214 | if (seg->enabled) { |
| 215 | seg->update_data = 1; |
| 216 | seg->update_map = 1; |
| 217 | } |
| 218 | } |
| 219 | cpi->active_map.update = 0; |
| 220 | } |
| 221 | } |
| 222 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 223 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 224 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 225 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 226 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 227 | const int mi_rows = cpi->common.mi_rows; |
| 228 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 229 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 230 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 231 | cpi->active_map.update = 1; |
| 232 | if (new_map_16x16) { |
| 233 | int r, c; |
| 234 | for (r = 0; r < mi_rows; ++r) { |
| 235 | for (c = 0; c < mi_cols; ++c) { |
| 236 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 237 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 238 | ? AM_SEGMENT_ID_ACTIVE |
| 239 | : AM_SEGMENT_ID_INACTIVE; |
| 240 | } |
| 241 | } |
| 242 | cpi->active_map.enabled = 1; |
| 243 | } else { |
| 244 | cpi->active_map.enabled = 0; |
| 245 | } |
| 246 | return 0; |
| 247 | } else { |
| 248 | return -1; |
| 249 | } |
| 250 | } |
| 251 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 252 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 253 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 254 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 255 | new_map_16x16) { |
| 256 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 257 | const int mi_rows = cpi->common.mi_rows; |
| 258 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 259 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 260 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 261 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 262 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 263 | if (cpi->active_map.enabled) { |
| 264 | int r, c; |
| 265 | for (r = 0; r < mi_rows; ++r) { |
| 266 | for (c = 0; c < mi_cols; ++c) { |
| 267 | // Cyclic refresh segments are considered active despite not having |
| 268 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 269 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 270 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | return 0; |
| 275 | } else { |
| 276 | return -1; |
| 277 | } |
| 278 | } |
| 279 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 280 | static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv |
| 281 | #if CONFIG_AMVR |
| 282 | , |
| 283 | int cur_frame_mv_precision_level |
| 284 | #endif |
| 285 | ) { |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 286 | MACROBLOCK *const mb = &cpi->td.mb; |
| 287 | cpi->common.allow_high_precision_mv = allow_high_precision_mv; |
| 288 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 289 | #if CONFIG_AMVR |
| 290 | if (cpi->common.allow_high_precision_mv && |
| 291 | cur_frame_mv_precision_level == 0) { |
| 292 | #else |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 293 | if (cpi->common.allow_high_precision_mv) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 294 | #endif |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 295 | int i; |
| 296 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 297 | mb->mv_cost_stack[i] = mb->nmvcost_hp[i]; |
| 298 | } |
| 299 | } else { |
| 300 | int i; |
| 301 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 302 | mb->mv_cost_stack[i] = mb->nmvcost[i]; |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 307 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 308 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 309 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 310 | return BLOCK_64X64; |
| 311 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 312 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 313 | return BLOCK_128X128; |
| 314 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 315 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 316 | |
| 317 | assert(IMPLIES(cpi->common.tile_cols > 1, |
| 318 | cpi->common.tile_width % MAX_MIB_SIZE == 0)); |
| 319 | assert(IMPLIES(cpi->common.tile_rows > 1, |
| 320 | cpi->common.tile_height % MAX_MIB_SIZE == 0)); |
| 321 | |
| 322 | // TODO(any): Possibly could improve this with a heuristic. |
| 323 | return BLOCK_128X128; |
| 324 | #else |
| 325 | (void)cpi; |
| 326 | return BLOCK_64X64; |
| 327 | #endif // CONFIG_EXT_PARTITION |
| 328 | } |
| 329 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 330 | static void setup_frame(AV1_COMP *cpi) { |
| 331 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 332 | // Set up entropy context depending on frame type. The decoder mandates |
| 333 | // the use of the default context, index 0, for keyframes and inter |
| 334 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 335 | // other inter-frames the encoder currently uses only two contexts; |
| 336 | // context 1 for ALTREF frames and context 0 for the others. |
| 337 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 338 | av1_setup_past_independence(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 339 | } else { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 340 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 341 | // Just use frame context from first signaled reference frame. |
| 342 | // This will always be LAST_FRAME for now. |
| 343 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 344 | #if CONFIG_EXT_REFS |
| 345 | const GF_GROUP *gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 346 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 347 | cm->frame_context_idx = EXT_ARF_FRAME; |
| 348 | else if (cpi->refresh_alt_ref_frame) |
| 349 | cm->frame_context_idx = ARF_FRAME; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 350 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 351 | if (cpi->refresh_alt_ref_frame) cm->frame_context_idx = ARF_FRAME; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 352 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 353 | else if (cpi->rc.is_src_frame_alt_ref) |
| 354 | cm->frame_context_idx = OVERLAY_FRAME; |
| 355 | else if (cpi->refresh_golden_frame) |
| 356 | cm->frame_context_idx = GLD_FRAME; |
| 357 | #if CONFIG_EXT_REFS |
| 358 | else if (cpi->refresh_bwd_ref_frame) |
| 359 | cm->frame_context_idx = BRF_FRAME; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 360 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 361 | else |
| 362 | cm->frame_context_idx = REGULAR_FRAME; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 363 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | if (cm->frame_type == KEY_FRAME) { |
| 367 | cpi->refresh_golden_frame = 1; |
| 368 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 369 | av1_zero(cpi->interp_filter_selected); |
Debargha Mukherjee | d2630fa | 2017-09-22 10:32:51 -0700 | [diff] [blame] | 370 | set_sb_size(cm, select_sb_size(cpi)); |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 371 | #if CONFIG_REFERENCE_BUFFER |
| 372 | set_use_reference_buffer(cm, 0); |
| 373 | #endif // CONFIG_REFERENCE_BUFFER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 374 | } else { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 375 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 376 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
| 377 | cm->frame_refs[0].idx < 0) { |
| 378 | *cm->fc = cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 379 | } else { |
| 380 | *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx]; |
| 381 | } |
| 382 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 383 | *cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 384 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 385 | av1_zero(cpi->interp_filter_selected[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 386 | } |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 387 | #if CONFIG_EXT_REFS |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 388 | #if CONFIG_ONE_SIDED_COMPOUND && \ |
| 389 | !CONFIG_EXT_COMP_REFS // No change to bitstream |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 390 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 391 | cpi->refresh_bwd_ref_frame = cpi->refresh_last_frame; |
| 392 | cpi->rc.is_bipred_frame = 1; |
| 393 | } |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 394 | #endif // CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
| 395 | #endif // CONFIG_EXT_REFS |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 396 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 397 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
| 398 | cm->frame_refs[0].idx < 0) { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 399 | // use default frame context values |
| 400 | cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 401 | } else { |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 402 | *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 403 | cm->pre_fc = &cm->frame_contexts[cm->frame_refs[0].idx]; |
| 404 | } |
| 405 | #else |
Thomas Daede | 10e1da9 | 2017-04-26 13:22:21 -0700 | [diff] [blame] | 406 | cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 407 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 408 | |
| 409 | cpi->vaq_refresh = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 412 | static void enc_setup_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 413 | int i; |
| 414 | cm->mi = cm->mip + cm->mi_stride + 1; |
| 415 | memset(cm->mip, 0, cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip)); |
| 416 | cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 417 | // Clear top border row |
| 418 | memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride); |
| 419 | // Clear left border column |
| 420 | for (i = 1; i < cm->mi_rows + 1; ++i) |
| 421 | 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] | 422 | cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; |
| 423 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; |
| 424 | |
| 425 | memset(cm->mi_grid_base, 0, |
| 426 | cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mi_grid_base)); |
| 427 | } |
| 428 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 429 | static int enc_alloc_mi(AV1_COMMON *cm, int mi_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 430 | cm->mip = aom_calloc(mi_size, sizeof(*cm->mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 431 | if (!cm->mip) return 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 432 | cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 433 | if (!cm->prev_mip) return 1; |
| 434 | cm->mi_alloc_size = mi_size; |
| 435 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 436 | 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] | 437 | if (!cm->mi_grid_base) return 1; |
| 438 | cm->prev_mi_grid_base = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 439 | (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 440 | if (!cm->prev_mi_grid_base) return 1; |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 445 | static void enc_free_mi(AV1_COMMON *cm) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 446 | aom_free(cm->mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 447 | cm->mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 448 | aom_free(cm->prev_mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 449 | cm->prev_mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 450 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 451 | cm->mi_grid_base = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 452 | aom_free(cm->prev_mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 453 | cm->prev_mi_grid_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 454 | cm->mi_alloc_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 457 | static void swap_mi_and_prev_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 458 | // Current mip will be the prev_mip for the next frame. |
| 459 | MODE_INFO **temp_base = cm->prev_mi_grid_base; |
| 460 | MODE_INFO *temp = cm->prev_mip; |
| 461 | cm->prev_mip = cm->mip; |
| 462 | cm->mip = temp; |
| 463 | |
| 464 | // Update the upper left visible macroblock ptrs. |
| 465 | cm->mi = cm->mip + cm->mi_stride + 1; |
| 466 | cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 467 | |
| 468 | cm->prev_mi_grid_base = cm->mi_grid_base; |
| 469 | cm->mi_grid_base = temp_base; |
| 470 | cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; |
| 471 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; |
| 472 | } |
| 473 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 474 | void av1_initialize_enc(void) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 475 | static volatile int init_done = 0; |
| 476 | |
| 477 | if (!init_done) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 478 | av1_rtcd(); |
| 479 | aom_dsp_rtcd(); |
| 480 | aom_scale_rtcd(); |
| 481 | av1_init_intra_predictors(); |
| 482 | av1_init_me_luts(); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 483 | #if !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 484 | av1_rc_init_minq_luts(); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 485 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 486 | av1_entropy_mv_init(); |
| 487 | av1_encode_token_init(); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 488 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 489 | init_done = 1; |
| 490 | } |
| 491 | } |
| 492 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 493 | static void dealloc_context_buffers_ext(AV1_COMP *cpi) { |
| 494 | if (cpi->mbmi_ext_base) { |
| 495 | aom_free(cpi->mbmi_ext_base); |
| 496 | cpi->mbmi_ext_base = NULL; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
| 501 | AV1_COMMON *cm = &cpi->common; |
| 502 | int mi_size = cm->mi_cols * cm->mi_rows; |
| 503 | |
| 504 | dealloc_context_buffers_ext(cpi); |
| 505 | CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, |
| 506 | aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); |
| 507 | } |
| 508 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 509 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 510 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 511 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 512 | dealloc_context_buffers_ext(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 513 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 514 | #if CONFIG_PVQ |
| 515 | if (cpi->oxcf.pass != 1) { |
Yushin Cho | 749c057 | 2017-04-07 10:36:47 -0700 | [diff] [blame] | 516 | const int tile_cols = cm->tile_cols; |
| 517 | const int tile_rows = cm->tile_rows; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 518 | int tile_col, tile_row; |
| 519 | |
| 520 | for (tile_row = 0; tile_row < tile_rows; ++tile_row) |
| 521 | for (tile_col = 0; tile_col < tile_cols; ++tile_col) { |
| 522 | TileDataEnc *tile_data = |
| 523 | &cpi->tile_data[tile_row * tile_cols + tile_col]; |
| 524 | aom_free(tile_data->pvq_q.buf); |
| 525 | } |
| 526 | } |
| 527 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 528 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 529 | cpi->tile_data = NULL; |
| 530 | |
| 531 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 532 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 533 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 534 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 535 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 536 | cpi->cyclic_refresh = NULL; |
| 537 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 538 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 539 | cpi->active_map.map = NULL; |
| 540 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 541 | #if CONFIG_MOTION_VAR |
| 542 | aom_free(cpi->td.mb.above_pred_buf); |
| 543 | cpi->td.mb.above_pred_buf = NULL; |
| 544 | |
| 545 | aom_free(cpi->td.mb.left_pred_buf); |
| 546 | cpi->td.mb.left_pred_buf = NULL; |
| 547 | |
| 548 | aom_free(cpi->td.mb.wsrc_buf); |
| 549 | cpi->td.mb.wsrc_buf = NULL; |
| 550 | |
| 551 | aom_free(cpi->td.mb.mask_buf); |
| 552 | cpi->td.mb.mask_buf = NULL; |
| 553 | #endif |
| 554 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 555 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 556 | #if CONFIG_LV_MAP |
| 557 | av1_free_txb_buf(cpi); |
| 558 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 559 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 560 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 561 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 562 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 563 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 564 | aom_free_frame_buffer(&cpi->last_frame_db); |
| 565 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
| 566 | aom_free(cpi->extra_rstbuf); |
Timothy B. Terriberry | 5d24b6f | 2017-06-15 13:39:35 -0700 | [diff] [blame] | 567 | { |
| 568 | int i; |
| 569 | for (i = 0; i < MAX_MB_PLANE; ++i) |
| 570 | av1_free_restoration_struct(&cpi->rst_search[i]); |
| 571 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 572 | #endif // CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 573 | aom_free_frame_buffer(&cpi->scaled_source); |
| 574 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 575 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 576 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 577 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 578 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 579 | cpi->tile_tok[0][0] = 0; |
| 580 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 581 | av1_free_pc_tree(&cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 582 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 583 | aom_free(cpi->td.mb.palette_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 584 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 585 | #if CONFIG_ANS |
Alex Converse | 1ac1ae7 | 2016-09-17 15:11:16 -0700 | [diff] [blame] | 586 | aom_buf_ans_free(&cpi->buf_ans); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 587 | #endif // CONFIG_ANS |
| 588 | } |
| 589 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 590 | static void save_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 591 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 592 | AV1_COMMON *cm = &cpi->common; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 593 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 594 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 595 | // Stores a snapshot of key state variables which can subsequently be |
| 596 | // restored with a call to av1_restore_coding_context. These functions are |
| 597 | // intended for use in a re-code loop in av1_compress_frame where the |
| 598 | // quantizer value is adjusted between loop iterations. |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 599 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 600 | av1_copy(cc->nmv_vec_cost[i], cpi->td.mb.nmv_vec_cost[i]); |
| 601 | av1_copy(cc->nmv_costs, cpi->nmv_costs); |
| 602 | av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp); |
| 603 | } |
| 604 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 605 | av1_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); |
| 606 | av1_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 607 | |
| 608 | cc->fc = *cm->fc; |
| 609 | } |
| 610 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 611 | static void restore_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 612 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 613 | AV1_COMMON *cm = &cpi->common; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 614 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 615 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 616 | // Restore key state variables to the snapshot state stored in the |
| 617 | // previous call to av1_save_coding_context. |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 618 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 619 | av1_copy(cpi->td.mb.nmv_vec_cost[i], cc->nmv_vec_cost[i]); |
| 620 | av1_copy(cpi->nmv_costs, cc->nmv_costs); |
| 621 | av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp); |
| 622 | } |
| 623 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 624 | av1_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); |
| 625 | av1_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 626 | |
| 627 | *cm->fc = cc->fc; |
| 628 | } |
| 629 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 630 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 631 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 632 | const RATE_CONTROL *const rc = &cpi->rc; |
| 633 | struct segmentation *const seg = &cm->seg; |
| 634 | |
| 635 | int high_q = (int)(rc->avg_q > 48.0); |
| 636 | int qi_delta; |
| 637 | |
| 638 | // Disable and clear down for KF |
| 639 | if (cm->frame_type == KEY_FRAME) { |
| 640 | // Clear down the global segmentation map |
| 641 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 642 | seg->update_map = 0; |
| 643 | seg->update_data = 0; |
| 644 | cpi->static_mb_pct = 0; |
| 645 | |
| 646 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 647 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 648 | |
| 649 | // Clear down the segment features. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 650 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 651 | } else if (cpi->refresh_alt_ref_frame) { |
| 652 | // If this is an alt ref frame |
| 653 | // Clear down the global segmentation map |
| 654 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 655 | seg->update_map = 0; |
| 656 | seg->update_data = 0; |
| 657 | cpi->static_mb_pct = 0; |
| 658 | |
| 659 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 660 | av1_disable_segmentation(seg); |
| 661 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 662 | |
| 663 | // Scan frames from current to arf frame. |
| 664 | // This function re-enables segmentation if appropriate. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 665 | av1_update_mbgraph_stats(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 666 | |
| 667 | // If segmentation was enabled set those features needed for the |
| 668 | // arf itself. |
| 669 | if (seg->enabled) { |
| 670 | seg->update_map = 1; |
| 671 | seg->update_data = 1; |
| 672 | |
| 673 | qi_delta = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 674 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, cm->bit_depth); |
| 675 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 676 | #if CONFIG_LOOPFILTER_LEVEL |
| 677 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 678 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 679 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 680 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 681 | |
| 682 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 683 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 684 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 685 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
| 686 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 687 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 688 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
| 689 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 690 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 691 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 692 | |
| 693 | // Where relevant assume segment data is delta data |
| 694 | seg->abs_delta = SEGMENT_DELTADATA; |
| 695 | } |
| 696 | } else if (seg->enabled) { |
| 697 | // All other frames if segmentation has been enabled |
| 698 | |
| 699 | // First normal frame in a valid gf or alt ref group |
| 700 | if (rc->frames_since_golden == 0) { |
| 701 | // Set up segment features for normal frames in an arf group |
| 702 | if (rc->source_alt_ref_active) { |
| 703 | seg->update_map = 0; |
| 704 | seg->update_data = 1; |
| 705 | seg->abs_delta = SEGMENT_DELTADATA; |
| 706 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 707 | qi_delta = |
| 708 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, cm->bit_depth); |
| 709 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 710 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 711 | |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 712 | #if CONFIG_LOOPFILTER_LEVEL |
| 713 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 714 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 715 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 716 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 717 | |
| 718 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 719 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 720 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 721 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
| 722 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 723 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
| 724 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 725 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 726 | |
| 727 | // Segment coding disabled for compred testing |
| 728 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 729 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 730 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 731 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 732 | } |
| 733 | } else { |
| 734 | // Disable segmentation and clear down features if alt ref |
| 735 | // is not active for this group |
| 736 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 737 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 738 | |
| 739 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 740 | |
| 741 | seg->update_map = 0; |
| 742 | seg->update_data = 0; |
| 743 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 744 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 745 | } |
| 746 | } else if (rc->is_src_frame_alt_ref) { |
| 747 | // Special case where we are coding over the top of a previous |
| 748 | // alt ref frame. |
| 749 | // Segment coding disabled for compred testing |
| 750 | |
| 751 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 752 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 753 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 754 | |
| 755 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 756 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 757 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 758 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 759 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 760 | |
| 761 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 762 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 763 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 764 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 765 | } |
| 766 | // Enable data update |
| 767 | seg->update_data = 1; |
| 768 | } else { |
| 769 | // All other frames. |
| 770 | |
| 771 | // No updates.. leave things as they are. |
| 772 | seg->update_map = 0; |
| 773 | seg->update_data = 0; |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 778 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 779 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 780 | MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible; |
| 781 | uint8_t *cache_ptr = cm->last_frame_seg_map; |
| 782 | int row, col; |
| 783 | |
| 784 | for (row = 0; row < cm->mi_rows; row++) { |
| 785 | MODE_INFO **mi_8x8 = mi_8x8_ptr; |
| 786 | uint8_t *cache = cache_ptr; |
| 787 | for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) |
| 788 | cache[0] = mi_8x8[0]->mbmi.segment_id; |
| 789 | mi_8x8_ptr += cm->mi_stride; |
| 790 | cache_ptr += cm->mi_cols; |
| 791 | } |
| 792 | } |
| 793 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 794 | static void alloc_raw_frame_buffers(AV1_COMP *cpi) { |
| 795 | AV1_COMMON *cm = &cpi->common; |
| 796 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 797 | |
| 798 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 799 | cpi->lookahead = av1_lookahead_init(oxcf->width, oxcf->height, |
| 800 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 801 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 802 | cm->use_highbitdepth, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 803 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 804 | oxcf->lag_in_frames); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 805 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 806 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 807 | "Failed to allocate lag buffers"); |
| 808 | |
| 809 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 810 | 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] | 811 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 812 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 813 | cm->use_highbitdepth, |
| 814 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 815 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 816 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 817 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 818 | "Failed to allocate altref buffer"); |
| 819 | } |
| 820 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 821 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 822 | AV1_COMMON *const cm = &cpi->common; |
| 823 | 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] | 824 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 825 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 826 | cm->use_highbitdepth, |
| 827 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 828 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 829 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 830 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 831 | "Failed to allocate last frame buffer"); |
| 832 | |
| 833 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 834 | if (aom_realloc_frame_buffer(&cpi->last_frame_db, cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 835 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 836 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 837 | cm->use_highbitdepth, |
| 838 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 839 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 840 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 841 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 842 | "Failed to allocate last frame deblocked buffer"); |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 843 | if (aom_realloc_frame_buffer( |
| 844 | &cpi->trial_frame_rst, |
| 845 | #if CONFIG_FRAME_SUPERRES |
| 846 | cm->superres_upscaled_width, cm->superres_upscaled_height, |
| 847 | #else |
| 848 | cm->width, cm->height, |
| 849 | #endif // CONFIG_FRAME_SUPERRES |
| 850 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 851 | #if CONFIG_HIGHBITDEPTH |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 852 | cm->use_highbitdepth, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 853 | #endif |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 854 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 855 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 856 | "Failed to allocate trial restored frame buffer"); |
Alex Converse | 232e384 | 2017-02-24 12:24:36 -0800 | [diff] [blame] | 857 | int extra_rstbuf_sz = RESTORATION_EXTBUF_SIZE; |
Debargha Mukherjee | b3c43bc | 2017-02-01 13:09:03 -0800 | [diff] [blame] | 858 | if (extra_rstbuf_sz > 0) { |
Alex Converse | 7f094f1 | 2017-02-23 17:29:40 -0800 | [diff] [blame] | 859 | aom_free(cpi->extra_rstbuf); |
Alex Converse | 232e384 | 2017-02-24 12:24:36 -0800 | [diff] [blame] | 860 | CHECK_MEM_ERROR(cm, cpi->extra_rstbuf, |
Alex Converse | 7f094f1 | 2017-02-23 17:29:40 -0800 | [diff] [blame] | 861 | (uint8_t *)aom_malloc(extra_rstbuf_sz)); |
Debargha Mukherjee | b3c43bc | 2017-02-01 13:09:03 -0800 | [diff] [blame] | 862 | } else { |
| 863 | cpi->extra_rstbuf = NULL; |
| 864 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 865 | #endif // CONFIG_LOOP_RESTORATION |
| 866 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 867 | if (aom_realloc_frame_buffer(&cpi->scaled_source, cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 868 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 869 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 870 | cm->use_highbitdepth, |
| 871 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 872 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 873 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 874 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 875 | "Failed to allocate scaled source buffer"); |
| 876 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 877 | 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] | 878 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 879 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 880 | cm->use_highbitdepth, |
| 881 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 882 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 883 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 884 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 885 | "Failed to allocate scaled last source buffer"); |
| 886 | } |
| 887 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 888 | static void alloc_compressor_data(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 889 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 890 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 891 | av1_alloc_context_buffers(cm, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 892 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 893 | #if CONFIG_LV_MAP |
| 894 | av1_alloc_txb_buf(cpi); |
| 895 | #endif |
| 896 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 897 | alloc_context_buffers_ext(cpi); |
| 898 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 899 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 900 | |
| 901 | { |
| 902 | unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols); |
| 903 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 904 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 907 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 908 | } |
| 909 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 910 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 911 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 912 | #if CONFIG_XIPHRC |
| 913 | if (!cpi->od_rc.cur_frame) return; |
| 914 | cpi->od_rc.framerate = cpi->framerate; |
| 915 | od_enc_rc_resize(&cpi->od_rc); |
| 916 | #else |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 917 | av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 918 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 921 | #if CONFIG_MAX_TILE |
| 922 | |
| 923 | static void set_tile_info_max_tile(AV1_COMP *cpi) { |
| 924 | AV1_COMMON *const cm = &cpi->common; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 925 | int i, start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 926 | |
| 927 | av1_get_tile_limits(cm); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 928 | |
| 929 | // configure tile columns |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 930 | 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] | 931 | cm->uniform_tile_spacing_flag = 1; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 932 | cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols); |
| 933 | 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] | 934 | } else { |
| 935 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); |
| 936 | int sb_cols = mi_cols >> MAX_MIB_SIZE_LOG2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 937 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 938 | cm->uniform_tile_spacing_flag = 0; |
| 939 | for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) { |
| 940 | cm->tile_col_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 941 | size_sb = cpi->oxcf.tile_widths[j++]; |
| 942 | if (j >= cpi->oxcf.tile_width_count) j = 0; |
| 943 | start_sb += AOMMIN(size_sb, MAX_TILE_WIDTH_SB); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 944 | } |
| 945 | cm->tile_cols = i; |
| 946 | cm->tile_col_start_sb[i] = sb_cols; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 947 | } |
| 948 | av1_calculate_tile_cols(cm); |
| 949 | |
| 950 | // configure tile rows |
| 951 | if (cm->uniform_tile_spacing_flag) { |
| 952 | cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows); |
| 953 | 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] | 954 | } else { |
| 955 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); |
| 956 | int sb_rows = mi_rows >> MAX_MIB_SIZE_LOG2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 957 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 958 | for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) { |
| 959 | cm->tile_row_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 960 | size_sb = cpi->oxcf.tile_heights[j++]; |
| 961 | if (j >= cpi->oxcf.tile_height_count) j = 0; |
| 962 | start_sb += AOMMIN(size_sb, cm->max_tile_height_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 963 | } |
| 964 | cm->tile_rows = i; |
| 965 | cm->tile_row_start_sb[i] = sb_rows; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 966 | } |
| 967 | av1_calculate_tile_rows(cm); |
| 968 | } |
| 969 | |
| 970 | #endif |
| 971 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 972 | static void set_tile_info(AV1_COMP *cpi) { |
| 973 | AV1_COMMON *const cm = &cpi->common; |
Thomas Davies | b25ba50 | 2017-07-18 10:18:24 +0100 | [diff] [blame] | 974 | #if CONFIG_DEPENDENT_HORZTILES |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 975 | int tile_row, tile_col, num_tiles_in_tg; |
| 976 | int tg_row_start, tg_col_start; |
| 977 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 978 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 979 | if (cpi->oxcf.large_scale_tile) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 980 | #if CONFIG_EXT_PARTITION |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 981 | if (cpi->oxcf.superblock_size != AOM_SUPERBLOCK_SIZE_64X64) { |
| 982 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 32); |
| 983 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 32); |
| 984 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 985 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
| 986 | } else { |
| 987 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 988 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
| 989 | cm->tile_width <<= MAX_MIB_SIZE_LOG2 - 1; |
| 990 | cm->tile_height <<= MAX_MIB_SIZE_LOG2 - 1; |
| 991 | } |
| 992 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 993 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 994 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 995 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 996 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 997 | #endif // CONFIG_EXT_PARTITION |
| 998 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 999 | cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols); |
| 1000 | cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1001 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1002 | assert(cm->tile_width >> MAX_MIB_SIZE <= 32); |
| 1003 | assert(cm->tile_height >> MAX_MIB_SIZE <= 32); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1004 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1005 | // Get the number of tiles |
| 1006 | cm->tile_cols = 1; |
| 1007 | 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] | 1008 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1009 | cm->tile_rows = 1; |
| 1010 | while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows; |
| 1011 | } else { |
| 1012 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1013 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1014 | #if CONFIG_MAX_TILE |
| 1015 | set_tile_info_max_tile(cpi); |
| 1016 | #else |
| 1017 | int min_log2_tile_cols, max_log2_tile_cols; |
| 1018 | 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] | 1019 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1020 | cm->log2_tile_cols = |
| 1021 | clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols); |
| 1022 | cm->log2_tile_rows = cpi->oxcf.tile_rows; |
Rupert Swarbrick | 940942b | 2017-09-01 12:05:55 +0100 | [diff] [blame] | 1023 | |
Rupert Swarbrick | 5a010aa | 2017-09-26 16:16:48 +0100 | [diff] [blame] | 1024 | cm->tile_width = |
| 1025 | get_tile_size(cm->mi_cols, cm->log2_tile_cols, &cm->tile_cols); |
| 1026 | cm->tile_height = |
| 1027 | 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] | 1028 | #endif // CONFIG_MAX_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1029 | #if CONFIG_EXT_TILE |
| 1030 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1031 | #endif // CONFIG_EXT_TILE |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 1032 | |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 1033 | #if CONFIG_DEPENDENT_HORZTILES |
| 1034 | cm->dependent_horz_tiles = cpi->oxcf.dependent_horz_tiles; |
Fangwen Fu | 70bcb89 | 2017-05-06 17:05:19 -0700 | [diff] [blame] | 1035 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1036 | if (cm->large_scale_tile) { |
| 1037 | // May not needed since cpi->oxcf.dependent_horz_tiles is already adjusted. |
| 1038 | cm->dependent_horz_tiles = 0; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1039 | } else { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1040 | #endif // CONFIG_EXT_TILE |
| 1041 | if (cm->log2_tile_rows == 0) cm->dependent_horz_tiles = 0; |
| 1042 | #if CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1043 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1044 | #endif // CONFIG_EXT_TILE |
| 1045 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1046 | #if CONFIG_EXT_TILE |
| 1047 | if (!cm->large_scale_tile) { |
| 1048 | #endif // CONFIG_EXT_TILE |
| 1049 | if (cpi->oxcf.mtu == 0) { |
| 1050 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 1051 | } else { |
| 1052 | // Use a default value for the purposes of weighting costs in probability |
| 1053 | // updates |
| 1054 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1055 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1056 | num_tiles_in_tg = |
| 1057 | (cm->tile_cols * cm->tile_rows + cm->num_tg - 1) / cm->num_tg; |
| 1058 | tg_row_start = 0; |
| 1059 | tg_col_start = 0; |
| 1060 | for (tile_row = 0; tile_row < cm->tile_rows; ++tile_row) { |
| 1061 | for (tile_col = 0; tile_col < cm->tile_cols; ++tile_col) { |
| 1062 | if ((tile_row * cm->tile_cols + tile_col) % num_tiles_in_tg == 0) { |
| 1063 | tg_row_start = tile_row; |
| 1064 | tg_col_start = tile_col; |
| 1065 | } |
| 1066 | cm->tile_group_start_row[tile_row][tile_col] = tg_row_start; |
| 1067 | cm->tile_group_start_col[tile_row][tile_col] = tg_col_start; |
| 1068 | } |
| 1069 | } |
| 1070 | #if CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1071 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1072 | #endif // CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1073 | #endif |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 1074 | |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 1075 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 1076 | cm->loop_filter_across_tiles_enabled = |
| 1077 | cpi->oxcf.loop_filter_across_tiles_enabled; |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 1078 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1081 | static void update_frame_size(AV1_COMP *cpi) { |
| 1082 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1083 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 1084 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1085 | av1_set_mb_mi(cm, cm->width, cm->height); |
| 1086 | av1_init_context_buffers(cm); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1087 | av1_init_macroblockd(cm, xd, |
| 1088 | #if CONFIG_PVQ |
| 1089 | NULL, |
| 1090 | #endif |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 1091 | #if CONFIG_CFL |
| 1092 | &NULL_CFL, |
| 1093 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1094 | NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1095 | memset(cpi->mbmi_ext_base, 0, |
| 1096 | cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1097 | set_tile_info(cpi); |
| 1098 | } |
| 1099 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1100 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1101 | #if CONFIG_EXT_REFS |
| 1102 | int fb_idx; |
| 1103 | for (fb_idx = 0; fb_idx < LAST_REF_FRAMES; ++fb_idx) |
| 1104 | cpi->lst_fb_idxes[fb_idx] = fb_idx; |
| 1105 | cpi->gld_fb_idx = LAST_REF_FRAMES; |
| 1106 | cpi->bwd_fb_idx = LAST_REF_FRAMES + 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1107 | cpi->alt2_fb_idx = LAST_REF_FRAMES + 2; |
| 1108 | cpi->alt_fb_idx = LAST_REF_FRAMES + 3; |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 1109 | cpi->ext_fb_idx = LAST_REF_FRAMES + 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1110 | for (fb_idx = 0; fb_idx < MAX_EXT_ARFS + 1; ++fb_idx) |
| 1111 | cpi->arf_map[fb_idx] = LAST_REF_FRAMES + 2 + fb_idx; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1112 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1113 | cpi->lst_fb_idx = 0; |
| 1114 | cpi->gld_fb_idx = 1; |
| 1115 | cpi->alt_fb_idx = 2; |
| 1116 | #endif // CONFIG_EXT_REFS |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1117 | #if CONFIG_AMVR |
| 1118 | cpi->rate_index = 0; |
| 1119 | cpi->rate_size = 0; |
| 1120 | cpi->cur_poc = -1; |
| 1121 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1124 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 1125 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1126 | |
| 1127 | cpi->oxcf = *oxcf; |
| 1128 | cpi->framerate = oxcf->init_framerate; |
| 1129 | |
| 1130 | cm->profile = oxcf->profile; |
| 1131 | cm->bit_depth = oxcf->bit_depth; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1132 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1133 | cm->use_highbitdepth = oxcf->use_highbitdepth; |
| 1134 | #endif |
| 1135 | cm->color_space = oxcf->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 1136 | #if CONFIG_COLORSPACE_HEADERS |
| 1137 | cm->transfer_function = oxcf->transfer_function; |
| 1138 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
| 1139 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1140 | cm->color_range = oxcf->color_range; |
| 1141 | |
| 1142 | cm->width = oxcf->width; |
| 1143 | cm->height = oxcf->height; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 1144 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1145 | |
| 1146 | // Single thread case: use counts in common. |
| 1147 | cpi->td.counts = &cm->counts; |
| 1148 | |
| 1149 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1150 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1151 | |
| 1152 | cpi->static_mb_pct = 0; |
| 1153 | cpi->ref_frame_flags = 0; |
| 1154 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 1155 | // Reset resize pending flags |
| 1156 | cpi->resize_pending_width = 0; |
| 1157 | cpi->resize_pending_height = 0; |
| 1158 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1159 | init_buffer_indices(cpi); |
| 1160 | } |
| 1161 | |
| 1162 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1163 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1164 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 1165 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 1166 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 1167 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 1168 | |
| 1169 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 1170 | rc->optimal_buffer_level = |
| 1171 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1172 | rc->maximum_buffer_size = |
| 1173 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1174 | } |
| 1175 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1176 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1177 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 1178 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1179 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1180 | cpi->fn_ptr[BT].vf = VF; \ |
| 1181 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1182 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1183 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 1184 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 1185 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
| 1186 | |
| 1187 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1188 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1189 | int source_stride, \ |
| 1190 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1191 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1192 | } \ |
| 1193 | static unsigned int fnname##_bits10( \ |
| 1194 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1195 | int ref_stride) { \ |
| 1196 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1197 | } \ |
| 1198 | static unsigned int fnname##_bits12( \ |
| 1199 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1200 | int ref_stride) { \ |
| 1201 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1202 | } |
| 1203 | |
| 1204 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1205 | static unsigned int fnname##_bits8( \ |
| 1206 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1207 | int ref_stride, const uint8_t *second_pred) { \ |
| 1208 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1209 | } \ |
| 1210 | static unsigned int fnname##_bits10( \ |
| 1211 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1212 | int ref_stride, const uint8_t *second_pred) { \ |
| 1213 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1214 | 2; \ |
| 1215 | } \ |
| 1216 | static unsigned int fnname##_bits12( \ |
| 1217 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1218 | int ref_stride, const uint8_t *second_pred) { \ |
| 1219 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1220 | 4; \ |
| 1221 | } |
| 1222 | |
| 1223 | #define MAKE_BFP_SAD3_WRAPPER(fnname) \ |
| 1224 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1225 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1226 | unsigned int *sad_array) { \ |
| 1227 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1228 | } \ |
| 1229 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1230 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1231 | unsigned int *sad_array) { \ |
| 1232 | int i; \ |
| 1233 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1234 | for (i = 0; i < 3; i++) sad_array[i] >>= 2; \ |
| 1235 | } \ |
| 1236 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1237 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1238 | unsigned int *sad_array) { \ |
| 1239 | int i; \ |
| 1240 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1241 | for (i = 0; i < 3; i++) sad_array[i] >>= 4; \ |
| 1242 | } |
| 1243 | |
| 1244 | #define MAKE_BFP_SAD8_WRAPPER(fnname) \ |
| 1245 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1246 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1247 | unsigned int *sad_array) { \ |
| 1248 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1249 | } \ |
| 1250 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1251 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1252 | unsigned int *sad_array) { \ |
| 1253 | int i; \ |
| 1254 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1255 | for (i = 0; i < 8; i++) sad_array[i] >>= 2; \ |
| 1256 | } \ |
| 1257 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1258 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1259 | unsigned int *sad_array) { \ |
| 1260 | int i; \ |
| 1261 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1262 | for (i = 0; i < 8; i++) sad_array[i] >>= 4; \ |
| 1263 | } |
| 1264 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1265 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1266 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1267 | unsigned int *sad_array) { \ |
| 1268 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1269 | } \ |
| 1270 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1271 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1272 | unsigned int *sad_array) { \ |
| 1273 | int i; \ |
| 1274 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1275 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1276 | } \ |
| 1277 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1278 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1279 | unsigned int *sad_array) { \ |
| 1280 | int i; \ |
| 1281 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1282 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1283 | } |
| 1284 | |
| 1285 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1286 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1287 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
| 1288 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad128x128x3) |
| 1289 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad128x128x8) |
| 1290 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1291 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1292 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1293 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1294 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1295 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1296 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1297 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1298 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1299 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1300 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1301 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1302 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1303 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1304 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1305 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1306 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1307 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1308 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1309 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1310 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1311 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
| 1312 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad32x32x3) |
| 1313 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad32x32x8) |
| 1314 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1315 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1316 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
| 1317 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad64x64x3) |
| 1318 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad64x64x8) |
| 1319 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1320 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1321 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
| 1322 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x16x3) |
| 1323 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x16x8) |
| 1324 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1325 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1326 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
| 1327 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x8x3) |
| 1328 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x8x8) |
| 1329 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1330 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1331 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
| 1332 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x16x3) |
| 1333 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x16x8) |
| 1334 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1335 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1336 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
| 1337 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x8x3) |
| 1338 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x8x8) |
| 1339 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1340 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1341 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
| 1342 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x4x8) |
| 1343 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1344 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1345 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
| 1346 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x8x8) |
| 1347 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1348 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1349 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
| 1350 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad4x4x3) |
| 1351 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x4x8) |
| 1352 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1353 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1354 | #if CONFIG_EXT_PARTITION_TYPES |
| 1355 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16) |
| 1356 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg) |
| 1357 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d) |
| 1358 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4) |
| 1359 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg) |
| 1360 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d) |
| 1361 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32) |
| 1362 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg) |
| 1363 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d) |
| 1364 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8) |
| 1365 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg) |
| 1366 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1367 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64) |
| 1368 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg) |
| 1369 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d) |
| 1370 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16) |
| 1371 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg) |
| 1372 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1373 | #if CONFIG_EXT_PARTITION |
| 1374 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x128) |
| 1375 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x128_avg) |
| 1376 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x128x4d) |
| 1377 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x32) |
| 1378 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x32_avg) |
| 1379 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x32x4d) |
| 1380 | #endif // CONFIG_EXT_PARTITION |
| 1381 | #endif // CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1382 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1383 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1384 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1385 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1386 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1387 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1388 | static unsigned int fnname##_bits8( \ |
| 1389 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1390 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1391 | int m_stride, int invert_mask) { \ |
| 1392 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1393 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1394 | } \ |
| 1395 | static unsigned int fnname##_bits10( \ |
| 1396 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1397 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1398 | int m_stride, int invert_mask) { \ |
| 1399 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1400 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1401 | 2; \ |
| 1402 | } \ |
| 1403 | static unsigned int fnname##_bits12( \ |
| 1404 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1405 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1406 | int m_stride, int invert_mask) { \ |
| 1407 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1408 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1409 | 4; \ |
| 1410 | } |
| 1411 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1412 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1413 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1414 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1415 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1416 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1417 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1418 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1419 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1420 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1421 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1422 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1423 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1424 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1425 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1426 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1427 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1428 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1429 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1430 | |
| 1431 | #if CONFIG_EXT_PARTITION_TYPES |
| 1432 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1433 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1434 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1435 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1436 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1437 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1438 | #if CONFIG_EXT_PARTITION |
| 1439 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x128) |
| 1440 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x32) |
| 1441 | #endif // CONFIG_EXT_PARTITION |
| 1442 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1443 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1444 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1445 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1446 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1447 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1448 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1449 | |
| 1450 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1451 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1452 | const int32_t *wsrc, \ |
| 1453 | const int32_t *msk) { \ |
| 1454 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1455 | } \ |
| 1456 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1457 | const int32_t *wsrc, \ |
| 1458 | const int32_t *msk) { \ |
| 1459 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1460 | } \ |
| 1461 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1462 | const int32_t *wsrc, \ |
| 1463 | const int32_t *msk) { \ |
| 1464 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1465 | } |
| 1466 | |
| 1467 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1468 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1469 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1470 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1471 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1472 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1473 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1474 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1475 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1476 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1477 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1478 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1479 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1480 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1481 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1482 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1483 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1484 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1485 | |
| 1486 | #if CONFIG_EXT_PARTITION_TYPES |
| 1487 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1488 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1489 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1490 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1491 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1492 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1493 | #if CONFIG_EXT_PARTITION |
| 1494 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x128) |
| 1495 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x32) |
| 1496 | #endif // CONFIG_EXT_PARTITION |
| 1497 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1498 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1499 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1500 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1501 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1502 | if (cm->use_highbitdepth) { |
| 1503 | switch (cm->bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1504 | case AOM_BITS_8: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1505 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1506 | #if CONFIG_EXT_PARTITION |
| 1507 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits8, |
| 1508 | aom_highbd_sad128x32_avg_bits8, aom_highbd_8_variance128x32, |
| 1509 | aom_highbd_8_sub_pixel_variance128x32, |
| 1510 | aom_highbd_8_sub_pixel_avg_variance128x32, NULL, NULL, |
| 1511 | aom_highbd_sad128x32x4d_bits8) |
| 1512 | |
| 1513 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits8, |
| 1514 | aom_highbd_sad32x128_avg_bits8, aom_highbd_8_variance32x128, |
| 1515 | aom_highbd_8_sub_pixel_variance32x128, |
| 1516 | aom_highbd_8_sub_pixel_avg_variance32x128, NULL, NULL, |
| 1517 | aom_highbd_sad32x128x4d_bits8) |
| 1518 | #endif // CONFIG_EXT_PARTITION |
| 1519 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1520 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1521 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1522 | aom_highbd_8_sub_pixel_variance64x16, |
| 1523 | aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1524 | aom_highbd_sad64x16x4d_bits8) |
| 1525 | |
| 1526 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1527 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1528 | aom_highbd_8_sub_pixel_variance16x64, |
| 1529 | aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1530 | aom_highbd_sad16x64x4d_bits8) |
| 1531 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1532 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits8, |
| 1533 | aom_highbd_sad32x8_avg_bits8, aom_highbd_8_variance32x8, |
| 1534 | aom_highbd_8_sub_pixel_variance32x8, |
| 1535 | aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1536 | aom_highbd_sad32x8x4d_bits8) |
| 1537 | |
| 1538 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits8, |
| 1539 | aom_highbd_sad8x32_avg_bits8, aom_highbd_8_variance8x32, |
| 1540 | aom_highbd_8_sub_pixel_variance8x32, |
| 1541 | aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1542 | aom_highbd_sad8x32x4d_bits8) |
| 1543 | |
| 1544 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits8, |
| 1545 | aom_highbd_sad16x4_avg_bits8, aom_highbd_8_variance16x4, |
| 1546 | aom_highbd_8_sub_pixel_variance16x4, |
| 1547 | aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1548 | aom_highbd_sad16x4x4d_bits8) |
| 1549 | |
| 1550 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits8, |
| 1551 | aom_highbd_sad4x16_avg_bits8, aom_highbd_8_variance4x16, |
| 1552 | aom_highbd_8_sub_pixel_variance4x16, |
| 1553 | aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1554 | aom_highbd_sad4x16x4d_bits8) |
| 1555 | #endif |
| 1556 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1557 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1558 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1559 | aom_highbd_8_sub_pixel_variance32x16, |
| 1560 | aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1561 | aom_highbd_sad32x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1562 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1563 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1564 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1565 | aom_highbd_8_sub_pixel_variance16x32, |
| 1566 | aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1567 | aom_highbd_sad16x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1568 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1569 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1570 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1571 | aom_highbd_8_sub_pixel_variance64x32, |
| 1572 | aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1573 | aom_highbd_sad64x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1574 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1575 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1576 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1577 | aom_highbd_8_sub_pixel_variance32x64, |
| 1578 | aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1579 | aom_highbd_sad32x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1580 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1581 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1582 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1583 | aom_highbd_8_sub_pixel_variance32x32, |
| 1584 | aom_highbd_8_sub_pixel_avg_variance32x32, |
| 1585 | aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8, |
| 1586 | aom_highbd_sad32x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1587 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1588 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1589 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1590 | aom_highbd_8_sub_pixel_variance64x64, |
| 1591 | aom_highbd_8_sub_pixel_avg_variance64x64, |
| 1592 | aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8, |
| 1593 | aom_highbd_sad64x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1594 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1595 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1596 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1597 | aom_highbd_8_sub_pixel_variance16x16, |
| 1598 | aom_highbd_8_sub_pixel_avg_variance16x16, |
| 1599 | aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8, |
| 1600 | aom_highbd_sad16x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1601 | |
| 1602 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1603 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1604 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
| 1605 | aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8, |
| 1606 | aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1607 | |
| 1608 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1609 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1610 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
| 1611 | aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8, |
| 1612 | aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1613 | |
| 1614 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1615 | BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8, |
| 1616 | aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8, |
| 1617 | aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits8, |
| 1618 | aom_highbd_sad8x8x8_bits8, aom_highbd_sad8x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1619 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1620 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8, |
| 1621 | aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4, |
| 1622 | aom_highbd_8_sub_pixel_variance8x4, |
| 1623 | aom_highbd_8_sub_pixel_avg_variance8x4, NULL, |
| 1624 | aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1625 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1626 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8, |
| 1627 | aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8, |
| 1628 | aom_highbd_8_sub_pixel_variance4x8, |
| 1629 | aom_highbd_8_sub_pixel_avg_variance4x8, NULL, |
| 1630 | aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1631 | |
| 1632 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1633 | BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8, |
| 1634 | aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4, |
| 1635 | aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits8, |
| 1636 | aom_highbd_sad4x4x8_bits8, aom_highbd_sad4x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1637 | |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 1638 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1639 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_8_variance2x2, NULL, NULL, |
| 1640 | NULL, NULL, NULL) |
| 1641 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_8_variance4x2, NULL, NULL, |
| 1642 | NULL, NULL, NULL) |
| 1643 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_8_variance2x4, NULL, NULL, |
| 1644 | NULL, NULL, NULL) |
| 1645 | #endif |
| 1646 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1647 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1648 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1649 | aom_highbd_sad128x128_avg_bits8, |
| 1650 | aom_highbd_8_variance128x128, |
| 1651 | aom_highbd_8_sub_pixel_variance128x128, |
| 1652 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1653 | aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8, |
| 1654 | aom_highbd_sad128x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1655 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1656 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1657 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1658 | aom_highbd_8_sub_pixel_variance128x64, |
| 1659 | aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1660 | aom_highbd_sad128x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1661 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1662 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1663 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1664 | aom_highbd_8_sub_pixel_variance64x128, |
| 1665 | aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1666 | aom_highbd_sad64x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1667 | #endif // CONFIG_EXT_PARTITION |
| 1668 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1669 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1670 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1671 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1672 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1673 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1674 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1675 | aom_highbd_8_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1676 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1677 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1678 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1679 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1680 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1681 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1682 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1683 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1684 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1685 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1686 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1687 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1688 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1689 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1690 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1691 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1692 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1693 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1694 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1695 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1696 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1697 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1698 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1699 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1700 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1701 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1702 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1703 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1704 | #if CONFIG_EXT_PARTITION |
| 1705 | HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits8, |
| 1706 | aom_highbd_8_masked_sub_pixel_variance128x32) |
| 1707 | |
| 1708 | HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits8, |
| 1709 | aom_highbd_8_masked_sub_pixel_variance32x128) |
| 1710 | #endif // CONFIG_EXT_PARTITION |
| 1711 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1712 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1713 | aom_highbd_8_masked_sub_pixel_variance64x16) |
| 1714 | |
| 1715 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1716 | aom_highbd_8_masked_sub_pixel_variance16x64) |
| 1717 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1718 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1719 | aom_highbd_8_masked_sub_pixel_variance32x8) |
| 1720 | |
| 1721 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1722 | aom_highbd_8_masked_sub_pixel_variance8x32) |
| 1723 | |
| 1724 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1725 | aom_highbd_8_masked_sub_pixel_variance16x4) |
| 1726 | |
| 1727 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1728 | aom_highbd_8_masked_sub_pixel_variance4x16) |
| 1729 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1730 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1731 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1732 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1733 | aom_highbd_obmc_variance128x128, |
| 1734 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1735 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1736 | aom_highbd_obmc_variance128x64, |
| 1737 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1738 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1739 | aom_highbd_obmc_variance64x128, |
| 1740 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1741 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1742 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1743 | aom_highbd_obmc_variance64x64, |
| 1744 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1745 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1746 | aom_highbd_obmc_variance64x32, |
| 1747 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1748 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1749 | aom_highbd_obmc_variance32x64, |
| 1750 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1751 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1752 | aom_highbd_obmc_variance32x32, |
| 1753 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1754 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1755 | aom_highbd_obmc_variance32x16, |
| 1756 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1757 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1758 | aom_highbd_obmc_variance16x32, |
| 1759 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1760 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1761 | aom_highbd_obmc_variance16x16, |
| 1762 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1763 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1764 | aom_highbd_obmc_variance8x16, |
| 1765 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1766 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1767 | aom_highbd_obmc_variance16x8, |
| 1768 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1769 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1770 | aom_highbd_obmc_variance8x8, |
| 1771 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 1772 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 1773 | aom_highbd_obmc_variance4x8, |
| 1774 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 1775 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 1776 | aom_highbd_obmc_variance8x4, |
| 1777 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 1778 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 1779 | aom_highbd_obmc_variance4x4, |
| 1780 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1781 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1782 | #if CONFIG_EXT_PARTITION |
| 1783 | HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits8, |
| 1784 | aom_highbd_obmc_variance128x32, |
| 1785 | aom_highbd_obmc_sub_pixel_variance128x32) |
| 1786 | |
| 1787 | HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits8, |
| 1788 | aom_highbd_obmc_variance32x128, |
| 1789 | aom_highbd_obmc_sub_pixel_variance32x128) |
| 1790 | #endif // CONFIG_EXT_PARTITION |
| 1791 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1792 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 1793 | aom_highbd_obmc_variance64x16, |
| 1794 | aom_highbd_obmc_sub_pixel_variance64x16) |
| 1795 | |
| 1796 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 1797 | aom_highbd_obmc_variance16x64, |
| 1798 | aom_highbd_obmc_sub_pixel_variance16x64) |
| 1799 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1800 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 1801 | aom_highbd_obmc_variance32x8, |
| 1802 | aom_highbd_obmc_sub_pixel_variance32x8) |
| 1803 | |
| 1804 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 1805 | aom_highbd_obmc_variance8x32, |
| 1806 | aom_highbd_obmc_sub_pixel_variance8x32) |
| 1807 | |
| 1808 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 1809 | aom_highbd_obmc_variance16x4, |
| 1810 | aom_highbd_obmc_sub_pixel_variance16x4) |
| 1811 | |
| 1812 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 1813 | aom_highbd_obmc_variance4x16, |
| 1814 | aom_highbd_obmc_sub_pixel_variance4x16) |
| 1815 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1816 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1817 | break; |
| 1818 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1819 | case AOM_BITS_10: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1820 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1821 | #if CONFIG_EXT_PARTITION |
| 1822 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits10, |
| 1823 | aom_highbd_sad128x32_avg_bits10, |
| 1824 | aom_highbd_10_variance128x32, |
| 1825 | aom_highbd_10_sub_pixel_variance128x32, |
| 1826 | aom_highbd_10_sub_pixel_avg_variance128x32, NULL, NULL, |
| 1827 | aom_highbd_sad128x32x4d_bits10) |
| 1828 | |
| 1829 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits10, |
| 1830 | aom_highbd_sad32x128_avg_bits10, |
| 1831 | aom_highbd_10_variance32x128, |
| 1832 | aom_highbd_10_sub_pixel_variance32x128, |
| 1833 | aom_highbd_10_sub_pixel_avg_variance32x128, NULL, NULL, |
| 1834 | aom_highbd_sad32x128x4d_bits10) |
| 1835 | #endif // CONFIG_EXT_PARTITION |
| 1836 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1837 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 1838 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 1839 | aom_highbd_10_sub_pixel_variance64x16, |
| 1840 | aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1841 | aom_highbd_sad64x16x4d_bits10) |
| 1842 | |
| 1843 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 1844 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 1845 | aom_highbd_10_sub_pixel_variance16x64, |
| 1846 | aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1847 | aom_highbd_sad16x64x4d_bits10) |
| 1848 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1849 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 1850 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 1851 | aom_highbd_10_sub_pixel_variance32x8, |
| 1852 | aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1853 | aom_highbd_sad32x8x4d_bits10) |
| 1854 | |
| 1855 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 1856 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 1857 | aom_highbd_10_sub_pixel_variance8x32, |
| 1858 | aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1859 | aom_highbd_sad8x32x4d_bits10) |
| 1860 | |
| 1861 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 1862 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 1863 | aom_highbd_10_sub_pixel_variance16x4, |
| 1864 | aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1865 | aom_highbd_sad16x4x4d_bits10) |
| 1866 | |
| 1867 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 1868 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 1869 | aom_highbd_10_sub_pixel_variance4x16, |
| 1870 | aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1871 | aom_highbd_sad4x16x4d_bits10) |
| 1872 | #endif |
| 1873 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1874 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 1875 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 1876 | aom_highbd_10_sub_pixel_variance32x16, |
| 1877 | aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1878 | aom_highbd_sad32x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1879 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1880 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 1881 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 1882 | aom_highbd_10_sub_pixel_variance16x32, |
| 1883 | aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1884 | aom_highbd_sad16x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1885 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1886 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 1887 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 1888 | aom_highbd_10_sub_pixel_variance64x32, |
| 1889 | aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1890 | aom_highbd_sad64x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1891 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1892 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 1893 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 1894 | aom_highbd_10_sub_pixel_variance32x64, |
| 1895 | aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1896 | aom_highbd_sad32x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1897 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1898 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 1899 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 1900 | aom_highbd_10_sub_pixel_variance32x32, |
| 1901 | aom_highbd_10_sub_pixel_avg_variance32x32, |
| 1902 | aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10, |
| 1903 | aom_highbd_sad32x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1904 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1905 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 1906 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 1907 | aom_highbd_10_sub_pixel_variance64x64, |
| 1908 | aom_highbd_10_sub_pixel_avg_variance64x64, |
| 1909 | aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10, |
| 1910 | aom_highbd_sad64x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1911 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1912 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 1913 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 1914 | aom_highbd_10_sub_pixel_variance16x16, |
| 1915 | aom_highbd_10_sub_pixel_avg_variance16x16, |
| 1916 | aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10, |
| 1917 | aom_highbd_sad16x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1918 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1919 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 1920 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 1921 | aom_highbd_10_sub_pixel_variance16x8, |
| 1922 | aom_highbd_10_sub_pixel_avg_variance16x8, |
| 1923 | aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10, |
| 1924 | aom_highbd_sad16x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1925 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1926 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 1927 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 1928 | aom_highbd_10_sub_pixel_variance8x16, |
| 1929 | aom_highbd_10_sub_pixel_avg_variance8x16, |
| 1930 | aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10, |
| 1931 | aom_highbd_sad8x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1932 | |
| 1933 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1934 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 1935 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
| 1936 | aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10, |
| 1937 | aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1938 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1939 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10, |
| 1940 | aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4, |
| 1941 | aom_highbd_10_sub_pixel_variance8x4, |
| 1942 | aom_highbd_10_sub_pixel_avg_variance8x4, NULL, |
| 1943 | aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1944 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1945 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10, |
| 1946 | aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8, |
| 1947 | aom_highbd_10_sub_pixel_variance4x8, |
| 1948 | aom_highbd_10_sub_pixel_avg_variance4x8, NULL, |
| 1949 | aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1950 | |
| 1951 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1952 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 1953 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
| 1954 | aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10, |
| 1955 | aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1956 | |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 1957 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1958 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_10_variance2x2, NULL, NULL, |
| 1959 | NULL, NULL, NULL) |
| 1960 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_10_variance4x2, NULL, NULL, |
| 1961 | NULL, NULL, NULL) |
| 1962 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_10_variance2x4, NULL, NULL, |
| 1963 | NULL, NULL, NULL) |
| 1964 | #endif |
| 1965 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1966 | #if CONFIG_EXT_PARTITION |
| 1967 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1968 | BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 1969 | aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128, |
| 1970 | aom_highbd_10_sub_pixel_variance128x128, |
| 1971 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 1972 | aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10, |
| 1973 | aom_highbd_sad128x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1974 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1975 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 1976 | aom_highbd_sad128x64_avg_bits10, |
| 1977 | aom_highbd_10_variance128x64, |
| 1978 | aom_highbd_10_sub_pixel_variance128x64, |
| 1979 | aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1980 | aom_highbd_sad128x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1981 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1982 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 1983 | aom_highbd_sad64x128_avg_bits10, |
| 1984 | aom_highbd_10_variance64x128, |
| 1985 | aom_highbd_10_sub_pixel_variance64x128, |
| 1986 | aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1987 | aom_highbd_sad64x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1988 | #endif // CONFIG_EXT_PARTITION |
| 1989 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1990 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1991 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 1992 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 1993 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 1994 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 1995 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 1996 | aom_highbd_10_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1997 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1998 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 1999 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 2000 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 2001 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 2002 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 2003 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 2004 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 2005 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 2006 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 2007 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 2008 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 2009 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 2010 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 2011 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 2012 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 2013 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 2014 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 2015 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 2016 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 2017 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 2018 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 2019 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 2020 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 2021 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 2022 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 2023 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2024 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2025 | #if CONFIG_EXT_PARTITION |
| 2026 | HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits10, |
| 2027 | aom_highbd_10_masked_sub_pixel_variance128x32) |
| 2028 | |
| 2029 | HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits10, |
| 2030 | aom_highbd_10_masked_sub_pixel_variance32x128) |
| 2031 | #endif // CONFIG_EXT_PARTITION |
| 2032 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2033 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 2034 | aom_highbd_10_masked_sub_pixel_variance64x16) |
| 2035 | |
| 2036 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 2037 | aom_highbd_10_masked_sub_pixel_variance16x64) |
| 2038 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2039 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 2040 | aom_highbd_10_masked_sub_pixel_variance32x8) |
| 2041 | |
| 2042 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 2043 | aom_highbd_10_masked_sub_pixel_variance8x32) |
| 2044 | |
| 2045 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 2046 | aom_highbd_10_masked_sub_pixel_variance16x4) |
| 2047 | |
| 2048 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 2049 | aom_highbd_10_masked_sub_pixel_variance4x16) |
| 2050 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2051 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2052 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2053 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 2054 | aom_highbd_10_obmc_variance128x128, |
| 2055 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 2056 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 2057 | aom_highbd_10_obmc_variance128x64, |
| 2058 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 2059 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 2060 | aom_highbd_10_obmc_variance64x128, |
| 2061 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2062 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2063 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 2064 | aom_highbd_10_obmc_variance64x64, |
| 2065 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 2066 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 2067 | aom_highbd_10_obmc_variance64x32, |
| 2068 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 2069 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 2070 | aom_highbd_10_obmc_variance32x64, |
| 2071 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 2072 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 2073 | aom_highbd_10_obmc_variance32x32, |
| 2074 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 2075 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 2076 | aom_highbd_10_obmc_variance32x16, |
| 2077 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 2078 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 2079 | aom_highbd_10_obmc_variance16x32, |
| 2080 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 2081 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 2082 | aom_highbd_10_obmc_variance16x16, |
| 2083 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 2084 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 2085 | aom_highbd_10_obmc_variance8x16, |
| 2086 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 2087 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 2088 | aom_highbd_10_obmc_variance16x8, |
| 2089 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 2090 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 2091 | aom_highbd_10_obmc_variance8x8, |
| 2092 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 2093 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 2094 | aom_highbd_10_obmc_variance4x8, |
| 2095 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 2096 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 2097 | aom_highbd_10_obmc_variance8x4, |
| 2098 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 2099 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 2100 | aom_highbd_10_obmc_variance4x4, |
| 2101 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2102 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2103 | #if CONFIG_EXT_PARTITION |
| 2104 | HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits10, |
| 2105 | aom_highbd_10_obmc_variance128x32, |
| 2106 | aom_highbd_10_obmc_sub_pixel_variance128x32) |
| 2107 | |
| 2108 | HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits10, |
| 2109 | aom_highbd_10_obmc_variance32x128, |
| 2110 | aom_highbd_10_obmc_sub_pixel_variance32x128) |
| 2111 | #endif // CONFIG_EXT_PARTITION |
| 2112 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2113 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 2114 | aom_highbd_10_obmc_variance64x16, |
| 2115 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 2116 | |
| 2117 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 2118 | aom_highbd_10_obmc_variance16x64, |
| 2119 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 2120 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2121 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 2122 | aom_highbd_10_obmc_variance32x8, |
| 2123 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 2124 | |
| 2125 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 2126 | aom_highbd_10_obmc_variance8x32, |
| 2127 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 2128 | |
| 2129 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 2130 | aom_highbd_10_obmc_variance16x4, |
| 2131 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 2132 | |
| 2133 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 2134 | aom_highbd_10_obmc_variance4x16, |
| 2135 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
| 2136 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2137 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2138 | break; |
| 2139 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2140 | case AOM_BITS_12: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2141 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2142 | #if CONFIG_EXT_PARTITION |
| 2143 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits12, |
| 2144 | aom_highbd_sad128x32_avg_bits12, |
| 2145 | aom_highbd_12_variance128x32, |
| 2146 | aom_highbd_12_sub_pixel_variance128x32, |
| 2147 | aom_highbd_12_sub_pixel_avg_variance128x32, NULL, NULL, |
| 2148 | aom_highbd_sad128x32x4d_bits12) |
| 2149 | |
| 2150 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits12, |
| 2151 | aom_highbd_sad32x128_avg_bits12, |
| 2152 | aom_highbd_12_variance32x128, |
| 2153 | aom_highbd_12_sub_pixel_variance32x128, |
| 2154 | aom_highbd_12_sub_pixel_avg_variance32x128, NULL, NULL, |
| 2155 | aom_highbd_sad32x128x4d_bits12) |
| 2156 | #endif // CONFIG_EXT_PARTITION |
| 2157 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2158 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 2159 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 2160 | aom_highbd_12_sub_pixel_variance64x16, |
| 2161 | aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2162 | aom_highbd_sad64x16x4d_bits12) |
| 2163 | |
| 2164 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 2165 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 2166 | aom_highbd_12_sub_pixel_variance16x64, |
| 2167 | aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2168 | aom_highbd_sad16x64x4d_bits12) |
| 2169 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2170 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 2171 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 2172 | aom_highbd_12_sub_pixel_variance32x8, |
| 2173 | aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2174 | aom_highbd_sad32x8x4d_bits12) |
| 2175 | |
| 2176 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 2177 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 2178 | aom_highbd_12_sub_pixel_variance8x32, |
| 2179 | aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2180 | aom_highbd_sad8x32x4d_bits12) |
| 2181 | |
| 2182 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 2183 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 2184 | aom_highbd_12_sub_pixel_variance16x4, |
| 2185 | aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2186 | aom_highbd_sad16x4x4d_bits12) |
| 2187 | |
| 2188 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 2189 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 2190 | aom_highbd_12_sub_pixel_variance4x16, |
| 2191 | aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2192 | aom_highbd_sad4x16x4d_bits12) |
| 2193 | #endif |
| 2194 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2195 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 2196 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 2197 | aom_highbd_12_sub_pixel_variance32x16, |
| 2198 | aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2199 | aom_highbd_sad32x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2200 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2201 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 2202 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 2203 | aom_highbd_12_sub_pixel_variance16x32, |
| 2204 | aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2205 | aom_highbd_sad16x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2206 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2207 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 2208 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 2209 | aom_highbd_12_sub_pixel_variance64x32, |
| 2210 | aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2211 | aom_highbd_sad64x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2212 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2213 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 2214 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 2215 | aom_highbd_12_sub_pixel_variance32x64, |
| 2216 | aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2217 | aom_highbd_sad32x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2218 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2219 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 2220 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 2221 | aom_highbd_12_sub_pixel_variance32x32, |
| 2222 | aom_highbd_12_sub_pixel_avg_variance32x32, |
| 2223 | aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12, |
| 2224 | aom_highbd_sad32x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2225 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2226 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2227 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2228 | aom_highbd_12_sub_pixel_variance64x64, |
| 2229 | aom_highbd_12_sub_pixel_avg_variance64x64, |
| 2230 | aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12, |
| 2231 | aom_highbd_sad64x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2232 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2233 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2234 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2235 | aom_highbd_12_sub_pixel_variance16x16, |
| 2236 | aom_highbd_12_sub_pixel_avg_variance16x16, |
| 2237 | aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12, |
| 2238 | aom_highbd_sad16x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2239 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2240 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2241 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2242 | aom_highbd_12_sub_pixel_variance16x8, |
| 2243 | aom_highbd_12_sub_pixel_avg_variance16x8, |
| 2244 | aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12, |
| 2245 | aom_highbd_sad16x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2246 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2247 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2248 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2249 | aom_highbd_12_sub_pixel_variance8x16, |
| 2250 | aom_highbd_12_sub_pixel_avg_variance8x16, |
| 2251 | aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12, |
| 2252 | aom_highbd_sad8x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2253 | |
| 2254 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2255 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2256 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
| 2257 | aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12, |
| 2258 | aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2259 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2260 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12, |
| 2261 | aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4, |
| 2262 | aom_highbd_12_sub_pixel_variance8x4, |
| 2263 | aom_highbd_12_sub_pixel_avg_variance8x4, NULL, |
| 2264 | aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2265 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2266 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12, |
| 2267 | aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8, |
| 2268 | aom_highbd_12_sub_pixel_variance4x8, |
| 2269 | aom_highbd_12_sub_pixel_avg_variance4x8, NULL, |
| 2270 | aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2271 | |
| 2272 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2273 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2274 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
| 2275 | aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12, |
| 2276 | aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2277 | |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 2278 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 2279 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_12_variance2x2, NULL, NULL, |
| 2280 | NULL, NULL, NULL) |
| 2281 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_12_variance4x2, NULL, NULL, |
| 2282 | NULL, NULL, NULL) |
| 2283 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_12_variance2x4, NULL, NULL, |
| 2284 | NULL, NULL, NULL) |
| 2285 | #endif |
| 2286 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2287 | #if CONFIG_EXT_PARTITION |
| 2288 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2289 | BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2290 | aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128, |
| 2291 | aom_highbd_12_sub_pixel_variance128x128, |
| 2292 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2293 | aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12, |
| 2294 | aom_highbd_sad128x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2295 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2296 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2297 | aom_highbd_sad128x64_avg_bits12, |
| 2298 | aom_highbd_12_variance128x64, |
| 2299 | aom_highbd_12_sub_pixel_variance128x64, |
| 2300 | aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL, |
| 2301 | aom_highbd_sad128x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2302 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2303 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2304 | aom_highbd_sad64x128_avg_bits12, |
| 2305 | aom_highbd_12_variance64x128, |
| 2306 | aom_highbd_12_sub_pixel_variance64x128, |
| 2307 | aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL, |
| 2308 | aom_highbd_sad64x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2309 | #endif // CONFIG_EXT_PARTITION |
| 2310 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2311 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2312 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2313 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2314 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2315 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2316 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2317 | aom_highbd_12_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2318 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2319 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2320 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2321 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2322 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2323 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2324 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2325 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2326 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2327 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2328 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2329 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2330 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2331 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2332 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2333 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2334 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2335 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2336 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2337 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2338 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2339 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2340 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2341 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2342 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2343 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2344 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2345 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2346 | #if CONFIG_EXT_PARTITION |
| 2347 | HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits12, |
| 2348 | aom_highbd_12_masked_sub_pixel_variance128x32) |
| 2349 | |
| 2350 | HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits12, |
| 2351 | aom_highbd_12_masked_sub_pixel_variance32x128) |
| 2352 | #endif // CONFIG_EXT_PARTITION |
| 2353 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2354 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2355 | aom_highbd_12_masked_sub_pixel_variance64x16) |
| 2356 | |
| 2357 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2358 | aom_highbd_12_masked_sub_pixel_variance16x64) |
| 2359 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2360 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2361 | aom_highbd_12_masked_sub_pixel_variance32x8) |
| 2362 | |
| 2363 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2364 | aom_highbd_12_masked_sub_pixel_variance8x32) |
| 2365 | |
| 2366 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2367 | aom_highbd_12_masked_sub_pixel_variance16x4) |
| 2368 | |
| 2369 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2370 | aom_highbd_12_masked_sub_pixel_variance4x16) |
| 2371 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2372 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2373 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2374 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2375 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2376 | aom_highbd_12_obmc_variance128x128, |
| 2377 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2378 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2379 | aom_highbd_12_obmc_variance128x64, |
| 2380 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 2381 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 2382 | aom_highbd_12_obmc_variance64x128, |
| 2383 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2384 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2385 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 2386 | aom_highbd_12_obmc_variance64x64, |
| 2387 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 2388 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 2389 | aom_highbd_12_obmc_variance64x32, |
| 2390 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 2391 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 2392 | aom_highbd_12_obmc_variance32x64, |
| 2393 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 2394 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 2395 | aom_highbd_12_obmc_variance32x32, |
| 2396 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 2397 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 2398 | aom_highbd_12_obmc_variance32x16, |
| 2399 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 2400 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 2401 | aom_highbd_12_obmc_variance16x32, |
| 2402 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 2403 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 2404 | aom_highbd_12_obmc_variance16x16, |
| 2405 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 2406 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 2407 | aom_highbd_12_obmc_variance8x16, |
| 2408 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 2409 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 2410 | aom_highbd_12_obmc_variance16x8, |
| 2411 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 2412 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 2413 | aom_highbd_12_obmc_variance8x8, |
| 2414 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 2415 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 2416 | aom_highbd_12_obmc_variance4x8, |
| 2417 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 2418 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 2419 | aom_highbd_12_obmc_variance8x4, |
| 2420 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 2421 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 2422 | aom_highbd_12_obmc_variance4x4, |
| 2423 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2424 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2425 | #if CONFIG_EXT_PARTITION |
| 2426 | HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits12, |
| 2427 | aom_highbd_12_obmc_variance128x32, |
| 2428 | aom_highbd_12_obmc_sub_pixel_variance128x32) |
| 2429 | |
| 2430 | HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits12, |
| 2431 | aom_highbd_12_obmc_variance32x128, |
| 2432 | aom_highbd_12_obmc_sub_pixel_variance32x128) |
| 2433 | #endif // CONFIG_EXT_PARTITION |
| 2434 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2435 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 2436 | aom_highbd_12_obmc_variance64x16, |
| 2437 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
| 2438 | |
| 2439 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 2440 | aom_highbd_12_obmc_variance16x64, |
| 2441 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
| 2442 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2443 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 2444 | aom_highbd_12_obmc_variance32x8, |
| 2445 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
| 2446 | |
| 2447 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 2448 | aom_highbd_12_obmc_variance8x32, |
| 2449 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
| 2450 | |
| 2451 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 2452 | aom_highbd_12_obmc_variance16x4, |
| 2453 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
| 2454 | |
| 2455 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 2456 | aom_highbd_12_obmc_variance4x16, |
| 2457 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
| 2458 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2459 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2460 | break; |
| 2461 | |
| 2462 | default: |
| 2463 | assert(0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2464 | "cm->bit_depth should be AOM_BITS_8, " |
| 2465 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2466 | } |
| 2467 | } |
| 2468 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2469 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2470 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2471 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 2472 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2473 | |
| 2474 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2475 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2476 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2477 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2478 | |
| 2479 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2480 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2481 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2482 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2483 | |
| 2484 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2485 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2486 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2487 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2488 | } |
| 2489 | |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2490 | void set_compound_tools(AV1_COMMON *cm) { |
| 2491 | (void)cm; |
| 2492 | #if CONFIG_INTERINTRA |
| 2493 | cm->allow_interintra_compound = 1; |
| 2494 | #endif // CONFIG_INTERINTRA |
| 2495 | #if CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT |
| 2496 | cm->allow_masked_compound = 1; |
| 2497 | #endif // CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT |
| 2498 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2499 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2500 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 2501 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2502 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2503 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2504 | |
| 2505 | if (cm->profile != oxcf->profile) cm->profile = oxcf->profile; |
| 2506 | cm->bit_depth = oxcf->bit_depth; |
| 2507 | cm->color_space = oxcf->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 2508 | #if CONFIG_COLORSPACE_HEADERS |
| 2509 | cm->transfer_function = oxcf->transfer_function; |
| 2510 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
| 2511 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2512 | cm->color_range = oxcf->color_range; |
| 2513 | |
| 2514 | if (cm->profile <= PROFILE_1) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2515 | assert(cm->bit_depth == AOM_BITS_8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2516 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2517 | assert(cm->bit_depth > AOM_BITS_8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2518 | |
| 2519 | cpi->oxcf = *oxcf; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2520 | x->e_mbd.bd = (int)cm->bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2521 | #if CONFIG_GLOBAL_MOTION |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2522 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2523 | #endif // CONFIG_GLOBAL_MOTION |
| 2524 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2525 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2526 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 2527 | } else { |
| 2528 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 2529 | } |
| 2530 | |
| 2531 | cpi->refresh_last_frame = 1; |
| 2532 | cpi->refresh_golden_frame = 0; |
| 2533 | #if CONFIG_EXT_REFS |
| 2534 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 2535 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2536 | #endif // CONFIG_EXT_REFS |
| 2537 | |
| 2538 | cm->refresh_frame_context = |
| 2539 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 2540 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 2541 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 2542 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2543 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 2544 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2545 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 2546 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2547 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 2548 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 2549 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2550 | set_compound_tools(cm); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2551 | av1_reset_segment_features(cm); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2552 | #if CONFIG_AMVR |
| 2553 | set_high_precision_mv(cpi, 0, 0); |
| 2554 | #else |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2555 | set_high_precision_mv(cpi, 0); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2556 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2557 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2558 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 2559 | |
| 2560 | // Under a configuration change, where maximum_buffer_size may change, |
| 2561 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2562 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2563 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2564 | |
| 2565 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2566 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2567 | |
| 2568 | // Set absolute upper and lower quality limits |
| 2569 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2570 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2571 | |
| 2572 | cm->interp_filter = cpi->sf.default_interp_filter; |
| 2573 | |
| 2574 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2575 | cm->render_width = cpi->oxcf.render_width; |
| 2576 | cm->render_height = cpi->oxcf.render_height; |
| 2577 | } else { |
| 2578 | cm->render_width = cpi->oxcf.width; |
| 2579 | cm->render_height = cpi->oxcf.height; |
| 2580 | } |
| 2581 | cm->width = cpi->oxcf.width; |
| 2582 | cm->height = cpi->oxcf.height; |
| 2583 | |
| 2584 | if (cpi->initial_width) { |
| 2585 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2586 | av1_free_context_buffers(cm); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 2587 | av1_free_pc_tree(&cpi->td); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2588 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2589 | realloc_segmentation_maps(cpi); |
| 2590 | cpi->initial_width = cpi->initial_height = 0; |
| 2591 | } |
| 2592 | } |
| 2593 | update_frame_size(cpi); |
| 2594 | |
| 2595 | cpi->alt_ref_source = NULL; |
| 2596 | rc->is_src_frame_alt_ref = 0; |
| 2597 | |
| 2598 | #if CONFIG_EXT_REFS |
| 2599 | rc->is_bwd_ref_frame = 0; |
| 2600 | rc->is_last_bipred_frame = 0; |
| 2601 | rc->is_bipred_frame = 0; |
| 2602 | #endif // CONFIG_EXT_REFS |
| 2603 | |
| 2604 | #if 0 |
| 2605 | // Experimental RD Code |
| 2606 | cpi->frame_distortion = 0; |
| 2607 | cpi->last_frame_distortion = 0; |
| 2608 | #endif |
| 2609 | |
| 2610 | set_tile_info(cpi); |
| 2611 | |
| 2612 | cpi->ext_refresh_frame_flags_pending = 0; |
| 2613 | cpi->ext_refresh_frame_context_pending = 0; |
| 2614 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2615 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2616 | highbd_set_var_fns(cpi); |
| 2617 | #endif |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2618 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 2619 | cpi->common.ans_window_size_log2 = cpi->oxcf.ans_window_size_log2; |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2620 | #endif // CONFIG_ANS && ANS_MAX_SYMBOLS |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2621 | #if CONFIG_AMVR |
| 2622 | cm->seq_mv_precision_level = 2; |
| 2623 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2626 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 2627 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2628 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2629 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2630 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2631 | |
| 2632 | if (!cm) return NULL; |
| 2633 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2634 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2635 | |
| 2636 | if (setjmp(cm->error.jmp)) { |
| 2637 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2638 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2639 | return 0; |
| 2640 | } |
| 2641 | |
| 2642 | cm->error.setjmp = 1; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2643 | cm->alloc_mi = enc_alloc_mi; |
| 2644 | cm->free_mi = enc_free_mi; |
| 2645 | cm->setup_mi = enc_setup_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2646 | |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 2647 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 2648 | get_default_ncobmc_kernels(cm); |
| 2649 | #endif // CONFIG_NCOBMC_ADAPT_WEIGHT |
| 2650 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2651 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2652 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
| 2653 | CHECK_MEM_ERROR(cm, cm->frame_contexts, |
| 2654 | (FRAME_CONTEXT *)aom_memalign( |
| 2655 | 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts))); |
| 2656 | memset(cm->fc, 0, sizeof(*cm->fc)); |
| 2657 | memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2658 | |
| 2659 | cpi->resize_state = 0; |
| 2660 | cpi->resize_avg_qp = 0; |
| 2661 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2662 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2663 | cpi->common.buffer_pool = pool; |
| 2664 | |
| 2665 | init_config(cpi, oxcf); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2666 | #if CONFIG_XIPHRC |
| 2667 | cpi->od_rc.framerate = cpi->framerate; |
| 2668 | cpi->od_rc.frame_width = cm->render_width; |
| 2669 | cpi->od_rc.frame_height = cm->render_height; |
| 2670 | cpi->od_rc.keyframe_rate = oxcf->key_freq; |
| 2671 | cpi->od_rc.goldenframe_rate = FIXED_GF_INTERVAL; |
| 2672 | cpi->od_rc.altref_rate = 25; |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2673 | cpi->od_rc.firstpass_quant = 1; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2674 | cpi->od_rc.bit_depth = cm->bit_depth; |
| 2675 | cpi->od_rc.minq = oxcf->best_allowed_q; |
| 2676 | cpi->od_rc.maxq = oxcf->worst_allowed_q; |
| 2677 | if (cpi->oxcf.rc_mode == AOM_CQ) cpi->od_rc.minq = cpi->od_rc.quality; |
| 2678 | cpi->od_rc.quality = cpi->oxcf.rc_mode == AOM_Q ? oxcf->cq_level : -1; |
| 2679 | cpi->od_rc.periodic_boosts = oxcf->frame_periodic_boost; |
| 2680 | od_enc_rc_init(&cpi->od_rc, |
| 2681 | cpi->oxcf.rc_mode == AOM_Q ? -1 : oxcf->target_bandwidth, |
| 2682 | oxcf->maximum_buffer_size_ms); |
| 2683 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2684 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2685 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2686 | |
| 2687 | cm->current_video_frame = 0; |
| 2688 | cpi->partition_search_skippable_frame = 0; |
| 2689 | cpi->tile_data = NULL; |
| 2690 | cpi->last_show_frame_buf_idx = INVALID_IDX; |
| 2691 | |
| 2692 | realloc_segmentation_maps(cpi); |
| 2693 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2694 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 2695 | memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs)); |
| 2696 | memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp)); |
| 2697 | } |
| 2698 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2699 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 2700 | i++) { |
| 2701 | CHECK_MEM_ERROR( |
| 2702 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2703 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | #if CONFIG_FP_MB_STATS |
| 2707 | cpi->use_fp_mb_stats = 0; |
| 2708 | if (cpi->use_fp_mb_stats) { |
| 2709 | // a place holder used to store the first pass mb stats in the first pass |
| 2710 | CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2711 | aom_calloc(cm->MBs * sizeof(uint8_t), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2712 | } else { |
| 2713 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2714 | } |
| 2715 | #endif |
| 2716 | |
| 2717 | cpi->refresh_alt_ref_frame = 0; |
| 2718 | cpi->multi_arf_last_grp_enabled = 0; |
| 2719 | |
| 2720 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 2721 | #if CONFIG_INTERNAL_STATS |
| 2722 | cpi->b_calculate_blockiness = 1; |
| 2723 | cpi->b_calculate_consistency = 1; |
| 2724 | cpi->total_inconsistency = 0; |
| 2725 | cpi->psnr.worst = 100.0; |
| 2726 | cpi->worst_ssim = 100.0; |
| 2727 | |
| 2728 | cpi->count = 0; |
| 2729 | cpi->bytes = 0; |
| 2730 | |
| 2731 | if (cpi->b_calculate_psnr) { |
| 2732 | cpi->total_sq_error = 0; |
| 2733 | cpi->total_samples = 0; |
| 2734 | cpi->tot_recode_hits = 0; |
| 2735 | cpi->summed_quality = 0; |
| 2736 | cpi->summed_weights = 0; |
| 2737 | } |
| 2738 | |
| 2739 | cpi->fastssim.worst = 100.0; |
| 2740 | cpi->psnrhvs.worst = 100.0; |
| 2741 | |
| 2742 | if (cpi->b_calculate_blockiness) { |
| 2743 | cpi->total_blockiness = 0; |
| 2744 | cpi->worst_blockiness = 0.0; |
| 2745 | } |
| 2746 | |
| 2747 | if (cpi->b_calculate_consistency) { |
| 2748 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2749 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2750 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 2751 | cpi->worst_consistency = 100.0; |
| 2752 | } |
| 2753 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2754 | #if CONFIG_ENTROPY_STATS |
| 2755 | av1_zero(aggregate_fc); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 2756 | av1_zero_array(aggregate_fc_per_type, FRAME_CONTEXTS); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2757 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2758 | |
| 2759 | cpi->first_time_stamp_ever = INT64_MAX; |
| 2760 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2761 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 2762 | cpi->td.mb.nmvcost[i][0] = &cpi->nmv_costs[i][0][MV_MAX]; |
| 2763 | cpi->td.mb.nmvcost[i][1] = &cpi->nmv_costs[i][1][MV_MAX]; |
| 2764 | cpi->td.mb.nmvcost_hp[i][0] = &cpi->nmv_costs_hp[i][0][MV_MAX]; |
| 2765 | cpi->td.mb.nmvcost_hp[i][1] = &cpi->nmv_costs_hp[i][1][MV_MAX]; |
| 2766 | } |
| 2767 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2768 | #ifdef OUTPUT_YUV_SKINMAP |
| 2769 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 2770 | #endif |
| 2771 | #ifdef OUTPUT_YUV_REC |
| 2772 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 2773 | #endif |
| 2774 | |
| 2775 | #if 0 |
| 2776 | framepsnr = fopen("framepsnr.stt", "a"); |
| 2777 | kf_list = fopen("kf_list.stt", "w"); |
| 2778 | #endif |
| 2779 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2780 | #if CONFIG_XIPHRC |
| 2781 | if (oxcf->pass == 2) { |
| 2782 | cpi->od_rc.twopass_allframes_buf = oxcf->two_pass_stats_in.buf; |
| 2783 | cpi->od_rc.twopass_allframes_buf_size = oxcf->two_pass_stats_in.sz; |
| 2784 | } |
| 2785 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2786 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2787 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2788 | } else if (oxcf->pass == 2) { |
| 2789 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 2790 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 2791 | |
| 2792 | #if CONFIG_FP_MB_STATS |
| 2793 | if (cpi->use_fp_mb_stats) { |
| 2794 | const size_t psz = cpi->common.MBs * sizeof(uint8_t); |
| 2795 | const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz); |
| 2796 | |
| 2797 | cpi->twopass.firstpass_mb_stats.mb_stats_start = |
| 2798 | oxcf->firstpass_mb_stats_in.buf; |
| 2799 | cpi->twopass.firstpass_mb_stats.mb_stats_end = |
| 2800 | cpi->twopass.firstpass_mb_stats.mb_stats_start + |
| 2801 | (ps - 1) * cpi->common.MBs * sizeof(uint8_t); |
| 2802 | } |
| 2803 | #endif |
| 2804 | |
| 2805 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 2806 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 2807 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 2808 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2809 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2810 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2811 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2812 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2813 | #if CONFIG_MOTION_VAR |
| 2814 | #if CONFIG_HIGHBITDEPTH |
| 2815 | int buf_scaler = 2; |
| 2816 | #else |
| 2817 | int buf_scaler = 1; |
| 2818 | #endif |
| 2819 | CHECK_MEM_ERROR( |
| 2820 | cm, cpi->td.mb.above_pred_buf, |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 2821 | (uint8_t *)aom_memalign(16, |
| 2822 | buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2823 | sizeof(*cpi->td.mb.above_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2824 | CHECK_MEM_ERROR( |
| 2825 | cm, cpi->td.mb.left_pred_buf, |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 2826 | (uint8_t *)aom_memalign(16, |
| 2827 | buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2828 | sizeof(*cpi->td.mb.left_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2829 | |
| 2830 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 2831 | (int32_t *)aom_memalign( |
| 2832 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 2833 | |
| 2834 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 2835 | (int32_t *)aom_memalign( |
| 2836 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 2837 | |
| 2838 | #endif |
| 2839 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2840 | av1_set_speed_features_framesize_independent(cpi); |
| 2841 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2842 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2843 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 2844 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 2845 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 2846 | cpi->fn_ptr[BT].vf = VF; \ |
| 2847 | cpi->fn_ptr[BT].svf = SVF; \ |
| 2848 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 2849 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 2850 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 2851 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
| 2852 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2853 | #if CONFIG_EXT_PARTITION_TYPES |
| 2854 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
| 2855 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2856 | aom_sad4x16x4d) |
| 2857 | |
| 2858 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
| 2859 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2860 | aom_sad16x4x4d) |
| 2861 | |
| 2862 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
| 2863 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2864 | aom_sad8x32x4d) |
| 2865 | |
| 2866 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
| 2867 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2868 | aom_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2869 | |
| 2870 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
| 2871 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2872 | aom_sad16x64x4d) |
| 2873 | |
| 2874 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
| 2875 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2876 | aom_sad64x16x4d) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2877 | |
| 2878 | #if CONFIG_EXT_PARTITION |
| 2879 | BFP(BLOCK_32X128, aom_sad32x128, aom_sad32x128_avg, aom_variance32x128, |
| 2880 | aom_sub_pixel_variance32x128, aom_sub_pixel_avg_variance32x128, NULL, |
| 2881 | NULL, aom_sad32x128x4d) |
| 2882 | |
| 2883 | BFP(BLOCK_128X32, aom_sad128x32, aom_sad128x32_avg, aom_variance128x32, |
| 2884 | aom_sub_pixel_variance128x32, aom_sub_pixel_avg_variance128x32, NULL, |
| 2885 | NULL, aom_sad128x32x4d) |
| 2886 | #endif // CONFIG_EXT_PARTITION |
| 2887 | #endif // CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2888 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2889 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2890 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 2891 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
| 2892 | aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2893 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2894 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
| 2895 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL, |
| 2896 | NULL, aom_sad128x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2897 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2898 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
| 2899 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL, |
| 2900 | NULL, aom_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2901 | #endif // CONFIG_EXT_PARTITION |
| 2902 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2903 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
| 2904 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2905 | aom_sad32x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2906 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2907 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
| 2908 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2909 | aom_sad16x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2910 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2911 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
| 2912 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2913 | aom_sad64x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2914 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2915 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
| 2916 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2917 | aom_sad32x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2918 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2919 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 2920 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
| 2921 | aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2922 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2923 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 2924 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
| 2925 | aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2926 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2927 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 2928 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
| 2929 | aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2930 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2931 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
| 2932 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3, |
| 2933 | aom_sad16x8x8, aom_sad16x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2934 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2935 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
| 2936 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3, |
| 2937 | aom_sad8x16x8, aom_sad8x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2938 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2939 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
| 2940 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3, |
| 2941 | aom_sad8x8x8, aom_sad8x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2942 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2943 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
| 2944 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL, |
| 2945 | aom_sad8x4x8, aom_sad8x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2946 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2947 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
| 2948 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL, |
| 2949 | aom_sad4x8x8, aom_sad4x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2950 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2951 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
| 2952 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3, |
| 2953 | aom_sad4x4x8, aom_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2954 | |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 2955 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 2956 | BFP(BLOCK_2X2, NULL, NULL, aom_variance2x2, NULL, NULL, NULL, NULL, NULL) |
Jingning Han | e2ffaf8 | 2016-12-14 15:26:30 -0800 | [diff] [blame] | 2957 | BFP(BLOCK_2X4, NULL, NULL, aom_variance2x4, NULL, NULL, NULL, NULL, NULL) |
| 2958 | BFP(BLOCK_4X2, NULL, NULL, aom_variance4x2, NULL, NULL, NULL, NULL, NULL) |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 2959 | #endif |
| 2960 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2961 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2962 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 2963 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 2964 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 2965 | cpi->fn_ptr[BT].osvf = OSVF; |
| 2966 | |
| 2967 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2968 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 2969 | aom_obmc_sub_pixel_variance128x128) |
| 2970 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 2971 | aom_obmc_sub_pixel_variance128x64) |
| 2972 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 2973 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2974 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2975 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 2976 | aom_obmc_sub_pixel_variance64x64) |
| 2977 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 2978 | aom_obmc_sub_pixel_variance64x32) |
| 2979 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 2980 | aom_obmc_sub_pixel_variance32x64) |
| 2981 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 2982 | aom_obmc_sub_pixel_variance32x32) |
| 2983 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 2984 | aom_obmc_sub_pixel_variance32x16) |
| 2985 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 2986 | aom_obmc_sub_pixel_variance16x32) |
| 2987 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 2988 | aom_obmc_sub_pixel_variance16x16) |
| 2989 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 2990 | aom_obmc_sub_pixel_variance16x8) |
| 2991 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 2992 | aom_obmc_sub_pixel_variance8x16) |
| 2993 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 2994 | aom_obmc_sub_pixel_variance8x8) |
| 2995 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 2996 | aom_obmc_sub_pixel_variance4x8) |
| 2997 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 2998 | aom_obmc_sub_pixel_variance8x4) |
| 2999 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 3000 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3001 | |
| 3002 | #if CONFIG_EXT_PARTITION_TYPES |
| 3003 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 3004 | aom_obmc_sub_pixel_variance4x16) |
| 3005 | |
| 3006 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 3007 | aom_obmc_sub_pixel_variance16x4) |
| 3008 | |
| 3009 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 3010 | aom_obmc_sub_pixel_variance8x32) |
| 3011 | |
| 3012 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 3013 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3014 | |
| 3015 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 3016 | aom_obmc_sub_pixel_variance16x64) |
| 3017 | |
| 3018 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 3019 | aom_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 3020 | |
| 3021 | #if CONFIG_EXT_PARTITION |
| 3022 | OBFP(BLOCK_32X128, aom_obmc_sad32x128, aom_obmc_variance32x128, |
| 3023 | aom_obmc_sub_pixel_variance32x128) |
| 3024 | |
| 3025 | OBFP(BLOCK_128X32, aom_obmc_sad128x32, aom_obmc_variance128x32, |
| 3026 | aom_obmc_sub_pixel_variance128x32) |
| 3027 | #endif // CONFIG_EXT_PARTITION |
| 3028 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 3029 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3030 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3031 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 3032 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 3033 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3034 | |
| 3035 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3036 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 3037 | aom_masked_sub_pixel_variance128x128) |
| 3038 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 3039 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3040 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3041 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 3042 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 3043 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 3044 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 3045 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 3046 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 3047 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 3048 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 3049 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 3050 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 3051 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 3052 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 3053 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3054 | |
| 3055 | #if CONFIG_EXT_PARTITION_TYPES |
| 3056 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 3057 | |
| 3058 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 3059 | |
| 3060 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 3061 | |
| 3062 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3063 | |
| 3064 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 3065 | |
| 3066 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 3067 | |
| 3068 | #if CONFIG_EXT_PARTITION |
| 3069 | MBFP(BLOCK_32X128, aom_masked_sad32x128, aom_masked_sub_pixel_variance32x128) |
| 3070 | |
| 3071 | MBFP(BLOCK_128X32, aom_masked_sad128x32, aom_masked_sub_pixel_variance128x32) |
| 3072 | #endif // CONFIG_EXT_PARTITION |
| 3073 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3074 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3075 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3076 | highbd_set_var_fns(cpi); |
| 3077 | #endif |
| 3078 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3079 | /* av1_init_quantizer() is first called here. Add check in |
| 3080 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3081 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3082 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3083 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3084 | av1_init_quantizer(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3085 | #if CONFIG_AOM_QM |
| 3086 | aom_qm_init(cm); |
| 3087 | #endif |
| 3088 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3089 | av1_loop_filter_init(cm); |
Fergus Simpson | dac6aff | 2017-05-18 15:11:38 -0700 | [diff] [blame] | 3090 | #if CONFIG_FRAME_SUPERRES |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3091 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 3092 | cm->superres_upscaled_width = oxcf->width; |
| 3093 | cm->superres_upscaled_height = oxcf->height; |
Fergus Simpson | dac6aff | 2017-05-18 15:11:38 -0700 | [diff] [blame] | 3094 | #endif // CONFIG_FRAME_SUPERRES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3095 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3096 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3097 | #endif // CONFIG_LOOP_RESTORATION |
| 3098 | |
| 3099 | cm->error.setjmp = 0; |
| 3100 | |
| 3101 | return cpi; |
| 3102 | } |
| 3103 | |
| 3104 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 3105 | |
| 3106 | #define SNPRINT2(H, T, V) \ |
| 3107 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
| 3108 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3109 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 3110 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3111 | unsigned int i; |
| 3112 | int t; |
| 3113 | |
| 3114 | if (!cpi) return; |
| 3115 | |
| 3116 | cm = &cpi->common; |
| 3117 | if (cm->current_video_frame > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3118 | #if CONFIG_ENTROPY_STATS |
| 3119 | if (cpi->oxcf.pass != 1) { |
| 3120 | fprintf(stderr, "Writing counts.stt\n"); |
| 3121 | FILE *f = fopen("counts.stt", "wb"); |
| 3122 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 3123 | fwrite(aggregate_fc_per_type, sizeof(aggregate_fc_per_type[0]), |
| 3124 | FRAME_CONTEXTS, f); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3125 | fclose(f); |
| 3126 | } |
| 3127 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3128 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3129 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3130 | |
| 3131 | if (cpi->oxcf.pass != 1) { |
| 3132 | char headings[512] = { 0 }; |
| 3133 | char results[512] = { 0 }; |
| 3134 | FILE *f = fopen("opsnr.stt", "a"); |
| 3135 | double time_encoded = |
| 3136 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 3137 | 10000000.000; |
| 3138 | double total_encode_time = |
| 3139 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 3140 | const double dr = |
| 3141 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 3142 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 3143 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 3144 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 3145 | |
| 3146 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3147 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3148 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 3149 | const double total_ssim = |
| 3150 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 3151 | snprintf(headings, sizeof(headings), |
| 3152 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3153 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3154 | "WstPsnr\tWstSsim\tWstFast\tWstHVS"); |
| 3155 | snprintf(results, sizeof(results), |
| 3156 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 3157 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 3158 | "%7.3f\t%7.3f\t%7.3f\t%7.3f", |
| 3159 | dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr, |
| 3160 | cpi->psnr.stat[ALL] / cpi->count, total_psnr, total_ssim, |
| 3161 | total_ssim, cpi->fastssim.stat[ALL] / cpi->count, |
| 3162 | cpi->psnrhvs.stat[ALL] / cpi->count, cpi->psnr.worst, |
| 3163 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst); |
| 3164 | |
| 3165 | if (cpi->b_calculate_blockiness) { |
| 3166 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 3167 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 3168 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 3169 | } |
| 3170 | |
| 3171 | if (cpi->b_calculate_consistency) { |
| 3172 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3173 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3174 | (double)cpi->total_inconsistency); |
| 3175 | |
| 3176 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 3177 | SNPRINT2(results, "\t%7.3f", consistency); |
| 3178 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 3179 | } |
Sarah Parker | f97b786 | 2016-08-25 17:42:57 -0700 | [diff] [blame] | 3180 | fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings); |
| 3181 | 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] | 3182 | rate_err, fabs(rate_err)); |
| 3183 | } |
| 3184 | |
| 3185 | fclose(f); |
| 3186 | } |
| 3187 | |
| 3188 | #endif |
| 3189 | |
| 3190 | #if 0 |
| 3191 | { |
| 3192 | printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); |
| 3193 | printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); |
| 3194 | printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, |
| 3195 | cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, |
| 3196 | cpi->time_compress_data / 1000, |
| 3197 | (cpi->time_receive_data + cpi->time_compress_data) / 1000); |
| 3198 | } |
| 3199 | #endif |
| 3200 | } |
| 3201 | |
| 3202 | for (t = 0; t < cpi->num_workers; ++t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3203 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3204 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 3205 | |
| 3206 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3207 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3208 | |
| 3209 | // Deallocate allocated thread data. |
| 3210 | if (t < cpi->num_workers - 1) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3211 | aom_free(thread_data->td->palette_buffer); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3212 | #if CONFIG_MOTION_VAR |
| 3213 | aom_free(thread_data->td->above_pred_buf); |
| 3214 | aom_free(thread_data->td->left_pred_buf); |
| 3215 | aom_free(thread_data->td->wsrc_buf); |
| 3216 | aom_free(thread_data->td->mask_buf); |
| 3217 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3218 | aom_free(thread_data->td->counts); |
| 3219 | av1_free_pc_tree(thread_data->td); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3220 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3221 | } |
| 3222 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3223 | aom_free(cpi->tile_thr_data); |
| 3224 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3225 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3226 | 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] | 3227 | |
| 3228 | dealloc_compressor_data(cpi); |
| 3229 | |
| 3230 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 3231 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3232 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3233 | } |
| 3234 | |
| 3235 | #if CONFIG_FP_MB_STATS |
| 3236 | if (cpi->use_fp_mb_stats) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3237 | aom_free(cpi->twopass.frame_mb_stats_buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3238 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 3239 | } |
| 3240 | #endif |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 3241 | #if CONFIG_INTERNAL_STATS |
| 3242 | aom_free(cpi->ssim_vars); |
| 3243 | cpi->ssim_vars = NULL; |
| 3244 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3245 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3246 | av1_remove_common(cm); |
| 3247 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 3248 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3249 | |
| 3250 | #ifdef OUTPUT_YUV_SKINMAP |
| 3251 | fclose(yuv_skinmap_file); |
| 3252 | #endif |
| 3253 | #ifdef OUTPUT_YUV_REC |
| 3254 | fclose(yuv_rec_file); |
| 3255 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3256 | #if 0 |
| 3257 | |
| 3258 | if (keyfile) |
| 3259 | fclose(keyfile); |
| 3260 | |
| 3261 | if (framepsnr) |
| 3262 | fclose(framepsnr); |
| 3263 | |
| 3264 | if (kf_list) |
| 3265 | fclose(kf_list); |
| 3266 | |
| 3267 | #endif |
| 3268 | } |
| 3269 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3270 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 3271 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3272 | int i; |
| 3273 | PSNR_STATS psnr; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3274 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3275 | aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3276 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
| 3277 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3278 | aom_calc_psnr(cpi->source, cpi->common.frame_to_show, &psnr); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3279 | #endif |
| 3280 | |
| 3281 | for (i = 0; i < 4; ++i) { |
| 3282 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 3283 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 3284 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 3285 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3286 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 3287 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3288 | } |
| 3289 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3290 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3291 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 3292 | |
| 3293 | cpi->ref_frame_flags = ref_frame_flags; |
| 3294 | return 0; |
| 3295 | } |
| 3296 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3297 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags) { |
| 3298 | cpi->ext_refresh_golden_frame = (ref_frame_flags & AOM_GOLD_FLAG) != 0; |
| 3299 | cpi->ext_refresh_alt_ref_frame = (ref_frame_flags & AOM_ALT_FLAG) != 0; |
| 3300 | cpi->ext_refresh_last_frame = (ref_frame_flags & AOM_LAST_FLAG) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3301 | cpi->ext_refresh_frame_flags_pending = 1; |
| 3302 | } |
| 3303 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3304 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3305 | AV1_COMMON *const cm = &cpi->common; |
| 3306 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3307 | if (cfg) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3308 | aom_yv12_copy_frame(cfg, sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3309 | return 0; |
| 3310 | } else { |
| 3311 | return -1; |
| 3312 | } |
| 3313 | } |
| 3314 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3315 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3316 | AV1_COMMON *const cm = &cpi->common; |
| 3317 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3318 | if (cfg) { |
| 3319 | aom_yv12_copy_frame(sd, cfg); |
| 3320 | return 0; |
| 3321 | } else { |
| 3322 | return -1; |
| 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3327 | cpi->ext_refresh_frame_context = update; |
| 3328 | cpi->ext_refresh_frame_context_pending = 1; |
| 3329 | return 0; |
| 3330 | } |
| 3331 | |
| 3332 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 3333 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 3334 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 3335 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 3336 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3337 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3338 | uint8_t *src = s->y_buffer; |
| 3339 | int h = s->y_height; |
| 3340 | |
| 3341 | do { |
| 3342 | fwrite(src, s->y_width, 1, f); |
| 3343 | src += s->y_stride; |
| 3344 | } while (--h); |
| 3345 | |
| 3346 | src = s->u_buffer; |
| 3347 | h = s->uv_height; |
| 3348 | |
| 3349 | do { |
| 3350 | fwrite(src, s->uv_width, 1, f); |
| 3351 | src += s->uv_stride; |
| 3352 | } while (--h); |
| 3353 | |
| 3354 | src = s->v_buffer; |
| 3355 | h = s->uv_height; |
| 3356 | |
| 3357 | do { |
| 3358 | fwrite(src, s->uv_width, 1, f); |
| 3359 | src += s->uv_stride; |
| 3360 | } while (--h); |
| 3361 | } |
| 3362 | #endif |
| 3363 | |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 3364 | #if CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3365 | #if USE_GF16_MULTI_LAYER |
| 3366 | static void check_show_existing_frame_gf16(AV1_COMP *cpi) { |
| 3367 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3368 | AV1_COMMON *const cm = &cpi->common; |
| 3369 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 3370 | gf_group->update_type[gf_group->index]; |
| 3371 | |
| 3372 | if (cm->show_existing_frame == 1) { |
| 3373 | cm->show_existing_frame = 0; |
| 3374 | } else if (cpi->rc.is_last_bipred_frame) { |
| 3375 | cpi->rc.is_last_bipred_frame = 0; |
| 3376 | cm->show_existing_frame = 1; |
| 3377 | cpi->existing_fb_idx_to_show = cpi->bwd_fb_idx; |
| 3378 | } else if (next_frame_update_type == OVERLAY_UPDATE || |
| 3379 | next_frame_update_type == INTNL_OVERLAY_UPDATE) { |
| 3380 | // Check the temporal filtering status for the next OVERLAY frame |
| 3381 | const int num_arfs_in_gf = cpi->num_extra_arfs + 1; |
| 3382 | int which_arf = 0, arf_idx; |
| 3383 | // Identify the index to the next overlay frame. |
| 3384 | for (arf_idx = 0; arf_idx < num_arfs_in_gf; arf_idx++) { |
| 3385 | if (gf_group->index == cpi->arf_pos_for_ovrly[arf_idx]) { |
| 3386 | which_arf = arf_idx; |
| 3387 | break; |
| 3388 | } |
| 3389 | } |
| 3390 | assert(arf_idx < num_arfs_in_gf); |
| 3391 | if (cpi->is_arf_filter_off[which_arf]) { |
| 3392 | cm->show_existing_frame = 1; |
| 3393 | cpi->rc.is_src_frame_alt_ref = 1; |
| 3394 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
| 3395 | ? cpi->alt_fb_idx |
| 3396 | : cpi->bwd_fb_idx; |
| 3397 | cpi->is_arf_filter_off[which_arf] = 0; |
| 3398 | } |
| 3399 | } |
| 3400 | cpi->rc.is_src_frame_ext_arf = 0; |
| 3401 | } |
| 3402 | #endif // USE_GF16_MULTI_LAYER |
| 3403 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3404 | static void check_show_existing_frame(AV1_COMP *cpi) { |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3405 | #if USE_GF16_MULTI_LAYER |
| 3406 | if (cpi->rc.baseline_gf_interval == 16) { |
| 3407 | check_show_existing_frame_gf16(cpi); |
| 3408 | return; |
| 3409 | } |
| 3410 | #endif // USE_GF16_MULTI_LAYER |
| 3411 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3412 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3413 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3414 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 3415 | gf_group->update_type[gf_group->index]; |
| 3416 | const int which_arf = gf_group->arf_update_idx[gf_group->index]; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3417 | |
| 3418 | if (cm->show_existing_frame == 1) { |
| 3419 | cm->show_existing_frame = 0; |
| 3420 | } else if (cpi->rc.is_last_bipred_frame) { |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3421 | // NOTE: If the current frame is a last bi-predictive frame, it is |
| 3422 | // needed next to show the BWDREF_FRAME, which is pointed by |
| 3423 | // the last_fb_idxes[0] after reference frame buffer update |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3424 | cpi->rc.is_last_bipred_frame = 0; |
| 3425 | cm->show_existing_frame = 1; |
| 3426 | cpi->existing_fb_idx_to_show = cpi->lst_fb_idxes[0]; |
| 3427 | } else if (cpi->is_arf_filter_off[which_arf] && |
| 3428 | (next_frame_update_type == OVERLAY_UPDATE || |
| 3429 | next_frame_update_type == INTNL_OVERLAY_UPDATE)) { |
| 3430 | // Other parameters related to OVERLAY_UPDATE will be taken care of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3431 | // in av1_rc_get_second_pass_params(cpi) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3432 | cm->show_existing_frame = 1; |
| 3433 | cpi->rc.is_src_frame_alt_ref = 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3434 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
| 3435 | ? cpi->alt_fb_idx |
| 3436 | : cpi->alt2_fb_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3437 | cpi->is_arf_filter_off[which_arf] = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3438 | } |
| 3439 | cpi->rc.is_src_frame_ext_arf = 0; |
| 3440 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 3441 | #endif // CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3442 | |
| 3443 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3444 | 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] | 3445 | uint8_t *src = s->y_buffer; |
| 3446 | int h = cm->height; |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3447 | if (yuv_rec_file == NULL) return; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3448 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3449 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 3450 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 3451 | |
| 3452 | do { |
| 3453 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 3454 | src16 += s->y_stride; |
| 3455 | } while (--h); |
| 3456 | |
| 3457 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 3458 | h = s->uv_height; |
| 3459 | |
| 3460 | do { |
| 3461 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3462 | src16 += s->uv_stride; |
| 3463 | } while (--h); |
| 3464 | |
| 3465 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 3466 | h = s->uv_height; |
| 3467 | |
| 3468 | do { |
| 3469 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3470 | src16 += s->uv_stride; |
| 3471 | } while (--h); |
| 3472 | |
| 3473 | fflush(yuv_rec_file); |
| 3474 | return; |
| 3475 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3476 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3477 | |
| 3478 | do { |
| 3479 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 3480 | src += s->y_stride; |
| 3481 | } while (--h); |
| 3482 | |
| 3483 | src = s->u_buffer; |
| 3484 | h = s->uv_height; |
| 3485 | |
| 3486 | do { |
| 3487 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3488 | src += s->uv_stride; |
| 3489 | } while (--h); |
| 3490 | |
| 3491 | src = s->v_buffer; |
| 3492 | h = s->uv_height; |
| 3493 | |
| 3494 | do { |
| 3495 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3496 | src += s->uv_stride; |
| 3497 | } while (--h); |
| 3498 | |
| 3499 | fflush(yuv_rec_file); |
| 3500 | } |
| 3501 | #endif // OUTPUT_YUV_REC |
| 3502 | |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3503 | #if CONFIG_GLOBAL_MOTION |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 3504 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3505 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 3506 | int i; |
| 3507 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3508 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3509 | AV1_COMMON *const cm = &cpi->common; |
| 3510 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3511 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3512 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3513 | cpi->gmparams_cost[i]) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3514 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3515 | assert(cm->global_motion[i].wmtype == IDENTITY); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3516 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 3517 | recode = 1; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3518 | recode |= (rdc->global_motion_used[i] > 0); |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3519 | } |
| 3520 | } |
| 3521 | return recode; |
| 3522 | } |
| 3523 | #endif // CONFIG_GLOBAL_MOTION |
| 3524 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3525 | // Function to test for conditions that indicate we should loop |
| 3526 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3527 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 3528 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3529 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3530 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3531 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 3532 | int force_recode = 0; |
| 3533 | |
| 3534 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 3535 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 3536 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3537 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 3538 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 3539 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 3540 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3541 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3542 | // Deal with frame undershoot and whether or not we are |
| 3543 | // below the automatically set cq level. |
| 3544 | if (q > oxcf->cq_level && |
| 3545 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 3546 | force_recode = 1; |
| 3547 | } |
| 3548 | } |
| 3549 | } |
| 3550 | return force_recode; |
| 3551 | } |
| 3552 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3553 | #define DUMP_REF_FRAME_IMAGES 0 |
| 3554 | |
| 3555 | #if DUMP_REF_FRAME_IMAGES == 1 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3556 | static int dump_one_image(AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3557 | const YV12_BUFFER_CONFIG *const ref_buf, |
| 3558 | char *file_name) { |
| 3559 | int h; |
| 3560 | FILE *f_ref = NULL; |
| 3561 | |
| 3562 | if (ref_buf == NULL) { |
| 3563 | printf("Frame data buffer is NULL.\n"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3564 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | if ((f_ref = fopen(file_name, "wb")) == NULL) { |
| 3568 | printf("Unable to open file %s to write.\n", file_name); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3569 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | // --- Y --- |
| 3573 | for (h = 0; h < cm->height; ++h) { |
| 3574 | fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref); |
| 3575 | } |
| 3576 | // --- U --- |
| 3577 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3578 | fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3579 | f_ref); |
| 3580 | } |
| 3581 | // --- V --- |
| 3582 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3583 | fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3584 | f_ref); |
| 3585 | } |
| 3586 | |
| 3587 | fclose(f_ref); |
| 3588 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3589 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3590 | } |
| 3591 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3592 | static void dump_ref_frame_images(AV1_COMP *cpi) { |
| 3593 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3594 | MV_REFERENCE_FRAME ref_frame; |
| 3595 | |
| 3596 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3597 | char file_name[256] = ""; |
| 3598 | snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv", |
| 3599 | cm->current_video_frame, ref_frame); |
| 3600 | dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name); |
| 3601 | } |
| 3602 | } |
| 3603 | #endif // DUMP_REF_FRAME_IMAGES == 1 |
| 3604 | |
| 3605 | #if CONFIG_EXT_REFS |
| 3606 | // This function is used to shift the virtual indices of last reference frames |
| 3607 | // as follows: |
| 3608 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3609 | // when the LAST_FRAME is updated. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3610 | static INLINE void shift_last_ref_frames(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3611 | int ref_frame; |
| 3612 | for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) { |
| 3613 | cpi->lst_fb_idxes[ref_frame] = cpi->lst_fb_idxes[ref_frame - 1]; |
| 3614 | |
| 3615 | // [0] is allocated to the current coded frame. The statistics for the |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3616 | // reference frames start at [LAST_FRAME], i.e. [1]. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3617 | if (!cpi->rc.is_src_frame_alt_ref) { |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3618 | memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME], |
| 3619 | cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME], |
| 3620 | sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3621 | } |
| 3622 | } |
| 3623 | } |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3624 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3625 | |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 3626 | #if CONFIG_VAR_REFS |
| 3627 | static void enc_check_valid_ref_frames(AV1_COMP *const cpi) { |
| 3628 | AV1_COMMON *const cm = &cpi->common; |
| 3629 | MV_REFERENCE_FRAME ref_frame; |
| 3630 | |
| 3631 | // TODO(zoeliu): To handle ALTREF_FRAME the same way as do with other |
| 3632 | // reference frames. Current encoder invalid ALTREF when ALTREF |
| 3633 | // is the same as LAST, but invalid all the other references |
| 3634 | // when they are the same as ALTREF. |
| 3635 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3636 | int ref_buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3637 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 3638 | |
| 3639 | if (ref_buf_idx != INVALID_IDX) { |
| 3640 | ref_buf->is_valid = 1; |
| 3641 | |
| 3642 | MV_REFERENCE_FRAME ref; |
| 3643 | for (ref = LAST_FRAME; ref < ref_frame; ++ref) { |
| 3644 | int buf_idx = get_ref_frame_buf_idx(cpi, ref); |
| 3645 | RefBuffer *const buf = &cm->frame_refs[ref - LAST_FRAME]; |
| 3646 | if (buf->is_valid && buf_idx == ref_buf_idx) { |
| 3647 | if (ref_frame != ALTREF_FRAME || ref == LAST_FRAME) { |
| 3648 | ref_buf->is_valid = 0; |
| 3649 | break; |
| 3650 | } else { |
| 3651 | buf->is_valid = 0; |
| 3652 | } |
| 3653 | } |
| 3654 | } |
| 3655 | } else { |
| 3656 | ref_buf->is_valid = 0; |
| 3657 | } |
| 3658 | } |
| 3659 | } |
| 3660 | #endif // CONFIG_VAR_REFS |
| 3661 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3662 | #if CONFIG_EXT_REFS |
| 3663 | #if USE_GF16_MULTI_LAYER |
| 3664 | static void update_reference_frames_gf16(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3665 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3666 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3667 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3668 | if (cm->frame_type == KEY_FRAME) { |
| 3669 | for (int ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) { |
| 3670 | ref_cnt_fb(pool->frame_bufs, |
| 3671 | &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]], |
| 3672 | cm->new_fb_idx); |
| 3673 | } |
| 3674 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3675 | cm->new_fb_idx); |
| 3676 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3677 | cm->new_fb_idx); |
| 3678 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3679 | cm->new_fb_idx); |
| 3680 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3681 | cm->new_fb_idx); |
| 3682 | } else { |
| 3683 | if (cpi->refresh_last_frame || cpi->refresh_golden_frame || |
| 3684 | cpi->refresh_bwd_ref_frame || cpi->refresh_alt2_ref_frame || |
| 3685 | cpi->refresh_alt_ref_frame) { |
| 3686 | assert(cpi->refresh_fb_idx >= 0 && cpi->refresh_fb_idx < REF_FRAMES); |
| 3687 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->refresh_fb_idx], |
| 3688 | cm->new_fb_idx); |
| 3689 | } |
| 3690 | |
| 3691 | // TODO(zoeliu): To handle cpi->interp_filter_selected[]. |
| 3692 | |
| 3693 | // For GF of 16, an additional ref frame index mapping needs to be handled |
| 3694 | // if this is the last frame to encode in the current GF group. |
| 3695 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3696 | if (gf_group->update_type[gf_group->index + 1] == OVERLAY_UPDATE) |
| 3697 | av1_ref_frame_map_idx_updates(cpi, gf_group->index + 1); |
| 3698 | } |
| 3699 | |
| 3700 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3701 | // Dump out all reference frame images. |
| 3702 | dump_ref_frame_images(cpi); |
| 3703 | #endif // DUMP_REF_FRAME_IMAGES |
| 3704 | } |
| 3705 | #endif // USE_GF16_MULTI_LAYER |
| 3706 | #endif // CONFIG_EXT_REFS |
| 3707 | |
| 3708 | static void update_reference_frames(AV1_COMP *cpi) { |
| 3709 | AV1_COMMON *const cm = &cpi->common; |
| 3710 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3711 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 3712 | // for the purpose to verify no mismatch between encoder and decoder. |
| 3713 | if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx; |
| 3714 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3715 | #if CONFIG_EXT_REFS |
| 3716 | #if USE_GF16_MULTI_LAYER |
| 3717 | if (cpi->rc.baseline_gf_interval == 16) { |
| 3718 | update_reference_frames_gf16(cpi); |
| 3719 | return; |
| 3720 | } |
| 3721 | #endif // USE_GF16_MULTI_LAYER |
| 3722 | #endif // CONFIG_EXT_REFS |
| 3723 | |
| 3724 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3725 | // At this point the new frame has been encoded. |
| 3726 | // If any buffer copy / swapping is signaled it should be done here. |
| 3727 | if (cm->frame_type == KEY_FRAME) { |
| 3728 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3729 | cm->new_fb_idx); |
| 3730 | #if CONFIG_EXT_REFS |
| 3731 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3732 | cm->new_fb_idx); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3733 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3734 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3735 | #endif // CONFIG_EXT_REFS |
| 3736 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3737 | cm->new_fb_idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3738 | } else if (av1_preserve_existing_gf(cpi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3739 | // We have decided to preserve the previously existing golden frame as our |
| 3740 | // new ARF frame. However, in the short term in function |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3741 | // 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] | 3742 | // we're updating the GF with the current decoded frame, we save it to the |
| 3743 | // ARF slot instead. |
| 3744 | // We now have to update the ARF with the current frame and swap gld_fb_idx |
| 3745 | // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF |
| 3746 | // slot and, if we're updating the GF, the current frame becomes the new GF. |
| 3747 | int tmp; |
| 3748 | |
| 3749 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3750 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3751 | tmp = cpi->alt_fb_idx; |
| 3752 | cpi->alt_fb_idx = cpi->gld_fb_idx; |
| 3753 | cpi->gld_fb_idx = tmp; |
| 3754 | |
| 3755 | #if CONFIG_EXT_REFS |
| 3756 | // We need to modify the mapping accordingly |
| 3757 | cpi->arf_map[0] = cpi->alt_fb_idx; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3758 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3759 | // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to |
| 3760 | // cpi->interp_filter_selected[GOLDEN_FRAME]? |
| 3761 | #if CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3762 | } else if (cpi->rc.is_src_frame_ext_arf && cm->show_existing_frame) { |
| 3763 | // Deal with the special case for showing existing internal ALTREF_FRAME |
| 3764 | // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME |
| 3765 | // by updating the virtual indices. |
| 3766 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3767 | const int which_arf = gf_group->arf_ref_idx[gf_group->index]; |
| 3768 | assert(gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3769 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3770 | const int tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3771 | shift_last_ref_frames(cpi); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3772 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3773 | cpi->lst_fb_idxes[0] = cpi->alt2_fb_idx; |
| 3774 | cpi->alt2_fb_idx = tmp; |
| 3775 | // We need to modify the mapping accordingly |
| 3776 | cpi->arf_map[which_arf] = cpi->alt2_fb_idx; |
| 3777 | |
| 3778 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3779 | cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3780 | sizeof(cpi->interp_filter_selected[ALTREF2_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3781 | #endif // CONFIG_EXT_REFS |
| 3782 | } else { /* For non key/golden frames */ |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3783 | // === ALTREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3784 | if (cpi->refresh_alt_ref_frame) { |
| 3785 | int arf_idx = cpi->alt_fb_idx; |
| 3786 | int which_arf = 0; |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 3787 | #if !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3788 | if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { |
| 3789 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3790 | arf_idx = gf_group->arf_update_idx[gf_group->index]; |
| 3791 | } |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 3792 | #endif // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3793 | 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] | 3794 | |
| 3795 | memcpy(cpi->interp_filter_selected[ALTREF_FRAME + which_arf], |
| 3796 | cpi->interp_filter_selected[0], |
| 3797 | sizeof(cpi->interp_filter_selected[0])); |
| 3798 | } |
| 3799 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3800 | // === GOLDEN_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3801 | if (cpi->refresh_golden_frame) { |
| 3802 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3803 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3804 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3805 | #if !CONFIG_EXT_REFS |
| 3806 | if (!cpi->rc.is_src_frame_alt_ref) |
| 3807 | #endif // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3808 | memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], |
| 3809 | cpi->interp_filter_selected[0], |
| 3810 | sizeof(cpi->interp_filter_selected[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3814 | // === BWDREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3815 | if (cpi->refresh_bwd_ref_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3816 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3817 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3818 | |
| 3819 | memcpy(cpi->interp_filter_selected[BWDREF_FRAME], |
| 3820 | cpi->interp_filter_selected[0], |
| 3821 | sizeof(cpi->interp_filter_selected[0])); |
| 3822 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3823 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3824 | // === ALTREF2_FRAME === |
| 3825 | if (cpi->refresh_alt2_ref_frame) { |
| 3826 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3827 | cm->new_fb_idx); |
| 3828 | |
| 3829 | memcpy(cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3830 | cpi->interp_filter_selected[0], |
| 3831 | sizeof(cpi->interp_filter_selected[0])); |
| 3832 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3833 | #endif // CONFIG_EXT_REFS |
| 3834 | } |
| 3835 | |
| 3836 | if (cpi->refresh_last_frame) { |
| 3837 | #if CONFIG_EXT_REFS |
| 3838 | // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame |
| 3839 | // reference to the reference frame buffer virtual index; and then (2) from |
| 3840 | // the virtual index to the reference frame buffer physical index: |
| 3841 | // |
| 3842 | // LAST_FRAME, ..., LAST3_FRAME, ..., ALTREF_FRAME |
| 3843 | // | | | |
| 3844 | // v v v |
| 3845 | // lst_fb_idxes[0], ..., lst_fb_idxes[2], ..., alt_fb_idx |
| 3846 | // | | | |
| 3847 | // v v v |
| 3848 | // ref_frame_map[], ..., ref_frame_map[], ..., ref_frame_map[] |
| 3849 | // |
| 3850 | // When refresh_last_frame is set, it is intended to retire LAST3_FRAME, |
| 3851 | // have the other 2 LAST reference frames shifted as follows: |
| 3852 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3853 | // , and then have LAST_FRAME refreshed by the newly coded frame. |
| 3854 | // |
| 3855 | // To fulfill it, the decoder will be notified to execute following 2 steps: |
| 3856 | // |
| 3857 | // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME |
| 3858 | // to point to the newly coded frame, i.e. |
| 3859 | // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx; |
| 3860 | // |
| 3861 | // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the |
| 3862 | // original virtual index of LAST3_FRAME and have the other mappings |
| 3863 | // shifted as follows: |
| 3864 | // LAST_FRAME, LAST2_FRAME, LAST3_FRAME |
| 3865 | // | | | |
| 3866 | // v v v |
| 3867 | // lst_fb_idxes[2], lst_fb_idxes[0], lst_fb_idxes[1] |
| 3868 | int ref_frame; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3869 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3870 | if (cm->frame_type == KEY_FRAME) { |
| 3871 | for (ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) { |
| 3872 | ref_cnt_fb(pool->frame_bufs, |
| 3873 | &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]], |
| 3874 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3875 | } |
| 3876 | } else { |
| 3877 | int tmp; |
| 3878 | |
| 3879 | ref_cnt_fb(pool->frame_bufs, |
| 3880 | &cm->ref_frame_map[cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]], |
| 3881 | cm->new_fb_idx); |
| 3882 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3883 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3884 | |
| 3885 | shift_last_ref_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3886 | cpi->lst_fb_idxes[0] = tmp; |
| 3887 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3888 | assert(cm->show_existing_frame == 0); |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3889 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3890 | cpi->interp_filter_selected[0], |
| 3891 | sizeof(cpi->interp_filter_selected[0])); |
Zoe Liu | aff92d5 | 2017-07-11 21:35:08 -0700 | [diff] [blame] | 3892 | |
| 3893 | if (cpi->rc.is_last_bipred_frame) { |
| 3894 | // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the |
| 3895 | // LAST3_FRAME by updating the virtual indices. |
| 3896 | // |
| 3897 | // NOTE: The source frame for BWDREF does not have a holding position as |
| 3898 | // the OVERLAY frame for ALTREF's. Hence, to resolve the reference |
| 3899 | // virtual index reshuffling for BWDREF, the encoder always |
| 3900 | // specifies a LAST_BIPRED right before BWDREF and completes the |
| 3901 | // reshuffling job accordingly. |
| 3902 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3903 | |
| 3904 | shift_last_ref_frames(cpi); |
| 3905 | cpi->lst_fb_idxes[0] = cpi->bwd_fb_idx; |
| 3906 | cpi->bwd_fb_idx = tmp; |
| 3907 | |
| 3908 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3909 | cpi->interp_filter_selected[BWDREF_FRAME], |
| 3910 | sizeof(cpi->interp_filter_selected[BWDREF_FRAME])); |
| 3911 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3912 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3913 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3914 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->lst_fb_idx], |
| 3915 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3916 | if (!cpi->rc.is_src_frame_alt_ref) { |
| 3917 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3918 | cpi->interp_filter_selected[0], |
| 3919 | sizeof(cpi->interp_filter_selected[0])); |
| 3920 | } |
| 3921 | #endif // CONFIG_EXT_REFS |
| 3922 | } |
| 3923 | |
| 3924 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3925 | // Dump out all reference frame images. |
| 3926 | dump_ref_frame_images(cpi); |
| 3927 | #endif // DUMP_REF_FRAME_IMAGES |
| 3928 | } |
| 3929 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3930 | 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] | 3931 | assert(buffer_idx != INVALID_IDX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3932 | RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 3933 | ensure_mv_buffer(new_fb_ptr, cm); |
| 3934 | new_fb_ptr->width = cm->width; |
| 3935 | new_fb_ptr->height = cm->height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3936 | } |
| 3937 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3938 | static void scale_references(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3939 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3940 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3941 | const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = { |
| 3942 | AOM_LAST_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3943 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3944 | AOM_LAST2_FLAG, |
| 3945 | AOM_LAST3_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3946 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3947 | AOM_GOLD_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3948 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3949 | AOM_BWD_FLAG, |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3950 | AOM_ALT2_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3951 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3952 | AOM_ALT_FLAG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3953 | }; |
| 3954 | |
| 3955 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3956 | // 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] | 3957 | if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 3958 | BufferPool *const pool = cm->buffer_pool; |
| 3959 | const YV12_BUFFER_CONFIG *const ref = |
| 3960 | get_ref_frame_buffer(cpi, ref_frame); |
| 3961 | |
| 3962 | if (ref == NULL) { |
| 3963 | cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3964 | continue; |
| 3965 | } |
| 3966 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3967 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3968 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3969 | RefCntBuffer *new_fb_ptr = NULL; |
| 3970 | int force_scaling = 0; |
| 3971 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3972 | if (new_fb == INVALID_IDX) { |
| 3973 | new_fb = get_free_fb(cm); |
| 3974 | force_scaling = 1; |
| 3975 | } |
| 3976 | if (new_fb == INVALID_IDX) return; |
| 3977 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3978 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3979 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3980 | if (aom_realloc_frame_buffer( |
| 3981 | &new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x, |
| 3982 | cm->subsampling_y, cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 3983 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3984 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3985 | "Failed to allocate frame buffer"); |
Debargha Mukherjee | 405c857 | 2017-07-10 09:29:17 -0700 | [diff] [blame] | 3986 | av1_resize_and_extend_frame(ref, &new_fb_ptr->buf, |
| 3987 | (int)cm->bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3988 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3989 | alloc_frame_mvs(cm, new_fb); |
| 3990 | } |
| 3991 | #else |
| 3992 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3993 | RefCntBuffer *new_fb_ptr = NULL; |
| 3994 | int force_scaling = 0; |
| 3995 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3996 | if (new_fb == INVALID_IDX) { |
| 3997 | new_fb = get_free_fb(cm); |
| 3998 | force_scaling = 1; |
| 3999 | } |
| 4000 | if (new_fb == INVALID_IDX) return; |
| 4001 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 4002 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 4003 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4004 | 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] | 4005 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 4006 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
| 4007 | NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4008 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4009 | "Failed to allocate frame buffer"); |
Debargha Mukherjee | 405c857 | 2017-07-10 09:29:17 -0700 | [diff] [blame] | 4010 | av1_resize_and_extend_frame(ref, &new_fb_ptr->buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4011 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 4012 | alloc_frame_mvs(cm, new_fb); |
| 4013 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4014 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4015 | } else { |
| 4016 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 4017 | RefCntBuffer *const buf = &pool->frame_bufs[buf_idx]; |
| 4018 | buf->buf.y_crop_width = ref->y_crop_width; |
| 4019 | buf->buf.y_crop_height = ref->y_crop_height; |
| 4020 | cpi->scaled_ref_idx[ref_frame - 1] = buf_idx; |
| 4021 | ++buf->ref_count; |
| 4022 | } |
| 4023 | } else { |
| 4024 | if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 4025 | } |
| 4026 | } |
| 4027 | } |
| 4028 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4029 | static void release_scaled_references(AV1_COMP *cpi) { |
| 4030 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4031 | int i; |
| 4032 | if (cpi->oxcf.pass == 0) { |
| 4033 | // Only release scaled references under certain conditions: |
| 4034 | // if reference will be updated, or if scaled reference has same resolution. |
| 4035 | int refresh[INTER_REFS_PER_FRAME]; |
| 4036 | refresh[0] = (cpi->refresh_last_frame) ? 1 : 0; |
| 4037 | #if CONFIG_EXT_REFS |
| 4038 | refresh[1] = refresh[2] = 0; |
| 4039 | refresh[3] = (cpi->refresh_golden_frame) ? 1 : 0; |
| 4040 | refresh[4] = (cpi->refresh_bwd_ref_frame) ? 1 : 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4041 | refresh[5] = (cpi->refresh_alt2_ref_frame) ? 1 : 0; |
| 4042 | refresh[6] = (cpi->refresh_alt_ref_frame) ? 1 : 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4043 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4044 | refresh[1] = (cpi->refresh_golden_frame) ? 1 : 0; |
| 4045 | refresh[2] = (cpi->refresh_alt_ref_frame) ? 1 : 0; |
| 4046 | #endif // CONFIG_EXT_REFS |
| 4047 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 4048 | const int idx = cpi->scaled_ref_idx[i - 1]; |
| 4049 | RefCntBuffer *const buf = |
| 4050 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 4051 | const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, i); |
| 4052 | if (buf != NULL && |
| 4053 | (refresh[i - 1] || (buf->buf.y_crop_width == ref->y_crop_width && |
| 4054 | buf->buf.y_crop_height == ref->y_crop_height))) { |
| 4055 | --buf->ref_count; |
| 4056 | cpi->scaled_ref_idx[i - 1] = INVALID_IDX; |
| 4057 | } |
| 4058 | } |
| 4059 | } else { |
| 4060 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) { |
| 4061 | const int idx = cpi->scaled_ref_idx[i]; |
| 4062 | RefCntBuffer *const buf = |
| 4063 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 4064 | if (buf != NULL) { |
| 4065 | --buf->ref_count; |
| 4066 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 4067 | } |
| 4068 | } |
| 4069 | } |
| 4070 | } |
| 4071 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4072 | #if 0 && CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4073 | static void output_frame_level_debug_stats(AV1_COMP *cpi) { |
| 4074 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4075 | FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); |
| 4076 | int64_t recon_err; |
| 4077 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4078 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4079 | |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4080 | 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] | 4081 | |
| 4082 | if (cpi->twopass.total_left_stats.coded_error != 0.0) |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 4083 | fprintf(f, "%10u %dx%d %d %d %10d %10d %10d %10d" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4084 | "%10"PRId64" %10"PRId64" %5d %5d %10"PRId64" " |
| 4085 | "%10"PRId64" %10"PRId64" %10d " |
| 4086 | "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" |
| 4087 | "%6d %6d %5d %5d %5d " |
| 4088 | "%10"PRId64" %10.3lf" |
| 4089 | "%10lf %8u %10"PRId64" %10d %10d %10d\n", |
| 4090 | cpi->common.current_video_frame, |
| 4091 | cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4092 | cpi->rc.source_alt_ref_pending, |
| 4093 | cpi->rc.source_alt_ref_active, |
| 4094 | cpi->rc.this_frame_target, |
| 4095 | cpi->rc.projected_frame_size, |
| 4096 | cpi->rc.projected_frame_size / cpi->common.MBs, |
| 4097 | (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), |
| 4098 | cpi->rc.vbr_bits_off_target, |
| 4099 | cpi->rc.vbr_bits_off_target_fast, |
| 4100 | cpi->twopass.extend_minq, |
| 4101 | cpi->twopass.extend_minq_fast, |
| 4102 | cpi->rc.total_target_vs_actual, |
| 4103 | (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), |
| 4104 | cpi->rc.total_actual_bits, cm->base_qindex, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4105 | av1_convert_qindex_to_q(cm->base_qindex, cm->bit_depth), |
| 4106 | (double)av1_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0, |
| 4107 | av1_convert_qindex_to_q(cpi->twopass.active_worst_quality, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4108 | cm->bit_depth), |
| 4109 | cpi->rc.avg_q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4110 | av1_convert_qindex_to_q(cpi->oxcf.cq_level, cm->bit_depth), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4111 | cpi->refresh_last_frame, cpi->refresh_golden_frame, |
| 4112 | cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, |
| 4113 | cpi->twopass.bits_left, |
| 4114 | cpi->twopass.total_left_stats.coded_error, |
| 4115 | cpi->twopass.bits_left / |
| 4116 | (1 + cpi->twopass.total_left_stats.coded_error), |
| 4117 | cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost, |
| 4118 | cpi->twopass.kf_zeromotion_pct, |
| 4119 | cpi->twopass.fr_content_type); |
| 4120 | |
| 4121 | fclose(f); |
| 4122 | |
| 4123 | if (0) { |
| 4124 | FILE *const fmodes = fopen("Modes.stt", "a"); |
| 4125 | int i; |
| 4126 | |
| 4127 | fprintf(fmodes, "%6d:%1d:%1d:%1d ", cpi->common.current_video_frame, |
| 4128 | cm->frame_type, cpi->refresh_golden_frame, |
| 4129 | cpi->refresh_alt_ref_frame); |
| 4130 | |
| 4131 | for (i = 0; i < MAX_MODES; ++i) |
| 4132 | fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]); |
| 4133 | |
| 4134 | fprintf(fmodes, "\n"); |
| 4135 | |
| 4136 | fclose(fmodes); |
| 4137 | } |
| 4138 | } |
| 4139 | #endif |
| 4140 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4141 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 4142 | const AV1_COMMON *const cm = &cpi->common; |
| 4143 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4144 | |
| 4145 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4146 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4147 | |
| 4148 | if (cpi->sf.mv.auto_mv_step_size) { |
| 4149 | if (frame_is_intra_only(cm)) { |
| 4150 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 4151 | // after a key/intra-only frame. |
| 4152 | cpi->max_mv_magnitude = max_mv_def; |
| 4153 | } else { |
| 4154 | if (cm->show_frame) { |
| 4155 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 4156 | // in the previous frame, capped by the default max_mv_magnitude based |
| 4157 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4158 | cpi->mv_step_param = av1_init_search_range( |
| 4159 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4160 | } |
| 4161 | cpi->max_mv_magnitude = 0; |
| 4162 | } |
| 4163 | } |
| 4164 | } |
| 4165 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4166 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4167 | #if CONFIG_GLOBAL_MOTION |
| 4168 | int i; |
| 4169 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 4170 | cpi->common.global_motion[i] = default_warp_params; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4171 | } |
| 4172 | cpi->global_motion_search_done = 0; |
| 4173 | #endif // CONFIG_GLOBAL_MOTION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4174 | av1_set_speed_features_framesize_independent(cpi); |
| 4175 | av1_set_rd_speed_thresholds(cpi); |
| 4176 | av1_set_rd_speed_thresholds_sub8x8(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4177 | cpi->common.interp_filter = cpi->sf.default_interp_filter; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 4178 | if (!frame_is_intra_only(&cpi->common)) set_compound_tools(&cpi->common); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4179 | } |
| 4180 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4181 | 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] | 4182 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4183 | AV1_COMMON *const cm = &cpi->common; |
| 4184 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4185 | |
| 4186 | // Setup variables that depend on the dimensions of the frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4187 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4188 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4189 | // Decide q and q bounds. |
| 4190 | #if CONFIG_XIPHRC |
| 4191 | int frame_type = cm->frame_type == KEY_FRAME ? OD_I_FRAME : OD_P_FRAME; |
| 4192 | *q = od_enc_rc_select_quantizers_and_lambdas( |
| 4193 | &cpi->od_rc, cpi->refresh_golden_frame, cpi->refresh_alt_ref_frame, |
| 4194 | frame_type, bottom_index, top_index); |
| 4195 | #else |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4196 | *q = av1_rc_pick_q_and_bounds(cpi, cm->width, cm->height, bottom_index, |
| 4197 | top_index); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4198 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4199 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 4200 | if (!frame_is_intra_only(cm)) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4201 | #if CONFIG_AMVR |
| 4202 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH, |
| 4203 | cpi->common.cur_frame_mv_precision_level); |
| 4204 | #else |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4205 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4206 | #endif |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 4207 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4208 | |
| 4209 | // Configure experimental use of segmentation for enhanced coding of |
| 4210 | // static regions if indicated. |
| 4211 | // Only allowed in the second pass of a two pass encode, as it requires |
| 4212 | // lagged coding, and if the relevant speed feature flag is set. |
| 4213 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 4214 | configure_static_seg_features(cpi); |
| 4215 | } |
| 4216 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4217 | static void init_motion_estimation(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4218 | int y_stride = cpi->scaled_source.y_stride; |
| 4219 | |
| 4220 | if (cpi->sf.mv.search_method == NSTEP) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4221 | av1_init3smotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4222 | } else if (cpi->sf.mv.search_method == DIAMOND) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4223 | av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4224 | } |
| 4225 | } |
| 4226 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4227 | #if CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4228 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
| 4229 | static void set_restoration_tilesize(int width, int height, int sx, int sy, |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4230 | RestorationInfo *rst) { |
| 4231 | (void)width; |
| 4232 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4233 | (void)sx; |
| 4234 | (void)sy; |
| 4235 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 4236 | int s = AOMMIN(sx, sy); |
| 4237 | #else |
| 4238 | int s = 0; |
| 4239 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 4240 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4241 | rst[0].restoration_tilesize = (RESTORATION_TILESIZE_MAX >> 1); |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4242 | rst[1].restoration_tilesize = rst[0].restoration_tilesize >> s; |
| 4243 | rst[2].restoration_tilesize = rst[1].restoration_tilesize; |
Debargha Mukherjee | 7a5587a | 2017-08-31 07:41:30 -0700 | [diff] [blame] | 4244 | |
| 4245 | rst[0].procunit_width = rst[0].procunit_height = RESTORATION_PROC_UNIT_SIZE; |
| 4246 | rst[1].procunit_width = rst[2].procunit_width = |
| 4247 | RESTORATION_PROC_UNIT_SIZE >> sx; |
| 4248 | rst[1].procunit_height = rst[2].procunit_height = |
| 4249 | RESTORATION_PROC_UNIT_SIZE >> sy; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4250 | } |
| 4251 | #endif // CONFIG_LOOP_RESTORATION |
| 4252 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4253 | static void init_ref_frame_bufs(AV1_COMMON *cm) { |
| 4254 | int i; |
| 4255 | BufferPool *const pool = cm->buffer_pool; |
| 4256 | cm->new_fb_idx = INVALID_IDX; |
| 4257 | for (i = 0; i < REF_FRAMES; ++i) { |
| 4258 | cm->ref_frame_map[i] = INVALID_IDX; |
| 4259 | pool->frame_bufs[i].ref_count = 0; |
| 4260 | } |
| 4261 | #if CONFIG_HASH_ME |
| 4262 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 4263 | av1_hash_table_init(&pool->frame_bufs[i].hash_table); |
| 4264 | } |
| 4265 | #endif |
| 4266 | } |
| 4267 | |
| 4268 | static void check_initial_width(AV1_COMP *cpi, |
| 4269 | #if CONFIG_HIGHBITDEPTH |
| 4270 | int use_highbitdepth, |
| 4271 | #endif |
| 4272 | int subsampling_x, int subsampling_y) { |
| 4273 | AV1_COMMON *const cm = &cpi->common; |
| 4274 | |
| 4275 | if (!cpi->initial_width || |
| 4276 | #if CONFIG_HIGHBITDEPTH |
| 4277 | cm->use_highbitdepth != use_highbitdepth || |
| 4278 | #endif |
| 4279 | cm->subsampling_x != subsampling_x || |
| 4280 | cm->subsampling_y != subsampling_y) { |
| 4281 | cm->subsampling_x = subsampling_x; |
| 4282 | cm->subsampling_y = subsampling_y; |
| 4283 | #if CONFIG_HIGHBITDEPTH |
| 4284 | cm->use_highbitdepth = use_highbitdepth; |
| 4285 | #endif |
| 4286 | |
| 4287 | alloc_raw_frame_buffers(cpi); |
| 4288 | init_ref_frame_bufs(cm); |
| 4289 | alloc_util_frame_buffers(cpi); |
| 4290 | |
| 4291 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 4292 | |
| 4293 | cpi->initial_width = cm->width; |
| 4294 | cpi->initial_height = cm->height; |
| 4295 | cpi->initial_mbs = cm->MBs; |
| 4296 | } |
| 4297 | } |
| 4298 | |
| 4299 | // Returns 1 if the assigned width or height was <= 0. |
| 4300 | static int set_size_literal(AV1_COMP *cpi, int width, int height) { |
| 4301 | AV1_COMMON *cm = &cpi->common; |
| 4302 | #if CONFIG_HIGHBITDEPTH |
| 4303 | check_initial_width(cpi, cm->use_highbitdepth, cm->subsampling_x, |
| 4304 | cm->subsampling_y); |
| 4305 | #else |
| 4306 | check_initial_width(cpi, cm->subsampling_x, cm->subsampling_y); |
| 4307 | #endif // CONFIG_HIGHBITDEPTH |
| 4308 | |
| 4309 | if (width <= 0 || height <= 0) return 1; |
| 4310 | |
| 4311 | cm->width = width; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4312 | cm->height = height; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4313 | |
| 4314 | if (cpi->initial_width && cpi->initial_height && |
| 4315 | (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) { |
| 4316 | av1_free_context_buffers(cm); |
| 4317 | av1_free_pc_tree(&cpi->td); |
| 4318 | alloc_compressor_data(cpi); |
| 4319 | realloc_segmentation_maps(cpi); |
| 4320 | cpi->initial_width = cpi->initial_height = 0; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4321 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4322 | update_frame_size(cpi); |
| 4323 | |
| 4324 | return 0; |
| 4325 | } |
| 4326 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4327 | static void set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4328 | AV1_COMMON *const cm = &cpi->common; |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4329 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4330 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4331 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4332 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 4333 | // There has been a change in the encoded frame size |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4334 | set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4335 | set_mv_search_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4336 | } |
| 4337 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 4338 | #if !CONFIG_XIPHRC |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4339 | if (cpi->oxcf.pass == 2) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4340 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4341 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 4342 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4343 | |
| 4344 | alloc_frame_mvs(cm, cm->new_fb_idx); |
| 4345 | |
| 4346 | // Reset the frame pointers to the current frame size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4347 | 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] | 4348 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4349 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4350 | cm->use_highbitdepth, |
| 4351 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 4352 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 4353 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4354 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4355 | "Failed to allocate frame buffer"); |
| 4356 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4357 | #if CONFIG_LOOP_RESTORATION |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4358 | set_restoration_tilesize( |
| 4359 | #if CONFIG_FRAME_SUPERRES |
| 4360 | cm->superres_upscaled_width, cm->superres_upscaled_height, |
| 4361 | #else |
| 4362 | cm->width, cm->height, |
| 4363 | #endif // CONFIG_FRAME_SUPERRES |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4364 | cm->subsampling_x, cm->subsampling_y, cm->rst_info); |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4365 | for (int i = 0; i < MAX_MB_PLANE; ++i) |
| 4366 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
| 4367 | av1_alloc_restoration_buffers(cm); |
| 4368 | for (int i = 0; i < MAX_MB_PLANE; ++i) { |
| 4369 | cpi->rst_search[i].restoration_tilesize = |
| 4370 | cm->rst_info[i].restoration_tilesize; |
Debargha Mukherjee | 7a5587a | 2017-08-31 07:41:30 -0700 | [diff] [blame] | 4371 | cpi->rst_search[i].procunit_width = cm->rst_info[i].procunit_width; |
| 4372 | cpi->rst_search[i].procunit_height = cm->rst_info[i].procunit_height; |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4373 | av1_alloc_restoration_struct(cm, &cpi->rst_search[i], |
| 4374 | #if CONFIG_FRAME_SUPERRES |
| 4375 | cm->superres_upscaled_width, |
| 4376 | cm->superres_upscaled_height); |
| 4377 | #else |
| 4378 | cm->width, cm->height); |
| 4379 | #endif // CONFIG_FRAME_SUPERRES |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4380 | } |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4381 | #endif // CONFIG_LOOP_RESTORATION |
| 4382 | alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4383 | init_motion_estimation(cpi); |
| 4384 | |
| 4385 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4386 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 4387 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 4388 | |
| 4389 | ref_buf->idx = buf_idx; |
| 4390 | |
| 4391 | if (buf_idx != INVALID_IDX) { |
| 4392 | YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf; |
| 4393 | ref_buf->buf = buf; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4394 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4395 | av1_setup_scale_factors_for_frame( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4396 | &ref_buf->sf, buf->y_crop_width, buf->y_crop_height, cm->width, |
| 4397 | cm->height, (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0); |
| 4398 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4399 | av1_setup_scale_factors_for_frame(&ref_buf->sf, buf->y_crop_width, |
| 4400 | buf->y_crop_height, cm->width, |
| 4401 | cm->height); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4402 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4403 | if (av1_is_scaled(&ref_buf->sf)) aom_extend_frame_borders(buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4404 | } else { |
| 4405 | ref_buf->buf = NULL; |
| 4406 | } |
| 4407 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 4408 | |
| 4409 | #if CONFIG_VAR_REFS |
| 4410 | // Check duplicate reference frames |
| 4411 | enc_check_valid_ref_frames(cpi); |
| 4412 | #endif // CONFIG_VAR_REFS |
| 4413 | |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 4414 | #if CONFIG_INTRABC |
| 4415 | #if CONFIG_HIGHBITDEPTH |
Sebastien Alaiwan | 1dcb707 | 2017-05-12 11:13:05 +0200 | [diff] [blame] | 4416 | av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height, |
| 4417 | cm->width, cm->height, |
| 4418 | cm->use_highbitdepth); |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 4419 | #else |
| 4420 | av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height, |
| 4421 | cm->width, cm->height); |
| 4422 | #endif // CONFIG_HIGHBITDEPTH |
| 4423 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4424 | |
| 4425 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 4426 | } |
| 4427 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4428 | static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) { |
| 4429 | // Choose an arbitrary random number |
| 4430 | static unsigned int seed = 56789; |
| 4431 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4432 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 4433 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4434 | |
| 4435 | switch (oxcf->resize_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4436 | case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4437 | case RESIZE_FIXED: |
| 4438 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4439 | new_denom = oxcf->resize_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4440 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4441 | new_denom = oxcf->resize_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4442 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4443 | case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4444 | default: assert(0); |
| 4445 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4446 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | #if CONFIG_FRAME_SUPERRES |
Urvang Joshi | e58b564 | 2017-10-05 17:59:43 -0700 | [diff] [blame] | 4450 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4451 | static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) { |
| 4452 | // Choose an arbitrary random number |
| 4453 | static unsigned int seed = 34567; |
| 4454 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4455 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 4456 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4457 | int bottom_index, top_index, q, qthresh; |
| 4458 | |
| 4459 | switch (oxcf->superres_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4460 | case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4461 | case SUPERRES_FIXED: |
| 4462 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4463 | new_denom = oxcf->superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4464 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4465 | new_denom = oxcf->superres_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4466 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4467 | case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4468 | case SUPERRES_QTHRESH: |
| 4469 | qthresh = (cpi->common.frame_type == KEY_FRAME ? oxcf->superres_kf_qthresh |
| 4470 | : oxcf->superres_qthresh); |
| 4471 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
| 4472 | q = av1_rc_pick_q_and_bounds(cpi, cpi->oxcf.width, cpi->oxcf.height, |
| 4473 | &bottom_index, &top_index); |
| 4474 | if (q < qthresh) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4475 | new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4476 | } else { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4477 | new_denom = SCALE_NUMERATOR + 1 + ((q - qthresh) >> 3); |
| 4478 | new_denom = AOMMIN(SCALE_NUMERATOR << 1, new_denom); |
| 4479 | // printf("SUPERRES: q %d, qthresh %d: denom %d\n", q, qthresh, |
| 4480 | // new_denom); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4481 | } |
| 4482 | break; |
| 4483 | default: assert(0); |
| 4484 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4485 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4486 | } |
| 4487 | |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4488 | static int dimension_is_ok(int orig_dim, int resized_dim, int denom) { |
| 4489 | return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2); |
| 4490 | } |
| 4491 | |
| 4492 | static int dimensions_are_ok(int owidth, int oheight, size_params_type *rsz) { |
| 4493 | return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom) && |
Urvang Joshi | e58b564 | 2017-10-05 17:59:43 -0700 | [diff] [blame] | 4494 | (SCALE_HORIZONTAL_ONLY || |
| 4495 | dimension_is_ok(oheight, rsz->resize_height, rsz->superres_denom)); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4496 | } |
| 4497 | |
| 4498 | #define DIVIDE_AND_ROUND(x, y) (((x) + ((y) >> 1)) / (y)) |
| 4499 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4500 | static int validate_size_scales(RESIZE_MODE resize_mode, |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4501 | SUPERRES_MODE superres_mode, int owidth, |
| 4502 | int oheight, size_params_type *rsz) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4503 | if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4504 | return 1; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4505 | } |
| 4506 | |
Urvang Joshi | e58b564 | 2017-10-05 17:59:43 -0700 | [diff] [blame] | 4507 | // Calculate current resize scale. |
| 4508 | #if SCALE_HORIZONTAL_ONLY |
| 4509 | int resize_denom = |
| 4510 | DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width); |
| 4511 | #else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4512 | int resize_denom = |
| 4513 | AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width), |
| 4514 | DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height)); |
Urvang Joshi | e58b564 | 2017-10-05 17:59:43 -0700 | [diff] [blame] | 4515 | #endif // SCALE_HORIZONTAL_ONLY |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4516 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4517 | if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4518 | // Alter superres scale as needed to enforce conformity. |
| 4519 | rsz->superres_denom = |
| 4520 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom; |
| 4521 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4522 | if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4523 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4524 | } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4525 | // Alter resize scale as needed to enforce conformity. |
| 4526 | resize_denom = |
| 4527 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4528 | rsz->resize_width = owidth; |
| 4529 | rsz->resize_height = oheight; |
| 4530 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4531 | resize_denom); |
| 4532 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4533 | if (resize_denom > SCALE_NUMERATOR) { |
| 4534 | --resize_denom; |
| 4535 | rsz->resize_width = owidth; |
| 4536 | rsz->resize_height = oheight; |
| 4537 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
| 4538 | resize_denom); |
| 4539 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4540 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4541 | } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4542 | // Alter both resize and superres scales as needed to enforce conformity. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4543 | do { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4544 | if (resize_denom > rsz->superres_denom) |
| 4545 | --resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4546 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4547 | --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4548 | rsz->resize_width = owidth; |
| 4549 | rsz->resize_height = oheight; |
| 4550 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4551 | resize_denom); |
| 4552 | } while (!dimensions_are_ok(owidth, oheight, rsz) && |
| 4553 | (resize_denom > SCALE_NUMERATOR || |
| 4554 | rsz->superres_denom > SCALE_NUMERATOR)); |
| 4555 | } else { // We are allowed to alter neither resize scale nor superres scale. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4556 | return 0; |
| 4557 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4558 | return dimensions_are_ok(owidth, oheight, rsz); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4559 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4560 | #undef DIVIDE_AND_ROUND |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4561 | #endif // CONFIG_FRAME_SUPERRES |
| 4562 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4563 | // Calculates resize and superres params for next frame |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4564 | size_params_type av1_calculate_next_size_params(AV1_COMP *cpi) { |
| 4565 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
| 4566 | size_params_type rsz = { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4567 | oxcf->width, |
| 4568 | oxcf->height, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4569 | #if CONFIG_FRAME_SUPERRES |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4570 | SCALE_NUMERATOR |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4571 | #endif // CONFIG_FRAME_SUPERRES |
| 4572 | }; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4573 | int resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4574 | if (oxcf->pass == 1) return rsz; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4575 | if (cpi->resize_pending_width && cpi->resize_pending_height) { |
| 4576 | rsz.resize_width = cpi->resize_pending_width; |
| 4577 | rsz.resize_height = cpi->resize_pending_height; |
| 4578 | cpi->resize_pending_width = cpi->resize_pending_height = 0; |
| 4579 | } else { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4580 | resize_denom = calculate_next_resize_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4581 | rsz.resize_width = cpi->oxcf.width; |
| 4582 | rsz.resize_height = cpi->oxcf.height; |
| 4583 | av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4584 | resize_denom); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4585 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4586 | #if CONFIG_FRAME_SUPERRES |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4587 | rsz.superres_denom = calculate_next_superres_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4588 | if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width, |
| 4589 | oxcf->height, &rsz)) |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4590 | assert(0 && "Invalid scale parameters"); |
| 4591 | #endif // CONFIG_FRAME_SUPERRES |
| 4592 | return rsz; |
| 4593 | } |
| 4594 | |
| 4595 | 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] | 4596 | int encode_width = rsz->resize_width; |
| 4597 | int encode_height = rsz->resize_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4598 | |
| 4599 | #if CONFIG_FRAME_SUPERRES |
| 4600 | AV1_COMMON *cm = &cpi->common; |
| 4601 | cm->superres_upscaled_width = encode_width; |
| 4602 | cm->superres_upscaled_height = encode_height; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4603 | cm->superres_scale_denominator = rsz->superres_denom; |
| 4604 | av1_calculate_scaled_size(&encode_width, &encode_height, rsz->superres_denom); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4605 | #endif // CONFIG_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4606 | set_frame_size(cpi, encode_width, encode_height); |
| 4607 | } |
| 4608 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4609 | static void setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4610 | size_params_type rsz = av1_calculate_next_size_params(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4611 | setup_frame_size_from_params(cpi, &rsz); |
| 4612 | } |
| 4613 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4614 | #if CONFIG_FRAME_SUPERRES |
| 4615 | static void superres_post_encode(AV1_COMP *cpi) { |
| 4616 | AV1_COMMON *cm = &cpi->common; |
| 4617 | |
| 4618 | if (av1_superres_unscaled(cm)) return; |
| 4619 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4620 | av1_superres_upscale(cm, NULL); |
| 4621 | |
| 4622 | // If regular resizing is occurring the source will need to be downscaled to |
| 4623 | // match the upscaled superres resolution. Otherwise the original source is |
| 4624 | // used. |
| 4625 | if (av1_resize_unscaled(cm)) { |
| 4626 | cpi->source = cpi->unscaled_source; |
| 4627 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 4628 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 4629 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 4630 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4631 | // Do downscale. cm->(width|height) has been updated by av1_superres_upscale |
| 4632 | if (aom_realloc_frame_buffer( |
| 4633 | &cpi->scaled_source, cm->superres_upscaled_width, |
| 4634 | cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y, |
| 4635 | #if CONFIG_HIGHBITDEPTH |
| 4636 | cm->use_highbitdepth, |
| 4637 | #endif // CONFIG_HIGHBITDEPTH |
| 4638 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
| 4639 | aom_internal_error( |
| 4640 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 4641 | "Failed to reallocate scaled source buffer for superres"); |
| 4642 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 4643 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
| 4644 | #if CONFIG_HIGHBITDEPTH |
| 4645 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
| 4646 | (int)cm->bit_depth); |
| 4647 | #else |
| 4648 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source); |
| 4649 | #endif // CONFIG_HIGHBITDEPTH |
| 4650 | cpi->source = &cpi->scaled_source; |
| 4651 | } |
| 4652 | } |
| 4653 | #endif // CONFIG_FRAME_SUPERRES |
| 4654 | |
| 4655 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
| 4656 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
| 4657 | struct loopfilter *lf = &cm->lf; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4658 | int no_loopfilter = 0; |
| 4659 | |
| 4660 | if (is_lossless_requested(&cpi->oxcf)) no_loopfilter = 1; |
| 4661 | |
| 4662 | #if CONFIG_EXT_TILE |
| 4663 | // 0 loopfilter level is only necessary if individual tile |
| 4664 | // decoding is required. |
| 4665 | if (cm->single_tile_decoding) no_loopfilter = 1; |
| 4666 | #endif // CONFIG_EXT_TILE |
| 4667 | |
| 4668 | if (no_loopfilter) { |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4669 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4670 | lf->filter_level[0] = 0; |
| 4671 | lf->filter_level[1] = 0; |
| 4672 | #else |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4673 | lf->filter_level = 0; |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4674 | #endif |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4675 | } else { |
| 4676 | struct aom_usec_timer timer; |
| 4677 | |
| 4678 | aom_clear_system_state(); |
| 4679 | |
| 4680 | aom_usec_timer_start(&timer); |
| 4681 | |
| 4682 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
| 4683 | |
| 4684 | aom_usec_timer_mark(&timer); |
| 4685 | cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer); |
| 4686 | } |
| 4687 | |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 4688 | #if !CONFIG_LPF_SB |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4689 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4690 | if (lf->filter_level[0] || lf->filter_level[1]) |
| 4691 | #else |
| 4692 | if (lf->filter_level > 0) |
| 4693 | #endif |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 4694 | #endif // CONFIG_LPF_SB |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4695 | { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4696 | #if CONFIG_VAR_TX || CONFIG_EXT_PARTITION || CONFIG_CB4X4 |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 4697 | #if CONFIG_LPF_SB |
| 4698 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0, 0, |
| 4699 | 0); |
| 4700 | #else |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4701 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4702 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level[0], |
| 4703 | lf->filter_level[1], 0, 0); |
| 4704 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_u, |
| 4705 | lf->filter_level_u, 1, 0); |
| 4706 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_v, |
| 4707 | lf->filter_level_v, 2, 0); |
| 4708 | |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 4709 | #else |
| 4710 | 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] | 4711 | #endif // CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 4712 | #endif // CONFIG_LPF_SB |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4713 | #else |
| 4714 | if (cpi->num_workers > 1) |
| 4715 | av1_loop_filter_frame_mt(cm->frame_to_show, cm, xd->plane, |
| 4716 | lf->filter_level, 0, 0, cpi->workers, |
| 4717 | cpi->num_workers, &cpi->lf_row_sync); |
| 4718 | else |
| 4719 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0); |
| 4720 | #endif |
| 4721 | } |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 4722 | |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 4723 | #if CONFIG_STRIPED_LOOP_RESTORATION |
| 4724 | av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm); |
| 4725 | #endif |
| 4726 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4727 | #if CONFIG_CDEF |
| 4728 | if (is_lossless_requested(&cpi->oxcf)) { |
| 4729 | cm->cdef_bits = 0; |
| 4730 | cm->cdef_strengths[0] = 0; |
| 4731 | cm->nb_cdef_strengths = 1; |
| 4732 | } else { |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 4733 | // Find CDEF parameters |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4734 | av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd, |
| 4735 | cpi->oxcf.speed > 0); |
| 4736 | |
| 4737 | // Apply the filter |
| 4738 | av1_cdef_frame(cm->frame_to_show, cm, xd); |
| 4739 | } |
| 4740 | #endif |
| 4741 | |
| 4742 | #if CONFIG_FRAME_SUPERRES |
| 4743 | superres_post_encode(cpi); |
| 4744 | #endif // CONFIG_FRAME_SUPERRES |
| 4745 | |
| 4746 | #if CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | fc9f3cc | 2017-09-11 14:51:14 -0700 | [diff] [blame] | 4747 | aom_extend_frame_borders(cm->frame_to_show); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4748 | av1_pick_filter_restoration(cpi->source, cpi, cpi->sf.lpf_pick); |
| 4749 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 4750 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 4751 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
| 4752 | av1_loop_restoration_frame(cm->frame_to_show, cm, cm->rst_info, 7, 0, NULL); |
| 4753 | } |
| 4754 | #endif // CONFIG_LOOP_RESTORATION |
| 4755 | // TODO(debargha): Fix mv search range on encoder side |
| 4756 | // aom_extend_frame_inner_borders(cm->frame_to_show); |
| 4757 | aom_extend_frame_borders(cm->frame_to_show); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4758 | } |
| 4759 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4760 | static void encode_without_recode_loop(AV1_COMP *cpi) { |
| 4761 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4762 | int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4763 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4764 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4765 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4766 | set_size_independent_vars(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4767 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4768 | setup_frame_size(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4769 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4770 | assert(cm->width == cpi->scaled_source.y_crop_width); |
| 4771 | assert(cm->height == cpi->scaled_source.y_crop_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 4772 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4773 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4774 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4775 | cpi->source = |
| 4776 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
| 4777 | if (cpi->unscaled_last_source != NULL) |
| 4778 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4779 | &cpi->scaled_last_source); |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4780 | #if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION |
| 4781 | cpi->source->buf_8bit_valid = 0; |
| 4782 | #endif |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4783 | |
| 4784 | if (frame_is_intra_only(cm) == 0) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4785 | scale_references(cpi); |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4786 | } |
| 4787 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4788 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4789 | setup_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4790 | suppress_active_map(cpi); |
hui su | ed5a30f | 2017-04-27 16:02:49 -0700 | [diff] [blame] | 4791 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4792 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4793 | // exclusive. |
| 4794 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4795 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4796 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4797 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4798 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4799 | av1_cyclic_refresh_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4800 | } |
| 4801 | apply_active_map(cpi); |
| 4802 | |
| 4803 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4804 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4805 | |
| 4806 | // Update some stats from cyclic refresh, and check if we should not update |
| 4807 | // golden reference, for 1 pass CBR. |
| 4808 | 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] | 4809 | (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR)) |
| 4810 | av1_cyclic_refresh_check_golden_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4811 | |
| 4812 | // Update the skip mb flag probabilities based on the distribution |
| 4813 | // seen in the last encoder iteration. |
| 4814 | // update_base_skip_probs(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4815 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4816 | } |
| 4817 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4818 | static void encode_with_recode_loop(AV1_COMP *cpi, size_t *size, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4819 | uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4820 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4821 | RATE_CONTROL *const rc = &cpi->rc; |
| 4822 | int bottom_index, top_index; |
| 4823 | int loop_count = 0; |
| 4824 | int loop_at_this_size = 0; |
| 4825 | int loop = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4826 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4827 | int overshoot_seen = 0; |
| 4828 | int undershoot_seen = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4829 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4830 | int frame_over_shoot_limit; |
| 4831 | int frame_under_shoot_limit; |
| 4832 | int q = 0, q_low = 0, q_high = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4833 | |
| 4834 | set_size_independent_vars(cpi); |
| 4835 | |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4836 | #if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION |
| 4837 | cpi->source->buf_8bit_valid = 0; |
| 4838 | #endif |
| 4839 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4840 | aom_clear_system_state(); |
| 4841 | setup_frame_size(cpi); |
| 4842 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4843 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4844 | do { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4845 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4846 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4847 | if (loop_count == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4848 | // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. |
| 4849 | set_mv_search_params(cpi); |
| 4850 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4851 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4852 | // Reset the loop state for new frame size. |
| 4853 | overshoot_seen = 0; |
| 4854 | undershoot_seen = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4855 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4856 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4857 | q_low = bottom_index; |
| 4858 | q_high = top_index; |
| 4859 | |
| 4860 | loop_at_this_size = 0; |
| 4861 | } |
| 4862 | |
| 4863 | // Decide frame size bounds first time through. |
| 4864 | if (loop_count == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4865 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4866 | &frame_under_shoot_limit, |
| 4867 | &frame_over_shoot_limit); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4868 | } |
| 4869 | |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4870 | #if CONFIG_GLOBAL_MOTION |
| 4871 | // if frame was scaled calculate global_motion_search again if already done |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4872 | if (loop_count > 0 && cpi->source && cpi->global_motion_search_done) |
| 4873 | if (cpi->source->y_crop_width != cm->width || |
| 4874 | cpi->source->y_crop_height != cm->height) |
| 4875 | cpi->global_motion_search_done = 0; |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4876 | #endif // CONFIG_GLOBAL_MOTION |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4877 | cpi->source = |
| 4878 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4879 | if (cpi->unscaled_last_source != NULL) |
| 4880 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4881 | &cpi->scaled_last_source); |
| 4882 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4883 | if (frame_is_intra_only(cm) == 0) { |
| 4884 | if (loop_count > 0) { |
| 4885 | release_scaled_references(cpi); |
| 4886 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4887 | scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4888 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4889 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4890 | |
| 4891 | if (loop_count == 0) setup_frame(cpi); |
| 4892 | |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 4893 | #if CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4894 | // Base q-index may have changed, so we need to assign proper default coef |
| 4895 | // probs before every iteration. |
| 4896 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
| 4897 | int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4898 | av1_default_coef_probs(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4899 | if (cm->frame_type == KEY_FRAME || cm->error_resilient_mode || |
| 4900 | cm->reset_frame_context == RESET_FRAME_CONTEXT_ALL) { |
| 4901 | for (i = 0; i < FRAME_CONTEXTS; ++i) cm->frame_contexts[i] = *cm->fc; |
| 4902 | } else if (cm->reset_frame_context == RESET_FRAME_CONTEXT_CURRENT) { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 4903 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 4904 | if (cm->frame_refs[0].idx >= 0) { |
| 4905 | cm->frame_contexts[cm->frame_refs[0].idx] = *cm->fc; |
| 4906 | } |
| 4907 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4908 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 4909 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4910 | } |
| 4911 | } |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 4912 | #endif // CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4913 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4914 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4915 | // exclusive. |
| 4916 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4917 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4918 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4919 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4920 | } |
| 4921 | |
| 4922 | // transform / motion compensation build reconstruction frame |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4923 | save_coding_context(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4924 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4925 | |
| 4926 | // Update the skip mb flag probabilities based on the distribution |
| 4927 | // seen in the last encoder iteration. |
| 4928 | // update_base_skip_probs(cpi); |
| 4929 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4930 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4931 | |
| 4932 | // Dummy pack of the bitstream using up to date stats to get an |
| 4933 | // accurate estimate of output frame size to determine if we need |
| 4934 | // to recode. |
| 4935 | if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4936 | restore_coding_context(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4937 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4938 | |
| 4939 | rc->projected_frame_size = (int)(*size) << 3; |
| 4940 | restore_coding_context(cpi); |
| 4941 | |
| 4942 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4943 | } |
| 4944 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4945 | if (cpi->oxcf.rc_mode == AOM_Q) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4946 | loop = 0; |
| 4947 | } else { |
| 4948 | if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced && |
| 4949 | (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
| 4950 | int last_q = q; |
| 4951 | int64_t kf_err; |
| 4952 | |
| 4953 | int64_t high_err_target = cpi->ambient_err; |
| 4954 | int64_t low_err_target = cpi->ambient_err >> 1; |
| 4955 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4956 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4957 | if (cm->use_highbitdepth) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4958 | 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] | 4959 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4960 | 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] | 4961 | } |
| 4962 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4963 | 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] | 4964 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4965 | |
| 4966 | // Prevent possible divide by zero error below for perfect KF |
| 4967 | kf_err += !kf_err; |
| 4968 | |
| 4969 | // The key frame is not good enough or we can afford |
| 4970 | // to make it better without undue risk of popping. |
| 4971 | if ((kf_err > high_err_target && |
| 4972 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4973 | (kf_err > low_err_target && |
| 4974 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4975 | // Lower q_high |
| 4976 | q_high = q > q_low ? q - 1 : q_low; |
| 4977 | |
| 4978 | // Adjust Q |
| 4979 | q = (int)((q * high_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4980 | q = AOMMIN(q, (q_high + q_low) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4981 | } else if (kf_err < low_err_target && |
| 4982 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4983 | // The key frame is much better than the previous frame |
| 4984 | // Raise q_low |
| 4985 | q_low = q < q_high ? q + 1 : q_high; |
| 4986 | |
| 4987 | // Adjust Q |
| 4988 | q = (int)((q * low_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4989 | q = AOMMIN(q, (q_high + q_low + 1) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4990 | } |
| 4991 | |
| 4992 | // Clamp Q to upper and lower limits: |
| 4993 | q = clamp(q, q_low, q_high); |
| 4994 | |
| 4995 | loop = q != last_q; |
| 4996 | } else if (recode_loop_test(cpi, frame_over_shoot_limit, |
| 4997 | frame_under_shoot_limit, q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4998 | AOMMAX(q_high, top_index), bottom_index)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4999 | // Is the projected frame size out of range and are we allowed |
| 5000 | // to attempt to recode. |
| 5001 | int last_q = q; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5002 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5003 | int retries = 0; |
| 5004 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5005 | // Frame size out of permitted range: |
| 5006 | // Update correction factor & compute new Q to try... |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5007 | // Frame is too large |
| 5008 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 5009 | // Special case if the projected size is > the max allowed. |
| 5010 | if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
| 5011 | q_high = rc->worst_quality; |
| 5012 | |
| 5013 | // Raise Qlow as to at least the current value |
| 5014 | q_low = q < q_high ? q + 1 : q_high; |
| 5015 | |
| 5016 | if (undershoot_seen || loop_at_this_size > 1) { |
| 5017 | // Update rate_correction_factor unless |
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 | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5019 | |
| 5020 | q = (q_high + q_low + 1) / 2; |
| 5021 | } else { |
| 5022 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5023 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5024 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5025 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5026 | AOMMAX(q_high, top_index), cm->width, |
| 5027 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5028 | |
| 5029 | while (q < q_low && 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 | AOMMAX(q_high, top_index), cm->width, |
| 5033 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5034 | retries++; |
| 5035 | } |
| 5036 | } |
| 5037 | |
| 5038 | overshoot_seen = 1; |
| 5039 | } else { |
| 5040 | // Frame is too small |
| 5041 | q_high = q > q_low ? q - 1 : q_low; |
| 5042 | |
| 5043 | if (overshoot_seen || loop_at_this_size > 1) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5044 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5045 | q = (q_high + q_low) / 2; |
| 5046 | } else { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5047 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5048 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5049 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5050 | // Special case reset for qlow for constrained quality. |
| 5051 | // This should only trigger where there is very substantial |
| 5052 | // undershoot on a frame and the auto cq level is above |
| 5053 | // the user passsed in value. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5054 | if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5055 | q_low = q; |
| 5056 | } |
| 5057 | |
| 5058 | while (q > q_high && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5059 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5060 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5061 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5062 | retries++; |
| 5063 | } |
| 5064 | } |
| 5065 | |
| 5066 | undershoot_seen = 1; |
| 5067 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5068 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5069 | |
| 5070 | // Clamp Q to upper and lower limits: |
| 5071 | q = clamp(q, q_low, q_high); |
| 5072 | |
| 5073 | loop = (q != last_q); |
| 5074 | } else { |
| 5075 | loop = 0; |
| 5076 | } |
| 5077 | } |
| 5078 | |
| 5079 | // Special case for overlay frame. |
| 5080 | if (rc->is_src_frame_alt_ref && |
| 5081 | rc->projected_frame_size < rc->max_frame_bandwidth) |
| 5082 | loop = 0; |
| 5083 | |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 5084 | #if CONFIG_GLOBAL_MOTION |
| 5085 | if (recode_loop_test_global_motion(cpi)) { |
| 5086 | loop = 1; |
| 5087 | } |
| 5088 | #endif // CONFIG_GLOBAL_MOTION |
| 5089 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5090 | if (loop) { |
| 5091 | ++loop_count; |
| 5092 | ++loop_at_this_size; |
| 5093 | |
| 5094 | #if CONFIG_INTERNAL_STATS |
| 5095 | ++cpi->tot_recode_hits; |
| 5096 | #endif |
| 5097 | } |
| 5098 | } while (loop); |
| 5099 | } |
| 5100 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5101 | static int get_ref_frame_flags(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5102 | const int *const map = cpi->common.ref_frame_map; |
| 5103 | |
| 5104 | #if CONFIG_EXT_REFS |
| 5105 | const int last2_is_last = |
| 5106 | map[cpi->lst_fb_idxes[1]] == map[cpi->lst_fb_idxes[0]]; |
| 5107 | const int last3_is_last = |
| 5108 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[0]]; |
| 5109 | const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 5110 | #if CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 5111 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 5112 | const int last3_is_last2 = |
| 5113 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]]; |
| 5114 | const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 5115 | const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 5116 | #else // !CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5117 | const int bwd_is_last = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 5118 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 5119 | |
| 5120 | const int last3_is_last2 = |
| 5121 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]]; |
| 5122 | const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 5123 | const int bwd_is_last2 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 5124 | |
| 5125 | const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 5126 | const int bwd_is_last3 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 5127 | |
| 5128 | const int bwd_is_gld = map[cpi->bwd_fb_idx] == map[cpi->gld_fb_idx]; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 5129 | #endif // CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5130 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5131 | const int alt2_is_last = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 5132 | const int alt2_is_last2 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 5133 | const int alt2_is_last3 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 5134 | const int alt2_is_gld = map[cpi->alt2_fb_idx] == map[cpi->gld_fb_idx]; |
| 5135 | const int alt2_is_bwd = map[cpi->alt2_fb_idx] == map[cpi->bwd_fb_idx]; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5136 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5137 | const int last2_is_alt = map[cpi->lst_fb_idxes[1]] == map[cpi->alt_fb_idx]; |
| 5138 | const int last3_is_alt = map[cpi->lst_fb_idxes[2]] == map[cpi->alt_fb_idx]; |
| 5139 | const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 5140 | 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] | 5141 | const int alt2_is_alt = map[cpi->alt2_fb_idx] == map[cpi->alt_fb_idx]; |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 5142 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5143 | const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx]; |
| 5144 | const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 5145 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx]; |
| 5146 | #endif // CONFIG_EXT_REFS |
| 5147 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5148 | int flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5149 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5150 | if (gld_is_last || gld_is_alt) flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5151 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5152 | 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] | 5153 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5154 | if (alt_is_last) flags &= ~AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5155 | |
| 5156 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5157 | if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5158 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5159 | if (last3_is_last || last3_is_last2 || last3_is_alt) flags &= ~AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5160 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5161 | if (gld_is_last2 || gld_is_last3) flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5162 | |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 5163 | #if CONFIG_ONE_SIDED_COMPOUND && \ |
| 5164 | !CONFIG_EXT_COMP_REFS // Changes LL & HL bitstream |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 5165 | /* Allow biprediction between two identical frames (e.g. bwd_is_last = 1) */ |
| 5166 | if (bwd_is_alt && (flags & AOM_BWD_FLAG)) flags &= ~AOM_BWD_FLAG; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 5167 | #else // !CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5168 | if ((bwd_is_last || bwd_is_last2 || bwd_is_last3 || bwd_is_gld || |
| 5169 | bwd_is_alt) && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5170 | (flags & AOM_BWD_FLAG)) |
| 5171 | flags &= ~AOM_BWD_FLAG; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 5172 | #endif // CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5173 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5174 | if ((alt2_is_last || alt2_is_last2 || alt2_is_last3 || alt2_is_gld || |
| 5175 | alt2_is_bwd || alt2_is_alt) && |
| 5176 | (flags & AOM_ALT2_FLAG)) |
| 5177 | flags &= ~AOM_ALT2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5178 | #endif // CONFIG_EXT_REFS |
| 5179 | |
| 5180 | return flags; |
| 5181 | } |
| 5182 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5183 | static void set_ext_overrides(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5184 | // Overrides the defaults with the externally supplied values with |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5185 | // av1_update_reference() and av1_update_entropy() calls |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5186 | // Note: The overrides are valid only for the next frame passed |
| 5187 | // to encode_frame_to_data_rate() function |
| 5188 | if (cpi->ext_refresh_frame_context_pending) { |
| 5189 | cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context; |
| 5190 | cpi->ext_refresh_frame_context_pending = 0; |
| 5191 | } |
| 5192 | if (cpi->ext_refresh_frame_flags_pending) { |
| 5193 | cpi->refresh_last_frame = cpi->ext_refresh_last_frame; |
| 5194 | cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame; |
| 5195 | cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; |
| 5196 | cpi->ext_refresh_frame_flags_pending = 0; |
| 5197 | } |
| 5198 | } |
| 5199 | |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 5200 | #if !CONFIG_FRAME_SIGN_BIAS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5201 | static void set_arf_sign_bias(AV1_COMP *cpi) { |
| 5202 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5203 | int arf_sign_bias; |
| 5204 | #if CONFIG_EXT_REFS |
| 5205 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5206 | // The arf_sign_bias will be one for internal ARFs' |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5207 | arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 5208 | (!cpi->refresh_alt_ref_frame || |
| 5209 | gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5210 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5211 | if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { |
| 5212 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5213 | arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 5214 | (!cpi->refresh_alt_ref_frame || |
| 5215 | (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)); |
| 5216 | } else { |
| 5217 | arf_sign_bias = |
| 5218 | (cpi->rc.source_alt_ref_active && !cpi->refresh_alt_ref_frame); |
| 5219 | } |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 5220 | #endif // CONFIG_EXT_REFS |
| 5221 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5222 | cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; |
| 5223 | #if CONFIG_EXT_REFS |
| 5224 | 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] | 5225 | cm->ref_frame_sign_bias[ALTREF2_FRAME] = |
| 5226 | cm->ref_frame_sign_bias[ALTREF_FRAME]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5227 | #endif // CONFIG_EXT_REFS |
| 5228 | } |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 5229 | #endif // !CONFIG_FRAME_SIGN_BIAS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5230 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5231 | static int setup_interp_filter_search_mask(AV1_COMP *cpi) { |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 5232 | InterpFilter ifilter; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5233 | int ref_total[TOTAL_REFS_PER_FRAME] = { 0 }; |
| 5234 | MV_REFERENCE_FRAME ref; |
| 5235 | int mask = 0; |
| 5236 | int arf_idx = ALTREF_FRAME; |
| 5237 | |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5238 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5239 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame || |
| 5240 | cpi->refresh_alt2_ref_frame) |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5241 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5242 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame) |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5243 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5244 | return mask; |
| 5245 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5246 | for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) |
| 5247 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) |
| 5248 | ref_total[ref] += cpi->interp_filter_selected[ref][ifilter]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5249 | |
| 5250 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) { |
| 5251 | if ((ref_total[LAST_FRAME] && |
| 5252 | cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) && |
| 5253 | #if CONFIG_EXT_REFS |
| 5254 | (ref_total[LAST2_FRAME] == 0 || |
| 5255 | cpi->interp_filter_selected[LAST2_FRAME][ifilter] * 50 < |
| 5256 | ref_total[LAST2_FRAME]) && |
| 5257 | (ref_total[LAST3_FRAME] == 0 || |
| 5258 | cpi->interp_filter_selected[LAST3_FRAME][ifilter] * 50 < |
| 5259 | ref_total[LAST3_FRAME]) && |
| 5260 | #endif // CONFIG_EXT_REFS |
| 5261 | (ref_total[GOLDEN_FRAME] == 0 || |
| 5262 | cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50 < |
| 5263 | ref_total[GOLDEN_FRAME]) && |
| 5264 | #if CONFIG_EXT_REFS |
| 5265 | (ref_total[BWDREF_FRAME] == 0 || |
| 5266 | cpi->interp_filter_selected[BWDREF_FRAME][ifilter] * 50 < |
| 5267 | ref_total[BWDREF_FRAME]) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5268 | (ref_total[ALTREF2_FRAME] == 0 || |
| 5269 | cpi->interp_filter_selected[ALTREF2_FRAME][ifilter] * 50 < |
| 5270 | ref_total[ALTREF2_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5271 | #endif // CONFIG_EXT_REFS |
| 5272 | (ref_total[ALTREF_FRAME] == 0 || |
| 5273 | cpi->interp_filter_selected[arf_idx][ifilter] * 50 < |
| 5274 | ref_total[ALTREF_FRAME])) |
| 5275 | mask |= 1 << ifilter; |
| 5276 | } |
| 5277 | return mask; |
| 5278 | } |
| 5279 | |
| 5280 | #define DUMP_RECON_FRAMES 0 |
| 5281 | |
| 5282 | #if DUMP_RECON_FRAMES == 1 |
| 5283 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5284 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 5285 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5286 | const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show; |
| 5287 | int h; |
| 5288 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 5289 | FILE *f_recon = NULL; |
| 5290 | |
| 5291 | if (recon_buf == NULL || !cm->show_frame) { |
| 5292 | printf("Frame %d is not ready or no show to dump.\n", |
| 5293 | cm->current_video_frame); |
| 5294 | return; |
| 5295 | } |
| 5296 | |
| 5297 | if (cm->current_video_frame == 0) { |
| 5298 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 5299 | printf("Unable to open file %s to write.\n", file_name); |
| 5300 | return; |
| 5301 | } |
| 5302 | } else { |
| 5303 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 5304 | printf("Unable to open file %s to append.\n", file_name); |
| 5305 | return; |
| 5306 | } |
| 5307 | } |
| 5308 | printf( |
| 5309 | "\nFrame=%5d, encode_update_type[%5d]=%1d, show_existing_frame=%d, " |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 5310 | "source_alt_ref_active=%d, refresh_alt_ref_frame=%d, rf_level=%d, " |
| 5311 | "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] | 5312 | cm->current_video_frame, cpi->twopass.gf_group.index, |
| 5313 | cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 5314 | cm->show_existing_frame, cpi->rc.source_alt_ref_active, |
| 5315 | cpi->refresh_alt_ref_frame, |
| 5316 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index], |
| 5317 | recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5318 | #if 0 |
| 5319 | int ref_frame; |
| 5320 | printf("get_ref_frame_map_idx: ["); |
| 5321 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
| 5322 | printf(" %d", get_ref_frame_map_idx(cpi, ref_frame)); |
| 5323 | printf(" ]\n"); |
| 5324 | printf("cm->new_fb_idx = %d\n", cm->new_fb_idx); |
| 5325 | printf("cm->ref_frame_map = ["); |
| 5326 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 5327 | printf(" %d", cm->ref_frame_map[ref_frame - LAST_FRAME]); |
| 5328 | } |
| 5329 | printf(" ]\n"); |
| 5330 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5331 | |
| 5332 | // --- Y --- |
| 5333 | for (h = 0; h < cm->height; ++h) { |
| 5334 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 5335 | f_recon); |
| 5336 | } |
| 5337 | // --- U --- |
| 5338 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 5339 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 5340 | f_recon); |
| 5341 | } |
| 5342 | // --- V --- |
| 5343 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 5344 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 5345 | f_recon); |
| 5346 | } |
| 5347 | |
| 5348 | fclose(f_recon); |
| 5349 | } |
| 5350 | #endif // DUMP_RECON_FRAMES |
| 5351 | |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5352 | static void make_update_tile_list_enc(AV1_COMP *cpi, const int tile_rows, |
| 5353 | const int tile_cols, |
| 5354 | FRAME_CONTEXT *ec_ctxs[]) { |
| 5355 | int i; |
| 5356 | for (i = 0; i < tile_rows * tile_cols; ++i) |
| 5357 | ec_ctxs[i] = &cpi->tile_data[i].tctx; |
| 5358 | } |
| 5359 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5360 | 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] | 5361 | uint8_t *dest, int skip_adapt, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5362 | unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5363 | AV1_COMMON *const cm = &cpi->common; |
| 5364 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5365 | struct segmentation *const seg = &cm->seg; |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5366 | FRAME_CONTEXT **tile_ctxs = aom_malloc(cm->tile_rows * cm->tile_cols * |
| 5367 | sizeof(&cpi->tile_data[0].tctx)); |
| 5368 | aom_cdf_prob **cdf_ptrs = |
| 5369 | aom_malloc(cm->tile_rows * cm->tile_cols * |
| 5370 | sizeof(&cpi->tile_data[0].tctx.partition_cdf[0][0])); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5371 | #if CONFIG_XIPHRC |
| 5372 | int frame_type; |
| 5373 | int drop_this_frame = 0; |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5374 | #endif // CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5375 | set_ext_overrides(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5376 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5377 | |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 5378 | #if !CONFIG_FRAME_SIGN_BIAS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5379 | // Set the arf sign bias for this frame. |
| 5380 | set_arf_sign_bias(cpi); |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 5381 | #endif // !CONFIG_FRAME_SIGN_BIAS |
| 5382 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 5383 | #if CONFIG_TEMPMV_SIGNALING |
| 5384 | // frame type has been decided outside of this function call |
| 5385 | cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only; |
| 5386 | cm->use_prev_frame_mvs = |
| 5387 | !cpi->oxcf.disable_tempmv && !cm->cur_frame->intra_only; |
| 5388 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5389 | |
| 5390 | #if CONFIG_EXT_REFS |
| 5391 | // NOTE: |
| 5392 | // (1) Move the setup of the ref_frame_flags upfront as it would be |
| 5393 | // determined by the current frame properties; |
| 5394 | // (2) The setup of the ref_frame_flags applies to both show_existing_frame's |
| 5395 | // and the other cases. |
| 5396 | if (cm->current_video_frame > 0) |
| 5397 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 5398 | |
| 5399 | if (cm->show_existing_frame) { |
| 5400 | // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current |
| 5401 | // BWDREF_FRAME in the reference frame buffer. |
| 5402 | cm->frame_type = INTER_FRAME; |
| 5403 | cm->show_frame = 1; |
| 5404 | cpi->frame_flags = *frame_flags; |
| 5405 | |
| 5406 | // In the case of show_existing frame, we will not send fresh flag |
| 5407 | // to decoder. Any change in the reference frame buffer can be done by |
| 5408 | // switching the virtual indices. |
| 5409 | |
| 5410 | cpi->refresh_last_frame = 0; |
| 5411 | cpi->refresh_golden_frame = 0; |
| 5412 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5413 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5414 | cpi->refresh_alt_ref_frame = 0; |
| 5415 | |
| 5416 | cpi->rc.is_bwd_ref_frame = 0; |
| 5417 | cpi->rc.is_last_bipred_frame = 0; |
| 5418 | cpi->rc.is_bipred_frame = 0; |
| 5419 | |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 5420 | restore_coding_context(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5421 | // Build the bitstream |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5422 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5423 | |
| 5424 | // Set up frame to show to get ready for stats collection. |
| 5425 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 5426 | |
| 5427 | #if DUMP_RECON_FRAMES == 1 |
| 5428 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 5429 | dump_filtered_recon_frames(cpi); |
| 5430 | #endif // DUMP_RECON_FRAMES |
| 5431 | |
| 5432 | // Update the LAST_FRAME in the reference frame buffer. |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5433 | // NOTE: |
| 5434 | // (1) For BWDREF_FRAME as the show_existing_frame, the reference frame |
| 5435 | // update has been done previously when handling the LAST_BIPRED_FRAME |
| 5436 | // right before BWDREF_FRAME (in the display order); |
| 5437 | // (2) For INTNL_OVERLAY as the show_existing_frame, the reference frame |
| 5438 | // update will be done when the following is called, which will exchange |
| 5439 | // the virtual indexes between LAST_FRAME and ALTREF2_FRAME, so that |
| 5440 | // LAST3 will get retired, LAST2 becomes LAST3, LAST becomes LAST2, and |
| 5441 | // ALTREF2_FRAME will serve as the new LAST_FRAME. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5442 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5443 | |
| 5444 | // Update frame flags |
| 5445 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 5446 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 5447 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 5448 | |
| 5449 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5450 | |
| 5451 | // Update the frame type |
| 5452 | cm->last_frame_type = cm->frame_type; |
| 5453 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5454 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 5455 | // to do post-encoding update accordingly. |
| 5456 | if (cpi->rc.is_src_frame_alt_ref) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5457 | av1_set_target_rate(cpi, cm->width, cm->height); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5458 | #if CONFIG_XIPHRC |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5459 | 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] | 5460 | drop_this_frame = od_enc_rc_update_state( |
| 5461 | &cpi->od_rc, *size << 3, cpi->refresh_golden_frame, |
| 5462 | cpi->refresh_alt_ref_frame, frame_type, cpi->droppable); |
| 5463 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5464 | av1_rc_postencode_update(cpi, *size); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5465 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5466 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5467 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5468 | ++cm->current_video_frame; |
| 5469 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5470 | aom_free(tile_ctxs); |
| 5471 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5472 | return; |
| 5473 | } |
| 5474 | #endif // CONFIG_EXT_REFS |
| 5475 | |
| 5476 | // Set default state for segment based loop filter update flags. |
| 5477 | cm->lf.mode_ref_delta_update = 0; |
| 5478 | |
| 5479 | if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search) |
| 5480 | cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi); |
| 5481 | |
| 5482 | // Set various flags etc to special state if it is a key frame. |
| 5483 | if (frame_is_intra_only(cm)) { |
| 5484 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5485 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5486 | |
| 5487 | // If segmentation is enabled force a map update for key frames. |
| 5488 | if (seg->enabled) { |
| 5489 | seg->update_map = 1; |
| 5490 | seg->update_data = 1; |
| 5491 | } |
| 5492 | |
| 5493 | // The alternate reference frame cannot be active for a key frame. |
| 5494 | cpi->rc.source_alt_ref_active = 0; |
| 5495 | |
| 5496 | cm->error_resilient_mode = oxcf->error_resilient_mode; |
| 5497 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 5498 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5499 | // By default, encoder assumes decoder can use prev_mi. |
| 5500 | if (cm->error_resilient_mode) { |
| 5501 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
| 5502 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 5503 | } else if (cm->intra_only) { |
| 5504 | // Only reset the current context. |
| 5505 | cm->reset_frame_context = RESET_FRAME_CONTEXT_CURRENT; |
| 5506 | } |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 5507 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5508 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5509 | if (cpi->oxcf.mtu == 0) { |
| 5510 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 5511 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 5512 | // Use a default value for the purposes of weighting costs in probability |
| 5513 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5514 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 5515 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5516 | |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 5517 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 5518 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 5519 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 5520 | #endif // CONFIG_EXT_TILE |
| 5521 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5522 | #if CONFIG_XIPHRC |
| 5523 | if (drop_this_frame) { |
| 5524 | av1_rc_postencode_update_drop_frame(cpi); |
| 5525 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5526 | aom_free(tile_ctxs); |
| 5527 | aom_free(cdf_ptrs); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5528 | return; |
| 5529 | } |
| 5530 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5531 | // For 1 pass CBR, check if we are dropping this frame. |
| 5532 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5533 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5534 | cm->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5535 | if (av1_rc_drop_frame(cpi)) { |
| 5536 | av1_rc_postencode_update_drop_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5537 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5538 | aom_free(tile_ctxs); |
| 5539 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5540 | return; |
| 5541 | } |
| 5542 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5543 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5544 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5545 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5546 | |
| 5547 | #if CONFIG_INTERNAL_STATS |
| 5548 | memset(cpi->mode_chosen_counts, 0, |
| 5549 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 5550 | #endif |
| 5551 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5552 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 5553 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5554 | /* Non-normative definition of current_frame_id ("frame counter" with |
| 5555 | * wraparound) */ |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5556 | const int frame_id_length = FRAME_ID_LENGTH_MINUS7 + 7; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5557 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5558 | int lsb, msb; |
Arild Fuldseth (arilfuld) | bac17c1 | 2016-12-02 12:01:06 +0100 | [diff] [blame] | 5559 | /* quasi-random initialization of current_frame_id for a key frame */ |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5560 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5561 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 5562 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 5563 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5564 | } else { |
| 5565 | #endif |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5566 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 5567 | msb = cpi->source->y_buffer[1] & 0xff; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5568 | #if CONFIG_HIGHBITDEPTH |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5569 | } |
Arild Fuldseth (arilfuld) | bac17c1 | 2016-12-02 12:01:06 +0100 | [diff] [blame] | 5570 | #endif |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5571 | cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5572 | } else { |
| 5573 | cm->current_frame_id = |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5574 | (cm->current_frame_id + 1 + (1 << frame_id_length)) % |
| 5575 | (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5576 | } |
| 5577 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 5578 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5579 | |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 5580 | #if CONFIG_EXT_DELTA_Q |
| 5581 | cm->delta_q_present_flag = cpi->oxcf.deltaq_mode != NO_DELTA_Q; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 5582 | cm->delta_lf_present_flag = cpi->oxcf.deltaq_mode == DELTA_Q_LF; |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 5583 | #if CONFIG_LOOPFILTER_LEVEL |
| 5584 | cm->delta_lf_multi = DEFAULT_DELTA_LF_MULTI; |
| 5585 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 5586 | #endif |
| 5587 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5588 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 5589 | encode_without_recode_loop(cpi); |
| 5590 | } else { |
| 5591 | encode_with_recode_loop(cpi, size, dest); |
| 5592 | } |
| 5593 | |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5594 | cm->last_tile_cols = cm->tile_cols; |
| 5595 | cm->last_tile_rows = cm->tile_rows; |
| 5596 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5597 | #ifdef OUTPUT_YUV_SKINMAP |
| 5598 | if (cpi->common.current_video_frame > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5599 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5600 | } |
| 5601 | #endif // OUTPUT_YUV_SKINMAP |
| 5602 | |
| 5603 | // Special case code to reduce pulsing when key frames are forced at a |
| 5604 | // fixed interval. Note the reconstruction error if it is the frame before |
| 5605 | // the force key frame |
| 5606 | 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] | 5607 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5608 | if (cm->use_highbitdepth) { |
| 5609 | cpi->ambient_err = |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5610 | aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5611 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5612 | 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] | 5613 | } |
| 5614 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5615 | 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] | 5616 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | // If the encoder forced a KEY_FRAME decision |
| 5620 | if (cm->frame_type == KEY_FRAME) { |
| 5621 | cpi->refresh_last_frame = 1; |
| 5622 | } |
| 5623 | |
| 5624 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 5625 | cm->frame_to_show->color_space = cm->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 5626 | #if CONFIG_COLORSPACE_HEADERS |
| 5627 | cm->frame_to_show->transfer_function = cm->transfer_function; |
| 5628 | cm->frame_to_show->chroma_sample_position = cm->chroma_sample_position; |
| 5629 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5630 | cm->frame_to_show->color_range = cm->color_range; |
| 5631 | cm->frame_to_show->render_width = cm->render_width; |
| 5632 | cm->frame_to_show->render_height = cm->render_height; |
| 5633 | |
| 5634 | #if CONFIG_EXT_REFS |
| 5635 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 5636 | // off. |
| 5637 | #endif // CONFIG_EXT_REFS |
| 5638 | |
| 5639 | // Pick the loop filter level for the frame. |
| 5640 | loopfilter_frame(cpi, cm); |
| 5641 | |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 5642 | #ifdef OUTPUT_YUV_REC |
| 5643 | aom_write_one_yuv_frame(cm, cm->frame_to_show); |
| 5644 | #endif |
| 5645 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5646 | // Build the bitstream |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5647 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5648 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5649 | if (skip_adapt) { |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5650 | aom_free(tile_ctxs); |
| 5651 | aom_free(cdf_ptrs); |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5652 | return; |
| 5653 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5654 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5655 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 5656 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5657 | int i; |
| 5658 | /* Update reference frame id values based on the value of refresh_mask */ |
| 5659 | for (i = 0; i < REF_FRAMES; i++) { |
| 5660 | if ((cm->refresh_mask >> i) & 1) { |
| 5661 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 5662 | } |
| 5663 | } |
| 5664 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 5665 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5666 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5667 | #if DUMP_RECON_FRAMES == 1 |
| 5668 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 5669 | if (cm->show_frame) dump_filtered_recon_frames(cpi); |
| 5670 | #endif // DUMP_RECON_FRAMES |
| 5671 | |
| 5672 | if (cm->seg.update_map) update_reference_segmentation_map(cpi); |
| 5673 | |
| 5674 | if (frame_is_intra_only(cm) == 0) { |
| 5675 | release_scaled_references(cpi); |
| 5676 | } |
| 5677 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5678 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5679 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5680 | #if CONFIG_ENTROPY_STATS |
| 5681 | av1_accumulate_frame_counts(&aggregate_fc, &cm->counts); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 5682 | assert(cm->frame_context_idx < FRAME_CONTEXTS); |
| 5683 | av1_accumulate_frame_counts(&aggregate_fc_per_type[cm->frame_context_idx], |
| 5684 | &cm->counts); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5685 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5686 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
hui su | b53682f | 2017-08-01 17:09:18 -0700 | [diff] [blame] | 5687 | #if CONFIG_LV_MAP |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5688 | av1_adapt_coef_probs(cm); |
hui su | b53682f | 2017-08-01 17:09:18 -0700 | [diff] [blame] | 5689 | #endif // CONFIG_LV_MAP |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5690 | av1_adapt_intra_frame_probs(cm); |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5691 | make_update_tile_list_enc(cpi, cm->tile_rows, cm->tile_cols, tile_ctxs); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5692 | av1_average_tile_coef_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5693 | cm->tile_rows * cm->tile_cols); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5694 | av1_average_tile_intra_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5695 | cm->tile_rows * cm->tile_cols); |
Yushin Cho | b188ea1 | 2017-03-13 13:45:23 -0700 | [diff] [blame] | 5696 | #if CONFIG_PVQ |
| 5697 | av1_average_tile_pvq_cdfs(cpi->common.fc, tile_ctxs, |
| 5698 | cm->tile_rows * cm->tile_cols); |
| 5699 | #endif // CONFIG_PVQ |
hui su | ff0da2b | 2017-03-07 15:51:37 -0800 | [diff] [blame] | 5700 | #if CONFIG_ADAPT_SCAN |
| 5701 | av1_adapt_scan_order(cm); |
| 5702 | #endif // CONFIG_ADAPT_SCAN |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | if (!frame_is_intra_only(cm)) { |
| 5706 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5707 | av1_adapt_inter_frame_probs(cm); |
| 5708 | av1_adapt_mv_probs(cm, cm->allow_high_precision_mv); |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5709 | av1_average_tile_inter_cdfs(&cpi->common, cpi->common.fc, tile_ctxs, |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5710 | cdf_ptrs, cm->tile_rows * cm->tile_cols); |
| 5711 | av1_average_tile_mv_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5712 | cm->tile_rows * cm->tile_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5713 | } |
| 5714 | } |
| 5715 | |
| 5716 | if (cpi->refresh_golden_frame == 1) |
| 5717 | cpi->frame_flags |= FRAMEFLAGS_GOLDEN; |
| 5718 | else |
| 5719 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 5720 | |
| 5721 | if (cpi->refresh_alt_ref_frame == 1) |
| 5722 | cpi->frame_flags |= FRAMEFLAGS_ALTREF; |
| 5723 | else |
| 5724 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 5725 | |
| 5726 | #if CONFIG_EXT_REFS |
| 5727 | if (cpi->refresh_bwd_ref_frame == 1) |
| 5728 | cpi->frame_flags |= FRAMEFLAGS_BWDREF; |
| 5729 | else |
| 5730 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 5731 | #endif // CONFIG_EXT_REFS |
| 5732 | |
| 5733 | #if !CONFIG_EXT_REFS |
| 5734 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 5735 | #endif // !CONFIG_EXT_REFS |
| 5736 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5737 | cm->last_frame_type = cm->frame_type; |
| 5738 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5739 | #if CONFIG_XIPHRC |
| 5740 | frame_type = cm->frame_type == KEY_FRAME ? OD_I_FRAME : OD_P_FRAME; |
| 5741 | |
| 5742 | drop_this_frame = |
| 5743 | od_enc_rc_update_state(&cpi->od_rc, *size << 3, cpi->refresh_golden_frame, |
| 5744 | cpi->refresh_alt_ref_frame, frame_type, 0); |
| 5745 | if (drop_this_frame) { |
| 5746 | av1_rc_postencode_update_drop_frame(cpi); |
| 5747 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5748 | aom_free(tile_ctxs); |
| 5749 | aom_free(cdf_ptrs); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5750 | return; |
| 5751 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5752 | #else // !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5753 | av1_rc_postencode_update(cpi, *size); |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5754 | #endif // CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5755 | |
| 5756 | #if 0 |
| 5757 | output_frame_level_debug_stats(cpi); |
| 5758 | #endif |
| 5759 | |
| 5760 | if (cm->frame_type == KEY_FRAME) { |
| 5761 | // Tell the caller that the frame was coded as a key frame |
| 5762 | *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY; |
| 5763 | } else { |
| 5764 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5765 | } |
| 5766 | |
| 5767 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 5768 | // filter deltas. |
| 5769 | cm->seg.update_map = 0; |
| 5770 | cm->seg.update_data = 0; |
| 5771 | cm->lf.mode_ref_delta_update = 0; |
| 5772 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5773 | if (cm->show_frame) { |
| 5774 | #if CONFIG_EXT_REFS |
| 5775 | // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that are |
| 5776 | // being used as reference. |
| 5777 | #endif // CONFIG_EXT_REFS |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5778 | swap_mi_and_prev_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5779 | // Don't increment frame counters if this was an altref buffer |
| 5780 | // update not a real frame |
| 5781 | ++cm->current_video_frame; |
| 5782 | } |
| 5783 | |
| 5784 | #if CONFIG_EXT_REFS |
| 5785 | // NOTE: Shall not refer to any frame not used as reference. |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5786 | if (cm->is_reference_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5787 | #endif // CONFIG_EXT_REFS |
| 5788 | cm->prev_frame = cm->cur_frame; |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5789 | // keep track of the last coded dimensions |
| 5790 | cm->last_width = cm->width; |
| 5791 | cm->last_height = cm->height; |
| 5792 | |
| 5793 | // reset to normal state now that we are done. |
| 5794 | cm->last_show_frame = cm->show_frame; |
| 5795 | #if CONFIG_EXT_REFS |
| 5796 | } |
| 5797 | #endif // CONFIG_EXT_REFS |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5798 | |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5799 | aom_free(tile_ctxs); |
| 5800 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5801 | } |
| 5802 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5803 | static void Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5804 | int skip_adapt, unsigned int *frame_flags) { |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5805 | #if CONFIG_XIPHRC |
| 5806 | int64_t ip_count; |
| 5807 | int frame_type, is_golden, is_altref; |
| 5808 | |
| 5809 | /* Not updated during init so update it here */ |
| 5810 | if (cpi->oxcf.rc_mode == AOM_Q) cpi->od_rc.quality = cpi->oxcf.cq_level; |
| 5811 | |
| 5812 | frame_type = od_frame_type(&cpi->od_rc, cpi->od_rc.cur_frame, &is_golden, |
| 5813 | &is_altref, &ip_count); |
| 5814 | |
| 5815 | if (frame_type == OD_I_FRAME) { |
| 5816 | frame_type = KEY_FRAME; |
| 5817 | cpi->frame_flags &= FRAMEFLAGS_KEY; |
| 5818 | } else if (frame_type == OD_P_FRAME) { |
| 5819 | frame_type = INTER_FRAME; |
| 5820 | } |
| 5821 | |
| 5822 | if (is_altref) { |
| 5823 | cpi->refresh_alt_ref_frame = 1; |
| 5824 | cpi->rc.source_alt_ref_active = 1; |
| 5825 | } |
| 5826 | |
| 5827 | cpi->refresh_golden_frame = is_golden; |
| 5828 | cpi->common.frame_type = frame_type; |
| 5829 | if (is_golden) cpi->frame_flags &= FRAMEFLAGS_GOLDEN; |
| 5830 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5831 | if (cpi->oxcf.rc_mode == AOM_CBR) { |
| 5832 | av1_rc_get_one_pass_cbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5833 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5834 | av1_rc_get_one_pass_vbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5835 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5836 | #endif |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5837 | encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5838 | } |
| 5839 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5840 | #if !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5841 | static void Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5842 | unsigned int *frame_flags) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5843 | encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5844 | |
| 5845 | #if CONFIG_EXT_REFS |
| 5846 | // Do not do post-encoding update for those frames that do not have a spot in |
| 5847 | // a gf group, but note that an OVERLAY frame always has a spot in a gf group, |
| 5848 | // even when show_existing_frame is used. |
| 5849 | 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] | 5850 | av1_twopass_postencode_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5851 | } |
| 5852 | check_show_existing_frame(cpi); |
| 5853 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5854 | av1_twopass_postencode_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5855 | #endif // CONFIG_EXT_REFS |
| 5856 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5857 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5858 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 5859 | 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] | 5860 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 5861 | int64_t end_time) { |
| 5862 | AV1_COMMON *const cm = &cpi->common; |
| 5863 | struct aom_usec_timer timer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5864 | int res = 0; |
| 5865 | const int subsampling_x = sd->subsampling_x; |
| 5866 | const int subsampling_y = sd->subsampling_y; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5867 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5868 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
| 5869 | #endif |
| 5870 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5871 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5872 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
| 5873 | #else |
| 5874 | check_initial_width(cpi, subsampling_x, subsampling_y); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5875 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5876 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5877 | aom_usec_timer_start(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5878 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5879 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5880 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5881 | use_highbitdepth, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5882 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5883 | frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5884 | res = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5885 | aom_usec_timer_mark(&timer); |
| 5886 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5887 | |
| 5888 | if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && |
| 5889 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5890 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5891 | "Non-4:2:0 color format requires profile 1 or 3"); |
| 5892 | res = -1; |
| 5893 | } |
| 5894 | if ((cm->profile == PROFILE_1 || cm->profile == PROFILE_3) && |
| 5895 | (subsampling_x == 1 && subsampling_y == 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5896 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5897 | "4:2:0 color format requires profile 0 or 2"); |
| 5898 | res = -1; |
| 5899 | } |
| 5900 | |
| 5901 | return res; |
| 5902 | } |
| 5903 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5904 | static int frame_is_reference(const AV1_COMP *cpi) { |
| 5905 | const AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5906 | |
| 5907 | return cm->frame_type == KEY_FRAME || cpi->refresh_last_frame || |
| 5908 | cpi->refresh_golden_frame || |
| 5909 | #if CONFIG_EXT_REFS |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5910 | cpi->refresh_bwd_ref_frame || cpi->refresh_alt2_ref_frame || |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5911 | #endif // CONFIG_EXT_REFS |
| 5912 | cpi->refresh_alt_ref_frame || !cm->error_resilient_mode || |
| 5913 | cm->lf.mode_ref_delta_update || cm->seg.update_map || |
| 5914 | cm->seg.update_data; |
| 5915 | } |
| 5916 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5917 | static void adjust_frame_rate(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5918 | const struct lookahead_entry *source) { |
| 5919 | int64_t this_duration; |
| 5920 | int step = 0; |
| 5921 | |
| 5922 | if (source->ts_start == cpi->first_time_stamp_ever) { |
| 5923 | this_duration = source->ts_end - source->ts_start; |
| 5924 | step = 1; |
| 5925 | } else { |
| 5926 | int64_t last_duration = |
| 5927 | cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen; |
| 5928 | |
| 5929 | this_duration = source->ts_end - cpi->last_end_time_stamp_seen; |
| 5930 | |
| 5931 | // do a step update if the duration changes by 10% |
| 5932 | if (last_duration) |
| 5933 | step = (int)((this_duration - last_duration) * 10 / last_duration); |
| 5934 | } |
| 5935 | |
| 5936 | if (this_duration) { |
| 5937 | if (step) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5938 | av1_new_framerate(cpi, 10000000.0 / this_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5939 | } else { |
| 5940 | // Average this frame's rate into the last second's average |
| 5941 | // frame rate. If we haven't seen 1 second yet, then average |
| 5942 | // over the whole interval seen. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5943 | const double interval = AOMMIN( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5944 | (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0); |
| 5945 | double avg_duration = 10000000.0 / cpi->framerate; |
| 5946 | avg_duration *= (interval - avg_duration + this_duration); |
| 5947 | avg_duration /= interval; |
| 5948 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5949 | av1_new_framerate(cpi, 10000000.0 / avg_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5950 | } |
| 5951 | } |
| 5952 | cpi->last_time_stamp_seen = source->ts_start; |
| 5953 | cpi->last_end_time_stamp_seen = source->ts_end; |
| 5954 | } |
| 5955 | |
| 5956 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5957 | // used as the arf midpoint. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5958 | static int get_arf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5959 | RATE_CONTROL *const rc = &cpi->rc; |
| 5960 | int arf_src_index = 0; |
| 5961 | if (is_altref_enabled(cpi)) { |
| 5962 | if (cpi->oxcf.pass == 2) { |
| 5963 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5964 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 5965 | arf_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5966 | } |
| 5967 | } else if (rc->source_alt_ref_pending) { |
| 5968 | arf_src_index = rc->frames_till_gf_update_due; |
| 5969 | } |
| 5970 | } |
| 5971 | return arf_src_index; |
| 5972 | } |
| 5973 | |
| 5974 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5975 | static int get_brf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5976 | int brf_src_index = 0; |
| 5977 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5978 | |
| 5979 | // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup |
| 5980 | // flag. |
| 5981 | if (gf_group->bidir_pred_enabled[gf_group->index]) { |
| 5982 | if (cpi->oxcf.pass == 2) { |
| 5983 | if (gf_group->update_type[gf_group->index] == BRF_UPDATE) |
| 5984 | brf_src_index = gf_group->brf_src_offset[gf_group->index]; |
| 5985 | } else { |
| 5986 | // TODO(zoeliu): To re-visit the setup for this scenario |
| 5987 | brf_src_index = cpi->rc.bipred_group_interval - 1; |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | return brf_src_index; |
| 5992 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5993 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5994 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5995 | // used as the arf midpoint. |
| 5996 | static int get_arf2_src_index(AV1_COMP *cpi) { |
| 5997 | int arf2_src_index = 0; |
| 5998 | if (is_altref_enabled(cpi) && cpi->num_extra_arfs) { |
| 5999 | if (cpi->oxcf.pass == 2) { |
| 6000 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 6001 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) { |
| 6002 | arf2_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 6003 | } |
| 6004 | } |
| 6005 | } |
| 6006 | return arf2_src_index; |
| 6007 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6008 | #endif // CONFIG_EXT_REFS |
| 6009 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6010 | static void check_src_altref(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6011 | const struct lookahead_entry *source) { |
| 6012 | RATE_CONTROL *const rc = &cpi->rc; |
| 6013 | |
| 6014 | // If pass == 2, the parameters set here will be reset in |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6015 | // av1_rc_get_second_pass_params() |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6016 | |
| 6017 | if (cpi->oxcf.pass == 2) { |
| 6018 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 6019 | rc->is_src_frame_alt_ref = |
| 6020 | #if CONFIG_EXT_REFS |
| 6021 | (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) || |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 6022 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6023 | (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 6024 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6025 | rc->is_src_frame_ext_arf = |
| 6026 | gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE; |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 6027 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6028 | } else { |
| 6029 | rc->is_src_frame_alt_ref = |
| 6030 | cpi->alt_ref_source && (source == cpi->alt_ref_source); |
| 6031 | } |
| 6032 | |
| 6033 | if (rc->is_src_frame_alt_ref) { |
| 6034 | // Current frame is an ARF overlay frame. |
| 6035 | cpi->alt_ref_source = NULL; |
| 6036 | |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 6037 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6038 | if (rc->is_src_frame_ext_arf && !cpi->common.show_existing_frame) { |
| 6039 | // For INTNL_OVERLAY, when show_existing_frame == 0, they do need to |
| 6040 | // refresh the LAST_FRAME, i.e. LAST3 gets retired, LAST2 becomes LAST3, |
| 6041 | // LAST becomes LAST2, and INTNL_OVERLAY becomes LAST. |
| 6042 | cpi->refresh_last_frame = 1; |
| 6043 | } else { |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 6044 | #endif // CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6045 | // Don't refresh the last buffer for an ARF overlay frame. It will |
| 6046 | // become the GF so preserve last as an alternative prediction option. |
| 6047 | cpi->refresh_last_frame = 0; |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 6048 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6049 | } |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 6050 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6051 | } |
| 6052 | } |
| 6053 | |
| 6054 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6055 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 6056 | const unsigned char *img2, int img2_pitch, |
| 6057 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6058 | |
| 6059 | static void adjust_image_stat(double y, double u, double v, double all, |
| 6060 | ImageStat *s) { |
| 6061 | s->stat[Y] += y; |
| 6062 | s->stat[U] += u; |
| 6063 | s->stat[V] += v; |
| 6064 | s->stat[ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6065 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6066 | } |
| 6067 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6068 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6069 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6070 | double samples = 0.0; |
| 6071 | uint32_t in_bit_depth = 8; |
| 6072 | uint32_t bit_depth = 8; |
| 6073 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6074 | #if CONFIG_INTER_STATS_ONLY |
Yaowu Xu | 1b4ffc4 | 2017-07-26 09:54:07 -0700 | [diff] [blame] | 6075 | if (cm->frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6076 | #endif |
| 6077 | cpi->bytes += frame_bytes; |
| 6078 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6079 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6080 | if (cm->use_highbitdepth) { |
| 6081 | in_bit_depth = cpi->oxcf.input_bit_depth; |
| 6082 | bit_depth = cm->bit_depth; |
| 6083 | } |
| 6084 | #endif |
| 6085 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6086 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6087 | const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; |
| 6088 | double y, u, v, frame_all; |
| 6089 | |
| 6090 | cpi->count++; |
| 6091 | if (cpi->b_calculate_psnr) { |
| 6092 | PSNR_STATS psnr; |
| 6093 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6094 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6095 | // TODO(yaowu): unify these two versions into one. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6096 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6097 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6098 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6099 | aom_calc_psnr(orig, recon, &psnr); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6100 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6101 | |
| 6102 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 6103 | &cpi->psnr); |
| 6104 | cpi->total_sq_error += psnr.sse[0]; |
| 6105 | cpi->total_samples += psnr.samples[0]; |
| 6106 | samples = psnr.samples[0]; |
| 6107 | // TODO(yaowu): unify these two versions into one. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6108 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6109 | if (cm->use_highbitdepth) |
| 6110 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6111 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6112 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6113 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6114 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6115 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6116 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6117 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6118 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6119 | cpi->summed_quality += frame_ssim2 * weight; |
| 6120 | cpi->summed_weights += weight; |
| 6121 | |
| 6122 | #if 0 |
| 6123 | { |
| 6124 | FILE *f = fopen("q_used.stt", "a"); |
| 6125 | fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", |
| 6126 | cpi->common.current_video_frame, y2, u2, v2, |
| 6127 | frame_psnr2, frame_ssim2); |
| 6128 | fclose(f); |
| 6129 | } |
| 6130 | #endif |
| 6131 | } |
| 6132 | if (cpi->b_calculate_blockiness) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6133 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6134 | if (!cm->use_highbitdepth) |
| 6135 | #endif |
| 6136 | { |
| 6137 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6138 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 6139 | recon->y_stride, orig->y_width, orig->y_height); |
| 6140 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6141 | cpi->total_blockiness += frame_blockiness; |
| 6142 | } |
| 6143 | |
| 6144 | if (cpi->b_calculate_consistency) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6145 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6146 | if (!cm->use_highbitdepth) |
| 6147 | #endif |
| 6148 | { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6149 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6150 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 6151 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 6152 | |
| 6153 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 6154 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6155 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6156 | if (consistency > 0.0) |
| 6157 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6158 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6159 | cpi->total_inconsistency += this_inconsistency; |
| 6160 | } |
| 6161 | } |
| 6162 | } |
| 6163 | |
| 6164 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6165 | 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] | 6166 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6167 | 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] | 6168 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 6169 | } |
| 6170 | } |
| 6171 | #endif // CONFIG_INTERNAL_STATS |
| 6172 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6173 | #if CONFIG_AMVR |
| 6174 | static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture, |
| 6175 | const YV12_BUFFER_CONFIG *last_picture, |
| 6176 | hash_table *last_hash_table) { |
| 6177 | aom_clear_system_state(); |
| 6178 | // check use hash ME |
| 6179 | int k; |
| 6180 | uint32_t hash_value_1; |
| 6181 | uint32_t hash_value_2; |
| 6182 | |
| 6183 | const int block_size = 8; |
| 6184 | const double threshold_current = 0.8; |
| 6185 | const double threshold_average = 0.95; |
| 6186 | const int max_history_size = 32; |
| 6187 | int T = 0; // total block |
| 6188 | int C = 0; // match with collocated block |
| 6189 | int S = 0; // smooth region but not match with collocated block |
| 6190 | int M = 0; // match with other block |
| 6191 | |
| 6192 | const int pic_width = cur_picture->y_width; |
| 6193 | const int pic_height = cur_picture->y_height; |
| 6194 | for (int i = 0; i + block_size <= pic_height; i += block_size) { |
| 6195 | for (int j = 0; j + block_size <= pic_width; j += block_size) { |
| 6196 | const int x_pos = j; |
| 6197 | const int y_pos = i; |
| 6198 | int match = 1; |
| 6199 | T++; |
| 6200 | |
| 6201 | // check whether collocated block match with current |
| 6202 | uint8_t *p_cur = cur_picture->y_buffer; |
| 6203 | uint8_t *p_ref = last_picture->y_buffer; |
| 6204 | int stride_cur = cur_picture->y_stride; |
| 6205 | int stride_ref = last_picture->y_stride; |
| 6206 | p_cur += (y_pos * stride_cur + x_pos); |
| 6207 | p_ref += (y_pos * stride_ref + x_pos); |
| 6208 | |
| 6209 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 6210 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 6211 | if (p_cur[tmpX] != p_ref[tmpX]) { |
| 6212 | match = 0; |
| 6213 | } |
| 6214 | } |
| 6215 | p_cur += stride_cur; |
| 6216 | p_ref += stride_ref; |
| 6217 | } |
| 6218 | |
| 6219 | if (match) { |
| 6220 | C++; |
| 6221 | continue; |
| 6222 | } |
| 6223 | |
| 6224 | if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos, |
| 6225 | y_pos) || |
| 6226 | av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) { |
| 6227 | S++; |
| 6228 | continue; |
| 6229 | } |
| 6230 | |
| 6231 | av1_get_block_hash_value( |
| 6232 | cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur, |
| 6233 | block_size, &hash_value_1, &hash_value_2); |
| 6234 | |
| 6235 | if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) { |
| 6236 | M++; |
| 6237 | } |
| 6238 | } |
| 6239 | } |
| 6240 | |
| 6241 | assert(T > 0); |
| 6242 | double csm_rate = ((double)(C + S + M)) / ((double)(T)); |
| 6243 | double m_rate = ((double)(M)) / ((double)(T)); |
| 6244 | |
| 6245 | cpi->csm_rate_array[cpi->rate_index] = csm_rate; |
| 6246 | cpi->m_rate_array[cpi->rate_index] = m_rate; |
| 6247 | |
| 6248 | cpi->rate_index = (cpi->rate_index + 1) % max_history_size; |
| 6249 | cpi->rate_size++; |
| 6250 | cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size); |
| 6251 | |
| 6252 | if (csm_rate < threshold_current) { |
| 6253 | return 0; |
| 6254 | } |
| 6255 | |
| 6256 | if (C == T) { |
| 6257 | return 1; |
| 6258 | } |
| 6259 | |
| 6260 | double csm_average = 0.0; |
| 6261 | double m_average = 0.0; |
| 6262 | |
| 6263 | for (k = 0; k < cpi->rate_size; k++) { |
| 6264 | csm_average += cpi->csm_rate_array[k]; |
| 6265 | m_average += cpi->m_rate_array[k]; |
| 6266 | } |
| 6267 | csm_average /= cpi->rate_size; |
| 6268 | m_average /= cpi->rate_size; |
| 6269 | |
| 6270 | if (csm_average < threshold_average) { |
| 6271 | return 0; |
| 6272 | } |
| 6273 | |
| 6274 | if (M > (T - C - S) / 3) { |
| 6275 | return 1; |
| 6276 | } |
| 6277 | |
| 6278 | if (csm_rate > 0.99 && m_rate > 0.01) { |
| 6279 | return 1; |
| 6280 | } |
| 6281 | |
| 6282 | if (csm_average + m_average > 1.01) { |
| 6283 | return 1; |
| 6284 | } |
| 6285 | |
| 6286 | return 0; |
| 6287 | } |
| 6288 | #endif |
| 6289 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6290 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 6291 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 6292 | int64_t *time_end, int flush) { |
| 6293 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 6294 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6295 | BufferPool *const pool = cm->buffer_pool; |
| 6296 | RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6297 | struct aom_usec_timer cmptimer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6298 | YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
| 6299 | struct lookahead_entry *last_source = NULL; |
| 6300 | struct lookahead_entry *source = NULL; |
| 6301 | int arf_src_index; |
| 6302 | #if CONFIG_EXT_REFS |
| 6303 | int brf_src_index; |
| 6304 | #endif // CONFIG_EXT_REFS |
| 6305 | int i; |
| 6306 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 6307 | #if CONFIG_XIPHRC |
| 6308 | cpi->od_rc.end_of_input = flush; |
| 6309 | #endif |
| 6310 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6311 | #if CONFIG_BITSTREAM_DEBUG |
| 6312 | assert(cpi->oxcf.max_threads == 0 && |
| 6313 | "bitstream debug tool does not support multithreading"); |
| 6314 | bitstream_queue_record_write(); |
Angie Chiang | cb9a9eb | 2016-09-01 16:10:50 -0700 | [diff] [blame] | 6315 | 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] | 6316 | #endif |
| 6317 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6318 | aom_usec_timer_start(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6319 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6320 | #if CONFIG_AMVR |
| 6321 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0); |
| 6322 | #else |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 6323 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6324 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6325 | |
| 6326 | // Is multi-arf enabled. |
| 6327 | // Note that at the moment multi_arf is only configured for 2 pass VBR |
| 6328 | if ((oxcf->pass == 2) && (cpi->oxcf.enable_auto_arf > 1)) |
| 6329 | cpi->multi_arf_allowed = 1; |
| 6330 | else |
| 6331 | cpi->multi_arf_allowed = 0; |
| 6332 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 6333 | // Normal defaults |
| 6334 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6335 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 6336 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6337 | cm->refresh_frame_context = |
| 6338 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 6339 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 6340 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
| 6341 | |
| 6342 | cpi->refresh_last_frame = 1; |
| 6343 | cpi->refresh_golden_frame = 0; |
| 6344 | #if CONFIG_EXT_REFS |
| 6345 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6346 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6347 | #endif // CONFIG_EXT_REFS |
| 6348 | cpi->refresh_alt_ref_frame = 0; |
| 6349 | |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 6350 | #if CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6351 | if (oxcf->pass == 2 && cm->show_existing_frame) { |
| 6352 | // Manage the source buffer and flush out the source frame that has been |
| 6353 | // coded already; Also get prepared for PSNR calculation if needed. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6354 | if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6355 | *size = 0; |
| 6356 | return -1; |
| 6357 | } |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6358 | cpi->source = &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6359 | // TODO(zoeliu): To track down to determine whether it's needed to adjust |
| 6360 | // the frame rate. |
| 6361 | *time_stamp = source->ts_start; |
| 6362 | *time_end = source->ts_end; |
| 6363 | |
| 6364 | // We need to adjust frame rate for an overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 6365 | 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] | 6366 | |
| 6367 | // Find a free buffer for the new frame, releasing the reference previously |
| 6368 | // held. |
| 6369 | if (cm->new_fb_idx != INVALID_IDX) { |
| 6370 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 6371 | } |
| 6372 | cm->new_fb_idx = get_free_fb(cm); |
| 6373 | |
| 6374 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 6375 | |
| 6376 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6377 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6378 | |
| 6379 | // Start with a 0 size frame. |
| 6380 | *size = 0; |
| 6381 | |
| 6382 | // We need to update the gf_group for show_existing overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 6383 | 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] | 6384 | |
| 6385 | Pass2Encode(cpi, size, dest, frame_flags); |
| 6386 | |
| 6387 | if (cpi->b_calculate_psnr) generate_psnr_packet(cpi); |
| 6388 | |
| 6389 | #if CONFIG_INTERNAL_STATS |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6390 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6391 | #endif // CONFIG_INTERNAL_STATS |
| 6392 | |
| 6393 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6394 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6395 | |
| 6396 | cm->show_existing_frame = 0; |
| 6397 | return 0; |
| 6398 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 6399 | #endif // CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6400 | |
| 6401 | // Should we encode an arf frame. |
| 6402 | arf_src_index = get_arf_src_index(cpi); |
| 6403 | if (arf_src_index) { |
| 6404 | for (i = 0; i <= arf_src_index; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6405 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6406 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 6407 | if (e == NULL) { |
| 6408 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6409 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6410 | arf_src_index = 0; |
| 6411 | flush = 1; |
| 6412 | break; |
| 6413 | } |
| 6414 | } |
| 6415 | } |
| 6416 | |
| 6417 | if (arf_src_index) { |
| 6418 | assert(arf_src_index <= rc->frames_to_key); |
| 6419 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6420 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6421 | cpi->alt_ref_source = source; |
| 6422 | |
| 6423 | if (oxcf->arnr_max_frames > 0) { |
Todd Nguyen | 302d097 | 2017-06-16 16:16:29 -0700 | [diff] [blame] | 6424 | // Produce the filtered ARF frame. |
| 6425 | #if CONFIG_BGSPRITE |
| 6426 | int bgsprite_ret = av1_background_sprite(cpi, arf_src_index); |
Todd Nguyen | 2fc2309 | 2017-07-11 12:00:36 -0700 | [diff] [blame] | 6427 | // Do temporal filter if bgsprite not generated. |
| 6428 | if (bgsprite_ret != 0) |
Todd Nguyen | 302d097 | 2017-06-16 16:16:29 -0700 | [diff] [blame] | 6429 | #endif // CONFIG_BGSPRITE |
Todd Nguyen | 8493f91 | 2017-07-20 12:45:12 -0700 | [diff] [blame] | 6430 | av1_temporal_filter(cpi, |
| 6431 | #if CONFIG_BGSPRITE |
Todd Nguyen | 1fd99c2 | 2017-07-31 17:50:41 -0700 | [diff] [blame] | 6432 | NULL, &cpi->alt_ref_buffer, |
Todd Nguyen | 8493f91 | 2017-07-20 12:45:12 -0700 | [diff] [blame] | 6433 | #endif // CONFIG_BGSPRITE |
| 6434 | arf_src_index); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6435 | aom_extend_frame_borders(&cpi->alt_ref_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6436 | force_src_buffer = &cpi->alt_ref_buffer; |
| 6437 | } |
| 6438 | |
| 6439 | cm->show_frame = 0; |
| 6440 | cm->intra_only = 0; |
| 6441 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6442 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6443 | cpi->refresh_golden_frame = 0; |
| 6444 | #if CONFIG_EXT_REFS |
| 6445 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6446 | cpi->refresh_alt2_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6447 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6448 | rc->is_src_frame_alt_ref = 0; |
| 6449 | } |
| 6450 | rc->source_alt_ref_pending = 0; |
| 6451 | } |
| 6452 | |
| 6453 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6454 | // Should we encode an arf2 frame. |
| 6455 | arf_src_index = get_arf2_src_index(cpi); |
| 6456 | if (arf_src_index) { |
| 6457 | for (i = 0; i <= arf_src_index; ++i) { |
| 6458 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
| 6459 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 6460 | if (e == NULL) { |
| 6461 | break; |
| 6462 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
| 6463 | arf_src_index = 0; |
| 6464 | flush = 1; |
| 6465 | break; |
| 6466 | } |
| 6467 | } |
| 6468 | } |
| 6469 | |
| 6470 | if (arf_src_index) { |
| 6471 | assert(arf_src_index <= rc->frames_to_key); |
| 6472 | |
| 6473 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
| 6474 | cpi->alt_ref_source = source; |
| 6475 | |
| 6476 | if (oxcf->arnr_max_frames > 0) { |
| 6477 | // Produce the filtered ARF frame. |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 6478 | av1_temporal_filter(cpi, |
| 6479 | #if CONFIG_BGSPRITE |
| 6480 | NULL, NULL, |
| 6481 | #endif // CONFIG_BGSPRITE |
| 6482 | arf_src_index); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6483 | aom_extend_frame_borders(&cpi->alt_ref_buffer); |
| 6484 | force_src_buffer = &cpi->alt_ref_buffer; |
| 6485 | } |
| 6486 | |
| 6487 | cm->show_frame = 0; |
| 6488 | cm->intra_only = 0; |
| 6489 | cpi->refresh_alt2_ref_frame = 1; |
| 6490 | cpi->refresh_last_frame = 0; |
| 6491 | cpi->refresh_golden_frame = 0; |
| 6492 | cpi->refresh_bwd_ref_frame = 0; |
| 6493 | cpi->refresh_alt_ref_frame = 0; |
| 6494 | rc->is_src_frame_alt_ref = 0; |
| 6495 | rc->is_src_frame_ext_arf = 0; |
| 6496 | } |
| 6497 | rc->source_alt_ref_pending = 0; |
| 6498 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6499 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6500 | rc->is_bwd_ref_frame = 0; |
| 6501 | brf_src_index = get_brf_src_index(cpi); |
| 6502 | if (brf_src_index) { |
| 6503 | assert(brf_src_index <= rc->frames_to_key); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6504 | if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6505 | cm->show_frame = 0; |
| 6506 | cm->intra_only = 0; |
| 6507 | |
| 6508 | cpi->refresh_bwd_ref_frame = 1; |
| 6509 | cpi->refresh_last_frame = 0; |
| 6510 | cpi->refresh_golden_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6511 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6512 | cpi->refresh_alt_ref_frame = 0; |
| 6513 | |
| 6514 | rc->is_bwd_ref_frame = 1; |
| 6515 | } |
| 6516 | } |
| 6517 | #endif // CONFIG_EXT_REFS |
| 6518 | |
| 6519 | if (!source) { |
| 6520 | // Get last frame source. |
| 6521 | if (cm->current_video_frame > 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6522 | if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6523 | return -1; |
| 6524 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 6525 | if (cm->current_video_frame > 0) assert(last_source != NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6526 | // Read in the source frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6527 | source = av1_lookahead_pop(cpi->lookahead, flush); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6528 | |
| 6529 | if (source != NULL) { |
| 6530 | cm->show_frame = 1; |
| 6531 | cm->intra_only = 0; |
| 6532 | |
| 6533 | // Check to see if the frame should be encoded as an arf overlay. |
| 6534 | check_src_altref(cpi, source); |
| 6535 | } |
| 6536 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6537 | if (source) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 6538 | cpi->unscaled_source = cpi->source = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6539 | force_src_buffer ? force_src_buffer : &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6540 | cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL; |
| 6541 | |
| 6542 | *time_stamp = source->ts_start; |
| 6543 | *time_end = source->ts_end; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6544 | *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6545 | |
| 6546 | } else { |
| 6547 | *size = 0; |
| 6548 | if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6549 | #if CONFIG_XIPHRC |
| 6550 | od_enc_rc_2pass_out(&cpi->od_rc, cpi->output_pkt_list, 1); |
| 6551 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6552 | av1_end_first_pass(cpi); /* get last stats packet */ |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 6553 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6554 | cpi->twopass.first_pass_done = 1; |
| 6555 | } |
| 6556 | return -1; |
| 6557 | } |
| 6558 | |
| 6559 | if (source->ts_start < cpi->first_time_stamp_ever) { |
| 6560 | cpi->first_time_stamp_ever = source->ts_start; |
| 6561 | cpi->last_end_time_stamp_seen = source->ts_start; |
| 6562 | } |
| 6563 | |
| 6564 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6565 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6566 | |
| 6567 | // adjust frame rates based on timestamps given |
| 6568 | if (cm->show_frame) adjust_frame_rate(cpi, source); |
| 6569 | |
| 6570 | // Find a free buffer for the new frame, releasing the reference previously |
| 6571 | // held. |
| 6572 | if (cm->new_fb_idx != INVALID_IDX) { |
| 6573 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 6574 | } |
| 6575 | cm->new_fb_idx = get_free_fb(cm); |
| 6576 | |
| 6577 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 6578 | |
| 6579 | cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 6580 | #if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION |
| 6581 | cm->cur_frame->buf.buf_8bit_valid = 0; |
| 6582 | #endif |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 6583 | #if !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6584 | if (cpi->multi_arf_allowed) { |
| 6585 | if (cm->frame_type == KEY_FRAME) { |
| 6586 | init_buffer_indices(cpi); |
| 6587 | } else if (oxcf->pass == 2) { |
| 6588 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 6589 | cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; |
| 6590 | } |
| 6591 | } |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 6592 | #endif // !CONFIG_EXT_REFS |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 6593 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6594 | // Start with a 0 size frame. |
| 6595 | *size = 0; |
| 6596 | |
| 6597 | cpi->frame_flags = *frame_flags; |
| 6598 | |
| 6599 | if (oxcf->pass == 2) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6600 | #if CONFIG_XIPHRC |
| 6601 | if (od_enc_rc_2pass_in(&cpi->od_rc) < 0) return -1; |
| 6602 | } |
| 6603 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6604 | av1_rc_get_second_pass_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6605 | } else if (oxcf->pass == 1) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 6606 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6607 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6608 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6609 | |
| 6610 | if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) { |
| 6611 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) |
| 6612 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 6613 | } |
| 6614 | |
| 6615 | #if CONFIG_AOM_QM |
| 6616 | cm->using_qmatrix = cpi->oxcf.using_qm; |
| 6617 | cm->min_qmlevel = cpi->oxcf.qm_minlevel; |
| 6618 | cm->max_qmlevel = cpi->oxcf.qm_maxlevel; |
| 6619 | #endif |
| 6620 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6621 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 6622 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 6623 | if (*time_stamp == 0) { |
| 6624 | cpi->common.current_frame_id = -1; |
| 6625 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6626 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 6627 | #endif // CONFIG_REFERENCE_BUFFER |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6628 | #if CONFIG_AMVR |
| 6629 | cpi->cur_poc++; |
| 6630 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
| 6631 | if (cpi->common.seq_mv_precision_level == 2) { |
| 6632 | struct lookahead_entry *previous_entry = |
| 6633 | cpi->lookahead->buf + cpi->previsous_index; |
| 6634 | cpi->common.cur_frame_mv_precision_level = is_integer_mv( |
| 6635 | cpi, cpi->source, &previous_entry->img, cpi->previsou_hash_table); |
| 6636 | } else { |
| 6637 | cpi->common.cur_frame_mv_precision_level = |
| 6638 | cpi->common.seq_mv_precision_level; |
| 6639 | } |
| 6640 | } else { |
| 6641 | cpi->common.cur_frame_mv_precision_level = 0; |
| 6642 | } |
| 6643 | #endif |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6644 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6645 | #if CONFIG_XIPHRC |
| 6646 | if (oxcf->pass == 1) { |
| 6647 | size_t tmp; |
| 6648 | if (cpi->od_rc.cur_frame == 0) Pass0Encode(cpi, &tmp, dest, 1, frame_flags); |
| 6649 | cpi->od_rc.firstpass_quant = cpi->od_rc.target_quantizer; |
| 6650 | Pass0Encode(cpi, &tmp, dest, 0, frame_flags); |
| 6651 | od_enc_rc_2pass_out(&cpi->od_rc, cpi->output_pkt_list, 0); |
| 6652 | } else if (oxcf->pass == 2) { |
| 6653 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
| 6654 | } else { |
| 6655 | if (cpi->od_rc.cur_frame == 0) { |
| 6656 | size_t tmp; |
| 6657 | Pass0Encode(cpi, &tmp, dest, 1, frame_flags); |
| 6658 | } |
| 6659 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
| 6660 | } |
| 6661 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6662 | if (oxcf->pass == 1) { |
| 6663 | cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6664 | av1_first_pass(cpi, source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6665 | } else if (oxcf->pass == 2) { |
| 6666 | Pass2Encode(cpi, size, dest, frame_flags); |
| 6667 | } else { |
| 6668 | // One pass encode |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6669 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6670 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6671 | #endif |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 6672 | #if CONFIG_HASH_ME |
| 6673 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6674 | #if CONFIG_AMVR |
| 6675 | cpi->previsou_hash_table = &cm->cur_frame->hash_table; |
| 6676 | { |
| 6677 | int l; |
| 6678 | for (l = -MAX_PRE_FRAMES; l < cpi->lookahead->max_sz; l++) { |
| 6679 | if ((cpi->lookahead->buf + l) == source) { |
| 6680 | cpi->previsous_index = l; |
| 6681 | break; |
| 6682 | } |
| 6683 | } |
| 6684 | |
| 6685 | if (l == cpi->lookahead->max_sz) { |
| 6686 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 6687 | "Failed to find last frame original buffer"); |
| 6688 | } |
| 6689 | } |
| 6690 | #endif |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | #endif |
| 6694 | |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 6695 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 6696 | cm->frame_contexts[cm->new_fb_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 6697 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6698 | if (!cm->error_resilient_mode) |
| 6699 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 6700 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6701 | |
| 6702 | // No frame encoded, or frame was dropped, release scaled references. |
| 6703 | if ((*size == 0) && (frame_is_intra_only(cm) == 0)) { |
| 6704 | release_scaled_references(cpi); |
| 6705 | } |
| 6706 | |
| 6707 | if (*size > 0) { |
| 6708 | cpi->droppable = !frame_is_reference(cpi); |
| 6709 | } |
| 6710 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6711 | aom_usec_timer_mark(&cmptimer); |
| 6712 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6713 | |
| 6714 | if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame) |
| 6715 | generate_psnr_packet(cpi); |
| 6716 | |
| 6717 | #if CONFIG_INTERNAL_STATS |
| 6718 | if (oxcf->pass != 1) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6719 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6720 | } |
| 6721 | #endif // CONFIG_INTERNAL_STATS |
| 6722 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 6723 | #if CONFIG_XIPHRC |
| 6724 | cpi->od_rc.cur_frame++; |
| 6725 | #endif |
| 6726 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6727 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6728 | |
| 6729 | return 0; |
| 6730 | } |
| 6731 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6732 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 6733 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6734 | if (!cm->show_frame) { |
| 6735 | return -1; |
| 6736 | } else { |
| 6737 | int ret; |
| 6738 | if (cm->frame_to_show) { |
| 6739 | *dest = *cm->frame_to_show; |
| 6740 | dest->y_width = cm->width; |
| 6741 | dest->y_height = cm->height; |
| 6742 | dest->uv_width = cm->width >> cm->subsampling_x; |
| 6743 | dest->uv_height = cm->height >> cm->subsampling_y; |
| 6744 | ret = 0; |
| 6745 | } else { |
| 6746 | ret = -1; |
| 6747 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6748 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6749 | return ret; |
| 6750 | } |
| 6751 | } |
| 6752 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6753 | 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] | 6754 | if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1; |
| 6755 | |
| 6756 | *frame = |
| 6757 | cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf; |
| 6758 | return 0; |
| 6759 | } |
| 6760 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6761 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 6762 | AOM_SCALING vert_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6763 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 6764 | |
| 6765 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 6766 | |
| 6767 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 6768 | Scale2Ratio(vert_mode, &vr, &vs); |
| 6769 | |
| 6770 | // always go to the next whole number |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 6771 | cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 6772 | cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6773 | |
| 6774 | return 0; |
| 6775 | } |
| 6776 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6777 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6778 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6779 | void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6780 | if (flags & |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6781 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF)) { |
| 6782 | int ref = AOM_REFFRAME_ALL; |
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_REF_LAST) { |
| 6785 | ref ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6786 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6787 | ref ^= AOM_LAST2_FLAG; |
| 6788 | ref ^= AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6789 | #endif // CONFIG_EXT_REFS |
| 6790 | } |
| 6791 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6792 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6793 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6794 | if (flags & AOM_EFLAG_NO_REF_ARF) ref ^= AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6795 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6796 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6797 | } |
| 6798 | |
| 6799 | if (flags & |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6800 | (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF | |
| 6801 | AOM_EFLAG_FORCE_GF | AOM_EFLAG_FORCE_ARF)) { |
| 6802 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6803 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6804 | if (flags & AOM_EFLAG_NO_UPD_LAST) { |
| 6805 | upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6806 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6807 | upd ^= AOM_LAST2_FLAG; |
| 6808 | upd ^= AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6809 | #endif // CONFIG_EXT_REFS |
| 6810 | } |
| 6811 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6812 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6813 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6814 | if (flags & AOM_EFLAG_NO_UPD_ARF) upd ^= AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6815 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6816 | av1_update_reference(cpi, upd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6817 | } |
| 6818 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6819 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 6820 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6821 | } |
| 6822 | } |