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 |
| 56 | #include "av1/encoder/ratectrl.h" |
| 57 | #include "av1/encoder/rd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 58 | #include "av1/encoder/segmentation.h" |
| 59 | #include "av1/encoder/speed_features.h" |
| 60 | #include "av1/encoder/temporal_filter.h" |
| 61 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 62 | #include "./av1_rtcd.h" |
| 63 | #include "./aom_dsp_rtcd.h" |
| 64 | #include "./aom_scale_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 65 | #include "aom_dsp/psnr.h" |
| 66 | #if CONFIG_INTERNAL_STATS |
| 67 | #include "aom_dsp/ssim.h" |
| 68 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 69 | #include "aom_dsp/aom_dsp_common.h" |
| 70 | #include "aom_dsp/aom_filter.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 71 | #include "aom_ports/aom_timer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 72 | #include "aom_ports/mem.h" |
| 73 | #include "aom_ports/system_state.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 74 | #include "aom_scale/aom_scale.h" |
Angie Chiang | 6062a8b | 2016-09-21 16:01:04 -0700 | [diff] [blame] | 75 | #if CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 76 | #include "aom_util/debug_util.h" |
Angie Chiang | 6062a8b | 2016-09-21 16:01:04 -0700 | [diff] [blame] | 77 | #endif // CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 78 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 79 | #if CONFIG_ENTROPY_STATS |
| 80 | FRAME_COUNTS aggregate_fc; |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 81 | // Aggregate frame counts per frame context type |
| 82 | FRAME_COUNTS aggregate_fc_per_type[FRAME_CONTEXTS]; |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 83 | #endif // CONFIG_ENTROPY_STATS |
| 84 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 85 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 86 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 87 | |
| 88 | #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ |
| 89 | |
| 90 | #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv |
| 91 | // for altref computation. |
| 92 | #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision |
| 93 | // mv. Choose a very high value for |
| 94 | // now so that HIGH_PRECISION is always |
| 95 | // chosen. |
| 96 | // #define OUTPUT_YUV_REC |
| 97 | #ifdef OUTPUT_YUV_DENOISED |
| 98 | FILE *yuv_denoised_file = NULL; |
| 99 | #endif |
| 100 | #ifdef OUTPUT_YUV_SKINMAP |
| 101 | FILE *yuv_skinmap_file = NULL; |
| 102 | #endif |
| 103 | #ifdef OUTPUT_YUV_REC |
| 104 | FILE *yuv_rec_file; |
| 105 | #define FILE_NAME_LEN 100 |
| 106 | #endif |
| 107 | |
| 108 | #if 0 |
| 109 | FILE *framepsnr; |
| 110 | FILE *kf_list; |
| 111 | FILE *keyfile; |
| 112 | #endif |
| 113 | |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 114 | #if CONFIG_CFL |
| 115 | CFL_CTX NULL_CFL; |
| 116 | #endif |
| 117 | |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 118 | #if CONFIG_INTERNAL_STATS |
| 119 | typedef enum { Y, U, V, ALL } STAT_TYPE; |
| 120 | #endif // CONFIG_INTERNAL_STATS |
| 121 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 122 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 123 | switch (mode) { |
| 124 | case NORMAL: |
| 125 | *hr = 1; |
| 126 | *hs = 1; |
| 127 | break; |
| 128 | case FOURFIVE: |
| 129 | *hr = 4; |
| 130 | *hs = 5; |
| 131 | break; |
| 132 | case THREEFIVE: |
| 133 | *hr = 3; |
| 134 | *hs = 5; |
| 135 | break; |
| 136 | case ONETWO: |
| 137 | *hr = 1; |
| 138 | *hs = 2; |
| 139 | break; |
| 140 | default: |
| 141 | *hr = 1; |
| 142 | *hs = 1; |
| 143 | assert(0); |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 149 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 150 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 151 | unsigned char *const seg_map = cpi->segmentation_map; |
| 152 | int i; |
| 153 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 154 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 155 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 156 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 157 | } |
| 158 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 159 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 160 | struct segmentation *const seg = &cpi->common.seg; |
| 161 | unsigned char *const seg_map = cpi->segmentation_map; |
| 162 | const unsigned char *const active_map = cpi->active_map.map; |
| 163 | int i; |
| 164 | |
| 165 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 166 | |
| 167 | if (frame_is_intra_only(&cpi->common)) { |
| 168 | cpi->active_map.enabled = 0; |
| 169 | cpi->active_map.update = 1; |
| 170 | } |
| 171 | |
| 172 | if (cpi->active_map.update) { |
| 173 | if (cpi->active_map.enabled) { |
| 174 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 175 | 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] | 176 | av1_enable_segmentation(seg); |
| 177 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
| 178 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 179 | // Setting the data to -MAX_LOOP_FILTER will result in the computed loop |
| 180 | // filter level being zero regardless of the value of seg->abs_delta. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 181 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF, |
| 182 | -MAX_LOOP_FILTER); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 183 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 184 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
| 185 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 186 | if (seg->enabled) { |
| 187 | seg->update_data = 1; |
| 188 | seg->update_map = 1; |
| 189 | } |
| 190 | } |
| 191 | cpi->active_map.update = 0; |
| 192 | } |
| 193 | } |
| 194 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 195 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 196 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 197 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 198 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 199 | const int mi_rows = cpi->common.mi_rows; |
| 200 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 201 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 202 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 203 | cpi->active_map.update = 1; |
| 204 | if (new_map_16x16) { |
| 205 | int r, c; |
| 206 | for (r = 0; r < mi_rows; ++r) { |
| 207 | for (c = 0; c < mi_cols; ++c) { |
| 208 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 209 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 210 | ? AM_SEGMENT_ID_ACTIVE |
| 211 | : AM_SEGMENT_ID_INACTIVE; |
| 212 | } |
| 213 | } |
| 214 | cpi->active_map.enabled = 1; |
| 215 | } else { |
| 216 | cpi->active_map.enabled = 0; |
| 217 | } |
| 218 | return 0; |
| 219 | } else { |
| 220 | return -1; |
| 221 | } |
| 222 | } |
| 223 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 224 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 225 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 226 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 227 | new_map_16x16) { |
| 228 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 229 | const int mi_rows = cpi->common.mi_rows; |
| 230 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 231 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 232 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 233 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 234 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 235 | if (cpi->active_map.enabled) { |
| 236 | int r, c; |
| 237 | for (r = 0; r < mi_rows; ++r) { |
| 238 | for (c = 0; c < mi_cols; ++c) { |
| 239 | // Cyclic refresh segments are considered active despite not having |
| 240 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 241 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 242 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | return 0; |
| 247 | } else { |
| 248 | return -1; |
| 249 | } |
| 250 | } |
| 251 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 252 | void av1_set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 253 | MACROBLOCK *const mb = &cpi->td.mb; |
| 254 | cpi->common.allow_high_precision_mv = allow_high_precision_mv; |
| 255 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 256 | if (cpi->common.allow_high_precision_mv) { |
| 257 | int i; |
| 258 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 259 | mb->mv_cost_stack[i] = mb->nmvcost_hp[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 260 | } |
| 261 | } else { |
| 262 | int i; |
| 263 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 264 | mb->mv_cost_stack[i] = mb->nmvcost[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 265 | } |
| 266 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 269 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 270 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 271 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 272 | return BLOCK_64X64; |
| 273 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 274 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 275 | return BLOCK_128X128; |
| 276 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 277 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 278 | |
| 279 | assert(IMPLIES(cpi->common.tile_cols > 1, |
| 280 | cpi->common.tile_width % MAX_MIB_SIZE == 0)); |
| 281 | assert(IMPLIES(cpi->common.tile_rows > 1, |
| 282 | cpi->common.tile_height % MAX_MIB_SIZE == 0)); |
| 283 | |
| 284 | // TODO(any): Possibly could improve this with a heuristic. |
| 285 | return BLOCK_128X128; |
| 286 | #else |
| 287 | (void)cpi; |
| 288 | return BLOCK_64X64; |
| 289 | #endif // CONFIG_EXT_PARTITION |
| 290 | } |
| 291 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 292 | static void setup_frame(AV1_COMP *cpi) { |
| 293 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 294 | // Set up entropy context depending on frame type. The decoder mandates |
| 295 | // the use of the default context, index 0, for keyframes and inter |
| 296 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 297 | // other inter-frames the encoder currently uses only two contexts; |
| 298 | // context 1 for ALTREF frames and context 0 for the others. |
| 299 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 300 | av1_setup_past_independence(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 301 | } else { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 302 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 303 | // Just use frame context from first signaled reference frame. |
| 304 | // This will always be LAST_FRAME for now. |
| 305 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 306 | #if CONFIG_EXT_REFS |
| 307 | const GF_GROUP *gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 308 | #if CONFIG_ALTREF2 |
| 309 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) |
| 310 | #else // !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 311 | if (gf_group->rf_level[gf_group->index] == GF_ARF_LOW) |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 312 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 313 | cm->frame_context_idx = EXT_ARF_FRAME; |
| 314 | else if (cpi->refresh_alt_ref_frame) |
| 315 | cm->frame_context_idx = ARF_FRAME; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 316 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 317 | if (cpi->refresh_alt_ref_frame) cm->frame_context_idx = ARF_FRAME; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 318 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 319 | else if (cpi->rc.is_src_frame_alt_ref) |
| 320 | cm->frame_context_idx = OVERLAY_FRAME; |
| 321 | else if (cpi->refresh_golden_frame) |
| 322 | cm->frame_context_idx = GLD_FRAME; |
| 323 | #if CONFIG_EXT_REFS |
| 324 | else if (cpi->refresh_bwd_ref_frame) |
| 325 | cm->frame_context_idx = BRF_FRAME; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 326 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 327 | else |
| 328 | cm->frame_context_idx = REGULAR_FRAME; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 329 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | if (cm->frame_type == KEY_FRAME) { |
| 333 | cpi->refresh_golden_frame = 1; |
| 334 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 335 | av1_zero(cpi->interp_filter_selected); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 336 | } else { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 337 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 338 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
| 339 | cm->frame_refs[0].idx < 0) { |
| 340 | *cm->fc = cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 341 | } else { |
| 342 | *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx]; |
| 343 | } |
| 344 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 345 | *cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 346 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 347 | av1_zero(cpi->interp_filter_selected[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 348 | } |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 349 | #if CONFIG_EXT_REFS |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 350 | #if CONFIG_ONE_SIDED_COMPOUND && \ |
| 351 | !CONFIG_EXT_COMP_REFS // No change to bitstream |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 352 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 353 | cpi->refresh_bwd_ref_frame = cpi->refresh_last_frame; |
| 354 | cpi->rc.is_bipred_frame = 1; |
| 355 | } |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 356 | #endif // CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
| 357 | #endif // CONFIG_EXT_REFS |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 358 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 359 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
| 360 | cm->frame_refs[0].idx < 0) { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 361 | // use default frame context values |
| 362 | cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 363 | } else { |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 364 | *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 365 | cm->pre_fc = &cm->frame_contexts[cm->frame_refs[0].idx]; |
| 366 | } |
| 367 | #else |
Thomas Daede | 10e1da9 | 2017-04-26 13:22:21 -0700 | [diff] [blame] | 368 | cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 369 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 370 | |
| 371 | cpi->vaq_refresh = 0; |
| 372 | |
| 373 | set_sb_size(cm, select_sb_size(cpi)); |
| 374 | } |
| 375 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 376 | static void av1_enc_setup_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 377 | int i; |
| 378 | cm->mi = cm->mip + cm->mi_stride + 1; |
| 379 | memset(cm->mip, 0, cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip)); |
| 380 | cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 381 | // Clear top border row |
| 382 | memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride); |
| 383 | // Clear left border column |
| 384 | for (i = 1; i < cm->mi_rows + 1; ++i) |
| 385 | 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] | 386 | cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; |
| 387 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; |
| 388 | |
| 389 | memset(cm->mi_grid_base, 0, |
| 390 | cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mi_grid_base)); |
| 391 | } |
| 392 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 393 | static int av1_enc_alloc_mi(AV1_COMMON *cm, int mi_size) { |
| 394 | cm->mip = aom_calloc(mi_size, sizeof(*cm->mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 395 | if (!cm->mip) return 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 396 | cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 397 | if (!cm->prev_mip) return 1; |
| 398 | cm->mi_alloc_size = mi_size; |
| 399 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 400 | 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] | 401 | if (!cm->mi_grid_base) return 1; |
| 402 | cm->prev_mi_grid_base = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 403 | (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 404 | if (!cm->prev_mi_grid_base) return 1; |
| 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 409 | static void av1_enc_free_mi(AV1_COMMON *cm) { |
| 410 | aom_free(cm->mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 411 | cm->mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 412 | aom_free(cm->prev_mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 413 | cm->prev_mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 414 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 415 | cm->mi_grid_base = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 416 | aom_free(cm->prev_mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 417 | cm->prev_mi_grid_base = NULL; |
| 418 | } |
| 419 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 420 | static void av1_swap_mi_and_prev_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 421 | // Current mip will be the prev_mip for the next frame. |
| 422 | MODE_INFO **temp_base = cm->prev_mi_grid_base; |
| 423 | MODE_INFO *temp = cm->prev_mip; |
| 424 | cm->prev_mip = cm->mip; |
| 425 | cm->mip = temp; |
| 426 | |
| 427 | // Update the upper left visible macroblock ptrs. |
| 428 | cm->mi = cm->mip + cm->mi_stride + 1; |
| 429 | cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 430 | |
| 431 | cm->prev_mi_grid_base = cm->mi_grid_base; |
| 432 | cm->mi_grid_base = temp_base; |
| 433 | cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; |
| 434 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; |
| 435 | } |
| 436 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 437 | void av1_initialize_enc(void) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 438 | static volatile int init_done = 0; |
| 439 | |
| 440 | if (!init_done) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 441 | av1_rtcd(); |
| 442 | aom_dsp_rtcd(); |
| 443 | aom_scale_rtcd(); |
| 444 | av1_init_intra_predictors(); |
| 445 | av1_init_me_luts(); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 446 | #if !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 447 | av1_rc_init_minq_luts(); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 448 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 449 | av1_entropy_mv_init(); |
| 450 | av1_encode_token_init(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 451 | #if CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 452 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 453 | #endif |
| 454 | init_done = 1; |
| 455 | } |
| 456 | } |
| 457 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 458 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 459 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 460 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 461 | aom_free(cpi->mbmi_ext_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 462 | cpi->mbmi_ext_base = NULL; |
| 463 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 464 | #if CONFIG_PVQ |
| 465 | if (cpi->oxcf.pass != 1) { |
Yushin Cho | 749c057 | 2017-04-07 10:36:47 -0700 | [diff] [blame] | 466 | const int tile_cols = cm->tile_cols; |
| 467 | const int tile_rows = cm->tile_rows; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 468 | int tile_col, tile_row; |
| 469 | |
| 470 | for (tile_row = 0; tile_row < tile_rows; ++tile_row) |
| 471 | for (tile_col = 0; tile_col < tile_cols; ++tile_col) { |
| 472 | TileDataEnc *tile_data = |
| 473 | &cpi->tile_data[tile_row * tile_cols + tile_col]; |
| 474 | aom_free(tile_data->pvq_q.buf); |
| 475 | } |
| 476 | } |
| 477 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 478 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 479 | cpi->tile_data = NULL; |
| 480 | |
| 481 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 482 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 483 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 484 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 485 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 486 | cpi->cyclic_refresh = NULL; |
| 487 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 488 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 489 | cpi->active_map.map = NULL; |
| 490 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 491 | #if CONFIG_MOTION_VAR |
| 492 | aom_free(cpi->td.mb.above_pred_buf); |
| 493 | cpi->td.mb.above_pred_buf = NULL; |
| 494 | |
| 495 | aom_free(cpi->td.mb.left_pred_buf); |
| 496 | cpi->td.mb.left_pred_buf = NULL; |
| 497 | |
| 498 | aom_free(cpi->td.mb.wsrc_buf); |
| 499 | cpi->td.mb.wsrc_buf = NULL; |
| 500 | |
| 501 | aom_free(cpi->td.mb.mask_buf); |
| 502 | cpi->td.mb.mask_buf = NULL; |
| 503 | #endif |
| 504 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 505 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 506 | #if CONFIG_LV_MAP |
| 507 | av1_free_txb_buf(cpi); |
| 508 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 509 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 510 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 511 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 512 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 513 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 514 | aom_free_frame_buffer(&cpi->last_frame_db); |
| 515 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
| 516 | aom_free(cpi->extra_rstbuf); |
Timothy B. Terriberry | 5d24b6f | 2017-06-15 13:39:35 -0700 | [diff] [blame] | 517 | { |
| 518 | int i; |
| 519 | for (i = 0; i < MAX_MB_PLANE; ++i) |
| 520 | av1_free_restoration_struct(&cpi->rst_search[i]); |
| 521 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 522 | #endif // CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 523 | aom_free_frame_buffer(&cpi->scaled_source); |
| 524 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 525 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 526 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 527 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 528 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 529 | cpi->tile_tok[0][0] = 0; |
| 530 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 531 | av1_free_pc_tree(&cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 532 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 533 | aom_free(cpi->td.mb.palette_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 534 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 535 | #if CONFIG_ANS |
Alex Converse | 1ac1ae7 | 2016-09-17 15:11:16 -0700 | [diff] [blame] | 536 | aom_buf_ans_free(&cpi->buf_ans); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 537 | #endif // CONFIG_ANS |
| 538 | } |
| 539 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 540 | static void save_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 541 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 542 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 543 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 544 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 545 | // Stores a snapshot of key state variables which can subsequently be |
| 546 | // restored with a call to av1_restore_coding_context. These functions are |
| 547 | // intended for use in a re-code loop in av1_compress_frame where the |
| 548 | // quantizer value is adjusted between loop iterations. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 549 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 550 | av1_copy(cc->nmv_vec_cost[i], cpi->td.mb.nmv_vec_cost[i]); |
Urvang Joshi | bffc0b5 | 2016-07-25 13:38:49 -0700 | [diff] [blame] | 551 | av1_copy(cc->nmv_costs, cpi->nmv_costs); |
| 552 | av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 553 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 554 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 555 | av1_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); |
| 556 | av1_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 557 | |
| 558 | cc->fc = *cm->fc; |
| 559 | } |
| 560 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 561 | static void restore_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 562 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 563 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 564 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 565 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 566 | // Restore key state variables to the snapshot state stored in the |
| 567 | // previous call to av1_save_coding_context. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 568 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 569 | av1_copy(cpi->td.mb.nmv_vec_cost[i], cc->nmv_vec_cost[i]); |
Urvang Joshi | bffc0b5 | 2016-07-25 13:38:49 -0700 | [diff] [blame] | 570 | av1_copy(cpi->nmv_costs, cc->nmv_costs); |
| 571 | av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 572 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 573 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 574 | av1_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); |
| 575 | av1_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 576 | |
| 577 | *cm->fc = cc->fc; |
| 578 | } |
| 579 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 580 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 581 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 582 | const RATE_CONTROL *const rc = &cpi->rc; |
| 583 | struct segmentation *const seg = &cm->seg; |
| 584 | |
| 585 | int high_q = (int)(rc->avg_q > 48.0); |
| 586 | int qi_delta; |
| 587 | |
| 588 | // Disable and clear down for KF |
| 589 | if (cm->frame_type == KEY_FRAME) { |
| 590 | // Clear down the global segmentation map |
| 591 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 592 | seg->update_map = 0; |
| 593 | seg->update_data = 0; |
| 594 | cpi->static_mb_pct = 0; |
| 595 | |
| 596 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 597 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 598 | |
| 599 | // Clear down the segment features. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 600 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 601 | } else if (cpi->refresh_alt_ref_frame) { |
| 602 | // If this is an alt ref frame |
| 603 | // Clear down the global segmentation map |
| 604 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 605 | seg->update_map = 0; |
| 606 | seg->update_data = 0; |
| 607 | cpi->static_mb_pct = 0; |
| 608 | |
| 609 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 610 | av1_disable_segmentation(seg); |
| 611 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 612 | |
| 613 | // Scan frames from current to arf frame. |
| 614 | // This function re-enables segmentation if appropriate. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 615 | av1_update_mbgraph_stats(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 616 | |
| 617 | // If segmentation was enabled set those features needed for the |
| 618 | // arf itself. |
| 619 | if (seg->enabled) { |
| 620 | seg->update_map = 1; |
| 621 | seg->update_data = 1; |
| 622 | |
| 623 | qi_delta = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 624 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, cm->bit_depth); |
| 625 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
| 626 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 627 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 628 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
| 629 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 630 | |
| 631 | // Where relevant assume segment data is delta data |
| 632 | seg->abs_delta = SEGMENT_DELTADATA; |
| 633 | } |
| 634 | } else if (seg->enabled) { |
| 635 | // All other frames if segmentation has been enabled |
| 636 | |
| 637 | // First normal frame in a valid gf or alt ref group |
| 638 | if (rc->frames_since_golden == 0) { |
| 639 | // Set up segment features for normal frames in an arf group |
| 640 | if (rc->source_alt_ref_active) { |
| 641 | seg->update_map = 0; |
| 642 | seg->update_data = 1; |
| 643 | seg->abs_delta = SEGMENT_DELTADATA; |
| 644 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 645 | qi_delta = |
| 646 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, cm->bit_depth); |
| 647 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 648 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 649 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 650 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
| 651 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 652 | |
| 653 | // Segment coding disabled for compred testing |
| 654 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 655 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 656 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 657 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 658 | } |
| 659 | } else { |
| 660 | // Disable segmentation and clear down features if alt ref |
| 661 | // is not active for this group |
| 662 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 663 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 664 | |
| 665 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 666 | |
| 667 | seg->update_map = 0; |
| 668 | seg->update_data = 0; |
| 669 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 670 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 671 | } |
| 672 | } else if (rc->is_src_frame_alt_ref) { |
| 673 | // Special case where we are coding over the top of a previous |
| 674 | // alt ref frame. |
| 675 | // Segment coding disabled for compred testing |
| 676 | |
| 677 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 678 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 679 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 680 | |
| 681 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 682 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 683 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 684 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 685 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 686 | |
| 687 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 688 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 689 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 690 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 691 | } |
| 692 | // Enable data update |
| 693 | seg->update_data = 1; |
| 694 | } else { |
| 695 | // All other frames. |
| 696 | |
| 697 | // No updates.. leave things as they are. |
| 698 | seg->update_map = 0; |
| 699 | seg->update_data = 0; |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 704 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 705 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 706 | MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible; |
| 707 | uint8_t *cache_ptr = cm->last_frame_seg_map; |
| 708 | int row, col; |
| 709 | |
| 710 | for (row = 0; row < cm->mi_rows; row++) { |
| 711 | MODE_INFO **mi_8x8 = mi_8x8_ptr; |
| 712 | uint8_t *cache = cache_ptr; |
| 713 | for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) |
| 714 | cache[0] = mi_8x8[0]->mbmi.segment_id; |
| 715 | mi_8x8_ptr += cm->mi_stride; |
| 716 | cache_ptr += cm->mi_cols; |
| 717 | } |
| 718 | } |
| 719 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 720 | static void alloc_raw_frame_buffers(AV1_COMP *cpi) { |
| 721 | AV1_COMMON *cm = &cpi->common; |
| 722 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 723 | |
| 724 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 725 | cpi->lookahead = av1_lookahead_init(oxcf->width, oxcf->height, |
| 726 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 727 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 728 | cm->use_highbitdepth, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 729 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 730 | oxcf->lag_in_frames); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 731 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 732 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 733 | "Failed to allocate lag buffers"); |
| 734 | |
| 735 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 736 | 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] | 737 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 738 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 739 | cm->use_highbitdepth, |
| 740 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 741 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 742 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 743 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 744 | "Failed to allocate altref buffer"); |
| 745 | } |
| 746 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 747 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 748 | AV1_COMMON *const cm = &cpi->common; |
| 749 | 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] | 750 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 751 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 752 | cm->use_highbitdepth, |
| 753 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 754 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 755 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 756 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 757 | "Failed to allocate last frame buffer"); |
| 758 | |
| 759 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 760 | if (aom_realloc_frame_buffer(&cpi->last_frame_db, cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 761 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 762 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 763 | cm->use_highbitdepth, |
| 764 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 765 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 766 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 767 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 768 | "Failed to allocate last frame deblocked buffer"); |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 769 | if (aom_realloc_frame_buffer( |
| 770 | &cpi->trial_frame_rst, |
| 771 | #if CONFIG_FRAME_SUPERRES |
| 772 | cm->superres_upscaled_width, cm->superres_upscaled_height, |
| 773 | #else |
| 774 | cm->width, cm->height, |
| 775 | #endif // CONFIG_FRAME_SUPERRES |
| 776 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 777 | #if CONFIG_HIGHBITDEPTH |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 778 | cm->use_highbitdepth, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 779 | #endif |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 780 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 781 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 782 | "Failed to allocate trial restored frame buffer"); |
Alex Converse | 232e384 | 2017-02-24 12:24:36 -0800 | [diff] [blame] | 783 | int extra_rstbuf_sz = RESTORATION_EXTBUF_SIZE; |
Debargha Mukherjee | b3c43bc | 2017-02-01 13:09:03 -0800 | [diff] [blame] | 784 | if (extra_rstbuf_sz > 0) { |
Alex Converse | 7f094f1 | 2017-02-23 17:29:40 -0800 | [diff] [blame] | 785 | aom_free(cpi->extra_rstbuf); |
Alex Converse | 232e384 | 2017-02-24 12:24:36 -0800 | [diff] [blame] | 786 | CHECK_MEM_ERROR(cm, cpi->extra_rstbuf, |
Alex Converse | 7f094f1 | 2017-02-23 17:29:40 -0800 | [diff] [blame] | 787 | (uint8_t *)aom_malloc(extra_rstbuf_sz)); |
Debargha Mukherjee | b3c43bc | 2017-02-01 13:09:03 -0800 | [diff] [blame] | 788 | } else { |
| 789 | cpi->extra_rstbuf = NULL; |
| 790 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 791 | #endif // CONFIG_LOOP_RESTORATION |
| 792 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 793 | if (aom_realloc_frame_buffer(&cpi->scaled_source, 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 scaled source buffer"); |
| 802 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 803 | 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] | 804 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 805 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 806 | cm->use_highbitdepth, |
| 807 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 808 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 809 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 810 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 811 | "Failed to allocate scaled last source buffer"); |
| 812 | } |
| 813 | |
Yunqing Wang | f5dc71e | 2017-05-04 18:20:17 -0700 | [diff] [blame] | 814 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 815 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 816 | int mi_size = cm->mi_cols * cm->mi_rows; |
| 817 | |
Yunqing Wang | f5dc71e | 2017-05-04 18:20:17 -0700 | [diff] [blame] | 818 | CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, |
| 819 | aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 822 | void av1_alloc_compressor_data(AV1_COMP *cpi) { |
| 823 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 824 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 825 | av1_alloc_context_buffers(cm, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 826 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 827 | #if CONFIG_LV_MAP |
| 828 | av1_alloc_txb_buf(cpi); |
| 829 | #endif |
| 830 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 831 | alloc_context_buffers_ext(cpi); |
| 832 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 833 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 834 | |
| 835 | { |
| 836 | unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols); |
| 837 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 838 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 841 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 844 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 845 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 846 | #if CONFIG_XIPHRC |
| 847 | if (!cpi->od_rc.cur_frame) return; |
| 848 | cpi->od_rc.framerate = cpi->framerate; |
| 849 | od_enc_rc_resize(&cpi->od_rc); |
| 850 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 851 | av1_rc_update_framerate(cpi); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 852 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 855 | static void set_tile_info(AV1_COMP *cpi) { |
| 856 | AV1_COMMON *const cm = &cpi->common; |
Thomas Davies | b25ba50 | 2017-07-18 10:18:24 +0100 | [diff] [blame] | 857 | #if CONFIG_DEPENDENT_HORZTILES |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 858 | int tile_row, tile_col, num_tiles_in_tg; |
| 859 | int tg_row_start, tg_col_start; |
| 860 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 861 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 862 | if (cpi->oxcf.large_scale_tile) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 863 | #if CONFIG_EXT_PARTITION |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 864 | if (cpi->oxcf.superblock_size != AOM_SUPERBLOCK_SIZE_64X64) { |
| 865 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 32); |
| 866 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 32); |
| 867 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 868 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
| 869 | } else { |
| 870 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 871 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
| 872 | cm->tile_width <<= MAX_MIB_SIZE_LOG2 - 1; |
| 873 | cm->tile_height <<= MAX_MIB_SIZE_LOG2 - 1; |
| 874 | } |
| 875 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 876 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 877 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 878 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 879 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 880 | #endif // CONFIG_EXT_PARTITION |
| 881 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 882 | cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols); |
| 883 | cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 884 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 885 | assert(cm->tile_width >> MAX_MIB_SIZE <= 32); |
| 886 | assert(cm->tile_height >> MAX_MIB_SIZE <= 32); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 887 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 888 | // Get the number of tiles |
| 889 | cm->tile_cols = 1; |
| 890 | 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] | 891 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 892 | cm->tile_rows = 1; |
| 893 | while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows; |
| 894 | } else { |
| 895 | #endif // CONFIG_EXT_TILE |
| 896 | int min_log2_tile_cols, max_log2_tile_cols; |
| 897 | 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] | 898 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 899 | cm->log2_tile_cols = |
| 900 | clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols); |
| 901 | cm->log2_tile_rows = cpi->oxcf.tile_rows; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 902 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 903 | cm->tile_cols = 1 << cm->log2_tile_cols; |
| 904 | cm->tile_rows = 1 << cm->log2_tile_rows; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 905 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 906 | cm->tile_width = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); |
| 907 | cm->tile_width >>= cm->log2_tile_cols; |
| 908 | cm->tile_height = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); |
| 909 | cm->tile_height >>= cm->log2_tile_rows; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 910 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 911 | // round to integer multiples of max superblock size |
| 912 | cm->tile_width = ALIGN_POWER_OF_TWO(cm->tile_width, MAX_MIB_SIZE_LOG2); |
| 913 | cm->tile_height = ALIGN_POWER_OF_TWO(cm->tile_height, MAX_MIB_SIZE_LOG2); |
| 914 | #if CONFIG_EXT_TILE |
| 915 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 916 | #endif // CONFIG_EXT_TILE |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 917 | |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 918 | #if CONFIG_DEPENDENT_HORZTILES |
| 919 | cm->dependent_horz_tiles = cpi->oxcf.dependent_horz_tiles; |
Fangwen Fu | 70bcb89 | 2017-05-06 17:05:19 -0700 | [diff] [blame] | 920 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 921 | if (cm->large_scale_tile) { |
| 922 | // May not needed since cpi->oxcf.dependent_horz_tiles is already adjusted. |
| 923 | cm->dependent_horz_tiles = 0; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 924 | } else { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 925 | #endif // CONFIG_EXT_TILE |
| 926 | if (cm->log2_tile_rows == 0) cm->dependent_horz_tiles = 0; |
| 927 | #if CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 928 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 929 | #endif // CONFIG_EXT_TILE |
| 930 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 931 | #if CONFIG_EXT_TILE |
| 932 | if (!cm->large_scale_tile) { |
| 933 | #endif // CONFIG_EXT_TILE |
| 934 | if (cpi->oxcf.mtu == 0) { |
| 935 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 936 | } else { |
| 937 | // Use a default value for the purposes of weighting costs in probability |
| 938 | // updates |
| 939 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 940 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 941 | num_tiles_in_tg = |
| 942 | (cm->tile_cols * cm->tile_rows + cm->num_tg - 1) / cm->num_tg; |
| 943 | tg_row_start = 0; |
| 944 | tg_col_start = 0; |
| 945 | for (tile_row = 0; tile_row < cm->tile_rows; ++tile_row) { |
| 946 | for (tile_col = 0; tile_col < cm->tile_cols; ++tile_col) { |
| 947 | if ((tile_row * cm->tile_cols + tile_col) % num_tiles_in_tg == 0) { |
| 948 | tg_row_start = tile_row; |
| 949 | tg_col_start = tile_col; |
| 950 | } |
| 951 | cm->tile_group_start_row[tile_row][tile_col] = tg_row_start; |
| 952 | cm->tile_group_start_col[tile_row][tile_col] = tg_col_start; |
| 953 | } |
| 954 | } |
| 955 | #if CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 956 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 957 | #endif // CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 958 | #endif |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 959 | |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 960 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 961 | cm->loop_filter_across_tiles_enabled = |
| 962 | cpi->oxcf.loop_filter_across_tiles_enabled; |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 963 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 966 | static void update_frame_size(AV1_COMP *cpi) { |
| 967 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 968 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 969 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 970 | av1_set_mb_mi(cm, cm->width, cm->height); |
| 971 | av1_init_context_buffers(cm); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 972 | av1_init_macroblockd(cm, xd, |
| 973 | #if CONFIG_PVQ |
| 974 | NULL, |
| 975 | #endif |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 976 | #if CONFIG_CFL |
| 977 | &NULL_CFL, |
| 978 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 979 | NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 980 | memset(cpi->mbmi_ext_base, 0, |
| 981 | cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
| 982 | |
| 983 | set_tile_info(cpi); |
| 984 | } |
| 985 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 986 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 987 | #if CONFIG_EXT_REFS |
| 988 | int fb_idx; |
| 989 | for (fb_idx = 0; fb_idx < LAST_REF_FRAMES; ++fb_idx) |
| 990 | cpi->lst_fb_idxes[fb_idx] = fb_idx; |
| 991 | cpi->gld_fb_idx = LAST_REF_FRAMES; |
| 992 | cpi->bwd_fb_idx = LAST_REF_FRAMES + 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 993 | #if CONFIG_ALTREF2 |
| 994 | cpi->alt2_fb_idx = LAST_REF_FRAMES + 2; |
| 995 | cpi->alt_fb_idx = LAST_REF_FRAMES + 3; |
| 996 | #else // !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 997 | cpi->alt_fb_idx = LAST_REF_FRAMES + 2; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 998 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 999 | for (fb_idx = 0; fb_idx < MAX_EXT_ARFS + 1; ++fb_idx) |
| 1000 | cpi->arf_map[fb_idx] = LAST_REF_FRAMES + 2 + fb_idx; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 1001 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1002 | cpi->lst_fb_idx = 0; |
| 1003 | cpi->gld_fb_idx = 1; |
| 1004 | cpi->alt_fb_idx = 2; |
| 1005 | #endif // CONFIG_EXT_REFS |
| 1006 | } |
| 1007 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1008 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 1009 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1010 | |
| 1011 | cpi->oxcf = *oxcf; |
| 1012 | cpi->framerate = oxcf->init_framerate; |
| 1013 | |
| 1014 | cm->profile = oxcf->profile; |
| 1015 | cm->bit_depth = oxcf->bit_depth; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1016 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1017 | cm->use_highbitdepth = oxcf->use_highbitdepth; |
| 1018 | #endif |
| 1019 | cm->color_space = oxcf->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 1020 | #if CONFIG_COLORSPACE_HEADERS |
| 1021 | cm->transfer_function = oxcf->transfer_function; |
| 1022 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
| 1023 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1024 | cm->color_range = oxcf->color_range; |
| 1025 | |
| 1026 | cm->width = oxcf->width; |
| 1027 | cm->height = oxcf->height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1028 | av1_alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1029 | |
| 1030 | // Single thread case: use counts in common. |
| 1031 | cpi->td.counts = &cm->counts; |
| 1032 | |
| 1033 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1034 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1035 | |
| 1036 | cpi->static_mb_pct = 0; |
| 1037 | cpi->ref_frame_flags = 0; |
| 1038 | |
| 1039 | init_buffer_indices(cpi); |
| 1040 | } |
| 1041 | |
| 1042 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1043 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1044 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 1045 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 1046 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 1047 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 1048 | |
| 1049 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 1050 | rc->optimal_buffer_level = |
| 1051 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1052 | rc->maximum_buffer_size = |
| 1053 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1054 | } |
| 1055 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1056 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1057 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 1058 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1059 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1060 | cpi->fn_ptr[BT].vf = VF; \ |
| 1061 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1062 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1063 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 1064 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 1065 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
| 1066 | |
| 1067 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1068 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1069 | int source_stride, \ |
| 1070 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1071 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1072 | } \ |
| 1073 | static unsigned int fnname##_bits10( \ |
| 1074 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1075 | int ref_stride) { \ |
| 1076 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1077 | } \ |
| 1078 | static unsigned int fnname##_bits12( \ |
| 1079 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1080 | int ref_stride) { \ |
| 1081 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1082 | } |
| 1083 | |
| 1084 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1085 | static unsigned int fnname##_bits8( \ |
| 1086 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1087 | int ref_stride, const uint8_t *second_pred) { \ |
| 1088 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1089 | } \ |
| 1090 | static unsigned int fnname##_bits10( \ |
| 1091 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1092 | int ref_stride, const uint8_t *second_pred) { \ |
| 1093 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1094 | 2; \ |
| 1095 | } \ |
| 1096 | static unsigned int fnname##_bits12( \ |
| 1097 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1098 | int ref_stride, const uint8_t *second_pred) { \ |
| 1099 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1100 | 4; \ |
| 1101 | } |
| 1102 | |
| 1103 | #define MAKE_BFP_SAD3_WRAPPER(fnname) \ |
| 1104 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1105 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1106 | unsigned int *sad_array) { \ |
| 1107 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1108 | } \ |
| 1109 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1110 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1111 | unsigned int *sad_array) { \ |
| 1112 | int i; \ |
| 1113 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1114 | for (i = 0; i < 3; i++) sad_array[i] >>= 2; \ |
| 1115 | } \ |
| 1116 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1117 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1118 | unsigned int *sad_array) { \ |
| 1119 | int i; \ |
| 1120 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1121 | for (i = 0; i < 3; i++) sad_array[i] >>= 4; \ |
| 1122 | } |
| 1123 | |
| 1124 | #define MAKE_BFP_SAD8_WRAPPER(fnname) \ |
| 1125 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1126 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1127 | unsigned int *sad_array) { \ |
| 1128 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1129 | } \ |
| 1130 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1131 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1132 | unsigned int *sad_array) { \ |
| 1133 | int i; \ |
| 1134 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1135 | for (i = 0; i < 8; i++) sad_array[i] >>= 2; \ |
| 1136 | } \ |
| 1137 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1138 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1139 | unsigned int *sad_array) { \ |
| 1140 | int i; \ |
| 1141 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1142 | for (i = 0; i < 8; i++) sad_array[i] >>= 4; \ |
| 1143 | } |
| 1144 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1145 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1146 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1147 | unsigned int *sad_array) { \ |
| 1148 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1149 | } \ |
| 1150 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1151 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1152 | unsigned int *sad_array) { \ |
| 1153 | int i; \ |
| 1154 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1155 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1156 | } \ |
| 1157 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1158 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1159 | unsigned int *sad_array) { \ |
| 1160 | int i; \ |
| 1161 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1162 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1163 | } |
| 1164 | |
| 1165 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1166 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1167 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
| 1168 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad128x128x3) |
| 1169 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad128x128x8) |
| 1170 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1171 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1172 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1173 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1174 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1175 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1176 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1177 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1178 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1179 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1180 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1181 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1182 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1183 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1184 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1185 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1186 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1187 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1188 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1189 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1190 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1191 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
| 1192 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad32x32x3) |
| 1193 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad32x32x8) |
| 1194 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1195 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1196 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
| 1197 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad64x64x3) |
| 1198 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad64x64x8) |
| 1199 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1200 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1201 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
| 1202 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x16x3) |
| 1203 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x16x8) |
| 1204 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1205 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1206 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
| 1207 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x8x3) |
| 1208 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x8x8) |
| 1209 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1210 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1211 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
| 1212 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x16x3) |
| 1213 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x16x8) |
| 1214 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1215 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1216 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
| 1217 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x8x3) |
| 1218 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x8x8) |
| 1219 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1220 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1221 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
| 1222 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x4x8) |
| 1223 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1224 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1225 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
| 1226 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x8x8) |
| 1227 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1228 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1229 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
| 1230 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad4x4x3) |
| 1231 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x4x8) |
| 1232 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1233 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1234 | #if CONFIG_EXT_PARTITION_TYPES |
| 1235 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16) |
| 1236 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg) |
| 1237 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d) |
| 1238 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4) |
| 1239 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg) |
| 1240 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d) |
| 1241 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32) |
| 1242 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg) |
| 1243 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d) |
| 1244 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8) |
| 1245 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg) |
| 1246 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1247 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64) |
| 1248 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg) |
| 1249 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d) |
| 1250 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16) |
| 1251 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg) |
| 1252 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1253 | #endif |
| 1254 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1255 | #if CONFIG_EXT_INTER |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1256 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1257 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1258 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1259 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1260 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1261 | static unsigned int fnname##_bits8( \ |
| 1262 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1263 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1264 | int m_stride, int invert_mask) { \ |
| 1265 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1266 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1267 | } \ |
| 1268 | static unsigned int fnname##_bits10( \ |
| 1269 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1270 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1271 | int m_stride, int invert_mask) { \ |
| 1272 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1273 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1274 | 2; \ |
| 1275 | } \ |
| 1276 | static unsigned int fnname##_bits12( \ |
| 1277 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1278 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1279 | int m_stride, int invert_mask) { \ |
| 1280 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1281 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1282 | 4; \ |
| 1283 | } |
| 1284 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1285 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1286 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1287 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1288 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1289 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1290 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1291 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1292 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1293 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1294 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1295 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1296 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1297 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1298 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1299 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1300 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1301 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1302 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1303 | |
| 1304 | #if CONFIG_EXT_PARTITION_TYPES |
| 1305 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1306 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1307 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1308 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1309 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1310 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1311 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1312 | #endif // CONFIG_EXT_INTER |
| 1313 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1314 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1315 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1316 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1317 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1318 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1319 | |
| 1320 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1321 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1322 | const int32_t *wsrc, \ |
| 1323 | const int32_t *msk) { \ |
| 1324 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1325 | } \ |
| 1326 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1327 | const int32_t *wsrc, \ |
| 1328 | const int32_t *msk) { \ |
| 1329 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1330 | } \ |
| 1331 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1332 | const int32_t *wsrc, \ |
| 1333 | const int32_t *msk) { \ |
| 1334 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1335 | } |
| 1336 | |
| 1337 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1338 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1339 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1340 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1341 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1342 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1343 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1344 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1345 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1346 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1347 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1348 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1349 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1350 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1351 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1352 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1353 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1354 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1355 | |
| 1356 | #if CONFIG_EXT_PARTITION_TYPES |
| 1357 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1358 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1359 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1360 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1361 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1362 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1363 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1364 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1365 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1366 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1367 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1368 | if (cm->use_highbitdepth) { |
| 1369 | switch (cm->bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1370 | case AOM_BITS_8: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1371 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1372 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1373 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1374 | aom_highbd_8_sub_pixel_variance64x16, |
| 1375 | aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1376 | aom_highbd_sad64x16x4d_bits8) |
| 1377 | |
| 1378 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1379 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1380 | aom_highbd_8_sub_pixel_variance16x64, |
| 1381 | aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1382 | aom_highbd_sad16x64x4d_bits8) |
| 1383 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1384 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits8, |
| 1385 | aom_highbd_sad32x8_avg_bits8, aom_highbd_8_variance32x8, |
| 1386 | aom_highbd_8_sub_pixel_variance32x8, |
| 1387 | aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1388 | aom_highbd_sad32x8x4d_bits8) |
| 1389 | |
| 1390 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits8, |
| 1391 | aom_highbd_sad8x32_avg_bits8, aom_highbd_8_variance8x32, |
| 1392 | aom_highbd_8_sub_pixel_variance8x32, |
| 1393 | aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1394 | aom_highbd_sad8x32x4d_bits8) |
| 1395 | |
| 1396 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits8, |
| 1397 | aom_highbd_sad16x4_avg_bits8, aom_highbd_8_variance16x4, |
| 1398 | aom_highbd_8_sub_pixel_variance16x4, |
| 1399 | aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1400 | aom_highbd_sad16x4x4d_bits8) |
| 1401 | |
| 1402 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits8, |
| 1403 | aom_highbd_sad4x16_avg_bits8, aom_highbd_8_variance4x16, |
| 1404 | aom_highbd_8_sub_pixel_variance4x16, |
| 1405 | aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1406 | aom_highbd_sad4x16x4d_bits8) |
| 1407 | #endif |
| 1408 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1409 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1410 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1411 | aom_highbd_8_sub_pixel_variance32x16, |
| 1412 | aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1413 | aom_highbd_sad32x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1414 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1415 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1416 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1417 | aom_highbd_8_sub_pixel_variance16x32, |
| 1418 | aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1419 | aom_highbd_sad16x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1420 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1421 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1422 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1423 | aom_highbd_8_sub_pixel_variance64x32, |
| 1424 | aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1425 | aom_highbd_sad64x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1426 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1427 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1428 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1429 | aom_highbd_8_sub_pixel_variance32x64, |
| 1430 | aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1431 | aom_highbd_sad32x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1432 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1433 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1434 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1435 | aom_highbd_8_sub_pixel_variance32x32, |
| 1436 | aom_highbd_8_sub_pixel_avg_variance32x32, |
| 1437 | aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8, |
| 1438 | aom_highbd_sad32x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1439 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1440 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1441 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1442 | aom_highbd_8_sub_pixel_variance64x64, |
| 1443 | aom_highbd_8_sub_pixel_avg_variance64x64, |
| 1444 | aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8, |
| 1445 | aom_highbd_sad64x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1446 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1447 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1448 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1449 | aom_highbd_8_sub_pixel_variance16x16, |
| 1450 | aom_highbd_8_sub_pixel_avg_variance16x16, |
| 1451 | aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8, |
| 1452 | aom_highbd_sad16x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1453 | |
| 1454 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1455 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1456 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
| 1457 | aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8, |
| 1458 | aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1459 | |
| 1460 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1461 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1462 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
| 1463 | aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8, |
| 1464 | aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1465 | |
| 1466 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1467 | BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8, |
| 1468 | aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8, |
| 1469 | aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits8, |
| 1470 | aom_highbd_sad8x8x8_bits8, aom_highbd_sad8x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1471 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1472 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8, |
| 1473 | aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4, |
| 1474 | aom_highbd_8_sub_pixel_variance8x4, |
| 1475 | aom_highbd_8_sub_pixel_avg_variance8x4, NULL, |
| 1476 | aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1477 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1478 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8, |
| 1479 | aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8, |
| 1480 | aom_highbd_8_sub_pixel_variance4x8, |
| 1481 | aom_highbd_8_sub_pixel_avg_variance4x8, NULL, |
| 1482 | aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1483 | |
| 1484 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1485 | BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8, |
| 1486 | aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4, |
| 1487 | aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits8, |
| 1488 | aom_highbd_sad4x4x8_bits8, aom_highbd_sad4x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1489 | |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 1490 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1491 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_8_variance2x2, NULL, NULL, |
| 1492 | NULL, NULL, NULL) |
| 1493 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_8_variance4x2, NULL, NULL, |
| 1494 | NULL, NULL, NULL) |
| 1495 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_8_variance2x4, NULL, NULL, |
| 1496 | NULL, NULL, NULL) |
| 1497 | #endif |
| 1498 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1499 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1500 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1501 | aom_highbd_sad128x128_avg_bits8, |
| 1502 | aom_highbd_8_variance128x128, |
| 1503 | aom_highbd_8_sub_pixel_variance128x128, |
| 1504 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1505 | aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8, |
| 1506 | aom_highbd_sad128x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1507 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1508 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1509 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1510 | aom_highbd_8_sub_pixel_variance128x64, |
| 1511 | aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1512 | aom_highbd_sad128x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1513 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1514 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1515 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1516 | aom_highbd_8_sub_pixel_variance64x128, |
| 1517 | aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1518 | aom_highbd_sad64x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1519 | #endif // CONFIG_EXT_PARTITION |
| 1520 | |
| 1521 | #if CONFIG_EXT_INTER |
| 1522 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1523 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1524 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1525 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1526 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1527 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1528 | aom_highbd_8_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1529 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1530 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1531 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1532 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1533 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1534 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1535 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1536 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1537 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1538 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1539 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1540 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1541 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1542 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1543 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1544 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1545 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1546 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1547 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1548 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1549 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1550 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1551 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1552 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1553 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1554 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1555 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1556 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1557 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1558 | aom_highbd_8_masked_sub_pixel_variance64x16) |
| 1559 | |
| 1560 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1561 | aom_highbd_8_masked_sub_pixel_variance16x64) |
| 1562 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1563 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1564 | aom_highbd_8_masked_sub_pixel_variance32x8) |
| 1565 | |
| 1566 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1567 | aom_highbd_8_masked_sub_pixel_variance8x32) |
| 1568 | |
| 1569 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1570 | aom_highbd_8_masked_sub_pixel_variance16x4) |
| 1571 | |
| 1572 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1573 | aom_highbd_8_masked_sub_pixel_variance4x16) |
| 1574 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1575 | #endif // CONFIG_EXT_INTER |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1576 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1577 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1578 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1579 | aom_highbd_obmc_variance128x128, |
| 1580 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1581 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1582 | aom_highbd_obmc_variance128x64, |
| 1583 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1584 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1585 | aom_highbd_obmc_variance64x128, |
| 1586 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1587 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1588 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1589 | aom_highbd_obmc_variance64x64, |
| 1590 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1591 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1592 | aom_highbd_obmc_variance64x32, |
| 1593 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1594 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1595 | aom_highbd_obmc_variance32x64, |
| 1596 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1597 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1598 | aom_highbd_obmc_variance32x32, |
| 1599 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1600 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1601 | aom_highbd_obmc_variance32x16, |
| 1602 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1603 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1604 | aom_highbd_obmc_variance16x32, |
| 1605 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1606 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1607 | aom_highbd_obmc_variance16x16, |
| 1608 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1609 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1610 | aom_highbd_obmc_variance8x16, |
| 1611 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1612 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1613 | aom_highbd_obmc_variance16x8, |
| 1614 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1615 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1616 | aom_highbd_obmc_variance8x8, |
| 1617 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 1618 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 1619 | aom_highbd_obmc_variance4x8, |
| 1620 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 1621 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 1622 | aom_highbd_obmc_variance8x4, |
| 1623 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 1624 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 1625 | aom_highbd_obmc_variance4x4, |
| 1626 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1627 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1628 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 1629 | aom_highbd_obmc_variance64x16, |
| 1630 | aom_highbd_obmc_sub_pixel_variance64x16) |
| 1631 | |
| 1632 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 1633 | aom_highbd_obmc_variance16x64, |
| 1634 | aom_highbd_obmc_sub_pixel_variance16x64) |
| 1635 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1636 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 1637 | aom_highbd_obmc_variance32x8, |
| 1638 | aom_highbd_obmc_sub_pixel_variance32x8) |
| 1639 | |
| 1640 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 1641 | aom_highbd_obmc_variance8x32, |
| 1642 | aom_highbd_obmc_sub_pixel_variance8x32) |
| 1643 | |
| 1644 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 1645 | aom_highbd_obmc_variance16x4, |
| 1646 | aom_highbd_obmc_sub_pixel_variance16x4) |
| 1647 | |
| 1648 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 1649 | aom_highbd_obmc_variance4x16, |
| 1650 | aom_highbd_obmc_sub_pixel_variance4x16) |
| 1651 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1652 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1653 | break; |
| 1654 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1655 | case AOM_BITS_10: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1656 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1657 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 1658 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 1659 | aom_highbd_10_sub_pixel_variance64x16, |
| 1660 | aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1661 | aom_highbd_sad64x16x4d_bits10) |
| 1662 | |
| 1663 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 1664 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 1665 | aom_highbd_10_sub_pixel_variance16x64, |
| 1666 | aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1667 | aom_highbd_sad16x64x4d_bits10) |
| 1668 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1669 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 1670 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 1671 | aom_highbd_10_sub_pixel_variance32x8, |
| 1672 | aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1673 | aom_highbd_sad32x8x4d_bits10) |
| 1674 | |
| 1675 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 1676 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 1677 | aom_highbd_10_sub_pixel_variance8x32, |
| 1678 | aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1679 | aom_highbd_sad8x32x4d_bits10) |
| 1680 | |
| 1681 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 1682 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 1683 | aom_highbd_10_sub_pixel_variance16x4, |
| 1684 | aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1685 | aom_highbd_sad16x4x4d_bits10) |
| 1686 | |
| 1687 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 1688 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 1689 | aom_highbd_10_sub_pixel_variance4x16, |
| 1690 | aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1691 | aom_highbd_sad4x16x4d_bits10) |
| 1692 | #endif |
| 1693 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1694 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 1695 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 1696 | aom_highbd_10_sub_pixel_variance32x16, |
| 1697 | aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1698 | aom_highbd_sad32x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1699 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1700 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 1701 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 1702 | aom_highbd_10_sub_pixel_variance16x32, |
| 1703 | aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1704 | aom_highbd_sad16x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1705 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1706 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 1707 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 1708 | aom_highbd_10_sub_pixel_variance64x32, |
| 1709 | aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1710 | aom_highbd_sad64x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1711 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1712 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 1713 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 1714 | aom_highbd_10_sub_pixel_variance32x64, |
| 1715 | aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1716 | aom_highbd_sad32x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1717 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1718 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 1719 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 1720 | aom_highbd_10_sub_pixel_variance32x32, |
| 1721 | aom_highbd_10_sub_pixel_avg_variance32x32, |
| 1722 | aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10, |
| 1723 | aom_highbd_sad32x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1724 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1725 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 1726 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 1727 | aom_highbd_10_sub_pixel_variance64x64, |
| 1728 | aom_highbd_10_sub_pixel_avg_variance64x64, |
| 1729 | aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10, |
| 1730 | aom_highbd_sad64x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1731 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1732 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 1733 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 1734 | aom_highbd_10_sub_pixel_variance16x16, |
| 1735 | aom_highbd_10_sub_pixel_avg_variance16x16, |
| 1736 | aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10, |
| 1737 | aom_highbd_sad16x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1738 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1739 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 1740 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 1741 | aom_highbd_10_sub_pixel_variance16x8, |
| 1742 | aom_highbd_10_sub_pixel_avg_variance16x8, |
| 1743 | aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10, |
| 1744 | aom_highbd_sad16x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1745 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1746 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 1747 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 1748 | aom_highbd_10_sub_pixel_variance8x16, |
| 1749 | aom_highbd_10_sub_pixel_avg_variance8x16, |
| 1750 | aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10, |
| 1751 | aom_highbd_sad8x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1752 | |
| 1753 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1754 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 1755 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
| 1756 | aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10, |
| 1757 | aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1758 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1759 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10, |
| 1760 | aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4, |
| 1761 | aom_highbd_10_sub_pixel_variance8x4, |
| 1762 | aom_highbd_10_sub_pixel_avg_variance8x4, NULL, |
| 1763 | aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1764 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1765 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10, |
| 1766 | aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8, |
| 1767 | aom_highbd_10_sub_pixel_variance4x8, |
| 1768 | aom_highbd_10_sub_pixel_avg_variance4x8, NULL, |
| 1769 | aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1770 | |
| 1771 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1772 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 1773 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
| 1774 | aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10, |
| 1775 | aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1776 | |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 1777 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1778 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_10_variance2x2, NULL, NULL, |
| 1779 | NULL, NULL, NULL) |
| 1780 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_10_variance4x2, NULL, NULL, |
| 1781 | NULL, NULL, NULL) |
| 1782 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_10_variance2x4, NULL, NULL, |
| 1783 | NULL, NULL, NULL) |
| 1784 | #endif |
| 1785 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1786 | #if CONFIG_EXT_PARTITION |
| 1787 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1788 | BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 1789 | aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128, |
| 1790 | aom_highbd_10_sub_pixel_variance128x128, |
| 1791 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 1792 | aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10, |
| 1793 | aom_highbd_sad128x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1794 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1795 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 1796 | aom_highbd_sad128x64_avg_bits10, |
| 1797 | aom_highbd_10_variance128x64, |
| 1798 | aom_highbd_10_sub_pixel_variance128x64, |
| 1799 | aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1800 | aom_highbd_sad128x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1801 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1802 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 1803 | aom_highbd_sad64x128_avg_bits10, |
| 1804 | aom_highbd_10_variance64x128, |
| 1805 | aom_highbd_10_sub_pixel_variance64x128, |
| 1806 | aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1807 | aom_highbd_sad64x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1808 | #endif // CONFIG_EXT_PARTITION |
| 1809 | |
| 1810 | #if CONFIG_EXT_INTER |
| 1811 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1812 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 1813 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 1814 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 1815 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 1816 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 1817 | aom_highbd_10_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1818 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1819 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 1820 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 1821 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 1822 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 1823 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 1824 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 1825 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 1826 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 1827 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 1828 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 1829 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 1830 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 1831 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 1832 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 1833 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 1834 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 1835 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 1836 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 1837 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 1838 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 1839 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 1840 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 1841 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 1842 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 1843 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 1844 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1845 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1846 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 1847 | aom_highbd_10_masked_sub_pixel_variance64x16) |
| 1848 | |
| 1849 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 1850 | aom_highbd_10_masked_sub_pixel_variance16x64) |
| 1851 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1852 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 1853 | aom_highbd_10_masked_sub_pixel_variance32x8) |
| 1854 | |
| 1855 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 1856 | aom_highbd_10_masked_sub_pixel_variance8x32) |
| 1857 | |
| 1858 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 1859 | aom_highbd_10_masked_sub_pixel_variance16x4) |
| 1860 | |
| 1861 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 1862 | aom_highbd_10_masked_sub_pixel_variance4x16) |
| 1863 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1864 | #endif // CONFIG_EXT_INTER |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1865 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1866 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1867 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 1868 | aom_highbd_10_obmc_variance128x128, |
| 1869 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 1870 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 1871 | aom_highbd_10_obmc_variance128x64, |
| 1872 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 1873 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 1874 | aom_highbd_10_obmc_variance64x128, |
| 1875 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1876 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1877 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 1878 | aom_highbd_10_obmc_variance64x64, |
| 1879 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 1880 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 1881 | aom_highbd_10_obmc_variance64x32, |
| 1882 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 1883 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 1884 | aom_highbd_10_obmc_variance32x64, |
| 1885 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 1886 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 1887 | aom_highbd_10_obmc_variance32x32, |
| 1888 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 1889 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 1890 | aom_highbd_10_obmc_variance32x16, |
| 1891 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 1892 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 1893 | aom_highbd_10_obmc_variance16x32, |
| 1894 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 1895 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 1896 | aom_highbd_10_obmc_variance16x16, |
| 1897 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 1898 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 1899 | aom_highbd_10_obmc_variance8x16, |
| 1900 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 1901 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 1902 | aom_highbd_10_obmc_variance16x8, |
| 1903 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 1904 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 1905 | aom_highbd_10_obmc_variance8x8, |
| 1906 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 1907 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 1908 | aom_highbd_10_obmc_variance4x8, |
| 1909 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 1910 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 1911 | aom_highbd_10_obmc_variance8x4, |
| 1912 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 1913 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 1914 | aom_highbd_10_obmc_variance4x4, |
| 1915 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1916 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1917 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 1918 | aom_highbd_10_obmc_variance64x16, |
| 1919 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 1920 | |
| 1921 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 1922 | aom_highbd_10_obmc_variance16x64, |
| 1923 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 1924 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1925 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 1926 | aom_highbd_10_obmc_variance32x8, |
| 1927 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 1928 | |
| 1929 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 1930 | aom_highbd_10_obmc_variance8x32, |
| 1931 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 1932 | |
| 1933 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 1934 | aom_highbd_10_obmc_variance16x4, |
| 1935 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 1936 | |
| 1937 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 1938 | aom_highbd_10_obmc_variance4x16, |
| 1939 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
| 1940 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1941 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1942 | break; |
| 1943 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1944 | case AOM_BITS_12: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1945 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1946 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 1947 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 1948 | aom_highbd_12_sub_pixel_variance64x16, |
| 1949 | aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1950 | aom_highbd_sad64x16x4d_bits12) |
| 1951 | |
| 1952 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 1953 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 1954 | aom_highbd_12_sub_pixel_variance16x64, |
| 1955 | aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1956 | aom_highbd_sad16x64x4d_bits12) |
| 1957 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1958 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 1959 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 1960 | aom_highbd_12_sub_pixel_variance32x8, |
| 1961 | aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1962 | aom_highbd_sad32x8x4d_bits12) |
| 1963 | |
| 1964 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 1965 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 1966 | aom_highbd_12_sub_pixel_variance8x32, |
| 1967 | aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1968 | aom_highbd_sad8x32x4d_bits12) |
| 1969 | |
| 1970 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 1971 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 1972 | aom_highbd_12_sub_pixel_variance16x4, |
| 1973 | aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1974 | aom_highbd_sad16x4x4d_bits12) |
| 1975 | |
| 1976 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 1977 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 1978 | aom_highbd_12_sub_pixel_variance4x16, |
| 1979 | aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1980 | aom_highbd_sad4x16x4d_bits12) |
| 1981 | #endif |
| 1982 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1983 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 1984 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 1985 | aom_highbd_12_sub_pixel_variance32x16, |
| 1986 | aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1987 | aom_highbd_sad32x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1988 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1989 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 1990 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 1991 | aom_highbd_12_sub_pixel_variance16x32, |
| 1992 | aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1993 | aom_highbd_sad16x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1994 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1995 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 1996 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 1997 | aom_highbd_12_sub_pixel_variance64x32, |
| 1998 | aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1999 | aom_highbd_sad64x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2000 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2001 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 2002 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 2003 | aom_highbd_12_sub_pixel_variance32x64, |
| 2004 | aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2005 | aom_highbd_sad32x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2006 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2007 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 2008 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 2009 | aom_highbd_12_sub_pixel_variance32x32, |
| 2010 | aom_highbd_12_sub_pixel_avg_variance32x32, |
| 2011 | aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12, |
| 2012 | aom_highbd_sad32x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2013 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2014 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2015 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2016 | aom_highbd_12_sub_pixel_variance64x64, |
| 2017 | aom_highbd_12_sub_pixel_avg_variance64x64, |
| 2018 | aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12, |
| 2019 | aom_highbd_sad64x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2020 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2021 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2022 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2023 | aom_highbd_12_sub_pixel_variance16x16, |
| 2024 | aom_highbd_12_sub_pixel_avg_variance16x16, |
| 2025 | aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12, |
| 2026 | aom_highbd_sad16x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2027 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2028 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2029 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2030 | aom_highbd_12_sub_pixel_variance16x8, |
| 2031 | aom_highbd_12_sub_pixel_avg_variance16x8, |
| 2032 | aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12, |
| 2033 | aom_highbd_sad16x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2034 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2035 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2036 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2037 | aom_highbd_12_sub_pixel_variance8x16, |
| 2038 | aom_highbd_12_sub_pixel_avg_variance8x16, |
| 2039 | aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12, |
| 2040 | aom_highbd_sad8x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2041 | |
| 2042 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2043 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2044 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
| 2045 | aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12, |
| 2046 | aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2047 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2048 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12, |
| 2049 | aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4, |
| 2050 | aom_highbd_12_sub_pixel_variance8x4, |
| 2051 | aom_highbd_12_sub_pixel_avg_variance8x4, NULL, |
| 2052 | aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2053 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2054 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12, |
| 2055 | aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8, |
| 2056 | aom_highbd_12_sub_pixel_variance4x8, |
| 2057 | aom_highbd_12_sub_pixel_avg_variance4x8, NULL, |
| 2058 | aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2059 | |
| 2060 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2061 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2062 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
| 2063 | aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12, |
| 2064 | aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2065 | |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 2066 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 2067 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_12_variance2x2, NULL, NULL, |
| 2068 | NULL, NULL, NULL) |
| 2069 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_12_variance4x2, NULL, NULL, |
| 2070 | NULL, NULL, NULL) |
| 2071 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_12_variance2x4, NULL, NULL, |
| 2072 | NULL, NULL, NULL) |
| 2073 | #endif |
| 2074 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2075 | #if CONFIG_EXT_PARTITION |
| 2076 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2077 | BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2078 | aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128, |
| 2079 | aom_highbd_12_sub_pixel_variance128x128, |
| 2080 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2081 | aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12, |
| 2082 | aom_highbd_sad128x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2083 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2084 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2085 | aom_highbd_sad128x64_avg_bits12, |
| 2086 | aom_highbd_12_variance128x64, |
| 2087 | aom_highbd_12_sub_pixel_variance128x64, |
| 2088 | aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL, |
| 2089 | aom_highbd_sad128x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2090 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2091 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2092 | aom_highbd_sad64x128_avg_bits12, |
| 2093 | aom_highbd_12_variance64x128, |
| 2094 | aom_highbd_12_sub_pixel_variance64x128, |
| 2095 | aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL, |
| 2096 | aom_highbd_sad64x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2097 | #endif // CONFIG_EXT_PARTITION |
| 2098 | |
| 2099 | #if CONFIG_EXT_INTER |
| 2100 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2101 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2102 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2103 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2104 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2105 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2106 | aom_highbd_12_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2107 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2108 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2109 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2110 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2111 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2112 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2113 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2114 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2115 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2116 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2117 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2118 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2119 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2120 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2121 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2122 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2123 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2124 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2125 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2126 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2127 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2128 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2129 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2130 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2131 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2132 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2133 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2134 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2135 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2136 | aom_highbd_12_masked_sub_pixel_variance64x16) |
| 2137 | |
| 2138 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2139 | aom_highbd_12_masked_sub_pixel_variance16x64) |
| 2140 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2141 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2142 | aom_highbd_12_masked_sub_pixel_variance32x8) |
| 2143 | |
| 2144 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2145 | aom_highbd_12_masked_sub_pixel_variance8x32) |
| 2146 | |
| 2147 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2148 | aom_highbd_12_masked_sub_pixel_variance16x4) |
| 2149 | |
| 2150 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2151 | aom_highbd_12_masked_sub_pixel_variance4x16) |
| 2152 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2153 | #endif // CONFIG_EXT_INTER |
| 2154 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2155 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2156 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2157 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2158 | aom_highbd_12_obmc_variance128x128, |
| 2159 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2160 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2161 | aom_highbd_12_obmc_variance128x64, |
| 2162 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 2163 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 2164 | aom_highbd_12_obmc_variance64x128, |
| 2165 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2166 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2167 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 2168 | aom_highbd_12_obmc_variance64x64, |
| 2169 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 2170 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 2171 | aom_highbd_12_obmc_variance64x32, |
| 2172 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 2173 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 2174 | aom_highbd_12_obmc_variance32x64, |
| 2175 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 2176 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 2177 | aom_highbd_12_obmc_variance32x32, |
| 2178 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 2179 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 2180 | aom_highbd_12_obmc_variance32x16, |
| 2181 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 2182 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 2183 | aom_highbd_12_obmc_variance16x32, |
| 2184 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 2185 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 2186 | aom_highbd_12_obmc_variance16x16, |
| 2187 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 2188 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 2189 | aom_highbd_12_obmc_variance8x16, |
| 2190 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 2191 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 2192 | aom_highbd_12_obmc_variance16x8, |
| 2193 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 2194 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 2195 | aom_highbd_12_obmc_variance8x8, |
| 2196 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 2197 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 2198 | aom_highbd_12_obmc_variance4x8, |
| 2199 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 2200 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 2201 | aom_highbd_12_obmc_variance8x4, |
| 2202 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 2203 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 2204 | aom_highbd_12_obmc_variance4x4, |
| 2205 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2206 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2207 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 2208 | aom_highbd_12_obmc_variance64x16, |
| 2209 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
| 2210 | |
| 2211 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 2212 | aom_highbd_12_obmc_variance16x64, |
| 2213 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
| 2214 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2215 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 2216 | aom_highbd_12_obmc_variance32x8, |
| 2217 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
| 2218 | |
| 2219 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 2220 | aom_highbd_12_obmc_variance8x32, |
| 2221 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
| 2222 | |
| 2223 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 2224 | aom_highbd_12_obmc_variance16x4, |
| 2225 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
| 2226 | |
| 2227 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 2228 | aom_highbd_12_obmc_variance4x16, |
| 2229 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
| 2230 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2231 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2232 | break; |
| 2233 | |
| 2234 | default: |
| 2235 | assert(0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2236 | "cm->bit_depth should be AOM_BITS_8, " |
| 2237 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2238 | } |
| 2239 | } |
| 2240 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2241 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2242 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2243 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 2244 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2245 | |
| 2246 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2247 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2248 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2249 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2250 | |
| 2251 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2252 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2253 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2254 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2255 | |
| 2256 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2257 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2258 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2259 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2260 | } |
| 2261 | |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2262 | #if CONFIG_EXT_INTER |
| 2263 | void set_compound_tools(AV1_COMMON *cm) { |
| 2264 | (void)cm; |
| 2265 | #if CONFIG_INTERINTRA |
| 2266 | cm->allow_interintra_compound = 1; |
| 2267 | #endif // CONFIG_INTERINTRA |
| 2268 | #if CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT |
| 2269 | cm->allow_masked_compound = 1; |
| 2270 | #endif // CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT |
| 2271 | } |
| 2272 | #endif // CONFIG_EXT_INTER |
| 2273 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2274 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 2275 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2276 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2277 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2278 | |
| 2279 | if (cm->profile != oxcf->profile) cm->profile = oxcf->profile; |
| 2280 | cm->bit_depth = oxcf->bit_depth; |
| 2281 | cm->color_space = oxcf->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 2282 | #if CONFIG_COLORSPACE_HEADERS |
| 2283 | cm->transfer_function = oxcf->transfer_function; |
| 2284 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
| 2285 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2286 | cm->color_range = oxcf->color_range; |
| 2287 | |
| 2288 | if (cm->profile <= PROFILE_1) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2289 | assert(cm->bit_depth == AOM_BITS_8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2290 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2291 | assert(cm->bit_depth > AOM_BITS_8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2292 | |
| 2293 | cpi->oxcf = *oxcf; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2294 | x->e_mbd.bd = (int)cm->bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2295 | #if CONFIG_GLOBAL_MOTION |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2296 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2297 | #endif // CONFIG_GLOBAL_MOTION |
| 2298 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2299 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2300 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 2301 | } else { |
| 2302 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 2303 | } |
| 2304 | |
| 2305 | cpi->refresh_last_frame = 1; |
| 2306 | cpi->refresh_golden_frame = 0; |
| 2307 | #if CONFIG_EXT_REFS |
| 2308 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 2309 | #if CONFIG_ALTREF2 |
| 2310 | cpi->refresh_alt2_ref_frame = 0; |
| 2311 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2312 | #endif // CONFIG_EXT_REFS |
| 2313 | |
| 2314 | cm->refresh_frame_context = |
| 2315 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 2316 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 2317 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 2318 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2319 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 2320 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2321 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 2322 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2323 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 2324 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 2325 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2326 | #if CONFIG_EXT_INTER |
| 2327 | set_compound_tools(cm); |
| 2328 | #endif // CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2329 | av1_reset_segment_features(cm); |
| 2330 | av1_set_high_precision_mv(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2331 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2332 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 2333 | |
| 2334 | // Under a configuration change, where maximum_buffer_size may change, |
| 2335 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2336 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2337 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2338 | |
| 2339 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2340 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2341 | |
| 2342 | // Set absolute upper and lower quality limits |
| 2343 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2344 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2345 | |
| 2346 | cm->interp_filter = cpi->sf.default_interp_filter; |
| 2347 | |
| 2348 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2349 | cm->render_width = cpi->oxcf.render_width; |
| 2350 | cm->render_height = cpi->oxcf.render_height; |
| 2351 | } else { |
| 2352 | cm->render_width = cpi->oxcf.width; |
| 2353 | cm->render_height = cpi->oxcf.height; |
| 2354 | } |
| 2355 | cm->width = cpi->oxcf.width; |
| 2356 | cm->height = cpi->oxcf.height; |
| 2357 | |
| 2358 | if (cpi->initial_width) { |
| 2359 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2360 | av1_free_context_buffers(cm); |
| 2361 | av1_alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2362 | realloc_segmentation_maps(cpi); |
| 2363 | cpi->initial_width = cpi->initial_height = 0; |
| 2364 | } |
| 2365 | } |
| 2366 | update_frame_size(cpi); |
| 2367 | |
| 2368 | cpi->alt_ref_source = NULL; |
| 2369 | rc->is_src_frame_alt_ref = 0; |
| 2370 | |
| 2371 | #if CONFIG_EXT_REFS |
| 2372 | rc->is_bwd_ref_frame = 0; |
| 2373 | rc->is_last_bipred_frame = 0; |
| 2374 | rc->is_bipred_frame = 0; |
| 2375 | #endif // CONFIG_EXT_REFS |
| 2376 | |
| 2377 | #if 0 |
| 2378 | // Experimental RD Code |
| 2379 | cpi->frame_distortion = 0; |
| 2380 | cpi->last_frame_distortion = 0; |
| 2381 | #endif |
| 2382 | |
| 2383 | set_tile_info(cpi); |
| 2384 | |
| 2385 | cpi->ext_refresh_frame_flags_pending = 0; |
| 2386 | cpi->ext_refresh_frame_context_pending = 0; |
| 2387 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2388 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2389 | highbd_set_var_fns(cpi); |
| 2390 | #endif |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2391 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 2392 | cpi->common.ans_window_size_log2 = cpi->oxcf.ans_window_size_log2; |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2393 | #endif // CONFIG_ANS && ANS_MAX_SYMBOLS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2394 | } |
| 2395 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2396 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 2397 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2398 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2399 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2400 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2401 | |
| 2402 | if (!cm) return NULL; |
| 2403 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2404 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2405 | |
| 2406 | if (setjmp(cm->error.jmp)) { |
| 2407 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2408 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2409 | return 0; |
| 2410 | } |
| 2411 | |
| 2412 | cm->error.setjmp = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2413 | cm->alloc_mi = av1_enc_alloc_mi; |
| 2414 | cm->free_mi = av1_enc_free_mi; |
| 2415 | cm->setup_mi = av1_enc_setup_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2416 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2417 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2418 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
| 2419 | CHECK_MEM_ERROR(cm, cm->frame_contexts, |
| 2420 | (FRAME_CONTEXT *)aom_memalign( |
| 2421 | 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts))); |
| 2422 | memset(cm->fc, 0, sizeof(*cm->fc)); |
| 2423 | memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2424 | |
| 2425 | cpi->resize_state = 0; |
| 2426 | cpi->resize_avg_qp = 0; |
| 2427 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2428 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2429 | cpi->common.buffer_pool = pool; |
| 2430 | |
| 2431 | init_config(cpi, oxcf); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2432 | #if CONFIG_XIPHRC |
| 2433 | cpi->od_rc.framerate = cpi->framerate; |
| 2434 | cpi->od_rc.frame_width = cm->render_width; |
| 2435 | cpi->od_rc.frame_height = cm->render_height; |
| 2436 | cpi->od_rc.keyframe_rate = oxcf->key_freq; |
| 2437 | cpi->od_rc.goldenframe_rate = FIXED_GF_INTERVAL; |
| 2438 | cpi->od_rc.altref_rate = 25; |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2439 | cpi->od_rc.firstpass_quant = 1; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2440 | cpi->od_rc.bit_depth = cm->bit_depth; |
| 2441 | cpi->od_rc.minq = oxcf->best_allowed_q; |
| 2442 | cpi->od_rc.maxq = oxcf->worst_allowed_q; |
| 2443 | if (cpi->oxcf.rc_mode == AOM_CQ) cpi->od_rc.minq = cpi->od_rc.quality; |
| 2444 | cpi->od_rc.quality = cpi->oxcf.rc_mode == AOM_Q ? oxcf->cq_level : -1; |
| 2445 | cpi->od_rc.periodic_boosts = oxcf->frame_periodic_boost; |
| 2446 | od_enc_rc_init(&cpi->od_rc, |
| 2447 | cpi->oxcf.rc_mode == AOM_Q ? -1 : oxcf->target_bandwidth, |
| 2448 | oxcf->maximum_buffer_size_ms); |
| 2449 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2450 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2451 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2452 | |
| 2453 | cm->current_video_frame = 0; |
| 2454 | cpi->partition_search_skippable_frame = 0; |
| 2455 | cpi->tile_data = NULL; |
| 2456 | cpi->last_show_frame_buf_idx = INVALID_IDX; |
| 2457 | |
| 2458 | realloc_segmentation_maps(cpi); |
| 2459 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2460 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
Urvang Joshi | bffc0b5 | 2016-07-25 13:38:49 -0700 | [diff] [blame] | 2461 | memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs)); |
| 2462 | memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2463 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2464 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2465 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 2466 | i++) { |
| 2467 | CHECK_MEM_ERROR( |
| 2468 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2469 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | #if CONFIG_FP_MB_STATS |
| 2473 | cpi->use_fp_mb_stats = 0; |
| 2474 | if (cpi->use_fp_mb_stats) { |
| 2475 | // a place holder used to store the first pass mb stats in the first pass |
| 2476 | CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2477 | aom_calloc(cm->MBs * sizeof(uint8_t), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2478 | } else { |
| 2479 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2480 | } |
| 2481 | #endif |
| 2482 | |
| 2483 | cpi->refresh_alt_ref_frame = 0; |
| 2484 | cpi->multi_arf_last_grp_enabled = 0; |
| 2485 | |
| 2486 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 2487 | #if CONFIG_INTERNAL_STATS |
| 2488 | cpi->b_calculate_blockiness = 1; |
| 2489 | cpi->b_calculate_consistency = 1; |
| 2490 | cpi->total_inconsistency = 0; |
| 2491 | cpi->psnr.worst = 100.0; |
| 2492 | cpi->worst_ssim = 100.0; |
| 2493 | |
| 2494 | cpi->count = 0; |
| 2495 | cpi->bytes = 0; |
| 2496 | |
| 2497 | if (cpi->b_calculate_psnr) { |
| 2498 | cpi->total_sq_error = 0; |
| 2499 | cpi->total_samples = 0; |
| 2500 | cpi->tot_recode_hits = 0; |
| 2501 | cpi->summed_quality = 0; |
| 2502 | cpi->summed_weights = 0; |
| 2503 | } |
| 2504 | |
| 2505 | cpi->fastssim.worst = 100.0; |
| 2506 | cpi->psnrhvs.worst = 100.0; |
| 2507 | |
| 2508 | if (cpi->b_calculate_blockiness) { |
| 2509 | cpi->total_blockiness = 0; |
| 2510 | cpi->worst_blockiness = 0.0; |
| 2511 | } |
| 2512 | |
| 2513 | if (cpi->b_calculate_consistency) { |
| 2514 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2515 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2516 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 2517 | cpi->worst_consistency = 100.0; |
| 2518 | } |
| 2519 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2520 | #if CONFIG_ENTROPY_STATS |
| 2521 | av1_zero(aggregate_fc); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 2522 | av1_zero_array(aggregate_fc_per_type, FRAME_CONTEXTS); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2523 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2524 | |
| 2525 | cpi->first_time_stamp_ever = INT64_MAX; |
| 2526 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2527 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 2528 | cpi->td.mb.nmvcost[i][0] = &cpi->nmv_costs[i][0][MV_MAX]; |
| 2529 | cpi->td.mb.nmvcost[i][1] = &cpi->nmv_costs[i][1][MV_MAX]; |
| 2530 | cpi->td.mb.nmvcost_hp[i][0] = &cpi->nmv_costs_hp[i][0][MV_MAX]; |
| 2531 | cpi->td.mb.nmvcost_hp[i][1] = &cpi->nmv_costs_hp[i][1][MV_MAX]; |
| 2532 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2533 | |
| 2534 | #ifdef OUTPUT_YUV_SKINMAP |
| 2535 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 2536 | #endif |
| 2537 | #ifdef OUTPUT_YUV_REC |
| 2538 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 2539 | #endif |
| 2540 | |
| 2541 | #if 0 |
| 2542 | framepsnr = fopen("framepsnr.stt", "a"); |
| 2543 | kf_list = fopen("kf_list.stt", "w"); |
| 2544 | #endif |
| 2545 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2546 | #if CONFIG_XIPHRC |
| 2547 | if (oxcf->pass == 2) { |
| 2548 | cpi->od_rc.twopass_allframes_buf = oxcf->two_pass_stats_in.buf; |
| 2549 | cpi->od_rc.twopass_allframes_buf_size = oxcf->two_pass_stats_in.sz; |
| 2550 | } |
| 2551 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2552 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2553 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2554 | } else if (oxcf->pass == 2) { |
| 2555 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 2556 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 2557 | |
| 2558 | #if CONFIG_FP_MB_STATS |
| 2559 | if (cpi->use_fp_mb_stats) { |
| 2560 | const size_t psz = cpi->common.MBs * sizeof(uint8_t); |
| 2561 | const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz); |
| 2562 | |
| 2563 | cpi->twopass.firstpass_mb_stats.mb_stats_start = |
| 2564 | oxcf->firstpass_mb_stats_in.buf; |
| 2565 | cpi->twopass.firstpass_mb_stats.mb_stats_end = |
| 2566 | cpi->twopass.firstpass_mb_stats.mb_stats_start + |
| 2567 | (ps - 1) * cpi->common.MBs * sizeof(uint8_t); |
| 2568 | } |
| 2569 | #endif |
| 2570 | |
| 2571 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 2572 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 2573 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 2574 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2575 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2576 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2577 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2578 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2579 | #if CONFIG_MOTION_VAR |
| 2580 | #if CONFIG_HIGHBITDEPTH |
| 2581 | int buf_scaler = 2; |
| 2582 | #else |
| 2583 | int buf_scaler = 1; |
| 2584 | #endif |
| 2585 | CHECK_MEM_ERROR( |
| 2586 | cm, cpi->td.mb.above_pred_buf, |
| 2587 | (uint8_t *)aom_memalign(16, buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2588 | sizeof(*cpi->td.mb.above_pred_buf))); |
| 2589 | CHECK_MEM_ERROR( |
| 2590 | cm, cpi->td.mb.left_pred_buf, |
| 2591 | (uint8_t *)aom_memalign(16, buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2592 | sizeof(*cpi->td.mb.left_pred_buf))); |
| 2593 | |
| 2594 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 2595 | (int32_t *)aom_memalign( |
| 2596 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 2597 | |
| 2598 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 2599 | (int32_t *)aom_memalign( |
| 2600 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 2601 | |
| 2602 | #endif |
| 2603 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2604 | av1_set_speed_features_framesize_independent(cpi); |
| 2605 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2606 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2607 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 2608 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 2609 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 2610 | cpi->fn_ptr[BT].vf = VF; \ |
| 2611 | cpi->fn_ptr[BT].svf = SVF; \ |
| 2612 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 2613 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 2614 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 2615 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
| 2616 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2617 | #if CONFIG_EXT_PARTITION_TYPES |
| 2618 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
| 2619 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2620 | aom_sad4x16x4d) |
| 2621 | |
| 2622 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
| 2623 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2624 | aom_sad16x4x4d) |
| 2625 | |
| 2626 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
| 2627 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2628 | aom_sad8x32x4d) |
| 2629 | |
| 2630 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
| 2631 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2632 | aom_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2633 | |
| 2634 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
| 2635 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2636 | aom_sad16x64x4d) |
| 2637 | |
| 2638 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
| 2639 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2640 | aom_sad64x16x4d) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2641 | #endif |
| 2642 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2643 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2644 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 2645 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
| 2646 | aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2647 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2648 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
| 2649 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL, |
| 2650 | NULL, aom_sad128x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2651 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2652 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
| 2653 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL, |
| 2654 | NULL, aom_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2655 | #endif // CONFIG_EXT_PARTITION |
| 2656 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2657 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
| 2658 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2659 | aom_sad32x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2660 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2661 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
| 2662 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2663 | aom_sad16x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2664 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2665 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
| 2666 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2667 | aom_sad64x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2668 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2669 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
| 2670 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2671 | aom_sad32x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2672 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2673 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 2674 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
| 2675 | aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2676 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2677 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 2678 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
| 2679 | aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2680 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2681 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 2682 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
| 2683 | aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2684 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2685 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
| 2686 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3, |
| 2687 | aom_sad16x8x8, aom_sad16x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2688 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2689 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
| 2690 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3, |
| 2691 | aom_sad8x16x8, aom_sad8x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2692 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2693 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
| 2694 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3, |
| 2695 | aom_sad8x8x8, aom_sad8x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2696 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2697 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
| 2698 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL, |
| 2699 | aom_sad8x4x8, aom_sad8x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2700 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2701 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
| 2702 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL, |
| 2703 | aom_sad4x8x8, aom_sad4x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2704 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2705 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
| 2706 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3, |
| 2707 | aom_sad4x4x8, aom_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2708 | |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 2709 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 2710 | BFP(BLOCK_2X2, NULL, NULL, aom_variance2x2, NULL, NULL, NULL, NULL, NULL) |
Jingning Han | e2ffaf8 | 2016-12-14 15:26:30 -0800 | [diff] [blame] | 2711 | BFP(BLOCK_2X4, NULL, NULL, aom_variance2x4, NULL, NULL, NULL, NULL, NULL) |
| 2712 | BFP(BLOCK_4X2, NULL, NULL, aom_variance4x2, NULL, NULL, NULL, NULL, NULL) |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 2713 | #endif |
| 2714 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2715 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2716 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 2717 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 2718 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 2719 | cpi->fn_ptr[BT].osvf = OSVF; |
| 2720 | |
| 2721 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2722 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 2723 | aom_obmc_sub_pixel_variance128x128) |
| 2724 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 2725 | aom_obmc_sub_pixel_variance128x64) |
| 2726 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 2727 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2728 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2729 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 2730 | aom_obmc_sub_pixel_variance64x64) |
| 2731 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 2732 | aom_obmc_sub_pixel_variance64x32) |
| 2733 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 2734 | aom_obmc_sub_pixel_variance32x64) |
| 2735 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 2736 | aom_obmc_sub_pixel_variance32x32) |
| 2737 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 2738 | aom_obmc_sub_pixel_variance32x16) |
| 2739 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 2740 | aom_obmc_sub_pixel_variance16x32) |
| 2741 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 2742 | aom_obmc_sub_pixel_variance16x16) |
| 2743 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 2744 | aom_obmc_sub_pixel_variance16x8) |
| 2745 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 2746 | aom_obmc_sub_pixel_variance8x16) |
| 2747 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 2748 | aom_obmc_sub_pixel_variance8x8) |
| 2749 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 2750 | aom_obmc_sub_pixel_variance4x8) |
| 2751 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 2752 | aom_obmc_sub_pixel_variance8x4) |
| 2753 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 2754 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2755 | |
| 2756 | #if CONFIG_EXT_PARTITION_TYPES |
| 2757 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 2758 | aom_obmc_sub_pixel_variance4x16) |
| 2759 | |
| 2760 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 2761 | aom_obmc_sub_pixel_variance16x4) |
| 2762 | |
| 2763 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 2764 | aom_obmc_sub_pixel_variance8x32) |
| 2765 | |
| 2766 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 2767 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2768 | |
| 2769 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 2770 | aom_obmc_sub_pixel_variance16x64) |
| 2771 | |
| 2772 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 2773 | aom_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2774 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2775 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2776 | |
| 2777 | #if CONFIG_EXT_INTER |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2778 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 2779 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 2780 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2781 | |
| 2782 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2783 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 2784 | aom_masked_sub_pixel_variance128x128) |
| 2785 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 2786 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2787 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2788 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 2789 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 2790 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 2791 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 2792 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 2793 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 2794 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 2795 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 2796 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 2797 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 2798 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 2799 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 2800 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2801 | |
| 2802 | #if CONFIG_EXT_PARTITION_TYPES |
| 2803 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 2804 | |
| 2805 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 2806 | |
| 2807 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 2808 | |
| 2809 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2810 | |
| 2811 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 2812 | |
| 2813 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2814 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2815 | #endif // CONFIG_EXT_INTER |
| 2816 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2817 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2818 | highbd_set_var_fns(cpi); |
| 2819 | #endif |
| 2820 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2821 | /* av1_init_quantizer() is first called here. Add check in |
| 2822 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2823 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2824 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2825 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2826 | av1_init_quantizer(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2827 | #if CONFIG_AOM_QM |
| 2828 | aom_qm_init(cm); |
| 2829 | #endif |
| 2830 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2831 | av1_loop_filter_init(cm); |
Fergus Simpson | dac6aff | 2017-05-18 15:11:38 -0700 | [diff] [blame] | 2832 | #if CONFIG_FRAME_SUPERRES |
Fergus Simpson | bfbf6a5 | 2017-06-14 23:13:12 -0700 | [diff] [blame] | 2833 | cm->superres_scale_numerator = SCALE_DENOMINATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 2834 | cm->superres_upscaled_width = oxcf->width; |
| 2835 | cm->superres_upscaled_height = oxcf->height; |
Fergus Simpson | dac6aff | 2017-05-18 15:11:38 -0700 | [diff] [blame] | 2836 | #endif // CONFIG_FRAME_SUPERRES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2837 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2838 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2839 | #endif // CONFIG_LOOP_RESTORATION |
| 2840 | |
| 2841 | cm->error.setjmp = 0; |
| 2842 | |
| 2843 | return cpi; |
| 2844 | } |
| 2845 | |
| 2846 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 2847 | |
| 2848 | #define SNPRINT2(H, T, V) \ |
| 2849 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
| 2850 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2851 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 2852 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2853 | unsigned int i; |
| 2854 | int t; |
| 2855 | |
| 2856 | if (!cpi) return; |
| 2857 | |
| 2858 | cm = &cpi->common; |
| 2859 | if (cm->current_video_frame > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2860 | #if CONFIG_ENTROPY_STATS |
| 2861 | if (cpi->oxcf.pass != 1) { |
| 2862 | fprintf(stderr, "Writing counts.stt\n"); |
| 2863 | FILE *f = fopen("counts.stt", "wb"); |
| 2864 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 2865 | fwrite(aggregate_fc_per_type, sizeof(aggregate_fc_per_type[0]), |
| 2866 | FRAME_CONTEXTS, f); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2867 | fclose(f); |
| 2868 | } |
| 2869 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2870 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2871 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2872 | |
| 2873 | if (cpi->oxcf.pass != 1) { |
| 2874 | char headings[512] = { 0 }; |
| 2875 | char results[512] = { 0 }; |
| 2876 | FILE *f = fopen("opsnr.stt", "a"); |
| 2877 | double time_encoded = |
| 2878 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 2879 | 10000000.000; |
| 2880 | double total_encode_time = |
| 2881 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 2882 | const double dr = |
| 2883 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 2884 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 2885 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 2886 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 2887 | |
| 2888 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2889 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2890 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 2891 | const double total_ssim = |
| 2892 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 2893 | snprintf(headings, sizeof(headings), |
| 2894 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2895 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2896 | "WstPsnr\tWstSsim\tWstFast\tWstHVS"); |
| 2897 | snprintf(results, sizeof(results), |
| 2898 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 2899 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 2900 | "%7.3f\t%7.3f\t%7.3f\t%7.3f", |
| 2901 | dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr, |
| 2902 | cpi->psnr.stat[ALL] / cpi->count, total_psnr, total_ssim, |
| 2903 | total_ssim, cpi->fastssim.stat[ALL] / cpi->count, |
| 2904 | cpi->psnrhvs.stat[ALL] / cpi->count, cpi->psnr.worst, |
| 2905 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst); |
| 2906 | |
| 2907 | if (cpi->b_calculate_blockiness) { |
| 2908 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 2909 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 2910 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 2911 | } |
| 2912 | |
| 2913 | if (cpi->b_calculate_consistency) { |
| 2914 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2915 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2916 | (double)cpi->total_inconsistency); |
| 2917 | |
| 2918 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 2919 | SNPRINT2(results, "\t%7.3f", consistency); |
| 2920 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 2921 | } |
Sarah Parker | f97b786 | 2016-08-25 17:42:57 -0700 | [diff] [blame] | 2922 | fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings); |
| 2923 | 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] | 2924 | rate_err, fabs(rate_err)); |
| 2925 | } |
| 2926 | |
| 2927 | fclose(f); |
| 2928 | } |
| 2929 | |
| 2930 | #endif |
| 2931 | |
| 2932 | #if 0 |
| 2933 | { |
| 2934 | printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); |
| 2935 | printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); |
| 2936 | printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, |
| 2937 | cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, |
| 2938 | cpi->time_compress_data / 1000, |
| 2939 | (cpi->time_receive_data + cpi->time_compress_data) / 1000); |
| 2940 | } |
| 2941 | #endif |
| 2942 | } |
| 2943 | |
| 2944 | for (t = 0; t < cpi->num_workers; ++t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2945 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2946 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 2947 | |
| 2948 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2949 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2950 | |
| 2951 | // Deallocate allocated thread data. |
| 2952 | if (t < cpi->num_workers - 1) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2953 | aom_free(thread_data->td->palette_buffer); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2954 | #if CONFIG_MOTION_VAR |
| 2955 | aom_free(thread_data->td->above_pred_buf); |
| 2956 | aom_free(thread_data->td->left_pred_buf); |
| 2957 | aom_free(thread_data->td->wsrc_buf); |
| 2958 | aom_free(thread_data->td->mask_buf); |
| 2959 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2960 | aom_free(thread_data->td->counts); |
| 2961 | av1_free_pc_tree(thread_data->td); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2962 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2963 | } |
| 2964 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2965 | aom_free(cpi->tile_thr_data); |
| 2966 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2967 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2968 | 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] | 2969 | |
| 2970 | dealloc_compressor_data(cpi); |
| 2971 | |
| 2972 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 2973 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2974 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2975 | } |
| 2976 | |
| 2977 | #if CONFIG_FP_MB_STATS |
| 2978 | if (cpi->use_fp_mb_stats) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2979 | aom_free(cpi->twopass.frame_mb_stats_buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2980 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2981 | } |
| 2982 | #endif |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 2983 | #if CONFIG_INTERNAL_STATS |
| 2984 | aom_free(cpi->ssim_vars); |
| 2985 | cpi->ssim_vars = NULL; |
| 2986 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2987 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2988 | av1_remove_common(cm); |
| 2989 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 2990 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2991 | |
| 2992 | #ifdef OUTPUT_YUV_SKINMAP |
| 2993 | fclose(yuv_skinmap_file); |
| 2994 | #endif |
| 2995 | #ifdef OUTPUT_YUV_REC |
| 2996 | fclose(yuv_rec_file); |
| 2997 | #endif |
| 2998 | |
| 2999 | #if 0 |
| 3000 | |
| 3001 | if (keyfile) |
| 3002 | fclose(keyfile); |
| 3003 | |
| 3004 | if (framepsnr) |
| 3005 | fclose(framepsnr); |
| 3006 | |
| 3007 | if (kf_list) |
| 3008 | fclose(kf_list); |
| 3009 | |
| 3010 | #endif |
| 3011 | } |
| 3012 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3013 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 3014 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3015 | int i; |
| 3016 | PSNR_STATS psnr; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3017 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3018 | aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3019 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
| 3020 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3021 | aom_calc_psnr(cpi->source, cpi->common.frame_to_show, &psnr); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3022 | #endif |
| 3023 | |
| 3024 | for (i = 0; i < 4; ++i) { |
| 3025 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 3026 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 3027 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 3028 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3029 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 3030 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3031 | } |
| 3032 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3033 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3034 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 3035 | |
| 3036 | cpi->ref_frame_flags = ref_frame_flags; |
| 3037 | return 0; |
| 3038 | } |
| 3039 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3040 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags) { |
| 3041 | cpi->ext_refresh_golden_frame = (ref_frame_flags & AOM_GOLD_FLAG) != 0; |
| 3042 | cpi->ext_refresh_alt_ref_frame = (ref_frame_flags & AOM_ALT_FLAG) != 0; |
| 3043 | cpi->ext_refresh_last_frame = (ref_frame_flags & AOM_LAST_FLAG) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3044 | cpi->ext_refresh_frame_flags_pending = 1; |
| 3045 | } |
| 3046 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3047 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3048 | AV1_COMMON *const cm = &cpi->common; |
| 3049 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3050 | if (cfg) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3051 | aom_yv12_copy_frame(cfg, sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3052 | return 0; |
| 3053 | } else { |
| 3054 | return -1; |
| 3055 | } |
| 3056 | } |
| 3057 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3058 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3059 | AV1_COMMON *const cm = &cpi->common; |
| 3060 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3061 | if (cfg) { |
| 3062 | aom_yv12_copy_frame(sd, cfg); |
| 3063 | return 0; |
| 3064 | } else { |
| 3065 | return -1; |
| 3066 | } |
| 3067 | } |
| 3068 | |
| 3069 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3070 | cpi->ext_refresh_frame_context = update; |
| 3071 | cpi->ext_refresh_frame_context_pending = 1; |
| 3072 | return 0; |
| 3073 | } |
| 3074 | |
| 3075 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 3076 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 3077 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 3078 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 3079 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3080 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3081 | uint8_t *src = s->y_buffer; |
| 3082 | int h = s->y_height; |
| 3083 | |
| 3084 | do { |
| 3085 | fwrite(src, s->y_width, 1, f); |
| 3086 | src += s->y_stride; |
| 3087 | } while (--h); |
| 3088 | |
| 3089 | src = s->u_buffer; |
| 3090 | h = s->uv_height; |
| 3091 | |
| 3092 | do { |
| 3093 | fwrite(src, s->uv_width, 1, f); |
| 3094 | src += s->uv_stride; |
| 3095 | } while (--h); |
| 3096 | |
| 3097 | src = s->v_buffer; |
| 3098 | h = s->uv_height; |
| 3099 | |
| 3100 | do { |
| 3101 | fwrite(src, s->uv_width, 1, f); |
| 3102 | src += s->uv_stride; |
| 3103 | } while (--h); |
| 3104 | } |
| 3105 | #endif |
| 3106 | |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 3107 | #if CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3108 | static void check_show_existing_frame(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3109 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3110 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3111 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 3112 | gf_group->update_type[gf_group->index]; |
| 3113 | const int which_arf = gf_group->arf_update_idx[gf_group->index]; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3114 | |
| 3115 | if (cm->show_existing_frame == 1) { |
| 3116 | cm->show_existing_frame = 0; |
| 3117 | } else if (cpi->rc.is_last_bipred_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3118 | // NOTE(zoeliu): If the current frame is a last bi-predictive frame, it is |
| 3119 | // needed next to show the BWDREF_FRAME, which is pointed by |
| 3120 | // the last_fb_idxes[0] after reference frame buffer update |
| 3121 | cpi->rc.is_last_bipred_frame = 0; |
| 3122 | cm->show_existing_frame = 1; |
| 3123 | cpi->existing_fb_idx_to_show = cpi->lst_fb_idxes[0]; |
| 3124 | } else if (cpi->is_arf_filter_off[which_arf] && |
| 3125 | (next_frame_update_type == OVERLAY_UPDATE || |
| 3126 | next_frame_update_type == INTNL_OVERLAY_UPDATE)) { |
| 3127 | // Other parameters related to OVERLAY_UPDATE will be taken care of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3128 | // in av1_rc_get_second_pass_params(cpi) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3129 | cm->show_existing_frame = 1; |
| 3130 | cpi->rc.is_src_frame_alt_ref = 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3131 | #if CONFIG_ALTREF2 |
| 3132 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
| 3133 | ? cpi->alt_fb_idx |
| 3134 | : cpi->alt2_fb_idx; |
| 3135 | #else // !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3136 | cpi->existing_fb_idx_to_show = cpi->alt_fb_idx; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3137 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3138 | cpi->is_arf_filter_off[which_arf] = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3139 | } |
| 3140 | cpi->rc.is_src_frame_ext_arf = 0; |
| 3141 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 3142 | #endif // CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3143 | |
| 3144 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3145 | 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] | 3146 | uint8_t *src = s->y_buffer; |
| 3147 | int h = cm->height; |
| 3148 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3149 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3150 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 3151 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 3152 | |
| 3153 | do { |
| 3154 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 3155 | src16 += s->y_stride; |
| 3156 | } while (--h); |
| 3157 | |
| 3158 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 3159 | h = s->uv_height; |
| 3160 | |
| 3161 | do { |
| 3162 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3163 | src16 += s->uv_stride; |
| 3164 | } while (--h); |
| 3165 | |
| 3166 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 3167 | h = s->uv_height; |
| 3168 | |
| 3169 | do { |
| 3170 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3171 | src16 += s->uv_stride; |
| 3172 | } while (--h); |
| 3173 | |
| 3174 | fflush(yuv_rec_file); |
| 3175 | return; |
| 3176 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3177 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3178 | |
| 3179 | do { |
| 3180 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 3181 | src += s->y_stride; |
| 3182 | } while (--h); |
| 3183 | |
| 3184 | src = s->u_buffer; |
| 3185 | h = s->uv_height; |
| 3186 | |
| 3187 | do { |
| 3188 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3189 | src += s->uv_stride; |
| 3190 | } while (--h); |
| 3191 | |
| 3192 | src = s->v_buffer; |
| 3193 | h = s->uv_height; |
| 3194 | |
| 3195 | do { |
| 3196 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3197 | src += s->uv_stride; |
| 3198 | } while (--h); |
| 3199 | |
| 3200 | fflush(yuv_rec_file); |
| 3201 | } |
| 3202 | #endif // OUTPUT_YUV_REC |
| 3203 | |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3204 | #if CONFIG_GLOBAL_MOTION |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 3205 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3206 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 3207 | int i; |
| 3208 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3209 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3210 | AV1_COMMON *const cm = &cpi->common; |
| 3211 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3212 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3213 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3214 | cpi->gmparams_cost[i]) { |
Sarah Parker | 4c10a3c | 2017-04-10 19:37:59 -0700 | [diff] [blame] | 3215 | set_default_warp_params(&cm->global_motion[i]); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3216 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 3217 | recode = 1; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3218 | recode |= (rdc->global_motion_used[i] > 0); |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3219 | } |
| 3220 | } |
| 3221 | return recode; |
| 3222 | } |
| 3223 | #endif // CONFIG_GLOBAL_MOTION |
| 3224 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3225 | // Function to test for conditions that indicate we should loop |
| 3226 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3227 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 3228 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3229 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3230 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3231 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 3232 | int force_recode = 0; |
| 3233 | |
| 3234 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 3235 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 3236 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3237 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 3238 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 3239 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 3240 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3241 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3242 | // Deal with frame undershoot and whether or not we are |
| 3243 | // below the automatically set cq level. |
| 3244 | if (q > oxcf->cq_level && |
| 3245 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 3246 | force_recode = 1; |
| 3247 | } |
| 3248 | } |
| 3249 | } |
| 3250 | return force_recode; |
| 3251 | } |
| 3252 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3253 | #define DUMP_REF_FRAME_IMAGES 0 |
| 3254 | |
| 3255 | #if DUMP_REF_FRAME_IMAGES == 1 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3256 | static int dump_one_image(AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3257 | const YV12_BUFFER_CONFIG *const ref_buf, |
| 3258 | char *file_name) { |
| 3259 | int h; |
| 3260 | FILE *f_ref = NULL; |
| 3261 | |
| 3262 | if (ref_buf == NULL) { |
| 3263 | printf("Frame data buffer is NULL.\n"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3264 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | if ((f_ref = fopen(file_name, "wb")) == NULL) { |
| 3268 | printf("Unable to open file %s to write.\n", file_name); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3269 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | // --- Y --- |
| 3273 | for (h = 0; h < cm->height; ++h) { |
| 3274 | fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref); |
| 3275 | } |
| 3276 | // --- U --- |
| 3277 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3278 | fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3279 | f_ref); |
| 3280 | } |
| 3281 | // --- V --- |
| 3282 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3283 | fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3284 | f_ref); |
| 3285 | } |
| 3286 | |
| 3287 | fclose(f_ref); |
| 3288 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3289 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3290 | } |
| 3291 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3292 | static void dump_ref_frame_images(AV1_COMP *cpi) { |
| 3293 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3294 | MV_REFERENCE_FRAME ref_frame; |
| 3295 | |
| 3296 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3297 | char file_name[256] = ""; |
| 3298 | snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv", |
| 3299 | cm->current_video_frame, ref_frame); |
| 3300 | dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name); |
| 3301 | } |
| 3302 | } |
| 3303 | #endif // DUMP_REF_FRAME_IMAGES == 1 |
| 3304 | |
| 3305 | #if CONFIG_EXT_REFS |
| 3306 | // This function is used to shift the virtual indices of last reference frames |
| 3307 | // as follows: |
| 3308 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3309 | // when the LAST_FRAME is updated. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3310 | static INLINE void shift_last_ref_frames(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3311 | int ref_frame; |
| 3312 | for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) { |
| 3313 | cpi->lst_fb_idxes[ref_frame] = cpi->lst_fb_idxes[ref_frame - 1]; |
| 3314 | |
| 3315 | // [0] is allocated to the current coded frame. The statistics for the |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3316 | // reference frames start at [LAST_FRAME], i.e. [1]. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3317 | if (!cpi->rc.is_src_frame_alt_ref) { |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3318 | memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME], |
| 3319 | cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME], |
| 3320 | sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3321 | } |
| 3322 | } |
| 3323 | } |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3324 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3325 | |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 3326 | #if CONFIG_VAR_REFS |
| 3327 | static void enc_check_valid_ref_frames(AV1_COMP *const cpi) { |
| 3328 | AV1_COMMON *const cm = &cpi->common; |
| 3329 | MV_REFERENCE_FRAME ref_frame; |
| 3330 | |
| 3331 | // TODO(zoeliu): To handle ALTREF_FRAME the same way as do with other |
| 3332 | // reference frames. Current encoder invalid ALTREF when ALTREF |
| 3333 | // is the same as LAST, but invalid all the other references |
| 3334 | // when they are the same as ALTREF. |
| 3335 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3336 | int ref_buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3337 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 3338 | |
| 3339 | if (ref_buf_idx != INVALID_IDX) { |
| 3340 | ref_buf->is_valid = 1; |
| 3341 | |
| 3342 | MV_REFERENCE_FRAME ref; |
| 3343 | for (ref = LAST_FRAME; ref < ref_frame; ++ref) { |
| 3344 | int buf_idx = get_ref_frame_buf_idx(cpi, ref); |
| 3345 | RefBuffer *const buf = &cm->frame_refs[ref - LAST_FRAME]; |
| 3346 | if (buf->is_valid && buf_idx == ref_buf_idx) { |
| 3347 | if (ref_frame != ALTREF_FRAME || ref == LAST_FRAME) { |
| 3348 | ref_buf->is_valid = 0; |
| 3349 | break; |
| 3350 | } else { |
| 3351 | buf->is_valid = 0; |
| 3352 | } |
| 3353 | } |
| 3354 | } |
| 3355 | } else { |
| 3356 | ref_buf->is_valid = 0; |
| 3357 | } |
| 3358 | } |
| 3359 | } |
| 3360 | #endif // CONFIG_VAR_REFS |
| 3361 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3362 | void av1_update_reference_frames(AV1_COMP *cpi) { |
| 3363 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3364 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3365 | |
| 3366 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 3367 | // for the purpose to verify no mismatch between encoder and decoder. |
| 3368 | if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx; |
| 3369 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3370 | // At this point the new frame has been encoded. |
| 3371 | // If any buffer copy / swapping is signaled it should be done here. |
| 3372 | if (cm->frame_type == KEY_FRAME) { |
| 3373 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3374 | cm->new_fb_idx); |
| 3375 | #if CONFIG_EXT_REFS |
| 3376 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3377 | cm->new_fb_idx); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3378 | #if CONFIG_ALTREF2 |
| 3379 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3380 | cm->new_fb_idx); |
| 3381 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3382 | #endif // CONFIG_EXT_REFS |
| 3383 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3384 | cm->new_fb_idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3385 | } else if (av1_preserve_existing_gf(cpi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3386 | // We have decided to preserve the previously existing golden frame as our |
| 3387 | // new ARF frame. However, in the short term in function |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3388 | // 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] | 3389 | // we're updating the GF with the current decoded frame, we save it to the |
| 3390 | // ARF slot instead. |
| 3391 | // We now have to update the ARF with the current frame and swap gld_fb_idx |
| 3392 | // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF |
| 3393 | // slot and, if we're updating the GF, the current frame becomes the new GF. |
| 3394 | int tmp; |
| 3395 | |
| 3396 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3397 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3398 | tmp = cpi->alt_fb_idx; |
| 3399 | cpi->alt_fb_idx = cpi->gld_fb_idx; |
| 3400 | cpi->gld_fb_idx = tmp; |
| 3401 | |
| 3402 | #if CONFIG_EXT_REFS |
| 3403 | // We need to modify the mapping accordingly |
| 3404 | cpi->arf_map[0] = cpi->alt_fb_idx; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3405 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3406 | // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to |
| 3407 | // cpi->interp_filter_selected[GOLDEN_FRAME]? |
| 3408 | #if CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3409 | } else if (cpi->rc.is_src_frame_ext_arf && cm->show_existing_frame) { |
| 3410 | // Deal with the special case for showing existing internal ALTREF_FRAME |
| 3411 | // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME |
| 3412 | // by updating the virtual indices. |
| 3413 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3414 | const int which_arf = gf_group->arf_ref_idx[gf_group->index]; |
| 3415 | assert(gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3416 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3417 | const int tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3418 | shift_last_ref_frames(cpi); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3419 | |
| 3420 | #if CONFIG_ALTREF2 |
| 3421 | cpi->lst_fb_idxes[0] = cpi->alt2_fb_idx; |
| 3422 | cpi->alt2_fb_idx = tmp; |
| 3423 | // We need to modify the mapping accordingly |
| 3424 | cpi->arf_map[which_arf] = cpi->alt2_fb_idx; |
| 3425 | |
| 3426 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3427 | cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3428 | sizeof(cpi->interp_filter_selected[ALTREF2_FRAME])); |
| 3429 | #else // !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3430 | cpi->lst_fb_idxes[0] = cpi->alt_fb_idx; |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3431 | cpi->alt_fb_idx = tmp; |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3432 | // We need to modify the mapping accordingly |
| 3433 | cpi->arf_map[which_arf] = cpi->alt_fb_idx; |
| 3434 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3435 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3436 | cpi->interp_filter_selected[ALTREF_FRAME + which_arf], |
| 3437 | sizeof(cpi->interp_filter_selected[ALTREF_FRAME + which_arf])); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3438 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3439 | #endif // CONFIG_EXT_REFS |
| 3440 | } else { /* For non key/golden frames */ |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3441 | // === ALTREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3442 | if (cpi->refresh_alt_ref_frame) { |
| 3443 | int arf_idx = cpi->alt_fb_idx; |
| 3444 | int which_arf = 0; |
| 3445 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3446 | #if !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3447 | if (cpi->oxcf.pass == 2) { |
| 3448 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3449 | which_arf = gf_group->arf_update_idx[gf_group->index]; |
| 3450 | arf_idx = cpi->arf_map[which_arf]; |
| 3451 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3452 | #endif // !CONFIG_ALTREF2 |
| 3453 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3454 | if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { |
| 3455 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3456 | arf_idx = gf_group->arf_update_idx[gf_group->index]; |
| 3457 | } |
| 3458 | #endif // CONFIG_EXT_REFS |
| 3459 | 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] | 3460 | |
| 3461 | memcpy(cpi->interp_filter_selected[ALTREF_FRAME + which_arf], |
| 3462 | cpi->interp_filter_selected[0], |
| 3463 | sizeof(cpi->interp_filter_selected[0])); |
| 3464 | } |
| 3465 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3466 | // === GOLDEN_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3467 | if (cpi->refresh_golden_frame) { |
| 3468 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3469 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3470 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3471 | #if !CONFIG_EXT_REFS |
| 3472 | if (!cpi->rc.is_src_frame_alt_ref) |
| 3473 | #endif // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3474 | memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], |
| 3475 | cpi->interp_filter_selected[0], |
| 3476 | sizeof(cpi->interp_filter_selected[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3480 | // === BWDREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3481 | if (cpi->refresh_bwd_ref_frame) { |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3482 | #if !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3483 | if (cpi->rc.is_bwd_ref_frame && cpi->num_extra_arfs) { |
| 3484 | // We have swapped the virtual indices to allow bwd_ref_frame to use |
| 3485 | // ALT0 as reference frame. We need to swap them back. |
| 3486 | // NOTE: The ALT_REFs' are indexed reversely, and ALT0 refers to the |
| 3487 | // farthest ALT_REF from the first frame in the gf group. |
| 3488 | int tmp = cpi->arf_map[0]; |
| 3489 | cpi->arf_map[0] = cpi->alt_fb_idx; |
| 3490 | cpi->alt_fb_idx = cpi->bwd_fb_idx; |
| 3491 | cpi->bwd_fb_idx = tmp; |
| 3492 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3493 | #endif // !CONFIG_ALTREF2 |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3494 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3495 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3496 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3497 | |
| 3498 | memcpy(cpi->interp_filter_selected[BWDREF_FRAME], |
| 3499 | cpi->interp_filter_selected[0], |
| 3500 | sizeof(cpi->interp_filter_selected[0])); |
| 3501 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3502 | |
| 3503 | #if CONFIG_ALTREF2 |
| 3504 | // === ALTREF2_FRAME === |
| 3505 | if (cpi->refresh_alt2_ref_frame) { |
| 3506 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3507 | cm->new_fb_idx); |
| 3508 | |
| 3509 | memcpy(cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3510 | cpi->interp_filter_selected[0], |
| 3511 | sizeof(cpi->interp_filter_selected[0])); |
| 3512 | } |
| 3513 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3514 | #endif // CONFIG_EXT_REFS |
| 3515 | } |
| 3516 | |
| 3517 | if (cpi->refresh_last_frame) { |
| 3518 | #if CONFIG_EXT_REFS |
| 3519 | // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame |
| 3520 | // reference to the reference frame buffer virtual index; and then (2) from |
| 3521 | // the virtual index to the reference frame buffer physical index: |
| 3522 | // |
| 3523 | // LAST_FRAME, ..., LAST3_FRAME, ..., ALTREF_FRAME |
| 3524 | // | | | |
| 3525 | // v v v |
| 3526 | // lst_fb_idxes[0], ..., lst_fb_idxes[2], ..., alt_fb_idx |
| 3527 | // | | | |
| 3528 | // v v v |
| 3529 | // ref_frame_map[], ..., ref_frame_map[], ..., ref_frame_map[] |
| 3530 | // |
| 3531 | // When refresh_last_frame is set, it is intended to retire LAST3_FRAME, |
| 3532 | // have the other 2 LAST reference frames shifted as follows: |
| 3533 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3534 | // , and then have LAST_FRAME refreshed by the newly coded frame. |
| 3535 | // |
| 3536 | // To fulfill it, the decoder will be notified to execute following 2 steps: |
| 3537 | // |
| 3538 | // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME |
| 3539 | // to point to the newly coded frame, i.e. |
| 3540 | // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx; |
| 3541 | // |
| 3542 | // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the |
| 3543 | // original virtual index of LAST3_FRAME and have the other mappings |
| 3544 | // shifted as follows: |
| 3545 | // LAST_FRAME, LAST2_FRAME, LAST3_FRAME |
| 3546 | // | | | |
| 3547 | // v v v |
| 3548 | // lst_fb_idxes[2], lst_fb_idxes[0], lst_fb_idxes[1] |
| 3549 | int ref_frame; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3550 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3551 | #if !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3552 | if (cpi->rc.is_bwd_ref_frame && cpi->num_extra_arfs) { |
| 3553 | // We have swapped the virtual indices to use ALT0 as BWD_REF |
| 3554 | // and we need to swap them back. |
| 3555 | int tmp = cpi->arf_map[0]; |
| 3556 | cpi->arf_map[0] = cpi->alt_fb_idx; |
| 3557 | cpi->alt_fb_idx = cpi->bwd_fb_idx; |
| 3558 | cpi->bwd_fb_idx = tmp; |
| 3559 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3560 | #endif // !CONFIG_ALTREF2 |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3561 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3562 | if (cm->frame_type == KEY_FRAME) { |
| 3563 | for (ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) { |
| 3564 | ref_cnt_fb(pool->frame_bufs, |
| 3565 | &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]], |
| 3566 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3567 | } |
| 3568 | } else { |
| 3569 | int tmp; |
| 3570 | |
| 3571 | ref_cnt_fb(pool->frame_bufs, |
| 3572 | &cm->ref_frame_map[cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]], |
| 3573 | cm->new_fb_idx); |
| 3574 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3575 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3576 | |
| 3577 | shift_last_ref_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3578 | cpi->lst_fb_idxes[0] = tmp; |
| 3579 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3580 | assert(cm->show_existing_frame == 0); |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3581 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3582 | cpi->interp_filter_selected[0], |
| 3583 | sizeof(cpi->interp_filter_selected[0])); |
Zoe Liu | aff92d5 | 2017-07-11 21:35:08 -0700 | [diff] [blame] | 3584 | |
| 3585 | if (cpi->rc.is_last_bipred_frame) { |
| 3586 | // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the |
| 3587 | // LAST3_FRAME by updating the virtual indices. |
| 3588 | // |
| 3589 | // NOTE: The source frame for BWDREF does not have a holding position as |
| 3590 | // the OVERLAY frame for ALTREF's. Hence, to resolve the reference |
| 3591 | // virtual index reshuffling for BWDREF, the encoder always |
| 3592 | // specifies a LAST_BIPRED right before BWDREF and completes the |
| 3593 | // reshuffling job accordingly. |
| 3594 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3595 | |
| 3596 | shift_last_ref_frames(cpi); |
| 3597 | cpi->lst_fb_idxes[0] = cpi->bwd_fb_idx; |
| 3598 | cpi->bwd_fb_idx = tmp; |
| 3599 | |
| 3600 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3601 | cpi->interp_filter_selected[BWDREF_FRAME], |
| 3602 | sizeof(cpi->interp_filter_selected[BWDREF_FRAME])); |
| 3603 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3604 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3605 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3606 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->lst_fb_idx], |
| 3607 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3608 | if (!cpi->rc.is_src_frame_alt_ref) { |
| 3609 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3610 | cpi->interp_filter_selected[0], |
| 3611 | sizeof(cpi->interp_filter_selected[0])); |
| 3612 | } |
| 3613 | #endif // CONFIG_EXT_REFS |
| 3614 | } |
| 3615 | |
| 3616 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3617 | // Dump out all reference frame images. |
| 3618 | dump_ref_frame_images(cpi); |
| 3619 | #endif // DUMP_REF_FRAME_IMAGES |
| 3620 | } |
| 3621 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3622 | 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] | 3623 | assert(buffer_idx != INVALID_IDX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3624 | RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 3625 | ensure_mv_buffer(new_fb_ptr, cm); |
| 3626 | new_fb_ptr->width = cm->width; |
| 3627 | new_fb_ptr->height = cm->height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3630 | void av1_scale_references(AV1_COMP *cpi) { |
| 3631 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3632 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3633 | const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = { |
| 3634 | AOM_LAST_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3635 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3636 | AOM_LAST2_FLAG, |
| 3637 | AOM_LAST3_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3638 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3639 | AOM_GOLD_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3640 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3641 | AOM_BWD_FLAG, |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3642 | #if CONFIG_ALTREF2 |
| 3643 | AOM_ALT2_FLAG, |
| 3644 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3645 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3646 | AOM_ALT_FLAG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3647 | }; |
| 3648 | |
| 3649 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3650 | // 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] | 3651 | if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 3652 | BufferPool *const pool = cm->buffer_pool; |
| 3653 | const YV12_BUFFER_CONFIG *const ref = |
| 3654 | get_ref_frame_buffer(cpi, ref_frame); |
| 3655 | |
| 3656 | if (ref == NULL) { |
| 3657 | cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3658 | continue; |
| 3659 | } |
| 3660 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3661 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3662 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3663 | RefCntBuffer *new_fb_ptr = NULL; |
| 3664 | int force_scaling = 0; |
| 3665 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3666 | if (new_fb == INVALID_IDX) { |
| 3667 | new_fb = get_free_fb(cm); |
| 3668 | force_scaling = 1; |
| 3669 | } |
| 3670 | if (new_fb == INVALID_IDX) return; |
| 3671 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3672 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3673 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3674 | if (aom_realloc_frame_buffer( |
| 3675 | &new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x, |
| 3676 | cm->subsampling_y, cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 3677 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3678 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3679 | "Failed to allocate frame buffer"); |
Debargha Mukherjee | 405c857 | 2017-07-10 09:29:17 -0700 | [diff] [blame] | 3680 | av1_resize_and_extend_frame(ref, &new_fb_ptr->buf, |
| 3681 | (int)cm->bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3682 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3683 | alloc_frame_mvs(cm, new_fb); |
| 3684 | } |
| 3685 | #else |
| 3686 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3687 | RefCntBuffer *new_fb_ptr = NULL; |
| 3688 | int force_scaling = 0; |
| 3689 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3690 | if (new_fb == INVALID_IDX) { |
| 3691 | new_fb = get_free_fb(cm); |
| 3692 | force_scaling = 1; |
| 3693 | } |
| 3694 | if (new_fb == INVALID_IDX) return; |
| 3695 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3696 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3697 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3698 | 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] | 3699 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3700 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
| 3701 | NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3702 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3703 | "Failed to allocate frame buffer"); |
Debargha Mukherjee | 405c857 | 2017-07-10 09:29:17 -0700 | [diff] [blame] | 3704 | av1_resize_and_extend_frame(ref, &new_fb_ptr->buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3705 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3706 | alloc_frame_mvs(cm, new_fb); |
| 3707 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3708 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3709 | } else { |
| 3710 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3711 | RefCntBuffer *const buf = &pool->frame_bufs[buf_idx]; |
| 3712 | buf->buf.y_crop_width = ref->y_crop_width; |
| 3713 | buf->buf.y_crop_height = ref->y_crop_height; |
| 3714 | cpi->scaled_ref_idx[ref_frame - 1] = buf_idx; |
| 3715 | ++buf->ref_count; |
| 3716 | } |
| 3717 | } else { |
| 3718 | if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3719 | } |
| 3720 | } |
| 3721 | } |
| 3722 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3723 | static void release_scaled_references(AV1_COMP *cpi) { |
| 3724 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3725 | int i; |
| 3726 | if (cpi->oxcf.pass == 0) { |
| 3727 | // Only release scaled references under certain conditions: |
| 3728 | // if reference will be updated, or if scaled reference has same resolution. |
| 3729 | int refresh[INTER_REFS_PER_FRAME]; |
| 3730 | refresh[0] = (cpi->refresh_last_frame) ? 1 : 0; |
| 3731 | #if CONFIG_EXT_REFS |
| 3732 | refresh[1] = refresh[2] = 0; |
| 3733 | refresh[3] = (cpi->refresh_golden_frame) ? 1 : 0; |
| 3734 | refresh[4] = (cpi->refresh_bwd_ref_frame) ? 1 : 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3735 | #if CONFIG_ALTREF2 |
| 3736 | refresh[5] = (cpi->refresh_alt2_ref_frame) ? 1 : 0; |
| 3737 | refresh[6] = (cpi->refresh_alt_ref_frame) ? 1 : 0; |
| 3738 | #else // !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3739 | refresh[5] = (cpi->refresh_alt_ref_frame) ? 1 : 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3740 | #endif // CONFIG_ALTREF2 |
| 3741 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3742 | refresh[1] = (cpi->refresh_golden_frame) ? 1 : 0; |
| 3743 | refresh[2] = (cpi->refresh_alt_ref_frame) ? 1 : 0; |
| 3744 | #endif // CONFIG_EXT_REFS |
| 3745 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3746 | const int idx = cpi->scaled_ref_idx[i - 1]; |
| 3747 | RefCntBuffer *const buf = |
| 3748 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 3749 | const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, i); |
| 3750 | if (buf != NULL && |
| 3751 | (refresh[i - 1] || (buf->buf.y_crop_width == ref->y_crop_width && |
| 3752 | buf->buf.y_crop_height == ref->y_crop_height))) { |
| 3753 | --buf->ref_count; |
| 3754 | cpi->scaled_ref_idx[i - 1] = INVALID_IDX; |
| 3755 | } |
| 3756 | } |
| 3757 | } else { |
| 3758 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) { |
| 3759 | const int idx = cpi->scaled_ref_idx[i]; |
| 3760 | RefCntBuffer *const buf = |
| 3761 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 3762 | if (buf != NULL) { |
| 3763 | --buf->ref_count; |
| 3764 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 3765 | } |
| 3766 | } |
| 3767 | } |
| 3768 | } |
| 3769 | |
| 3770 | static void full_to_model_count(unsigned int *model_count, |
| 3771 | unsigned int *full_count) { |
| 3772 | int n; |
| 3773 | model_count[ZERO_TOKEN] = full_count[ZERO_TOKEN]; |
| 3774 | model_count[ONE_TOKEN] = full_count[ONE_TOKEN]; |
| 3775 | model_count[TWO_TOKEN] = full_count[TWO_TOKEN]; |
| 3776 | for (n = THREE_TOKEN; n < EOB_TOKEN; ++n) |
| 3777 | model_count[TWO_TOKEN] += full_count[n]; |
| 3778 | model_count[EOB_MODEL_TOKEN] = full_count[EOB_TOKEN]; |
| 3779 | } |
| 3780 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3781 | void av1_full_to_model_counts(av1_coeff_count_model *model_count, |
| 3782 | av1_coeff_count *full_count) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3783 | int i, j, k, l; |
| 3784 | |
| 3785 | for (i = 0; i < PLANE_TYPES; ++i) |
| 3786 | for (j = 0; j < REF_TYPES; ++j) |
| 3787 | for (k = 0; k < COEF_BANDS; ++k) |
| 3788 | for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) |
| 3789 | full_to_model_count(model_count[i][j][k][l], full_count[i][j][k][l]); |
| 3790 | } |
| 3791 | |
| 3792 | #if 0 && CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3793 | static void output_frame_level_debug_stats(AV1_COMP *cpi) { |
| 3794 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3795 | FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); |
| 3796 | int64_t recon_err; |
| 3797 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3798 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3799 | |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3800 | 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] | 3801 | |
| 3802 | if (cpi->twopass.total_left_stats.coded_error != 0.0) |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 3803 | fprintf(f, "%10u %dx%d %d %d %10d %10d %10d %10d" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3804 | "%10"PRId64" %10"PRId64" %5d %5d %10"PRId64" " |
| 3805 | "%10"PRId64" %10"PRId64" %10d " |
| 3806 | "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" |
| 3807 | "%6d %6d %5d %5d %5d " |
| 3808 | "%10"PRId64" %10.3lf" |
| 3809 | "%10lf %8u %10"PRId64" %10d %10d %10d\n", |
| 3810 | cpi->common.current_video_frame, |
| 3811 | cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3812 | cpi->rc.source_alt_ref_pending, |
| 3813 | cpi->rc.source_alt_ref_active, |
| 3814 | cpi->rc.this_frame_target, |
| 3815 | cpi->rc.projected_frame_size, |
| 3816 | cpi->rc.projected_frame_size / cpi->common.MBs, |
| 3817 | (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), |
| 3818 | cpi->rc.vbr_bits_off_target, |
| 3819 | cpi->rc.vbr_bits_off_target_fast, |
| 3820 | cpi->twopass.extend_minq, |
| 3821 | cpi->twopass.extend_minq_fast, |
| 3822 | cpi->rc.total_target_vs_actual, |
| 3823 | (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), |
| 3824 | cpi->rc.total_actual_bits, cm->base_qindex, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3825 | av1_convert_qindex_to_q(cm->base_qindex, cm->bit_depth), |
| 3826 | (double)av1_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0, |
| 3827 | av1_convert_qindex_to_q(cpi->twopass.active_worst_quality, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3828 | cm->bit_depth), |
| 3829 | cpi->rc.avg_q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3830 | av1_convert_qindex_to_q(cpi->oxcf.cq_level, cm->bit_depth), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3831 | cpi->refresh_last_frame, cpi->refresh_golden_frame, |
| 3832 | cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, |
| 3833 | cpi->twopass.bits_left, |
| 3834 | cpi->twopass.total_left_stats.coded_error, |
| 3835 | cpi->twopass.bits_left / |
| 3836 | (1 + cpi->twopass.total_left_stats.coded_error), |
| 3837 | cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost, |
| 3838 | cpi->twopass.kf_zeromotion_pct, |
| 3839 | cpi->twopass.fr_content_type); |
| 3840 | |
| 3841 | fclose(f); |
| 3842 | |
| 3843 | if (0) { |
| 3844 | FILE *const fmodes = fopen("Modes.stt", "a"); |
| 3845 | int i; |
| 3846 | |
| 3847 | fprintf(fmodes, "%6d:%1d:%1d:%1d ", cpi->common.current_video_frame, |
| 3848 | cm->frame_type, cpi->refresh_golden_frame, |
| 3849 | cpi->refresh_alt_ref_frame); |
| 3850 | |
| 3851 | for (i = 0; i < MAX_MODES; ++i) |
| 3852 | fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]); |
| 3853 | |
| 3854 | fprintf(fmodes, "\n"); |
| 3855 | |
| 3856 | fclose(fmodes); |
| 3857 | } |
| 3858 | } |
| 3859 | #endif |
| 3860 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3861 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 3862 | const AV1_COMMON *const cm = &cpi->common; |
| 3863 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3864 | |
| 3865 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3866 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3867 | |
| 3868 | if (cpi->sf.mv.auto_mv_step_size) { |
| 3869 | if (frame_is_intra_only(cm)) { |
| 3870 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 3871 | // after a key/intra-only frame. |
| 3872 | cpi->max_mv_magnitude = max_mv_def; |
| 3873 | } else { |
| 3874 | if (cm->show_frame) { |
| 3875 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 3876 | // in the previous frame, capped by the default max_mv_magnitude based |
| 3877 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3878 | cpi->mv_step_param = av1_init_search_range( |
| 3879 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3880 | } |
| 3881 | cpi->max_mv_magnitude = 0; |
| 3882 | } |
| 3883 | } |
| 3884 | } |
| 3885 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3886 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3887 | #if CONFIG_GLOBAL_MOTION |
| 3888 | int i; |
| 3889 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
Sarah Parker | 4c10a3c | 2017-04-10 19:37:59 -0700 | [diff] [blame] | 3890 | set_default_warp_params(&cpi->common.global_motion[i]); |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3891 | } |
| 3892 | cpi->global_motion_search_done = 0; |
| 3893 | #endif // CONFIG_GLOBAL_MOTION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3894 | av1_set_speed_features_framesize_independent(cpi); |
| 3895 | av1_set_rd_speed_thresholds(cpi); |
| 3896 | av1_set_rd_speed_thresholds_sub8x8(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3897 | cpi->common.interp_filter = cpi->sf.default_interp_filter; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3898 | #if CONFIG_EXT_INTER |
| 3899 | if (!frame_is_intra_only(&cpi->common)) set_compound_tools(&cpi->common); |
| 3900 | #endif // CONFIG_EXT_INTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3901 | } |
| 3902 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3903 | 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] | 3904 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3905 | AV1_COMMON *const cm = &cpi->common; |
| 3906 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3907 | |
| 3908 | // Setup variables that depend on the dimensions of the frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3909 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3910 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 3911 | // Decide q and q bounds. |
| 3912 | #if CONFIG_XIPHRC |
| 3913 | int frame_type = cm->frame_type == KEY_FRAME ? OD_I_FRAME : OD_P_FRAME; |
| 3914 | *q = od_enc_rc_select_quantizers_and_lambdas( |
| 3915 | &cpi->od_rc, cpi->refresh_golden_frame, cpi->refresh_alt_ref_frame, |
| 3916 | frame_type, bottom_index, top_index); |
| 3917 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3918 | *q = av1_rc_pick_q_and_bounds(cpi, bottom_index, top_index); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 3919 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3920 | |
| 3921 | if (!frame_is_intra_only(cm)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3922 | av1_set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | // Configure experimental use of segmentation for enhanced coding of |
| 3926 | // static regions if indicated. |
| 3927 | // Only allowed in the second pass of a two pass encode, as it requires |
| 3928 | // lagged coding, and if the relevant speed feature flag is set. |
| 3929 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 3930 | configure_static_seg_features(cpi); |
| 3931 | } |
| 3932 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3933 | static void init_motion_estimation(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3934 | int y_stride = cpi->scaled_source.y_stride; |
| 3935 | |
| 3936 | if (cpi->sf.mv.search_method == NSTEP) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3937 | av1_init3smotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3938 | } else if (cpi->sf.mv.search_method == DIAMOND) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3939 | av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3940 | } |
| 3941 | } |
| 3942 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3943 | #if CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3944 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
| 3945 | static void set_restoration_tilesize(int width, int height, int sx, int sy, |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3946 | RestorationInfo *rst) { |
| 3947 | (void)width; |
| 3948 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3949 | (void)sx; |
| 3950 | (void)sy; |
| 3951 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3952 | int s = AOMMIN(sx, sy); |
| 3953 | #else |
| 3954 | int s = 0; |
| 3955 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3956 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3957 | rst[0].restoration_tilesize = (RESTORATION_TILESIZE_MAX >> 1); |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3958 | rst[1].restoration_tilesize = rst[0].restoration_tilesize >> s; |
| 3959 | rst[2].restoration_tilesize = rst[1].restoration_tilesize; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3960 | } |
| 3961 | #endif // CONFIG_LOOP_RESTORATION |
| 3962 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3963 | static void set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3964 | AV1_COMMON *const cm = &cpi->common; |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3965 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3966 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3967 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3968 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 3969 | // There has been a change in the encoded frame size |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3970 | av1_set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3971 | set_mv_search_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3972 | } |
| 3973 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 3974 | #if !CONFIG_XIPHRC |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3975 | if (cpi->oxcf.pass == 2) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3976 | av1_set_target_rate(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3977 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 3978 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3979 | |
| 3980 | alloc_frame_mvs(cm, cm->new_fb_idx); |
| 3981 | |
| 3982 | // Reset the frame pointers to the current frame size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3983 | 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] | 3984 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3985 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3986 | cm->use_highbitdepth, |
| 3987 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3988 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 3989 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3990 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3991 | "Failed to allocate frame buffer"); |
| 3992 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3993 | #if CONFIG_LOOP_RESTORATION |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 3994 | set_restoration_tilesize( |
| 3995 | #if CONFIG_FRAME_SUPERRES |
| 3996 | cm->superres_upscaled_width, cm->superres_upscaled_height, |
| 3997 | #else |
| 3998 | cm->width, cm->height, |
| 3999 | #endif // CONFIG_FRAME_SUPERRES |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 4000 | cm->subsampling_x, cm->subsampling_y, cm->rst_info); |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4001 | for (int i = 0; i < MAX_MB_PLANE; ++i) |
| 4002 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
| 4003 | av1_alloc_restoration_buffers(cm); |
| 4004 | for (int i = 0; i < MAX_MB_PLANE; ++i) { |
| 4005 | cpi->rst_search[i].restoration_tilesize = |
| 4006 | cm->rst_info[i].restoration_tilesize; |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4007 | av1_alloc_restoration_struct(cm, &cpi->rst_search[i], |
| 4008 | #if CONFIG_FRAME_SUPERRES |
| 4009 | cm->superres_upscaled_width, |
| 4010 | cm->superres_upscaled_height); |
| 4011 | #else |
| 4012 | cm->width, cm->height); |
| 4013 | #endif // CONFIG_FRAME_SUPERRES |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 4014 | } |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 4015 | #endif // CONFIG_LOOP_RESTORATION |
| 4016 | alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4017 | init_motion_estimation(cpi); |
| 4018 | |
| 4019 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4020 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 4021 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 4022 | |
| 4023 | ref_buf->idx = buf_idx; |
| 4024 | |
| 4025 | if (buf_idx != INVALID_IDX) { |
| 4026 | YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf; |
| 4027 | ref_buf->buf = buf; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4028 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4029 | av1_setup_scale_factors_for_frame( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4030 | &ref_buf->sf, buf->y_crop_width, buf->y_crop_height, cm->width, |
| 4031 | cm->height, (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0); |
| 4032 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4033 | av1_setup_scale_factors_for_frame(&ref_buf->sf, buf->y_crop_width, |
| 4034 | buf->y_crop_height, cm->width, |
| 4035 | cm->height); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4036 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4037 | if (av1_is_scaled(&ref_buf->sf)) aom_extend_frame_borders(buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4038 | } else { |
| 4039 | ref_buf->buf = NULL; |
| 4040 | } |
| 4041 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 4042 | |
| 4043 | #if CONFIG_VAR_REFS |
| 4044 | // Check duplicate reference frames |
| 4045 | enc_check_valid_ref_frames(cpi); |
| 4046 | #endif // CONFIG_VAR_REFS |
| 4047 | |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 4048 | #if CONFIG_INTRABC |
| 4049 | #if CONFIG_HIGHBITDEPTH |
Sebastien Alaiwan | 1dcb707 | 2017-05-12 11:13:05 +0200 | [diff] [blame] | 4050 | av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height, |
| 4051 | cm->width, cm->height, |
| 4052 | cm->use_highbitdepth); |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 4053 | #else |
| 4054 | av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height, |
| 4055 | cm->width, cm->height); |
| 4056 | #endif // CONFIG_HIGHBITDEPTH |
| 4057 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4058 | |
| 4059 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 4060 | } |
| 4061 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4062 | static void setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 4063 | int encode_width = cpi->oxcf.width; |
| 4064 | int encode_height = cpi->oxcf.height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4065 | |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 4066 | uint8_t resize_num = av1_calculate_next_resize_scale(cpi); |
Fergus Simpson | bfbf6a5 | 2017-06-14 23:13:12 -0700 | [diff] [blame] | 4067 | av1_calculate_scaled_size(&encode_width, &encode_height, resize_num); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4068 | |
| 4069 | #if CONFIG_FRAME_SUPERRES |
| 4070 | AV1_COMMON *cm = &cpi->common; |
| 4071 | cm->superres_upscaled_width = encode_width; |
| 4072 | cm->superres_upscaled_height = encode_height; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 4073 | cm->superres_scale_numerator = |
Urvang Joshi | 0b90540 | 2017-08-02 10:56:23 -0700 | [diff] [blame] | 4074 | av1_calculate_next_superres_scale(cpi, encode_width, encode_height); |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 4075 | av1_calculate_scaled_size(&encode_width, &encode_height, |
Fergus Simpson | bfbf6a5 | 2017-06-14 23:13:12 -0700 | [diff] [blame] | 4076 | cm->superres_scale_numerator); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4077 | #endif // CONFIG_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4078 | |
| 4079 | set_frame_size(cpi, encode_width, encode_height); |
| 4080 | } |
| 4081 | |
| 4082 | #if CONFIG_FRAME_SUPERRES |
| 4083 | static void superres_post_encode(AV1_COMP *cpi) { |
| 4084 | AV1_COMMON *cm = &cpi->common; |
| 4085 | |
| 4086 | if (av1_superres_unscaled(cm)) return; |
| 4087 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4088 | av1_superres_upscale(cm, NULL); |
| 4089 | |
| 4090 | // If regular resizing is occurring the source will need to be downscaled to |
| 4091 | // match the upscaled superres resolution. Otherwise the original source is |
| 4092 | // used. |
| 4093 | if (av1_resize_unscaled(cm)) { |
| 4094 | cpi->source = cpi->unscaled_source; |
| 4095 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 4096 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 4097 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 4098 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4099 | // Do downscale. cm->(width|height) has been updated by av1_superres_upscale |
| 4100 | if (aom_realloc_frame_buffer( |
| 4101 | &cpi->scaled_source, cm->superres_upscaled_width, |
| 4102 | cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y, |
| 4103 | #if CONFIG_HIGHBITDEPTH |
| 4104 | cm->use_highbitdepth, |
| 4105 | #endif // CONFIG_HIGHBITDEPTH |
| 4106 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
| 4107 | aom_internal_error( |
| 4108 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 4109 | "Failed to reallocate scaled source buffer for superres"); |
| 4110 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 4111 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
| 4112 | #if CONFIG_HIGHBITDEPTH |
| 4113 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
| 4114 | (int)cm->bit_depth); |
| 4115 | #else |
| 4116 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source); |
| 4117 | #endif // CONFIG_HIGHBITDEPTH |
| 4118 | cpi->source = &cpi->scaled_source; |
| 4119 | } |
| 4120 | } |
| 4121 | #endif // CONFIG_FRAME_SUPERRES |
| 4122 | |
| 4123 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
| 4124 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
| 4125 | struct loopfilter *lf = &cm->lf; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4126 | int no_loopfilter = 0; |
| 4127 | |
| 4128 | if (is_lossless_requested(&cpi->oxcf)) no_loopfilter = 1; |
| 4129 | |
| 4130 | #if CONFIG_EXT_TILE |
| 4131 | // 0 loopfilter level is only necessary if individual tile |
| 4132 | // decoding is required. |
| 4133 | if (cm->single_tile_decoding) no_loopfilter = 1; |
| 4134 | #endif // CONFIG_EXT_TILE |
| 4135 | |
| 4136 | if (no_loopfilter) { |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame^] | 4137 | #if CONFIG_UV_LVL |
| 4138 | lf->filter_level[0] = 0; |
| 4139 | lf->filter_level[1] = 0; |
| 4140 | #else |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4141 | lf->filter_level = 0; |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame^] | 4142 | #endif |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4143 | } else { |
| 4144 | struct aom_usec_timer timer; |
| 4145 | |
| 4146 | aom_clear_system_state(); |
| 4147 | |
| 4148 | aom_usec_timer_start(&timer); |
| 4149 | |
| 4150 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
| 4151 | |
| 4152 | aom_usec_timer_mark(&timer); |
| 4153 | cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer); |
| 4154 | } |
| 4155 | |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame^] | 4156 | #if CONFIG_UV_LVL |
| 4157 | if (lf->filter_level[0] || lf->filter_level[1]) |
| 4158 | #else |
| 4159 | if (lf->filter_level > 0) |
| 4160 | #endif |
| 4161 | { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4162 | #if CONFIG_VAR_TX || CONFIG_EXT_PARTITION || CONFIG_CB4X4 |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 4163 | #if CONFIG_UV_LVL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame^] | 4164 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level[0], |
| 4165 | lf->filter_level[1], 0, 0); |
| 4166 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_u, |
| 4167 | lf->filter_level_u, 1, 0); |
| 4168 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_v, |
| 4169 | lf->filter_level_v, 2, 0); |
| 4170 | |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 4171 | #else |
| 4172 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0); |
| 4173 | #endif // CONFIG_UV_LVL |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4174 | #else |
| 4175 | if (cpi->num_workers > 1) |
| 4176 | av1_loop_filter_frame_mt(cm->frame_to_show, cm, xd->plane, |
| 4177 | lf->filter_level, 0, 0, cpi->workers, |
| 4178 | cpi->num_workers, &cpi->lf_row_sync); |
| 4179 | else |
| 4180 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0); |
| 4181 | #endif |
| 4182 | } |
| 4183 | #if CONFIG_CDEF |
| 4184 | if (is_lossless_requested(&cpi->oxcf)) { |
| 4185 | cm->cdef_bits = 0; |
| 4186 | cm->cdef_strengths[0] = 0; |
| 4187 | cm->nb_cdef_strengths = 1; |
| 4188 | } else { |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 4189 | // Find CDEF parameters |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4190 | av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd, |
| 4191 | cpi->oxcf.speed > 0); |
| 4192 | |
| 4193 | // Apply the filter |
| 4194 | av1_cdef_frame(cm->frame_to_show, cm, xd); |
| 4195 | } |
| 4196 | #endif |
| 4197 | |
| 4198 | #if CONFIG_FRAME_SUPERRES |
| 4199 | superres_post_encode(cpi); |
| 4200 | #endif // CONFIG_FRAME_SUPERRES |
| 4201 | |
| 4202 | #if CONFIG_LOOP_RESTORATION |
| 4203 | av1_pick_filter_restoration(cpi->source, cpi, cpi->sf.lpf_pick); |
| 4204 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 4205 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 4206 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
| 4207 | av1_loop_restoration_frame(cm->frame_to_show, cm, cm->rst_info, 7, 0, NULL); |
| 4208 | } |
| 4209 | #endif // CONFIG_LOOP_RESTORATION |
| 4210 | // TODO(debargha): Fix mv search range on encoder side |
| 4211 | // aom_extend_frame_inner_borders(cm->frame_to_show); |
| 4212 | aom_extend_frame_borders(cm->frame_to_show); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4213 | } |
| 4214 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4215 | static void encode_without_recode_loop(AV1_COMP *cpi) { |
| 4216 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4217 | int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4218 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4219 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4220 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4221 | set_size_independent_vars(cpi); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4222 | setup_frame_size(cpi); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4223 | assert(cm->width == cpi->scaled_source.y_crop_width); |
| 4224 | assert(cm->height == cpi->scaled_source.y_crop_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 4225 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4226 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4227 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4228 | cpi->source = |
| 4229 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
| 4230 | if (cpi->unscaled_last_source != NULL) |
| 4231 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4232 | &cpi->scaled_last_source); |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4233 | #if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION |
| 4234 | cpi->source->buf_8bit_valid = 0; |
| 4235 | #endif |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4236 | |
| 4237 | if (frame_is_intra_only(cm) == 0) { |
| 4238 | av1_scale_references(cpi); |
| 4239 | } |
| 4240 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4241 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4242 | setup_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4243 | suppress_active_map(cpi); |
hui su | ed5a30f | 2017-04-27 16:02:49 -0700 | [diff] [blame] | 4244 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4245 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4246 | // exclusive. |
| 4247 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4248 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4249 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4250 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4251 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4252 | av1_cyclic_refresh_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4253 | } |
| 4254 | apply_active_map(cpi); |
| 4255 | |
| 4256 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4257 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4258 | |
| 4259 | // Update some stats from cyclic refresh, and check if we should not update |
| 4260 | // golden reference, for 1 pass CBR. |
| 4261 | 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] | 4262 | (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR)) |
| 4263 | av1_cyclic_refresh_check_golden_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4264 | |
| 4265 | // Update the skip mb flag probabilities based on the distribution |
| 4266 | // seen in the last encoder iteration. |
| 4267 | // update_base_skip_probs(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4268 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4269 | } |
| 4270 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4271 | static void encode_with_recode_loop(AV1_COMP *cpi, size_t *size, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4272 | uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4273 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4274 | RATE_CONTROL *const rc = &cpi->rc; |
| 4275 | int bottom_index, top_index; |
| 4276 | int loop_count = 0; |
| 4277 | int loop_at_this_size = 0; |
| 4278 | int loop = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4279 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4280 | int overshoot_seen = 0; |
| 4281 | int undershoot_seen = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4282 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4283 | int frame_over_shoot_limit; |
| 4284 | int frame_under_shoot_limit; |
| 4285 | int q = 0, q_low = 0, q_high = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4286 | |
| 4287 | set_size_independent_vars(cpi); |
| 4288 | |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4289 | #if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION |
| 4290 | cpi->source->buf_8bit_valid = 0; |
| 4291 | #endif |
| 4292 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4293 | do { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4294 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4295 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4296 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4297 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4298 | if (loop_count == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4299 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4300 | |
| 4301 | // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. |
| 4302 | set_mv_search_params(cpi); |
| 4303 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4304 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4305 | // Reset the loop state for new frame size. |
| 4306 | overshoot_seen = 0; |
| 4307 | undershoot_seen = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4308 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4309 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4310 | q_low = bottom_index; |
| 4311 | q_high = top_index; |
| 4312 | |
| 4313 | loop_at_this_size = 0; |
| 4314 | } |
| 4315 | |
| 4316 | // Decide frame size bounds first time through. |
| 4317 | if (loop_count == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4318 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4319 | &frame_under_shoot_limit, |
| 4320 | &frame_over_shoot_limit); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4321 | } |
| 4322 | |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4323 | cpi->source = |
| 4324 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
| 4325 | #if CONFIG_GLOBAL_MOTION |
| 4326 | // if frame was scaled calculate global_motion_search again if already done |
| 4327 | if (cpi->source != cpi->unscaled_source) cpi->global_motion_search_done = 0; |
| 4328 | #endif // CONFIG_GLOBAL_MOTION |
| 4329 | if (cpi->unscaled_last_source != NULL) |
| 4330 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4331 | &cpi->scaled_last_source); |
| 4332 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4333 | if (frame_is_intra_only(cm) == 0) { |
| 4334 | if (loop_count > 0) { |
| 4335 | release_scaled_references(cpi); |
| 4336 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4337 | av1_scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4338 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4339 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4340 | |
| 4341 | if (loop_count == 0) setup_frame(cpi); |
| 4342 | |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 4343 | #if CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4344 | // Base q-index may have changed, so we need to assign proper default coef |
| 4345 | // probs before every iteration. |
| 4346 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
| 4347 | int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4348 | av1_default_coef_probs(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4349 | if (cm->frame_type == KEY_FRAME || cm->error_resilient_mode || |
| 4350 | cm->reset_frame_context == RESET_FRAME_CONTEXT_ALL) { |
| 4351 | for (i = 0; i < FRAME_CONTEXTS; ++i) cm->frame_contexts[i] = *cm->fc; |
| 4352 | } else if (cm->reset_frame_context == RESET_FRAME_CONTEXT_CURRENT) { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 4353 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 4354 | if (cm->frame_refs[0].idx >= 0) { |
| 4355 | cm->frame_contexts[cm->frame_refs[0].idx] = *cm->fc; |
| 4356 | } |
| 4357 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4358 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 4359 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4360 | } |
| 4361 | } |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 4362 | #endif // CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4363 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4364 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4365 | // exclusive. |
| 4366 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4367 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4368 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4369 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4373 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4374 | |
| 4375 | // Update the skip mb flag probabilities based on the distribution |
| 4376 | // seen in the last encoder iteration. |
| 4377 | // update_base_skip_probs(cpi); |
| 4378 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4379 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4380 | |
| 4381 | // Dummy pack of the bitstream using up to date stats to get an |
| 4382 | // accurate estimate of output frame size to determine if we need |
| 4383 | // to recode. |
| 4384 | if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
| 4385 | save_coding_context(cpi); |
| 4386 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4387 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4388 | |
| 4389 | rc->projected_frame_size = (int)(*size) << 3; |
| 4390 | restore_coding_context(cpi); |
| 4391 | |
| 4392 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4393 | } |
| 4394 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4395 | if (cpi->oxcf.rc_mode == AOM_Q) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4396 | loop = 0; |
| 4397 | } else { |
| 4398 | if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced && |
| 4399 | (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
| 4400 | int last_q = q; |
| 4401 | int64_t kf_err; |
| 4402 | |
| 4403 | int64_t high_err_target = cpi->ambient_err; |
| 4404 | int64_t low_err_target = cpi->ambient_err >> 1; |
| 4405 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4406 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4407 | if (cm->use_highbitdepth) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4408 | 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] | 4409 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4410 | 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] | 4411 | } |
| 4412 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4413 | 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] | 4414 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4415 | |
| 4416 | // Prevent possible divide by zero error below for perfect KF |
| 4417 | kf_err += !kf_err; |
| 4418 | |
| 4419 | // The key frame is not good enough or we can afford |
| 4420 | // to make it better without undue risk of popping. |
| 4421 | if ((kf_err > high_err_target && |
| 4422 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4423 | (kf_err > low_err_target && |
| 4424 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4425 | // Lower q_high |
| 4426 | q_high = q > q_low ? q - 1 : q_low; |
| 4427 | |
| 4428 | // Adjust Q |
| 4429 | q = (int)((q * high_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4430 | q = AOMMIN(q, (q_high + q_low) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4431 | } else if (kf_err < low_err_target && |
| 4432 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4433 | // The key frame is much better than the previous frame |
| 4434 | // Raise q_low |
| 4435 | q_low = q < q_high ? q + 1 : q_high; |
| 4436 | |
| 4437 | // Adjust Q |
| 4438 | q = (int)((q * low_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4439 | q = AOMMIN(q, (q_high + q_low + 1) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | // Clamp Q to upper and lower limits: |
| 4443 | q = clamp(q, q_low, q_high); |
| 4444 | |
| 4445 | loop = q != last_q; |
| 4446 | } else if (recode_loop_test(cpi, frame_over_shoot_limit, |
| 4447 | frame_under_shoot_limit, q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4448 | AOMMAX(q_high, top_index), bottom_index)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4449 | // Is the projected frame size out of range and are we allowed |
| 4450 | // to attempt to recode. |
| 4451 | int last_q = q; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4452 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4453 | int retries = 0; |
| 4454 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4455 | // Frame size out of permitted range: |
| 4456 | // Update correction factor & compute new Q to try... |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4457 | // Frame is too large |
| 4458 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 4459 | // Special case if the projected size is > the max allowed. |
| 4460 | if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
| 4461 | q_high = rc->worst_quality; |
| 4462 | |
| 4463 | // Raise Qlow as to at least the current value |
| 4464 | q_low = q < q_high ? q + 1 : q_high; |
| 4465 | |
| 4466 | if (undershoot_seen || loop_at_this_size > 1) { |
| 4467 | // Update rate_correction_factor unless |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4468 | av1_rc_update_rate_correction_factors(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4469 | |
| 4470 | q = (q_high + q_low + 1) / 2; |
| 4471 | } else { |
| 4472 | // Update rate_correction_factor unless |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4473 | av1_rc_update_rate_correction_factors(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4474 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4475 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4476 | AOMMAX(q_high, top_index)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4477 | |
| 4478 | while (q < q_low && retries < 10) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4479 | av1_rc_update_rate_correction_factors(cpi); |
| 4480 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4481 | AOMMAX(q_high, top_index)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4482 | retries++; |
| 4483 | } |
| 4484 | } |
| 4485 | |
| 4486 | overshoot_seen = 1; |
| 4487 | } else { |
| 4488 | // Frame is too small |
| 4489 | q_high = q > q_low ? q - 1 : q_low; |
| 4490 | |
| 4491 | if (overshoot_seen || loop_at_this_size > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4492 | av1_rc_update_rate_correction_factors(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4493 | q = (q_high + q_low) / 2; |
| 4494 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4495 | av1_rc_update_rate_correction_factors(cpi); |
| 4496 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4497 | top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4498 | // Special case reset for qlow for constrained quality. |
| 4499 | // This should only trigger where there is very substantial |
| 4500 | // undershoot on a frame and the auto cq level is above |
| 4501 | // the user passsed in value. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4502 | if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4503 | q_low = q; |
| 4504 | } |
| 4505 | |
| 4506 | while (q > q_high && retries < 10) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4507 | av1_rc_update_rate_correction_factors(cpi); |
| 4508 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4509 | top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4510 | retries++; |
| 4511 | } |
| 4512 | } |
| 4513 | |
| 4514 | undershoot_seen = 1; |
| 4515 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4516 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4517 | |
| 4518 | // Clamp Q to upper and lower limits: |
| 4519 | q = clamp(q, q_low, q_high); |
| 4520 | |
| 4521 | loop = (q != last_q); |
| 4522 | } else { |
| 4523 | loop = 0; |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | // Special case for overlay frame. |
| 4528 | if (rc->is_src_frame_alt_ref && |
| 4529 | rc->projected_frame_size < rc->max_frame_bandwidth) |
| 4530 | loop = 0; |
| 4531 | |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4532 | #if CONFIG_GLOBAL_MOTION |
| 4533 | if (recode_loop_test_global_motion(cpi)) { |
| 4534 | loop = 1; |
| 4535 | } |
| 4536 | #endif // CONFIG_GLOBAL_MOTION |
| 4537 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4538 | if (loop) { |
| 4539 | ++loop_count; |
| 4540 | ++loop_at_this_size; |
| 4541 | |
| 4542 | #if CONFIG_INTERNAL_STATS |
| 4543 | ++cpi->tot_recode_hits; |
| 4544 | #endif |
| 4545 | } |
| 4546 | } while (loop); |
| 4547 | } |
| 4548 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4549 | static int get_ref_frame_flags(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4550 | const int *const map = cpi->common.ref_frame_map; |
| 4551 | |
| 4552 | #if CONFIG_EXT_REFS |
| 4553 | const int last2_is_last = |
| 4554 | map[cpi->lst_fb_idxes[1]] == map[cpi->lst_fb_idxes[0]]; |
| 4555 | const int last3_is_last = |
| 4556 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[0]]; |
| 4557 | const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4558 | #if CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 4559 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4560 | const int last3_is_last2 = |
| 4561 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]]; |
| 4562 | const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4563 | const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4564 | #else // !CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4565 | const int bwd_is_last = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4566 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4567 | |
| 4568 | const int last3_is_last2 = |
| 4569 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]]; |
| 4570 | const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4571 | const int bwd_is_last2 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4572 | |
| 4573 | const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 4574 | const int bwd_is_last3 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 4575 | |
| 4576 | const int bwd_is_gld = map[cpi->bwd_fb_idx] == map[cpi->gld_fb_idx]; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4577 | #endif // CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4578 | |
| 4579 | #if CONFIG_ALTREF2 |
| 4580 | const int alt2_is_last = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4581 | const int alt2_is_last2 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4582 | const int alt2_is_last3 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 4583 | const int alt2_is_gld = map[cpi->alt2_fb_idx] == map[cpi->gld_fb_idx]; |
| 4584 | const int alt2_is_bwd = map[cpi->alt2_fb_idx] == map[cpi->bwd_fb_idx]; |
| 4585 | #endif // CONFIG_ALTREF2 |
| 4586 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4587 | const int last2_is_alt = map[cpi->lst_fb_idxes[1]] == map[cpi->alt_fb_idx]; |
| 4588 | const int last3_is_alt = map[cpi->lst_fb_idxes[2]] == map[cpi->alt_fb_idx]; |
| 4589 | const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 4590 | 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] | 4591 | #if CONFIG_ALTREF2 |
| 4592 | const int alt2_is_alt = map[cpi->alt2_fb_idx] == map[cpi->alt_fb_idx]; |
| 4593 | #endif // CONFIG_ALTREF2 |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 4594 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4595 | const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx]; |
| 4596 | const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 4597 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx]; |
| 4598 | #endif // CONFIG_EXT_REFS |
| 4599 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4600 | int flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4601 | |
| 4602 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4603 | #if !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4604 | // Disable the use of BWDREF_FRAME for non-bipredictive frames. |
| 4605 | if (!(cpi->rc.is_bipred_frame || cpi->rc.is_last_bipred_frame || |
| 4606 | (cpi->rc.is_bwd_ref_frame && cpi->num_extra_arfs))) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4607 | flags &= ~AOM_BWD_FLAG; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4608 | #endif // !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4609 | #endif // CONFIG_EXT_REFS |
| 4610 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4611 | if (gld_is_last || gld_is_alt) flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4612 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4613 | 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] | 4614 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4615 | if (alt_is_last) flags &= ~AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4616 | |
| 4617 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4618 | if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4619 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4620 | if (last3_is_last || last3_is_last2 || last3_is_alt) flags &= ~AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4621 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4622 | if (gld_is_last2 || gld_is_last3) flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4623 | |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4624 | #if CONFIG_ONE_SIDED_COMPOUND && \ |
| 4625 | !CONFIG_EXT_COMP_REFS // Changes LL & HL bitstream |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 4626 | /* Allow biprediction between two identical frames (e.g. bwd_is_last = 1) */ |
| 4627 | if (bwd_is_alt && (flags & AOM_BWD_FLAG)) flags &= ~AOM_BWD_FLAG; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4628 | #else // !CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4629 | if ((bwd_is_last || bwd_is_last2 || bwd_is_last3 || bwd_is_gld || |
| 4630 | bwd_is_alt) && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4631 | (flags & AOM_BWD_FLAG)) |
| 4632 | flags &= ~AOM_BWD_FLAG; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4633 | #endif // CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4634 | |
| 4635 | #if CONFIG_ALTREF2 |
| 4636 | if ((alt2_is_last || alt2_is_last2 || alt2_is_last3 || alt2_is_gld || |
| 4637 | alt2_is_bwd || alt2_is_alt) && |
| 4638 | (flags & AOM_ALT2_FLAG)) |
| 4639 | flags &= ~AOM_ALT2_FLAG; |
| 4640 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4641 | #endif // CONFIG_EXT_REFS |
| 4642 | |
| 4643 | return flags; |
| 4644 | } |
| 4645 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4646 | static void set_ext_overrides(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4647 | // Overrides the defaults with the externally supplied values with |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4648 | // av1_update_reference() and av1_update_entropy() calls |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4649 | // Note: The overrides are valid only for the next frame passed |
| 4650 | // to encode_frame_to_data_rate() function |
| 4651 | if (cpi->ext_refresh_frame_context_pending) { |
| 4652 | cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context; |
| 4653 | cpi->ext_refresh_frame_context_pending = 0; |
| 4654 | } |
| 4655 | if (cpi->ext_refresh_frame_flags_pending) { |
| 4656 | cpi->refresh_last_frame = cpi->ext_refresh_last_frame; |
| 4657 | cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame; |
| 4658 | cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; |
| 4659 | cpi->ext_refresh_frame_flags_pending = 0; |
| 4660 | } |
| 4661 | } |
| 4662 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4663 | static void set_arf_sign_bias(AV1_COMP *cpi) { |
| 4664 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4665 | int arf_sign_bias; |
| 4666 | #if CONFIG_EXT_REFS |
| 4667 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4668 | // The arf_sign_bias will be one for internal ARFs' |
| 4669 | #if CONFIG_ALTREF2 |
| 4670 | arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 4671 | (!cpi->refresh_alt_ref_frame || |
| 4672 | gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE); |
| 4673 | #else // !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4674 | arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 4675 | (!cpi->refresh_alt_ref_frame || |
| 4676 | (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4677 | #endif // CONFIG_ALTREF2 |
| 4678 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4679 | if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { |
| 4680 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 4681 | arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 4682 | (!cpi->refresh_alt_ref_frame || |
| 4683 | (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)); |
| 4684 | } else { |
| 4685 | arf_sign_bias = |
| 4686 | (cpi->rc.source_alt_ref_active && !cpi->refresh_alt_ref_frame); |
| 4687 | } |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 4688 | #endif // CONFIG_EXT_REFS |
| 4689 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4690 | cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; |
| 4691 | #if CONFIG_EXT_REFS |
| 4692 | 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] | 4693 | #if CONFIG_ALTREF2 |
| 4694 | cm->ref_frame_sign_bias[ALTREF2_FRAME] = |
| 4695 | cm->ref_frame_sign_bias[ALTREF_FRAME]; |
| 4696 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4697 | #endif // CONFIG_EXT_REFS |
| 4698 | } |
| 4699 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4700 | static int setup_interp_filter_search_mask(AV1_COMP *cpi) { |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 4701 | InterpFilter ifilter; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4702 | int ref_total[TOTAL_REFS_PER_FRAME] = { 0 }; |
| 4703 | MV_REFERENCE_FRAME ref; |
| 4704 | int mask = 0; |
| 4705 | int arf_idx = ALTREF_FRAME; |
| 4706 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4707 | #if CONFIG_EXT_REFS && !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4708 | // Get which arf used as ALTREF_FRAME |
| 4709 | if (cpi->oxcf.pass == 2) |
| 4710 | arf_idx += cpi->twopass.gf_group.arf_ref_idx[cpi->twopass.gf_group.index]; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4711 | #endif // CONFIG_EXT_REFS && !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4712 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4713 | #if CONFIG_ALTREF2 |
| 4714 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame || |
| 4715 | cpi->refresh_alt2_ref_frame) |
| 4716 | #else // !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4717 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame) |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4718 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4719 | return mask; |
| 4720 | |
| 4721 | #if CONFIG_EXT_REFS |
| 4722 | for (ref = LAST_FRAME; ref < ALTREF_FRAME; ++ref) |
| 4723 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) |
| 4724 | ref_total[ref] += cpi->interp_filter_selected[ref][ifilter]; |
| 4725 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4726 | #if !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4727 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) |
| 4728 | ref_total[ref] += cpi->interp_filter_selected[arf_idx][ifilter]; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4729 | #endif // !CONFIG_ALTREF2 |
| 4730 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4731 | for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) |
| 4732 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) |
| 4733 | ref_total[ref] += cpi->interp_filter_selected[ref][ifilter]; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 4734 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4735 | |
| 4736 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) { |
| 4737 | if ((ref_total[LAST_FRAME] && |
| 4738 | cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) && |
| 4739 | #if CONFIG_EXT_REFS |
| 4740 | (ref_total[LAST2_FRAME] == 0 || |
| 4741 | cpi->interp_filter_selected[LAST2_FRAME][ifilter] * 50 < |
| 4742 | ref_total[LAST2_FRAME]) && |
| 4743 | (ref_total[LAST3_FRAME] == 0 || |
| 4744 | cpi->interp_filter_selected[LAST3_FRAME][ifilter] * 50 < |
| 4745 | ref_total[LAST3_FRAME]) && |
| 4746 | #endif // CONFIG_EXT_REFS |
| 4747 | (ref_total[GOLDEN_FRAME] == 0 || |
| 4748 | cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50 < |
| 4749 | ref_total[GOLDEN_FRAME]) && |
| 4750 | #if CONFIG_EXT_REFS |
| 4751 | (ref_total[BWDREF_FRAME] == 0 || |
| 4752 | cpi->interp_filter_selected[BWDREF_FRAME][ifilter] * 50 < |
| 4753 | ref_total[BWDREF_FRAME]) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4754 | #if CONFIG_ALTREF2 |
| 4755 | (ref_total[ALTREF2_FRAME] == 0 || |
| 4756 | cpi->interp_filter_selected[ALTREF2_FRAME][ifilter] * 50 < |
| 4757 | ref_total[ALTREF2_FRAME]) && |
| 4758 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4759 | #endif // CONFIG_EXT_REFS |
| 4760 | (ref_total[ALTREF_FRAME] == 0 || |
| 4761 | cpi->interp_filter_selected[arf_idx][ifilter] * 50 < |
| 4762 | ref_total[ALTREF_FRAME])) |
| 4763 | mask |= 1 << ifilter; |
| 4764 | } |
| 4765 | return mask; |
| 4766 | } |
| 4767 | |
| 4768 | #define DUMP_RECON_FRAMES 0 |
| 4769 | |
| 4770 | #if DUMP_RECON_FRAMES == 1 |
| 4771 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4772 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 4773 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4774 | const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show; |
| 4775 | int h; |
| 4776 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 4777 | FILE *f_recon = NULL; |
| 4778 | |
| 4779 | if (recon_buf == NULL || !cm->show_frame) { |
| 4780 | printf("Frame %d is not ready or no show to dump.\n", |
| 4781 | cm->current_video_frame); |
| 4782 | return; |
| 4783 | } |
| 4784 | |
| 4785 | if (cm->current_video_frame == 0) { |
| 4786 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 4787 | printf("Unable to open file %s to write.\n", file_name); |
| 4788 | return; |
| 4789 | } |
| 4790 | } else { |
| 4791 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 4792 | printf("Unable to open file %s to append.\n", file_name); |
| 4793 | return; |
| 4794 | } |
| 4795 | } |
| 4796 | printf( |
| 4797 | "\nFrame=%5d, encode_update_type[%5d]=%1d, show_existing_frame=%d, " |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 4798 | "source_alt_ref_active=%d, refresh_alt_ref_frame=%d, rf_level=%d, " |
| 4799 | "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] | 4800 | cm->current_video_frame, cpi->twopass.gf_group.index, |
| 4801 | cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 4802 | cm->show_existing_frame, cpi->rc.source_alt_ref_active, |
| 4803 | cpi->refresh_alt_ref_frame, |
| 4804 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index], |
| 4805 | recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4806 | #if 0 |
| 4807 | int ref_frame; |
| 4808 | printf("get_ref_frame_map_idx: ["); |
| 4809 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
| 4810 | printf(" %d", get_ref_frame_map_idx(cpi, ref_frame)); |
| 4811 | printf(" ]\n"); |
| 4812 | printf("cm->new_fb_idx = %d\n", cm->new_fb_idx); |
| 4813 | printf("cm->ref_frame_map = ["); |
| 4814 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4815 | printf(" %d", cm->ref_frame_map[ref_frame - LAST_FRAME]); |
| 4816 | } |
| 4817 | printf(" ]\n"); |
| 4818 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4819 | |
| 4820 | // --- Y --- |
| 4821 | for (h = 0; h < cm->height; ++h) { |
| 4822 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 4823 | f_recon); |
| 4824 | } |
| 4825 | // --- U --- |
| 4826 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4827 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4828 | f_recon); |
| 4829 | } |
| 4830 | // --- V --- |
| 4831 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4832 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4833 | f_recon); |
| 4834 | } |
| 4835 | |
| 4836 | fclose(f_recon); |
| 4837 | } |
| 4838 | #endif // DUMP_RECON_FRAMES |
| 4839 | |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 4840 | static void make_update_tile_list_enc(AV1_COMP *cpi, const int tile_rows, |
| 4841 | const int tile_cols, |
| 4842 | FRAME_CONTEXT *ec_ctxs[]) { |
| 4843 | int i; |
| 4844 | for (i = 0; i < tile_rows * tile_cols; ++i) |
| 4845 | ec_ctxs[i] = &cpi->tile_data[i].tctx; |
| 4846 | } |
| 4847 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4848 | 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] | 4849 | uint8_t *dest, int skip_adapt, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4850 | unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4851 | AV1_COMMON *const cm = &cpi->common; |
| 4852 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4853 | struct segmentation *const seg = &cm->seg; |
| 4854 | TX_SIZE t; |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 4855 | FRAME_CONTEXT **tile_ctxs = aom_malloc(cm->tile_rows * cm->tile_cols * |
| 4856 | sizeof(&cpi->tile_data[0].tctx)); |
| 4857 | aom_cdf_prob **cdf_ptrs = |
| 4858 | aom_malloc(cm->tile_rows * cm->tile_cols * |
| 4859 | sizeof(&cpi->tile_data[0].tctx.partition_cdf[0][0])); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4860 | #if CONFIG_XIPHRC |
| 4861 | int frame_type; |
| 4862 | int drop_this_frame = 0; |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 4863 | #endif // CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4864 | set_ext_overrides(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4865 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4866 | |
| 4867 | // Set the arf sign bias for this frame. |
| 4868 | set_arf_sign_bias(cpi); |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 4869 | #if CONFIG_TEMPMV_SIGNALING |
| 4870 | // frame type has been decided outside of this function call |
| 4871 | cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only; |
| 4872 | cm->use_prev_frame_mvs = |
| 4873 | !cpi->oxcf.disable_tempmv && !cm->cur_frame->intra_only; |
| 4874 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4875 | |
| 4876 | #if CONFIG_EXT_REFS |
| 4877 | // NOTE: |
| 4878 | // (1) Move the setup of the ref_frame_flags upfront as it would be |
| 4879 | // determined by the current frame properties; |
| 4880 | // (2) The setup of the ref_frame_flags applies to both show_existing_frame's |
| 4881 | // and the other cases. |
| 4882 | if (cm->current_video_frame > 0) |
| 4883 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 4884 | |
| 4885 | if (cm->show_existing_frame) { |
| 4886 | // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current |
| 4887 | // BWDREF_FRAME in the reference frame buffer. |
| 4888 | cm->frame_type = INTER_FRAME; |
| 4889 | cm->show_frame = 1; |
| 4890 | cpi->frame_flags = *frame_flags; |
| 4891 | |
| 4892 | // In the case of show_existing frame, we will not send fresh flag |
| 4893 | // to decoder. Any change in the reference frame buffer can be done by |
| 4894 | // switching the virtual indices. |
| 4895 | |
| 4896 | cpi->refresh_last_frame = 0; |
| 4897 | cpi->refresh_golden_frame = 0; |
| 4898 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4899 | #if CONFIG_ALTREF2 |
| 4900 | cpi->refresh_alt2_ref_frame = 0; |
| 4901 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4902 | cpi->refresh_alt_ref_frame = 0; |
| 4903 | |
| 4904 | cpi->rc.is_bwd_ref_frame = 0; |
| 4905 | cpi->rc.is_last_bipred_frame = 0; |
| 4906 | cpi->rc.is_bipred_frame = 0; |
| 4907 | |
| 4908 | // Build the bitstream |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4909 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4910 | |
| 4911 | // Set up frame to show to get ready for stats collection. |
| 4912 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 4913 | |
| 4914 | #if DUMP_RECON_FRAMES == 1 |
| 4915 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 4916 | dump_filtered_recon_frames(cpi); |
| 4917 | #endif // DUMP_RECON_FRAMES |
| 4918 | |
| 4919 | // Update the LAST_FRAME in the reference frame buffer. |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4920 | // NOTE: |
| 4921 | // (1) For BWDREF_FRAME as the show_existing_frame, the reference frame |
| 4922 | // update has been done previously when handling the LAST_BIPRED_FRAME |
| 4923 | // right before BWDREF_FRAME (in the display order); |
| 4924 | // (2) For INTNL_OVERLAY as the show_existing_frame, the reference frame |
| 4925 | // update will be done when the following is called, which will exchange |
| 4926 | // the virtual indexes between LAST_FRAME and ALTREF2_FRAME, so that |
| 4927 | // LAST3 will get retired, LAST2 becomes LAST3, LAST becomes LAST2, and |
| 4928 | // ALTREF2_FRAME will serve as the new LAST_FRAME. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4929 | av1_update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4930 | |
| 4931 | // Update frame flags |
| 4932 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 4933 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 4934 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 4935 | |
| 4936 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 4937 | |
| 4938 | // Update the frame type |
| 4939 | cm->last_frame_type = cm->frame_type; |
| 4940 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4941 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 4942 | // to do post-encoding update accordingly. |
| 4943 | if (cpi->rc.is_src_frame_alt_ref) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4944 | av1_set_target_rate(cpi); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4945 | #if CONFIG_XIPHRC |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 4946 | 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] | 4947 | drop_this_frame = od_enc_rc_update_state( |
| 4948 | &cpi->od_rc, *size << 3, cpi->refresh_golden_frame, |
| 4949 | cpi->refresh_alt_ref_frame, frame_type, cpi->droppable); |
| 4950 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4951 | av1_rc_postencode_update(cpi, *size); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4952 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4953 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4954 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4955 | ++cm->current_video_frame; |
| 4956 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 4957 | aom_free(tile_ctxs); |
| 4958 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4959 | return; |
| 4960 | } |
| 4961 | #endif // CONFIG_EXT_REFS |
| 4962 | |
| 4963 | // Set default state for segment based loop filter update flags. |
| 4964 | cm->lf.mode_ref_delta_update = 0; |
| 4965 | |
| 4966 | if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search) |
| 4967 | cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi); |
| 4968 | |
| 4969 | // Set various flags etc to special state if it is a key frame. |
| 4970 | if (frame_is_intra_only(cm)) { |
| 4971 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4972 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4973 | |
| 4974 | // If segmentation is enabled force a map update for key frames. |
| 4975 | if (seg->enabled) { |
| 4976 | seg->update_map = 1; |
| 4977 | seg->update_data = 1; |
| 4978 | } |
| 4979 | |
| 4980 | // The alternate reference frame cannot be active for a key frame. |
| 4981 | cpi->rc.source_alt_ref_active = 0; |
| 4982 | |
| 4983 | cm->error_resilient_mode = oxcf->error_resilient_mode; |
| 4984 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 4985 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4986 | // By default, encoder assumes decoder can use prev_mi. |
| 4987 | if (cm->error_resilient_mode) { |
| 4988 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
| 4989 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 4990 | } else if (cm->intra_only) { |
| 4991 | // Only reset the current context. |
| 4992 | cm->reset_frame_context = RESET_FRAME_CONTEXT_CURRENT; |
| 4993 | } |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 4994 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4995 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4996 | if (cpi->oxcf.mtu == 0) { |
| 4997 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 4998 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 4999 | // Use a default value for the purposes of weighting costs in probability |
| 5000 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 5001 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 5002 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5003 | |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 5004 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 5005 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 5006 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 5007 | #endif // CONFIG_EXT_TILE |
| 5008 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5009 | #if CONFIG_XIPHRC |
| 5010 | if (drop_this_frame) { |
| 5011 | av1_rc_postencode_update_drop_frame(cpi); |
| 5012 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5013 | aom_free(tile_ctxs); |
| 5014 | aom_free(cdf_ptrs); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5015 | return; |
| 5016 | } |
| 5017 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5018 | // For 1 pass CBR, check if we are dropping this frame. |
| 5019 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5020 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5021 | cm->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5022 | if (av1_rc_drop_frame(cpi)) { |
| 5023 | av1_rc_postencode_update_drop_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5024 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5025 | aom_free(tile_ctxs); |
| 5026 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5027 | return; |
| 5028 | } |
| 5029 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5030 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5031 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5032 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5033 | |
| 5034 | #if CONFIG_INTERNAL_STATS |
| 5035 | memset(cpi->mode_chosen_counts, 0, |
| 5036 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 5037 | #endif |
| 5038 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5039 | #if CONFIG_REFERENCE_BUFFER |
| 5040 | { |
| 5041 | /* Non-normative definition of current_frame_id ("frame counter" with |
| 5042 | * wraparound) */ |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5043 | const int frame_id_length = FRAME_ID_LENGTH_MINUS7 + 7; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5044 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5045 | int lsb, msb; |
Arild Fuldseth (arilfuld) | bac17c1 | 2016-12-02 12:01:06 +0100 | [diff] [blame] | 5046 | /* quasi-random initialization of current_frame_id for a key frame */ |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5047 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5048 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 5049 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 5050 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5051 | } else { |
| 5052 | #endif |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5053 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 5054 | msb = cpi->source->y_buffer[1] & 0xff; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5055 | #if CONFIG_HIGHBITDEPTH |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 5056 | } |
Arild Fuldseth (arilfuld) | bac17c1 | 2016-12-02 12:01:06 +0100 | [diff] [blame] | 5057 | #endif |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5058 | cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5059 | } else { |
| 5060 | cm->current_frame_id = |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 5061 | (cm->current_frame_id + 1 + (1 << frame_id_length)) % |
| 5062 | (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5063 | } |
| 5064 | } |
| 5065 | #endif |
| 5066 | |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 5067 | #if CONFIG_EXT_DELTA_Q |
| 5068 | cm->delta_q_present_flag = cpi->oxcf.deltaq_mode != NO_DELTA_Q; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 5069 | cm->delta_lf_present_flag = cpi->oxcf.deltaq_mode == DELTA_Q_LF; |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 5070 | #endif |
| 5071 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5072 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 5073 | encode_without_recode_loop(cpi); |
| 5074 | } else { |
| 5075 | encode_with_recode_loop(cpi, size, dest); |
| 5076 | } |
| 5077 | |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5078 | cm->last_tile_cols = cm->tile_cols; |
| 5079 | cm->last_tile_rows = cm->tile_rows; |
| 5080 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5081 | #ifdef OUTPUT_YUV_SKINMAP |
| 5082 | if (cpi->common.current_video_frame > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5083 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5084 | } |
| 5085 | #endif // OUTPUT_YUV_SKINMAP |
| 5086 | |
| 5087 | // Special case code to reduce pulsing when key frames are forced at a |
| 5088 | // fixed interval. Note the reconstruction error if it is the frame before |
| 5089 | // the force key frame |
| 5090 | 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] | 5091 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5092 | if (cm->use_highbitdepth) { |
| 5093 | cpi->ambient_err = |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5094 | aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5095 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5096 | 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] | 5097 | } |
| 5098 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5099 | 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] | 5100 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
| 5103 | // If the encoder forced a KEY_FRAME decision |
| 5104 | if (cm->frame_type == KEY_FRAME) { |
| 5105 | cpi->refresh_last_frame = 1; |
| 5106 | } |
| 5107 | |
| 5108 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 5109 | cm->frame_to_show->color_space = cm->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 5110 | #if CONFIG_COLORSPACE_HEADERS |
| 5111 | cm->frame_to_show->transfer_function = cm->transfer_function; |
| 5112 | cm->frame_to_show->chroma_sample_position = cm->chroma_sample_position; |
| 5113 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5114 | cm->frame_to_show->color_range = cm->color_range; |
| 5115 | cm->frame_to_show->render_width = cm->render_width; |
| 5116 | cm->frame_to_show->render_height = cm->render_height; |
| 5117 | |
| 5118 | #if CONFIG_EXT_REFS |
| 5119 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 5120 | // off. |
| 5121 | #endif // CONFIG_EXT_REFS |
| 5122 | |
| 5123 | // Pick the loop filter level for the frame. |
| 5124 | loopfilter_frame(cpi, cm); |
| 5125 | |
| 5126 | // Build the bitstream |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5127 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5128 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5129 | if (skip_adapt) { |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5130 | aom_free(tile_ctxs); |
| 5131 | aom_free(cdf_ptrs); |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5132 | return; |
| 5133 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5134 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5135 | #if CONFIG_REFERENCE_BUFFER |
| 5136 | { |
| 5137 | int i; |
| 5138 | /* Update reference frame id values based on the value of refresh_mask */ |
| 5139 | for (i = 0; i < REF_FRAMES; i++) { |
| 5140 | if ((cm->refresh_mask >> i) & 1) { |
| 5141 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 5142 | } |
| 5143 | } |
| 5144 | } |
| 5145 | #endif |
| 5146 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5147 | #if DUMP_RECON_FRAMES == 1 |
| 5148 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 5149 | if (cm->show_frame) dump_filtered_recon_frames(cpi); |
| 5150 | #endif // DUMP_RECON_FRAMES |
| 5151 | |
| 5152 | if (cm->seg.update_map) update_reference_segmentation_map(cpi); |
| 5153 | |
| 5154 | if (frame_is_intra_only(cm) == 0) { |
| 5155 | release_scaled_references(cpi); |
| 5156 | } |
| 5157 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5158 | av1_update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5159 | |
Jingning Han | 6de954c | 2016-12-16 09:52:04 -0800 | [diff] [blame] | 5160 | for (t = 0; t < TX_SIZES; t++) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5161 | av1_full_to_model_counts(cpi->td.counts->coef[t], |
| 5162 | cpi->td.rd_counts.coef_counts[t]); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5163 | #if CONFIG_ENTROPY_STATS |
| 5164 | av1_accumulate_frame_counts(&aggregate_fc, &cm->counts); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 5165 | assert(cm->frame_context_idx < FRAME_CONTEXTS); |
| 5166 | av1_accumulate_frame_counts(&aggregate_fc_per_type[cm->frame_context_idx], |
| 5167 | &cm->counts); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5168 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5169 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5170 | av1_adapt_coef_probs(cm); |
| 5171 | av1_adapt_intra_frame_probs(cm); |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5172 | make_update_tile_list_enc(cpi, cm->tile_rows, cm->tile_cols, tile_ctxs); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5173 | av1_average_tile_coef_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5174 | cm->tile_rows * cm->tile_cols); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5175 | av1_average_tile_intra_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5176 | cm->tile_rows * cm->tile_cols); |
Yushin Cho | b188ea1 | 2017-03-13 13:45:23 -0700 | [diff] [blame] | 5177 | #if CONFIG_PVQ |
| 5178 | av1_average_tile_pvq_cdfs(cpi->common.fc, tile_ctxs, |
| 5179 | cm->tile_rows * cm->tile_cols); |
| 5180 | #endif // CONFIG_PVQ |
hui su | ff0da2b | 2017-03-07 15:51:37 -0800 | [diff] [blame] | 5181 | #if CONFIG_ADAPT_SCAN |
| 5182 | av1_adapt_scan_order(cm); |
| 5183 | #endif // CONFIG_ADAPT_SCAN |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | if (!frame_is_intra_only(cm)) { |
| 5187 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5188 | av1_adapt_inter_frame_probs(cm); |
| 5189 | av1_adapt_mv_probs(cm, cm->allow_high_precision_mv); |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5190 | av1_average_tile_inter_cdfs(&cpi->common, cpi->common.fc, tile_ctxs, |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5191 | cdf_ptrs, cm->tile_rows * cm->tile_cols); |
| 5192 | av1_average_tile_mv_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5193 | cm->tile_rows * cm->tile_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5194 | } |
| 5195 | } |
| 5196 | |
| 5197 | if (cpi->refresh_golden_frame == 1) |
| 5198 | cpi->frame_flags |= FRAMEFLAGS_GOLDEN; |
| 5199 | else |
| 5200 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 5201 | |
| 5202 | if (cpi->refresh_alt_ref_frame == 1) |
| 5203 | cpi->frame_flags |= FRAMEFLAGS_ALTREF; |
| 5204 | else |
| 5205 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 5206 | |
| 5207 | #if CONFIG_EXT_REFS |
| 5208 | if (cpi->refresh_bwd_ref_frame == 1) |
| 5209 | cpi->frame_flags |= FRAMEFLAGS_BWDREF; |
| 5210 | else |
| 5211 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 5212 | #endif // CONFIG_EXT_REFS |
| 5213 | |
| 5214 | #if !CONFIG_EXT_REFS |
| 5215 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 5216 | #endif // !CONFIG_EXT_REFS |
| 5217 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5218 | cm->last_frame_type = cm->frame_type; |
| 5219 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5220 | #if CONFIG_XIPHRC |
| 5221 | frame_type = cm->frame_type == KEY_FRAME ? OD_I_FRAME : OD_P_FRAME; |
| 5222 | |
| 5223 | drop_this_frame = |
| 5224 | od_enc_rc_update_state(&cpi->od_rc, *size << 3, cpi->refresh_golden_frame, |
| 5225 | cpi->refresh_alt_ref_frame, frame_type, 0); |
| 5226 | if (drop_this_frame) { |
| 5227 | av1_rc_postencode_update_drop_frame(cpi); |
| 5228 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5229 | aom_free(tile_ctxs); |
| 5230 | aom_free(cdf_ptrs); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5231 | return; |
| 5232 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5233 | #else // !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5234 | av1_rc_postencode_update(cpi, *size); |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5235 | #endif // CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5236 | |
| 5237 | #if 0 |
| 5238 | output_frame_level_debug_stats(cpi); |
| 5239 | #endif |
| 5240 | |
| 5241 | if (cm->frame_type == KEY_FRAME) { |
| 5242 | // Tell the caller that the frame was coded as a key frame |
| 5243 | *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY; |
| 5244 | } else { |
| 5245 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5246 | } |
| 5247 | |
| 5248 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 5249 | // filter deltas. |
| 5250 | cm->seg.update_map = 0; |
| 5251 | cm->seg.update_data = 0; |
| 5252 | cm->lf.mode_ref_delta_update = 0; |
| 5253 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5254 | if (cm->show_frame) { |
| 5255 | #if CONFIG_EXT_REFS |
| 5256 | // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that are |
| 5257 | // being used as reference. |
| 5258 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5259 | av1_swap_mi_and_prev_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5260 | // Don't increment frame counters if this was an altref buffer |
| 5261 | // update not a real frame |
| 5262 | ++cm->current_video_frame; |
| 5263 | } |
| 5264 | |
| 5265 | #if CONFIG_EXT_REFS |
| 5266 | // NOTE: Shall not refer to any frame not used as reference. |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5267 | if (cm->is_reference_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5268 | #endif // CONFIG_EXT_REFS |
| 5269 | cm->prev_frame = cm->cur_frame; |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5270 | // keep track of the last coded dimensions |
| 5271 | cm->last_width = cm->width; |
| 5272 | cm->last_height = cm->height; |
| 5273 | |
| 5274 | // reset to normal state now that we are done. |
| 5275 | cm->last_show_frame = cm->show_frame; |
| 5276 | #if CONFIG_EXT_REFS |
| 5277 | } |
| 5278 | #endif // CONFIG_EXT_REFS |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5279 | |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5280 | aom_free(tile_ctxs); |
| 5281 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5282 | } |
| 5283 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5284 | static void Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5285 | int skip_adapt, unsigned int *frame_flags) { |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5286 | #if CONFIG_XIPHRC |
| 5287 | int64_t ip_count; |
| 5288 | int frame_type, is_golden, is_altref; |
| 5289 | |
| 5290 | /* Not updated during init so update it here */ |
| 5291 | if (cpi->oxcf.rc_mode == AOM_Q) cpi->od_rc.quality = cpi->oxcf.cq_level; |
| 5292 | |
| 5293 | frame_type = od_frame_type(&cpi->od_rc, cpi->od_rc.cur_frame, &is_golden, |
| 5294 | &is_altref, &ip_count); |
| 5295 | |
| 5296 | if (frame_type == OD_I_FRAME) { |
| 5297 | frame_type = KEY_FRAME; |
| 5298 | cpi->frame_flags &= FRAMEFLAGS_KEY; |
| 5299 | } else if (frame_type == OD_P_FRAME) { |
| 5300 | frame_type = INTER_FRAME; |
| 5301 | } |
| 5302 | |
| 5303 | if (is_altref) { |
| 5304 | cpi->refresh_alt_ref_frame = 1; |
| 5305 | cpi->rc.source_alt_ref_active = 1; |
| 5306 | } |
| 5307 | |
| 5308 | cpi->refresh_golden_frame = is_golden; |
| 5309 | cpi->common.frame_type = frame_type; |
| 5310 | if (is_golden) cpi->frame_flags &= FRAMEFLAGS_GOLDEN; |
| 5311 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5312 | if (cpi->oxcf.rc_mode == AOM_CBR) { |
| 5313 | av1_rc_get_one_pass_cbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5314 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5315 | av1_rc_get_one_pass_vbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5316 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5317 | #endif |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5318 | encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5319 | } |
| 5320 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5321 | #if !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5322 | static void Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5323 | unsigned int *frame_flags) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5324 | encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5325 | |
| 5326 | #if CONFIG_EXT_REFS |
| 5327 | // Do not do post-encoding update for those frames that do not have a spot in |
| 5328 | // a gf group, but note that an OVERLAY frame always has a spot in a gf group, |
| 5329 | // even when show_existing_frame is used. |
| 5330 | 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] | 5331 | av1_twopass_postencode_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5332 | } |
| 5333 | check_show_existing_frame(cpi); |
| 5334 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5335 | av1_twopass_postencode_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5336 | #endif // CONFIG_EXT_REFS |
| 5337 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5338 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5339 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5340 | static void init_ref_frame_bufs(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5341 | int i; |
| 5342 | BufferPool *const pool = cm->buffer_pool; |
| 5343 | cm->new_fb_idx = INVALID_IDX; |
| 5344 | for (i = 0; i < REF_FRAMES; ++i) { |
| 5345 | cm->ref_frame_map[i] = INVALID_IDX; |
| 5346 | pool->frame_bufs[i].ref_count = 0; |
| 5347 | } |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 5348 | #if CONFIG_HASH_ME |
| 5349 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 5350 | av1_hash_table_init(&pool->frame_bufs[i].hash_table); |
| 5351 | } |
| 5352 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5353 | } |
| 5354 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5355 | static void check_initial_width(AV1_COMP *cpi, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5356 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5357 | int use_highbitdepth, |
| 5358 | #endif |
| 5359 | int subsampling_x, int subsampling_y) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5360 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5361 | |
| 5362 | if (!cpi->initial_width || |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5363 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5364 | cm->use_highbitdepth != use_highbitdepth || |
| 5365 | #endif |
| 5366 | cm->subsampling_x != subsampling_x || |
| 5367 | cm->subsampling_y != subsampling_y) { |
| 5368 | cm->subsampling_x = subsampling_x; |
| 5369 | cm->subsampling_y = subsampling_y; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5370 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5371 | cm->use_highbitdepth = use_highbitdepth; |
| 5372 | #endif |
| 5373 | |
| 5374 | alloc_raw_frame_buffers(cpi); |
| 5375 | init_ref_frame_bufs(cm); |
| 5376 | alloc_util_frame_buffers(cpi); |
| 5377 | |
| 5378 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 5379 | |
| 5380 | cpi->initial_width = cm->width; |
| 5381 | cpi->initial_height = cm->height; |
| 5382 | cpi->initial_mbs = cm->MBs; |
| 5383 | } |
| 5384 | } |
| 5385 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 5386 | 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] | 5387 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 5388 | int64_t end_time) { |
| 5389 | AV1_COMMON *const cm = &cpi->common; |
| 5390 | struct aom_usec_timer timer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5391 | int res = 0; |
| 5392 | const int subsampling_x = sd->subsampling_x; |
| 5393 | const int subsampling_y = sd->subsampling_y; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5394 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5395 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
| 5396 | #endif |
| 5397 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5398 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5399 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
| 5400 | #else |
| 5401 | check_initial_width(cpi, subsampling_x, subsampling_y); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5402 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5403 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5404 | aom_usec_timer_start(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5405 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5406 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5407 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5408 | use_highbitdepth, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5409 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5410 | frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5411 | res = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5412 | aom_usec_timer_mark(&timer); |
| 5413 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5414 | |
| 5415 | if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && |
| 5416 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5417 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5418 | "Non-4:2:0 color format requires profile 1 or 3"); |
| 5419 | res = -1; |
| 5420 | } |
| 5421 | if ((cm->profile == PROFILE_1 || cm->profile == PROFILE_3) && |
| 5422 | (subsampling_x == 1 && subsampling_y == 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5423 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5424 | "4:2:0 color format requires profile 0 or 2"); |
| 5425 | res = -1; |
| 5426 | } |
| 5427 | |
| 5428 | return res; |
| 5429 | } |
| 5430 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5431 | static int frame_is_reference(const AV1_COMP *cpi) { |
| 5432 | const AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5433 | |
| 5434 | return cm->frame_type == KEY_FRAME || cpi->refresh_last_frame || |
| 5435 | cpi->refresh_golden_frame || |
| 5436 | #if CONFIG_EXT_REFS |
| 5437 | cpi->refresh_bwd_ref_frame || |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5438 | #if CONFIG_ALTREF2 |
| 5439 | cpi->refresh_alt2_ref_frame || |
| 5440 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5441 | #endif // CONFIG_EXT_REFS |
| 5442 | cpi->refresh_alt_ref_frame || !cm->error_resilient_mode || |
| 5443 | cm->lf.mode_ref_delta_update || cm->seg.update_map || |
| 5444 | cm->seg.update_data; |
| 5445 | } |
| 5446 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5447 | static void adjust_frame_rate(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5448 | const struct lookahead_entry *source) { |
| 5449 | int64_t this_duration; |
| 5450 | int step = 0; |
| 5451 | |
| 5452 | if (source->ts_start == cpi->first_time_stamp_ever) { |
| 5453 | this_duration = source->ts_end - source->ts_start; |
| 5454 | step = 1; |
| 5455 | } else { |
| 5456 | int64_t last_duration = |
| 5457 | cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen; |
| 5458 | |
| 5459 | this_duration = source->ts_end - cpi->last_end_time_stamp_seen; |
| 5460 | |
| 5461 | // do a step update if the duration changes by 10% |
| 5462 | if (last_duration) |
| 5463 | step = (int)((this_duration - last_duration) * 10 / last_duration); |
| 5464 | } |
| 5465 | |
| 5466 | if (this_duration) { |
| 5467 | if (step) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5468 | av1_new_framerate(cpi, 10000000.0 / this_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5469 | } else { |
| 5470 | // Average this frame's rate into the last second's average |
| 5471 | // frame rate. If we haven't seen 1 second yet, then average |
| 5472 | // over the whole interval seen. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5473 | const double interval = AOMMIN( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5474 | (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0); |
| 5475 | double avg_duration = 10000000.0 / cpi->framerate; |
| 5476 | avg_duration *= (interval - avg_duration + this_duration); |
| 5477 | avg_duration /= interval; |
| 5478 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5479 | av1_new_framerate(cpi, 10000000.0 / avg_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5480 | } |
| 5481 | } |
| 5482 | cpi->last_time_stamp_seen = source->ts_start; |
| 5483 | cpi->last_end_time_stamp_seen = source->ts_end; |
| 5484 | } |
| 5485 | |
| 5486 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5487 | // used as the arf midpoint. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5488 | static int get_arf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5489 | RATE_CONTROL *const rc = &cpi->rc; |
| 5490 | int arf_src_index = 0; |
| 5491 | if (is_altref_enabled(cpi)) { |
| 5492 | if (cpi->oxcf.pass == 2) { |
| 5493 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5494 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 5495 | arf_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5496 | } |
| 5497 | } else if (rc->source_alt_ref_pending) { |
| 5498 | arf_src_index = rc->frames_till_gf_update_due; |
| 5499 | } |
| 5500 | } |
| 5501 | return arf_src_index; |
| 5502 | } |
| 5503 | |
| 5504 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5505 | static int get_brf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5506 | int brf_src_index = 0; |
| 5507 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5508 | |
| 5509 | // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup |
| 5510 | // flag. |
| 5511 | if (gf_group->bidir_pred_enabled[gf_group->index]) { |
| 5512 | if (cpi->oxcf.pass == 2) { |
| 5513 | if (gf_group->update_type[gf_group->index] == BRF_UPDATE) |
| 5514 | brf_src_index = gf_group->brf_src_offset[gf_group->index]; |
| 5515 | } else { |
| 5516 | // TODO(zoeliu): To re-visit the setup for this scenario |
| 5517 | brf_src_index = cpi->rc.bipred_group_interval - 1; |
| 5518 | } |
| 5519 | } |
| 5520 | |
| 5521 | return brf_src_index; |
| 5522 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5523 | |
| 5524 | #if CONFIG_ALTREF2 |
| 5525 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5526 | // used as the arf midpoint. |
| 5527 | static int get_arf2_src_index(AV1_COMP *cpi) { |
| 5528 | int arf2_src_index = 0; |
| 5529 | if (is_altref_enabled(cpi) && cpi->num_extra_arfs) { |
| 5530 | if (cpi->oxcf.pass == 2) { |
| 5531 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5532 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) { |
| 5533 | arf2_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5534 | } |
| 5535 | } |
| 5536 | } |
| 5537 | return arf2_src_index; |
| 5538 | } |
| 5539 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5540 | #endif // CONFIG_EXT_REFS |
| 5541 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5542 | static void check_src_altref(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5543 | const struct lookahead_entry *source) { |
| 5544 | RATE_CONTROL *const rc = &cpi->rc; |
| 5545 | |
| 5546 | // If pass == 2, the parameters set here will be reset in |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5547 | // av1_rc_get_second_pass_params() |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5548 | |
| 5549 | if (cpi->oxcf.pass == 2) { |
| 5550 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5551 | rc->is_src_frame_alt_ref = |
| 5552 | #if CONFIG_EXT_REFS |
| 5553 | (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) || |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 5554 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5555 | (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); |
Zoe Liu | 438b3ae | 2017-08-01 17:36:04 -0700 | [diff] [blame] | 5556 | #if CONFIG_ALTREF2 |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5557 | rc->is_src_frame_ext_arf = |
| 5558 | gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE; |
Zoe Liu | 438b3ae | 2017-08-01 17:36:04 -0700 | [diff] [blame] | 5559 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5560 | } else { |
| 5561 | rc->is_src_frame_alt_ref = |
| 5562 | cpi->alt_ref_source && (source == cpi->alt_ref_source); |
| 5563 | } |
| 5564 | |
| 5565 | if (rc->is_src_frame_alt_ref) { |
| 5566 | // Current frame is an ARF overlay frame. |
| 5567 | cpi->alt_ref_source = NULL; |
| 5568 | |
Zoe Liu | 438b3ae | 2017-08-01 17:36:04 -0700 | [diff] [blame] | 5569 | #if CONFIG_ALTREF2 |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5570 | if (rc->is_src_frame_ext_arf && !cpi->common.show_existing_frame) { |
| 5571 | // For INTNL_OVERLAY, when show_existing_frame == 0, they do need to |
| 5572 | // refresh the LAST_FRAME, i.e. LAST3 gets retired, LAST2 becomes LAST3, |
| 5573 | // LAST becomes LAST2, and INTNL_OVERLAY becomes LAST. |
| 5574 | cpi->refresh_last_frame = 1; |
| 5575 | } else { |
Zoe Liu | 438b3ae | 2017-08-01 17:36:04 -0700 | [diff] [blame] | 5576 | #endif // CONFIG_ALTREF2 |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5577 | // Don't refresh the last buffer for an ARF overlay frame. It will |
| 5578 | // become the GF so preserve last as an alternative prediction option. |
| 5579 | cpi->refresh_last_frame = 0; |
Zoe Liu | 438b3ae | 2017-08-01 17:36:04 -0700 | [diff] [blame] | 5580 | #if CONFIG_ALTREF2 |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5581 | } |
Zoe Liu | 438b3ae | 2017-08-01 17:36:04 -0700 | [diff] [blame] | 5582 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5583 | } |
| 5584 | } |
| 5585 | |
| 5586 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5587 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 5588 | const unsigned char *img2, int img2_pitch, |
| 5589 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5590 | |
| 5591 | static void adjust_image_stat(double y, double u, double v, double all, |
| 5592 | ImageStat *s) { |
| 5593 | s->stat[Y] += y; |
| 5594 | s->stat[U] += u; |
| 5595 | s->stat[V] += v; |
| 5596 | s->stat[ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5597 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5598 | } |
| 5599 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5600 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5601 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5602 | double samples = 0.0; |
| 5603 | uint32_t in_bit_depth = 8; |
| 5604 | uint32_t bit_depth = 8; |
| 5605 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5606 | #if CONFIG_INTER_STATS_ONLY |
Yaowu Xu | 1b4ffc4 | 2017-07-26 09:54:07 -0700 | [diff] [blame] | 5607 | if (cm->frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5608 | #endif |
| 5609 | cpi->bytes += frame_bytes; |
| 5610 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5611 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5612 | if (cm->use_highbitdepth) { |
| 5613 | in_bit_depth = cpi->oxcf.input_bit_depth; |
| 5614 | bit_depth = cm->bit_depth; |
| 5615 | } |
| 5616 | #endif |
| 5617 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5618 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5619 | const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; |
| 5620 | double y, u, v, frame_all; |
| 5621 | |
| 5622 | cpi->count++; |
| 5623 | if (cpi->b_calculate_psnr) { |
| 5624 | PSNR_STATS psnr; |
| 5625 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5626 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5627 | // TODO(yaowu): unify these two versions into one. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5628 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5629 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5630 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5631 | aom_calc_psnr(orig, recon, &psnr); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5632 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5633 | |
| 5634 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 5635 | &cpi->psnr); |
| 5636 | cpi->total_sq_error += psnr.sse[0]; |
| 5637 | cpi->total_samples += psnr.samples[0]; |
| 5638 | samples = psnr.samples[0]; |
| 5639 | // TODO(yaowu): unify these two versions into one. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5640 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5641 | if (cm->use_highbitdepth) |
| 5642 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5643 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5644 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5645 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5646 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5647 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5648 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5649 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5650 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5651 | cpi->summed_quality += frame_ssim2 * weight; |
| 5652 | cpi->summed_weights += weight; |
| 5653 | |
| 5654 | #if 0 |
| 5655 | { |
| 5656 | FILE *f = fopen("q_used.stt", "a"); |
| 5657 | fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", |
| 5658 | cpi->common.current_video_frame, y2, u2, v2, |
| 5659 | frame_psnr2, frame_ssim2); |
| 5660 | fclose(f); |
| 5661 | } |
| 5662 | #endif |
| 5663 | } |
| 5664 | if (cpi->b_calculate_blockiness) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5665 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5666 | if (!cm->use_highbitdepth) |
| 5667 | #endif |
| 5668 | { |
| 5669 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5670 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 5671 | recon->y_stride, orig->y_width, orig->y_height); |
| 5672 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5673 | cpi->total_blockiness += frame_blockiness; |
| 5674 | } |
| 5675 | |
| 5676 | if (cpi->b_calculate_consistency) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5677 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5678 | if (!cm->use_highbitdepth) |
| 5679 | #endif |
| 5680 | { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5681 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5682 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 5683 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 5684 | |
| 5685 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 5686 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5687 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5688 | if (consistency > 0.0) |
| 5689 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5690 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5691 | cpi->total_inconsistency += this_inconsistency; |
| 5692 | } |
| 5693 | } |
| 5694 | } |
| 5695 | |
| 5696 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5697 | 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] | 5698 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5699 | 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] | 5700 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 5701 | } |
| 5702 | } |
| 5703 | #endif // CONFIG_INTERNAL_STATS |
| 5704 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5705 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 5706 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 5707 | int64_t *time_end, int flush) { |
| 5708 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 5709 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5710 | BufferPool *const pool = cm->buffer_pool; |
| 5711 | RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5712 | struct aom_usec_timer cmptimer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5713 | YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
| 5714 | struct lookahead_entry *last_source = NULL; |
| 5715 | struct lookahead_entry *source = NULL; |
| 5716 | int arf_src_index; |
| 5717 | #if CONFIG_EXT_REFS |
| 5718 | int brf_src_index; |
| 5719 | #endif // CONFIG_EXT_REFS |
| 5720 | int i; |
| 5721 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5722 | #if CONFIG_XIPHRC |
| 5723 | cpi->od_rc.end_of_input = flush; |
| 5724 | #endif |
| 5725 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5726 | #if CONFIG_BITSTREAM_DEBUG |
| 5727 | assert(cpi->oxcf.max_threads == 0 && |
| 5728 | "bitstream debug tool does not support multithreading"); |
| 5729 | bitstream_queue_record_write(); |
Angie Chiang | cb9a9eb | 2016-09-01 16:10:50 -0700 | [diff] [blame] | 5730 | 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] | 5731 | #endif |
| 5732 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5733 | aom_usec_timer_start(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5734 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5735 | av1_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5736 | |
| 5737 | // Is multi-arf enabled. |
| 5738 | // Note that at the moment multi_arf is only configured for 2 pass VBR |
| 5739 | if ((oxcf->pass == 2) && (cpi->oxcf.enable_auto_arf > 1)) |
| 5740 | cpi->multi_arf_allowed = 1; |
| 5741 | else |
| 5742 | cpi->multi_arf_allowed = 0; |
| 5743 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 5744 | // Normal defaults |
| 5745 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5746 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 5747 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5748 | cm->refresh_frame_context = |
| 5749 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 5750 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 5751 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
| 5752 | |
| 5753 | cpi->refresh_last_frame = 1; |
| 5754 | cpi->refresh_golden_frame = 0; |
| 5755 | #if CONFIG_EXT_REFS |
| 5756 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5757 | #if CONFIG_ALTREF2 |
| 5758 | cpi->refresh_alt2_ref_frame = 0; |
| 5759 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5760 | #endif // CONFIG_EXT_REFS |
| 5761 | cpi->refresh_alt_ref_frame = 0; |
| 5762 | |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5763 | #if CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5764 | if (oxcf->pass == 2 && cm->show_existing_frame) { |
| 5765 | // Manage the source buffer and flush out the source frame that has been |
| 5766 | // coded already; Also get prepared for PSNR calculation if needed. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5767 | if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5768 | *size = 0; |
| 5769 | return -1; |
| 5770 | } |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5771 | cpi->source = &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5772 | // TODO(zoeliu): To track down to determine whether it's needed to adjust |
| 5773 | // the frame rate. |
| 5774 | *time_stamp = source->ts_start; |
| 5775 | *time_end = source->ts_end; |
| 5776 | |
| 5777 | // We need to adjust frame rate for an overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5778 | 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] | 5779 | |
| 5780 | // Find a free buffer for the new frame, releasing the reference previously |
| 5781 | // held. |
| 5782 | if (cm->new_fb_idx != INVALID_IDX) { |
| 5783 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 5784 | } |
| 5785 | cm->new_fb_idx = get_free_fb(cm); |
| 5786 | |
| 5787 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 5788 | |
| 5789 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5790 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5791 | |
| 5792 | // Start with a 0 size frame. |
| 5793 | *size = 0; |
| 5794 | |
| 5795 | // We need to update the gf_group for show_existing overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5796 | 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] | 5797 | |
| 5798 | Pass2Encode(cpi, size, dest, frame_flags); |
| 5799 | |
| 5800 | if (cpi->b_calculate_psnr) generate_psnr_packet(cpi); |
| 5801 | |
| 5802 | #if CONFIG_INTERNAL_STATS |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5803 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5804 | #endif // CONFIG_INTERNAL_STATS |
| 5805 | |
| 5806 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5807 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5808 | |
| 5809 | cm->show_existing_frame = 0; |
| 5810 | return 0; |
| 5811 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5812 | #endif // CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5813 | |
| 5814 | // Should we encode an arf frame. |
| 5815 | arf_src_index = get_arf_src_index(cpi); |
| 5816 | if (arf_src_index) { |
| 5817 | for (i = 0; i <= arf_src_index; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5818 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5819 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 5820 | if (e == NULL) { |
| 5821 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5822 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5823 | arf_src_index = 0; |
| 5824 | flush = 1; |
| 5825 | break; |
| 5826 | } |
| 5827 | } |
| 5828 | } |
| 5829 | |
| 5830 | if (arf_src_index) { |
| 5831 | assert(arf_src_index <= rc->frames_to_key); |
| 5832 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5833 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5834 | cpi->alt_ref_source = source; |
| 5835 | |
| 5836 | if (oxcf->arnr_max_frames > 0) { |
Todd Nguyen | 302d097 | 2017-06-16 16:16:29 -0700 | [diff] [blame] | 5837 | // Produce the filtered ARF frame. |
| 5838 | #if CONFIG_BGSPRITE |
| 5839 | int bgsprite_ret = av1_background_sprite(cpi, arf_src_index); |
Todd Nguyen | 2fc2309 | 2017-07-11 12:00:36 -0700 | [diff] [blame] | 5840 | // Do temporal filter if bgsprite not generated. |
| 5841 | if (bgsprite_ret != 0) |
Todd Nguyen | 302d097 | 2017-06-16 16:16:29 -0700 | [diff] [blame] | 5842 | #endif // CONFIG_BGSPRITE |
Todd Nguyen | 8493f91 | 2017-07-20 12:45:12 -0700 | [diff] [blame] | 5843 | av1_temporal_filter(cpi, |
| 5844 | #if CONFIG_BGSPRITE |
Todd Nguyen | 1fd99c2 | 2017-07-31 17:50:41 -0700 | [diff] [blame] | 5845 | NULL, &cpi->alt_ref_buffer, |
Todd Nguyen | 8493f91 | 2017-07-20 12:45:12 -0700 | [diff] [blame] | 5846 | #endif // CONFIG_BGSPRITE |
| 5847 | arf_src_index); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5848 | aom_extend_frame_borders(&cpi->alt_ref_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5849 | force_src_buffer = &cpi->alt_ref_buffer; |
| 5850 | } |
| 5851 | |
| 5852 | cm->show_frame = 0; |
| 5853 | cm->intra_only = 0; |
| 5854 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5855 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5856 | cpi->refresh_golden_frame = 0; |
| 5857 | #if CONFIG_EXT_REFS |
| 5858 | cpi->refresh_bwd_ref_frame = 0; |
| 5859 | #if CONFIG_ALTREF2 |
| 5860 | cpi->refresh_alt2_ref_frame = 0; |
| 5861 | #endif // CONFIG_ALTREF2 |
| 5862 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5863 | rc->is_src_frame_alt_ref = 0; |
| 5864 | } |
| 5865 | rc->source_alt_ref_pending = 0; |
| 5866 | } |
| 5867 | |
| 5868 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5869 | #if CONFIG_ALTREF2 |
| 5870 | // Should we encode an arf2 frame. |
| 5871 | arf_src_index = get_arf2_src_index(cpi); |
| 5872 | if (arf_src_index) { |
| 5873 | for (i = 0; i <= arf_src_index; ++i) { |
| 5874 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
| 5875 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 5876 | if (e == NULL) { |
| 5877 | break; |
| 5878 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
| 5879 | arf_src_index = 0; |
| 5880 | flush = 1; |
| 5881 | break; |
| 5882 | } |
| 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | if (arf_src_index) { |
| 5887 | assert(arf_src_index <= rc->frames_to_key); |
| 5888 | |
| 5889 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
| 5890 | cpi->alt_ref_source = source; |
| 5891 | |
| 5892 | if (oxcf->arnr_max_frames > 0) { |
| 5893 | // Produce the filtered ARF frame. |
| 5894 | av1_temporal_filter(cpi, arf_src_index); |
| 5895 | aom_extend_frame_borders(&cpi->alt_ref_buffer); |
| 5896 | force_src_buffer = &cpi->alt_ref_buffer; |
| 5897 | } |
| 5898 | |
| 5899 | cm->show_frame = 0; |
| 5900 | cm->intra_only = 0; |
| 5901 | cpi->refresh_alt2_ref_frame = 1; |
| 5902 | cpi->refresh_last_frame = 0; |
| 5903 | cpi->refresh_golden_frame = 0; |
| 5904 | cpi->refresh_bwd_ref_frame = 0; |
| 5905 | cpi->refresh_alt_ref_frame = 0; |
| 5906 | rc->is_src_frame_alt_ref = 0; |
| 5907 | rc->is_src_frame_ext_arf = 0; |
| 5908 | } |
| 5909 | rc->source_alt_ref_pending = 0; |
| 5910 | } |
| 5911 | #endif // CONFIG_ALTREF2 |
| 5912 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5913 | rc->is_bwd_ref_frame = 0; |
| 5914 | brf_src_index = get_brf_src_index(cpi); |
| 5915 | if (brf_src_index) { |
| 5916 | assert(brf_src_index <= rc->frames_to_key); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5917 | if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5918 | cm->show_frame = 0; |
| 5919 | cm->intra_only = 0; |
| 5920 | |
| 5921 | cpi->refresh_bwd_ref_frame = 1; |
| 5922 | cpi->refresh_last_frame = 0; |
| 5923 | cpi->refresh_golden_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5924 | #if CONFIG_ALTREF2 |
| 5925 | cpi->refresh_alt2_ref_frame = 0; |
| 5926 | #endif // CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5927 | cpi->refresh_alt_ref_frame = 0; |
| 5928 | |
| 5929 | rc->is_bwd_ref_frame = 1; |
| 5930 | } |
| 5931 | } |
| 5932 | #endif // CONFIG_EXT_REFS |
| 5933 | |
| 5934 | if (!source) { |
| 5935 | // Get last frame source. |
| 5936 | if (cm->current_video_frame > 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5937 | if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5938 | return -1; |
| 5939 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5940 | if (cm->current_video_frame > 0) assert(last_source != NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5941 | // Read in the source frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5942 | source = av1_lookahead_pop(cpi->lookahead, flush); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5943 | |
| 5944 | if (source != NULL) { |
| 5945 | cm->show_frame = 1; |
| 5946 | cm->intra_only = 0; |
| 5947 | |
| 5948 | // Check to see if the frame should be encoded as an arf overlay. |
| 5949 | check_src_altref(cpi, source); |
| 5950 | } |
| 5951 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5952 | if (source) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5953 | cpi->unscaled_source = cpi->source = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5954 | force_src_buffer ? force_src_buffer : &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5955 | cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL; |
| 5956 | |
| 5957 | *time_stamp = source->ts_start; |
| 5958 | *time_end = source->ts_end; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5959 | *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5960 | |
| 5961 | } else { |
| 5962 | *size = 0; |
| 5963 | if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5964 | #if CONFIG_XIPHRC |
| 5965 | od_enc_rc_2pass_out(&cpi->od_rc, cpi->output_pkt_list, 1); |
| 5966 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5967 | av1_end_first_pass(cpi); /* get last stats packet */ |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5968 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5969 | cpi->twopass.first_pass_done = 1; |
| 5970 | } |
| 5971 | return -1; |
| 5972 | } |
| 5973 | |
| 5974 | if (source->ts_start < cpi->first_time_stamp_ever) { |
| 5975 | cpi->first_time_stamp_ever = source->ts_start; |
| 5976 | cpi->last_end_time_stamp_seen = source->ts_start; |
| 5977 | } |
| 5978 | |
| 5979 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5980 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5981 | |
| 5982 | // adjust frame rates based on timestamps given |
| 5983 | if (cm->show_frame) adjust_frame_rate(cpi, source); |
| 5984 | |
| 5985 | // Find a free buffer for the new frame, releasing the reference previously |
| 5986 | // held. |
| 5987 | if (cm->new_fb_idx != INVALID_IDX) { |
| 5988 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 5989 | } |
| 5990 | cm->new_fb_idx = get_free_fb(cm); |
| 5991 | |
| 5992 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 5993 | |
| 5994 | cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 5995 | #if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION |
| 5996 | cm->cur_frame->buf.buf_8bit_valid = 0; |
| 5997 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5998 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5999 | #if !CONFIG_ALTREF2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6000 | if (oxcf->pass == 2) { |
| 6001 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 6002 | cpi->alt_fb_idx = cpi->arf_map[gf_group->arf_ref_idx[gf_group->index]]; |
| 6003 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 6004 | #endif // !CONFIG_ALTREF2 |
| 6005 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6006 | if (cpi->multi_arf_allowed) { |
| 6007 | if (cm->frame_type == KEY_FRAME) { |
| 6008 | init_buffer_indices(cpi); |
| 6009 | } else if (oxcf->pass == 2) { |
| 6010 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 6011 | cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; |
| 6012 | } |
| 6013 | } |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 6014 | #endif // CONFIG_EXT_REFS |
| 6015 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6016 | // Start with a 0 size frame. |
| 6017 | *size = 0; |
| 6018 | |
| 6019 | cpi->frame_flags = *frame_flags; |
| 6020 | |
| 6021 | if (oxcf->pass == 2) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6022 | #if CONFIG_XIPHRC |
| 6023 | if (od_enc_rc_2pass_in(&cpi->od_rc) < 0) return -1; |
| 6024 | } |
| 6025 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6026 | av1_rc_get_second_pass_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6027 | } else if (oxcf->pass == 1) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 6028 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6029 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6030 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6031 | |
| 6032 | if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) { |
| 6033 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) |
| 6034 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 6035 | } |
| 6036 | |
| 6037 | #if CONFIG_AOM_QM |
| 6038 | cm->using_qmatrix = cpi->oxcf.using_qm; |
| 6039 | cm->min_qmlevel = cpi->oxcf.qm_minlevel; |
| 6040 | cm->max_qmlevel = cpi->oxcf.qm_maxlevel; |
| 6041 | #endif |
| 6042 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 6043 | #if CONFIG_REFERENCE_BUFFER |
| 6044 | if (*time_stamp == 0) { |
| 6045 | cpi->common.current_frame_id = -1; |
| 6046 | } |
| 6047 | #endif |
| 6048 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6049 | #if CONFIG_XIPHRC |
| 6050 | if (oxcf->pass == 1) { |
| 6051 | size_t tmp; |
| 6052 | if (cpi->od_rc.cur_frame == 0) Pass0Encode(cpi, &tmp, dest, 1, frame_flags); |
| 6053 | cpi->od_rc.firstpass_quant = cpi->od_rc.target_quantizer; |
| 6054 | Pass0Encode(cpi, &tmp, dest, 0, frame_flags); |
| 6055 | od_enc_rc_2pass_out(&cpi->od_rc, cpi->output_pkt_list, 0); |
| 6056 | } else if (oxcf->pass == 2) { |
| 6057 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
| 6058 | } else { |
| 6059 | if (cpi->od_rc.cur_frame == 0) { |
| 6060 | size_t tmp; |
| 6061 | Pass0Encode(cpi, &tmp, dest, 1, frame_flags); |
| 6062 | } |
| 6063 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
| 6064 | } |
| 6065 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6066 | if (oxcf->pass == 1) { |
| 6067 | cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6068 | av1_first_pass(cpi, source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6069 | } else if (oxcf->pass == 2) { |
| 6070 | Pass2Encode(cpi, size, dest, frame_flags); |
| 6071 | } else { |
| 6072 | // One pass encode |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6073 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6074 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 6075 | #endif |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 6076 | #if CONFIG_HASH_ME |
| 6077 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
| 6078 | // add to hash table |
| 6079 | const int pic_width = cpi->source->y_crop_width; |
| 6080 | const int pic_height = cpi->source->y_crop_height; |
| 6081 | uint32_t *block_hash_values[2][2]; |
| 6082 | int8_t *is_block_same[2][3]; |
| 6083 | int k, j; |
| 6084 | |
| 6085 | for (k = 0; k < 2; k++) { |
| 6086 | for (j = 0; j < 2; j++) { |
| 6087 | CHECK_MEM_ERROR(cm, block_hash_values[k][j], |
| 6088 | aom_malloc(sizeof(uint32_t) * pic_width * pic_height)); |
| 6089 | } |
| 6090 | |
| 6091 | for (j = 0; j < 3; j++) { |
| 6092 | CHECK_MEM_ERROR(cm, is_block_same[k][j], |
| 6093 | aom_malloc(sizeof(int8_t) * pic_width * pic_height)); |
| 6094 | } |
| 6095 | } |
| 6096 | |
| 6097 | av1_hash_table_create(&cm->cur_frame->hash_table); |
| 6098 | av1_generate_block_2x2_hash_value(cpi->source, block_hash_values[0], |
| 6099 | is_block_same[0]); |
| 6100 | av1_generate_block_hash_value(cpi->source, 4, block_hash_values[0], |
| 6101 | block_hash_values[1], is_block_same[0], |
| 6102 | is_block_same[1]); |
| 6103 | av1_generate_block_hash_value(cpi->source, 8, block_hash_values[1], |
| 6104 | block_hash_values[0], is_block_same[1], |
| 6105 | is_block_same[0]); |
| 6106 | av1_add_to_hash_map_by_row_with_precal_data( |
| 6107 | &cm->cur_frame->hash_table, block_hash_values[0], is_block_same[0][2], |
| 6108 | pic_width, pic_height, 8); |
| 6109 | av1_generate_block_hash_value(cpi->source, 16, block_hash_values[0], |
| 6110 | block_hash_values[1], is_block_same[0], |
| 6111 | is_block_same[1]); |
| 6112 | av1_add_to_hash_map_by_row_with_precal_data( |
| 6113 | &cm->cur_frame->hash_table, block_hash_values[1], is_block_same[1][2], |
| 6114 | pic_width, pic_height, 16); |
| 6115 | av1_generate_block_hash_value(cpi->source, 32, block_hash_values[1], |
| 6116 | block_hash_values[0], is_block_same[1], |
| 6117 | is_block_same[0]); |
| 6118 | av1_add_to_hash_map_by_row_with_precal_data( |
| 6119 | &cm->cur_frame->hash_table, block_hash_values[0], is_block_same[0][2], |
| 6120 | pic_width, pic_height, 32); |
| 6121 | av1_generate_block_hash_value(cpi->source, 64, block_hash_values[0], |
| 6122 | block_hash_values[1], is_block_same[0], |
| 6123 | is_block_same[1]); |
| 6124 | av1_add_to_hash_map_by_row_with_precal_data( |
| 6125 | &cm->cur_frame->hash_table, block_hash_values[1], is_block_same[1][2], |
| 6126 | pic_width, pic_height, 64); |
| 6127 | |
| 6128 | for (k = 0; k < 2; k++) { |
| 6129 | for (j = 0; j < 2; j++) { |
| 6130 | aom_free(block_hash_values[k][j]); |
| 6131 | } |
| 6132 | |
| 6133 | for (j = 0; j < 3; j++) { |
| 6134 | aom_free(is_block_same[k][j]); |
| 6135 | } |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | #endif |
| 6140 | |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 6141 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 6142 | cm->frame_contexts[cm->new_fb_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 6143 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6144 | if (!cm->error_resilient_mode) |
| 6145 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 6146 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6147 | |
| 6148 | // No frame encoded, or frame was dropped, release scaled references. |
| 6149 | if ((*size == 0) && (frame_is_intra_only(cm) == 0)) { |
| 6150 | release_scaled_references(cpi); |
| 6151 | } |
| 6152 | |
| 6153 | if (*size > 0) { |
| 6154 | cpi->droppable = !frame_is_reference(cpi); |
| 6155 | } |
| 6156 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6157 | aom_usec_timer_mark(&cmptimer); |
| 6158 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6159 | |
| 6160 | if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame) |
| 6161 | generate_psnr_packet(cpi); |
| 6162 | |
| 6163 | #if CONFIG_INTERNAL_STATS |
| 6164 | if (oxcf->pass != 1) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6165 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6166 | } |
| 6167 | #endif // CONFIG_INTERNAL_STATS |
| 6168 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 6169 | #if CONFIG_XIPHRC |
| 6170 | cpi->od_rc.cur_frame++; |
| 6171 | #endif |
| 6172 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6173 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6174 | |
| 6175 | return 0; |
| 6176 | } |
| 6177 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6178 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 6179 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6180 | if (!cm->show_frame) { |
| 6181 | return -1; |
| 6182 | } else { |
| 6183 | int ret; |
| 6184 | if (cm->frame_to_show) { |
| 6185 | *dest = *cm->frame_to_show; |
| 6186 | dest->y_width = cm->width; |
| 6187 | dest->y_height = cm->height; |
| 6188 | dest->uv_width = cm->width >> cm->subsampling_x; |
| 6189 | dest->uv_height = cm->height >> cm->subsampling_y; |
| 6190 | ret = 0; |
| 6191 | } else { |
| 6192 | ret = -1; |
| 6193 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6194 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6195 | return ret; |
| 6196 | } |
| 6197 | } |
| 6198 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6199 | 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] | 6200 | if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1; |
| 6201 | |
| 6202 | *frame = |
| 6203 | cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf; |
| 6204 | return 0; |
| 6205 | } |
| 6206 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6207 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 6208 | AOM_SCALING vert_mode) { |
| 6209 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6210 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 6211 | |
| 6212 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 6213 | |
| 6214 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 6215 | Scale2Ratio(vert_mode, &vr, &vs); |
| 6216 | |
| 6217 | // always go to the next whole number |
| 6218 | cm->width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 6219 | cm->height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
| 6220 | assert(cm->width <= cpi->initial_width); |
| 6221 | assert(cm->height <= cpi->initial_height); |
| 6222 | |
| 6223 | update_frame_size(cpi); |
| 6224 | |
| 6225 | return 0; |
| 6226 | } |
| 6227 | |
Fergus Simpson | 0a30c88 | 2017-05-16 16:54:51 -0700 | [diff] [blame] | 6228 | int av1_set_size_literal(AV1_COMP *cpi, int width, int height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6229 | AV1_COMMON *cm = &cpi->common; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6230 | #if CONFIG_HIGHBITDEPTH |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 6231 | check_initial_width(cpi, cm->use_highbitdepth, cm->subsampling_x, |
| 6232 | cm->subsampling_y); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6233 | #else |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 6234 | check_initial_width(cpi, cm->subsampling_x, cm->subsampling_y); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6235 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6236 | |
Fergus Simpson | 0a30c88 | 2017-05-16 16:54:51 -0700 | [diff] [blame] | 6237 | if (width <= 0 || height <= 0) return 1; |
| 6238 | |
| 6239 | cm->width = width; |
| 6240 | if (cm->width > cpi->initial_width) { |
| 6241 | cm->width = cpi->initial_width; |
| 6242 | printf("Warning: Desired width too large, changed to %d\n", cm->width); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6243 | } |
| 6244 | |
Fergus Simpson | 0a30c88 | 2017-05-16 16:54:51 -0700 | [diff] [blame] | 6245 | cm->height = height; |
| 6246 | if (cm->height > cpi->initial_height) { |
| 6247 | cm->height = cpi->initial_height; |
| 6248 | printf("Warning: Desired height too large, changed to %d\n", cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6249 | } |
Fergus Simpson | 0a30c88 | 2017-05-16 16:54:51 -0700 | [diff] [blame] | 6250 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6251 | assert(cm->width <= cpi->initial_width); |
| 6252 | assert(cm->height <= cpi->initial_height); |
| 6253 | |
| 6254 | update_frame_size(cpi); |
| 6255 | |
| 6256 | return 0; |
| 6257 | } |
| 6258 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6259 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6260 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6261 | 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] | 6262 | if (flags & |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6263 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF)) { |
| 6264 | int ref = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6265 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6266 | if (flags & AOM_EFLAG_NO_REF_LAST) { |
| 6267 | ref ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6268 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6269 | ref ^= AOM_LAST2_FLAG; |
| 6270 | ref ^= AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6271 | #endif // CONFIG_EXT_REFS |
| 6272 | } |
| 6273 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6274 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6275 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6276 | if (flags & AOM_EFLAG_NO_REF_ARF) ref ^= AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6277 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6278 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6279 | } |
| 6280 | |
| 6281 | if (flags & |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6282 | (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF | |
| 6283 | AOM_EFLAG_FORCE_GF | AOM_EFLAG_FORCE_ARF)) { |
| 6284 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6285 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6286 | if (flags & AOM_EFLAG_NO_UPD_LAST) { |
| 6287 | upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6288 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6289 | upd ^= AOM_LAST2_FLAG; |
| 6290 | upd ^= AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6291 | #endif // CONFIG_EXT_REFS |
| 6292 | } |
| 6293 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6294 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6295 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6296 | if (flags & AOM_EFLAG_NO_UPD_ARF) upd ^= AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6297 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6298 | av1_update_reference(cpi, upd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6299 | } |
| 6300 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6301 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 6302 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6303 | } |
| 6304 | } |