Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Urvang Joshi | 8a02d76 | 2016-07-28 15:51:12 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Urvang Joshi | 8a02d76 | 2016-07-28 15:51:12 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <limits.h> |
| 13 | #include <math.h> |
| 14 | #include <stdio.h> |
| 15 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | #include "./aom_config.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | |
| 18 | #include "av1/common/alloccommon.h" |
Jean-Marc Valin | 0143513 | 2017-02-18 14:12:53 -0500 | [diff] [blame] | 19 | #if CONFIG_CDEF |
Steinar Midtskogen | a9d41e8 | 2017-03-17 12:48:15 +0100 | [diff] [blame] | 20 | #include "av1/common/cdef.h" |
Jean-Marc Valin | 0143513 | 2017-02-18 14:12:53 -0500 | [diff] [blame] | 21 | #endif // CONFIG_CDEF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 22 | #include "av1/common/filter.h" |
| 23 | #include "av1/common/idct.h" |
| 24 | #include "av1/common/reconinter.h" |
| 25 | #include "av1/common/reconintra.h" |
Fergus Simpson | d056500 | 2017-03-27 16:51:52 -0700 | [diff] [blame] | 26 | #include "av1/common/resize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | #include "av1/common/tile_common.h" |
| 28 | |
| 29 | #include "av1/encoder/aq_complexity.h" |
| 30 | #include "av1/encoder/aq_cyclicrefresh.h" |
| 31 | #include "av1/encoder/aq_variance.h" |
| 32 | #include "av1/encoder/bitstream.h" |
Todd Nguyen | 302d097 | 2017-06-16 16:16:29 -0700 | [diff] [blame] | 33 | #if CONFIG_BGSPRITE |
| 34 | #include "av1/encoder/bgsprite.h" |
| 35 | #endif // CONFIG_BGSPRITE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 36 | #if CONFIG_ANS |
Alex Converse | 1ac1ae7 | 2016-09-17 15:11:16 -0700 | [diff] [blame] | 37 | #include "aom_dsp/buf_ans.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 38 | #endif |
| 39 | #include "av1/encoder/context_tree.h" |
| 40 | #include "av1/encoder/encodeframe.h" |
| 41 | #include "av1/encoder/encodemv.h" |
| 42 | #include "av1/encoder/encoder.h" |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 43 | #if CONFIG_LV_MAP |
| 44 | #include "av1/encoder/encodetxb.h" |
| 45 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 46 | #include "av1/encoder/ethread.h" |
| 47 | #include "av1/encoder/firstpass.h" |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 48 | #if CONFIG_HASH_ME |
| 49 | #include "av1/encoder/hash_motion.h" |
| 50 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 51 | #include "av1/encoder/mbgraph.h" |
| 52 | #include "av1/encoder/picklpf.h" |
| 53 | #if CONFIG_LOOP_RESTORATION |
| 54 | #include "av1/encoder/pickrst.h" |
| 55 | #endif // CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 56 | #include "av1/encoder/random.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 57 | #include "av1/encoder/ratectrl.h" |
| 58 | #include "av1/encoder/rd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 59 | #include "av1/encoder/segmentation.h" |
| 60 | #include "av1/encoder/speed_features.h" |
| 61 | #include "av1/encoder/temporal_filter.h" |
| 62 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 63 | #include "./av1_rtcd.h" |
| 64 | #include "./aom_dsp_rtcd.h" |
| 65 | #include "./aom_scale_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | #include "aom_dsp/psnr.h" |
| 67 | #if CONFIG_INTERNAL_STATS |
| 68 | #include "aom_dsp/ssim.h" |
| 69 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 70 | #include "aom_dsp/aom_dsp_common.h" |
| 71 | #include "aom_dsp/aom_filter.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 72 | #include "aom_ports/aom_timer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 73 | #include "aom_ports/mem.h" |
| 74 | #include "aom_ports/system_state.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 75 | #include "aom_scale/aom_scale.h" |
Angie Chiang | 6062a8b | 2016-09-21 16:01:04 -0700 | [diff] [blame] | 76 | #if CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 77 | #include "aom_util/debug_util.h" |
Angie Chiang | 6062a8b | 2016-09-21 16:01:04 -0700 | [diff] [blame] | 78 | #endif // CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 79 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 80 | #if CONFIG_ENTROPY_STATS |
| 81 | FRAME_COUNTS aggregate_fc; |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 82 | // Aggregate frame counts per frame context type |
| 83 | FRAME_COUNTS aggregate_fc_per_type[FRAME_CONTEXTS]; |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 84 | #endif // CONFIG_ENTROPY_STATS |
| 85 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 86 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 87 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 88 | |
| 89 | #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ |
| 90 | |
| 91 | #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv |
| 92 | // for altref computation. |
| 93 | #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision |
| 94 | // mv. Choose a very high value for |
| 95 | // now so that HIGH_PRECISION is always |
| 96 | // chosen. |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 97 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 98 | // #define OUTPUT_YUV_REC |
| 99 | #ifdef OUTPUT_YUV_DENOISED |
| 100 | FILE *yuv_denoised_file = NULL; |
| 101 | #endif |
| 102 | #ifdef OUTPUT_YUV_SKINMAP |
| 103 | FILE *yuv_skinmap_file = NULL; |
| 104 | #endif |
| 105 | #ifdef OUTPUT_YUV_REC |
| 106 | FILE *yuv_rec_file; |
| 107 | #define FILE_NAME_LEN 100 |
| 108 | #endif |
| 109 | |
| 110 | #if 0 |
| 111 | FILE *framepsnr; |
| 112 | FILE *kf_list; |
| 113 | FILE *keyfile; |
| 114 | #endif |
| 115 | |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 116 | #if CONFIG_CFL |
| 117 | CFL_CTX NULL_CFL; |
| 118 | #endif |
| 119 | |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 120 | #if CONFIG_INTERNAL_STATS |
| 121 | typedef enum { Y, U, V, ALL } STAT_TYPE; |
| 122 | #endif // CONFIG_INTERNAL_STATS |
| 123 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 124 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 125 | switch (mode) { |
| 126 | case NORMAL: |
| 127 | *hr = 1; |
| 128 | *hs = 1; |
| 129 | break; |
| 130 | case FOURFIVE: |
| 131 | *hr = 4; |
| 132 | *hs = 5; |
| 133 | break; |
| 134 | case THREEFIVE: |
| 135 | *hr = 3; |
| 136 | *hs = 5; |
| 137 | break; |
| 138 | case ONETWO: |
| 139 | *hr = 1; |
| 140 | *hs = 2; |
| 141 | break; |
| 142 | default: |
| 143 | *hr = 1; |
| 144 | *hs = 1; |
| 145 | assert(0); |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 151 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 152 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 153 | unsigned char *const seg_map = cpi->segmentation_map; |
| 154 | int i; |
| 155 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 156 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 157 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 158 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 159 | } |
| 160 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 161 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 162 | struct segmentation *const seg = &cpi->common.seg; |
| 163 | unsigned char *const seg_map = cpi->segmentation_map; |
| 164 | const unsigned char *const active_map = cpi->active_map.map; |
| 165 | int i; |
| 166 | |
| 167 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 168 | |
| 169 | if (frame_is_intra_only(&cpi->common)) { |
| 170 | cpi->active_map.enabled = 0; |
| 171 | cpi->active_map.update = 1; |
| 172 | } |
| 173 | |
| 174 | if (cpi->active_map.update) { |
| 175 | if (cpi->active_map.enabled) { |
| 176 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 177 | if (seg_map[i] == AM_SEGMENT_ID_ACTIVE) seg_map[i] = active_map[i]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 178 | av1_enable_segmentation(seg); |
| 179 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 180 | #if CONFIG_LOOPFILTER_LEVEL |
| 181 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 182 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 183 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 184 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 185 | |
| 186 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H, |
| 187 | -MAX_LOOP_FILTER); |
| 188 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V, |
| 189 | -MAX_LOOP_FILTER); |
| 190 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U, |
| 191 | -MAX_LOOP_FILTER); |
| 192 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V, |
| 193 | -MAX_LOOP_FILTER); |
| 194 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 195 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 196 | // Setting the data to -MAX_LOOP_FILTER will result in the computed loop |
| 197 | // filter level being zero regardless of the value of seg->abs_delta. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 198 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF, |
| 199 | -MAX_LOOP_FILTER); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 200 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 201 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 202 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 203 | #if CONFIG_LOOPFILTER_LEVEL |
| 204 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_H); |
| 205 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_Y_V); |
| 206 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_U); |
| 207 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF_V); |
| 208 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 209 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 210 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 211 | if (seg->enabled) { |
| 212 | seg->update_data = 1; |
| 213 | seg->update_map = 1; |
| 214 | } |
| 215 | } |
| 216 | cpi->active_map.update = 0; |
| 217 | } |
| 218 | } |
| 219 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 220 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 221 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 222 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 223 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 224 | const int mi_rows = cpi->common.mi_rows; |
| 225 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 226 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 227 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 228 | cpi->active_map.update = 1; |
| 229 | if (new_map_16x16) { |
| 230 | int r, c; |
| 231 | for (r = 0; r < mi_rows; ++r) { |
| 232 | for (c = 0; c < mi_cols; ++c) { |
| 233 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 234 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 235 | ? AM_SEGMENT_ID_ACTIVE |
| 236 | : AM_SEGMENT_ID_INACTIVE; |
| 237 | } |
| 238 | } |
| 239 | cpi->active_map.enabled = 1; |
| 240 | } else { |
| 241 | cpi->active_map.enabled = 0; |
| 242 | } |
| 243 | return 0; |
| 244 | } else { |
| 245 | return -1; |
| 246 | } |
| 247 | } |
| 248 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 249 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 250 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 251 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 252 | new_map_16x16) { |
| 253 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 254 | const int mi_rows = cpi->common.mi_rows; |
| 255 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 256 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 257 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 258 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 259 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 260 | if (cpi->active_map.enabled) { |
| 261 | int r, c; |
| 262 | for (r = 0; r < mi_rows; ++r) { |
| 263 | for (c = 0; c < mi_cols; ++c) { |
| 264 | // Cyclic refresh segments are considered active despite not having |
| 265 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 266 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 267 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | return 0; |
| 272 | } else { |
| 273 | return -1; |
| 274 | } |
| 275 | } |
| 276 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 277 | static void set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv |
| 278 | #if CONFIG_AMVR |
| 279 | , |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 280 | int cur_frame_force_integer_mv |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 281 | #endif |
| 282 | ) { |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 283 | MACROBLOCK *const mb = &cpi->td.mb; |
| 284 | cpi->common.allow_high_precision_mv = allow_high_precision_mv; |
| 285 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 286 | #if CONFIG_AMVR |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 287 | if (cpi->common.allow_high_precision_mv && cur_frame_force_integer_mv == 0) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 288 | #else |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 289 | if (cpi->common.allow_high_precision_mv) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 290 | #endif |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 291 | int i; |
| 292 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 293 | mb->mv_cost_stack[i] = mb->nmvcost_hp[i]; |
| 294 | } |
| 295 | } else { |
| 296 | int i; |
| 297 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 298 | mb->mv_cost_stack[i] = mb->nmvcost[i]; |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 303 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 304 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 305 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 306 | return BLOCK_64X64; |
| 307 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 308 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 309 | return BLOCK_128X128; |
| 310 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 311 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 312 | |
| 313 | assert(IMPLIES(cpi->common.tile_cols > 1, |
| 314 | cpi->common.tile_width % MAX_MIB_SIZE == 0)); |
| 315 | assert(IMPLIES(cpi->common.tile_rows > 1, |
| 316 | cpi->common.tile_height % MAX_MIB_SIZE == 0)); |
| 317 | |
| 318 | // TODO(any): Possibly could improve this with a heuristic. |
| 319 | return BLOCK_128X128; |
| 320 | #else |
| 321 | (void)cpi; |
| 322 | return BLOCK_64X64; |
| 323 | #endif // CONFIG_EXT_PARTITION |
| 324 | } |
| 325 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 326 | static void setup_frame(AV1_COMP *cpi) { |
| 327 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 328 | // Set up entropy context depending on frame type. The decoder mandates |
| 329 | // the use of the default context, index 0, for keyframes and inter |
| 330 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 331 | // other inter-frames the encoder currently uses only two contexts; |
| 332 | // context 1 for ALTREF frames and context 0 for the others. |
| 333 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 334 | av1_setup_past_independence(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 335 | } else { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 336 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 337 | // Just use frame context from first signaled reference frame. |
| 338 | // This will always be LAST_FRAME for now. |
| 339 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 340 | const GF_GROUP *gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 341 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 342 | cm->frame_context_idx = EXT_ARF_FRAME; |
| 343 | else if (cpi->refresh_alt_ref_frame) |
| 344 | cm->frame_context_idx = ARF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 345 | else if (cpi->rc.is_src_frame_alt_ref) |
| 346 | cm->frame_context_idx = OVERLAY_FRAME; |
| 347 | else if (cpi->refresh_golden_frame) |
| 348 | cm->frame_context_idx = GLD_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 349 | else if (cpi->refresh_bwd_ref_frame) |
| 350 | cm->frame_context_idx = BRF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 351 | else |
| 352 | cm->frame_context_idx = REGULAR_FRAME; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 353 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | if (cm->frame_type == KEY_FRAME) { |
| 357 | cpi->refresh_golden_frame = 1; |
| 358 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 359 | av1_zero(cpi->interp_filter_selected); |
Debargha Mukherjee | d2630fa | 2017-09-22 10:32:51 -0700 | [diff] [blame] | 360 | set_sb_size(cm, select_sb_size(cpi)); |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 361 | #if CONFIG_REFERENCE_BUFFER |
| 362 | set_use_reference_buffer(cm, 0); |
| 363 | #endif // CONFIG_REFERENCE_BUFFER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 364 | } else { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 365 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 366 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
| 367 | cm->frame_refs[0].idx < 0) { |
| 368 | *cm->fc = cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 369 | } else { |
| 370 | *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx]; |
| 371 | } |
| 372 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 373 | *cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 374 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 375 | av1_zero(cpi->interp_filter_selected[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 376 | } |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 377 | #if CONFIG_ONE_SIDED_COMPOUND && \ |
| 378 | !CONFIG_EXT_COMP_REFS // No change to bitstream |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 379 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 380 | cpi->refresh_bwd_ref_frame = cpi->refresh_last_frame; |
| 381 | cpi->rc.is_bipred_frame = 1; |
| 382 | } |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 383 | #endif // CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 384 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 385 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
| 386 | cm->frame_refs[0].idx < 0) { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 387 | // use default frame context values |
| 388 | cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 389 | } else { |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 390 | *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 391 | cm->pre_fc = &cm->frame_contexts[cm->frame_refs[0].idx]; |
| 392 | } |
| 393 | #else |
Thomas Daede | 10e1da9 | 2017-04-26 13:22:21 -0700 | [diff] [blame] | 394 | cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 395 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 396 | |
| 397 | cpi->vaq_refresh = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 400 | static void enc_setup_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 401 | int i; |
| 402 | cm->mi = cm->mip + cm->mi_stride + 1; |
| 403 | memset(cm->mip, 0, cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip)); |
| 404 | cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 405 | // Clear top border row |
| 406 | memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride); |
| 407 | // Clear left border column |
| 408 | for (i = 1; i < cm->mi_rows + 1; ++i) |
| 409 | 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] | 410 | cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; |
| 411 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; |
| 412 | |
| 413 | memset(cm->mi_grid_base, 0, |
| 414 | cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mi_grid_base)); |
| 415 | } |
| 416 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 417 | static int enc_alloc_mi(AV1_COMMON *cm, int mi_size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 418 | cm->mip = aom_calloc(mi_size, sizeof(*cm->mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 419 | if (!cm->mip) return 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 420 | cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 421 | if (!cm->prev_mip) return 1; |
| 422 | cm->mi_alloc_size = mi_size; |
| 423 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 424 | 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] | 425 | if (!cm->mi_grid_base) return 1; |
| 426 | cm->prev_mi_grid_base = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 427 | (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 428 | if (!cm->prev_mi_grid_base) return 1; |
| 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 433 | static void enc_free_mi(AV1_COMMON *cm) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 434 | aom_free(cm->mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 435 | cm->mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 436 | aom_free(cm->prev_mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 437 | cm->prev_mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 438 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 439 | cm->mi_grid_base = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 440 | aom_free(cm->prev_mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 441 | cm->prev_mi_grid_base = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 442 | cm->mi_alloc_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 445 | static void swap_mi_and_prev_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 446 | // Current mip will be the prev_mip for the next frame. |
| 447 | MODE_INFO **temp_base = cm->prev_mi_grid_base; |
| 448 | MODE_INFO *temp = cm->prev_mip; |
| 449 | cm->prev_mip = cm->mip; |
| 450 | cm->mip = temp; |
| 451 | |
| 452 | // Update the upper left visible macroblock ptrs. |
| 453 | cm->mi = cm->mip + cm->mi_stride + 1; |
| 454 | cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 455 | |
| 456 | cm->prev_mi_grid_base = cm->mi_grid_base; |
| 457 | cm->mi_grid_base = temp_base; |
| 458 | cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; |
| 459 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; |
| 460 | } |
| 461 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 462 | void av1_initialize_enc(void) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 463 | static volatile int init_done = 0; |
| 464 | |
| 465 | if (!init_done) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 466 | av1_rtcd(); |
| 467 | aom_dsp_rtcd(); |
| 468 | aom_scale_rtcd(); |
| 469 | av1_init_intra_predictors(); |
| 470 | av1_init_me_luts(); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 471 | #if !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 472 | av1_rc_init_minq_luts(); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 473 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 474 | av1_entropy_mv_init(); |
| 475 | av1_encode_token_init(); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 476 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 477 | init_done = 1; |
| 478 | } |
| 479 | } |
| 480 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 481 | static void dealloc_context_buffers_ext(AV1_COMP *cpi) { |
| 482 | if (cpi->mbmi_ext_base) { |
| 483 | aom_free(cpi->mbmi_ext_base); |
| 484 | cpi->mbmi_ext_base = NULL; |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
| 489 | AV1_COMMON *cm = &cpi->common; |
| 490 | int mi_size = cm->mi_cols * cm->mi_rows; |
| 491 | |
| 492 | dealloc_context_buffers_ext(cpi); |
| 493 | CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, |
| 494 | aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); |
| 495 | } |
| 496 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 497 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 498 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 499 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 500 | dealloc_context_buffers_ext(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 501 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 502 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 503 | cpi->tile_data = NULL; |
| 504 | |
| 505 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 506 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 507 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 508 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 509 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 510 | cpi->cyclic_refresh = NULL; |
| 511 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 512 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 513 | cpi->active_map.map = NULL; |
| 514 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 515 | aom_free(cpi->td.mb.above_pred_buf); |
| 516 | cpi->td.mb.above_pred_buf = NULL; |
| 517 | |
| 518 | aom_free(cpi->td.mb.left_pred_buf); |
| 519 | cpi->td.mb.left_pred_buf = NULL; |
| 520 | |
| 521 | aom_free(cpi->td.mb.wsrc_buf); |
| 522 | cpi->td.mb.wsrc_buf = NULL; |
| 523 | |
| 524 | aom_free(cpi->td.mb.mask_buf); |
| 525 | cpi->td.mb.mask_buf = NULL; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 526 | |
Jingning Han | 6cc1fd3 | 2017-10-13 09:05:36 -0700 | [diff] [blame] | 527 | #if CONFIG_MFMV |
| 528 | aom_free(cm->tpl_mvs); |
| 529 | cm->tpl_mvs = NULL; |
| 530 | #endif |
| 531 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 532 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 533 | #if CONFIG_LV_MAP |
| 534 | av1_free_txb_buf(cpi); |
| 535 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 536 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 537 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 538 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 539 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 540 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 541 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 542 | #endif // CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 543 | aom_free_frame_buffer(&cpi->scaled_source); |
| 544 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 545 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 546 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 547 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 548 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 549 | cpi->tile_tok[0][0] = 0; |
| 550 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 551 | av1_free_pc_tree(&cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 552 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 553 | aom_free(cpi->td.mb.palette_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 554 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 555 | #if CONFIG_ANS |
Alex Converse | 1ac1ae7 | 2016-09-17 15:11:16 -0700 | [diff] [blame] | 556 | aom_buf_ans_free(&cpi->buf_ans); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 557 | #endif // CONFIG_ANS |
| 558 | } |
| 559 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 560 | static void save_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 561 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 562 | AV1_COMMON *cm = &cpi->common; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 563 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 564 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 565 | // Stores a snapshot of key state variables which can subsequently be |
| 566 | // restored with a call to av1_restore_coding_context. These functions are |
| 567 | // intended for use in a re-code loop in av1_compress_frame where the |
| 568 | // quantizer value is adjusted between loop iterations. |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 569 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 570 | av1_copy(cc->nmv_vec_cost[i], cpi->td.mb.nmv_vec_cost[i]); |
| 571 | av1_copy(cc->nmv_costs, cpi->nmv_costs); |
| 572 | av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp); |
| 573 | } |
| 574 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 575 | av1_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); |
| 576 | av1_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 577 | |
| 578 | cc->fc = *cm->fc; |
| 579 | } |
| 580 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 581 | static void restore_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 582 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 583 | AV1_COMMON *cm = &cpi->common; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 584 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 585 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 586 | // Restore key state variables to the snapshot state stored in the |
| 587 | // previous call to av1_save_coding_context. |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 588 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 589 | av1_copy(cpi->td.mb.nmv_vec_cost[i], cc->nmv_vec_cost[i]); |
| 590 | av1_copy(cpi->nmv_costs, cc->nmv_costs); |
| 591 | av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp); |
| 592 | } |
| 593 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 594 | av1_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); |
| 595 | av1_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 596 | |
| 597 | *cm->fc = cc->fc; |
| 598 | } |
| 599 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 600 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 601 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 602 | const RATE_CONTROL *const rc = &cpi->rc; |
| 603 | struct segmentation *const seg = &cm->seg; |
| 604 | |
| 605 | int high_q = (int)(rc->avg_q > 48.0); |
| 606 | int qi_delta; |
| 607 | |
| 608 | // Disable and clear down for KF |
| 609 | if (cm->frame_type == KEY_FRAME) { |
| 610 | // Clear down the global segmentation map |
| 611 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 612 | seg->update_map = 0; |
| 613 | seg->update_data = 0; |
| 614 | cpi->static_mb_pct = 0; |
| 615 | |
| 616 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 617 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 618 | |
| 619 | // Clear down the segment features. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 620 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 621 | } else if (cpi->refresh_alt_ref_frame) { |
| 622 | // If this is an alt ref frame |
| 623 | // Clear down the global segmentation map |
| 624 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 625 | seg->update_map = 0; |
| 626 | seg->update_data = 0; |
| 627 | cpi->static_mb_pct = 0; |
| 628 | |
| 629 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 630 | av1_disable_segmentation(seg); |
| 631 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 632 | |
| 633 | // Scan frames from current to arf frame. |
| 634 | // This function re-enables segmentation if appropriate. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 635 | av1_update_mbgraph_stats(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 636 | |
| 637 | // If segmentation was enabled set those features needed for the |
| 638 | // arf itself. |
| 639 | if (seg->enabled) { |
| 640 | seg->update_map = 1; |
| 641 | seg->update_data = 1; |
| 642 | |
| 643 | qi_delta = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 644 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, cm->bit_depth); |
| 645 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 646 | #if CONFIG_LOOPFILTER_LEVEL |
| 647 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 648 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 649 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 650 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 651 | |
| 652 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 653 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 654 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 655 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
| 656 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 657 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 658 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
| 659 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 660 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 661 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 662 | |
| 663 | // Where relevant assume segment data is delta data |
| 664 | seg->abs_delta = SEGMENT_DELTADATA; |
| 665 | } |
| 666 | } else if (seg->enabled) { |
| 667 | // All other frames if segmentation has been enabled |
| 668 | |
| 669 | // First normal frame in a valid gf or alt ref group |
| 670 | if (rc->frames_since_golden == 0) { |
| 671 | // Set up segment features for normal frames in an arf group |
| 672 | if (rc->source_alt_ref_active) { |
| 673 | seg->update_map = 0; |
| 674 | seg->update_data = 1; |
| 675 | seg->abs_delta = SEGMENT_DELTADATA; |
| 676 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 677 | qi_delta = |
| 678 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, cm->bit_depth); |
| 679 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 680 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 681 | |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 682 | #if CONFIG_LOOPFILTER_LEVEL |
| 683 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_H, -2); |
| 684 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_Y_V, -2); |
| 685 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_U, -2); |
| 686 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF_V, -2); |
| 687 | |
| 688 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_H); |
| 689 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_Y_V); |
| 690 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_U); |
| 691 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF_V); |
| 692 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 693 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
| 694 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 695 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 696 | |
| 697 | // Segment coding disabled for compred testing |
| 698 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 699 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 700 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 701 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 702 | } |
| 703 | } else { |
| 704 | // Disable segmentation and clear down features if alt ref |
| 705 | // is not active for this group |
| 706 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 707 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 708 | |
| 709 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 710 | |
| 711 | seg->update_map = 0; |
| 712 | seg->update_data = 0; |
| 713 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 714 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 715 | } |
| 716 | } else if (rc->is_src_frame_alt_ref) { |
| 717 | // Special case where we are coding over the top of a previous |
| 718 | // alt ref frame. |
| 719 | // Segment coding disabled for compred testing |
| 720 | |
| 721 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 722 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 723 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 724 | |
| 725 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 726 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 727 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 728 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 729 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 730 | |
| 731 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 732 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 733 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 734 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 735 | } |
| 736 | // Enable data update |
| 737 | seg->update_data = 1; |
| 738 | } else { |
| 739 | // All other frames. |
| 740 | |
| 741 | // No updates.. leave things as they are. |
| 742 | seg->update_map = 0; |
| 743 | seg->update_data = 0; |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 748 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 749 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 750 | MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible; |
| 751 | uint8_t *cache_ptr = cm->last_frame_seg_map; |
| 752 | int row, col; |
| 753 | |
| 754 | for (row = 0; row < cm->mi_rows; row++) { |
| 755 | MODE_INFO **mi_8x8 = mi_8x8_ptr; |
| 756 | uint8_t *cache = cache_ptr; |
| 757 | for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) |
| 758 | cache[0] = mi_8x8[0]->mbmi.segment_id; |
| 759 | mi_8x8_ptr += cm->mi_stride; |
| 760 | cache_ptr += cm->mi_cols; |
| 761 | } |
| 762 | } |
| 763 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 764 | static void alloc_raw_frame_buffers(AV1_COMP *cpi) { |
| 765 | AV1_COMMON *cm = &cpi->common; |
| 766 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 767 | |
| 768 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 769 | cpi->lookahead = av1_lookahead_init(oxcf->width, oxcf->height, |
| 770 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 771 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 772 | cm->use_highbitdepth, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 773 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 774 | oxcf->lag_in_frames); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 775 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 776 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 777 | "Failed to allocate lag buffers"); |
| 778 | |
| 779 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 780 | 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] | 781 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 782 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 783 | cm->use_highbitdepth, |
| 784 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 785 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 786 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 787 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 788 | "Failed to allocate altref buffer"); |
| 789 | } |
| 790 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 791 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 792 | AV1_COMMON *const cm = &cpi->common; |
| 793 | 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] | 794 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 795 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 796 | cm->use_highbitdepth, |
| 797 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 798 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 799 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 800 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 801 | "Failed to allocate last frame buffer"); |
| 802 | |
| 803 | #if CONFIG_LOOP_RESTORATION |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 804 | if (aom_realloc_frame_buffer( |
| 805 | &cpi->trial_frame_rst, |
| 806 | #if CONFIG_FRAME_SUPERRES |
| 807 | cm->superres_upscaled_width, cm->superres_upscaled_height, |
| 808 | #else |
| 809 | cm->width, cm->height, |
| 810 | #endif // CONFIG_FRAME_SUPERRES |
| 811 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 812 | #if CONFIG_HIGHBITDEPTH |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 813 | cm->use_highbitdepth, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 814 | #endif |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 815 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 816 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 817 | "Failed to allocate trial restored frame buffer"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 818 | #endif // CONFIG_LOOP_RESTORATION |
| 819 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 820 | if (aom_realloc_frame_buffer(&cpi->scaled_source, cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 821 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 822 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 823 | cm->use_highbitdepth, |
| 824 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 825 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 826 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 827 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 828 | "Failed to allocate scaled source buffer"); |
| 829 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 830 | 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] | 831 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 832 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 833 | cm->use_highbitdepth, |
| 834 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 835 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 836 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 837 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 838 | "Failed to allocate scaled last source buffer"); |
| 839 | } |
| 840 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 841 | static void alloc_compressor_data(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 842 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 843 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 844 | av1_alloc_context_buffers(cm, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 845 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 846 | #if CONFIG_LV_MAP |
| 847 | av1_alloc_txb_buf(cpi); |
| 848 | #endif |
| 849 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 850 | alloc_context_buffers_ext(cpi); |
| 851 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 852 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 853 | |
| 854 | { |
Yaowu Xu | e39b3b8 | 2017-10-31 16:11:59 -0700 | [diff] [blame] | 855 | unsigned int tokens = |
| 856 | get_token_alloc(cm->mb_rows, cm->mb_cols, MAX_SB_SIZE_LOG2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 857 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 858 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 861 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 864 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 865 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 866 | #if CONFIG_XIPHRC |
| 867 | if (!cpi->od_rc.cur_frame) return; |
| 868 | cpi->od_rc.framerate = cpi->framerate; |
| 869 | od_enc_rc_resize(&cpi->od_rc); |
| 870 | #else |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 871 | av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 872 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 875 | #if CONFIG_MAX_TILE |
| 876 | |
| 877 | static void set_tile_info_max_tile(AV1_COMP *cpi) { |
| 878 | AV1_COMMON *const cm = &cpi->common; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 879 | int i, start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 880 | |
| 881 | av1_get_tile_limits(cm); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 882 | |
| 883 | // configure tile columns |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 884 | 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] | 885 | cm->uniform_tile_spacing_flag = 1; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 886 | cm->log2_tile_cols = AOMMAX(cpi->oxcf.tile_columns, cm->min_log2_tile_cols); |
| 887 | 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] | 888 | } else { |
| 889 | int mi_cols = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); |
| 890 | int sb_cols = mi_cols >> MAX_MIB_SIZE_LOG2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 891 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 892 | cm->uniform_tile_spacing_flag = 0; |
| 893 | for (i = 0, start_sb = 0; start_sb < sb_cols && i < MAX_TILE_COLS; i++) { |
| 894 | cm->tile_col_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 895 | size_sb = cpi->oxcf.tile_widths[j++]; |
| 896 | if (j >= cpi->oxcf.tile_width_count) j = 0; |
| 897 | start_sb += AOMMIN(size_sb, MAX_TILE_WIDTH_SB); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 898 | } |
| 899 | cm->tile_cols = i; |
| 900 | cm->tile_col_start_sb[i] = sb_cols; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 901 | } |
| 902 | av1_calculate_tile_cols(cm); |
| 903 | |
| 904 | // configure tile rows |
| 905 | if (cm->uniform_tile_spacing_flag) { |
| 906 | cm->log2_tile_rows = AOMMAX(cpi->oxcf.tile_rows, cm->min_log2_tile_rows); |
| 907 | 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] | 908 | } else { |
| 909 | int mi_rows = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); |
| 910 | int sb_rows = mi_rows >> MAX_MIB_SIZE_LOG2; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 911 | int size_sb, j = 0; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 912 | for (i = 0, start_sb = 0; start_sb < sb_rows && i < MAX_TILE_ROWS; i++) { |
| 913 | cm->tile_row_start_sb[i] = start_sb; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 914 | size_sb = cpi->oxcf.tile_heights[j++]; |
| 915 | if (j >= cpi->oxcf.tile_height_count) j = 0; |
| 916 | start_sb += AOMMIN(size_sb, cm->max_tile_height_sb); |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 917 | } |
| 918 | cm->tile_rows = i; |
| 919 | cm->tile_row_start_sb[i] = sb_rows; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 920 | } |
| 921 | av1_calculate_tile_rows(cm); |
| 922 | } |
| 923 | |
| 924 | #endif |
| 925 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 926 | static void set_tile_info(AV1_COMP *cpi) { |
| 927 | AV1_COMMON *const cm = &cpi->common; |
Thomas Davies | b25ba50 | 2017-07-18 10:18:24 +0100 | [diff] [blame] | 928 | #if CONFIG_DEPENDENT_HORZTILES |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 929 | int tile_row, tile_col, num_tiles_in_tg; |
| 930 | int tg_row_start, tg_col_start; |
| 931 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 932 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 933 | if (cpi->oxcf.large_scale_tile) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 934 | #if CONFIG_EXT_PARTITION |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 935 | if (cpi->oxcf.superblock_size != AOM_SUPERBLOCK_SIZE_64X64) { |
| 936 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 32); |
| 937 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 32); |
| 938 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 939 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
| 940 | } else { |
| 941 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 942 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
| 943 | cm->tile_width <<= MAX_MIB_SIZE_LOG2 - 1; |
| 944 | cm->tile_height <<= MAX_MIB_SIZE_LOG2 - 1; |
| 945 | } |
| 946 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 947 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 948 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 949 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 950 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 951 | #endif // CONFIG_EXT_PARTITION |
| 952 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 953 | cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols); |
| 954 | cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 955 | |
Yaowu Xu | 8d0039c | 2017-10-13 07:51:46 -0700 | [diff] [blame] | 956 | assert(cm->tile_width >> MAX_MIB_SIZE_LOG2 <= 32); |
| 957 | assert(cm->tile_height >> MAX_MIB_SIZE_LOG2 <= 32); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 958 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 959 | // Get the number of tiles |
| 960 | cm->tile_cols = 1; |
| 961 | 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] | 962 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 963 | cm->tile_rows = 1; |
| 964 | while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows; |
| 965 | } else { |
| 966 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 967 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 968 | #if CONFIG_MAX_TILE |
| 969 | set_tile_info_max_tile(cpi); |
| 970 | #else |
| 971 | int min_log2_tile_cols, max_log2_tile_cols; |
| 972 | 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] | 973 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 974 | cm->log2_tile_cols = |
| 975 | clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols); |
| 976 | cm->log2_tile_rows = cpi->oxcf.tile_rows; |
Rupert Swarbrick | 940942b | 2017-09-01 12:05:55 +0100 | [diff] [blame] | 977 | |
Rupert Swarbrick | 5a010aa | 2017-09-26 16:16:48 +0100 | [diff] [blame] | 978 | cm->tile_width = |
| 979 | get_tile_size(cm->mi_cols, cm->log2_tile_cols, &cm->tile_cols); |
| 980 | cm->tile_height = |
| 981 | 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] | 982 | #endif // CONFIG_MAX_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 983 | #if CONFIG_EXT_TILE |
| 984 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 985 | #endif // CONFIG_EXT_TILE |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 986 | |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 987 | #if CONFIG_DEPENDENT_HORZTILES |
| 988 | cm->dependent_horz_tiles = cpi->oxcf.dependent_horz_tiles; |
Fangwen Fu | 70bcb89 | 2017-05-06 17:05:19 -0700 | [diff] [blame] | 989 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 990 | if (cm->large_scale_tile) { |
| 991 | // May not needed since cpi->oxcf.dependent_horz_tiles is already adjusted. |
| 992 | cm->dependent_horz_tiles = 0; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 993 | } else { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 994 | #endif // CONFIG_EXT_TILE |
| 995 | if (cm->log2_tile_rows == 0) cm->dependent_horz_tiles = 0; |
| 996 | #if CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 997 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 998 | #endif // CONFIG_EXT_TILE |
| 999 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1000 | #if CONFIG_EXT_TILE |
| 1001 | if (!cm->large_scale_tile) { |
| 1002 | #endif // CONFIG_EXT_TILE |
| 1003 | if (cpi->oxcf.mtu == 0) { |
| 1004 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 1005 | } else { |
| 1006 | // Use a default value for the purposes of weighting costs in probability |
| 1007 | // updates |
| 1008 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1009 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1010 | num_tiles_in_tg = |
| 1011 | (cm->tile_cols * cm->tile_rows + cm->num_tg - 1) / cm->num_tg; |
| 1012 | tg_row_start = 0; |
| 1013 | tg_col_start = 0; |
| 1014 | for (tile_row = 0; tile_row < cm->tile_rows; ++tile_row) { |
| 1015 | for (tile_col = 0; tile_col < cm->tile_cols; ++tile_col) { |
| 1016 | if ((tile_row * cm->tile_cols + tile_col) % num_tiles_in_tg == 0) { |
| 1017 | tg_row_start = tile_row; |
| 1018 | tg_col_start = tile_col; |
| 1019 | } |
| 1020 | cm->tile_group_start_row[tile_row][tile_col] = tg_row_start; |
| 1021 | cm->tile_group_start_col[tile_row][tile_col] = tg_col_start; |
| 1022 | } |
| 1023 | } |
| 1024 | #if CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1025 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1026 | #endif // CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 1027 | #endif |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 1028 | |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 1029 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 1030 | cm->loop_filter_across_tiles_enabled = |
| 1031 | cpi->oxcf.loop_filter_across_tiles_enabled; |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 1032 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1035 | static void update_frame_size(AV1_COMP *cpi) { |
| 1036 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1037 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 1038 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1039 | av1_set_mb_mi(cm, cm->width, cm->height); |
| 1040 | av1_init_context_buffers(cm); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1041 | av1_init_macroblockd(cm, xd, |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 1042 | #if CONFIG_CFL |
| 1043 | &NULL_CFL, |
| 1044 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1045 | NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1046 | memset(cpi->mbmi_ext_base, 0, |
| 1047 | cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1048 | set_tile_info(cpi); |
| 1049 | } |
| 1050 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1051 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1052 | int fb_idx; |
| 1053 | for (fb_idx = 0; fb_idx < LAST_REF_FRAMES; ++fb_idx) |
| 1054 | cpi->lst_fb_idxes[fb_idx] = fb_idx; |
| 1055 | cpi->gld_fb_idx = LAST_REF_FRAMES; |
| 1056 | cpi->bwd_fb_idx = LAST_REF_FRAMES + 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1057 | cpi->alt2_fb_idx = LAST_REF_FRAMES + 2; |
| 1058 | cpi->alt_fb_idx = LAST_REF_FRAMES + 3; |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 1059 | cpi->ext_fb_idx = LAST_REF_FRAMES + 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1060 | for (fb_idx = 0; fb_idx < MAX_EXT_ARFS + 1; ++fb_idx) |
| 1061 | cpi->arf_map[fb_idx] = LAST_REF_FRAMES + 2 + fb_idx; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1062 | #if CONFIG_AMVR |
| 1063 | cpi->rate_index = 0; |
| 1064 | cpi->rate_size = 0; |
| 1065 | cpi->cur_poc = -1; |
| 1066 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1069 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 1070 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1071 | |
| 1072 | cpi->oxcf = *oxcf; |
| 1073 | cpi->framerate = oxcf->init_framerate; |
| 1074 | |
| 1075 | cm->profile = oxcf->profile; |
| 1076 | cm->bit_depth = oxcf->bit_depth; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1077 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1078 | cm->use_highbitdepth = oxcf->use_highbitdepth; |
| 1079 | #endif |
| 1080 | cm->color_space = oxcf->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 1081 | #if CONFIG_COLORSPACE_HEADERS |
| 1082 | cm->transfer_function = oxcf->transfer_function; |
| 1083 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
| 1084 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1085 | cm->color_range = oxcf->color_range; |
| 1086 | |
| 1087 | cm->width = oxcf->width; |
| 1088 | cm->height = oxcf->height; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 1089 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1090 | |
| 1091 | // Single thread case: use counts in common. |
| 1092 | cpi->td.counts = &cm->counts; |
| 1093 | |
| 1094 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1095 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1096 | |
| 1097 | cpi->static_mb_pct = 0; |
| 1098 | cpi->ref_frame_flags = 0; |
| 1099 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 1100 | // Reset resize pending flags |
| 1101 | cpi->resize_pending_width = 0; |
| 1102 | cpi->resize_pending_height = 0; |
| 1103 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1104 | init_buffer_indices(cpi); |
| 1105 | } |
| 1106 | |
| 1107 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1108 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1109 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 1110 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 1111 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 1112 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 1113 | |
| 1114 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 1115 | rc->optimal_buffer_level = |
| 1116 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1117 | rc->maximum_buffer_size = |
| 1118 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1119 | } |
| 1120 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1121 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1122 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 1123 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1124 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1125 | cpi->fn_ptr[BT].vf = VF; \ |
| 1126 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1127 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1128 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 1129 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 1130 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
| 1131 | |
| 1132 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1133 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1134 | int source_stride, \ |
| 1135 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1136 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1137 | } \ |
| 1138 | static unsigned int fnname##_bits10( \ |
| 1139 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1140 | int ref_stride) { \ |
| 1141 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1142 | } \ |
| 1143 | static unsigned int fnname##_bits12( \ |
| 1144 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1145 | int ref_stride) { \ |
| 1146 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1147 | } |
| 1148 | |
| 1149 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1150 | static unsigned int fnname##_bits8( \ |
| 1151 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1152 | int ref_stride, const uint8_t *second_pred) { \ |
| 1153 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1154 | } \ |
| 1155 | static unsigned int fnname##_bits10( \ |
| 1156 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1157 | int ref_stride, const uint8_t *second_pred) { \ |
| 1158 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1159 | 2; \ |
| 1160 | } \ |
| 1161 | static unsigned int fnname##_bits12( \ |
| 1162 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1163 | int ref_stride, const uint8_t *second_pred) { \ |
| 1164 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1165 | 4; \ |
| 1166 | } |
| 1167 | |
| 1168 | #define MAKE_BFP_SAD3_WRAPPER(fnname) \ |
| 1169 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1170 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1171 | unsigned int *sad_array) { \ |
| 1172 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1173 | } \ |
| 1174 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1175 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1176 | unsigned int *sad_array) { \ |
| 1177 | int i; \ |
| 1178 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1179 | for (i = 0; i < 3; i++) sad_array[i] >>= 2; \ |
| 1180 | } \ |
| 1181 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1182 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1183 | unsigned int *sad_array) { \ |
| 1184 | int i; \ |
| 1185 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1186 | for (i = 0; i < 3; i++) sad_array[i] >>= 4; \ |
| 1187 | } |
| 1188 | |
| 1189 | #define MAKE_BFP_SAD8_WRAPPER(fnname) \ |
| 1190 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1191 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1192 | unsigned int *sad_array) { \ |
| 1193 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1194 | } \ |
| 1195 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1196 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1197 | unsigned int *sad_array) { \ |
| 1198 | int i; \ |
| 1199 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1200 | for (i = 0; i < 8; i++) sad_array[i] >>= 2; \ |
| 1201 | } \ |
| 1202 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1203 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1204 | unsigned int *sad_array) { \ |
| 1205 | int i; \ |
| 1206 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1207 | for (i = 0; i < 8; i++) sad_array[i] >>= 4; \ |
| 1208 | } |
| 1209 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1210 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1211 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1212 | unsigned int *sad_array) { \ |
| 1213 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1214 | } \ |
| 1215 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1216 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1217 | unsigned int *sad_array) { \ |
| 1218 | int i; \ |
| 1219 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1220 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1221 | } \ |
| 1222 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1223 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1224 | unsigned int *sad_array) { \ |
| 1225 | int i; \ |
| 1226 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1227 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1228 | } |
| 1229 | |
| 1230 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1231 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1232 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
| 1233 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad128x128x3) |
| 1234 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad128x128x8) |
| 1235 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1236 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1237 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1238 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1239 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1240 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1241 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1242 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1243 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1244 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1245 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1246 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1247 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1248 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1249 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1250 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1251 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1252 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1253 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1254 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1255 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1256 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
| 1257 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad32x32x3) |
| 1258 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad32x32x8) |
| 1259 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1260 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1261 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
| 1262 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad64x64x3) |
| 1263 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad64x64x8) |
| 1264 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1265 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1266 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
| 1267 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x16x3) |
| 1268 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x16x8) |
| 1269 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1270 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1271 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
| 1272 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x8x3) |
| 1273 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x8x8) |
| 1274 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1275 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1276 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
| 1277 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x16x3) |
| 1278 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x16x8) |
| 1279 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1280 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1281 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
| 1282 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x8x3) |
| 1283 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x8x8) |
| 1284 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1285 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1286 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
| 1287 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x4x8) |
| 1288 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1289 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1290 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
| 1291 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x8x8) |
| 1292 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1293 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1294 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
| 1295 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad4x4x3) |
| 1296 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x4x8) |
| 1297 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1298 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1299 | #if CONFIG_EXT_PARTITION_TYPES |
| 1300 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16) |
| 1301 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg) |
| 1302 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d) |
| 1303 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4) |
| 1304 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg) |
| 1305 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d) |
| 1306 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32) |
| 1307 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg) |
| 1308 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d) |
| 1309 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8) |
| 1310 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg) |
| 1311 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1312 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64) |
| 1313 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg) |
| 1314 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d) |
| 1315 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16) |
| 1316 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg) |
| 1317 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1318 | #if CONFIG_EXT_PARTITION |
| 1319 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x128) |
| 1320 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x128_avg) |
| 1321 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x128x4d) |
| 1322 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x32) |
| 1323 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x32_avg) |
| 1324 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x32x4d) |
| 1325 | #endif // CONFIG_EXT_PARTITION |
| 1326 | #endif // CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1327 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1328 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1329 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1330 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1331 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1332 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1333 | static unsigned int fnname##_bits8( \ |
| 1334 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1335 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1336 | int m_stride, int invert_mask) { \ |
| 1337 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1338 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1339 | } \ |
| 1340 | static unsigned int fnname##_bits10( \ |
| 1341 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1342 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1343 | int m_stride, int invert_mask) { \ |
| 1344 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1345 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1346 | 2; \ |
| 1347 | } \ |
| 1348 | static unsigned int fnname##_bits12( \ |
| 1349 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1350 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1351 | int m_stride, int invert_mask) { \ |
| 1352 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1353 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1354 | 4; \ |
| 1355 | } |
| 1356 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1357 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1358 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1359 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1360 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1361 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1362 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1363 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1364 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1365 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1366 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1367 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1368 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1369 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1370 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1371 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1372 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1373 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1374 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1375 | |
| 1376 | #if CONFIG_EXT_PARTITION_TYPES |
| 1377 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1378 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1379 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1380 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1381 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1382 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1383 | #if CONFIG_EXT_PARTITION |
| 1384 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x128) |
| 1385 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x32) |
| 1386 | #endif // CONFIG_EXT_PARTITION |
| 1387 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1388 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1389 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1390 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1391 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1392 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1393 | |
| 1394 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1395 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1396 | const int32_t *wsrc, \ |
| 1397 | const int32_t *msk) { \ |
| 1398 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1399 | } \ |
| 1400 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1401 | const int32_t *wsrc, \ |
| 1402 | const int32_t *msk) { \ |
| 1403 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1404 | } \ |
| 1405 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1406 | const int32_t *wsrc, \ |
| 1407 | const int32_t *msk) { \ |
| 1408 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1409 | } |
| 1410 | |
| 1411 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1412 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1413 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1414 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1415 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1416 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1417 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1418 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1419 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1420 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1421 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1422 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1423 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1424 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1425 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1426 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1427 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1428 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1429 | |
| 1430 | #if CONFIG_EXT_PARTITION_TYPES |
| 1431 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1432 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1433 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1434 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1435 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1436 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1437 | #if CONFIG_EXT_PARTITION |
| 1438 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x128) |
| 1439 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x32) |
| 1440 | #endif // CONFIG_EXT_PARTITION |
| 1441 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1442 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1443 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1444 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1445 | if (cm->use_highbitdepth) { |
| 1446 | switch (cm->bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1447 | case AOM_BITS_8: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1448 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1449 | #if CONFIG_EXT_PARTITION |
| 1450 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits8, |
| 1451 | aom_highbd_sad128x32_avg_bits8, aom_highbd_8_variance128x32, |
| 1452 | aom_highbd_8_sub_pixel_variance128x32, |
| 1453 | aom_highbd_8_sub_pixel_avg_variance128x32, NULL, NULL, |
| 1454 | aom_highbd_sad128x32x4d_bits8) |
| 1455 | |
| 1456 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits8, |
| 1457 | aom_highbd_sad32x128_avg_bits8, aom_highbd_8_variance32x128, |
| 1458 | aom_highbd_8_sub_pixel_variance32x128, |
| 1459 | aom_highbd_8_sub_pixel_avg_variance32x128, NULL, NULL, |
| 1460 | aom_highbd_sad32x128x4d_bits8) |
| 1461 | #endif // CONFIG_EXT_PARTITION |
| 1462 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1463 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1464 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1465 | aom_highbd_8_sub_pixel_variance64x16, |
| 1466 | aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1467 | aom_highbd_sad64x16x4d_bits8) |
| 1468 | |
| 1469 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1470 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1471 | aom_highbd_8_sub_pixel_variance16x64, |
| 1472 | aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1473 | aom_highbd_sad16x64x4d_bits8) |
| 1474 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1475 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits8, |
| 1476 | aom_highbd_sad32x8_avg_bits8, aom_highbd_8_variance32x8, |
| 1477 | aom_highbd_8_sub_pixel_variance32x8, |
| 1478 | aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1479 | aom_highbd_sad32x8x4d_bits8) |
| 1480 | |
| 1481 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits8, |
| 1482 | aom_highbd_sad8x32_avg_bits8, aom_highbd_8_variance8x32, |
| 1483 | aom_highbd_8_sub_pixel_variance8x32, |
| 1484 | aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1485 | aom_highbd_sad8x32x4d_bits8) |
| 1486 | |
| 1487 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits8, |
| 1488 | aom_highbd_sad16x4_avg_bits8, aom_highbd_8_variance16x4, |
| 1489 | aom_highbd_8_sub_pixel_variance16x4, |
| 1490 | aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1491 | aom_highbd_sad16x4x4d_bits8) |
| 1492 | |
| 1493 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits8, |
| 1494 | aom_highbd_sad4x16_avg_bits8, aom_highbd_8_variance4x16, |
| 1495 | aom_highbd_8_sub_pixel_variance4x16, |
| 1496 | aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1497 | aom_highbd_sad4x16x4d_bits8) |
| 1498 | #endif |
| 1499 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1500 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1501 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1502 | aom_highbd_8_sub_pixel_variance32x16, |
| 1503 | aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1504 | aom_highbd_sad32x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1505 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1506 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1507 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1508 | aom_highbd_8_sub_pixel_variance16x32, |
| 1509 | aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1510 | aom_highbd_sad16x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1511 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1512 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1513 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1514 | aom_highbd_8_sub_pixel_variance64x32, |
| 1515 | aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1516 | aom_highbd_sad64x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1517 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1518 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1519 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1520 | aom_highbd_8_sub_pixel_variance32x64, |
| 1521 | aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1522 | aom_highbd_sad32x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1523 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1524 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1525 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1526 | aom_highbd_8_sub_pixel_variance32x32, |
| 1527 | aom_highbd_8_sub_pixel_avg_variance32x32, |
| 1528 | aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8, |
| 1529 | aom_highbd_sad32x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1530 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1531 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1532 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1533 | aom_highbd_8_sub_pixel_variance64x64, |
| 1534 | aom_highbd_8_sub_pixel_avg_variance64x64, |
| 1535 | aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8, |
| 1536 | aom_highbd_sad64x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1537 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1538 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1539 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1540 | aom_highbd_8_sub_pixel_variance16x16, |
| 1541 | aom_highbd_8_sub_pixel_avg_variance16x16, |
| 1542 | aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8, |
| 1543 | aom_highbd_sad16x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1544 | |
| 1545 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1546 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1547 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
| 1548 | aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8, |
| 1549 | aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1550 | |
| 1551 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1552 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1553 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
| 1554 | aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8, |
| 1555 | aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1556 | |
| 1557 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1558 | BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8, |
| 1559 | aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8, |
| 1560 | aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits8, |
| 1561 | aom_highbd_sad8x8x8_bits8, aom_highbd_sad8x8x4d_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_8X4, aom_highbd_sad8x4_bits8, |
| 1564 | aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4, |
| 1565 | aom_highbd_8_sub_pixel_variance8x4, |
| 1566 | aom_highbd_8_sub_pixel_avg_variance8x4, NULL, |
| 1567 | aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_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_4X8, aom_highbd_sad4x8_bits8, |
| 1570 | aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8, |
| 1571 | aom_highbd_8_sub_pixel_variance4x8, |
| 1572 | aom_highbd_8_sub_pixel_avg_variance4x8, NULL, |
| 1573 | aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1574 | |
| 1575 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1576 | BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8, |
| 1577 | aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4, |
| 1578 | aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits8, |
| 1579 | aom_highbd_sad4x4x8_bits8, aom_highbd_sad4x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1580 | |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1581 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_8_variance2x2, NULL, NULL, |
| 1582 | NULL, NULL, NULL) |
| 1583 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_8_variance4x2, NULL, NULL, |
| 1584 | NULL, NULL, NULL) |
| 1585 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_8_variance2x4, NULL, NULL, |
| 1586 | NULL, NULL, NULL) |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1587 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1588 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1589 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1590 | aom_highbd_sad128x128_avg_bits8, |
| 1591 | aom_highbd_8_variance128x128, |
| 1592 | aom_highbd_8_sub_pixel_variance128x128, |
| 1593 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1594 | aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8, |
| 1595 | aom_highbd_sad128x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1596 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1597 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1598 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1599 | aom_highbd_8_sub_pixel_variance128x64, |
| 1600 | aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1601 | aom_highbd_sad128x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1602 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1603 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1604 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1605 | aom_highbd_8_sub_pixel_variance64x128, |
| 1606 | aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1607 | aom_highbd_sad64x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1608 | #endif // CONFIG_EXT_PARTITION |
| 1609 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1610 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1611 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1612 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1613 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1614 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1615 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1616 | aom_highbd_8_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1617 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1618 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1619 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1620 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1621 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1622 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1623 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1624 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1625 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1626 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1627 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1628 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1629 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1630 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1631 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1632 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1633 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1634 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1635 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1636 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1637 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1638 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1639 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1640 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1641 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1642 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1643 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1644 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1645 | #if CONFIG_EXT_PARTITION |
| 1646 | HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits8, |
| 1647 | aom_highbd_8_masked_sub_pixel_variance128x32) |
| 1648 | |
| 1649 | HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits8, |
| 1650 | aom_highbd_8_masked_sub_pixel_variance32x128) |
| 1651 | #endif // CONFIG_EXT_PARTITION |
| 1652 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1653 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1654 | aom_highbd_8_masked_sub_pixel_variance64x16) |
| 1655 | |
| 1656 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1657 | aom_highbd_8_masked_sub_pixel_variance16x64) |
| 1658 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1659 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1660 | aom_highbd_8_masked_sub_pixel_variance32x8) |
| 1661 | |
| 1662 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1663 | aom_highbd_8_masked_sub_pixel_variance8x32) |
| 1664 | |
| 1665 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1666 | aom_highbd_8_masked_sub_pixel_variance16x4) |
| 1667 | |
| 1668 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1669 | aom_highbd_8_masked_sub_pixel_variance4x16) |
| 1670 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1671 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1672 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1673 | aom_highbd_obmc_variance128x128, |
| 1674 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1675 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1676 | aom_highbd_obmc_variance128x64, |
| 1677 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1678 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1679 | aom_highbd_obmc_variance64x128, |
| 1680 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1681 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1682 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1683 | aom_highbd_obmc_variance64x64, |
| 1684 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1685 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1686 | aom_highbd_obmc_variance64x32, |
| 1687 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1688 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1689 | aom_highbd_obmc_variance32x64, |
| 1690 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1691 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1692 | aom_highbd_obmc_variance32x32, |
| 1693 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1694 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1695 | aom_highbd_obmc_variance32x16, |
| 1696 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1697 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1698 | aom_highbd_obmc_variance16x32, |
| 1699 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1700 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1701 | aom_highbd_obmc_variance16x16, |
| 1702 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1703 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1704 | aom_highbd_obmc_variance8x16, |
| 1705 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1706 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1707 | aom_highbd_obmc_variance16x8, |
| 1708 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1709 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1710 | aom_highbd_obmc_variance8x8, |
| 1711 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 1712 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 1713 | aom_highbd_obmc_variance4x8, |
| 1714 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 1715 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 1716 | aom_highbd_obmc_variance8x4, |
| 1717 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 1718 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 1719 | aom_highbd_obmc_variance4x4, |
| 1720 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1721 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1722 | #if CONFIG_EXT_PARTITION |
| 1723 | HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits8, |
| 1724 | aom_highbd_obmc_variance128x32, |
| 1725 | aom_highbd_obmc_sub_pixel_variance128x32) |
| 1726 | |
| 1727 | HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits8, |
| 1728 | aom_highbd_obmc_variance32x128, |
| 1729 | aom_highbd_obmc_sub_pixel_variance32x128) |
| 1730 | #endif // CONFIG_EXT_PARTITION |
| 1731 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1732 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 1733 | aom_highbd_obmc_variance64x16, |
| 1734 | aom_highbd_obmc_sub_pixel_variance64x16) |
| 1735 | |
| 1736 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 1737 | aom_highbd_obmc_variance16x64, |
| 1738 | aom_highbd_obmc_sub_pixel_variance16x64) |
| 1739 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1740 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 1741 | aom_highbd_obmc_variance32x8, |
| 1742 | aom_highbd_obmc_sub_pixel_variance32x8) |
| 1743 | |
| 1744 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 1745 | aom_highbd_obmc_variance8x32, |
| 1746 | aom_highbd_obmc_sub_pixel_variance8x32) |
| 1747 | |
| 1748 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 1749 | aom_highbd_obmc_variance16x4, |
| 1750 | aom_highbd_obmc_sub_pixel_variance16x4) |
| 1751 | |
| 1752 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 1753 | aom_highbd_obmc_variance4x16, |
| 1754 | aom_highbd_obmc_sub_pixel_variance4x16) |
| 1755 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1756 | break; |
| 1757 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1758 | case AOM_BITS_10: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1759 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1760 | #if CONFIG_EXT_PARTITION |
| 1761 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits10, |
| 1762 | aom_highbd_sad128x32_avg_bits10, |
| 1763 | aom_highbd_10_variance128x32, |
| 1764 | aom_highbd_10_sub_pixel_variance128x32, |
| 1765 | aom_highbd_10_sub_pixel_avg_variance128x32, NULL, NULL, |
| 1766 | aom_highbd_sad128x32x4d_bits10) |
| 1767 | |
| 1768 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits10, |
| 1769 | aom_highbd_sad32x128_avg_bits10, |
| 1770 | aom_highbd_10_variance32x128, |
| 1771 | aom_highbd_10_sub_pixel_variance32x128, |
| 1772 | aom_highbd_10_sub_pixel_avg_variance32x128, NULL, NULL, |
| 1773 | aom_highbd_sad32x128x4d_bits10) |
| 1774 | #endif // CONFIG_EXT_PARTITION |
| 1775 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1776 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 1777 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 1778 | aom_highbd_10_sub_pixel_variance64x16, |
| 1779 | aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1780 | aom_highbd_sad64x16x4d_bits10) |
| 1781 | |
| 1782 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 1783 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 1784 | aom_highbd_10_sub_pixel_variance16x64, |
| 1785 | aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1786 | aom_highbd_sad16x64x4d_bits10) |
| 1787 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1788 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 1789 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 1790 | aom_highbd_10_sub_pixel_variance32x8, |
| 1791 | aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1792 | aom_highbd_sad32x8x4d_bits10) |
| 1793 | |
| 1794 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 1795 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 1796 | aom_highbd_10_sub_pixel_variance8x32, |
| 1797 | aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1798 | aom_highbd_sad8x32x4d_bits10) |
| 1799 | |
| 1800 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 1801 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 1802 | aom_highbd_10_sub_pixel_variance16x4, |
| 1803 | aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1804 | aom_highbd_sad16x4x4d_bits10) |
| 1805 | |
| 1806 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 1807 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 1808 | aom_highbd_10_sub_pixel_variance4x16, |
| 1809 | aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1810 | aom_highbd_sad4x16x4d_bits10) |
| 1811 | #endif |
| 1812 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1813 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 1814 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 1815 | aom_highbd_10_sub_pixel_variance32x16, |
| 1816 | aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1817 | aom_highbd_sad32x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1818 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1819 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 1820 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 1821 | aom_highbd_10_sub_pixel_variance16x32, |
| 1822 | aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1823 | aom_highbd_sad16x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1824 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1825 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 1826 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 1827 | aom_highbd_10_sub_pixel_variance64x32, |
| 1828 | aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1829 | aom_highbd_sad64x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1830 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1831 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 1832 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 1833 | aom_highbd_10_sub_pixel_variance32x64, |
| 1834 | aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1835 | aom_highbd_sad32x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1836 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1837 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 1838 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 1839 | aom_highbd_10_sub_pixel_variance32x32, |
| 1840 | aom_highbd_10_sub_pixel_avg_variance32x32, |
| 1841 | aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10, |
| 1842 | aom_highbd_sad32x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1843 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1844 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 1845 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 1846 | aom_highbd_10_sub_pixel_variance64x64, |
| 1847 | aom_highbd_10_sub_pixel_avg_variance64x64, |
| 1848 | aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10, |
| 1849 | aom_highbd_sad64x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1850 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1851 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 1852 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 1853 | aom_highbd_10_sub_pixel_variance16x16, |
| 1854 | aom_highbd_10_sub_pixel_avg_variance16x16, |
| 1855 | aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10, |
| 1856 | aom_highbd_sad16x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1857 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1858 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 1859 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 1860 | aom_highbd_10_sub_pixel_variance16x8, |
| 1861 | aom_highbd_10_sub_pixel_avg_variance16x8, |
| 1862 | aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10, |
| 1863 | aom_highbd_sad16x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1864 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1865 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 1866 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 1867 | aom_highbd_10_sub_pixel_variance8x16, |
| 1868 | aom_highbd_10_sub_pixel_avg_variance8x16, |
| 1869 | aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10, |
| 1870 | aom_highbd_sad8x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1871 | |
| 1872 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1873 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 1874 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
| 1875 | aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10, |
| 1876 | aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1877 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1878 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10, |
| 1879 | aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4, |
| 1880 | aom_highbd_10_sub_pixel_variance8x4, |
| 1881 | aom_highbd_10_sub_pixel_avg_variance8x4, NULL, |
| 1882 | aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1883 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1884 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10, |
| 1885 | aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8, |
| 1886 | aom_highbd_10_sub_pixel_variance4x8, |
| 1887 | aom_highbd_10_sub_pixel_avg_variance4x8, NULL, |
| 1888 | aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1889 | |
| 1890 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1891 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 1892 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
| 1893 | aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10, |
| 1894 | aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1895 | |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1896 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_10_variance2x2, NULL, NULL, |
| 1897 | NULL, NULL, NULL) |
| 1898 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_10_variance4x2, NULL, NULL, |
| 1899 | NULL, NULL, NULL) |
| 1900 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_10_variance2x4, NULL, NULL, |
| 1901 | NULL, NULL, NULL) |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1902 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1903 | #if CONFIG_EXT_PARTITION |
| 1904 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1905 | BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 1906 | aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128, |
| 1907 | aom_highbd_10_sub_pixel_variance128x128, |
| 1908 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 1909 | aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10, |
| 1910 | aom_highbd_sad128x128x4d_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_128X64, aom_highbd_sad128x64_bits10, |
| 1913 | aom_highbd_sad128x64_avg_bits10, |
| 1914 | aom_highbd_10_variance128x64, |
| 1915 | aom_highbd_10_sub_pixel_variance128x64, |
| 1916 | aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1917 | aom_highbd_sad128x64x4d_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_64X128, aom_highbd_sad64x128_bits10, |
| 1920 | aom_highbd_sad64x128_avg_bits10, |
| 1921 | aom_highbd_10_variance64x128, |
| 1922 | aom_highbd_10_sub_pixel_variance64x128, |
| 1923 | aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1924 | aom_highbd_sad64x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1925 | #endif // CONFIG_EXT_PARTITION |
| 1926 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1927 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1928 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 1929 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 1930 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 1931 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 1932 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 1933 | aom_highbd_10_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1934 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1935 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 1936 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 1937 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 1938 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 1939 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 1940 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 1941 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 1942 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 1943 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 1944 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 1945 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 1946 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 1947 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 1948 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 1949 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 1950 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 1951 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 1952 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 1953 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 1954 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 1955 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 1956 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 1957 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 1958 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 1959 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 1960 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1961 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1962 | #if CONFIG_EXT_PARTITION |
| 1963 | HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits10, |
| 1964 | aom_highbd_10_masked_sub_pixel_variance128x32) |
| 1965 | |
| 1966 | HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits10, |
| 1967 | aom_highbd_10_masked_sub_pixel_variance32x128) |
| 1968 | #endif // CONFIG_EXT_PARTITION |
| 1969 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1970 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 1971 | aom_highbd_10_masked_sub_pixel_variance64x16) |
| 1972 | |
| 1973 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 1974 | aom_highbd_10_masked_sub_pixel_variance16x64) |
| 1975 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1976 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 1977 | aom_highbd_10_masked_sub_pixel_variance32x8) |
| 1978 | |
| 1979 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 1980 | aom_highbd_10_masked_sub_pixel_variance8x32) |
| 1981 | |
| 1982 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 1983 | aom_highbd_10_masked_sub_pixel_variance16x4) |
| 1984 | |
| 1985 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 1986 | aom_highbd_10_masked_sub_pixel_variance4x16) |
| 1987 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1988 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1989 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 1990 | aom_highbd_10_obmc_variance128x128, |
| 1991 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 1992 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 1993 | aom_highbd_10_obmc_variance128x64, |
| 1994 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 1995 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 1996 | aom_highbd_10_obmc_variance64x128, |
| 1997 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1998 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1999 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 2000 | aom_highbd_10_obmc_variance64x64, |
| 2001 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 2002 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 2003 | aom_highbd_10_obmc_variance64x32, |
| 2004 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 2005 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 2006 | aom_highbd_10_obmc_variance32x64, |
| 2007 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 2008 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 2009 | aom_highbd_10_obmc_variance32x32, |
| 2010 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 2011 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 2012 | aom_highbd_10_obmc_variance32x16, |
| 2013 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 2014 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 2015 | aom_highbd_10_obmc_variance16x32, |
| 2016 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 2017 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 2018 | aom_highbd_10_obmc_variance16x16, |
| 2019 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 2020 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 2021 | aom_highbd_10_obmc_variance8x16, |
| 2022 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 2023 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 2024 | aom_highbd_10_obmc_variance16x8, |
| 2025 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 2026 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 2027 | aom_highbd_10_obmc_variance8x8, |
| 2028 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 2029 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 2030 | aom_highbd_10_obmc_variance4x8, |
| 2031 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 2032 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 2033 | aom_highbd_10_obmc_variance8x4, |
| 2034 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 2035 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 2036 | aom_highbd_10_obmc_variance4x4, |
| 2037 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2038 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2039 | #if CONFIG_EXT_PARTITION |
| 2040 | HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits10, |
| 2041 | aom_highbd_10_obmc_variance128x32, |
| 2042 | aom_highbd_10_obmc_sub_pixel_variance128x32) |
| 2043 | |
| 2044 | HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits10, |
| 2045 | aom_highbd_10_obmc_variance32x128, |
| 2046 | aom_highbd_10_obmc_sub_pixel_variance32x128) |
| 2047 | #endif // CONFIG_EXT_PARTITION |
| 2048 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2049 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 2050 | aom_highbd_10_obmc_variance64x16, |
| 2051 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 2052 | |
| 2053 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 2054 | aom_highbd_10_obmc_variance16x64, |
| 2055 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 2056 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2057 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 2058 | aom_highbd_10_obmc_variance32x8, |
| 2059 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 2060 | |
| 2061 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 2062 | aom_highbd_10_obmc_variance8x32, |
| 2063 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 2064 | |
| 2065 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 2066 | aom_highbd_10_obmc_variance16x4, |
| 2067 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 2068 | |
| 2069 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 2070 | aom_highbd_10_obmc_variance4x16, |
| 2071 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
| 2072 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2073 | break; |
| 2074 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2075 | case AOM_BITS_12: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2076 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2077 | #if CONFIG_EXT_PARTITION |
| 2078 | HIGHBD_BFP(BLOCK_128X32, aom_highbd_sad128x32_bits12, |
| 2079 | aom_highbd_sad128x32_avg_bits12, |
| 2080 | aom_highbd_12_variance128x32, |
| 2081 | aom_highbd_12_sub_pixel_variance128x32, |
| 2082 | aom_highbd_12_sub_pixel_avg_variance128x32, NULL, NULL, |
| 2083 | aom_highbd_sad128x32x4d_bits12) |
| 2084 | |
| 2085 | HIGHBD_BFP(BLOCK_32X128, aom_highbd_sad32x128_bits12, |
| 2086 | aom_highbd_sad32x128_avg_bits12, |
| 2087 | aom_highbd_12_variance32x128, |
| 2088 | aom_highbd_12_sub_pixel_variance32x128, |
| 2089 | aom_highbd_12_sub_pixel_avg_variance32x128, NULL, NULL, |
| 2090 | aom_highbd_sad32x128x4d_bits12) |
| 2091 | #endif // CONFIG_EXT_PARTITION |
| 2092 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2093 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 2094 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 2095 | aom_highbd_12_sub_pixel_variance64x16, |
| 2096 | aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2097 | aom_highbd_sad64x16x4d_bits12) |
| 2098 | |
| 2099 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 2100 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 2101 | aom_highbd_12_sub_pixel_variance16x64, |
| 2102 | aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2103 | aom_highbd_sad16x64x4d_bits12) |
| 2104 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2105 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 2106 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 2107 | aom_highbd_12_sub_pixel_variance32x8, |
| 2108 | aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2109 | aom_highbd_sad32x8x4d_bits12) |
| 2110 | |
| 2111 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 2112 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 2113 | aom_highbd_12_sub_pixel_variance8x32, |
| 2114 | aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2115 | aom_highbd_sad8x32x4d_bits12) |
| 2116 | |
| 2117 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 2118 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 2119 | aom_highbd_12_sub_pixel_variance16x4, |
| 2120 | aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2121 | aom_highbd_sad16x4x4d_bits12) |
| 2122 | |
| 2123 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 2124 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 2125 | aom_highbd_12_sub_pixel_variance4x16, |
| 2126 | aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2127 | aom_highbd_sad4x16x4d_bits12) |
| 2128 | #endif |
| 2129 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2130 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 2131 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 2132 | aom_highbd_12_sub_pixel_variance32x16, |
| 2133 | aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2134 | aom_highbd_sad32x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2135 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2136 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 2137 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 2138 | aom_highbd_12_sub_pixel_variance16x32, |
| 2139 | aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2140 | aom_highbd_sad16x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2141 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2142 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 2143 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 2144 | aom_highbd_12_sub_pixel_variance64x32, |
| 2145 | aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2146 | aom_highbd_sad64x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2147 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2148 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 2149 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 2150 | aom_highbd_12_sub_pixel_variance32x64, |
| 2151 | aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2152 | aom_highbd_sad32x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2153 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2154 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 2155 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 2156 | aom_highbd_12_sub_pixel_variance32x32, |
| 2157 | aom_highbd_12_sub_pixel_avg_variance32x32, |
| 2158 | aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12, |
| 2159 | aom_highbd_sad32x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2160 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2161 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2162 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2163 | aom_highbd_12_sub_pixel_variance64x64, |
| 2164 | aom_highbd_12_sub_pixel_avg_variance64x64, |
| 2165 | aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12, |
| 2166 | aom_highbd_sad64x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2167 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2168 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2169 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2170 | aom_highbd_12_sub_pixel_variance16x16, |
| 2171 | aom_highbd_12_sub_pixel_avg_variance16x16, |
| 2172 | aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12, |
| 2173 | aom_highbd_sad16x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2174 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2175 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2176 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2177 | aom_highbd_12_sub_pixel_variance16x8, |
| 2178 | aom_highbd_12_sub_pixel_avg_variance16x8, |
| 2179 | aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12, |
| 2180 | aom_highbd_sad16x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2181 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2182 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2183 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2184 | aom_highbd_12_sub_pixel_variance8x16, |
| 2185 | aom_highbd_12_sub_pixel_avg_variance8x16, |
| 2186 | aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12, |
| 2187 | aom_highbd_sad8x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2188 | |
| 2189 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2190 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2191 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
| 2192 | aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12, |
| 2193 | aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2194 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2195 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12, |
| 2196 | aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4, |
| 2197 | aom_highbd_12_sub_pixel_variance8x4, |
| 2198 | aom_highbd_12_sub_pixel_avg_variance8x4, NULL, |
| 2199 | aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_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_4X8, aom_highbd_sad4x8_bits12, |
| 2202 | aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8, |
| 2203 | aom_highbd_12_sub_pixel_variance4x8, |
| 2204 | aom_highbd_12_sub_pixel_avg_variance4x8, NULL, |
| 2205 | aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2206 | |
| 2207 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2208 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2209 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
| 2210 | aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12, |
| 2211 | aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2212 | |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 2213 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_12_variance2x2, NULL, NULL, |
| 2214 | NULL, NULL, NULL) |
| 2215 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_12_variance4x2, NULL, NULL, |
| 2216 | NULL, NULL, NULL) |
| 2217 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_12_variance2x4, NULL, NULL, |
| 2218 | NULL, NULL, NULL) |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 2219 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2220 | #if CONFIG_EXT_PARTITION |
| 2221 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2222 | BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2223 | aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128, |
| 2224 | aom_highbd_12_sub_pixel_variance128x128, |
| 2225 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2226 | aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12, |
| 2227 | aom_highbd_sad128x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2228 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2229 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2230 | aom_highbd_sad128x64_avg_bits12, |
| 2231 | aom_highbd_12_variance128x64, |
| 2232 | aom_highbd_12_sub_pixel_variance128x64, |
| 2233 | aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL, |
| 2234 | aom_highbd_sad128x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2235 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2236 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2237 | aom_highbd_sad64x128_avg_bits12, |
| 2238 | aom_highbd_12_variance64x128, |
| 2239 | aom_highbd_12_sub_pixel_variance64x128, |
| 2240 | aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL, |
| 2241 | aom_highbd_sad64x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2242 | #endif // CONFIG_EXT_PARTITION |
| 2243 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2244 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2245 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2246 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2247 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2248 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2249 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2250 | aom_highbd_12_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2251 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2252 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2253 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2254 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2255 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2256 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2257 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2258 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2259 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2260 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2261 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2262 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2263 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2264 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2265 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2266 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2267 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2268 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2269 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2270 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2271 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2272 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2273 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2274 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2275 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2276 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2277 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2278 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2279 | #if CONFIG_EXT_PARTITION |
| 2280 | HIGHBD_MBFP(BLOCK_128X32, aom_highbd_masked_sad128x32_bits12, |
| 2281 | aom_highbd_12_masked_sub_pixel_variance128x32) |
| 2282 | |
| 2283 | HIGHBD_MBFP(BLOCK_32X128, aom_highbd_masked_sad32x128_bits12, |
| 2284 | aom_highbd_12_masked_sub_pixel_variance32x128) |
| 2285 | #endif // CONFIG_EXT_PARTITION |
| 2286 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2287 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2288 | aom_highbd_12_masked_sub_pixel_variance64x16) |
| 2289 | |
| 2290 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2291 | aom_highbd_12_masked_sub_pixel_variance16x64) |
| 2292 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2293 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2294 | aom_highbd_12_masked_sub_pixel_variance32x8) |
| 2295 | |
| 2296 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2297 | aom_highbd_12_masked_sub_pixel_variance8x32) |
| 2298 | |
| 2299 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2300 | aom_highbd_12_masked_sub_pixel_variance16x4) |
| 2301 | |
| 2302 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2303 | aom_highbd_12_masked_sub_pixel_variance4x16) |
| 2304 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2305 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2306 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2307 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2308 | aom_highbd_12_obmc_variance128x128, |
| 2309 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2310 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2311 | aom_highbd_12_obmc_variance128x64, |
| 2312 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 2313 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 2314 | aom_highbd_12_obmc_variance64x128, |
| 2315 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2316 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2317 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 2318 | aom_highbd_12_obmc_variance64x64, |
| 2319 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 2320 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 2321 | aom_highbd_12_obmc_variance64x32, |
| 2322 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 2323 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 2324 | aom_highbd_12_obmc_variance32x64, |
| 2325 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 2326 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 2327 | aom_highbd_12_obmc_variance32x32, |
| 2328 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 2329 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 2330 | aom_highbd_12_obmc_variance32x16, |
| 2331 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 2332 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 2333 | aom_highbd_12_obmc_variance16x32, |
| 2334 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 2335 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 2336 | aom_highbd_12_obmc_variance16x16, |
| 2337 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 2338 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 2339 | aom_highbd_12_obmc_variance8x16, |
| 2340 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 2341 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 2342 | aom_highbd_12_obmc_variance16x8, |
| 2343 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 2344 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 2345 | aom_highbd_12_obmc_variance8x8, |
| 2346 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 2347 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 2348 | aom_highbd_12_obmc_variance4x8, |
| 2349 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 2350 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 2351 | aom_highbd_12_obmc_variance8x4, |
| 2352 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 2353 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 2354 | aom_highbd_12_obmc_variance4x4, |
| 2355 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2356 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2357 | #if CONFIG_EXT_PARTITION |
| 2358 | HIGHBD_OBFP(BLOCK_128X32, aom_highbd_obmc_sad128x32_bits12, |
| 2359 | aom_highbd_12_obmc_variance128x32, |
| 2360 | aom_highbd_12_obmc_sub_pixel_variance128x32) |
| 2361 | |
| 2362 | HIGHBD_OBFP(BLOCK_32X128, aom_highbd_obmc_sad32x128_bits12, |
| 2363 | aom_highbd_12_obmc_variance32x128, |
| 2364 | aom_highbd_12_obmc_sub_pixel_variance32x128) |
| 2365 | #endif // CONFIG_EXT_PARTITION |
| 2366 | |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2367 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 2368 | aom_highbd_12_obmc_variance64x16, |
| 2369 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
| 2370 | |
| 2371 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 2372 | aom_highbd_12_obmc_variance16x64, |
| 2373 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
| 2374 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2375 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 2376 | aom_highbd_12_obmc_variance32x8, |
| 2377 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
| 2378 | |
| 2379 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 2380 | aom_highbd_12_obmc_variance8x32, |
| 2381 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
| 2382 | |
| 2383 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 2384 | aom_highbd_12_obmc_variance16x4, |
| 2385 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
| 2386 | |
| 2387 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 2388 | aom_highbd_12_obmc_variance4x16, |
| 2389 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
| 2390 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2391 | break; |
| 2392 | |
| 2393 | default: |
| 2394 | assert(0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2395 | "cm->bit_depth should be AOM_BITS_8, " |
| 2396 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2397 | } |
| 2398 | } |
| 2399 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2400 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2401 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2402 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 2403 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2404 | |
| 2405 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2406 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2407 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2408 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2409 | |
| 2410 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2411 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2412 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2413 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2414 | |
| 2415 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2416 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2417 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2418 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2419 | } |
| 2420 | |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2421 | void set_compound_tools(AV1_COMMON *cm) { |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2422 | cm->allow_interintra_compound = 1; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2423 | cm->allow_masked_compound = 1; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2424 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2425 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2426 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 2427 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2428 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2429 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2430 | |
| 2431 | if (cm->profile != oxcf->profile) cm->profile = oxcf->profile; |
| 2432 | cm->bit_depth = oxcf->bit_depth; |
| 2433 | cm->color_space = oxcf->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 2434 | #if CONFIG_COLORSPACE_HEADERS |
| 2435 | cm->transfer_function = oxcf->transfer_function; |
| 2436 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
| 2437 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2438 | cm->color_range = oxcf->color_range; |
| 2439 | |
| 2440 | if (cm->profile <= PROFILE_1) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2441 | assert(cm->bit_depth == AOM_BITS_8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2442 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2443 | assert(cm->bit_depth > AOM_BITS_8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2444 | |
| 2445 | cpi->oxcf = *oxcf; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2446 | x->e_mbd.bd = (int)cm->bit_depth; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2447 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2448 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2449 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2450 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 2451 | } else { |
| 2452 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 2453 | } |
| 2454 | |
| 2455 | cpi->refresh_last_frame = 1; |
| 2456 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2457 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 2458 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2459 | |
| 2460 | cm->refresh_frame_context = |
| 2461 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 2462 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 2463 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 2464 | #if CONFIG_EXT_TILE |
| 2465 | if (oxcf->large_scale_tile) |
| 2466 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 2467 | #endif // CONFIG_EXT_TILE |
| 2468 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 2469 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2470 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 2471 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2472 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 2473 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2474 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 2475 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 2476 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2477 | set_compound_tools(cm); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2478 | av1_reset_segment_features(cm); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2479 | #if CONFIG_AMVR |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2480 | set_high_precision_mv(cpi, 1, 0); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2481 | #else |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2482 | set_high_precision_mv(cpi, 1); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2483 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2484 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2485 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 2486 | |
| 2487 | // Under a configuration change, where maximum_buffer_size may change, |
| 2488 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2489 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2490 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2491 | |
| 2492 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2493 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2494 | |
| 2495 | // Set absolute upper and lower quality limits |
| 2496 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2497 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2498 | |
| 2499 | cm->interp_filter = cpi->sf.default_interp_filter; |
| 2500 | |
| 2501 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2502 | cm->render_width = cpi->oxcf.render_width; |
| 2503 | cm->render_height = cpi->oxcf.render_height; |
| 2504 | } else { |
| 2505 | cm->render_width = cpi->oxcf.width; |
| 2506 | cm->render_height = cpi->oxcf.height; |
| 2507 | } |
| 2508 | cm->width = cpi->oxcf.width; |
| 2509 | cm->height = cpi->oxcf.height; |
| 2510 | |
| 2511 | if (cpi->initial_width) { |
| 2512 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2513 | av1_free_context_buffers(cm); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 2514 | av1_free_pc_tree(&cpi->td); |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2515 | alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2516 | realloc_segmentation_maps(cpi); |
| 2517 | cpi->initial_width = cpi->initial_height = 0; |
| 2518 | } |
| 2519 | } |
| 2520 | update_frame_size(cpi); |
| 2521 | |
| 2522 | cpi->alt_ref_source = NULL; |
| 2523 | rc->is_src_frame_alt_ref = 0; |
| 2524 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2525 | rc->is_bwd_ref_frame = 0; |
| 2526 | rc->is_last_bipred_frame = 0; |
| 2527 | rc->is_bipred_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2528 | |
| 2529 | #if 0 |
| 2530 | // Experimental RD Code |
| 2531 | cpi->frame_distortion = 0; |
| 2532 | cpi->last_frame_distortion = 0; |
| 2533 | #endif |
| 2534 | |
| 2535 | set_tile_info(cpi); |
| 2536 | |
| 2537 | cpi->ext_refresh_frame_flags_pending = 0; |
| 2538 | cpi->ext_refresh_frame_context_pending = 0; |
| 2539 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2540 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2541 | highbd_set_var_fns(cpi); |
| 2542 | #endif |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2543 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 2544 | cpi->common.ans_window_size_log2 = cpi->oxcf.ans_window_size_log2; |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2545 | #endif // CONFIG_ANS && ANS_MAX_SYMBOLS |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2546 | #if CONFIG_AMVR |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 2547 | cm->seq_force_integer_mv = 2; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2548 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2549 | } |
| 2550 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2551 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 2552 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2553 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2554 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2555 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2556 | |
| 2557 | if (!cm) return NULL; |
| 2558 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2559 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2560 | |
| 2561 | if (setjmp(cm->error.jmp)) { |
| 2562 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2563 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2564 | return 0; |
| 2565 | } |
| 2566 | |
| 2567 | cm->error.setjmp = 1; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 2568 | cm->alloc_mi = enc_alloc_mi; |
| 2569 | cm->free_mi = enc_free_mi; |
| 2570 | cm->setup_mi = enc_setup_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2571 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2572 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2573 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
| 2574 | CHECK_MEM_ERROR(cm, cm->frame_contexts, |
| 2575 | (FRAME_CONTEXT *)aom_memalign( |
| 2576 | 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts))); |
| 2577 | memset(cm->fc, 0, sizeof(*cm->fc)); |
| 2578 | memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2579 | |
| 2580 | cpi->resize_state = 0; |
| 2581 | cpi->resize_avg_qp = 0; |
| 2582 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2583 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2584 | cpi->common.buffer_pool = pool; |
| 2585 | |
| 2586 | init_config(cpi, oxcf); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2587 | #if CONFIG_XIPHRC |
| 2588 | cpi->od_rc.framerate = cpi->framerate; |
| 2589 | cpi->od_rc.frame_width = cm->render_width; |
| 2590 | cpi->od_rc.frame_height = cm->render_height; |
| 2591 | cpi->od_rc.keyframe_rate = oxcf->key_freq; |
| 2592 | cpi->od_rc.goldenframe_rate = FIXED_GF_INTERVAL; |
| 2593 | cpi->od_rc.altref_rate = 25; |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2594 | cpi->od_rc.firstpass_quant = 1; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2595 | cpi->od_rc.bit_depth = cm->bit_depth; |
| 2596 | cpi->od_rc.minq = oxcf->best_allowed_q; |
| 2597 | cpi->od_rc.maxq = oxcf->worst_allowed_q; |
| 2598 | if (cpi->oxcf.rc_mode == AOM_CQ) cpi->od_rc.minq = cpi->od_rc.quality; |
| 2599 | cpi->od_rc.quality = cpi->oxcf.rc_mode == AOM_Q ? oxcf->cq_level : -1; |
| 2600 | cpi->od_rc.periodic_boosts = oxcf->frame_periodic_boost; |
| 2601 | od_enc_rc_init(&cpi->od_rc, |
| 2602 | cpi->oxcf.rc_mode == AOM_Q ? -1 : oxcf->target_bandwidth, |
| 2603 | oxcf->maximum_buffer_size_ms); |
| 2604 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2605 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2606 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2607 | |
| 2608 | cm->current_video_frame = 0; |
| 2609 | cpi->partition_search_skippable_frame = 0; |
| 2610 | cpi->tile_data = NULL; |
| 2611 | cpi->last_show_frame_buf_idx = INVALID_IDX; |
| 2612 | |
| 2613 | realloc_segmentation_maps(cpi); |
| 2614 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2615 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 2616 | memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs)); |
| 2617 | memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp)); |
| 2618 | } |
| 2619 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2620 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 2621 | i++) { |
| 2622 | CHECK_MEM_ERROR( |
| 2623 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2624 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | #if CONFIG_FP_MB_STATS |
| 2628 | cpi->use_fp_mb_stats = 0; |
| 2629 | if (cpi->use_fp_mb_stats) { |
| 2630 | // a place holder used to store the first pass mb stats in the first pass |
| 2631 | CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2632 | aom_calloc(cm->MBs * sizeof(uint8_t), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2633 | } else { |
| 2634 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2635 | } |
| 2636 | #endif |
| 2637 | |
| 2638 | cpi->refresh_alt_ref_frame = 0; |
| 2639 | cpi->multi_arf_last_grp_enabled = 0; |
| 2640 | |
| 2641 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 2642 | #if CONFIG_INTERNAL_STATS |
| 2643 | cpi->b_calculate_blockiness = 1; |
| 2644 | cpi->b_calculate_consistency = 1; |
| 2645 | cpi->total_inconsistency = 0; |
| 2646 | cpi->psnr.worst = 100.0; |
| 2647 | cpi->worst_ssim = 100.0; |
| 2648 | |
| 2649 | cpi->count = 0; |
| 2650 | cpi->bytes = 0; |
| 2651 | |
| 2652 | if (cpi->b_calculate_psnr) { |
| 2653 | cpi->total_sq_error = 0; |
| 2654 | cpi->total_samples = 0; |
| 2655 | cpi->tot_recode_hits = 0; |
| 2656 | cpi->summed_quality = 0; |
| 2657 | cpi->summed_weights = 0; |
| 2658 | } |
| 2659 | |
| 2660 | cpi->fastssim.worst = 100.0; |
| 2661 | cpi->psnrhvs.worst = 100.0; |
| 2662 | |
| 2663 | if (cpi->b_calculate_blockiness) { |
| 2664 | cpi->total_blockiness = 0; |
| 2665 | cpi->worst_blockiness = 0.0; |
| 2666 | } |
| 2667 | |
| 2668 | if (cpi->b_calculate_consistency) { |
| 2669 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2670 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2671 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 2672 | cpi->worst_consistency = 100.0; |
| 2673 | } |
| 2674 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2675 | #if CONFIG_ENTROPY_STATS |
| 2676 | av1_zero(aggregate_fc); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 2677 | av1_zero_array(aggregate_fc_per_type, FRAME_CONTEXTS); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2678 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2679 | |
| 2680 | cpi->first_time_stamp_ever = INT64_MAX; |
| 2681 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2682 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 2683 | cpi->td.mb.nmvcost[i][0] = &cpi->nmv_costs[i][0][MV_MAX]; |
| 2684 | cpi->td.mb.nmvcost[i][1] = &cpi->nmv_costs[i][1][MV_MAX]; |
| 2685 | cpi->td.mb.nmvcost_hp[i][0] = &cpi->nmv_costs_hp[i][0][MV_MAX]; |
| 2686 | cpi->td.mb.nmvcost_hp[i][1] = &cpi->nmv_costs_hp[i][1][MV_MAX]; |
| 2687 | } |
| 2688 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2689 | #ifdef OUTPUT_YUV_SKINMAP |
| 2690 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 2691 | #endif |
| 2692 | #ifdef OUTPUT_YUV_REC |
| 2693 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 2694 | #endif |
| 2695 | |
| 2696 | #if 0 |
| 2697 | framepsnr = fopen("framepsnr.stt", "a"); |
| 2698 | kf_list = fopen("kf_list.stt", "w"); |
| 2699 | #endif |
| 2700 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2701 | #if CONFIG_XIPHRC |
| 2702 | if (oxcf->pass == 2) { |
| 2703 | cpi->od_rc.twopass_allframes_buf = oxcf->two_pass_stats_in.buf; |
| 2704 | cpi->od_rc.twopass_allframes_buf_size = oxcf->two_pass_stats_in.sz; |
| 2705 | } |
| 2706 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2707 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2708 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2709 | } else if (oxcf->pass == 2) { |
| 2710 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 2711 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 2712 | |
| 2713 | #if CONFIG_FP_MB_STATS |
| 2714 | if (cpi->use_fp_mb_stats) { |
| 2715 | const size_t psz = cpi->common.MBs * sizeof(uint8_t); |
| 2716 | const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz); |
| 2717 | |
| 2718 | cpi->twopass.firstpass_mb_stats.mb_stats_start = |
| 2719 | oxcf->firstpass_mb_stats_in.buf; |
| 2720 | cpi->twopass.firstpass_mb_stats.mb_stats_end = |
| 2721 | cpi->twopass.firstpass_mb_stats.mb_stats_start + |
| 2722 | (ps - 1) * cpi->common.MBs * sizeof(uint8_t); |
| 2723 | } |
| 2724 | #endif |
| 2725 | |
| 2726 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 2727 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 2728 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 2729 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2730 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2731 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2732 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2733 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2734 | #if CONFIG_HIGHBITDEPTH |
| 2735 | int buf_scaler = 2; |
| 2736 | #else |
| 2737 | int buf_scaler = 1; |
| 2738 | #endif |
| 2739 | CHECK_MEM_ERROR( |
| 2740 | cm, cpi->td.mb.above_pred_buf, |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 2741 | (uint8_t *)aom_memalign(16, |
| 2742 | buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2743 | sizeof(*cpi->td.mb.above_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2744 | CHECK_MEM_ERROR( |
| 2745 | cm, cpi->td.mb.left_pred_buf, |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 2746 | (uint8_t *)aom_memalign(16, |
| 2747 | buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2748 | sizeof(*cpi->td.mb.left_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2749 | |
| 2750 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 2751 | (int32_t *)aom_memalign( |
| 2752 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 2753 | |
| 2754 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 2755 | (int32_t *)aom_memalign( |
| 2756 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 2757 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2758 | av1_set_speed_features_framesize_independent(cpi); |
| 2759 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2760 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2761 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 2762 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 2763 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 2764 | cpi->fn_ptr[BT].vf = VF; \ |
| 2765 | cpi->fn_ptr[BT].svf = SVF; \ |
| 2766 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 2767 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 2768 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 2769 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
| 2770 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2771 | #if CONFIG_EXT_PARTITION_TYPES |
| 2772 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
| 2773 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2774 | aom_sad4x16x4d) |
| 2775 | |
| 2776 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
| 2777 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2778 | aom_sad16x4x4d) |
| 2779 | |
| 2780 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
| 2781 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2782 | aom_sad8x32x4d) |
| 2783 | |
| 2784 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
| 2785 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2786 | aom_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2787 | |
| 2788 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
| 2789 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2790 | aom_sad16x64x4d) |
| 2791 | |
| 2792 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
| 2793 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2794 | aom_sad64x16x4d) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2795 | |
| 2796 | #if CONFIG_EXT_PARTITION |
| 2797 | BFP(BLOCK_32X128, aom_sad32x128, aom_sad32x128_avg, aom_variance32x128, |
| 2798 | aom_sub_pixel_variance32x128, aom_sub_pixel_avg_variance32x128, NULL, |
| 2799 | NULL, aom_sad32x128x4d) |
| 2800 | |
| 2801 | BFP(BLOCK_128X32, aom_sad128x32, aom_sad128x32_avg, aom_variance128x32, |
| 2802 | aom_sub_pixel_variance128x32, aom_sub_pixel_avg_variance128x32, NULL, |
| 2803 | NULL, aom_sad128x32x4d) |
| 2804 | #endif // CONFIG_EXT_PARTITION |
| 2805 | #endif // CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2806 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2807 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2808 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 2809 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
| 2810 | aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2811 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2812 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
| 2813 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL, |
| 2814 | NULL, aom_sad128x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2815 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2816 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
| 2817 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL, |
| 2818 | NULL, aom_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2819 | #endif // CONFIG_EXT_PARTITION |
| 2820 | |
Cheng Chen | efc55fd | 2017-10-10 12:08:28 -0700 | [diff] [blame] | 2821 | #if CONFIG_JNT_COMP |
| 2822 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg_c, aom_variance32x16, |
| 2823 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2824 | aom_sad32x16x4d) |
| 2825 | |
| 2826 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg_c, aom_variance16x32, |
| 2827 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2828 | aom_sad16x32x4d) |
| 2829 | |
| 2830 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg_c, aom_variance64x32, |
| 2831 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2832 | aom_sad64x32x4d) |
| 2833 | |
| 2834 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg_c, aom_variance32x64, |
| 2835 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2836 | aom_sad32x64x4d) |
| 2837 | |
| 2838 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg_c, aom_variance32x32, |
| 2839 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
| 2840 | aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d) |
| 2841 | |
| 2842 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg_c, aom_variance64x64, |
| 2843 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
| 2844 | aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d) |
| 2845 | |
| 2846 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg_c, aom_variance16x16, |
| 2847 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
| 2848 | aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d) |
| 2849 | |
| 2850 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg_c, aom_variance16x8, |
| 2851 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3, |
| 2852 | aom_sad16x8x8, aom_sad16x8x4d) |
| 2853 | |
| 2854 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg_c, aom_variance8x16, |
| 2855 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3, |
| 2856 | aom_sad8x16x8, aom_sad8x16x4d) |
| 2857 | |
| 2858 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg_c, aom_variance8x8, |
| 2859 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3, |
| 2860 | aom_sad8x8x8, aom_sad8x8x4d) |
| 2861 | |
| 2862 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg_c, aom_variance8x4, |
| 2863 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL, |
| 2864 | aom_sad8x4x8, aom_sad8x4x4d) |
| 2865 | |
| 2866 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg_c, aom_variance4x8, |
| 2867 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL, |
| 2868 | aom_sad4x8x8, aom_sad4x8x4d) |
| 2869 | |
| 2870 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg_c, aom_variance4x4, |
| 2871 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3, |
| 2872 | aom_sad4x4x8, aom_sad4x4x4d) |
| 2873 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2874 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
| 2875 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2876 | aom_sad32x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2877 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2878 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
| 2879 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2880 | aom_sad16x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2881 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2882 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
| 2883 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2884 | aom_sad64x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2885 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2886 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
| 2887 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2888 | aom_sad32x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2889 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2890 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 2891 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
| 2892 | aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d) |
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_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 2895 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
| 2896 | aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d) |
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_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 2899 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
| 2900 | aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2901 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2902 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
| 2903 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3, |
| 2904 | aom_sad16x8x8, aom_sad16x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2905 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2906 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
| 2907 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3, |
| 2908 | aom_sad8x16x8, aom_sad8x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2909 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2910 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
| 2911 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3, |
| 2912 | aom_sad8x8x8, aom_sad8x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2913 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2914 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
| 2915 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL, |
| 2916 | aom_sad8x4x8, aom_sad8x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2917 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2918 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
| 2919 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL, |
| 2920 | aom_sad4x8x8, aom_sad4x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2921 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2922 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
| 2923 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3, |
| 2924 | aom_sad4x4x8, aom_sad4x4x4d) |
Cheng Chen | efc55fd | 2017-10-10 12:08:28 -0700 | [diff] [blame] | 2925 | #endif // CONFIG_JNT_COMP |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2926 | |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 2927 | BFP(BLOCK_2X2, NULL, NULL, aom_variance2x2, NULL, NULL, NULL, NULL, NULL) |
Jingning Han | e2ffaf8 | 2016-12-14 15:26:30 -0800 | [diff] [blame] | 2928 | BFP(BLOCK_2X4, NULL, NULL, aom_variance2x4, NULL, NULL, NULL, NULL, NULL) |
| 2929 | BFP(BLOCK_4X2, NULL, NULL, aom_variance4x2, NULL, NULL, NULL, NULL, NULL) |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 2930 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2931 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 2932 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 2933 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 2934 | cpi->fn_ptr[BT].osvf = OSVF; |
| 2935 | |
| 2936 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2937 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 2938 | aom_obmc_sub_pixel_variance128x128) |
| 2939 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 2940 | aom_obmc_sub_pixel_variance128x64) |
| 2941 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 2942 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2943 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2944 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 2945 | aom_obmc_sub_pixel_variance64x64) |
| 2946 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 2947 | aom_obmc_sub_pixel_variance64x32) |
| 2948 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 2949 | aom_obmc_sub_pixel_variance32x64) |
| 2950 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 2951 | aom_obmc_sub_pixel_variance32x32) |
| 2952 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 2953 | aom_obmc_sub_pixel_variance32x16) |
| 2954 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 2955 | aom_obmc_sub_pixel_variance16x32) |
| 2956 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 2957 | aom_obmc_sub_pixel_variance16x16) |
| 2958 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 2959 | aom_obmc_sub_pixel_variance16x8) |
| 2960 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 2961 | aom_obmc_sub_pixel_variance8x16) |
| 2962 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 2963 | aom_obmc_sub_pixel_variance8x8) |
| 2964 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 2965 | aom_obmc_sub_pixel_variance4x8) |
| 2966 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 2967 | aom_obmc_sub_pixel_variance8x4) |
| 2968 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 2969 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2970 | |
| 2971 | #if CONFIG_EXT_PARTITION_TYPES |
| 2972 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 2973 | aom_obmc_sub_pixel_variance4x16) |
| 2974 | |
| 2975 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 2976 | aom_obmc_sub_pixel_variance16x4) |
| 2977 | |
| 2978 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 2979 | aom_obmc_sub_pixel_variance8x32) |
| 2980 | |
| 2981 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 2982 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2983 | |
| 2984 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 2985 | aom_obmc_sub_pixel_variance16x64) |
| 2986 | |
| 2987 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 2988 | aom_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 2989 | |
| 2990 | #if CONFIG_EXT_PARTITION |
| 2991 | OBFP(BLOCK_32X128, aom_obmc_sad32x128, aom_obmc_variance32x128, |
| 2992 | aom_obmc_sub_pixel_variance32x128) |
| 2993 | |
| 2994 | OBFP(BLOCK_128X32, aom_obmc_sad128x32, aom_obmc_variance128x32, |
| 2995 | aom_obmc_sub_pixel_variance128x32) |
| 2996 | #endif // CONFIG_EXT_PARTITION |
| 2997 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2998 | |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2999 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 3000 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 3001 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3002 | |
| 3003 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3004 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 3005 | aom_masked_sub_pixel_variance128x128) |
| 3006 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 3007 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3008 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 3009 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 3010 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 3011 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 3012 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 3013 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 3014 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 3015 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 3016 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 3017 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 3018 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 3019 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 3020 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 3021 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3022 | |
| 3023 | #if CONFIG_EXT_PARTITION_TYPES |
| 3024 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 3025 | |
| 3026 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 3027 | |
| 3028 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 3029 | |
| 3030 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 3031 | |
| 3032 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 3033 | |
| 3034 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 3035 | |
| 3036 | #if CONFIG_EXT_PARTITION |
| 3037 | MBFP(BLOCK_32X128, aom_masked_sad32x128, aom_masked_sub_pixel_variance32x128) |
| 3038 | |
| 3039 | MBFP(BLOCK_128X32, aom_masked_sad128x32, aom_masked_sub_pixel_variance128x32) |
| 3040 | #endif // CONFIG_EXT_PARTITION |
| 3041 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3042 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3043 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3044 | highbd_set_var_fns(cpi); |
| 3045 | #endif |
| 3046 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3047 | /* av1_init_quantizer() is first called here. Add check in |
| 3048 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3049 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3050 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3051 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3052 | av1_init_quantizer(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3053 | #if CONFIG_AOM_QM |
| 3054 | aom_qm_init(cm); |
| 3055 | #endif |
| 3056 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3057 | av1_loop_filter_init(cm); |
Fergus Simpson | dac6aff | 2017-05-18 15:11:38 -0700 | [diff] [blame] | 3058 | #if CONFIG_FRAME_SUPERRES |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 3059 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 3060 | cm->superres_upscaled_width = oxcf->width; |
| 3061 | cm->superres_upscaled_height = oxcf->height; |
Fergus Simpson | dac6aff | 2017-05-18 15:11:38 -0700 | [diff] [blame] | 3062 | #endif // CONFIG_FRAME_SUPERRES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3063 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3064 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3065 | #endif // CONFIG_LOOP_RESTORATION |
| 3066 | |
| 3067 | cm->error.setjmp = 0; |
| 3068 | |
| 3069 | return cpi; |
| 3070 | } |
| 3071 | |
| 3072 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 3073 | |
| 3074 | #define SNPRINT2(H, T, V) \ |
| 3075 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
| 3076 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3077 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 3078 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3079 | unsigned int i; |
| 3080 | int t; |
| 3081 | |
| 3082 | if (!cpi) return; |
| 3083 | |
| 3084 | cm = &cpi->common; |
| 3085 | if (cm->current_video_frame > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3086 | #if CONFIG_ENTROPY_STATS |
| 3087 | if (cpi->oxcf.pass != 1) { |
| 3088 | fprintf(stderr, "Writing counts.stt\n"); |
| 3089 | FILE *f = fopen("counts.stt", "wb"); |
| 3090 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 3091 | fwrite(aggregate_fc_per_type, sizeof(aggregate_fc_per_type[0]), |
| 3092 | FRAME_CONTEXTS, f); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 3093 | fclose(f); |
| 3094 | } |
| 3095 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3096 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3097 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3098 | |
| 3099 | if (cpi->oxcf.pass != 1) { |
| 3100 | char headings[512] = { 0 }; |
| 3101 | char results[512] = { 0 }; |
| 3102 | FILE *f = fopen("opsnr.stt", "a"); |
| 3103 | double time_encoded = |
| 3104 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 3105 | 10000000.000; |
| 3106 | double total_encode_time = |
| 3107 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 3108 | const double dr = |
| 3109 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 3110 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 3111 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 3112 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 3113 | |
| 3114 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3115 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3116 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 3117 | const double total_ssim = |
| 3118 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 3119 | snprintf(headings, sizeof(headings), |
| 3120 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3121 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3122 | "WstPsnr\tWstSsim\tWstFast\tWstHVS"); |
| 3123 | snprintf(results, sizeof(results), |
| 3124 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 3125 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 3126 | "%7.3f\t%7.3f\t%7.3f\t%7.3f", |
| 3127 | dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr, |
| 3128 | cpi->psnr.stat[ALL] / cpi->count, total_psnr, total_ssim, |
| 3129 | total_ssim, cpi->fastssim.stat[ALL] / cpi->count, |
| 3130 | cpi->psnrhvs.stat[ALL] / cpi->count, cpi->psnr.worst, |
| 3131 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst); |
| 3132 | |
| 3133 | if (cpi->b_calculate_blockiness) { |
| 3134 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 3135 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 3136 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 3137 | } |
| 3138 | |
| 3139 | if (cpi->b_calculate_consistency) { |
| 3140 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3141 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3142 | (double)cpi->total_inconsistency); |
| 3143 | |
| 3144 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 3145 | SNPRINT2(results, "\t%7.3f", consistency); |
| 3146 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 3147 | } |
Sarah Parker | f97b786 | 2016-08-25 17:42:57 -0700 | [diff] [blame] | 3148 | fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings); |
| 3149 | 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] | 3150 | rate_err, fabs(rate_err)); |
| 3151 | } |
| 3152 | |
| 3153 | fclose(f); |
| 3154 | } |
| 3155 | |
| 3156 | #endif |
| 3157 | |
| 3158 | #if 0 |
| 3159 | { |
| 3160 | printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); |
| 3161 | printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); |
| 3162 | printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, |
| 3163 | cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, |
| 3164 | cpi->time_compress_data / 1000, |
| 3165 | (cpi->time_receive_data + cpi->time_compress_data) / 1000); |
| 3166 | } |
| 3167 | #endif |
| 3168 | } |
| 3169 | |
| 3170 | for (t = 0; t < cpi->num_workers; ++t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3171 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3172 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 3173 | |
| 3174 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3175 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3176 | |
| 3177 | // Deallocate allocated thread data. |
| 3178 | if (t < cpi->num_workers - 1) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 3179 | aom_free(thread_data->td->palette_buffer); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 3180 | aom_free(thread_data->td->above_pred_buf); |
| 3181 | aom_free(thread_data->td->left_pred_buf); |
| 3182 | aom_free(thread_data->td->wsrc_buf); |
| 3183 | aom_free(thread_data->td->mask_buf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3184 | aom_free(thread_data->td->counts); |
| 3185 | av1_free_pc_tree(thread_data->td); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3186 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3187 | } |
| 3188 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3189 | aom_free(cpi->tile_thr_data); |
| 3190 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3191 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3192 | 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] | 3193 | |
| 3194 | dealloc_compressor_data(cpi); |
| 3195 | |
| 3196 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 3197 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3198 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | #if CONFIG_FP_MB_STATS |
| 3202 | if (cpi->use_fp_mb_stats) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3203 | aom_free(cpi->twopass.frame_mb_stats_buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3204 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 3205 | } |
| 3206 | #endif |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 3207 | #if CONFIG_INTERNAL_STATS |
| 3208 | aom_free(cpi->ssim_vars); |
| 3209 | cpi->ssim_vars = NULL; |
| 3210 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3211 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3212 | av1_remove_common(cm); |
| 3213 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 3214 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3215 | |
| 3216 | #ifdef OUTPUT_YUV_SKINMAP |
| 3217 | fclose(yuv_skinmap_file); |
| 3218 | #endif |
| 3219 | #ifdef OUTPUT_YUV_REC |
| 3220 | fclose(yuv_rec_file); |
| 3221 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3222 | #if 0 |
| 3223 | |
| 3224 | if (keyfile) |
| 3225 | fclose(keyfile); |
| 3226 | |
| 3227 | if (framepsnr) |
| 3228 | fclose(framepsnr); |
| 3229 | |
| 3230 | if (kf_list) |
| 3231 | fclose(kf_list); |
| 3232 | |
| 3233 | #endif |
| 3234 | } |
| 3235 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3236 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 3237 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3238 | int i; |
| 3239 | PSNR_STATS psnr; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3240 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3241 | aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3242 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
| 3243 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3244 | aom_calc_psnr(cpi->source, cpi->common.frame_to_show, &psnr); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3245 | #endif |
| 3246 | |
| 3247 | for (i = 0; i < 4; ++i) { |
| 3248 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 3249 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 3250 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 3251 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3252 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 3253 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3254 | } |
| 3255 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3256 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3257 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 3258 | |
| 3259 | cpi->ref_frame_flags = ref_frame_flags; |
| 3260 | return 0; |
| 3261 | } |
| 3262 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3263 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags) { |
| 3264 | cpi->ext_refresh_golden_frame = (ref_frame_flags & AOM_GOLD_FLAG) != 0; |
| 3265 | cpi->ext_refresh_alt_ref_frame = (ref_frame_flags & AOM_ALT_FLAG) != 0; |
| 3266 | cpi->ext_refresh_last_frame = (ref_frame_flags & AOM_LAST_FLAG) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3267 | cpi->ext_refresh_frame_flags_pending = 1; |
| 3268 | } |
| 3269 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3270 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3271 | AV1_COMMON *const cm = &cpi->common; |
| 3272 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3273 | if (cfg) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3274 | aom_yv12_copy_frame(cfg, sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3275 | return 0; |
| 3276 | } else { |
| 3277 | return -1; |
| 3278 | } |
| 3279 | } |
| 3280 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3281 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3282 | AV1_COMMON *const cm = &cpi->common; |
| 3283 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3284 | if (cfg) { |
| 3285 | aom_yv12_copy_frame(sd, cfg); |
| 3286 | return 0; |
| 3287 | } else { |
| 3288 | return -1; |
| 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3293 | cpi->ext_refresh_frame_context = update; |
| 3294 | cpi->ext_refresh_frame_context_pending = 1; |
| 3295 | return 0; |
| 3296 | } |
| 3297 | |
| 3298 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 3299 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 3300 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 3301 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 3302 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3303 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3304 | uint8_t *src = s->y_buffer; |
| 3305 | int h = s->y_height; |
| 3306 | |
| 3307 | do { |
| 3308 | fwrite(src, s->y_width, 1, f); |
| 3309 | src += s->y_stride; |
| 3310 | } while (--h); |
| 3311 | |
| 3312 | src = s->u_buffer; |
| 3313 | h = s->uv_height; |
| 3314 | |
| 3315 | do { |
| 3316 | fwrite(src, s->uv_width, 1, f); |
| 3317 | src += s->uv_stride; |
| 3318 | } while (--h); |
| 3319 | |
| 3320 | src = s->v_buffer; |
| 3321 | h = s->uv_height; |
| 3322 | |
| 3323 | do { |
| 3324 | fwrite(src, s->uv_width, 1, f); |
| 3325 | src += s->uv_stride; |
| 3326 | } while (--h); |
| 3327 | } |
| 3328 | #endif |
| 3329 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3330 | #if !CONFIG_XIPHRC |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3331 | #if USE_GF16_MULTI_LAYER |
| 3332 | static void check_show_existing_frame_gf16(AV1_COMP *cpi) { |
| 3333 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3334 | AV1_COMMON *const cm = &cpi->common; |
| 3335 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 3336 | gf_group->update_type[gf_group->index]; |
| 3337 | |
| 3338 | if (cm->show_existing_frame == 1) { |
| 3339 | cm->show_existing_frame = 0; |
| 3340 | } else if (cpi->rc.is_last_bipred_frame) { |
| 3341 | cpi->rc.is_last_bipred_frame = 0; |
| 3342 | cm->show_existing_frame = 1; |
| 3343 | cpi->existing_fb_idx_to_show = cpi->bwd_fb_idx; |
| 3344 | } else if (next_frame_update_type == OVERLAY_UPDATE || |
| 3345 | next_frame_update_type == INTNL_OVERLAY_UPDATE) { |
| 3346 | // Check the temporal filtering status for the next OVERLAY frame |
| 3347 | const int num_arfs_in_gf = cpi->num_extra_arfs + 1; |
| 3348 | int which_arf = 0, arf_idx; |
| 3349 | // Identify the index to the next overlay frame. |
| 3350 | for (arf_idx = 0; arf_idx < num_arfs_in_gf; arf_idx++) { |
| 3351 | if (gf_group->index == cpi->arf_pos_for_ovrly[arf_idx]) { |
| 3352 | which_arf = arf_idx; |
| 3353 | break; |
| 3354 | } |
| 3355 | } |
| 3356 | assert(arf_idx < num_arfs_in_gf); |
| 3357 | if (cpi->is_arf_filter_off[which_arf]) { |
| 3358 | cm->show_existing_frame = 1; |
| 3359 | cpi->rc.is_src_frame_alt_ref = 1; |
| 3360 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
| 3361 | ? cpi->alt_fb_idx |
| 3362 | : cpi->bwd_fb_idx; |
| 3363 | cpi->is_arf_filter_off[which_arf] = 0; |
| 3364 | } |
| 3365 | } |
| 3366 | cpi->rc.is_src_frame_ext_arf = 0; |
| 3367 | } |
| 3368 | #endif // USE_GF16_MULTI_LAYER |
| 3369 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3370 | static void check_show_existing_frame(AV1_COMP *cpi) { |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3371 | #if USE_GF16_MULTI_LAYER |
| 3372 | if (cpi->rc.baseline_gf_interval == 16) { |
| 3373 | check_show_existing_frame_gf16(cpi); |
| 3374 | return; |
| 3375 | } |
| 3376 | #endif // USE_GF16_MULTI_LAYER |
| 3377 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3378 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3379 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3380 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 3381 | gf_group->update_type[gf_group->index]; |
| 3382 | const int which_arf = gf_group->arf_update_idx[gf_group->index]; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3383 | |
| 3384 | if (cm->show_existing_frame == 1) { |
| 3385 | cm->show_existing_frame = 0; |
| 3386 | } else if (cpi->rc.is_last_bipred_frame) { |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3387 | // NOTE: If the current frame is a last bi-predictive frame, it is |
| 3388 | // needed next to show the BWDREF_FRAME, which is pointed by |
| 3389 | // the last_fb_idxes[0] after reference frame buffer update |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3390 | cpi->rc.is_last_bipred_frame = 0; |
| 3391 | cm->show_existing_frame = 1; |
| 3392 | cpi->existing_fb_idx_to_show = cpi->lst_fb_idxes[0]; |
| 3393 | } else if (cpi->is_arf_filter_off[which_arf] && |
| 3394 | (next_frame_update_type == OVERLAY_UPDATE || |
| 3395 | next_frame_update_type == INTNL_OVERLAY_UPDATE)) { |
| 3396 | // Other parameters related to OVERLAY_UPDATE will be taken care of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3397 | // in av1_rc_get_second_pass_params(cpi) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3398 | cm->show_existing_frame = 1; |
| 3399 | cpi->rc.is_src_frame_alt_ref = 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3400 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
| 3401 | ? cpi->alt_fb_idx |
| 3402 | : cpi->alt2_fb_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3403 | cpi->is_arf_filter_off[which_arf] = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3404 | } |
| 3405 | cpi->rc.is_src_frame_ext_arf = 0; |
| 3406 | } |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3407 | #endif // !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3408 | |
| 3409 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3410 | 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] | 3411 | uint8_t *src = s->y_buffer; |
| 3412 | int h = cm->height; |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 3413 | if (yuv_rec_file == NULL) return; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3414 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3415 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 3416 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 3417 | |
| 3418 | do { |
| 3419 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 3420 | src16 += s->y_stride; |
| 3421 | } while (--h); |
| 3422 | |
| 3423 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 3424 | h = s->uv_height; |
| 3425 | |
| 3426 | do { |
| 3427 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3428 | src16 += s->uv_stride; |
| 3429 | } while (--h); |
| 3430 | |
| 3431 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 3432 | h = s->uv_height; |
| 3433 | |
| 3434 | do { |
| 3435 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3436 | src16 += s->uv_stride; |
| 3437 | } while (--h); |
| 3438 | |
| 3439 | fflush(yuv_rec_file); |
| 3440 | return; |
| 3441 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3442 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3443 | |
| 3444 | do { |
| 3445 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 3446 | src += s->y_stride; |
| 3447 | } while (--h); |
| 3448 | |
| 3449 | src = s->u_buffer; |
| 3450 | h = s->uv_height; |
| 3451 | |
| 3452 | do { |
| 3453 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3454 | src += s->uv_stride; |
| 3455 | } while (--h); |
| 3456 | |
| 3457 | src = s->v_buffer; |
| 3458 | h = s->uv_height; |
| 3459 | |
| 3460 | do { |
| 3461 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3462 | src += s->uv_stride; |
| 3463 | } while (--h); |
| 3464 | |
| 3465 | fflush(yuv_rec_file); |
| 3466 | } |
| 3467 | #endif // OUTPUT_YUV_REC |
| 3468 | |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 3469 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3470 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 3471 | int i; |
| 3472 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3473 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3474 | AV1_COMMON *const cm = &cpi->common; |
| 3475 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3476 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3477 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3478 | cpi->gmparams_cost[i]) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3479 | cm->global_motion[i] = default_warp_params; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 3480 | assert(cm->global_motion[i].wmtype == IDENTITY); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3481 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 3482 | recode = 1; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3483 | recode |= (rdc->global_motion_used[i] > 0); |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3484 | } |
| 3485 | } |
| 3486 | return recode; |
| 3487 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3488 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3489 | // Function to test for conditions that indicate we should loop |
| 3490 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3491 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 3492 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3493 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3494 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3495 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 3496 | int force_recode = 0; |
| 3497 | |
| 3498 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 3499 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 3500 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3501 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 3502 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 3503 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 3504 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3505 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3506 | // Deal with frame undershoot and whether or not we are |
| 3507 | // below the automatically set cq level. |
| 3508 | if (q > oxcf->cq_level && |
| 3509 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 3510 | force_recode = 1; |
| 3511 | } |
| 3512 | } |
| 3513 | } |
| 3514 | return force_recode; |
| 3515 | } |
| 3516 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3517 | #define DUMP_REF_FRAME_IMAGES 0 |
| 3518 | |
| 3519 | #if DUMP_REF_FRAME_IMAGES == 1 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3520 | static int dump_one_image(AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3521 | const YV12_BUFFER_CONFIG *const ref_buf, |
| 3522 | char *file_name) { |
| 3523 | int h; |
| 3524 | FILE *f_ref = NULL; |
| 3525 | |
| 3526 | if (ref_buf == NULL) { |
| 3527 | printf("Frame data buffer is NULL.\n"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3528 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | if ((f_ref = fopen(file_name, "wb")) == NULL) { |
| 3532 | printf("Unable to open file %s to write.\n", file_name); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3533 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3534 | } |
| 3535 | |
| 3536 | // --- Y --- |
| 3537 | for (h = 0; h < cm->height; ++h) { |
| 3538 | fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref); |
| 3539 | } |
| 3540 | // --- U --- |
| 3541 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3542 | fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3543 | f_ref); |
| 3544 | } |
| 3545 | // --- V --- |
| 3546 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3547 | fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3548 | f_ref); |
| 3549 | } |
| 3550 | |
| 3551 | fclose(f_ref); |
| 3552 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3553 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3556 | static void dump_ref_frame_images(AV1_COMP *cpi) { |
| 3557 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3558 | MV_REFERENCE_FRAME ref_frame; |
| 3559 | |
| 3560 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3561 | char file_name[256] = ""; |
| 3562 | snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv", |
| 3563 | cm->current_video_frame, ref_frame); |
| 3564 | dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name); |
| 3565 | } |
| 3566 | } |
| 3567 | #endif // DUMP_REF_FRAME_IMAGES == 1 |
| 3568 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3569 | // This function is used to shift the virtual indices of last reference frames |
| 3570 | // as follows: |
| 3571 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3572 | // when the LAST_FRAME is updated. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3573 | static INLINE void shift_last_ref_frames(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3574 | int ref_frame; |
| 3575 | for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) { |
| 3576 | cpi->lst_fb_idxes[ref_frame] = cpi->lst_fb_idxes[ref_frame - 1]; |
| 3577 | |
| 3578 | // [0] is allocated to the current coded frame. The statistics for the |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3579 | // reference frames start at [LAST_FRAME], i.e. [1]. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3580 | if (!cpi->rc.is_src_frame_alt_ref) { |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3581 | memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME], |
| 3582 | cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME], |
| 3583 | sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3584 | } |
| 3585 | } |
| 3586 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3587 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3588 | #if USE_GF16_MULTI_LAYER |
| 3589 | static void update_reference_frames_gf16(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3590 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3591 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3592 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3593 | if (cm->frame_type == KEY_FRAME) { |
| 3594 | for (int ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) { |
| 3595 | ref_cnt_fb(pool->frame_bufs, |
| 3596 | &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]], |
| 3597 | cm->new_fb_idx); |
| 3598 | } |
| 3599 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3600 | cm->new_fb_idx); |
| 3601 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3602 | cm->new_fb_idx); |
| 3603 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3604 | cm->new_fb_idx); |
| 3605 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3606 | cm->new_fb_idx); |
| 3607 | } else { |
| 3608 | if (cpi->refresh_last_frame || cpi->refresh_golden_frame || |
| 3609 | cpi->refresh_bwd_ref_frame || cpi->refresh_alt2_ref_frame || |
| 3610 | cpi->refresh_alt_ref_frame) { |
| 3611 | assert(cpi->refresh_fb_idx >= 0 && cpi->refresh_fb_idx < REF_FRAMES); |
| 3612 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->refresh_fb_idx], |
| 3613 | cm->new_fb_idx); |
| 3614 | } |
| 3615 | |
| 3616 | // TODO(zoeliu): To handle cpi->interp_filter_selected[]. |
| 3617 | |
| 3618 | // For GF of 16, an additional ref frame index mapping needs to be handled |
| 3619 | // if this is the last frame to encode in the current GF group. |
| 3620 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3621 | if (gf_group->update_type[gf_group->index + 1] == OVERLAY_UPDATE) |
| 3622 | av1_ref_frame_map_idx_updates(cpi, gf_group->index + 1); |
| 3623 | } |
| 3624 | |
| 3625 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3626 | // Dump out all reference frame images. |
| 3627 | dump_ref_frame_images(cpi); |
| 3628 | #endif // DUMP_REF_FRAME_IMAGES |
| 3629 | } |
| 3630 | #endif // USE_GF16_MULTI_LAYER |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3631 | |
| 3632 | static void update_reference_frames(AV1_COMP *cpi) { |
| 3633 | AV1_COMMON *const cm = &cpi->common; |
| 3634 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3635 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 3636 | // for the purpose to verify no mismatch between encoder and decoder. |
| 3637 | if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx; |
| 3638 | |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3639 | #if USE_GF16_MULTI_LAYER |
| 3640 | if (cpi->rc.baseline_gf_interval == 16) { |
| 3641 | update_reference_frames_gf16(cpi); |
| 3642 | return; |
| 3643 | } |
| 3644 | #endif // USE_GF16_MULTI_LAYER |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 3645 | |
| 3646 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3647 | // At this point the new frame has been encoded. |
| 3648 | // If any buffer copy / swapping is signaled it should be done here. |
| 3649 | if (cm->frame_type == KEY_FRAME) { |
| 3650 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3651 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3652 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3653 | cm->new_fb_idx); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3654 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3655 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3656 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3657 | cm->new_fb_idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3658 | } else if (av1_preserve_existing_gf(cpi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3659 | // We have decided to preserve the previously existing golden frame as our |
| 3660 | // new ARF frame. However, in the short term in function |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3661 | // 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] | 3662 | // we're updating the GF with the current decoded frame, we save it to the |
| 3663 | // ARF slot instead. |
| 3664 | // We now have to update the ARF with the current frame and swap gld_fb_idx |
| 3665 | // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF |
| 3666 | // slot and, if we're updating the GF, the current frame becomes the new GF. |
| 3667 | int tmp; |
| 3668 | |
| 3669 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3670 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3671 | tmp = cpi->alt_fb_idx; |
| 3672 | cpi->alt_fb_idx = cpi->gld_fb_idx; |
| 3673 | cpi->gld_fb_idx = tmp; |
| 3674 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3675 | // We need to modify the mapping accordingly |
| 3676 | cpi->arf_map[0] = cpi->alt_fb_idx; |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3677 | // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to |
| 3678 | // cpi->interp_filter_selected[GOLDEN_FRAME]? |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3679 | } else if (cpi->rc.is_src_frame_ext_arf && cm->show_existing_frame) { |
| 3680 | // Deal with the special case for showing existing internal ALTREF_FRAME |
| 3681 | // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME |
| 3682 | // by updating the virtual indices. |
| 3683 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3684 | const int which_arf = gf_group->arf_ref_idx[gf_group->index]; |
| 3685 | assert(gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3686 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3687 | const int tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3688 | shift_last_ref_frames(cpi); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3689 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3690 | cpi->lst_fb_idxes[0] = cpi->alt2_fb_idx; |
| 3691 | cpi->alt2_fb_idx = tmp; |
| 3692 | // We need to modify the mapping accordingly |
| 3693 | cpi->arf_map[which_arf] = cpi->alt2_fb_idx; |
| 3694 | |
| 3695 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3696 | cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3697 | sizeof(cpi->interp_filter_selected[ALTREF2_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3698 | } else { /* For non key/golden frames */ |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3699 | // === ALTREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3700 | if (cpi->refresh_alt_ref_frame) { |
| 3701 | int arf_idx = cpi->alt_fb_idx; |
| 3702 | int which_arf = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3703 | 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] | 3704 | |
| 3705 | memcpy(cpi->interp_filter_selected[ALTREF_FRAME + which_arf], |
| 3706 | cpi->interp_filter_selected[0], |
| 3707 | sizeof(cpi->interp_filter_selected[0])); |
| 3708 | } |
| 3709 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3710 | // === GOLDEN_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3711 | if (cpi->refresh_golden_frame) { |
| 3712 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3713 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3714 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3715 | memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], |
| 3716 | cpi->interp_filter_selected[0], |
| 3717 | sizeof(cpi->interp_filter_selected[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3718 | } |
| 3719 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3720 | // === BWDREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3721 | if (cpi->refresh_bwd_ref_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3722 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3723 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3724 | |
| 3725 | memcpy(cpi->interp_filter_selected[BWDREF_FRAME], |
| 3726 | cpi->interp_filter_selected[0], |
| 3727 | sizeof(cpi->interp_filter_selected[0])); |
| 3728 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3729 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3730 | // === ALTREF2_FRAME === |
| 3731 | if (cpi->refresh_alt2_ref_frame) { |
| 3732 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3733 | cm->new_fb_idx); |
| 3734 | |
| 3735 | memcpy(cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3736 | cpi->interp_filter_selected[0], |
| 3737 | sizeof(cpi->interp_filter_selected[0])); |
| 3738 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | if (cpi->refresh_last_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3742 | // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame |
| 3743 | // reference to the reference frame buffer virtual index; and then (2) from |
| 3744 | // the virtual index to the reference frame buffer physical index: |
| 3745 | // |
| 3746 | // LAST_FRAME, ..., LAST3_FRAME, ..., ALTREF_FRAME |
| 3747 | // | | | |
| 3748 | // v v v |
| 3749 | // lst_fb_idxes[0], ..., lst_fb_idxes[2], ..., alt_fb_idx |
| 3750 | // | | | |
| 3751 | // v v v |
| 3752 | // ref_frame_map[], ..., ref_frame_map[], ..., ref_frame_map[] |
| 3753 | // |
| 3754 | // When refresh_last_frame is set, it is intended to retire LAST3_FRAME, |
| 3755 | // have the other 2 LAST reference frames shifted as follows: |
| 3756 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3757 | // , and then have LAST_FRAME refreshed by the newly coded frame. |
| 3758 | // |
| 3759 | // To fulfill it, the decoder will be notified to execute following 2 steps: |
| 3760 | // |
| 3761 | // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME |
| 3762 | // to point to the newly coded frame, i.e. |
| 3763 | // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx; |
| 3764 | // |
| 3765 | // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the |
| 3766 | // original virtual index of LAST3_FRAME and have the other mappings |
| 3767 | // shifted as follows: |
| 3768 | // LAST_FRAME, LAST2_FRAME, LAST3_FRAME |
| 3769 | // | | | |
| 3770 | // v v v |
| 3771 | // lst_fb_idxes[2], lst_fb_idxes[0], lst_fb_idxes[1] |
| 3772 | int ref_frame; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3773 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3774 | if (cm->frame_type == KEY_FRAME) { |
| 3775 | for (ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) { |
| 3776 | ref_cnt_fb(pool->frame_bufs, |
| 3777 | &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]], |
| 3778 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3779 | } |
| 3780 | } else { |
| 3781 | int tmp; |
| 3782 | |
| 3783 | ref_cnt_fb(pool->frame_bufs, |
| 3784 | &cm->ref_frame_map[cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]], |
| 3785 | cm->new_fb_idx); |
| 3786 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3787 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3788 | |
| 3789 | shift_last_ref_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3790 | cpi->lst_fb_idxes[0] = tmp; |
| 3791 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3792 | assert(cm->show_existing_frame == 0); |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3793 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3794 | cpi->interp_filter_selected[0], |
| 3795 | sizeof(cpi->interp_filter_selected[0])); |
Zoe Liu | aff92d5 | 2017-07-11 21:35:08 -0700 | [diff] [blame] | 3796 | |
| 3797 | if (cpi->rc.is_last_bipred_frame) { |
| 3798 | // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the |
| 3799 | // LAST3_FRAME by updating the virtual indices. |
| 3800 | // |
| 3801 | // NOTE: The source frame for BWDREF does not have a holding position as |
| 3802 | // the OVERLAY frame for ALTREF's. Hence, to resolve the reference |
| 3803 | // virtual index reshuffling for BWDREF, the encoder always |
| 3804 | // specifies a LAST_BIPRED right before BWDREF and completes the |
| 3805 | // reshuffling job accordingly. |
| 3806 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3807 | |
| 3808 | shift_last_ref_frames(cpi); |
| 3809 | cpi->lst_fb_idxes[0] = cpi->bwd_fb_idx; |
| 3810 | cpi->bwd_fb_idx = tmp; |
| 3811 | |
| 3812 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3813 | cpi->interp_filter_selected[BWDREF_FRAME], |
| 3814 | sizeof(cpi->interp_filter_selected[BWDREF_FRAME])); |
| 3815 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3816 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3820 | // Dump out all reference frame images. |
| 3821 | dump_ref_frame_images(cpi); |
| 3822 | #endif // DUMP_REF_FRAME_IMAGES |
| 3823 | } |
| 3824 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3825 | 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] | 3826 | assert(buffer_idx != INVALID_IDX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3827 | RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 3828 | ensure_mv_buffer(new_fb_ptr, cm); |
| 3829 | new_fb_ptr->width = cm->width; |
| 3830 | new_fb_ptr->height = cm->height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 3833 | static void scale_references(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3834 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3835 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3836 | const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = { |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 3837 | AOM_LAST_FLAG, AOM_LAST2_FLAG, AOM_LAST3_FLAG, AOM_GOLD_FLAG, |
| 3838 | AOM_BWD_FLAG, AOM_ALT2_FLAG, AOM_ALT_FLAG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3839 | }; |
| 3840 | |
| 3841 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3842 | // 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] | 3843 | if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 3844 | BufferPool *const pool = cm->buffer_pool; |
| 3845 | const YV12_BUFFER_CONFIG *const ref = |
| 3846 | get_ref_frame_buffer(cpi, ref_frame); |
| 3847 | |
| 3848 | if (ref == NULL) { |
| 3849 | cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3850 | continue; |
| 3851 | } |
| 3852 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3853 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3854 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3855 | RefCntBuffer *new_fb_ptr = NULL; |
| 3856 | int force_scaling = 0; |
| 3857 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3858 | if (new_fb == INVALID_IDX) { |
| 3859 | new_fb = get_free_fb(cm); |
| 3860 | force_scaling = 1; |
| 3861 | } |
| 3862 | if (new_fb == INVALID_IDX) return; |
| 3863 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3864 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3865 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3866 | if (aom_realloc_frame_buffer( |
| 3867 | &new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x, |
| 3868 | cm->subsampling_y, cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 3869 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3870 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3871 | "Failed to allocate frame buffer"); |
Debargha Mukherjee | 405c857 | 2017-07-10 09:29:17 -0700 | [diff] [blame] | 3872 | av1_resize_and_extend_frame(ref, &new_fb_ptr->buf, |
| 3873 | (int)cm->bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3874 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3875 | alloc_frame_mvs(cm, new_fb); |
| 3876 | } |
| 3877 | #else |
| 3878 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3879 | RefCntBuffer *new_fb_ptr = NULL; |
| 3880 | int force_scaling = 0; |
| 3881 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3882 | if (new_fb == INVALID_IDX) { |
| 3883 | new_fb = get_free_fb(cm); |
| 3884 | force_scaling = 1; |
| 3885 | } |
| 3886 | if (new_fb == INVALID_IDX) return; |
| 3887 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3888 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3889 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3890 | 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] | 3891 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3892 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
| 3893 | NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3894 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3895 | "Failed to allocate frame buffer"); |
Debargha Mukherjee | 405c857 | 2017-07-10 09:29:17 -0700 | [diff] [blame] | 3896 | av1_resize_and_extend_frame(ref, &new_fb_ptr->buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3897 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3898 | alloc_frame_mvs(cm, new_fb); |
| 3899 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3900 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3901 | } else { |
| 3902 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3903 | RefCntBuffer *const buf = &pool->frame_bufs[buf_idx]; |
| 3904 | buf->buf.y_crop_width = ref->y_crop_width; |
| 3905 | buf->buf.y_crop_height = ref->y_crop_height; |
| 3906 | cpi->scaled_ref_idx[ref_frame - 1] = buf_idx; |
| 3907 | ++buf->ref_count; |
| 3908 | } |
| 3909 | } else { |
| 3910 | if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3911 | } |
| 3912 | } |
| 3913 | } |
| 3914 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3915 | static void release_scaled_references(AV1_COMP *cpi) { |
| 3916 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3917 | int i; |
| 3918 | if (cpi->oxcf.pass == 0) { |
| 3919 | // Only release scaled references under certain conditions: |
| 3920 | // if reference will be updated, or if scaled reference has same resolution. |
| 3921 | int refresh[INTER_REFS_PER_FRAME]; |
| 3922 | refresh[0] = (cpi->refresh_last_frame) ? 1 : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3923 | refresh[1] = refresh[2] = 0; |
| 3924 | refresh[3] = (cpi->refresh_golden_frame) ? 1 : 0; |
| 3925 | refresh[4] = (cpi->refresh_bwd_ref_frame) ? 1 : 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3926 | refresh[5] = (cpi->refresh_alt2_ref_frame) ? 1 : 0; |
| 3927 | refresh[6] = (cpi->refresh_alt_ref_frame) ? 1 : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3928 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3929 | const int idx = cpi->scaled_ref_idx[i - 1]; |
| 3930 | RefCntBuffer *const buf = |
| 3931 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 3932 | const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, i); |
| 3933 | if (buf != NULL && |
| 3934 | (refresh[i - 1] || (buf->buf.y_crop_width == ref->y_crop_width && |
| 3935 | buf->buf.y_crop_height == ref->y_crop_height))) { |
| 3936 | --buf->ref_count; |
| 3937 | cpi->scaled_ref_idx[i - 1] = INVALID_IDX; |
| 3938 | } |
| 3939 | } |
| 3940 | } else { |
| 3941 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) { |
| 3942 | const int idx = cpi->scaled_ref_idx[i]; |
| 3943 | RefCntBuffer *const buf = |
| 3944 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 3945 | if (buf != NULL) { |
| 3946 | --buf->ref_count; |
| 3947 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 3948 | } |
| 3949 | } |
| 3950 | } |
| 3951 | } |
| 3952 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3953 | #if 0 && CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3954 | static void output_frame_level_debug_stats(AV1_COMP *cpi) { |
| 3955 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3956 | FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); |
| 3957 | int64_t recon_err; |
| 3958 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3959 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3960 | |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3961 | 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] | 3962 | |
| 3963 | if (cpi->twopass.total_left_stats.coded_error != 0.0) |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 3964 | fprintf(f, "%10u %dx%d %d %d %10d %10d %10d %10d" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3965 | "%10"PRId64" %10"PRId64" %5d %5d %10"PRId64" " |
| 3966 | "%10"PRId64" %10"PRId64" %10d " |
| 3967 | "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" |
| 3968 | "%6d %6d %5d %5d %5d " |
| 3969 | "%10"PRId64" %10.3lf" |
| 3970 | "%10lf %8u %10"PRId64" %10d %10d %10d\n", |
| 3971 | cpi->common.current_video_frame, |
| 3972 | cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3973 | cpi->rc.source_alt_ref_pending, |
| 3974 | cpi->rc.source_alt_ref_active, |
| 3975 | cpi->rc.this_frame_target, |
| 3976 | cpi->rc.projected_frame_size, |
| 3977 | cpi->rc.projected_frame_size / cpi->common.MBs, |
| 3978 | (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), |
| 3979 | cpi->rc.vbr_bits_off_target, |
| 3980 | cpi->rc.vbr_bits_off_target_fast, |
| 3981 | cpi->twopass.extend_minq, |
| 3982 | cpi->twopass.extend_minq_fast, |
| 3983 | cpi->rc.total_target_vs_actual, |
| 3984 | (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), |
| 3985 | cpi->rc.total_actual_bits, cm->base_qindex, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3986 | av1_convert_qindex_to_q(cm->base_qindex, cm->bit_depth), |
| 3987 | (double)av1_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0, |
| 3988 | av1_convert_qindex_to_q(cpi->twopass.active_worst_quality, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3989 | cm->bit_depth), |
| 3990 | cpi->rc.avg_q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3991 | av1_convert_qindex_to_q(cpi->oxcf.cq_level, cm->bit_depth), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3992 | cpi->refresh_last_frame, cpi->refresh_golden_frame, |
| 3993 | cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, |
| 3994 | cpi->twopass.bits_left, |
| 3995 | cpi->twopass.total_left_stats.coded_error, |
| 3996 | cpi->twopass.bits_left / |
| 3997 | (1 + cpi->twopass.total_left_stats.coded_error), |
| 3998 | cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost, |
| 3999 | cpi->twopass.kf_zeromotion_pct, |
| 4000 | cpi->twopass.fr_content_type); |
| 4001 | |
| 4002 | fclose(f); |
| 4003 | |
| 4004 | if (0) { |
| 4005 | FILE *const fmodes = fopen("Modes.stt", "a"); |
| 4006 | int i; |
| 4007 | |
| 4008 | fprintf(fmodes, "%6d:%1d:%1d:%1d ", cpi->common.current_video_frame, |
| 4009 | cm->frame_type, cpi->refresh_golden_frame, |
| 4010 | cpi->refresh_alt_ref_frame); |
| 4011 | |
| 4012 | for (i = 0; i < MAX_MODES; ++i) |
| 4013 | fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]); |
| 4014 | |
| 4015 | fprintf(fmodes, "\n"); |
| 4016 | |
| 4017 | fclose(fmodes); |
| 4018 | } |
| 4019 | } |
| 4020 | #endif |
| 4021 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4022 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 4023 | const AV1_COMMON *const cm = &cpi->common; |
| 4024 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4025 | |
| 4026 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4027 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4028 | |
| 4029 | if (cpi->sf.mv.auto_mv_step_size) { |
| 4030 | if (frame_is_intra_only(cm)) { |
| 4031 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 4032 | // after a key/intra-only frame. |
| 4033 | cpi->max_mv_magnitude = max_mv_def; |
| 4034 | } else { |
| 4035 | if (cm->show_frame) { |
| 4036 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 4037 | // in the previous frame, capped by the default max_mv_magnitude based |
| 4038 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4039 | cpi->mv_step_param = av1_init_search_range( |
| 4040 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4041 | } |
| 4042 | cpi->max_mv_magnitude = 0; |
| 4043 | } |
| 4044 | } |
| 4045 | } |
| 4046 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4047 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4048 | int i; |
| 4049 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 4050 | cpi->common.global_motion[i] = default_warp_params; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4051 | } |
| 4052 | cpi->global_motion_search_done = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4053 | av1_set_speed_features_framesize_independent(cpi); |
| 4054 | av1_set_rd_speed_thresholds(cpi); |
| 4055 | av1_set_rd_speed_thresholds_sub8x8(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4056 | cpi->common.interp_filter = cpi->sf.default_interp_filter; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 4057 | if (!frame_is_intra_only(&cpi->common)) set_compound_tools(&cpi->common); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4058 | } |
| 4059 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4060 | 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] | 4061 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4062 | AV1_COMMON *const cm = &cpi->common; |
| 4063 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4064 | |
| 4065 | // Setup variables that depend on the dimensions of the frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4066 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4067 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4068 | // Decide q and q bounds. |
| 4069 | #if CONFIG_XIPHRC |
| 4070 | int frame_type = cm->frame_type == KEY_FRAME ? OD_I_FRAME : OD_P_FRAME; |
| 4071 | *q = od_enc_rc_select_quantizers_and_lambdas( |
| 4072 | &cpi->od_rc, cpi->refresh_golden_frame, cpi->refresh_alt_ref_frame, |
| 4073 | frame_type, bottom_index, top_index); |
| 4074 | #else |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4075 | *q = av1_rc_pick_q_and_bounds(cpi, cm->width, cm->height, bottom_index, |
| 4076 | top_index); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4077 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4078 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 4079 | if (!frame_is_intra_only(cm)) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4080 | #if CONFIG_AMVR |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 4081 | #if CONFIG_EIGHTH_PEL_MV_ONLY |
| 4082 | set_high_precision_mv(cpi, 1, cpi->common.cur_frame_force_integer_mv); |
| 4083 | #else |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4084 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH, |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 4085 | cpi->common.cur_frame_force_integer_mv); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 4086 | #endif // CONFIG_EIGHTH_PEL_MV_ONLY |
| 4087 | #else |
| 4088 | #if CONFIG_EIGHTH_PEL_MV_ONLY |
| 4089 | set_high_precision_mv(cpi, 1); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4090 | #else |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4091 | set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 4092 | #endif // CONFIG_EIGHTH_PEL_MV_ONLY |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 4093 | #endif |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 4094 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4095 | |
| 4096 | // Configure experimental use of segmentation for enhanced coding of |
| 4097 | // static regions if indicated. |
| 4098 | // Only allowed in the second pass of a two pass encode, as it requires |
| 4099 | // lagged coding, and if the relevant speed feature flag is set. |
| 4100 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 4101 | configure_static_seg_features(cpi); |
| 4102 | } |
| 4103 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4104 | static void init_motion_estimation(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4105 | int y_stride = cpi->scaled_source.y_stride; |
| 4106 | |
| 4107 | if (cpi->sf.mv.search_method == NSTEP) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4108 | av1_init3smotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4109 | } else if (cpi->sf.mv.search_method == DIAMOND) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4110 | av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4111 | } |
| 4112 | } |
| 4113 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4114 | #if CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4115 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4116 | static void set_restoration_unit_size(int width, int height, int sx, int sy, |
| 4117 | RestorationInfo *rst) { |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4118 | (void)width; |
| 4119 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4120 | (void)sx; |
| 4121 | (void)sy; |
| 4122 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 4123 | int s = AOMMIN(sx, sy); |
| 4124 | #else |
| 4125 | int s = 0; |
| 4126 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 4127 | |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4128 | rst[0].restoration_unit_size = (RESTORATION_TILESIZE_MAX >> 1); |
| 4129 | rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s; |
| 4130 | rst[2].restoration_unit_size = rst[1].restoration_unit_size; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4131 | } |
| 4132 | #endif // CONFIG_LOOP_RESTORATION |
| 4133 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4134 | static void init_ref_frame_bufs(AV1_COMMON *cm) { |
| 4135 | int i; |
| 4136 | BufferPool *const pool = cm->buffer_pool; |
| 4137 | cm->new_fb_idx = INVALID_IDX; |
| 4138 | for (i = 0; i < REF_FRAMES; ++i) { |
| 4139 | cm->ref_frame_map[i] = INVALID_IDX; |
| 4140 | pool->frame_bufs[i].ref_count = 0; |
| 4141 | } |
| 4142 | #if CONFIG_HASH_ME |
| 4143 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 4144 | av1_hash_table_init(&pool->frame_bufs[i].hash_table); |
| 4145 | } |
| 4146 | #endif |
| 4147 | } |
| 4148 | |
| 4149 | static void check_initial_width(AV1_COMP *cpi, |
| 4150 | #if CONFIG_HIGHBITDEPTH |
| 4151 | int use_highbitdepth, |
| 4152 | #endif |
| 4153 | int subsampling_x, int subsampling_y) { |
| 4154 | AV1_COMMON *const cm = &cpi->common; |
| 4155 | |
| 4156 | if (!cpi->initial_width || |
| 4157 | #if CONFIG_HIGHBITDEPTH |
| 4158 | cm->use_highbitdepth != use_highbitdepth || |
| 4159 | #endif |
| 4160 | cm->subsampling_x != subsampling_x || |
| 4161 | cm->subsampling_y != subsampling_y) { |
| 4162 | cm->subsampling_x = subsampling_x; |
| 4163 | cm->subsampling_y = subsampling_y; |
| 4164 | #if CONFIG_HIGHBITDEPTH |
| 4165 | cm->use_highbitdepth = use_highbitdepth; |
| 4166 | #endif |
| 4167 | |
| 4168 | alloc_raw_frame_buffers(cpi); |
| 4169 | init_ref_frame_bufs(cm); |
| 4170 | alloc_util_frame_buffers(cpi); |
| 4171 | |
| 4172 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 4173 | |
| 4174 | cpi->initial_width = cm->width; |
| 4175 | cpi->initial_height = cm->height; |
| 4176 | cpi->initial_mbs = cm->MBs; |
| 4177 | } |
| 4178 | } |
| 4179 | |
| 4180 | // Returns 1 if the assigned width or height was <= 0. |
| 4181 | static int set_size_literal(AV1_COMP *cpi, int width, int height) { |
| 4182 | AV1_COMMON *cm = &cpi->common; |
| 4183 | #if CONFIG_HIGHBITDEPTH |
| 4184 | check_initial_width(cpi, cm->use_highbitdepth, cm->subsampling_x, |
| 4185 | cm->subsampling_y); |
| 4186 | #else |
| 4187 | check_initial_width(cpi, cm->subsampling_x, cm->subsampling_y); |
| 4188 | #endif // CONFIG_HIGHBITDEPTH |
| 4189 | |
| 4190 | if (width <= 0 || height <= 0) return 1; |
| 4191 | |
| 4192 | cm->width = width; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4193 | cm->height = height; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4194 | |
| 4195 | if (cpi->initial_width && cpi->initial_height && |
| 4196 | (cm->width > cpi->initial_width || cm->height > cpi->initial_height)) { |
| 4197 | av1_free_context_buffers(cm); |
| 4198 | av1_free_pc_tree(&cpi->td); |
| 4199 | alloc_compressor_data(cpi); |
| 4200 | realloc_segmentation_maps(cpi); |
| 4201 | cpi->initial_width = cpi->initial_height = 0; |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4202 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4203 | update_frame_size(cpi); |
| 4204 | |
| 4205 | return 0; |
| 4206 | } |
| 4207 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4208 | static void set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4209 | AV1_COMMON *const cm = &cpi->common; |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4210 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4211 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4212 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4213 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 4214 | // There has been a change in the encoded frame size |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4215 | set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4216 | set_mv_search_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4217 | } |
| 4218 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 4219 | #if !CONFIG_XIPHRC |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4220 | if (cpi->oxcf.pass == 2) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4221 | av1_set_target_rate(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4222 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 4223 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4224 | |
| 4225 | alloc_frame_mvs(cm, cm->new_fb_idx); |
| 4226 | |
| 4227 | // Reset the frame pointers to the current frame size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4228 | 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] | 4229 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4230 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4231 | cm->use_highbitdepth, |
| 4232 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 4233 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 4234 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4235 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4236 | "Failed to allocate frame buffer"); |
| 4237 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4238 | #if CONFIG_LOOP_RESTORATION |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4239 | #if CONFIG_FRAME_SUPERRES |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4240 | const int frame_width = cm->superres_upscaled_width; |
| 4241 | const int frame_height = cm->superres_upscaled_height; |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4242 | #else |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4243 | const int frame_width = cm->width; |
| 4244 | const int frame_height = cm->height; |
| 4245 | #endif |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 4246 | set_restoration_unit_size(frame_width, frame_height, cm->subsampling_x, |
| 4247 | cm->subsampling_y, cm->rst_info); |
Rupert Swarbrick | 1a96c3f | 2017-10-24 11:55:00 +0100 | [diff] [blame] | 4248 | for (int i = 0; i < MAX_MB_PLANE; ++i) |
| 4249 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 4250 | |
| 4251 | av1_alloc_restoration_buffers(cm); |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4252 | #endif // CONFIG_LOOP_RESTORATION |
| 4253 | alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4254 | init_motion_estimation(cpi); |
| 4255 | |
| 4256 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4257 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 4258 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 4259 | |
| 4260 | ref_buf->idx = buf_idx; |
| 4261 | |
| 4262 | if (buf_idx != INVALID_IDX) { |
| 4263 | YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf; |
| 4264 | ref_buf->buf = buf; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4265 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4266 | av1_setup_scale_factors_for_frame( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4267 | &ref_buf->sf, buf->y_crop_width, buf->y_crop_height, cm->width, |
| 4268 | cm->height, (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0); |
| 4269 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4270 | av1_setup_scale_factors_for_frame(&ref_buf->sf, buf->y_crop_width, |
| 4271 | buf->y_crop_height, cm->width, |
| 4272 | cm->height); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4273 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4274 | if (av1_is_scaled(&ref_buf->sf)) aom_extend_frame_borders(buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4275 | } else { |
| 4276 | ref_buf->buf = NULL; |
| 4277 | } |
| 4278 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 4279 | |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 4280 | #if CONFIG_INTRABC |
| 4281 | #if CONFIG_HIGHBITDEPTH |
Sebastien Alaiwan | 1dcb707 | 2017-05-12 11:13:05 +0200 | [diff] [blame] | 4282 | av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height, |
| 4283 | cm->width, cm->height, |
| 4284 | cm->use_highbitdepth); |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 4285 | #else |
| 4286 | av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height, |
| 4287 | cm->width, cm->height); |
| 4288 | #endif // CONFIG_HIGHBITDEPTH |
| 4289 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4290 | |
| 4291 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 4292 | } |
| 4293 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4294 | static uint8_t calculate_next_resize_scale(const AV1_COMP *cpi) { |
| 4295 | // Choose an arbitrary random number |
| 4296 | static unsigned int seed = 56789; |
| 4297 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4298 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 4299 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4300 | |
| 4301 | switch (oxcf->resize_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4302 | case RESIZE_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4303 | case RESIZE_FIXED: |
| 4304 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4305 | new_denom = oxcf->resize_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4306 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4307 | new_denom = oxcf->resize_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4308 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4309 | case RESIZE_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4310 | default: assert(0); |
| 4311 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4312 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | #if CONFIG_FRAME_SUPERRES |
Urvang Joshi | e58b564 | 2017-10-05 17:59:43 -0700 | [diff] [blame] | 4316 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4317 | static uint8_t calculate_next_superres_scale(AV1_COMP *cpi) { |
| 4318 | // Choose an arbitrary random number |
| 4319 | static unsigned int seed = 34567; |
| 4320 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4321 | if (oxcf->pass == 1) return SCALE_NUMERATOR; |
| 4322 | uint8_t new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4323 | int bottom_index, top_index, q, qthresh; |
| 4324 | |
| 4325 | switch (oxcf->superres_mode) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4326 | case SUPERRES_NONE: new_denom = SCALE_NUMERATOR; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4327 | case SUPERRES_FIXED: |
| 4328 | if (cpi->common.frame_type == KEY_FRAME) |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4329 | new_denom = oxcf->superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4330 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4331 | new_denom = oxcf->superres_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4332 | break; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4333 | case SUPERRES_RANDOM: new_denom = lcg_rand16(&seed) % 9 + 8; break; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4334 | case SUPERRES_QTHRESH: |
| 4335 | qthresh = (cpi->common.frame_type == KEY_FRAME ? oxcf->superres_kf_qthresh |
| 4336 | : oxcf->superres_qthresh); |
| 4337 | av1_set_target_rate(cpi, cpi->oxcf.width, cpi->oxcf.height); |
| 4338 | q = av1_rc_pick_q_and_bounds(cpi, cpi->oxcf.width, cpi->oxcf.height, |
| 4339 | &bottom_index, &top_index); |
| 4340 | if (q < qthresh) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4341 | new_denom = SCALE_NUMERATOR; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4342 | } else { |
Urvang Joshi | 28983f7 | 2017-10-25 14:41:06 -0700 | [diff] [blame] | 4343 | const uint8_t min_denom = SCALE_NUMERATOR + 1; |
| 4344 | const uint8_t denom_step = (MAXQ - qthresh + 1) >> 3; |
| 4345 | const uint8_t additional_denom = (q - qthresh) / denom_step; |
| 4346 | new_denom = AOMMIN(min_denom + additional_denom, SCALE_NUMERATOR << 1); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4347 | } |
| 4348 | break; |
| 4349 | default: assert(0); |
| 4350 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4351 | return new_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4352 | } |
| 4353 | |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4354 | static int dimension_is_ok(int orig_dim, int resized_dim, int denom) { |
| 4355 | return (resized_dim * SCALE_NUMERATOR >= orig_dim * denom / 2); |
| 4356 | } |
| 4357 | |
| 4358 | static int dimensions_are_ok(int owidth, int oheight, size_params_type *rsz) { |
| 4359 | return dimension_is_ok(owidth, rsz->resize_width, rsz->superres_denom) && |
Urvang Joshi | 3d8bcb2 | 2017-10-09 12:18:59 -0700 | [diff] [blame] | 4360 | (CONFIG_HORZONLY_FRAME_SUPERRES || |
Urvang Joshi | e58b564 | 2017-10-05 17:59:43 -0700 | [diff] [blame] | 4361 | dimension_is_ok(oheight, rsz->resize_height, rsz->superres_denom)); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4362 | } |
| 4363 | |
| 4364 | #define DIVIDE_AND_ROUND(x, y) (((x) + ((y) >> 1)) / (y)) |
| 4365 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4366 | static int validate_size_scales(RESIZE_MODE resize_mode, |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4367 | SUPERRES_MODE superres_mode, int owidth, |
| 4368 | int oheight, size_params_type *rsz) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4369 | if (dimensions_are_ok(owidth, oheight, rsz)) { // Nothing to do. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4370 | return 1; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4371 | } |
| 4372 | |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 4373 | // Calculate current resize scale. |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4374 | int resize_denom = |
| 4375 | AOMMAX(DIVIDE_AND_ROUND(owidth * SCALE_NUMERATOR, rsz->resize_width), |
| 4376 | DIVIDE_AND_ROUND(oheight * SCALE_NUMERATOR, rsz->resize_height)); |
| 4377 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4378 | if (resize_mode != RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4379 | // Alter superres scale as needed to enforce conformity. |
| 4380 | rsz->superres_denom = |
| 4381 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / resize_denom; |
| 4382 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4383 | if (rsz->superres_denom > SCALE_NUMERATOR) --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4384 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4385 | } else if (resize_mode == RESIZE_RANDOM && superres_mode != SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4386 | // Alter resize scale as needed to enforce conformity. |
| 4387 | resize_denom = |
| 4388 | (2 * SCALE_NUMERATOR * SCALE_NUMERATOR) / rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4389 | rsz->resize_width = owidth; |
| 4390 | rsz->resize_height = oheight; |
| 4391 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4392 | resize_denom); |
| 4393 | if (!dimensions_are_ok(owidth, oheight, rsz)) { |
| 4394 | if (resize_denom > SCALE_NUMERATOR) { |
| 4395 | --resize_denom; |
| 4396 | rsz->resize_width = owidth; |
| 4397 | rsz->resize_height = oheight; |
| 4398 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
| 4399 | resize_denom); |
| 4400 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4401 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4402 | } else if (resize_mode == RESIZE_RANDOM && superres_mode == SUPERRES_RANDOM) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4403 | // Alter both resize and superres scales as needed to enforce conformity. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4404 | do { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4405 | if (resize_denom > rsz->superres_denom) |
| 4406 | --resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4407 | else |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4408 | --rsz->superres_denom; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4409 | rsz->resize_width = owidth; |
| 4410 | rsz->resize_height = oheight; |
| 4411 | av1_calculate_scaled_size(&rsz->resize_width, &rsz->resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4412 | resize_denom); |
| 4413 | } while (!dimensions_are_ok(owidth, oheight, rsz) && |
| 4414 | (resize_denom > SCALE_NUMERATOR || |
| 4415 | rsz->superres_denom > SCALE_NUMERATOR)); |
| 4416 | } else { // We are allowed to alter neither resize scale nor superres scale. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4417 | return 0; |
| 4418 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4419 | return dimensions_are_ok(owidth, oheight, rsz); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4420 | } |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4421 | #undef DIVIDE_AND_ROUND |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4422 | #endif // CONFIG_FRAME_SUPERRES |
| 4423 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4424 | // Calculates resize and superres params for next frame |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4425 | size_params_type av1_calculate_next_size_params(AV1_COMP *cpi) { |
| 4426 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
| 4427 | size_params_type rsz = { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4428 | oxcf->width, |
| 4429 | oxcf->height, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4430 | #if CONFIG_FRAME_SUPERRES |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4431 | SCALE_NUMERATOR |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4432 | #endif // CONFIG_FRAME_SUPERRES |
| 4433 | }; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4434 | int resize_denom; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4435 | if (oxcf->pass == 1) return rsz; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4436 | if (cpi->resize_pending_width && cpi->resize_pending_height) { |
| 4437 | rsz.resize_width = cpi->resize_pending_width; |
| 4438 | rsz.resize_height = cpi->resize_pending_height; |
| 4439 | cpi->resize_pending_width = cpi->resize_pending_height = 0; |
| 4440 | } else { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4441 | resize_denom = calculate_next_resize_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4442 | rsz.resize_width = cpi->oxcf.width; |
| 4443 | rsz.resize_height = cpi->oxcf.height; |
| 4444 | av1_calculate_scaled_size(&rsz.resize_width, &rsz.resize_height, |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4445 | resize_denom); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4446 | } |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4447 | #if CONFIG_FRAME_SUPERRES |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4448 | rsz.superres_denom = calculate_next_superres_scale(cpi); |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4449 | if (!validate_size_scales(oxcf->resize_mode, oxcf->superres_mode, oxcf->width, |
| 4450 | oxcf->height, &rsz)) |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4451 | assert(0 && "Invalid scale parameters"); |
| 4452 | #endif // CONFIG_FRAME_SUPERRES |
| 4453 | return rsz; |
| 4454 | } |
| 4455 | |
| 4456 | 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] | 4457 | int encode_width = rsz->resize_width; |
| 4458 | int encode_height = rsz->resize_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4459 | |
| 4460 | #if CONFIG_FRAME_SUPERRES |
| 4461 | AV1_COMMON *cm = &cpi->common; |
| 4462 | cm->superres_upscaled_width = encode_width; |
| 4463 | cm->superres_upscaled_height = encode_height; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 4464 | cm->superres_scale_denominator = rsz->superres_denom; |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 4465 | av1_calculate_scaled_superres_size(&encode_width, &encode_height, |
| 4466 | rsz->superres_denom); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4467 | #endif // CONFIG_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4468 | set_frame_size(cpi, encode_width, encode_height); |
| 4469 | } |
| 4470 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4471 | static void setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4472 | size_params_type rsz = av1_calculate_next_size_params(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4473 | setup_frame_size_from_params(cpi, &rsz); |
| 4474 | } |
| 4475 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4476 | #if CONFIG_FRAME_SUPERRES |
| 4477 | static void superres_post_encode(AV1_COMP *cpi) { |
| 4478 | AV1_COMMON *cm = &cpi->common; |
| 4479 | |
| 4480 | if (av1_superres_unscaled(cm)) return; |
| 4481 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4482 | av1_superres_upscale(cm, NULL); |
| 4483 | |
| 4484 | // If regular resizing is occurring the source will need to be downscaled to |
| 4485 | // match the upscaled superres resolution. Otherwise the original source is |
| 4486 | // used. |
| 4487 | if (av1_resize_unscaled(cm)) { |
| 4488 | cpi->source = cpi->unscaled_source; |
| 4489 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 4490 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 4491 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 4492 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4493 | // Do downscale. cm->(width|height) has been updated by av1_superres_upscale |
| 4494 | if (aom_realloc_frame_buffer( |
| 4495 | &cpi->scaled_source, cm->superres_upscaled_width, |
| 4496 | cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y, |
| 4497 | #if CONFIG_HIGHBITDEPTH |
| 4498 | cm->use_highbitdepth, |
| 4499 | #endif // CONFIG_HIGHBITDEPTH |
| 4500 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
| 4501 | aom_internal_error( |
| 4502 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 4503 | "Failed to reallocate scaled source buffer for superres"); |
| 4504 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 4505 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
| 4506 | #if CONFIG_HIGHBITDEPTH |
| 4507 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
| 4508 | (int)cm->bit_depth); |
| 4509 | #else |
| 4510 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source); |
| 4511 | #endif // CONFIG_HIGHBITDEPTH |
| 4512 | cpi->source = &cpi->scaled_source; |
| 4513 | } |
| 4514 | } |
| 4515 | #endif // CONFIG_FRAME_SUPERRES |
| 4516 | |
| 4517 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
| 4518 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
| 4519 | struct loopfilter *lf = &cm->lf; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4520 | int no_loopfilter = 0; |
| 4521 | |
| 4522 | if (is_lossless_requested(&cpi->oxcf)) no_loopfilter = 1; |
| 4523 | |
| 4524 | #if CONFIG_EXT_TILE |
| 4525 | // 0 loopfilter level is only necessary if individual tile |
| 4526 | // decoding is required. |
| 4527 | if (cm->single_tile_decoding) no_loopfilter = 1; |
| 4528 | #endif // CONFIG_EXT_TILE |
| 4529 | |
| 4530 | if (no_loopfilter) { |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4531 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4532 | lf->filter_level[0] = 0; |
| 4533 | lf->filter_level[1] = 0; |
| 4534 | #else |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4535 | lf->filter_level = 0; |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4536 | #endif |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4537 | } else { |
| 4538 | struct aom_usec_timer timer; |
| 4539 | |
| 4540 | aom_clear_system_state(); |
| 4541 | |
| 4542 | aom_usec_timer_start(&timer); |
| 4543 | |
| 4544 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
| 4545 | |
| 4546 | aom_usec_timer_mark(&timer); |
| 4547 | cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer); |
| 4548 | } |
| 4549 | |
Cheng Chen | 5ad5b28 | 2017-10-05 16:36:06 -0700 | [diff] [blame] | 4550 | #if CONFIG_INTRABC |
| 4551 | // When intraBC is on, do loop filtering per superblock, |
| 4552 | // instead of do it after the whole frame has been encoded, |
| 4553 | // as is in the else branch |
| 4554 | #else |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 4555 | #if !CONFIG_LPF_SB |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4556 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4557 | if (lf->filter_level[0] || lf->filter_level[1]) |
| 4558 | #else |
| 4559 | if (lf->filter_level > 0) |
| 4560 | #endif |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 4561 | #endif // CONFIG_LPF_SB |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4562 | { |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 4563 | #if CONFIG_LPF_SB |
| 4564 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0, 0, |
| 4565 | 0); |
| 4566 | #else |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4567 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4568 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level[0], |
| 4569 | lf->filter_level[1], 0, 0); |
| 4570 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_u, |
| 4571 | lf->filter_level_u, 1, 0); |
| 4572 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_v, |
| 4573 | lf->filter_level_v, 2, 0); |
| 4574 | |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 4575 | #else |
| 4576 | 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] | 4577 | #endif // CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 4578 | #endif // CONFIG_LPF_SB |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4579 | } |
Cheng Chen | 5ad5b28 | 2017-10-05 16:36:06 -0700 | [diff] [blame] | 4580 | #endif // CONFIG_INTRABC |
Debargha Mukherjee | e168a78 | 2017-08-31 12:30:10 -0700 | [diff] [blame] | 4581 | |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 4582 | #if CONFIG_STRIPED_LOOP_RESTORATION |
Rupert Swarbrick | 76c7800 | 2017-11-02 17:26:35 +0000 | [diff] [blame] | 4583 | #if CONFIG_FRAME_SUPERRES && CONFIG_HORZONLY_FRAME_SUPERRES |
| 4584 | aom_extend_frame_borders(cm->frame_to_show); |
| 4585 | #endif |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 4586 | av1_loop_restoration_save_boundary_lines(cm->frame_to_show, cm); |
| 4587 | #endif |
| 4588 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4589 | #if CONFIG_CDEF |
| 4590 | if (is_lossless_requested(&cpi->oxcf)) { |
| 4591 | cm->cdef_bits = 0; |
| 4592 | cm->cdef_strengths[0] = 0; |
| 4593 | cm->nb_cdef_strengths = 1; |
| 4594 | } else { |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 4595 | // Find CDEF parameters |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4596 | av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd, |
Debargha Mukherjee | d7338aa | 2017-11-04 07:34:50 -0700 | [diff] [blame] | 4597 | cpi->sf.fast_cdef_search); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4598 | |
| 4599 | // Apply the filter |
| 4600 | av1_cdef_frame(cm->frame_to_show, cm, xd); |
| 4601 | } |
| 4602 | #endif |
| 4603 | |
| 4604 | #if CONFIG_FRAME_SUPERRES |
| 4605 | superres_post_encode(cpi); |
| 4606 | #endif // CONFIG_FRAME_SUPERRES |
| 4607 | |
| 4608 | #if CONFIG_LOOP_RESTORATION |
Rupert Swarbrick | 146a060 | 2017-10-17 16:52:20 +0100 | [diff] [blame] | 4609 | av1_pick_filter_restoration(cpi->source, cpi); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4610 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 4611 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 4612 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 4613 | av1_loop_restoration_filter_frame(cm->frame_to_show, cm, cm->rst_info, 7, |
| 4614 | NULL); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4615 | } |
| 4616 | #endif // CONFIG_LOOP_RESTORATION |
| 4617 | // TODO(debargha): Fix mv search range on encoder side |
| 4618 | // aom_extend_frame_inner_borders(cm->frame_to_show); |
| 4619 | aom_extend_frame_borders(cm->frame_to_show); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4620 | } |
| 4621 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4622 | static void encode_without_recode_loop(AV1_COMP *cpi) { |
| 4623 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4624 | int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4625 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4626 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4627 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4628 | set_size_independent_vars(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4629 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4630 | setup_frame_size(cpi); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4631 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4632 | assert(cm->width == cpi->scaled_source.y_crop_width); |
| 4633 | assert(cm->height == cpi->scaled_source.y_crop_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 4634 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4635 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4636 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4637 | cpi->source = |
| 4638 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
| 4639 | if (cpi->unscaled_last_source != NULL) |
| 4640 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4641 | &cpi->scaled_last_source); |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 4642 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4643 | cpi->source->buf_8bit_valid = 0; |
| 4644 | #endif |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4645 | |
| 4646 | if (frame_is_intra_only(cm) == 0) { |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4647 | scale_references(cpi); |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4648 | } |
| 4649 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4650 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4651 | setup_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4652 | suppress_active_map(cpi); |
hui su | ed5a30f | 2017-04-27 16:02:49 -0700 | [diff] [blame] | 4653 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4654 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4655 | // exclusive. |
| 4656 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4657 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4658 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4659 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4660 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4661 | av1_cyclic_refresh_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4662 | } |
| 4663 | apply_active_map(cpi); |
| 4664 | |
| 4665 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4666 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4667 | |
| 4668 | // Update some stats from cyclic refresh, and check if we should not update |
| 4669 | // golden reference, for 1 pass CBR. |
| 4670 | 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] | 4671 | (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR)) |
| 4672 | av1_cyclic_refresh_check_golden_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4673 | |
| 4674 | // Update the skip mb flag probabilities based on the distribution |
| 4675 | // seen in the last encoder iteration. |
| 4676 | // update_base_skip_probs(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4677 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4678 | } |
| 4679 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4680 | static void encode_with_recode_loop(AV1_COMP *cpi, size_t *size, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4681 | uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4682 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4683 | RATE_CONTROL *const rc = &cpi->rc; |
| 4684 | int bottom_index, top_index; |
| 4685 | int loop_count = 0; |
| 4686 | int loop_at_this_size = 0; |
| 4687 | int loop = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4688 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4689 | int overshoot_seen = 0; |
| 4690 | int undershoot_seen = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4691 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4692 | int frame_over_shoot_limit; |
| 4693 | int frame_under_shoot_limit; |
| 4694 | int q = 0, q_low = 0, q_high = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4695 | |
| 4696 | set_size_independent_vars(cpi); |
| 4697 | |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 4698 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4699 | cpi->source->buf_8bit_valid = 0; |
| 4700 | #endif |
| 4701 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4702 | aom_clear_system_state(); |
| 4703 | setup_frame_size(cpi); |
| 4704 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4705 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4706 | do { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4707 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4708 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4709 | if (loop_count == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4710 | // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. |
| 4711 | set_mv_search_params(cpi); |
| 4712 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4713 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4714 | // Reset the loop state for new frame size. |
| 4715 | overshoot_seen = 0; |
| 4716 | undershoot_seen = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4717 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4718 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4719 | q_low = bottom_index; |
| 4720 | q_high = top_index; |
| 4721 | |
| 4722 | loop_at_this_size = 0; |
| 4723 | } |
| 4724 | |
| 4725 | // Decide frame size bounds first time through. |
| 4726 | if (loop_count == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4727 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4728 | &frame_under_shoot_limit, |
| 4729 | &frame_over_shoot_limit); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4730 | } |
| 4731 | |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4732 | // if frame was scaled calculate global_motion_search again if already done |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4733 | if (loop_count > 0 && cpi->source && cpi->global_motion_search_done) |
| 4734 | if (cpi->source->y_crop_width != cm->width || |
| 4735 | cpi->source->y_crop_height != cm->height) |
| 4736 | cpi->global_motion_search_done = 0; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 4737 | cpi->source = |
| 4738 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4739 | if (cpi->unscaled_last_source != NULL) |
| 4740 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4741 | &cpi->scaled_last_source); |
| 4742 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4743 | if (frame_is_intra_only(cm) == 0) { |
| 4744 | if (loop_count > 0) { |
| 4745 | release_scaled_references(cpi); |
| 4746 | } |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 4747 | scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4748 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4749 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4750 | |
| 4751 | if (loop_count == 0) setup_frame(cpi); |
| 4752 | |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 4753 | #if CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4754 | // Base q-index may have changed, so we need to assign proper default coef |
| 4755 | // probs before every iteration. |
| 4756 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
| 4757 | int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4758 | av1_default_coef_probs(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4759 | if (cm->frame_type == KEY_FRAME || cm->error_resilient_mode || |
| 4760 | cm->reset_frame_context == RESET_FRAME_CONTEXT_ALL) { |
| 4761 | for (i = 0; i < FRAME_CONTEXTS; ++i) cm->frame_contexts[i] = *cm->fc; |
| 4762 | } else if (cm->reset_frame_context == RESET_FRAME_CONTEXT_CURRENT) { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 4763 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 4764 | if (cm->frame_refs[0].idx >= 0) { |
| 4765 | cm->frame_contexts[cm->frame_refs[0].idx] = *cm->fc; |
| 4766 | } |
| 4767 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4768 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 4769 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4770 | } |
| 4771 | } |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 4772 | #endif // CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4773 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4774 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4775 | // exclusive. |
| 4776 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4777 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4778 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4779 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | // transform / motion compensation build reconstruction frame |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4783 | save_coding_context(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4784 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4785 | |
| 4786 | // Update the skip mb flag probabilities based on the distribution |
| 4787 | // seen in the last encoder iteration. |
| 4788 | // update_base_skip_probs(cpi); |
| 4789 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4790 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4791 | |
| 4792 | // Dummy pack of the bitstream using up to date stats to get an |
| 4793 | // accurate estimate of output frame size to determine if we need |
| 4794 | // to recode. |
| 4795 | if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4796 | restore_coding_context(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4797 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4798 | |
| 4799 | rc->projected_frame_size = (int)(*size) << 3; |
| 4800 | restore_coding_context(cpi); |
| 4801 | |
| 4802 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4803 | } |
| 4804 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4805 | if (cpi->oxcf.rc_mode == AOM_Q) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4806 | loop = 0; |
| 4807 | } else { |
| 4808 | if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced && |
| 4809 | (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
| 4810 | int last_q = q; |
| 4811 | int64_t kf_err; |
| 4812 | |
| 4813 | int64_t high_err_target = cpi->ambient_err; |
| 4814 | int64_t low_err_target = cpi->ambient_err >> 1; |
| 4815 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4816 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4817 | if (cm->use_highbitdepth) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4818 | 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] | 4819 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4820 | 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] | 4821 | } |
| 4822 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4823 | 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] | 4824 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4825 | |
| 4826 | // Prevent possible divide by zero error below for perfect KF |
| 4827 | kf_err += !kf_err; |
| 4828 | |
| 4829 | // The key frame is not good enough or we can afford |
| 4830 | // to make it better without undue risk of popping. |
| 4831 | if ((kf_err > high_err_target && |
| 4832 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4833 | (kf_err > low_err_target && |
| 4834 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4835 | // Lower q_high |
| 4836 | q_high = q > q_low ? q - 1 : q_low; |
| 4837 | |
| 4838 | // Adjust Q |
| 4839 | q = (int)((q * high_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4840 | q = AOMMIN(q, (q_high + q_low) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4841 | } else if (kf_err < low_err_target && |
| 4842 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4843 | // The key frame is much better than the previous frame |
| 4844 | // Raise q_low |
| 4845 | q_low = q < q_high ? q + 1 : q_high; |
| 4846 | |
| 4847 | // Adjust Q |
| 4848 | q = (int)((q * low_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4849 | q = AOMMIN(q, (q_high + q_low + 1) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4850 | } |
| 4851 | |
| 4852 | // Clamp Q to upper and lower limits: |
| 4853 | q = clamp(q, q_low, q_high); |
| 4854 | |
| 4855 | loop = q != last_q; |
| 4856 | } else if (recode_loop_test(cpi, frame_over_shoot_limit, |
| 4857 | frame_under_shoot_limit, q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4858 | AOMMAX(q_high, top_index), bottom_index)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4859 | // Is the projected frame size out of range and are we allowed |
| 4860 | // to attempt to recode. |
| 4861 | int last_q = q; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4862 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4863 | int retries = 0; |
| 4864 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4865 | // Frame size out of permitted range: |
| 4866 | // Update correction factor & compute new Q to try... |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4867 | // Frame is too large |
| 4868 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 4869 | // Special case if the projected size is > the max allowed. |
| 4870 | if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
| 4871 | q_high = rc->worst_quality; |
| 4872 | |
| 4873 | // Raise Qlow as to at least the current value |
| 4874 | q_low = q < q_high ? q + 1 : q_high; |
| 4875 | |
| 4876 | if (undershoot_seen || loop_at_this_size > 1) { |
| 4877 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4878 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4879 | |
| 4880 | q = (q_high + q_low + 1) / 2; |
| 4881 | } else { |
| 4882 | // Update rate_correction_factor unless |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4883 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4884 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4885 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4886 | AOMMAX(q_high, top_index), cm->width, |
| 4887 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4888 | |
| 4889 | while (q < q_low && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4890 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4891 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4892 | AOMMAX(q_high, top_index), cm->width, |
| 4893 | cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4894 | retries++; |
| 4895 | } |
| 4896 | } |
| 4897 | |
| 4898 | overshoot_seen = 1; |
| 4899 | } else { |
| 4900 | // Frame is too small |
| 4901 | q_high = q > q_low ? q - 1 : q_low; |
| 4902 | |
| 4903 | if (overshoot_seen || loop_at_this_size > 1) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4904 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4905 | q = (q_high + q_low) / 2; |
| 4906 | } else { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4907 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4908 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4909 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4910 | // Special case reset for qlow for constrained quality. |
| 4911 | // This should only trigger where there is very substantial |
| 4912 | // undershoot on a frame and the auto cq level is above |
| 4913 | // the user passsed in value. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4914 | if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4915 | q_low = q; |
| 4916 | } |
| 4917 | |
| 4918 | while (q > q_high && retries < 10) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4919 | av1_rc_update_rate_correction_factors(cpi, cm->width, cm->height); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4920 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 4921 | top_index, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4922 | retries++; |
| 4923 | } |
| 4924 | } |
| 4925 | |
| 4926 | undershoot_seen = 1; |
| 4927 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4928 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4929 | |
| 4930 | // Clamp Q to upper and lower limits: |
| 4931 | q = clamp(q, q_low, q_high); |
| 4932 | |
| 4933 | loop = (q != last_q); |
| 4934 | } else { |
| 4935 | loop = 0; |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | // Special case for overlay frame. |
| 4940 | if (rc->is_src_frame_alt_ref && |
| 4941 | rc->projected_frame_size < rc->max_frame_bandwidth) |
| 4942 | loop = 0; |
| 4943 | |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4944 | if (recode_loop_test_global_motion(cpi)) { |
| 4945 | loop = 1; |
| 4946 | } |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4947 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4948 | if (loop) { |
| 4949 | ++loop_count; |
| 4950 | ++loop_at_this_size; |
| 4951 | |
| 4952 | #if CONFIG_INTERNAL_STATS |
| 4953 | ++cpi->tot_recode_hits; |
| 4954 | #endif |
| 4955 | } |
| 4956 | } while (loop); |
| 4957 | } |
| 4958 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4959 | static int get_ref_frame_flags(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4960 | const int *const map = cpi->common.ref_frame_map; |
| 4961 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4962 | // No.1 Priority: LAST_FRAME |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4963 | const int last2_is_last = |
| 4964 | map[cpi->lst_fb_idxes[1]] == map[cpi->lst_fb_idxes[0]]; |
| 4965 | const int last3_is_last = |
| 4966 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[0]]; |
| 4967 | const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4968 | const int bwd_is_last = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4969 | const int alt2_is_last = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4970 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4971 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4972 | // No.2 Priority: ALTREF_FRAME |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4973 | const int last2_is_alt = map[cpi->lst_fb_idxes[1]] == map[cpi->alt_fb_idx]; |
| 4974 | const int last3_is_alt = map[cpi->lst_fb_idxes[2]] == map[cpi->alt_fb_idx]; |
| 4975 | const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 4976 | 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] | 4977 | const int alt2_is_alt = map[cpi->alt2_fb_idx] == map[cpi->alt_fb_idx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4978 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4979 | // No.3 Priority: LAST2_FRAME |
| 4980 | const int last3_is_last2 = |
| 4981 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]]; |
| 4982 | const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4983 | const int bwd_is_last2 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4984 | const int alt2_is_last2 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4985 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 4986 | // No.4 Priority: LAST3_FRAME |
| 4987 | const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 4988 | const int bwd_is_last3 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 4989 | const int alt2_is_last3 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 4990 | |
| 4991 | // No.5 Priority: GOLDEN_FRAME |
| 4992 | const int bwd_is_gld = map[cpi->bwd_fb_idx] == map[cpi->gld_fb_idx]; |
| 4993 | const int alt2_is_gld = map[cpi->alt2_fb_idx] == map[cpi->gld_fb_idx]; |
| 4994 | |
| 4995 | // No.6 Priority: BWDREF_FRAME |
| 4996 | const int alt2_is_bwd = map[cpi->alt2_fb_idx] == map[cpi->bwd_fb_idx]; |
| 4997 | |
| 4998 | // No.7 Priority: ALTREF2_FRAME |
| 4999 | |
| 5000 | int flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5001 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5002 | 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] | 5003 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5004 | if (alt_is_last) flags &= ~AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5005 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5006 | if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5007 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5008 | if (last3_is_last || last3_is_alt || last3_is_last2) flags &= ~AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5009 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5010 | if (gld_is_last || gld_is_alt || gld_is_last2 || gld_is_last3) |
| 5011 | flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5012 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5013 | if ((bwd_is_last || bwd_is_alt || bwd_is_last2 || bwd_is_last3 || |
| 5014 | bwd_is_gld) && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5015 | (flags & AOM_BWD_FLAG)) |
| 5016 | flags &= ~AOM_BWD_FLAG; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5017 | |
Zoe Liu | 368bf16 | 2017-11-03 20:10:19 -0700 | [diff] [blame] | 5018 | if ((alt2_is_last || alt2_is_alt || alt2_is_last2 || alt2_is_last3 || |
| 5019 | alt2_is_gld || alt2_is_bwd) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5020 | (flags & AOM_ALT2_FLAG)) |
| 5021 | flags &= ~AOM_ALT2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5022 | |
| 5023 | return flags; |
| 5024 | } |
| 5025 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5026 | static void set_ext_overrides(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5027 | // Overrides the defaults with the externally supplied values with |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5028 | // av1_update_reference() and av1_update_entropy() calls |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5029 | // Note: The overrides are valid only for the next frame passed |
| 5030 | // to encode_frame_to_data_rate() function |
| 5031 | if (cpi->ext_refresh_frame_context_pending) { |
| 5032 | cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context; |
| 5033 | cpi->ext_refresh_frame_context_pending = 0; |
| 5034 | } |
| 5035 | if (cpi->ext_refresh_frame_flags_pending) { |
| 5036 | cpi->refresh_last_frame = cpi->ext_refresh_last_frame; |
| 5037 | cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame; |
| 5038 | cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; |
| 5039 | cpi->ext_refresh_frame_flags_pending = 0; |
| 5040 | } |
| 5041 | } |
| 5042 | |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 5043 | #if !CONFIG_FRAME_SIGN_BIAS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5044 | static void set_arf_sign_bias(AV1_COMP *cpi) { |
| 5045 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5046 | int arf_sign_bias; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5047 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5048 | // The arf_sign_bias will be one for internal ARFs' |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5049 | arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 5050 | (!cpi->refresh_alt_ref_frame || |
| 5051 | gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE); |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 5052 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5053 | cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5054 | 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] | 5055 | cm->ref_frame_sign_bias[ALTREF2_FRAME] = |
| 5056 | cm->ref_frame_sign_bias[ALTREF_FRAME]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5057 | } |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 5058 | #endif // !CONFIG_FRAME_SIGN_BIAS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5059 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5060 | static int setup_interp_filter_search_mask(AV1_COMP *cpi) { |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 5061 | InterpFilter ifilter; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5062 | int ref_total[TOTAL_REFS_PER_FRAME] = { 0 }; |
| 5063 | MV_REFERENCE_FRAME ref; |
| 5064 | int mask = 0; |
| 5065 | int arf_idx = ALTREF_FRAME; |
| 5066 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5067 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame || |
| 5068 | cpi->refresh_alt2_ref_frame) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5069 | return mask; |
| 5070 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5071 | for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) |
| 5072 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) |
| 5073 | ref_total[ref] += cpi->interp_filter_selected[ref][ifilter]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5074 | |
| 5075 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) { |
| 5076 | if ((ref_total[LAST_FRAME] && |
| 5077 | cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5078 | (ref_total[LAST2_FRAME] == 0 || |
| 5079 | cpi->interp_filter_selected[LAST2_FRAME][ifilter] * 50 < |
| 5080 | ref_total[LAST2_FRAME]) && |
| 5081 | (ref_total[LAST3_FRAME] == 0 || |
| 5082 | cpi->interp_filter_selected[LAST3_FRAME][ifilter] * 50 < |
| 5083 | ref_total[LAST3_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5084 | (ref_total[GOLDEN_FRAME] == 0 || |
| 5085 | cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50 < |
| 5086 | ref_total[GOLDEN_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5087 | (ref_total[BWDREF_FRAME] == 0 || |
| 5088 | cpi->interp_filter_selected[BWDREF_FRAME][ifilter] * 50 < |
| 5089 | ref_total[BWDREF_FRAME]) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5090 | (ref_total[ALTREF2_FRAME] == 0 || |
| 5091 | cpi->interp_filter_selected[ALTREF2_FRAME][ifilter] * 50 < |
| 5092 | ref_total[ALTREF2_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5093 | (ref_total[ALTREF_FRAME] == 0 || |
| 5094 | cpi->interp_filter_selected[arf_idx][ifilter] * 50 < |
| 5095 | ref_total[ALTREF_FRAME])) |
| 5096 | mask |= 1 << ifilter; |
| 5097 | } |
| 5098 | return mask; |
| 5099 | } |
| 5100 | |
| 5101 | #define DUMP_RECON_FRAMES 0 |
| 5102 | |
| 5103 | #if DUMP_RECON_FRAMES == 1 |
| 5104 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5105 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 5106 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5107 | const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5108 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame^] | 5109 | if (recon_buf == NULL) { |
| 5110 | printf("Frame %d is not ready.\n", cm->current_video_frame); |
| 5111 | return; |
| 5112 | } |
| 5113 | |
| 5114 | #if CONFIG_FRAME_MARKER |
| 5115 | static const int flag_list[TOTAL_REFS_PER_FRAME] = { 0, |
| 5116 | AOM_LAST_FLAG, |
| 5117 | AOM_LAST2_FLAG, |
| 5118 | AOM_LAST3_FLAG, |
| 5119 | AOM_GOLD_FLAG, |
| 5120 | AOM_BWD_FLAG, |
| 5121 | AOM_ALT2_FLAG, |
| 5122 | AOM_ALT_FLAG }; |
| 5123 | printf( |
| 5124 | "\n***Frame=%d (frame_offset=%d, show_frame=%d, " |
| 5125 | "show_existing_frame=%d) " |
| 5126 | "[LAST LAST2 LAST3 GOLDEN BWD ALT2 ALT]=[", |
| 5127 | cm->current_video_frame, cm->frame_offset, cm->show_frame, |
| 5128 | cm->show_existing_frame); |
| 5129 | for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 5130 | const int buf_idx = cm->frame_refs[ref_frame - LAST_FRAME].idx; |
| 5131 | const int ref_offset = |
| 5132 | (buf_idx >= 0) |
| 5133 | ? (int)cm->buffer_pool->frame_bufs[buf_idx].cur_frame_offset |
| 5134 | : -1; |
| 5135 | printf(" %d(%c)", ref_offset, |
| 5136 | (cpi->ref_frame_flags & flag_list[ref_frame]) ? 'Y' : 'N'); |
| 5137 | } |
| 5138 | printf(" ]\n"); |
| 5139 | #endif // CONFIG_FRAME_MARKER |
| 5140 | |
| 5141 | if (!cm->show_frame) { |
| 5142 | printf("Frame %d is a no show frame, so no image dump.\n", |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5143 | cm->current_video_frame); |
| 5144 | return; |
| 5145 | } |
| 5146 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame^] | 5147 | int h; |
| 5148 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 5149 | FILE *f_recon = NULL; |
| 5150 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5151 | if (cm->current_video_frame == 0) { |
| 5152 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 5153 | printf("Unable to open file %s to write.\n", file_name); |
| 5154 | return; |
| 5155 | } |
| 5156 | } else { |
| 5157 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 5158 | printf("Unable to open file %s to append.\n", file_name); |
| 5159 | return; |
| 5160 | } |
| 5161 | } |
| 5162 | printf( |
| 5163 | "\nFrame=%5d, encode_update_type[%5d]=%1d, show_existing_frame=%d, " |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 5164 | "source_alt_ref_active=%d, refresh_alt_ref_frame=%d, rf_level=%d, " |
| 5165 | "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] | 5166 | cm->current_video_frame, cpi->twopass.gf_group.index, |
| 5167 | cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 5168 | cm->show_existing_frame, cpi->rc.source_alt_ref_active, |
| 5169 | cpi->refresh_alt_ref_frame, |
| 5170 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index], |
| 5171 | recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5172 | #if 0 |
| 5173 | int ref_frame; |
| 5174 | printf("get_ref_frame_map_idx: ["); |
| 5175 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
| 5176 | printf(" %d", get_ref_frame_map_idx(cpi, ref_frame)); |
| 5177 | printf(" ]\n"); |
| 5178 | printf("cm->new_fb_idx = %d\n", cm->new_fb_idx); |
| 5179 | printf("cm->ref_frame_map = ["); |
| 5180 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 5181 | printf(" %d", cm->ref_frame_map[ref_frame - LAST_FRAME]); |
| 5182 | } |
| 5183 | printf(" ]\n"); |
| 5184 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5185 | |
| 5186 | // --- Y --- |
| 5187 | for (h = 0; h < cm->height; ++h) { |
| 5188 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 5189 | f_recon); |
| 5190 | } |
| 5191 | // --- U --- |
| 5192 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 5193 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 5194 | f_recon); |
| 5195 | } |
| 5196 | // --- V --- |
| 5197 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 5198 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 5199 | f_recon); |
| 5200 | } |
| 5201 | |
| 5202 | fclose(f_recon); |
| 5203 | } |
| 5204 | #endif // DUMP_RECON_FRAMES |
| 5205 | |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5206 | static void make_update_tile_list_enc(AV1_COMP *cpi, const int start_tile, |
| 5207 | const int num_tiles, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5208 | FRAME_CONTEXT *ec_ctxs[]) { |
| 5209 | int i; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5210 | for (i = start_tile; i < start_tile + num_tiles; ++i) |
| 5211 | ec_ctxs[i - start_tile] = &cpi->tile_data[i].tctx; |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5212 | } |
| 5213 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5214 | 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] | 5215 | uint8_t *dest, int skip_adapt, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5216 | unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5217 | AV1_COMMON *const cm = &cpi->common; |
| 5218 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5219 | struct segmentation *const seg = &cm->seg; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5220 | #if CONFIG_SIMPLE_BWD_ADAPT |
| 5221 | const int num_bwd_ctxs = 1; |
| 5222 | #else |
| 5223 | const int num_bwd_ctxs = cm->tile_rows * cm->tile_cols; |
| 5224 | #endif |
| 5225 | |
| 5226 | FRAME_CONTEXT **tile_ctxs = |
| 5227 | aom_malloc(num_bwd_ctxs * sizeof(&cpi->tile_data[0].tctx)); |
| 5228 | aom_cdf_prob **cdf_ptrs = aom_malloc( |
| 5229 | num_bwd_ctxs * sizeof(&cpi->tile_data[0].tctx.partition_cdf[0][0])); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5230 | #if CONFIG_XIPHRC |
| 5231 | int frame_type; |
| 5232 | int drop_this_frame = 0; |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5233 | #endif // CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5234 | set_ext_overrides(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5235 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5236 | |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 5237 | #if !CONFIG_FRAME_SIGN_BIAS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5238 | // Set the arf sign bias for this frame. |
| 5239 | set_arf_sign_bias(cpi); |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 5240 | #endif // !CONFIG_FRAME_SIGN_BIAS |
| 5241 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 5242 | #if CONFIG_TEMPMV_SIGNALING |
| 5243 | // frame type has been decided outside of this function call |
| 5244 | cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only; |
Jingning Han | e17ebe9 | 2017-11-03 15:25:42 -0700 | [diff] [blame] | 5245 | cm->use_ref_frame_mvs = |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 5246 | !cpi->oxcf.disable_tempmv && !cm->cur_frame->intra_only; |
Jingning Han | e17ebe9 | 2017-11-03 15:25:42 -0700 | [diff] [blame] | 5247 | cm->use_prev_frame_mvs = cm->use_ref_frame_mvs; |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 5248 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5249 | |
Jingning Han | d8a15a6 | 2017-10-30 10:53:42 -0700 | [diff] [blame] | 5250 | // Reset the frame packet stamp index. |
| 5251 | if (cm->frame_type == KEY_FRAME) cm->current_video_frame = 0; |
| 5252 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5253 | // NOTE: |
| 5254 | // (1) Move the setup of the ref_frame_flags upfront as it would be |
| 5255 | // determined by the current frame properties; |
| 5256 | // (2) The setup of the ref_frame_flags applies to both show_existing_frame's |
| 5257 | // and the other cases. |
| 5258 | if (cm->current_video_frame > 0) |
| 5259 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 5260 | |
| 5261 | if (cm->show_existing_frame) { |
| 5262 | // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current |
| 5263 | // BWDREF_FRAME in the reference frame buffer. |
| 5264 | cm->frame_type = INTER_FRAME; |
| 5265 | cm->show_frame = 1; |
| 5266 | cpi->frame_flags = *frame_flags; |
| 5267 | |
| 5268 | // In the case of show_existing frame, we will not send fresh flag |
| 5269 | // to decoder. Any change in the reference frame buffer can be done by |
| 5270 | // switching the virtual indices. |
| 5271 | |
| 5272 | cpi->refresh_last_frame = 0; |
| 5273 | cpi->refresh_golden_frame = 0; |
| 5274 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5275 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5276 | cpi->refresh_alt_ref_frame = 0; |
| 5277 | |
| 5278 | cpi->rc.is_bwd_ref_frame = 0; |
| 5279 | cpi->rc.is_last_bipred_frame = 0; |
| 5280 | cpi->rc.is_bipred_frame = 0; |
| 5281 | |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 5282 | restore_coding_context(cpi); |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame^] | 5283 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5284 | // Build the bitstream |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5285 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5286 | |
| 5287 | // Set up frame to show to get ready for stats collection. |
| 5288 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 5289 | |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame^] | 5290 | #if CONFIG_FRAME_MARKER |
| 5291 | // Update current frame offset. |
| 5292 | cm->frame_offset = |
| 5293 | cm->buffer_pool->frame_bufs[cm->new_fb_idx].cur_frame_offset; |
| 5294 | #endif // CONFIG_FRAME_MARKER |
| 5295 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5296 | #if DUMP_RECON_FRAMES == 1 |
| 5297 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 5298 | dump_filtered_recon_frames(cpi); |
| 5299 | #endif // DUMP_RECON_FRAMES |
| 5300 | |
| 5301 | // Update the LAST_FRAME in the reference frame buffer. |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5302 | // NOTE: |
| 5303 | // (1) For BWDREF_FRAME as the show_existing_frame, the reference frame |
| 5304 | // update has been done previously when handling the LAST_BIPRED_FRAME |
| 5305 | // right before BWDREF_FRAME (in the display order); |
| 5306 | // (2) For INTNL_OVERLAY as the show_existing_frame, the reference frame |
| 5307 | // update will be done when the following is called, which will exchange |
| 5308 | // the virtual indexes between LAST_FRAME and ALTREF2_FRAME, so that |
| 5309 | // LAST3 will get retired, LAST2 becomes LAST3, LAST becomes LAST2, and |
| 5310 | // ALTREF2_FRAME will serve as the new LAST_FRAME. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5311 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5312 | |
| 5313 | // Update frame flags |
| 5314 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 5315 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 5316 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 5317 | |
| 5318 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5319 | |
| 5320 | // Update the frame type |
| 5321 | cm->last_frame_type = cm->frame_type; |
| 5322 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5323 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 5324 | // to do post-encoding update accordingly. |
| 5325 | if (cpi->rc.is_src_frame_alt_ref) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 5326 | av1_set_target_rate(cpi, cm->width, cm->height); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5327 | #if CONFIG_XIPHRC |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5328 | 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] | 5329 | drop_this_frame = od_enc_rc_update_state( |
| 5330 | &cpi->od_rc, *size << 3, cpi->refresh_golden_frame, |
| 5331 | cpi->refresh_alt_ref_frame, frame_type, cpi->droppable); |
| 5332 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5333 | av1_rc_postencode_update(cpi, *size); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5334 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5335 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5336 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5337 | ++cm->current_video_frame; |
| 5338 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5339 | aom_free(tile_ctxs); |
| 5340 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5341 | return; |
| 5342 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5343 | |
| 5344 | // Set default state for segment based loop filter update flags. |
| 5345 | cm->lf.mode_ref_delta_update = 0; |
| 5346 | |
| 5347 | if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search) |
| 5348 | cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi); |
| 5349 | |
| 5350 | // Set various flags etc to special state if it is a key frame. |
| 5351 | if (frame_is_intra_only(cm)) { |
| 5352 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5353 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5354 | |
| 5355 | // If segmentation is enabled force a map update for key frames. |
| 5356 | if (seg->enabled) { |
| 5357 | seg->update_map = 1; |
| 5358 | seg->update_data = 1; |
| 5359 | } |
| 5360 | |
| 5361 | // The alternate reference frame cannot be active for a key frame. |
| 5362 | cpi->rc.source_alt_ref_active = 0; |
| 5363 | |
| 5364 | cm->error_resilient_mode = oxcf->error_resilient_mode; |
| 5365 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 5366 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5367 | // By default, encoder assumes decoder can use prev_mi. |
| 5368 | if (cm->error_resilient_mode) { |
| 5369 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
| 5370 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 5371 | } else if (cm->intra_only) { |
| 5372 | // Only reset the current context. |
| 5373 | cm->reset_frame_context = RESET_FRAME_CONTEXT_CURRENT; |
| 5374 | } |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 5375 | #if CONFIG_EXT_TILE |
| 5376 | if (cpi->oxcf.large_scale_tile) |
| 5377 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 5378 | #endif // CONFIG_EXT_TILE |
| 5379 | #endif // !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5380 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5381 | if (cpi->oxcf.mtu == 0) { |
| 5382 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 5383 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 5384 | // Use a default value for the purposes of weighting costs in probability |
| 5385 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5386 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 5387 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5388 | |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 5389 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 5390 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 5391 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 5392 | #endif // CONFIG_EXT_TILE |
| 5393 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5394 | #if CONFIG_XIPHRC |
| 5395 | if (drop_this_frame) { |
| 5396 | av1_rc_postencode_update_drop_frame(cpi); |
| 5397 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5398 | aom_free(tile_ctxs); |
| 5399 | aom_free(cdf_ptrs); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5400 | return; |
| 5401 | } |
| 5402 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5403 | // For 1 pass CBR, check if we are dropping this frame. |
| 5404 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5405 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5406 | cm->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5407 | if (av1_rc_drop_frame(cpi)) { |
| 5408 | av1_rc_postencode_update_drop_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5409 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5410 | aom_free(tile_ctxs); |
| 5411 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5412 | return; |
| 5413 | } |
| 5414 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5415 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5416 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5417 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5418 | |
| 5419 | #if CONFIG_INTERNAL_STATS |
| 5420 | memset(cpi->mode_chosen_counts, 0, |
| 5421 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 5422 | #endif |
| 5423 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5424 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 5425 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5426 | /* Non-normative definition of current_frame_id ("frame counter" with |
| 5427 | * wraparound) */ |
Sebastien Alaiwan | d418f68 | 2017-10-19 15:06:52 +0200 | [diff] [blame] | 5428 | const int frame_id_length = FRAME_ID_LENGTH; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5429 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5430 | int lsb, msb; |
Arild Fuldseth (arilfuld) | bac17c1 | 2016-12-02 12:01:06 +0100 | [diff] [blame] | 5431 | /* quasi-random initialization of current_frame_id for a key frame */ |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5432 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5433 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 5434 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 5435 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5436 | } else { |
| 5437 | #endif |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5438 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 5439 | msb = cpi->source->y_buffer[1] & 0xff; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5440 | #if CONFIG_HIGHBITDEPTH |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5441 | } |
Arild Fuldseth (arilfuld) | bac17c1 | 2016-12-02 12:01:06 +0100 | [diff] [blame] | 5442 | #endif |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5443 | cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5444 | } else { |
| 5445 | cm->current_frame_id = |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5446 | (cm->current_frame_id + 1 + (1 << frame_id_length)) % |
| 5447 | (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5448 | } |
| 5449 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 5450 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5451 | |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 5452 | #if CONFIG_EXT_DELTA_Q |
| 5453 | cm->delta_q_present_flag = cpi->oxcf.deltaq_mode != NO_DELTA_Q; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 5454 | cm->delta_lf_present_flag = cpi->oxcf.deltaq_mode == DELTA_Q_LF; |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 5455 | #if CONFIG_LOOPFILTER_LEVEL |
| 5456 | cm->delta_lf_multi = DEFAULT_DELTA_LF_MULTI; |
| 5457 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 5458 | #endif |
| 5459 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5460 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 5461 | encode_without_recode_loop(cpi); |
| 5462 | } else { |
| 5463 | encode_with_recode_loop(cpi, size, dest); |
| 5464 | } |
| 5465 | |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5466 | cm->last_tile_cols = cm->tile_cols; |
| 5467 | cm->last_tile_rows = cm->tile_rows; |
| 5468 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5469 | #ifdef OUTPUT_YUV_SKINMAP |
| 5470 | if (cpi->common.current_video_frame > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5471 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5472 | } |
| 5473 | #endif // OUTPUT_YUV_SKINMAP |
| 5474 | |
| 5475 | // Special case code to reduce pulsing when key frames are forced at a |
| 5476 | // fixed interval. Note the reconstruction error if it is the frame before |
| 5477 | // the force key frame |
| 5478 | 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] | 5479 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5480 | if (cm->use_highbitdepth) { |
| 5481 | cpi->ambient_err = |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5482 | aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5483 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5484 | 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] | 5485 | } |
| 5486 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5487 | 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] | 5488 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5489 | } |
| 5490 | |
| 5491 | // If the encoder forced a KEY_FRAME decision |
| 5492 | if (cm->frame_type == KEY_FRAME) { |
| 5493 | cpi->refresh_last_frame = 1; |
| 5494 | } |
| 5495 | |
| 5496 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 5497 | cm->frame_to_show->color_space = cm->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 5498 | #if CONFIG_COLORSPACE_HEADERS |
| 5499 | cm->frame_to_show->transfer_function = cm->transfer_function; |
| 5500 | cm->frame_to_show->chroma_sample_position = cm->chroma_sample_position; |
| 5501 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5502 | cm->frame_to_show->color_range = cm->color_range; |
| 5503 | cm->frame_to_show->render_width = cm->render_width; |
| 5504 | cm->frame_to_show->render_height = cm->render_height; |
| 5505 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5506 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 5507 | // off. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5508 | |
| 5509 | // Pick the loop filter level for the frame. |
| 5510 | loopfilter_frame(cpi, cm); |
| 5511 | |
Wei-Ting Lin | 01d4d8f | 2017-08-03 17:04:12 -0700 | [diff] [blame] | 5512 | #ifdef OUTPUT_YUV_REC |
| 5513 | aom_write_one_yuv_frame(cm, cm->frame_to_show); |
| 5514 | #endif |
| 5515 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5516 | // Build the bitstream |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5517 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5518 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5519 | if (skip_adapt) { |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5520 | aom_free(tile_ctxs); |
| 5521 | aom_free(cdf_ptrs); |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5522 | return; |
| 5523 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5524 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5525 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 5526 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5527 | int i; |
| 5528 | /* Update reference frame id values based on the value of refresh_mask */ |
| 5529 | for (i = 0; i < REF_FRAMES; i++) { |
| 5530 | if ((cm->refresh_mask >> i) & 1) { |
| 5531 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 5532 | } |
| 5533 | } |
| 5534 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 5535 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5536 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5537 | #if DUMP_RECON_FRAMES == 1 |
| 5538 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Zoe Liu | b4f3103 | 2017-11-03 23:48:35 -0700 | [diff] [blame^] | 5539 | dump_filtered_recon_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5540 | #endif // DUMP_RECON_FRAMES |
| 5541 | |
| 5542 | if (cm->seg.update_map) update_reference_segmentation_map(cpi); |
| 5543 | |
| 5544 | if (frame_is_intra_only(cm) == 0) { |
| 5545 | release_scaled_references(cpi); |
| 5546 | } |
| 5547 | |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5548 | update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5549 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5550 | #if CONFIG_ENTROPY_STATS |
| 5551 | av1_accumulate_frame_counts(&aggregate_fc, &cm->counts); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 5552 | assert(cm->frame_context_idx < FRAME_CONTEXTS); |
| 5553 | av1_accumulate_frame_counts(&aggregate_fc_per_type[cm->frame_context_idx], |
| 5554 | &cm->counts); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5555 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5556 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5557 | av1_adapt_intra_frame_probs(cm); |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5558 | #if CONFIG_SIMPLE_BWD_ADAPT |
| 5559 | make_update_tile_list_enc(cpi, cm->largest_tile_id, 1, tile_ctxs); |
| 5560 | #else |
| 5561 | make_update_tile_list_enc(cpi, 0, num_bwd_ctxs, tile_ctxs); |
| 5562 | #endif |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5563 | av1_average_tile_coef_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5564 | num_bwd_ctxs); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5565 | av1_average_tile_intra_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5566 | num_bwd_ctxs); |
Debargha Mukherjee | 43061b3 | 2017-10-13 16:50:17 -0700 | [diff] [blame] | 5567 | av1_average_tile_loopfilter_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
| 5568 | num_bwd_ctxs); |
hui su | ff0da2b | 2017-03-07 15:51:37 -0800 | [diff] [blame] | 5569 | #if CONFIG_ADAPT_SCAN |
| 5570 | av1_adapt_scan_order(cm); |
| 5571 | #endif // CONFIG_ADAPT_SCAN |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5572 | } |
| 5573 | |
| 5574 | if (!frame_is_intra_only(cm)) { |
| 5575 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5576 | av1_adapt_inter_frame_probs(cm); |
| 5577 | av1_adapt_mv_probs(cm, cm->allow_high_precision_mv); |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5578 | av1_average_tile_inter_cdfs(&cpi->common, cpi->common.fc, tile_ctxs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5579 | cdf_ptrs, num_bwd_ctxs); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5580 | av1_average_tile_mv_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 5581 | num_bwd_ctxs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5582 | } |
| 5583 | } |
| 5584 | |
| 5585 | if (cpi->refresh_golden_frame == 1) |
| 5586 | cpi->frame_flags |= FRAMEFLAGS_GOLDEN; |
| 5587 | else |
| 5588 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 5589 | |
| 5590 | if (cpi->refresh_alt_ref_frame == 1) |
| 5591 | cpi->frame_flags |= FRAMEFLAGS_ALTREF; |
| 5592 | else |
| 5593 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 5594 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5595 | if (cpi->refresh_bwd_ref_frame == 1) |
| 5596 | cpi->frame_flags |= FRAMEFLAGS_BWDREF; |
| 5597 | else |
| 5598 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5599 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5600 | cm->last_frame_type = cm->frame_type; |
| 5601 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5602 | #if CONFIG_XIPHRC |
| 5603 | frame_type = cm->frame_type == KEY_FRAME ? OD_I_FRAME : OD_P_FRAME; |
| 5604 | |
| 5605 | drop_this_frame = |
| 5606 | od_enc_rc_update_state(&cpi->od_rc, *size << 3, cpi->refresh_golden_frame, |
| 5607 | cpi->refresh_alt_ref_frame, frame_type, 0); |
| 5608 | if (drop_this_frame) { |
| 5609 | av1_rc_postencode_update_drop_frame(cpi); |
| 5610 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5611 | aom_free(tile_ctxs); |
| 5612 | aom_free(cdf_ptrs); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5613 | return; |
| 5614 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5615 | #else // !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5616 | av1_rc_postencode_update(cpi, *size); |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5617 | #endif // CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5618 | |
| 5619 | #if 0 |
| 5620 | output_frame_level_debug_stats(cpi); |
| 5621 | #endif |
| 5622 | |
| 5623 | if (cm->frame_type == KEY_FRAME) { |
| 5624 | // Tell the caller that the frame was coded as a key frame |
| 5625 | *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY; |
| 5626 | } else { |
| 5627 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5628 | } |
| 5629 | |
| 5630 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 5631 | // filter deltas. |
| 5632 | cm->seg.update_map = 0; |
| 5633 | cm->seg.update_data = 0; |
| 5634 | cm->lf.mode_ref_delta_update = 0; |
| 5635 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5636 | if (cm->show_frame) { |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5637 | // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that are |
| 5638 | // being used as reference. |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 5639 | swap_mi_and_prev_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5640 | // Don't increment frame counters if this was an altref buffer |
| 5641 | // update not a real frame |
| 5642 | ++cm->current_video_frame; |
| 5643 | } |
| 5644 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5645 | // NOTE: Shall not refer to any frame not used as reference. |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5646 | if (cm->is_reference_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5647 | cm->prev_frame = cm->cur_frame; |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5648 | // keep track of the last coded dimensions |
| 5649 | cm->last_width = cm->width; |
| 5650 | cm->last_height = cm->height; |
| 5651 | |
| 5652 | // reset to normal state now that we are done. |
| 5653 | cm->last_show_frame = cm->show_frame; |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5654 | } |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5655 | |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5656 | aom_free(tile_ctxs); |
| 5657 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5658 | } |
| 5659 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5660 | static void Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5661 | int skip_adapt, unsigned int *frame_flags) { |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5662 | #if CONFIG_XIPHRC |
| 5663 | int64_t ip_count; |
| 5664 | int frame_type, is_golden, is_altref; |
| 5665 | |
| 5666 | /* Not updated during init so update it here */ |
| 5667 | if (cpi->oxcf.rc_mode == AOM_Q) cpi->od_rc.quality = cpi->oxcf.cq_level; |
| 5668 | |
| 5669 | frame_type = od_frame_type(&cpi->od_rc, cpi->od_rc.cur_frame, &is_golden, |
| 5670 | &is_altref, &ip_count); |
| 5671 | |
| 5672 | if (frame_type == OD_I_FRAME) { |
| 5673 | frame_type = KEY_FRAME; |
| 5674 | cpi->frame_flags &= FRAMEFLAGS_KEY; |
| 5675 | } else if (frame_type == OD_P_FRAME) { |
| 5676 | frame_type = INTER_FRAME; |
| 5677 | } |
| 5678 | |
| 5679 | if (is_altref) { |
| 5680 | cpi->refresh_alt_ref_frame = 1; |
| 5681 | cpi->rc.source_alt_ref_active = 1; |
| 5682 | } |
| 5683 | |
| 5684 | cpi->refresh_golden_frame = is_golden; |
| 5685 | cpi->common.frame_type = frame_type; |
| 5686 | if (is_golden) cpi->frame_flags &= FRAMEFLAGS_GOLDEN; |
| 5687 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5688 | if (cpi->oxcf.rc_mode == AOM_CBR) { |
| 5689 | av1_rc_get_one_pass_cbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5690 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5691 | av1_rc_get_one_pass_vbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5692 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5693 | #endif |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5694 | encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5695 | } |
| 5696 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5697 | #if !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5698 | static void Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5699 | unsigned int *frame_flags) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5700 | encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5701 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5702 | // Do not do post-encoding update for those frames that do not have a spot in |
| 5703 | // a gf group, but note that an OVERLAY frame always has a spot in a gf group, |
| 5704 | // even when show_existing_frame is used. |
| 5705 | 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] | 5706 | av1_twopass_postencode_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5707 | } |
| 5708 | check_show_existing_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5709 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5710 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5711 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 5712 | 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] | 5713 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 5714 | int64_t end_time) { |
| 5715 | AV1_COMMON *const cm = &cpi->common; |
| 5716 | struct aom_usec_timer timer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5717 | int res = 0; |
| 5718 | const int subsampling_x = sd->subsampling_x; |
| 5719 | const int subsampling_y = sd->subsampling_y; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5720 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5721 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
| 5722 | #endif |
| 5723 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5724 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5725 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
| 5726 | #else |
| 5727 | check_initial_width(cpi, subsampling_x, subsampling_y); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5728 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5729 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5730 | aom_usec_timer_start(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5731 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5732 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5733 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5734 | use_highbitdepth, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5735 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5736 | frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5737 | res = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5738 | aom_usec_timer_mark(&timer); |
| 5739 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5740 | |
| 5741 | if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && |
| 5742 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5743 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5744 | "Non-4:2:0 color format requires profile 1 or 3"); |
| 5745 | res = -1; |
| 5746 | } |
| 5747 | if ((cm->profile == PROFILE_1 || cm->profile == PROFILE_3) && |
| 5748 | (subsampling_x == 1 && subsampling_y == 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5749 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5750 | "4:2:0 color format requires profile 0 or 2"); |
| 5751 | res = -1; |
| 5752 | } |
| 5753 | |
| 5754 | return res; |
| 5755 | } |
| 5756 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5757 | static int frame_is_reference(const AV1_COMP *cpi) { |
| 5758 | const AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5759 | |
| 5760 | return cm->frame_type == KEY_FRAME || cpi->refresh_last_frame || |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 5761 | cpi->refresh_golden_frame || cpi->refresh_bwd_ref_frame || |
| 5762 | cpi->refresh_alt2_ref_frame || cpi->refresh_alt_ref_frame || |
| 5763 | !cm->error_resilient_mode || cm->lf.mode_ref_delta_update || |
| 5764 | cm->seg.update_map || cm->seg.update_data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5765 | } |
| 5766 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5767 | static void adjust_frame_rate(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5768 | const struct lookahead_entry *source) { |
| 5769 | int64_t this_duration; |
| 5770 | int step = 0; |
| 5771 | |
| 5772 | if (source->ts_start == cpi->first_time_stamp_ever) { |
| 5773 | this_duration = source->ts_end - source->ts_start; |
| 5774 | step = 1; |
| 5775 | } else { |
| 5776 | int64_t last_duration = |
| 5777 | cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen; |
| 5778 | |
| 5779 | this_duration = source->ts_end - cpi->last_end_time_stamp_seen; |
| 5780 | |
| 5781 | // do a step update if the duration changes by 10% |
| 5782 | if (last_duration) |
| 5783 | step = (int)((this_duration - last_duration) * 10 / last_duration); |
| 5784 | } |
| 5785 | |
| 5786 | if (this_duration) { |
| 5787 | if (step) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5788 | av1_new_framerate(cpi, 10000000.0 / this_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5789 | } else { |
| 5790 | // Average this frame's rate into the last second's average |
| 5791 | // frame rate. If we haven't seen 1 second yet, then average |
| 5792 | // over the whole interval seen. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5793 | const double interval = AOMMIN( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5794 | (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0); |
| 5795 | double avg_duration = 10000000.0 / cpi->framerate; |
| 5796 | avg_duration *= (interval - avg_duration + this_duration); |
| 5797 | avg_duration /= interval; |
| 5798 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5799 | av1_new_framerate(cpi, 10000000.0 / avg_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5800 | } |
| 5801 | } |
| 5802 | cpi->last_time_stamp_seen = source->ts_start; |
| 5803 | cpi->last_end_time_stamp_seen = source->ts_end; |
| 5804 | } |
| 5805 | |
| 5806 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5807 | // used as the arf midpoint. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5808 | static int get_arf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5809 | RATE_CONTROL *const rc = &cpi->rc; |
| 5810 | int arf_src_index = 0; |
| 5811 | if (is_altref_enabled(cpi)) { |
| 5812 | if (cpi->oxcf.pass == 2) { |
| 5813 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5814 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 5815 | arf_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5816 | } |
| 5817 | } else if (rc->source_alt_ref_pending) { |
| 5818 | arf_src_index = rc->frames_till_gf_update_due; |
| 5819 | } |
| 5820 | } |
| 5821 | return arf_src_index; |
| 5822 | } |
| 5823 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5824 | static int get_brf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5825 | int brf_src_index = 0; |
| 5826 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5827 | |
| 5828 | // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup |
| 5829 | // flag. |
| 5830 | if (gf_group->bidir_pred_enabled[gf_group->index]) { |
| 5831 | if (cpi->oxcf.pass == 2) { |
| 5832 | if (gf_group->update_type[gf_group->index] == BRF_UPDATE) |
| 5833 | brf_src_index = gf_group->brf_src_offset[gf_group->index]; |
| 5834 | } else { |
| 5835 | // TODO(zoeliu): To re-visit the setup for this scenario |
| 5836 | brf_src_index = cpi->rc.bipred_group_interval - 1; |
| 5837 | } |
| 5838 | } |
| 5839 | |
| 5840 | return brf_src_index; |
| 5841 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5842 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5843 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5844 | // used as the arf midpoint. |
| 5845 | static int get_arf2_src_index(AV1_COMP *cpi) { |
| 5846 | int arf2_src_index = 0; |
| 5847 | if (is_altref_enabled(cpi) && cpi->num_extra_arfs) { |
| 5848 | if (cpi->oxcf.pass == 2) { |
| 5849 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5850 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) { |
| 5851 | arf2_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5852 | } |
| 5853 | } |
| 5854 | } |
| 5855 | return arf2_src_index; |
| 5856 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5857 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5858 | static void check_src_altref(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5859 | const struct lookahead_entry *source) { |
| 5860 | RATE_CONTROL *const rc = &cpi->rc; |
| 5861 | |
| 5862 | // If pass == 2, the parameters set here will be reset in |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5863 | // av1_rc_get_second_pass_params() |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5864 | |
| 5865 | if (cpi->oxcf.pass == 2) { |
| 5866 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5867 | rc->is_src_frame_alt_ref = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5868 | (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) || |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5869 | (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5870 | rc->is_src_frame_ext_arf = |
| 5871 | gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5872 | } else { |
| 5873 | rc->is_src_frame_alt_ref = |
| 5874 | cpi->alt_ref_source && (source == cpi->alt_ref_source); |
| 5875 | } |
| 5876 | |
| 5877 | if (rc->is_src_frame_alt_ref) { |
| 5878 | // Current frame is an ARF overlay frame. |
| 5879 | cpi->alt_ref_source = NULL; |
| 5880 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5881 | if (rc->is_src_frame_ext_arf && !cpi->common.show_existing_frame) { |
| 5882 | // For INTNL_OVERLAY, when show_existing_frame == 0, they do need to |
| 5883 | // refresh the LAST_FRAME, i.e. LAST3 gets retired, LAST2 becomes LAST3, |
| 5884 | // LAST becomes LAST2, and INTNL_OVERLAY becomes LAST. |
| 5885 | cpi->refresh_last_frame = 1; |
| 5886 | } else { |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5887 | // Don't refresh the last buffer for an ARF overlay frame. It will |
| 5888 | // become the GF so preserve last as an alternative prediction option. |
| 5889 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5890 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5891 | } |
| 5892 | } |
| 5893 | |
| 5894 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5895 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 5896 | const unsigned char *img2, int img2_pitch, |
| 5897 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5898 | |
| 5899 | static void adjust_image_stat(double y, double u, double v, double all, |
| 5900 | ImageStat *s) { |
| 5901 | s->stat[Y] += y; |
| 5902 | s->stat[U] += u; |
| 5903 | s->stat[V] += v; |
| 5904 | s->stat[ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5905 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5906 | } |
| 5907 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5908 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5909 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5910 | double samples = 0.0; |
| 5911 | uint32_t in_bit_depth = 8; |
| 5912 | uint32_t bit_depth = 8; |
| 5913 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5914 | #if CONFIG_INTER_STATS_ONLY |
Yaowu Xu | 1b4ffc4 | 2017-07-26 09:54:07 -0700 | [diff] [blame] | 5915 | if (cm->frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5916 | #endif |
| 5917 | cpi->bytes += frame_bytes; |
| 5918 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5919 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5920 | if (cm->use_highbitdepth) { |
| 5921 | in_bit_depth = cpi->oxcf.input_bit_depth; |
| 5922 | bit_depth = cm->bit_depth; |
| 5923 | } |
| 5924 | #endif |
| 5925 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5926 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5927 | const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; |
| 5928 | double y, u, v, frame_all; |
| 5929 | |
| 5930 | cpi->count++; |
| 5931 | if (cpi->b_calculate_psnr) { |
| 5932 | PSNR_STATS psnr; |
| 5933 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5934 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5935 | // TODO(yaowu): unify these two versions into one. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5936 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5937 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5938 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5939 | aom_calc_psnr(orig, recon, &psnr); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5940 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5941 | |
| 5942 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 5943 | &cpi->psnr); |
| 5944 | cpi->total_sq_error += psnr.sse[0]; |
| 5945 | cpi->total_samples += psnr.samples[0]; |
| 5946 | samples = psnr.samples[0]; |
| 5947 | // TODO(yaowu): unify these two versions into one. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5948 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5949 | if (cm->use_highbitdepth) |
| 5950 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5951 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5952 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5953 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5954 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5955 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5956 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5957 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5958 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5959 | cpi->summed_quality += frame_ssim2 * weight; |
| 5960 | cpi->summed_weights += weight; |
| 5961 | |
| 5962 | #if 0 |
| 5963 | { |
| 5964 | FILE *f = fopen("q_used.stt", "a"); |
| 5965 | fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", |
| 5966 | cpi->common.current_video_frame, y2, u2, v2, |
| 5967 | frame_psnr2, frame_ssim2); |
| 5968 | fclose(f); |
| 5969 | } |
| 5970 | #endif |
| 5971 | } |
| 5972 | if (cpi->b_calculate_blockiness) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5973 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5974 | if (!cm->use_highbitdepth) |
| 5975 | #endif |
| 5976 | { |
| 5977 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5978 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 5979 | recon->y_stride, orig->y_width, orig->y_height); |
| 5980 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5981 | cpi->total_blockiness += frame_blockiness; |
| 5982 | } |
| 5983 | |
| 5984 | if (cpi->b_calculate_consistency) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5985 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5986 | if (!cm->use_highbitdepth) |
| 5987 | #endif |
| 5988 | { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5989 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5990 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 5991 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 5992 | |
| 5993 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 5994 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5995 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5996 | if (consistency > 0.0) |
| 5997 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5998 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5999 | cpi->total_inconsistency += this_inconsistency; |
| 6000 | } |
| 6001 | } |
| 6002 | } |
| 6003 | |
| 6004 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6005 | 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] | 6006 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6007 | 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] | 6008 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 6009 | } |
| 6010 | } |
| 6011 | #endif // CONFIG_INTERNAL_STATS |
| 6012 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6013 | #if CONFIG_AMVR |
| 6014 | static int is_integer_mv(AV1_COMP *cpi, const YV12_BUFFER_CONFIG *cur_picture, |
| 6015 | const YV12_BUFFER_CONFIG *last_picture, |
| 6016 | hash_table *last_hash_table) { |
| 6017 | aom_clear_system_state(); |
| 6018 | // check use hash ME |
| 6019 | int k; |
| 6020 | uint32_t hash_value_1; |
| 6021 | uint32_t hash_value_2; |
| 6022 | |
| 6023 | const int block_size = 8; |
| 6024 | const double threshold_current = 0.8; |
| 6025 | const double threshold_average = 0.95; |
| 6026 | const int max_history_size = 32; |
| 6027 | int T = 0; // total block |
| 6028 | int C = 0; // match with collocated block |
| 6029 | int S = 0; // smooth region but not match with collocated block |
| 6030 | int M = 0; // match with other block |
| 6031 | |
| 6032 | const int pic_width = cur_picture->y_width; |
| 6033 | const int pic_height = cur_picture->y_height; |
| 6034 | for (int i = 0; i + block_size <= pic_height; i += block_size) { |
| 6035 | for (int j = 0; j + block_size <= pic_width; j += block_size) { |
| 6036 | const int x_pos = j; |
| 6037 | const int y_pos = i; |
| 6038 | int match = 1; |
| 6039 | T++; |
| 6040 | |
| 6041 | // check whether collocated block match with current |
| 6042 | uint8_t *p_cur = cur_picture->y_buffer; |
| 6043 | uint8_t *p_ref = last_picture->y_buffer; |
| 6044 | int stride_cur = cur_picture->y_stride; |
| 6045 | int stride_ref = last_picture->y_stride; |
| 6046 | p_cur += (y_pos * stride_cur + x_pos); |
| 6047 | p_ref += (y_pos * stride_ref + x_pos); |
| 6048 | |
| 6049 | for (int tmpY = 0; tmpY < block_size && match; tmpY++) { |
| 6050 | for (int tmpX = 0; tmpX < block_size && match; tmpX++) { |
| 6051 | if (p_cur[tmpX] != p_ref[tmpX]) { |
| 6052 | match = 0; |
| 6053 | } |
| 6054 | } |
| 6055 | p_cur += stride_cur; |
| 6056 | p_ref += stride_ref; |
| 6057 | } |
| 6058 | |
| 6059 | if (match) { |
| 6060 | C++; |
| 6061 | continue; |
| 6062 | } |
| 6063 | |
| 6064 | if (av1_hash_is_horizontal_perfect(cur_picture, block_size, x_pos, |
| 6065 | y_pos) || |
| 6066 | av1_hash_is_vertical_perfect(cur_picture, block_size, x_pos, y_pos)) { |
| 6067 | S++; |
| 6068 | continue; |
| 6069 | } |
| 6070 | |
| 6071 | av1_get_block_hash_value( |
| 6072 | cur_picture->y_buffer + y_pos * stride_cur + x_pos, stride_cur, |
| 6073 | block_size, &hash_value_1, &hash_value_2); |
| 6074 | |
| 6075 | if (av1_has_exact_match(last_hash_table, hash_value_1, hash_value_2)) { |
| 6076 | M++; |
| 6077 | } |
| 6078 | } |
| 6079 | } |
| 6080 | |
| 6081 | assert(T > 0); |
| 6082 | double csm_rate = ((double)(C + S + M)) / ((double)(T)); |
| 6083 | double m_rate = ((double)(M)) / ((double)(T)); |
| 6084 | |
| 6085 | cpi->csm_rate_array[cpi->rate_index] = csm_rate; |
| 6086 | cpi->m_rate_array[cpi->rate_index] = m_rate; |
| 6087 | |
| 6088 | cpi->rate_index = (cpi->rate_index + 1) % max_history_size; |
| 6089 | cpi->rate_size++; |
| 6090 | cpi->rate_size = AOMMIN(cpi->rate_size, max_history_size); |
| 6091 | |
| 6092 | if (csm_rate < threshold_current) { |
| 6093 | return 0; |
| 6094 | } |
| 6095 | |
| 6096 | if (C == T) { |
| 6097 | return 1; |
| 6098 | } |
| 6099 | |
| 6100 | double csm_average = 0.0; |
| 6101 | double m_average = 0.0; |
| 6102 | |
| 6103 | for (k = 0; k < cpi->rate_size; k++) { |
| 6104 | csm_average += cpi->csm_rate_array[k]; |
| 6105 | m_average += cpi->m_rate_array[k]; |
| 6106 | } |
| 6107 | csm_average /= cpi->rate_size; |
| 6108 | m_average /= cpi->rate_size; |
| 6109 | |
| 6110 | if (csm_average < threshold_average) { |
| 6111 | return 0; |
| 6112 | } |
| 6113 | |
| 6114 | if (M > (T - C - S) / 3) { |
| 6115 | return 1; |
| 6116 | } |
| 6117 | |
| 6118 | if (csm_rate > 0.99 && m_rate > 0.01) { |
| 6119 | return 1; |
| 6120 | } |
| 6121 | |
| 6122 | if (csm_average + m_average > 1.01) { |
| 6123 | return 1; |
| 6124 | } |
| 6125 | |
| 6126 | return 0; |
| 6127 | } |
| 6128 | #endif |
| 6129 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6130 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 6131 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 6132 | int64_t *time_end, int flush) { |
| 6133 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 6134 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6135 | BufferPool *const pool = cm->buffer_pool; |
| 6136 | RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6137 | struct aom_usec_timer cmptimer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6138 | YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
| 6139 | struct lookahead_entry *last_source = NULL; |
| 6140 | struct lookahead_entry *source = NULL; |
| 6141 | int arf_src_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6142 | int brf_src_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6143 | int i; |
| 6144 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 6145 | #if CONFIG_XIPHRC |
| 6146 | cpi->od_rc.end_of_input = flush; |
| 6147 | #endif |
| 6148 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6149 | #if CONFIG_BITSTREAM_DEBUG |
| 6150 | assert(cpi->oxcf.max_threads == 0 && |
| 6151 | "bitstream debug tool does not support multithreading"); |
| 6152 | bitstream_queue_record_write(); |
Angie Chiang | cb9a9eb | 2016-09-01 16:10:50 -0700 | [diff] [blame] | 6153 | 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] | 6154 | #endif |
| 6155 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6156 | aom_usec_timer_start(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6157 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6158 | #if CONFIG_AMVR |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 6159 | #if CONFIG_EIGHTH_PEL_MV_ONLY |
| 6160 | set_high_precision_mv(cpi, 1, 0); |
| 6161 | #else |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6162 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 6163 | #endif // CONFIG_EIGHTH_PEL_MV_ONLY |
| 6164 | #else |
| 6165 | #if CONFIG_EIGHTH_PEL_MV_ONLY |
| 6166 | set_high_precision_mv(cpi, 1); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6167 | #else |
Cheng Chen | 46f30c7 | 2017-09-07 11:13:33 -0700 | [diff] [blame] | 6168 | set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 6169 | #endif // CONFIG_EIGHTH_PEL_MV_ONLY |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6170 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6171 | |
| 6172 | // Is multi-arf enabled. |
| 6173 | // Note that at the moment multi_arf is only configured for 2 pass VBR |
| 6174 | if ((oxcf->pass == 2) && (cpi->oxcf.enable_auto_arf > 1)) |
| 6175 | cpi->multi_arf_allowed = 1; |
| 6176 | else |
| 6177 | cpi->multi_arf_allowed = 0; |
| 6178 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 6179 | // Normal defaults |
| 6180 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6181 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 6182 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6183 | cm->refresh_frame_context = |
| 6184 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 6185 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 6186 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 6187 | #if CONFIG_EXT_TILE |
| 6188 | if (oxcf->large_scale_tile) |
| 6189 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 6190 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6191 | |
| 6192 | cpi->refresh_last_frame = 1; |
| 6193 | cpi->refresh_golden_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6194 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6195 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6196 | cpi->refresh_alt_ref_frame = 0; |
| 6197 | |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 6198 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6199 | if (oxcf->pass == 2 && cm->show_existing_frame) { |
| 6200 | // Manage the source buffer and flush out the source frame that has been |
| 6201 | // coded already; Also get prepared for PSNR calculation if needed. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6202 | if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6203 | *size = 0; |
| 6204 | return -1; |
| 6205 | } |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 6206 | cpi->source = &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6207 | // TODO(zoeliu): To track down to determine whether it's needed to adjust |
| 6208 | // the frame rate. |
| 6209 | *time_stamp = source->ts_start; |
| 6210 | *time_end = source->ts_end; |
| 6211 | |
| 6212 | // We need to adjust frame rate for an overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 6213 | 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] | 6214 | |
| 6215 | // Find a free buffer for the new frame, releasing the reference previously |
| 6216 | // held. |
| 6217 | if (cm->new_fb_idx != INVALID_IDX) { |
| 6218 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 6219 | } |
| 6220 | cm->new_fb_idx = get_free_fb(cm); |
| 6221 | |
| 6222 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 6223 | |
| 6224 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6225 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6226 | |
| 6227 | // Start with a 0 size frame. |
| 6228 | *size = 0; |
| 6229 | |
| 6230 | // We need to update the gf_group for show_existing overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 6231 | 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] | 6232 | |
| 6233 | Pass2Encode(cpi, size, dest, frame_flags); |
| 6234 | |
| 6235 | if (cpi->b_calculate_psnr) generate_psnr_packet(cpi); |
| 6236 | |
| 6237 | #if CONFIG_INTERNAL_STATS |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6238 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6239 | #endif // CONFIG_INTERNAL_STATS |
| 6240 | |
| 6241 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6242 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6243 | |
| 6244 | cm->show_existing_frame = 0; |
| 6245 | return 0; |
| 6246 | } |
Sebastien Alaiwan | 365e644 | 2017-10-16 11:35:00 +0200 | [diff] [blame] | 6247 | #endif // !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6248 | |
| 6249 | // Should we encode an arf frame. |
| 6250 | arf_src_index = get_arf_src_index(cpi); |
| 6251 | if (arf_src_index) { |
| 6252 | for (i = 0; i <= arf_src_index; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6253 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6254 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 6255 | if (e == NULL) { |
| 6256 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6257 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6258 | arf_src_index = 0; |
| 6259 | flush = 1; |
| 6260 | break; |
| 6261 | } |
| 6262 | } |
| 6263 | } |
| 6264 | |
| 6265 | if (arf_src_index) { |
| 6266 | assert(arf_src_index <= rc->frames_to_key); |
| 6267 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6268 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6269 | cpi->alt_ref_source = source; |
| 6270 | |
| 6271 | if (oxcf->arnr_max_frames > 0) { |
Todd Nguyen | 302d097 | 2017-06-16 16:16:29 -0700 | [diff] [blame] | 6272 | // Produce the filtered ARF frame. |
| 6273 | #if CONFIG_BGSPRITE |
| 6274 | int bgsprite_ret = av1_background_sprite(cpi, arf_src_index); |
Todd Nguyen | 2fc2309 | 2017-07-11 12:00:36 -0700 | [diff] [blame] | 6275 | // Do temporal filter if bgsprite not generated. |
| 6276 | if (bgsprite_ret != 0) |
Todd Nguyen | 302d097 | 2017-06-16 16:16:29 -0700 | [diff] [blame] | 6277 | #endif // CONFIG_BGSPRITE |
Todd Nguyen | 8493f91 | 2017-07-20 12:45:12 -0700 | [diff] [blame] | 6278 | av1_temporal_filter(cpi, |
| 6279 | #if CONFIG_BGSPRITE |
Todd Nguyen | 1fd99c2 | 2017-07-31 17:50:41 -0700 | [diff] [blame] | 6280 | NULL, &cpi->alt_ref_buffer, |
Todd Nguyen | 8493f91 | 2017-07-20 12:45:12 -0700 | [diff] [blame] | 6281 | #endif // CONFIG_BGSPRITE |
| 6282 | arf_src_index); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6283 | aom_extend_frame_borders(&cpi->alt_ref_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6284 | force_src_buffer = &cpi->alt_ref_buffer; |
| 6285 | } |
| 6286 | |
| 6287 | cm->show_frame = 0; |
| 6288 | cm->intra_only = 0; |
| 6289 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6290 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6291 | cpi->refresh_golden_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6292 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6293 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6294 | rc->is_src_frame_alt_ref = 0; |
| 6295 | } |
| 6296 | rc->source_alt_ref_pending = 0; |
| 6297 | } |
| 6298 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6299 | // Should we encode an arf2 frame. |
| 6300 | arf_src_index = get_arf2_src_index(cpi); |
| 6301 | if (arf_src_index) { |
| 6302 | for (i = 0; i <= arf_src_index; ++i) { |
| 6303 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
| 6304 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 6305 | if (e == NULL) { |
| 6306 | break; |
| 6307 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
| 6308 | arf_src_index = 0; |
| 6309 | flush = 1; |
| 6310 | break; |
| 6311 | } |
| 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | if (arf_src_index) { |
| 6316 | assert(arf_src_index <= rc->frames_to_key); |
| 6317 | |
| 6318 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
| 6319 | cpi->alt_ref_source = source; |
| 6320 | |
| 6321 | if (oxcf->arnr_max_frames > 0) { |
| 6322 | // Produce the filtered ARF frame. |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 6323 | av1_temporal_filter(cpi, |
| 6324 | #if CONFIG_BGSPRITE |
| 6325 | NULL, NULL, |
| 6326 | #endif // CONFIG_BGSPRITE |
| 6327 | arf_src_index); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6328 | aom_extend_frame_borders(&cpi->alt_ref_buffer); |
| 6329 | force_src_buffer = &cpi->alt_ref_buffer; |
| 6330 | } |
| 6331 | |
| 6332 | cm->show_frame = 0; |
| 6333 | cm->intra_only = 0; |
| 6334 | cpi->refresh_alt2_ref_frame = 1; |
| 6335 | cpi->refresh_last_frame = 0; |
| 6336 | cpi->refresh_golden_frame = 0; |
| 6337 | cpi->refresh_bwd_ref_frame = 0; |
| 6338 | cpi->refresh_alt_ref_frame = 0; |
| 6339 | rc->is_src_frame_alt_ref = 0; |
| 6340 | rc->is_src_frame_ext_arf = 0; |
| 6341 | } |
| 6342 | rc->source_alt_ref_pending = 0; |
| 6343 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6344 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6345 | rc->is_bwd_ref_frame = 0; |
| 6346 | brf_src_index = get_brf_src_index(cpi); |
| 6347 | if (brf_src_index) { |
| 6348 | assert(brf_src_index <= rc->frames_to_key); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6349 | if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6350 | cm->show_frame = 0; |
| 6351 | cm->intra_only = 0; |
| 6352 | |
| 6353 | cpi->refresh_bwd_ref_frame = 1; |
| 6354 | cpi->refresh_last_frame = 0; |
| 6355 | cpi->refresh_golden_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6356 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6357 | cpi->refresh_alt_ref_frame = 0; |
| 6358 | |
| 6359 | rc->is_bwd_ref_frame = 1; |
| 6360 | } |
| 6361 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6362 | |
| 6363 | if (!source) { |
| 6364 | // Get last frame source. |
| 6365 | if (cm->current_video_frame > 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6366 | if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6367 | return -1; |
| 6368 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 6369 | if (cm->current_video_frame > 0) assert(last_source != NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6370 | // Read in the source frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6371 | source = av1_lookahead_pop(cpi->lookahead, flush); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6372 | |
| 6373 | if (source != NULL) { |
| 6374 | cm->show_frame = 1; |
| 6375 | cm->intra_only = 0; |
| 6376 | |
| 6377 | // Check to see if the frame should be encoded as an arf overlay. |
| 6378 | check_src_altref(cpi, source); |
| 6379 | } |
| 6380 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6381 | if (source) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 6382 | cpi->unscaled_source = cpi->source = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6383 | force_src_buffer ? force_src_buffer : &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6384 | cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL; |
| 6385 | |
| 6386 | *time_stamp = source->ts_start; |
| 6387 | *time_end = source->ts_end; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6388 | *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6389 | |
| 6390 | } else { |
| 6391 | *size = 0; |
| 6392 | if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6393 | #if CONFIG_XIPHRC |
| 6394 | od_enc_rc_2pass_out(&cpi->od_rc, cpi->output_pkt_list, 1); |
| 6395 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6396 | av1_end_first_pass(cpi); /* get last stats packet */ |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 6397 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6398 | cpi->twopass.first_pass_done = 1; |
| 6399 | } |
| 6400 | return -1; |
| 6401 | } |
| 6402 | |
| 6403 | if (source->ts_start < cpi->first_time_stamp_ever) { |
| 6404 | cpi->first_time_stamp_ever = source->ts_start; |
| 6405 | cpi->last_end_time_stamp_seen = source->ts_start; |
| 6406 | } |
| 6407 | |
| 6408 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6409 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6410 | |
| 6411 | // adjust frame rates based on timestamps given |
| 6412 | if (cm->show_frame) adjust_frame_rate(cpi, source); |
| 6413 | |
| 6414 | // Find a free buffer for the new frame, releasing the reference previously |
| 6415 | // held. |
| 6416 | if (cm->new_fb_idx != INVALID_IDX) { |
| 6417 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 6418 | } |
| 6419 | cm->new_fb_idx = get_free_fb(cm); |
| 6420 | |
| 6421 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 6422 | |
| 6423 | cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; |
Sebastien Alaiwan | 4879580 | 2017-10-30 12:07:13 +0100 | [diff] [blame] | 6424 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 6425 | cm->cur_frame->buf.buf_8bit_valid = 0; |
| 6426 | #endif |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 6427 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6428 | // Start with a 0 size frame. |
| 6429 | *size = 0; |
| 6430 | |
| 6431 | cpi->frame_flags = *frame_flags; |
| 6432 | |
| 6433 | if (oxcf->pass == 2) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6434 | #if CONFIG_XIPHRC |
| 6435 | if (od_enc_rc_2pass_in(&cpi->od_rc) < 0) return -1; |
| 6436 | } |
| 6437 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6438 | av1_rc_get_second_pass_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6439 | } else if (oxcf->pass == 1) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 6440 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6441 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6442 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6443 | |
| 6444 | if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) { |
| 6445 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) |
| 6446 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 6447 | } |
| 6448 | |
| 6449 | #if CONFIG_AOM_QM |
| 6450 | cm->using_qmatrix = cpi->oxcf.using_qm; |
| 6451 | cm->min_qmlevel = cpi->oxcf.qm_minlevel; |
| 6452 | cm->max_qmlevel = cpi->oxcf.qm_maxlevel; |
| 6453 | #endif |
| 6454 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6455 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 6456 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 6457 | if (*time_stamp == 0) { |
| 6458 | cpi->common.current_frame_id = -1; |
| 6459 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6460 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 6461 | #endif // CONFIG_REFERENCE_BUFFER |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6462 | #if CONFIG_AMVR |
| 6463 | cpi->cur_poc++; |
| 6464 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 6465 | if (cpi->common.seq_force_integer_mv == 2) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6466 | struct lookahead_entry *previous_entry = |
| 6467 | cpi->lookahead->buf + cpi->previsous_index; |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 6468 | cpi->common.cur_frame_force_integer_mv = is_integer_mv( |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6469 | cpi, cpi->source, &previous_entry->img, cpi->previsou_hash_table); |
| 6470 | } else { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 6471 | cpi->common.cur_frame_force_integer_mv = cpi->common.seq_force_integer_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6472 | } |
| 6473 | } else { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 6474 | cpi->common.cur_frame_force_integer_mv = 0; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6475 | } |
| 6476 | #endif |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6477 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6478 | #if CONFIG_XIPHRC |
| 6479 | if (oxcf->pass == 1) { |
| 6480 | size_t tmp; |
| 6481 | if (cpi->od_rc.cur_frame == 0) Pass0Encode(cpi, &tmp, dest, 1, frame_flags); |
| 6482 | cpi->od_rc.firstpass_quant = cpi->od_rc.target_quantizer; |
| 6483 | Pass0Encode(cpi, &tmp, dest, 0, frame_flags); |
| 6484 | od_enc_rc_2pass_out(&cpi->od_rc, cpi->output_pkt_list, 0); |
| 6485 | } else if (oxcf->pass == 2) { |
| 6486 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
| 6487 | } else { |
| 6488 | if (cpi->od_rc.cur_frame == 0) { |
| 6489 | size_t tmp; |
| 6490 | Pass0Encode(cpi, &tmp, dest, 1, frame_flags); |
| 6491 | } |
| 6492 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
| 6493 | } |
| 6494 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6495 | if (oxcf->pass == 1) { |
| 6496 | cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6497 | av1_first_pass(cpi, source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6498 | } else if (oxcf->pass == 2) { |
| 6499 | Pass2Encode(cpi, size, dest, frame_flags); |
| 6500 | } else { |
| 6501 | // One pass encode |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6502 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6503 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6504 | #endif |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 6505 | #if CONFIG_HASH_ME |
| 6506 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 6507 | #if CONFIG_AMVR |
| 6508 | cpi->previsou_hash_table = &cm->cur_frame->hash_table; |
| 6509 | { |
| 6510 | int l; |
| 6511 | for (l = -MAX_PRE_FRAMES; l < cpi->lookahead->max_sz; l++) { |
| 6512 | if ((cpi->lookahead->buf + l) == source) { |
| 6513 | cpi->previsous_index = l; |
| 6514 | break; |
| 6515 | } |
| 6516 | } |
| 6517 | |
| 6518 | if (l == cpi->lookahead->max_sz) { |
| 6519 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
| 6520 | "Failed to find last frame original buffer"); |
| 6521 | } |
| 6522 | } |
| 6523 | #endif |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 6524 | } |
| 6525 | |
| 6526 | #endif |
| 6527 | |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 6528 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 6529 | cm->frame_contexts[cm->new_fb_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 6530 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6531 | if (!cm->error_resilient_mode) |
| 6532 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 6533 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6534 | |
| 6535 | // No frame encoded, or frame was dropped, release scaled references. |
| 6536 | if ((*size == 0) && (frame_is_intra_only(cm) == 0)) { |
| 6537 | release_scaled_references(cpi); |
| 6538 | } |
| 6539 | |
| 6540 | if (*size > 0) { |
| 6541 | cpi->droppable = !frame_is_reference(cpi); |
| 6542 | } |
| 6543 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6544 | aom_usec_timer_mark(&cmptimer); |
| 6545 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6546 | |
| 6547 | if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame) |
| 6548 | generate_psnr_packet(cpi); |
| 6549 | |
| 6550 | #if CONFIG_INTERNAL_STATS |
| 6551 | if (oxcf->pass != 1) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6552 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6553 | } |
| 6554 | #endif // CONFIG_INTERNAL_STATS |
| 6555 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 6556 | #if CONFIG_XIPHRC |
| 6557 | cpi->od_rc.cur_frame++; |
| 6558 | #endif |
| 6559 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6560 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6561 | |
| 6562 | return 0; |
| 6563 | } |
| 6564 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6565 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 6566 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6567 | if (!cm->show_frame) { |
| 6568 | return -1; |
| 6569 | } else { |
| 6570 | int ret; |
| 6571 | if (cm->frame_to_show) { |
| 6572 | *dest = *cm->frame_to_show; |
| 6573 | dest->y_width = cm->width; |
| 6574 | dest->y_height = cm->height; |
| 6575 | dest->uv_width = cm->width >> cm->subsampling_x; |
| 6576 | dest->uv_height = cm->height >> cm->subsampling_y; |
| 6577 | ret = 0; |
| 6578 | } else { |
| 6579 | ret = -1; |
| 6580 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6581 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6582 | return ret; |
| 6583 | } |
| 6584 | } |
| 6585 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6586 | 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] | 6587 | if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1; |
| 6588 | |
| 6589 | *frame = |
| 6590 | cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf; |
| 6591 | return 0; |
| 6592 | } |
| 6593 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6594 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 6595 | AOM_SCALING vert_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6596 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 6597 | |
| 6598 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 6599 | |
| 6600 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 6601 | Scale2Ratio(vert_mode, &vr, &vs); |
| 6602 | |
| 6603 | // always go to the next whole number |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 6604 | cpi->resize_pending_width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 6605 | cpi->resize_pending_height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6606 | |
| 6607 | return 0; |
| 6608 | } |
| 6609 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6610 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6611 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6612 | 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] | 6613 | if (flags & |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6614 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF)) { |
| 6615 | int ref = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6616 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6617 | if (flags & AOM_EFLAG_NO_REF_LAST) { |
| 6618 | ref ^= AOM_LAST_FLAG; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6619 | ref ^= AOM_LAST2_FLAG; |
| 6620 | ref ^= AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6621 | } |
| 6622 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6623 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6624 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6625 | if (flags & AOM_EFLAG_NO_REF_ARF) ref ^= AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6626 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6627 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6628 | } |
| 6629 | |
| 6630 | if (flags & |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6631 | (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF | |
| 6632 | AOM_EFLAG_FORCE_GF | AOM_EFLAG_FORCE_ARF)) { |
| 6633 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6634 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6635 | if (flags & AOM_EFLAG_NO_UPD_LAST) { |
| 6636 | upd ^= AOM_LAST_FLAG; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6637 | upd ^= AOM_LAST2_FLAG; |
| 6638 | upd ^= AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6639 | } |
| 6640 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6641 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6642 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6643 | if (flags & AOM_EFLAG_NO_UPD_ARF) upd ^= AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6644 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6645 | av1_update_reference(cpi, upd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6646 | } |
| 6647 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6648 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 6649 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6650 | } |
| 6651 | } |