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 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 252 | void av1_set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv) { |
| 253 | MACROBLOCK *const mb = &cpi->td.mb; |
| 254 | cpi->common.allow_high_precision_mv = allow_high_precision_mv; |
| 255 | |
| 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]; |
| 260 | } |
| 261 | } else { |
| 262 | int i; |
| 263 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 264 | mb->mv_cost_stack[i] = mb->nmvcost[i]; |
| 265 | } |
| 266 | } |
| 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 (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 309 | cm->frame_context_idx = EXT_ARF_FRAME; |
| 310 | else if (cpi->refresh_alt_ref_frame) |
| 311 | cm->frame_context_idx = ARF_FRAME; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 312 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 313 | if (cpi->refresh_alt_ref_frame) cm->frame_context_idx = ARF_FRAME; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 314 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 315 | else if (cpi->rc.is_src_frame_alt_ref) |
| 316 | cm->frame_context_idx = OVERLAY_FRAME; |
| 317 | else if (cpi->refresh_golden_frame) |
| 318 | cm->frame_context_idx = GLD_FRAME; |
| 319 | #if CONFIG_EXT_REFS |
| 320 | else if (cpi->refresh_bwd_ref_frame) |
| 321 | cm->frame_context_idx = BRF_FRAME; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 322 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 323 | else |
| 324 | cm->frame_context_idx = REGULAR_FRAME; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 325 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | if (cm->frame_type == KEY_FRAME) { |
| 329 | cpi->refresh_golden_frame = 1; |
| 330 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 331 | av1_zero(cpi->interp_filter_selected); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 332 | } else { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 333 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 334 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
| 335 | cm->frame_refs[0].idx < 0) { |
| 336 | *cm->fc = cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 337 | } else { |
| 338 | *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx]; |
| 339 | } |
| 340 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 341 | *cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 342 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 343 | av1_zero(cpi->interp_filter_selected[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 344 | } |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 345 | #if CONFIG_EXT_REFS |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 346 | #if CONFIG_ONE_SIDED_COMPOUND && \ |
| 347 | !CONFIG_EXT_COMP_REFS // No change to bitstream |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 348 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 349 | cpi->refresh_bwd_ref_frame = cpi->refresh_last_frame; |
| 350 | cpi->rc.is_bipred_frame = 1; |
| 351 | } |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 352 | #endif // CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
| 353 | #endif // CONFIG_EXT_REFS |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 354 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 355 | if (frame_is_intra_only(cm) || cm->error_resilient_mode || |
| 356 | cm->frame_refs[0].idx < 0) { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 357 | // use default frame context values |
| 358 | cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 359 | } else { |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 360 | *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 361 | cm->pre_fc = &cm->frame_contexts[cm->frame_refs[0].idx]; |
| 362 | } |
| 363 | #else |
Thomas Daede | 10e1da9 | 2017-04-26 13:22:21 -0700 | [diff] [blame] | 364 | cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx]; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 365 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 366 | |
| 367 | cpi->vaq_refresh = 0; |
| 368 | |
| 369 | set_sb_size(cm, select_sb_size(cpi)); |
| 370 | } |
| 371 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 372 | static void av1_enc_setup_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 373 | int i; |
| 374 | cm->mi = cm->mip + cm->mi_stride + 1; |
| 375 | memset(cm->mip, 0, cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip)); |
| 376 | cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 377 | // Clear top border row |
| 378 | memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride); |
| 379 | // Clear left border column |
| 380 | for (i = 1; i < cm->mi_rows + 1; ++i) |
| 381 | 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] | 382 | cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; |
| 383 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; |
| 384 | |
| 385 | memset(cm->mi_grid_base, 0, |
| 386 | cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mi_grid_base)); |
| 387 | } |
| 388 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 389 | static int av1_enc_alloc_mi(AV1_COMMON *cm, int mi_size) { |
| 390 | cm->mip = aom_calloc(mi_size, sizeof(*cm->mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 391 | if (!cm->mip) return 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 392 | cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 393 | if (!cm->prev_mip) return 1; |
| 394 | cm->mi_alloc_size = mi_size; |
| 395 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 396 | 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] | 397 | if (!cm->mi_grid_base) return 1; |
| 398 | cm->prev_mi_grid_base = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 399 | (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 400 | if (!cm->prev_mi_grid_base) return 1; |
| 401 | |
| 402 | return 0; |
| 403 | } |
| 404 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 405 | static void av1_enc_free_mi(AV1_COMMON *cm) { |
| 406 | aom_free(cm->mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 407 | cm->mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 408 | aom_free(cm->prev_mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 409 | cm->prev_mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 410 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 411 | cm->mi_grid_base = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 412 | aom_free(cm->prev_mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 413 | cm->prev_mi_grid_base = NULL; |
| 414 | } |
| 415 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 416 | static void av1_swap_mi_and_prev_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 417 | // Current mip will be the prev_mip for the next frame. |
| 418 | MODE_INFO **temp_base = cm->prev_mi_grid_base; |
| 419 | MODE_INFO *temp = cm->prev_mip; |
| 420 | cm->prev_mip = cm->mip; |
| 421 | cm->mip = temp; |
| 422 | |
| 423 | // Update the upper left visible macroblock ptrs. |
| 424 | cm->mi = cm->mip + cm->mi_stride + 1; |
| 425 | cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 426 | |
| 427 | cm->prev_mi_grid_base = cm->mi_grid_base; |
| 428 | cm->mi_grid_base = temp_base; |
| 429 | cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; |
| 430 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; |
| 431 | } |
| 432 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 433 | void av1_initialize_enc(void) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 434 | static volatile int init_done = 0; |
| 435 | |
| 436 | if (!init_done) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 437 | av1_rtcd(); |
| 438 | aom_dsp_rtcd(); |
| 439 | aom_scale_rtcd(); |
| 440 | av1_init_intra_predictors(); |
| 441 | av1_init_me_luts(); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 442 | #if !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 443 | av1_rc_init_minq_luts(); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 444 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 445 | av1_entropy_mv_init(); |
| 446 | av1_encode_token_init(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 447 | #if CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 448 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 449 | #endif |
| 450 | init_done = 1; |
| 451 | } |
| 452 | } |
| 453 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 454 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 455 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 456 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 457 | aom_free(cpi->mbmi_ext_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 458 | cpi->mbmi_ext_base = NULL; |
| 459 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 460 | #if CONFIG_PVQ |
| 461 | if (cpi->oxcf.pass != 1) { |
Yushin Cho | 749c057 | 2017-04-07 10:36:47 -0700 | [diff] [blame] | 462 | const int tile_cols = cm->tile_cols; |
| 463 | const int tile_rows = cm->tile_rows; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 464 | int tile_col, tile_row; |
| 465 | |
| 466 | for (tile_row = 0; tile_row < tile_rows; ++tile_row) |
| 467 | for (tile_col = 0; tile_col < tile_cols; ++tile_col) { |
| 468 | TileDataEnc *tile_data = |
| 469 | &cpi->tile_data[tile_row * tile_cols + tile_col]; |
| 470 | aom_free(tile_data->pvq_q.buf); |
| 471 | } |
| 472 | } |
| 473 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 474 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 475 | cpi->tile_data = NULL; |
| 476 | |
| 477 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 478 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 479 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 480 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 481 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 482 | cpi->cyclic_refresh = NULL; |
| 483 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 484 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 485 | cpi->active_map.map = NULL; |
| 486 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 487 | #if CONFIG_MOTION_VAR |
| 488 | aom_free(cpi->td.mb.above_pred_buf); |
| 489 | cpi->td.mb.above_pred_buf = NULL; |
| 490 | |
| 491 | aom_free(cpi->td.mb.left_pred_buf); |
| 492 | cpi->td.mb.left_pred_buf = NULL; |
| 493 | |
| 494 | aom_free(cpi->td.mb.wsrc_buf); |
| 495 | cpi->td.mb.wsrc_buf = NULL; |
| 496 | |
| 497 | aom_free(cpi->td.mb.mask_buf); |
| 498 | cpi->td.mb.mask_buf = NULL; |
| 499 | #endif |
| 500 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 501 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 502 | #if CONFIG_LV_MAP |
| 503 | av1_free_txb_buf(cpi); |
| 504 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 505 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 506 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 507 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 508 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 509 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 510 | aom_free_frame_buffer(&cpi->last_frame_db); |
| 511 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
| 512 | aom_free(cpi->extra_rstbuf); |
Timothy B. Terriberry | 5d24b6f | 2017-06-15 13:39:35 -0700 | [diff] [blame] | 513 | { |
| 514 | int i; |
| 515 | for (i = 0; i < MAX_MB_PLANE; ++i) |
| 516 | av1_free_restoration_struct(&cpi->rst_search[i]); |
| 517 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 518 | #endif // CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 519 | aom_free_frame_buffer(&cpi->scaled_source); |
| 520 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 521 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 522 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 523 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 524 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 525 | cpi->tile_tok[0][0] = 0; |
| 526 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 527 | av1_free_pc_tree(&cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 528 | |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 529 | aom_free(cpi->td.mb.palette_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 530 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 531 | #if CONFIG_ANS |
Alex Converse | 1ac1ae7 | 2016-09-17 15:11:16 -0700 | [diff] [blame] | 532 | aom_buf_ans_free(&cpi->buf_ans); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 533 | #endif // CONFIG_ANS |
| 534 | } |
| 535 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 536 | static void save_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 537 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 538 | AV1_COMMON *cm = &cpi->common; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 539 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 540 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 541 | // Stores a snapshot of key state variables which can subsequently be |
| 542 | // restored with a call to av1_restore_coding_context. These functions are |
| 543 | // intended for use in a re-code loop in av1_compress_frame where the |
| 544 | // quantizer value is adjusted between loop iterations. |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 545 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 546 | av1_copy(cc->nmv_vec_cost[i], cpi->td.mb.nmv_vec_cost[i]); |
| 547 | av1_copy(cc->nmv_costs, cpi->nmv_costs); |
| 548 | av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp); |
| 549 | } |
| 550 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 551 | av1_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); |
| 552 | av1_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 553 | |
| 554 | cc->fc = *cm->fc; |
| 555 | } |
| 556 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 557 | static void restore_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 558 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 559 | AV1_COMMON *cm = &cpi->common; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 560 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 561 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 562 | // Restore key state variables to the snapshot state stored in the |
| 563 | // previous call to av1_save_coding_context. |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 564 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 565 | av1_copy(cpi->td.mb.nmv_vec_cost[i], cc->nmv_vec_cost[i]); |
| 566 | av1_copy(cpi->nmv_costs, cc->nmv_costs); |
| 567 | av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp); |
| 568 | } |
| 569 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 570 | av1_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); |
| 571 | av1_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 572 | |
| 573 | *cm->fc = cc->fc; |
| 574 | } |
| 575 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 576 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 577 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 578 | const RATE_CONTROL *const rc = &cpi->rc; |
| 579 | struct segmentation *const seg = &cm->seg; |
| 580 | |
| 581 | int high_q = (int)(rc->avg_q > 48.0); |
| 582 | int qi_delta; |
| 583 | |
| 584 | // Disable and clear down for KF |
| 585 | if (cm->frame_type == KEY_FRAME) { |
| 586 | // Clear down the global segmentation map |
| 587 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 588 | seg->update_map = 0; |
| 589 | seg->update_data = 0; |
| 590 | cpi->static_mb_pct = 0; |
| 591 | |
| 592 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 593 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 594 | |
| 595 | // Clear down the segment features. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 596 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 597 | } else if (cpi->refresh_alt_ref_frame) { |
| 598 | // If this is an alt ref frame |
| 599 | // Clear down the global segmentation map |
| 600 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 601 | seg->update_map = 0; |
| 602 | seg->update_data = 0; |
| 603 | cpi->static_mb_pct = 0; |
| 604 | |
| 605 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 606 | av1_disable_segmentation(seg); |
| 607 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 608 | |
| 609 | // Scan frames from current to arf frame. |
| 610 | // This function re-enables segmentation if appropriate. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 611 | av1_update_mbgraph_stats(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 612 | |
| 613 | // If segmentation was enabled set those features needed for the |
| 614 | // arf itself. |
| 615 | if (seg->enabled) { |
| 616 | seg->update_map = 1; |
| 617 | seg->update_data = 1; |
| 618 | |
| 619 | qi_delta = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 620 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, cm->bit_depth); |
| 621 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
| 622 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 623 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 624 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
| 625 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 626 | |
| 627 | // Where relevant assume segment data is delta data |
| 628 | seg->abs_delta = SEGMENT_DELTADATA; |
| 629 | } |
| 630 | } else if (seg->enabled) { |
| 631 | // All other frames if segmentation has been enabled |
| 632 | |
| 633 | // First normal frame in a valid gf or alt ref group |
| 634 | if (rc->frames_since_golden == 0) { |
| 635 | // Set up segment features for normal frames in an arf group |
| 636 | if (rc->source_alt_ref_active) { |
| 637 | seg->update_map = 0; |
| 638 | seg->update_data = 1; |
| 639 | seg->abs_delta = SEGMENT_DELTADATA; |
| 640 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 641 | qi_delta = |
| 642 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, cm->bit_depth); |
| 643 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 644 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 645 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 646 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
| 647 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 648 | |
| 649 | // Segment coding disabled for compred testing |
| 650 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 651 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 652 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 653 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 654 | } |
| 655 | } else { |
| 656 | // Disable segmentation and clear down features if alt ref |
| 657 | // is not active for this group |
| 658 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 659 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 660 | |
| 661 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 662 | |
| 663 | seg->update_map = 0; |
| 664 | seg->update_data = 0; |
| 665 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 666 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 667 | } |
| 668 | } else if (rc->is_src_frame_alt_ref) { |
| 669 | // Special case where we are coding over the top of a previous |
| 670 | // alt ref frame. |
| 671 | // Segment coding disabled for compred testing |
| 672 | |
| 673 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 674 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 675 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 676 | |
| 677 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 678 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 679 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 680 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 681 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 682 | |
| 683 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 684 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 685 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 686 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 687 | } |
| 688 | // Enable data update |
| 689 | seg->update_data = 1; |
| 690 | } else { |
| 691 | // All other frames. |
| 692 | |
| 693 | // No updates.. leave things as they are. |
| 694 | seg->update_map = 0; |
| 695 | seg->update_data = 0; |
| 696 | } |
| 697 | } |
| 698 | } |
| 699 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 700 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 701 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 702 | MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible; |
| 703 | uint8_t *cache_ptr = cm->last_frame_seg_map; |
| 704 | int row, col; |
| 705 | |
| 706 | for (row = 0; row < cm->mi_rows; row++) { |
| 707 | MODE_INFO **mi_8x8 = mi_8x8_ptr; |
| 708 | uint8_t *cache = cache_ptr; |
| 709 | for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) |
| 710 | cache[0] = mi_8x8[0]->mbmi.segment_id; |
| 711 | mi_8x8_ptr += cm->mi_stride; |
| 712 | cache_ptr += cm->mi_cols; |
| 713 | } |
| 714 | } |
| 715 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 716 | static void alloc_raw_frame_buffers(AV1_COMP *cpi) { |
| 717 | AV1_COMMON *cm = &cpi->common; |
| 718 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 719 | |
| 720 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 721 | cpi->lookahead = av1_lookahead_init(oxcf->width, oxcf->height, |
| 722 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 723 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 724 | cm->use_highbitdepth, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 725 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 726 | oxcf->lag_in_frames); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 727 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 728 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 729 | "Failed to allocate lag buffers"); |
| 730 | |
| 731 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 732 | 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] | 733 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 734 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 735 | cm->use_highbitdepth, |
| 736 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 737 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 738 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 739 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 740 | "Failed to allocate altref buffer"); |
| 741 | } |
| 742 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 743 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 744 | AV1_COMMON *const cm = &cpi->common; |
| 745 | 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] | 746 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 747 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 748 | cm->use_highbitdepth, |
| 749 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 750 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 751 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 752 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 753 | "Failed to allocate last frame buffer"); |
| 754 | |
| 755 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 756 | 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] | 757 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 758 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 759 | cm->use_highbitdepth, |
| 760 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 761 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 762 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 763 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 764 | "Failed to allocate last frame deblocked buffer"); |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 765 | if (aom_realloc_frame_buffer( |
| 766 | &cpi->trial_frame_rst, |
| 767 | #if CONFIG_FRAME_SUPERRES |
| 768 | cm->superres_upscaled_width, cm->superres_upscaled_height, |
| 769 | #else |
| 770 | cm->width, cm->height, |
| 771 | #endif // CONFIG_FRAME_SUPERRES |
| 772 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 773 | #if CONFIG_HIGHBITDEPTH |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 774 | cm->use_highbitdepth, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 775 | #endif |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 776 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 777 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 778 | "Failed to allocate trial restored frame buffer"); |
Alex Converse | 232e384 | 2017-02-24 12:24:36 -0800 | [diff] [blame] | 779 | int extra_rstbuf_sz = RESTORATION_EXTBUF_SIZE; |
Debargha Mukherjee | b3c43bc | 2017-02-01 13:09:03 -0800 | [diff] [blame] | 780 | if (extra_rstbuf_sz > 0) { |
Alex Converse | 7f094f1 | 2017-02-23 17:29:40 -0800 | [diff] [blame] | 781 | aom_free(cpi->extra_rstbuf); |
Alex Converse | 232e384 | 2017-02-24 12:24:36 -0800 | [diff] [blame] | 782 | CHECK_MEM_ERROR(cm, cpi->extra_rstbuf, |
Alex Converse | 7f094f1 | 2017-02-23 17:29:40 -0800 | [diff] [blame] | 783 | (uint8_t *)aom_malloc(extra_rstbuf_sz)); |
Debargha Mukherjee | b3c43bc | 2017-02-01 13:09:03 -0800 | [diff] [blame] | 784 | } else { |
| 785 | cpi->extra_rstbuf = NULL; |
| 786 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 787 | #endif // CONFIG_LOOP_RESTORATION |
| 788 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 789 | if (aom_realloc_frame_buffer(&cpi->scaled_source, cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 790 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 791 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 792 | cm->use_highbitdepth, |
| 793 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 794 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 795 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 796 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 797 | "Failed to allocate scaled source buffer"); |
| 798 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 799 | 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] | 800 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 801 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 802 | cm->use_highbitdepth, |
| 803 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 804 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 805 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 806 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 807 | "Failed to allocate scaled last source buffer"); |
| 808 | } |
| 809 | |
Yunqing Wang | f5dc71e | 2017-05-04 18:20:17 -0700 | [diff] [blame] | 810 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 811 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 812 | int mi_size = cm->mi_cols * cm->mi_rows; |
| 813 | |
Yunqing Wang | f5dc71e | 2017-05-04 18:20:17 -0700 | [diff] [blame] | 814 | CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, |
| 815 | aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 818 | void av1_alloc_compressor_data(AV1_COMP *cpi) { |
| 819 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 820 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 821 | av1_alloc_context_buffers(cm, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 822 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 823 | #if CONFIG_LV_MAP |
| 824 | av1_alloc_txb_buf(cpi); |
| 825 | #endif |
| 826 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 827 | alloc_context_buffers_ext(cpi); |
| 828 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 829 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 830 | |
| 831 | { |
| 832 | unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols); |
| 833 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 834 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 837 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 840 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 841 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 842 | #if CONFIG_XIPHRC |
| 843 | if (!cpi->od_rc.cur_frame) return; |
| 844 | cpi->od_rc.framerate = cpi->framerate; |
| 845 | od_enc_rc_resize(&cpi->od_rc); |
| 846 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 847 | av1_rc_update_framerate(cpi); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 848 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 851 | static void set_tile_info(AV1_COMP *cpi) { |
| 852 | AV1_COMMON *const cm = &cpi->common; |
Thomas Davies | b25ba50 | 2017-07-18 10:18:24 +0100 | [diff] [blame] | 853 | #if CONFIG_DEPENDENT_HORZTILES |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 854 | int tile_row, tile_col, num_tiles_in_tg; |
| 855 | int tg_row_start, tg_col_start; |
| 856 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 857 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 858 | if (cpi->oxcf.large_scale_tile) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 859 | #if CONFIG_EXT_PARTITION |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 860 | if (cpi->oxcf.superblock_size != AOM_SUPERBLOCK_SIZE_64X64) { |
| 861 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 32); |
| 862 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 32); |
| 863 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 864 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
| 865 | } else { |
| 866 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 867 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
| 868 | cm->tile_width <<= MAX_MIB_SIZE_LOG2 - 1; |
| 869 | cm->tile_height <<= MAX_MIB_SIZE_LOG2 - 1; |
| 870 | } |
| 871 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 872 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 873 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 874 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 875 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 876 | #endif // CONFIG_EXT_PARTITION |
| 877 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 878 | cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols); |
| 879 | cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 880 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 881 | assert(cm->tile_width >> MAX_MIB_SIZE <= 32); |
| 882 | assert(cm->tile_height >> MAX_MIB_SIZE <= 32); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 883 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 884 | // Get the number of tiles |
| 885 | cm->tile_cols = 1; |
| 886 | 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] | 887 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 888 | cm->tile_rows = 1; |
| 889 | while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows; |
| 890 | } else { |
| 891 | #endif // CONFIG_EXT_TILE |
| 892 | int min_log2_tile_cols, max_log2_tile_cols; |
| 893 | 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] | 894 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 895 | cm->log2_tile_cols = |
| 896 | clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols); |
| 897 | cm->log2_tile_rows = cpi->oxcf.tile_rows; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 898 | |
Rupert Swarbrick | 9a3640d | 2017-09-01 13:54:41 +0100 | [diff] [blame] | 899 | cm->tile_width = get_tile_size(cm->mi_cols, cm->log2_tile_cols); |
| 900 | cm->tile_height = get_tile_size(cm->mi_rows, cm->log2_tile_rows); |
Rupert Swarbrick | 940942b | 2017-09-01 12:05:55 +0100 | [diff] [blame] | 901 | |
| 902 | const int max_cols = (cm->mi_cols + cm->tile_width - 1) / cm->tile_width; |
| 903 | const int max_rows = (cm->mi_rows + cm->tile_height - 1) / cm->tile_height; |
| 904 | |
| 905 | cm->tile_cols = AOMMIN(1 << cm->log2_tile_cols, max_cols); |
| 906 | cm->tile_rows = AOMMIN(1 << cm->log2_tile_rows, max_rows); |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 907 | #if CONFIG_EXT_TILE |
| 908 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 909 | #endif // CONFIG_EXT_TILE |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 910 | |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 911 | #if CONFIG_DEPENDENT_HORZTILES |
| 912 | cm->dependent_horz_tiles = cpi->oxcf.dependent_horz_tiles; |
Fangwen Fu | 70bcb89 | 2017-05-06 17:05:19 -0700 | [diff] [blame] | 913 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 914 | if (cm->large_scale_tile) { |
| 915 | // May not needed since cpi->oxcf.dependent_horz_tiles is already adjusted. |
| 916 | cm->dependent_horz_tiles = 0; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 917 | } else { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 918 | #endif // CONFIG_EXT_TILE |
| 919 | if (cm->log2_tile_rows == 0) cm->dependent_horz_tiles = 0; |
| 920 | #if CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 921 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 922 | #endif // CONFIG_EXT_TILE |
| 923 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 924 | #if CONFIG_EXT_TILE |
| 925 | if (!cm->large_scale_tile) { |
| 926 | #endif // CONFIG_EXT_TILE |
| 927 | if (cpi->oxcf.mtu == 0) { |
| 928 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 929 | } else { |
| 930 | // Use a default value for the purposes of weighting costs in probability |
| 931 | // updates |
| 932 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 933 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 934 | num_tiles_in_tg = |
| 935 | (cm->tile_cols * cm->tile_rows + cm->num_tg - 1) / cm->num_tg; |
| 936 | tg_row_start = 0; |
| 937 | tg_col_start = 0; |
| 938 | for (tile_row = 0; tile_row < cm->tile_rows; ++tile_row) { |
| 939 | for (tile_col = 0; tile_col < cm->tile_cols; ++tile_col) { |
| 940 | if ((tile_row * cm->tile_cols + tile_col) % num_tiles_in_tg == 0) { |
| 941 | tg_row_start = tile_row; |
| 942 | tg_col_start = tile_col; |
| 943 | } |
| 944 | cm->tile_group_start_row[tile_row][tile_col] = tg_row_start; |
| 945 | cm->tile_group_start_col[tile_row][tile_col] = tg_col_start; |
| 946 | } |
| 947 | } |
| 948 | #if CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 949 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 950 | #endif // CONFIG_EXT_TILE |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 951 | #endif |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 952 | |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 953 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 954 | cm->loop_filter_across_tiles_enabled = |
| 955 | cpi->oxcf.loop_filter_across_tiles_enabled; |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 956 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 959 | static void update_frame_size(AV1_COMP *cpi) { |
| 960 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 961 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 962 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 963 | av1_set_mb_mi(cm, cm->width, cm->height); |
| 964 | av1_init_context_buffers(cm); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 965 | av1_init_macroblockd(cm, xd, |
| 966 | #if CONFIG_PVQ |
| 967 | NULL, |
| 968 | #endif |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 969 | #if CONFIG_CFL |
| 970 | &NULL_CFL, |
| 971 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 972 | NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 973 | memset(cpi->mbmi_ext_base, 0, |
| 974 | cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
| 975 | |
| 976 | set_tile_info(cpi); |
| 977 | } |
| 978 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 979 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 980 | #if CONFIG_EXT_REFS |
| 981 | int fb_idx; |
| 982 | for (fb_idx = 0; fb_idx < LAST_REF_FRAMES; ++fb_idx) |
| 983 | cpi->lst_fb_idxes[fb_idx] = fb_idx; |
| 984 | cpi->gld_fb_idx = LAST_REF_FRAMES; |
| 985 | cpi->bwd_fb_idx = LAST_REF_FRAMES + 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 986 | cpi->alt2_fb_idx = LAST_REF_FRAMES + 2; |
| 987 | cpi->alt_fb_idx = LAST_REF_FRAMES + 3; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 988 | for (fb_idx = 0; fb_idx < MAX_EXT_ARFS + 1; ++fb_idx) |
| 989 | cpi->arf_map[fb_idx] = LAST_REF_FRAMES + 2 + fb_idx; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 990 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 991 | cpi->lst_fb_idx = 0; |
| 992 | cpi->gld_fb_idx = 1; |
| 993 | cpi->alt_fb_idx = 2; |
| 994 | #endif // CONFIG_EXT_REFS |
| 995 | } |
| 996 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 997 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 998 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 999 | |
| 1000 | cpi->oxcf = *oxcf; |
| 1001 | cpi->framerate = oxcf->init_framerate; |
| 1002 | |
| 1003 | cm->profile = oxcf->profile; |
| 1004 | cm->bit_depth = oxcf->bit_depth; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1005 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1006 | cm->use_highbitdepth = oxcf->use_highbitdepth; |
| 1007 | #endif |
| 1008 | cm->color_space = oxcf->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 1009 | #if CONFIG_COLORSPACE_HEADERS |
| 1010 | cm->transfer_function = oxcf->transfer_function; |
| 1011 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
| 1012 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1013 | cm->color_range = oxcf->color_range; |
| 1014 | |
| 1015 | cm->width = oxcf->width; |
| 1016 | cm->height = oxcf->height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1017 | av1_alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1018 | |
| 1019 | // Single thread case: use counts in common. |
| 1020 | cpi->td.counts = &cm->counts; |
| 1021 | |
| 1022 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1023 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1024 | |
| 1025 | cpi->static_mb_pct = 0; |
| 1026 | cpi->ref_frame_flags = 0; |
| 1027 | |
| 1028 | init_buffer_indices(cpi); |
| 1029 | } |
| 1030 | |
| 1031 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1032 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1033 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 1034 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 1035 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 1036 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 1037 | |
| 1038 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 1039 | rc->optimal_buffer_level = |
| 1040 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1041 | rc->maximum_buffer_size = |
| 1042 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1043 | } |
| 1044 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1045 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1046 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 1047 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1048 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1049 | cpi->fn_ptr[BT].vf = VF; \ |
| 1050 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1051 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1052 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 1053 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 1054 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
| 1055 | |
| 1056 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1057 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1058 | int source_stride, \ |
| 1059 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1060 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1061 | } \ |
| 1062 | static unsigned int fnname##_bits10( \ |
| 1063 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1064 | int ref_stride) { \ |
| 1065 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1066 | } \ |
| 1067 | static unsigned int fnname##_bits12( \ |
| 1068 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1069 | int ref_stride) { \ |
| 1070 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1071 | } |
| 1072 | |
| 1073 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1074 | static unsigned int fnname##_bits8( \ |
| 1075 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1076 | int ref_stride, const uint8_t *second_pred) { \ |
| 1077 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1078 | } \ |
| 1079 | static unsigned int fnname##_bits10( \ |
| 1080 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1081 | int ref_stride, const uint8_t *second_pred) { \ |
| 1082 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1083 | 2; \ |
| 1084 | } \ |
| 1085 | static unsigned int fnname##_bits12( \ |
| 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 | 4; \ |
| 1090 | } |
| 1091 | |
| 1092 | #define MAKE_BFP_SAD3_WRAPPER(fnname) \ |
| 1093 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1094 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1095 | unsigned int *sad_array) { \ |
| 1096 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1097 | } \ |
| 1098 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1099 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1100 | unsigned int *sad_array) { \ |
| 1101 | int i; \ |
| 1102 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1103 | for (i = 0; i < 3; i++) sad_array[i] >>= 2; \ |
| 1104 | } \ |
| 1105 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1106 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1107 | unsigned int *sad_array) { \ |
| 1108 | int i; \ |
| 1109 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1110 | for (i = 0; i < 3; i++) sad_array[i] >>= 4; \ |
| 1111 | } |
| 1112 | |
| 1113 | #define MAKE_BFP_SAD8_WRAPPER(fnname) \ |
| 1114 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1115 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1116 | unsigned int *sad_array) { \ |
| 1117 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1118 | } \ |
| 1119 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1120 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1121 | unsigned int *sad_array) { \ |
| 1122 | int i; \ |
| 1123 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1124 | for (i = 0; i < 8; i++) sad_array[i] >>= 2; \ |
| 1125 | } \ |
| 1126 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1127 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1128 | unsigned int *sad_array) { \ |
| 1129 | int i; \ |
| 1130 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1131 | for (i = 0; i < 8; i++) sad_array[i] >>= 4; \ |
| 1132 | } |
| 1133 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1134 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1135 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1136 | unsigned int *sad_array) { \ |
| 1137 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1138 | } \ |
| 1139 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1140 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1141 | unsigned int *sad_array) { \ |
| 1142 | int i; \ |
| 1143 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1144 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1145 | } \ |
| 1146 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1147 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1148 | unsigned int *sad_array) { \ |
| 1149 | int i; \ |
| 1150 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1151 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1152 | } |
| 1153 | |
| 1154 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1155 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1156 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
| 1157 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad128x128x3) |
| 1158 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad128x128x8) |
| 1159 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1160 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1161 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1162 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1163 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1164 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1165 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1166 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1167 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1168 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1169 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1170 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1171 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1172 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1173 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1174 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1175 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1176 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1177 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1178 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1179 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1180 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
| 1181 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad32x32x3) |
| 1182 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad32x32x8) |
| 1183 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1184 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1185 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
| 1186 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad64x64x3) |
| 1187 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad64x64x8) |
| 1188 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1189 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1190 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
| 1191 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x16x3) |
| 1192 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x16x8) |
| 1193 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1194 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1195 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
| 1196 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x8x3) |
| 1197 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x8x8) |
| 1198 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1199 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1200 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
| 1201 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x16x3) |
| 1202 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x16x8) |
| 1203 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1204 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1205 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
| 1206 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x8x3) |
| 1207 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x8x8) |
| 1208 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1209 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1210 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
| 1211 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x4x8) |
| 1212 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1213 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1214 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
| 1215 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x8x8) |
| 1216 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1217 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1218 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
| 1219 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad4x4x3) |
| 1220 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x4x8) |
| 1221 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1222 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1223 | #if CONFIG_EXT_PARTITION_TYPES |
| 1224 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16) |
| 1225 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg) |
| 1226 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d) |
| 1227 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4) |
| 1228 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg) |
| 1229 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d) |
| 1230 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32) |
| 1231 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg) |
| 1232 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d) |
| 1233 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8) |
| 1234 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg) |
| 1235 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1236 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64) |
| 1237 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg) |
| 1238 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d) |
| 1239 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16) |
| 1240 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg) |
| 1241 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1242 | #endif |
| 1243 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1244 | #if CONFIG_EXT_INTER |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1245 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1246 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1247 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1248 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1249 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1250 | static unsigned int fnname##_bits8( \ |
| 1251 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1252 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1253 | int m_stride, int invert_mask) { \ |
| 1254 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1255 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1256 | } \ |
| 1257 | static unsigned int fnname##_bits10( \ |
| 1258 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1259 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1260 | int m_stride, int invert_mask) { \ |
| 1261 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1262 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1263 | 2; \ |
| 1264 | } \ |
| 1265 | static unsigned int fnname##_bits12( \ |
| 1266 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1267 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1268 | int m_stride, int invert_mask) { \ |
| 1269 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1270 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1271 | 4; \ |
| 1272 | } |
| 1273 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1274 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1275 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1276 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1277 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1278 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1279 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1280 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1281 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1282 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1283 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1284 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1285 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1286 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1287 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1288 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1289 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1290 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1291 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1292 | |
| 1293 | #if CONFIG_EXT_PARTITION_TYPES |
| 1294 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16) |
| 1295 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4) |
| 1296 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32) |
| 1297 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1298 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64) |
| 1299 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1300 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1301 | #endif // CONFIG_EXT_INTER |
| 1302 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1303 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1304 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1305 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1306 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1307 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1308 | |
| 1309 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1310 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1311 | const int32_t *wsrc, \ |
| 1312 | const int32_t *msk) { \ |
| 1313 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1314 | } \ |
| 1315 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1316 | const int32_t *wsrc, \ |
| 1317 | const int32_t *msk) { \ |
| 1318 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1319 | } \ |
| 1320 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1321 | const int32_t *wsrc, \ |
| 1322 | const int32_t *msk) { \ |
| 1323 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1324 | } |
| 1325 | |
| 1326 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1327 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1328 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1329 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1330 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1331 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1332 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1333 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1334 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1335 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1336 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1337 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1338 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1339 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1340 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1341 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1342 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1343 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1344 | |
| 1345 | #if CONFIG_EXT_PARTITION_TYPES |
| 1346 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16) |
| 1347 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4) |
| 1348 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32) |
| 1349 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1350 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64) |
| 1351 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1352 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1353 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1354 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1355 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1356 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1357 | if (cm->use_highbitdepth) { |
| 1358 | switch (cm->bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1359 | case AOM_BITS_8: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1360 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1361 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits8, |
| 1362 | aom_highbd_sad64x16_avg_bits8, aom_highbd_8_variance64x16, |
| 1363 | aom_highbd_8_sub_pixel_variance64x16, |
| 1364 | aom_highbd_8_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1365 | aom_highbd_sad64x16x4d_bits8) |
| 1366 | |
| 1367 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits8, |
| 1368 | aom_highbd_sad16x64_avg_bits8, aom_highbd_8_variance16x64, |
| 1369 | aom_highbd_8_sub_pixel_variance16x64, |
| 1370 | aom_highbd_8_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1371 | aom_highbd_sad16x64x4d_bits8) |
| 1372 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1373 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits8, |
| 1374 | aom_highbd_sad32x8_avg_bits8, aom_highbd_8_variance32x8, |
| 1375 | aom_highbd_8_sub_pixel_variance32x8, |
| 1376 | aom_highbd_8_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1377 | aom_highbd_sad32x8x4d_bits8) |
| 1378 | |
| 1379 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits8, |
| 1380 | aom_highbd_sad8x32_avg_bits8, aom_highbd_8_variance8x32, |
| 1381 | aom_highbd_8_sub_pixel_variance8x32, |
| 1382 | aom_highbd_8_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1383 | aom_highbd_sad8x32x4d_bits8) |
| 1384 | |
| 1385 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits8, |
| 1386 | aom_highbd_sad16x4_avg_bits8, aom_highbd_8_variance16x4, |
| 1387 | aom_highbd_8_sub_pixel_variance16x4, |
| 1388 | aom_highbd_8_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1389 | aom_highbd_sad16x4x4d_bits8) |
| 1390 | |
| 1391 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits8, |
| 1392 | aom_highbd_sad4x16_avg_bits8, aom_highbd_8_variance4x16, |
| 1393 | aom_highbd_8_sub_pixel_variance4x16, |
| 1394 | aom_highbd_8_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1395 | aom_highbd_sad4x16x4d_bits8) |
| 1396 | #endif |
| 1397 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1398 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1399 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1400 | aom_highbd_8_sub_pixel_variance32x16, |
| 1401 | aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1402 | aom_highbd_sad32x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1403 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1404 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1405 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1406 | aom_highbd_8_sub_pixel_variance16x32, |
| 1407 | aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1408 | aom_highbd_sad16x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1409 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1410 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1411 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1412 | aom_highbd_8_sub_pixel_variance64x32, |
| 1413 | aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1414 | aom_highbd_sad64x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1415 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1416 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1417 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1418 | aom_highbd_8_sub_pixel_variance32x64, |
| 1419 | aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1420 | aom_highbd_sad32x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1421 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1422 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1423 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1424 | aom_highbd_8_sub_pixel_variance32x32, |
| 1425 | aom_highbd_8_sub_pixel_avg_variance32x32, |
| 1426 | aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8, |
| 1427 | aom_highbd_sad32x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1428 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1429 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1430 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1431 | aom_highbd_8_sub_pixel_variance64x64, |
| 1432 | aom_highbd_8_sub_pixel_avg_variance64x64, |
| 1433 | aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8, |
| 1434 | aom_highbd_sad64x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1435 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1436 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1437 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1438 | aom_highbd_8_sub_pixel_variance16x16, |
| 1439 | aom_highbd_8_sub_pixel_avg_variance16x16, |
| 1440 | aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8, |
| 1441 | aom_highbd_sad16x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1442 | |
| 1443 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1444 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1445 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
| 1446 | aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8, |
| 1447 | aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1448 | |
| 1449 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1450 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1451 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
| 1452 | aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8, |
| 1453 | aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1454 | |
| 1455 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1456 | BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8, |
| 1457 | aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8, |
| 1458 | aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits8, |
| 1459 | aom_highbd_sad8x8x8_bits8, aom_highbd_sad8x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1460 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1461 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8, |
| 1462 | aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4, |
| 1463 | aom_highbd_8_sub_pixel_variance8x4, |
| 1464 | aom_highbd_8_sub_pixel_avg_variance8x4, NULL, |
| 1465 | aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1466 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1467 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8, |
| 1468 | aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8, |
| 1469 | aom_highbd_8_sub_pixel_variance4x8, |
| 1470 | aom_highbd_8_sub_pixel_avg_variance4x8, NULL, |
| 1471 | aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1472 | |
| 1473 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1474 | BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8, |
| 1475 | aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4, |
| 1476 | aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits8, |
| 1477 | aom_highbd_sad4x4x8_bits8, aom_highbd_sad4x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1478 | |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 1479 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1480 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_8_variance2x2, NULL, NULL, |
| 1481 | NULL, NULL, NULL) |
| 1482 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_8_variance4x2, NULL, NULL, |
| 1483 | NULL, NULL, NULL) |
| 1484 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_8_variance2x4, NULL, NULL, |
| 1485 | NULL, NULL, NULL) |
| 1486 | #endif |
| 1487 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1488 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1489 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1490 | aom_highbd_sad128x128_avg_bits8, |
| 1491 | aom_highbd_8_variance128x128, |
| 1492 | aom_highbd_8_sub_pixel_variance128x128, |
| 1493 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1494 | aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8, |
| 1495 | aom_highbd_sad128x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1496 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1497 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1498 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1499 | aom_highbd_8_sub_pixel_variance128x64, |
| 1500 | aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1501 | aom_highbd_sad128x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1502 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1503 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1504 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1505 | aom_highbd_8_sub_pixel_variance64x128, |
| 1506 | aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1507 | aom_highbd_sad64x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1508 | #endif // CONFIG_EXT_PARTITION |
| 1509 | |
| 1510 | #if CONFIG_EXT_INTER |
| 1511 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1512 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1513 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1514 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1515 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1516 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1517 | aom_highbd_8_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1518 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1519 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1520 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1521 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1522 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1523 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1524 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1525 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1526 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1527 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1528 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1529 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1530 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1531 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1532 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1533 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1534 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1535 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1536 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1537 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1538 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1539 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1540 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1541 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1542 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1543 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1544 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1545 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1546 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits8, |
| 1547 | aom_highbd_8_masked_sub_pixel_variance64x16) |
| 1548 | |
| 1549 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits8, |
| 1550 | aom_highbd_8_masked_sub_pixel_variance16x64) |
| 1551 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1552 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits8, |
| 1553 | aom_highbd_8_masked_sub_pixel_variance32x8) |
| 1554 | |
| 1555 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits8, |
| 1556 | aom_highbd_8_masked_sub_pixel_variance8x32) |
| 1557 | |
| 1558 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits8, |
| 1559 | aom_highbd_8_masked_sub_pixel_variance16x4) |
| 1560 | |
| 1561 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits8, |
| 1562 | aom_highbd_8_masked_sub_pixel_variance4x16) |
| 1563 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1564 | #endif // CONFIG_EXT_INTER |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1565 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1566 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1567 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1568 | aom_highbd_obmc_variance128x128, |
| 1569 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1570 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1571 | aom_highbd_obmc_variance128x64, |
| 1572 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1573 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1574 | aom_highbd_obmc_variance64x128, |
| 1575 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1576 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1577 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1578 | aom_highbd_obmc_variance64x64, |
| 1579 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1580 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1581 | aom_highbd_obmc_variance64x32, |
| 1582 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1583 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1584 | aom_highbd_obmc_variance32x64, |
| 1585 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1586 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1587 | aom_highbd_obmc_variance32x32, |
| 1588 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1589 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1590 | aom_highbd_obmc_variance32x16, |
| 1591 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1592 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1593 | aom_highbd_obmc_variance16x32, |
| 1594 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1595 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1596 | aom_highbd_obmc_variance16x16, |
| 1597 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1598 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1599 | aom_highbd_obmc_variance8x16, |
| 1600 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1601 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1602 | aom_highbd_obmc_variance16x8, |
| 1603 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1604 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1605 | aom_highbd_obmc_variance8x8, |
| 1606 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 1607 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 1608 | aom_highbd_obmc_variance4x8, |
| 1609 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 1610 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 1611 | aom_highbd_obmc_variance8x4, |
| 1612 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 1613 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 1614 | aom_highbd_obmc_variance4x4, |
| 1615 | aom_highbd_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1616 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1617 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits8, |
| 1618 | aom_highbd_obmc_variance64x16, |
| 1619 | aom_highbd_obmc_sub_pixel_variance64x16) |
| 1620 | |
| 1621 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits8, |
| 1622 | aom_highbd_obmc_variance16x64, |
| 1623 | aom_highbd_obmc_sub_pixel_variance16x64) |
| 1624 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1625 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits8, |
| 1626 | aom_highbd_obmc_variance32x8, |
| 1627 | aom_highbd_obmc_sub_pixel_variance32x8) |
| 1628 | |
| 1629 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits8, |
| 1630 | aom_highbd_obmc_variance8x32, |
| 1631 | aom_highbd_obmc_sub_pixel_variance8x32) |
| 1632 | |
| 1633 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits8, |
| 1634 | aom_highbd_obmc_variance16x4, |
| 1635 | aom_highbd_obmc_sub_pixel_variance16x4) |
| 1636 | |
| 1637 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits8, |
| 1638 | aom_highbd_obmc_variance4x16, |
| 1639 | aom_highbd_obmc_sub_pixel_variance4x16) |
| 1640 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1641 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1642 | break; |
| 1643 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1644 | case AOM_BITS_10: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1645 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1646 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits10, |
| 1647 | aom_highbd_sad64x16_avg_bits10, aom_highbd_10_variance64x16, |
| 1648 | aom_highbd_10_sub_pixel_variance64x16, |
| 1649 | aom_highbd_10_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1650 | aom_highbd_sad64x16x4d_bits10) |
| 1651 | |
| 1652 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits10, |
| 1653 | aom_highbd_sad16x64_avg_bits10, aom_highbd_10_variance16x64, |
| 1654 | aom_highbd_10_sub_pixel_variance16x64, |
| 1655 | aom_highbd_10_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1656 | aom_highbd_sad16x64x4d_bits10) |
| 1657 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1658 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits10, |
| 1659 | aom_highbd_sad32x8_avg_bits10, aom_highbd_10_variance32x8, |
| 1660 | aom_highbd_10_sub_pixel_variance32x8, |
| 1661 | aom_highbd_10_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1662 | aom_highbd_sad32x8x4d_bits10) |
| 1663 | |
| 1664 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits10, |
| 1665 | aom_highbd_sad8x32_avg_bits10, aom_highbd_10_variance8x32, |
| 1666 | aom_highbd_10_sub_pixel_variance8x32, |
| 1667 | aom_highbd_10_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1668 | aom_highbd_sad8x32x4d_bits10) |
| 1669 | |
| 1670 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits10, |
| 1671 | aom_highbd_sad16x4_avg_bits10, aom_highbd_10_variance16x4, |
| 1672 | aom_highbd_10_sub_pixel_variance16x4, |
| 1673 | aom_highbd_10_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1674 | aom_highbd_sad16x4x4d_bits10) |
| 1675 | |
| 1676 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits10, |
| 1677 | aom_highbd_sad4x16_avg_bits10, aom_highbd_10_variance4x16, |
| 1678 | aom_highbd_10_sub_pixel_variance4x16, |
| 1679 | aom_highbd_10_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1680 | aom_highbd_sad4x16x4d_bits10) |
| 1681 | #endif |
| 1682 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1683 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 1684 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 1685 | aom_highbd_10_sub_pixel_variance32x16, |
| 1686 | aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1687 | aom_highbd_sad32x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1688 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1689 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 1690 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 1691 | aom_highbd_10_sub_pixel_variance16x32, |
| 1692 | aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1693 | aom_highbd_sad16x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1694 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1695 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 1696 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 1697 | aom_highbd_10_sub_pixel_variance64x32, |
| 1698 | aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1699 | aom_highbd_sad64x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1700 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1701 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 1702 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 1703 | aom_highbd_10_sub_pixel_variance32x64, |
| 1704 | aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1705 | aom_highbd_sad32x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1706 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1707 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 1708 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 1709 | aom_highbd_10_sub_pixel_variance32x32, |
| 1710 | aom_highbd_10_sub_pixel_avg_variance32x32, |
| 1711 | aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10, |
| 1712 | aom_highbd_sad32x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1713 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1714 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 1715 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 1716 | aom_highbd_10_sub_pixel_variance64x64, |
| 1717 | aom_highbd_10_sub_pixel_avg_variance64x64, |
| 1718 | aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10, |
| 1719 | aom_highbd_sad64x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1720 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1721 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 1722 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 1723 | aom_highbd_10_sub_pixel_variance16x16, |
| 1724 | aom_highbd_10_sub_pixel_avg_variance16x16, |
| 1725 | aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10, |
| 1726 | aom_highbd_sad16x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1727 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1728 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 1729 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 1730 | aom_highbd_10_sub_pixel_variance16x8, |
| 1731 | aom_highbd_10_sub_pixel_avg_variance16x8, |
| 1732 | aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10, |
| 1733 | aom_highbd_sad16x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1734 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1735 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 1736 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 1737 | aom_highbd_10_sub_pixel_variance8x16, |
| 1738 | aom_highbd_10_sub_pixel_avg_variance8x16, |
| 1739 | aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10, |
| 1740 | aom_highbd_sad8x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1741 | |
| 1742 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1743 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 1744 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
| 1745 | aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10, |
| 1746 | aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1747 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1748 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10, |
| 1749 | aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4, |
| 1750 | aom_highbd_10_sub_pixel_variance8x4, |
| 1751 | aom_highbd_10_sub_pixel_avg_variance8x4, NULL, |
| 1752 | aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1753 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1754 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10, |
| 1755 | aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8, |
| 1756 | aom_highbd_10_sub_pixel_variance4x8, |
| 1757 | aom_highbd_10_sub_pixel_avg_variance4x8, NULL, |
| 1758 | aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1759 | |
| 1760 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1761 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 1762 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
| 1763 | aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10, |
| 1764 | aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1765 | |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 1766 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1767 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_10_variance2x2, NULL, NULL, |
| 1768 | NULL, NULL, NULL) |
| 1769 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_10_variance4x2, NULL, NULL, |
| 1770 | NULL, NULL, NULL) |
| 1771 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_10_variance2x4, NULL, NULL, |
| 1772 | NULL, NULL, NULL) |
| 1773 | #endif |
| 1774 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1775 | #if CONFIG_EXT_PARTITION |
| 1776 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1777 | BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 1778 | aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128, |
| 1779 | aom_highbd_10_sub_pixel_variance128x128, |
| 1780 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 1781 | aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10, |
| 1782 | aom_highbd_sad128x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1783 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1784 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 1785 | aom_highbd_sad128x64_avg_bits10, |
| 1786 | aom_highbd_10_variance128x64, |
| 1787 | aom_highbd_10_sub_pixel_variance128x64, |
| 1788 | aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1789 | aom_highbd_sad128x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1790 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1791 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 1792 | aom_highbd_sad64x128_avg_bits10, |
| 1793 | aom_highbd_10_variance64x128, |
| 1794 | aom_highbd_10_sub_pixel_variance64x128, |
| 1795 | aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1796 | aom_highbd_sad64x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1797 | #endif // CONFIG_EXT_PARTITION |
| 1798 | |
| 1799 | #if CONFIG_EXT_INTER |
| 1800 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1801 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 1802 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 1803 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 1804 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 1805 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 1806 | aom_highbd_10_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1807 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1808 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 1809 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 1810 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 1811 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 1812 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 1813 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 1814 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 1815 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 1816 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 1817 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 1818 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 1819 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 1820 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 1821 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 1822 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 1823 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 1824 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 1825 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 1826 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 1827 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 1828 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 1829 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 1830 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 1831 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 1832 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 1833 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1834 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1835 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits10, |
| 1836 | aom_highbd_10_masked_sub_pixel_variance64x16) |
| 1837 | |
| 1838 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits10, |
| 1839 | aom_highbd_10_masked_sub_pixel_variance16x64) |
| 1840 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1841 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits10, |
| 1842 | aom_highbd_10_masked_sub_pixel_variance32x8) |
| 1843 | |
| 1844 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits10, |
| 1845 | aom_highbd_10_masked_sub_pixel_variance8x32) |
| 1846 | |
| 1847 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits10, |
| 1848 | aom_highbd_10_masked_sub_pixel_variance16x4) |
| 1849 | |
| 1850 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits10, |
| 1851 | aom_highbd_10_masked_sub_pixel_variance4x16) |
| 1852 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1853 | #endif // CONFIG_EXT_INTER |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1854 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1855 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1856 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 1857 | aom_highbd_10_obmc_variance128x128, |
| 1858 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 1859 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 1860 | aom_highbd_10_obmc_variance128x64, |
| 1861 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 1862 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 1863 | aom_highbd_10_obmc_variance64x128, |
| 1864 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1865 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1866 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 1867 | aom_highbd_10_obmc_variance64x64, |
| 1868 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 1869 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 1870 | aom_highbd_10_obmc_variance64x32, |
| 1871 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 1872 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 1873 | aom_highbd_10_obmc_variance32x64, |
| 1874 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 1875 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 1876 | aom_highbd_10_obmc_variance32x32, |
| 1877 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 1878 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 1879 | aom_highbd_10_obmc_variance32x16, |
| 1880 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 1881 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 1882 | aom_highbd_10_obmc_variance16x32, |
| 1883 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 1884 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 1885 | aom_highbd_10_obmc_variance16x16, |
| 1886 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 1887 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 1888 | aom_highbd_10_obmc_variance8x16, |
| 1889 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 1890 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 1891 | aom_highbd_10_obmc_variance16x8, |
| 1892 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 1893 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 1894 | aom_highbd_10_obmc_variance8x8, |
| 1895 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 1896 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 1897 | aom_highbd_10_obmc_variance4x8, |
| 1898 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 1899 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 1900 | aom_highbd_10_obmc_variance8x4, |
| 1901 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 1902 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 1903 | aom_highbd_10_obmc_variance4x4, |
| 1904 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1905 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1906 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits10, |
| 1907 | aom_highbd_10_obmc_variance64x16, |
| 1908 | aom_highbd_10_obmc_sub_pixel_variance64x16) |
| 1909 | |
| 1910 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits10, |
| 1911 | aom_highbd_10_obmc_variance16x64, |
| 1912 | aom_highbd_10_obmc_sub_pixel_variance16x64) |
| 1913 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1914 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits10, |
| 1915 | aom_highbd_10_obmc_variance32x8, |
| 1916 | aom_highbd_10_obmc_sub_pixel_variance32x8) |
| 1917 | |
| 1918 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits10, |
| 1919 | aom_highbd_10_obmc_variance8x32, |
| 1920 | aom_highbd_10_obmc_sub_pixel_variance8x32) |
| 1921 | |
| 1922 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits10, |
| 1923 | aom_highbd_10_obmc_variance16x4, |
| 1924 | aom_highbd_10_obmc_sub_pixel_variance16x4) |
| 1925 | |
| 1926 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits10, |
| 1927 | aom_highbd_10_obmc_variance4x16, |
| 1928 | aom_highbd_10_obmc_sub_pixel_variance4x16) |
| 1929 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1930 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1931 | break; |
| 1932 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1933 | case AOM_BITS_12: |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1934 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1935 | HIGHBD_BFP(BLOCK_64X16, aom_highbd_sad64x16_bits12, |
| 1936 | aom_highbd_sad64x16_avg_bits12, aom_highbd_12_variance64x16, |
| 1937 | aom_highbd_12_sub_pixel_variance64x16, |
| 1938 | aom_highbd_12_sub_pixel_avg_variance64x16, NULL, NULL, |
| 1939 | aom_highbd_sad64x16x4d_bits12) |
| 1940 | |
| 1941 | HIGHBD_BFP(BLOCK_16X64, aom_highbd_sad16x64_bits12, |
| 1942 | aom_highbd_sad16x64_avg_bits12, aom_highbd_12_variance16x64, |
| 1943 | aom_highbd_12_sub_pixel_variance16x64, |
| 1944 | aom_highbd_12_sub_pixel_avg_variance16x64, NULL, NULL, |
| 1945 | aom_highbd_sad16x64x4d_bits12) |
| 1946 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1947 | HIGHBD_BFP(BLOCK_32X8, aom_highbd_sad32x8_bits12, |
| 1948 | aom_highbd_sad32x8_avg_bits12, aom_highbd_12_variance32x8, |
| 1949 | aom_highbd_12_sub_pixel_variance32x8, |
| 1950 | aom_highbd_12_sub_pixel_avg_variance32x8, NULL, NULL, |
| 1951 | aom_highbd_sad32x8x4d_bits12) |
| 1952 | |
| 1953 | HIGHBD_BFP(BLOCK_8X32, aom_highbd_sad8x32_bits12, |
| 1954 | aom_highbd_sad8x32_avg_bits12, aom_highbd_12_variance8x32, |
| 1955 | aom_highbd_12_sub_pixel_variance8x32, |
| 1956 | aom_highbd_12_sub_pixel_avg_variance8x32, NULL, NULL, |
| 1957 | aom_highbd_sad8x32x4d_bits12) |
| 1958 | |
| 1959 | HIGHBD_BFP(BLOCK_16X4, aom_highbd_sad16x4_bits12, |
| 1960 | aom_highbd_sad16x4_avg_bits12, aom_highbd_12_variance16x4, |
| 1961 | aom_highbd_12_sub_pixel_variance16x4, |
| 1962 | aom_highbd_12_sub_pixel_avg_variance16x4, NULL, NULL, |
| 1963 | aom_highbd_sad16x4x4d_bits12) |
| 1964 | |
| 1965 | HIGHBD_BFP(BLOCK_4X16, aom_highbd_sad4x16_bits12, |
| 1966 | aom_highbd_sad4x16_avg_bits12, aom_highbd_12_variance4x16, |
| 1967 | aom_highbd_12_sub_pixel_variance4x16, |
| 1968 | aom_highbd_12_sub_pixel_avg_variance4x16, NULL, NULL, |
| 1969 | aom_highbd_sad4x16x4d_bits12) |
| 1970 | #endif |
| 1971 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1972 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 1973 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 1974 | aom_highbd_12_sub_pixel_variance32x16, |
| 1975 | aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1976 | aom_highbd_sad32x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1977 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1978 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 1979 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 1980 | aom_highbd_12_sub_pixel_variance16x32, |
| 1981 | aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1982 | aom_highbd_sad16x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1983 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1984 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 1985 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 1986 | aom_highbd_12_sub_pixel_variance64x32, |
| 1987 | aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1988 | aom_highbd_sad64x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1989 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1990 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 1991 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 1992 | aom_highbd_12_sub_pixel_variance32x64, |
| 1993 | aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1994 | aom_highbd_sad32x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1995 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1996 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 1997 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 1998 | aom_highbd_12_sub_pixel_variance32x32, |
| 1999 | aom_highbd_12_sub_pixel_avg_variance32x32, |
| 2000 | aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12, |
| 2001 | aom_highbd_sad32x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2002 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2003 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 2004 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 2005 | aom_highbd_12_sub_pixel_variance64x64, |
| 2006 | aom_highbd_12_sub_pixel_avg_variance64x64, |
| 2007 | aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12, |
| 2008 | aom_highbd_sad64x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2009 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2010 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 2011 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 2012 | aom_highbd_12_sub_pixel_variance16x16, |
| 2013 | aom_highbd_12_sub_pixel_avg_variance16x16, |
| 2014 | aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12, |
| 2015 | aom_highbd_sad16x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2016 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2017 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 2018 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 2019 | aom_highbd_12_sub_pixel_variance16x8, |
| 2020 | aom_highbd_12_sub_pixel_avg_variance16x8, |
| 2021 | aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12, |
| 2022 | aom_highbd_sad16x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2023 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2024 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 2025 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 2026 | aom_highbd_12_sub_pixel_variance8x16, |
| 2027 | aom_highbd_12_sub_pixel_avg_variance8x16, |
| 2028 | aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12, |
| 2029 | aom_highbd_sad8x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2030 | |
| 2031 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2032 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 2033 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
| 2034 | aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12, |
| 2035 | aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2036 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2037 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12, |
| 2038 | aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4, |
| 2039 | aom_highbd_12_sub_pixel_variance8x4, |
| 2040 | aom_highbd_12_sub_pixel_avg_variance8x4, NULL, |
| 2041 | aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2042 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2043 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12, |
| 2044 | aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8, |
| 2045 | aom_highbd_12_sub_pixel_variance4x8, |
| 2046 | aom_highbd_12_sub_pixel_avg_variance4x8, NULL, |
| 2047 | aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2048 | |
| 2049 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2050 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 2051 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
| 2052 | aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12, |
| 2053 | aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2054 | |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 2055 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 2056 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_12_variance2x2, NULL, NULL, |
| 2057 | NULL, NULL, NULL) |
| 2058 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_12_variance4x2, NULL, NULL, |
| 2059 | NULL, NULL, NULL) |
| 2060 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_12_variance2x4, NULL, NULL, |
| 2061 | NULL, NULL, NULL) |
| 2062 | #endif |
| 2063 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2064 | #if CONFIG_EXT_PARTITION |
| 2065 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2066 | BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 2067 | aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128, |
| 2068 | aom_highbd_12_sub_pixel_variance128x128, |
| 2069 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 2070 | aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12, |
| 2071 | aom_highbd_sad128x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2072 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2073 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 2074 | aom_highbd_sad128x64_avg_bits12, |
| 2075 | aom_highbd_12_variance128x64, |
| 2076 | aom_highbd_12_sub_pixel_variance128x64, |
| 2077 | aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL, |
| 2078 | aom_highbd_sad128x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2079 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2080 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 2081 | aom_highbd_sad64x128_avg_bits12, |
| 2082 | aom_highbd_12_variance64x128, |
| 2083 | aom_highbd_12_sub_pixel_variance64x128, |
| 2084 | aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL, |
| 2085 | aom_highbd_sad64x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2086 | #endif // CONFIG_EXT_PARTITION |
| 2087 | |
| 2088 | #if CONFIG_EXT_INTER |
| 2089 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2090 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 2091 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 2092 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 2093 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 2094 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 2095 | aom_highbd_12_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2096 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2097 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 2098 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 2099 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 2100 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 2101 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 2102 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 2103 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 2104 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 2105 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 2106 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 2107 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 2108 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 2109 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 2110 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 2111 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 2112 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 2113 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 2114 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 2115 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 2116 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 2117 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 2118 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 2119 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 2120 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 2121 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 2122 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2123 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2124 | HIGHBD_MBFP(BLOCK_64X16, aom_highbd_masked_sad64x16_bits12, |
| 2125 | aom_highbd_12_masked_sub_pixel_variance64x16) |
| 2126 | |
| 2127 | HIGHBD_MBFP(BLOCK_16X64, aom_highbd_masked_sad16x64_bits12, |
| 2128 | aom_highbd_12_masked_sub_pixel_variance16x64) |
| 2129 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2130 | HIGHBD_MBFP(BLOCK_32X8, aom_highbd_masked_sad32x8_bits12, |
| 2131 | aom_highbd_12_masked_sub_pixel_variance32x8) |
| 2132 | |
| 2133 | HIGHBD_MBFP(BLOCK_8X32, aom_highbd_masked_sad8x32_bits12, |
| 2134 | aom_highbd_12_masked_sub_pixel_variance8x32) |
| 2135 | |
| 2136 | HIGHBD_MBFP(BLOCK_16X4, aom_highbd_masked_sad16x4_bits12, |
| 2137 | aom_highbd_12_masked_sub_pixel_variance16x4) |
| 2138 | |
| 2139 | HIGHBD_MBFP(BLOCK_4X16, aom_highbd_masked_sad4x16_bits12, |
| 2140 | aom_highbd_12_masked_sub_pixel_variance4x16) |
| 2141 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2142 | #endif // CONFIG_EXT_INTER |
| 2143 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2144 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2145 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2146 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 2147 | aom_highbd_12_obmc_variance128x128, |
| 2148 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 2149 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 2150 | aom_highbd_12_obmc_variance128x64, |
| 2151 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 2152 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 2153 | aom_highbd_12_obmc_variance64x128, |
| 2154 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2155 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2156 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 2157 | aom_highbd_12_obmc_variance64x64, |
| 2158 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 2159 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 2160 | aom_highbd_12_obmc_variance64x32, |
| 2161 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 2162 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 2163 | aom_highbd_12_obmc_variance32x64, |
| 2164 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 2165 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 2166 | aom_highbd_12_obmc_variance32x32, |
| 2167 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 2168 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 2169 | aom_highbd_12_obmc_variance32x16, |
| 2170 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 2171 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 2172 | aom_highbd_12_obmc_variance16x32, |
| 2173 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 2174 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 2175 | aom_highbd_12_obmc_variance16x16, |
| 2176 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 2177 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 2178 | aom_highbd_12_obmc_variance8x16, |
| 2179 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 2180 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 2181 | aom_highbd_12_obmc_variance16x8, |
| 2182 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 2183 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 2184 | aom_highbd_12_obmc_variance8x8, |
| 2185 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 2186 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 2187 | aom_highbd_12_obmc_variance4x8, |
| 2188 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 2189 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 2190 | aom_highbd_12_obmc_variance8x4, |
| 2191 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 2192 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 2193 | aom_highbd_12_obmc_variance4x4, |
| 2194 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2195 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2196 | HIGHBD_OBFP(BLOCK_64X16, aom_highbd_obmc_sad64x16_bits12, |
| 2197 | aom_highbd_12_obmc_variance64x16, |
| 2198 | aom_highbd_12_obmc_sub_pixel_variance64x16) |
| 2199 | |
| 2200 | HIGHBD_OBFP(BLOCK_16X64, aom_highbd_obmc_sad16x64_bits12, |
| 2201 | aom_highbd_12_obmc_variance16x64, |
| 2202 | aom_highbd_12_obmc_sub_pixel_variance16x64) |
| 2203 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2204 | HIGHBD_OBFP(BLOCK_32X8, aom_highbd_obmc_sad32x8_bits12, |
| 2205 | aom_highbd_12_obmc_variance32x8, |
| 2206 | aom_highbd_12_obmc_sub_pixel_variance32x8) |
| 2207 | |
| 2208 | HIGHBD_OBFP(BLOCK_8X32, aom_highbd_obmc_sad8x32_bits12, |
| 2209 | aom_highbd_12_obmc_variance8x32, |
| 2210 | aom_highbd_12_obmc_sub_pixel_variance8x32) |
| 2211 | |
| 2212 | HIGHBD_OBFP(BLOCK_16X4, aom_highbd_obmc_sad16x4_bits12, |
| 2213 | aom_highbd_12_obmc_variance16x4, |
| 2214 | aom_highbd_12_obmc_sub_pixel_variance16x4) |
| 2215 | |
| 2216 | HIGHBD_OBFP(BLOCK_4X16, aom_highbd_obmc_sad4x16_bits12, |
| 2217 | aom_highbd_12_obmc_variance4x16, |
| 2218 | aom_highbd_12_obmc_sub_pixel_variance4x16) |
| 2219 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2220 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2221 | break; |
| 2222 | |
| 2223 | default: |
| 2224 | assert(0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2225 | "cm->bit_depth should be AOM_BITS_8, " |
| 2226 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2230 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2231 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2232 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 2233 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2234 | |
| 2235 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2236 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2237 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2238 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2239 | |
| 2240 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2241 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2242 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2243 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2244 | |
| 2245 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2246 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2247 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2248 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2251 | #if CONFIG_EXT_INTER |
| 2252 | void set_compound_tools(AV1_COMMON *cm) { |
| 2253 | (void)cm; |
| 2254 | #if CONFIG_INTERINTRA |
| 2255 | cm->allow_interintra_compound = 1; |
| 2256 | #endif // CONFIG_INTERINTRA |
| 2257 | #if CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT |
| 2258 | cm->allow_masked_compound = 1; |
| 2259 | #endif // CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT |
| 2260 | } |
| 2261 | #endif // CONFIG_EXT_INTER |
| 2262 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2263 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 2264 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2265 | RATE_CONTROL *const rc = &cpi->rc; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2266 | MACROBLOCK *const x = &cpi->td.mb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2267 | |
| 2268 | if (cm->profile != oxcf->profile) cm->profile = oxcf->profile; |
| 2269 | cm->bit_depth = oxcf->bit_depth; |
| 2270 | cm->color_space = oxcf->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 2271 | #if CONFIG_COLORSPACE_HEADERS |
| 2272 | cm->transfer_function = oxcf->transfer_function; |
| 2273 | cm->chroma_sample_position = oxcf->chroma_sample_position; |
| 2274 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2275 | cm->color_range = oxcf->color_range; |
| 2276 | |
| 2277 | if (cm->profile <= PROFILE_1) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2278 | assert(cm->bit_depth == AOM_BITS_8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2279 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2280 | assert(cm->bit_depth > AOM_BITS_8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2281 | |
| 2282 | cpi->oxcf = *oxcf; |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2283 | x->e_mbd.bd = (int)cm->bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2284 | #if CONFIG_GLOBAL_MOTION |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2285 | x->e_mbd.global_motion = cm->global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2286 | #endif // CONFIG_GLOBAL_MOTION |
| 2287 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2288 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2289 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 2290 | } else { |
| 2291 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 2292 | } |
| 2293 | |
| 2294 | cpi->refresh_last_frame = 1; |
| 2295 | cpi->refresh_golden_frame = 0; |
| 2296 | #if CONFIG_EXT_REFS |
| 2297 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 2298 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2299 | #endif // CONFIG_EXT_REFS |
| 2300 | |
| 2301 | cm->refresh_frame_context = |
| 2302 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 2303 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 2304 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 2305 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2306 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 2307 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2308 | |
Alex Converse | 74ad091 | 2017-07-18 10:22:58 -0700 | [diff] [blame] | 2309 | if (x->palette_buffer == NULL) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2310 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
| 2311 | aom_memalign(16, sizeof(*x->palette_buffer))); |
| 2312 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2313 | #if CONFIG_EXT_INTER |
| 2314 | set_compound_tools(cm); |
| 2315 | #endif // CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2316 | av1_reset_segment_features(cm); |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2317 | av1_set_high_precision_mv(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2318 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2319 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 2320 | |
| 2321 | // Under a configuration change, where maximum_buffer_size may change, |
| 2322 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2323 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2324 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2325 | |
| 2326 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2327 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2328 | |
| 2329 | // Set absolute upper and lower quality limits |
| 2330 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2331 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2332 | |
| 2333 | cm->interp_filter = cpi->sf.default_interp_filter; |
| 2334 | |
| 2335 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2336 | cm->render_width = cpi->oxcf.render_width; |
| 2337 | cm->render_height = cpi->oxcf.render_height; |
| 2338 | } else { |
| 2339 | cm->render_width = cpi->oxcf.width; |
| 2340 | cm->render_height = cpi->oxcf.height; |
| 2341 | } |
| 2342 | cm->width = cpi->oxcf.width; |
| 2343 | cm->height = cpi->oxcf.height; |
| 2344 | |
| 2345 | if (cpi->initial_width) { |
| 2346 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2347 | av1_free_context_buffers(cm); |
| 2348 | av1_alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2349 | realloc_segmentation_maps(cpi); |
| 2350 | cpi->initial_width = cpi->initial_height = 0; |
| 2351 | } |
| 2352 | } |
| 2353 | update_frame_size(cpi); |
| 2354 | |
| 2355 | cpi->alt_ref_source = NULL; |
| 2356 | rc->is_src_frame_alt_ref = 0; |
| 2357 | |
| 2358 | #if CONFIG_EXT_REFS |
| 2359 | rc->is_bwd_ref_frame = 0; |
| 2360 | rc->is_last_bipred_frame = 0; |
| 2361 | rc->is_bipred_frame = 0; |
| 2362 | #endif // CONFIG_EXT_REFS |
| 2363 | |
| 2364 | #if 0 |
| 2365 | // Experimental RD Code |
| 2366 | cpi->frame_distortion = 0; |
| 2367 | cpi->last_frame_distortion = 0; |
| 2368 | #endif |
| 2369 | |
| 2370 | set_tile_info(cpi); |
| 2371 | |
| 2372 | cpi->ext_refresh_frame_flags_pending = 0; |
| 2373 | cpi->ext_refresh_frame_context_pending = 0; |
| 2374 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2375 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2376 | highbd_set_var_fns(cpi); |
| 2377 | #endif |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2378 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 2379 | cpi->common.ans_window_size_log2 = cpi->oxcf.ans_window_size_log2; |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2380 | #endif // CONFIG_ANS && ANS_MAX_SYMBOLS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2381 | } |
| 2382 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2383 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 2384 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2385 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2386 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2387 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2388 | |
| 2389 | if (!cm) return NULL; |
| 2390 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2391 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2392 | |
| 2393 | if (setjmp(cm->error.jmp)) { |
| 2394 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2395 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2396 | return 0; |
| 2397 | } |
| 2398 | |
| 2399 | cm->error.setjmp = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2400 | cm->alloc_mi = av1_enc_alloc_mi; |
| 2401 | cm->free_mi = av1_enc_free_mi; |
| 2402 | cm->setup_mi = av1_enc_setup_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2403 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2404 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2405 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
| 2406 | CHECK_MEM_ERROR(cm, cm->frame_contexts, |
| 2407 | (FRAME_CONTEXT *)aom_memalign( |
| 2408 | 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts))); |
| 2409 | memset(cm->fc, 0, sizeof(*cm->fc)); |
| 2410 | memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2411 | |
| 2412 | cpi->resize_state = 0; |
| 2413 | cpi->resize_avg_qp = 0; |
| 2414 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2415 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2416 | cpi->common.buffer_pool = pool; |
| 2417 | |
| 2418 | init_config(cpi, oxcf); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2419 | #if CONFIG_XIPHRC |
| 2420 | cpi->od_rc.framerate = cpi->framerate; |
| 2421 | cpi->od_rc.frame_width = cm->render_width; |
| 2422 | cpi->od_rc.frame_height = cm->render_height; |
| 2423 | cpi->od_rc.keyframe_rate = oxcf->key_freq; |
| 2424 | cpi->od_rc.goldenframe_rate = FIXED_GF_INTERVAL; |
| 2425 | cpi->od_rc.altref_rate = 25; |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2426 | cpi->od_rc.firstpass_quant = 1; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2427 | cpi->od_rc.bit_depth = cm->bit_depth; |
| 2428 | cpi->od_rc.minq = oxcf->best_allowed_q; |
| 2429 | cpi->od_rc.maxq = oxcf->worst_allowed_q; |
| 2430 | if (cpi->oxcf.rc_mode == AOM_CQ) cpi->od_rc.minq = cpi->od_rc.quality; |
| 2431 | cpi->od_rc.quality = cpi->oxcf.rc_mode == AOM_Q ? oxcf->cq_level : -1; |
| 2432 | cpi->od_rc.periodic_boosts = oxcf->frame_periodic_boost; |
| 2433 | od_enc_rc_init(&cpi->od_rc, |
| 2434 | cpi->oxcf.rc_mode == AOM_Q ? -1 : oxcf->target_bandwidth, |
| 2435 | oxcf->maximum_buffer_size_ms); |
| 2436 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2437 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2438 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2439 | |
| 2440 | cm->current_video_frame = 0; |
| 2441 | cpi->partition_search_skippable_frame = 0; |
| 2442 | cpi->tile_data = NULL; |
| 2443 | cpi->last_show_frame_buf_idx = INVALID_IDX; |
| 2444 | |
| 2445 | realloc_segmentation_maps(cpi); |
| 2446 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2447 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 2448 | memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs)); |
| 2449 | memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp)); |
| 2450 | } |
| 2451 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2452 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 2453 | i++) { |
| 2454 | CHECK_MEM_ERROR( |
| 2455 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2456 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | #if CONFIG_FP_MB_STATS |
| 2460 | cpi->use_fp_mb_stats = 0; |
| 2461 | if (cpi->use_fp_mb_stats) { |
| 2462 | // a place holder used to store the first pass mb stats in the first pass |
| 2463 | CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2464 | aom_calloc(cm->MBs * sizeof(uint8_t), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2465 | } else { |
| 2466 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2467 | } |
| 2468 | #endif |
| 2469 | |
| 2470 | cpi->refresh_alt_ref_frame = 0; |
| 2471 | cpi->multi_arf_last_grp_enabled = 0; |
| 2472 | |
| 2473 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 2474 | #if CONFIG_INTERNAL_STATS |
| 2475 | cpi->b_calculate_blockiness = 1; |
| 2476 | cpi->b_calculate_consistency = 1; |
| 2477 | cpi->total_inconsistency = 0; |
| 2478 | cpi->psnr.worst = 100.0; |
| 2479 | cpi->worst_ssim = 100.0; |
| 2480 | |
| 2481 | cpi->count = 0; |
| 2482 | cpi->bytes = 0; |
| 2483 | |
| 2484 | if (cpi->b_calculate_psnr) { |
| 2485 | cpi->total_sq_error = 0; |
| 2486 | cpi->total_samples = 0; |
| 2487 | cpi->tot_recode_hits = 0; |
| 2488 | cpi->summed_quality = 0; |
| 2489 | cpi->summed_weights = 0; |
| 2490 | } |
| 2491 | |
| 2492 | cpi->fastssim.worst = 100.0; |
| 2493 | cpi->psnrhvs.worst = 100.0; |
| 2494 | |
| 2495 | if (cpi->b_calculate_blockiness) { |
| 2496 | cpi->total_blockiness = 0; |
| 2497 | cpi->worst_blockiness = 0.0; |
| 2498 | } |
| 2499 | |
| 2500 | if (cpi->b_calculate_consistency) { |
| 2501 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2502 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2503 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 2504 | cpi->worst_consistency = 100.0; |
| 2505 | } |
| 2506 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2507 | #if CONFIG_ENTROPY_STATS |
| 2508 | av1_zero(aggregate_fc); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 2509 | av1_zero_array(aggregate_fc_per_type, FRAME_CONTEXTS); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2510 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2511 | |
| 2512 | cpi->first_time_stamp_ever = INT64_MAX; |
| 2513 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 2514 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 2515 | cpi->td.mb.nmvcost[i][0] = &cpi->nmv_costs[i][0][MV_MAX]; |
| 2516 | cpi->td.mb.nmvcost[i][1] = &cpi->nmv_costs[i][1][MV_MAX]; |
| 2517 | cpi->td.mb.nmvcost_hp[i][0] = &cpi->nmv_costs_hp[i][0][MV_MAX]; |
| 2518 | cpi->td.mb.nmvcost_hp[i][1] = &cpi->nmv_costs_hp[i][1][MV_MAX]; |
| 2519 | } |
| 2520 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2521 | #ifdef OUTPUT_YUV_SKINMAP |
| 2522 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 2523 | #endif |
| 2524 | #ifdef OUTPUT_YUV_REC |
| 2525 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 2526 | #endif |
| 2527 | |
| 2528 | #if 0 |
| 2529 | framepsnr = fopen("framepsnr.stt", "a"); |
| 2530 | kf_list = fopen("kf_list.stt", "w"); |
| 2531 | #endif |
| 2532 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2533 | #if CONFIG_XIPHRC |
| 2534 | if (oxcf->pass == 2) { |
| 2535 | cpi->od_rc.twopass_allframes_buf = oxcf->two_pass_stats_in.buf; |
| 2536 | cpi->od_rc.twopass_allframes_buf_size = oxcf->two_pass_stats_in.sz; |
| 2537 | } |
| 2538 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2539 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2540 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2541 | } else if (oxcf->pass == 2) { |
| 2542 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 2543 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 2544 | |
| 2545 | #if CONFIG_FP_MB_STATS |
| 2546 | if (cpi->use_fp_mb_stats) { |
| 2547 | const size_t psz = cpi->common.MBs * sizeof(uint8_t); |
| 2548 | const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz); |
| 2549 | |
| 2550 | cpi->twopass.firstpass_mb_stats.mb_stats_start = |
| 2551 | oxcf->firstpass_mb_stats_in.buf; |
| 2552 | cpi->twopass.firstpass_mb_stats.mb_stats_end = |
| 2553 | cpi->twopass.firstpass_mb_stats.mb_stats_start + |
| 2554 | (ps - 1) * cpi->common.MBs * sizeof(uint8_t); |
| 2555 | } |
| 2556 | #endif |
| 2557 | |
| 2558 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 2559 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 2560 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 2561 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2562 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2563 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2564 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2565 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2566 | #if CONFIG_MOTION_VAR |
| 2567 | #if CONFIG_HIGHBITDEPTH |
| 2568 | int buf_scaler = 2; |
| 2569 | #else |
| 2570 | int buf_scaler = 1; |
| 2571 | #endif |
| 2572 | CHECK_MEM_ERROR( |
| 2573 | cm, cpi->td.mb.above_pred_buf, |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 2574 | (uint8_t *)aom_memalign(16, |
| 2575 | buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2576 | sizeof(*cpi->td.mb.above_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2577 | CHECK_MEM_ERROR( |
| 2578 | cm, cpi->td.mb.left_pred_buf, |
clang-format | 4eafefe | 2017-09-04 12:51:20 -0700 | [diff] [blame] | 2579 | (uint8_t *)aom_memalign(16, |
| 2580 | buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2581 | sizeof(*cpi->td.mb.left_pred_buf))); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2582 | |
| 2583 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 2584 | (int32_t *)aom_memalign( |
| 2585 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 2586 | |
| 2587 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 2588 | (int32_t *)aom_memalign( |
| 2589 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 2590 | |
| 2591 | #endif |
| 2592 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2593 | av1_set_speed_features_framesize_independent(cpi); |
| 2594 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2595 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2596 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 2597 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 2598 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 2599 | cpi->fn_ptr[BT].vf = VF; \ |
| 2600 | cpi->fn_ptr[BT].svf = SVF; \ |
| 2601 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 2602 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 2603 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 2604 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
| 2605 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2606 | #if CONFIG_EXT_PARTITION_TYPES |
| 2607 | BFP(BLOCK_4X16, aom_sad4x16, aom_sad4x16_avg, aom_variance4x16, |
| 2608 | aom_sub_pixel_variance4x16, aom_sub_pixel_avg_variance4x16, NULL, NULL, |
| 2609 | aom_sad4x16x4d) |
| 2610 | |
| 2611 | BFP(BLOCK_16X4, aom_sad16x4, aom_sad16x4_avg, aom_variance16x4, |
| 2612 | aom_sub_pixel_variance16x4, aom_sub_pixel_avg_variance16x4, NULL, NULL, |
| 2613 | aom_sad16x4x4d) |
| 2614 | |
| 2615 | BFP(BLOCK_8X32, aom_sad8x32, aom_sad8x32_avg, aom_variance8x32, |
| 2616 | aom_sub_pixel_variance8x32, aom_sub_pixel_avg_variance8x32, NULL, NULL, |
| 2617 | aom_sad8x32x4d) |
| 2618 | |
| 2619 | BFP(BLOCK_32X8, aom_sad32x8, aom_sad32x8_avg, aom_variance32x8, |
| 2620 | aom_sub_pixel_variance32x8, aom_sub_pixel_avg_variance32x8, NULL, NULL, |
| 2621 | aom_sad32x8x4d) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2622 | |
| 2623 | BFP(BLOCK_16X64, aom_sad16x64, aom_sad16x64_avg, aom_variance16x64, |
| 2624 | aom_sub_pixel_variance16x64, aom_sub_pixel_avg_variance16x64, NULL, NULL, |
| 2625 | aom_sad16x64x4d) |
| 2626 | |
| 2627 | BFP(BLOCK_64X16, aom_sad64x16, aom_sad64x16_avg, aom_variance64x16, |
| 2628 | aom_sub_pixel_variance64x16, aom_sub_pixel_avg_variance64x16, NULL, NULL, |
| 2629 | aom_sad64x16x4d) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2630 | #endif |
| 2631 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2632 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2633 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 2634 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
| 2635 | aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2636 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2637 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
| 2638 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL, |
| 2639 | NULL, aom_sad128x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2640 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2641 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
| 2642 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL, |
| 2643 | NULL, aom_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2644 | #endif // CONFIG_EXT_PARTITION |
| 2645 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2646 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
| 2647 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2648 | aom_sad32x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2649 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2650 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
| 2651 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2652 | aom_sad16x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2653 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2654 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
| 2655 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2656 | aom_sad64x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2657 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2658 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
| 2659 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2660 | aom_sad32x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2661 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2662 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 2663 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
| 2664 | aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2665 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2666 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 2667 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
| 2668 | aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2669 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2670 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 2671 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
| 2672 | aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2673 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2674 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
| 2675 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3, |
| 2676 | aom_sad16x8x8, aom_sad16x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2677 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2678 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
| 2679 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3, |
| 2680 | aom_sad8x16x8, aom_sad8x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2681 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2682 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
| 2683 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3, |
| 2684 | aom_sad8x8x8, aom_sad8x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2685 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2686 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
| 2687 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL, |
| 2688 | aom_sad8x4x8, aom_sad8x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2689 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2690 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
| 2691 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL, |
| 2692 | aom_sad4x8x8, aom_sad4x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2693 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2694 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
| 2695 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3, |
| 2696 | aom_sad4x4x8, aom_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2697 | |
Timothy B. Terriberry | 81ec261 | 2017-04-26 16:53:47 -0700 | [diff] [blame] | 2698 | #if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8 |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 2699 | BFP(BLOCK_2X2, NULL, NULL, aom_variance2x2, NULL, NULL, NULL, NULL, NULL) |
Jingning Han | e2ffaf8 | 2016-12-14 15:26:30 -0800 | [diff] [blame] | 2700 | BFP(BLOCK_2X4, NULL, NULL, aom_variance2x4, NULL, NULL, NULL, NULL, NULL) |
| 2701 | BFP(BLOCK_4X2, NULL, NULL, aom_variance4x2, NULL, NULL, NULL, NULL, NULL) |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 2702 | #endif |
| 2703 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2704 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2705 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 2706 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 2707 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 2708 | cpi->fn_ptr[BT].osvf = OSVF; |
| 2709 | |
| 2710 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2711 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 2712 | aom_obmc_sub_pixel_variance128x128) |
| 2713 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 2714 | aom_obmc_sub_pixel_variance128x64) |
| 2715 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 2716 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2717 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2718 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 2719 | aom_obmc_sub_pixel_variance64x64) |
| 2720 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 2721 | aom_obmc_sub_pixel_variance64x32) |
| 2722 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 2723 | aom_obmc_sub_pixel_variance32x64) |
| 2724 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 2725 | aom_obmc_sub_pixel_variance32x32) |
| 2726 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 2727 | aom_obmc_sub_pixel_variance32x16) |
| 2728 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 2729 | aom_obmc_sub_pixel_variance16x32) |
| 2730 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 2731 | aom_obmc_sub_pixel_variance16x16) |
| 2732 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 2733 | aom_obmc_sub_pixel_variance16x8) |
| 2734 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 2735 | aom_obmc_sub_pixel_variance8x16) |
| 2736 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 2737 | aom_obmc_sub_pixel_variance8x8) |
| 2738 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 2739 | aom_obmc_sub_pixel_variance4x8) |
| 2740 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 2741 | aom_obmc_sub_pixel_variance8x4) |
| 2742 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 2743 | aom_obmc_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2744 | |
| 2745 | #if CONFIG_EXT_PARTITION_TYPES |
| 2746 | OBFP(BLOCK_4X16, aom_obmc_sad4x16, aom_obmc_variance4x16, |
| 2747 | aom_obmc_sub_pixel_variance4x16) |
| 2748 | |
| 2749 | OBFP(BLOCK_16X4, aom_obmc_sad16x4, aom_obmc_variance16x4, |
| 2750 | aom_obmc_sub_pixel_variance16x4) |
| 2751 | |
| 2752 | OBFP(BLOCK_8X32, aom_obmc_sad8x32, aom_obmc_variance8x32, |
| 2753 | aom_obmc_sub_pixel_variance8x32) |
| 2754 | |
| 2755 | OBFP(BLOCK_32X8, aom_obmc_sad32x8, aom_obmc_variance32x8, |
| 2756 | aom_obmc_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2757 | |
| 2758 | OBFP(BLOCK_16X64, aom_obmc_sad16x64, aom_obmc_variance16x64, |
| 2759 | aom_obmc_sub_pixel_variance16x64) |
| 2760 | |
| 2761 | OBFP(BLOCK_64X16, aom_obmc_sad64x16, aom_obmc_variance64x16, |
| 2762 | aom_obmc_sub_pixel_variance64x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2763 | #endif |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2764 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2765 | |
| 2766 | #if CONFIG_EXT_INTER |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2767 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 2768 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 2769 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2770 | |
| 2771 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2772 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 2773 | aom_masked_sub_pixel_variance128x128) |
| 2774 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 2775 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2776 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2777 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 2778 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 2779 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 2780 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 2781 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 2782 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 2783 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 2784 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 2785 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 2786 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 2787 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 2788 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 2789 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2790 | |
| 2791 | #if CONFIG_EXT_PARTITION_TYPES |
| 2792 | MBFP(BLOCK_4X16, aom_masked_sad4x16, aom_masked_sub_pixel_variance4x16) |
| 2793 | |
| 2794 | MBFP(BLOCK_16X4, aom_masked_sad16x4, aom_masked_sub_pixel_variance16x4) |
| 2795 | |
| 2796 | MBFP(BLOCK_8X32, aom_masked_sad8x32, aom_masked_sub_pixel_variance8x32) |
| 2797 | |
| 2798 | MBFP(BLOCK_32X8, aom_masked_sad32x8, aom_masked_sub_pixel_variance32x8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 2799 | |
| 2800 | MBFP(BLOCK_16X64, aom_masked_sad16x64, aom_masked_sub_pixel_variance16x64) |
| 2801 | |
| 2802 | MBFP(BLOCK_64X16, aom_masked_sad64x16, aom_masked_sub_pixel_variance64x16) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 2803 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2804 | #endif // CONFIG_EXT_INTER |
| 2805 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2806 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2807 | highbd_set_var_fns(cpi); |
| 2808 | #endif |
| 2809 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2810 | /* av1_init_quantizer() is first called here. Add check in |
| 2811 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2812 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2813 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2814 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2815 | av1_init_quantizer(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2816 | #if CONFIG_AOM_QM |
| 2817 | aom_qm_init(cm); |
| 2818 | #endif |
| 2819 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2820 | av1_loop_filter_init(cm); |
Fergus Simpson | dac6aff | 2017-05-18 15:11:38 -0700 | [diff] [blame] | 2821 | #if CONFIG_FRAME_SUPERRES |
Fergus Simpson | bfbf6a5 | 2017-06-14 23:13:12 -0700 | [diff] [blame] | 2822 | cm->superres_scale_numerator = SCALE_DENOMINATOR; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 2823 | cm->superres_upscaled_width = oxcf->width; |
| 2824 | cm->superres_upscaled_height = oxcf->height; |
Fergus Simpson | dac6aff | 2017-05-18 15:11:38 -0700 | [diff] [blame] | 2825 | #endif // CONFIG_FRAME_SUPERRES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2826 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2827 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2828 | #endif // CONFIG_LOOP_RESTORATION |
| 2829 | |
| 2830 | cm->error.setjmp = 0; |
| 2831 | |
| 2832 | return cpi; |
| 2833 | } |
| 2834 | |
| 2835 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 2836 | |
| 2837 | #define SNPRINT2(H, T, V) \ |
| 2838 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
| 2839 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2840 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 2841 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2842 | unsigned int i; |
| 2843 | int t; |
| 2844 | |
| 2845 | if (!cpi) return; |
| 2846 | |
| 2847 | cm = &cpi->common; |
| 2848 | if (cm->current_video_frame > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2849 | #if CONFIG_ENTROPY_STATS |
| 2850 | if (cpi->oxcf.pass != 1) { |
| 2851 | fprintf(stderr, "Writing counts.stt\n"); |
| 2852 | FILE *f = fopen("counts.stt", "wb"); |
| 2853 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 2854 | fwrite(aggregate_fc_per_type, sizeof(aggregate_fc_per_type[0]), |
| 2855 | FRAME_CONTEXTS, f); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2856 | fclose(f); |
| 2857 | } |
| 2858 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2859 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2860 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2861 | |
| 2862 | if (cpi->oxcf.pass != 1) { |
| 2863 | char headings[512] = { 0 }; |
| 2864 | char results[512] = { 0 }; |
| 2865 | FILE *f = fopen("opsnr.stt", "a"); |
| 2866 | double time_encoded = |
| 2867 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 2868 | 10000000.000; |
| 2869 | double total_encode_time = |
| 2870 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 2871 | const double dr = |
| 2872 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 2873 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 2874 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 2875 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 2876 | |
| 2877 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2878 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2879 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 2880 | const double total_ssim = |
| 2881 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 2882 | snprintf(headings, sizeof(headings), |
| 2883 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2884 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2885 | "WstPsnr\tWstSsim\tWstFast\tWstHVS"); |
| 2886 | snprintf(results, sizeof(results), |
| 2887 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 2888 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 2889 | "%7.3f\t%7.3f\t%7.3f\t%7.3f", |
| 2890 | dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr, |
| 2891 | cpi->psnr.stat[ALL] / cpi->count, total_psnr, total_ssim, |
| 2892 | total_ssim, cpi->fastssim.stat[ALL] / cpi->count, |
| 2893 | cpi->psnrhvs.stat[ALL] / cpi->count, cpi->psnr.worst, |
| 2894 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst); |
| 2895 | |
| 2896 | if (cpi->b_calculate_blockiness) { |
| 2897 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 2898 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 2899 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 2900 | } |
| 2901 | |
| 2902 | if (cpi->b_calculate_consistency) { |
| 2903 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2904 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2905 | (double)cpi->total_inconsistency); |
| 2906 | |
| 2907 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 2908 | SNPRINT2(results, "\t%7.3f", consistency); |
| 2909 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 2910 | } |
Sarah Parker | f97b786 | 2016-08-25 17:42:57 -0700 | [diff] [blame] | 2911 | fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings); |
| 2912 | 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] | 2913 | rate_err, fabs(rate_err)); |
| 2914 | } |
| 2915 | |
| 2916 | fclose(f); |
| 2917 | } |
| 2918 | |
| 2919 | #endif |
| 2920 | |
| 2921 | #if 0 |
| 2922 | { |
| 2923 | printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); |
| 2924 | printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); |
| 2925 | printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, |
| 2926 | cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, |
| 2927 | cpi->time_compress_data / 1000, |
| 2928 | (cpi->time_receive_data + cpi->time_compress_data) / 1000); |
| 2929 | } |
| 2930 | #endif |
| 2931 | } |
| 2932 | |
| 2933 | for (t = 0; t < cpi->num_workers; ++t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2934 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2935 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 2936 | |
| 2937 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2938 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2939 | |
| 2940 | // Deallocate allocated thread data. |
| 2941 | if (t < cpi->num_workers - 1) { |
hui su | d9a812b | 2017-07-06 14:34:37 -0700 | [diff] [blame] | 2942 | aom_free(thread_data->td->palette_buffer); |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2943 | #if CONFIG_MOTION_VAR |
| 2944 | aom_free(thread_data->td->above_pred_buf); |
| 2945 | aom_free(thread_data->td->left_pred_buf); |
| 2946 | aom_free(thread_data->td->wsrc_buf); |
| 2947 | aom_free(thread_data->td->mask_buf); |
| 2948 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2949 | aom_free(thread_data->td->counts); |
| 2950 | av1_free_pc_tree(thread_data->td); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2951 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2952 | } |
| 2953 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2954 | aom_free(cpi->tile_thr_data); |
| 2955 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2956 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2957 | 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] | 2958 | |
| 2959 | dealloc_compressor_data(cpi); |
| 2960 | |
| 2961 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 2962 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2963 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | #if CONFIG_FP_MB_STATS |
| 2967 | if (cpi->use_fp_mb_stats) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2968 | aom_free(cpi->twopass.frame_mb_stats_buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2969 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2970 | } |
| 2971 | #endif |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 2972 | #if CONFIG_INTERNAL_STATS |
| 2973 | aom_free(cpi->ssim_vars); |
| 2974 | cpi->ssim_vars = NULL; |
| 2975 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2976 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2977 | av1_remove_common(cm); |
| 2978 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 2979 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2980 | |
| 2981 | #ifdef OUTPUT_YUV_SKINMAP |
| 2982 | fclose(yuv_skinmap_file); |
| 2983 | #endif |
| 2984 | #ifdef OUTPUT_YUV_REC |
| 2985 | fclose(yuv_rec_file); |
| 2986 | #endif |
| 2987 | |
| 2988 | #if 0 |
| 2989 | |
| 2990 | if (keyfile) |
| 2991 | fclose(keyfile); |
| 2992 | |
| 2993 | if (framepsnr) |
| 2994 | fclose(framepsnr); |
| 2995 | |
| 2996 | if (kf_list) |
| 2997 | fclose(kf_list); |
| 2998 | |
| 2999 | #endif |
| 3000 | } |
| 3001 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3002 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 3003 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3004 | int i; |
| 3005 | PSNR_STATS psnr; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3006 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3007 | aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3008 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
| 3009 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3010 | aom_calc_psnr(cpi->source, cpi->common.frame_to_show, &psnr); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3011 | #endif |
| 3012 | |
| 3013 | for (i = 0; i < 4; ++i) { |
| 3014 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 3015 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 3016 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 3017 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3018 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 3019 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3022 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3023 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 3024 | |
| 3025 | cpi->ref_frame_flags = ref_frame_flags; |
| 3026 | return 0; |
| 3027 | } |
| 3028 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3029 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags) { |
| 3030 | cpi->ext_refresh_golden_frame = (ref_frame_flags & AOM_GOLD_FLAG) != 0; |
| 3031 | cpi->ext_refresh_alt_ref_frame = (ref_frame_flags & AOM_ALT_FLAG) != 0; |
| 3032 | cpi->ext_refresh_last_frame = (ref_frame_flags & AOM_LAST_FLAG) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3033 | cpi->ext_refresh_frame_flags_pending = 1; |
| 3034 | } |
| 3035 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3036 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd) { |
| 3037 | AV1_COMMON *const cm = &cpi->common; |
| 3038 | YV12_BUFFER_CONFIG *cfg = get_ref_frame(cm, idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3039 | if (cfg) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3040 | aom_yv12_copy_frame(cfg, sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3041 | return 0; |
| 3042 | } else { |
| 3043 | return -1; |
| 3044 | } |
| 3045 | } |
| 3046 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 3047 | int av1_set_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 | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3050 | if (cfg) { |
| 3051 | aom_yv12_copy_frame(sd, cfg); |
| 3052 | return 0; |
| 3053 | } else { |
| 3054 | return -1; |
| 3055 | } |
| 3056 | } |
| 3057 | |
| 3058 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3059 | cpi->ext_refresh_frame_context = update; |
| 3060 | cpi->ext_refresh_frame_context_pending = 1; |
| 3061 | return 0; |
| 3062 | } |
| 3063 | |
| 3064 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 3065 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 3066 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 3067 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 3068 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3069 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3070 | uint8_t *src = s->y_buffer; |
| 3071 | int h = s->y_height; |
| 3072 | |
| 3073 | do { |
| 3074 | fwrite(src, s->y_width, 1, f); |
| 3075 | src += s->y_stride; |
| 3076 | } while (--h); |
| 3077 | |
| 3078 | src = s->u_buffer; |
| 3079 | h = s->uv_height; |
| 3080 | |
| 3081 | do { |
| 3082 | fwrite(src, s->uv_width, 1, f); |
| 3083 | src += s->uv_stride; |
| 3084 | } while (--h); |
| 3085 | |
| 3086 | src = s->v_buffer; |
| 3087 | h = s->uv_height; |
| 3088 | |
| 3089 | do { |
| 3090 | fwrite(src, s->uv_width, 1, f); |
| 3091 | src += s->uv_stride; |
| 3092 | } while (--h); |
| 3093 | } |
| 3094 | #endif |
| 3095 | |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 3096 | #if CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3097 | static void check_show_existing_frame(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3098 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3099 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3100 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 3101 | gf_group->update_type[gf_group->index]; |
| 3102 | const int which_arf = gf_group->arf_update_idx[gf_group->index]; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3103 | |
| 3104 | if (cm->show_existing_frame == 1) { |
| 3105 | cm->show_existing_frame = 0; |
| 3106 | } else if (cpi->rc.is_last_bipred_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3107 | // NOTE(zoeliu): If the current frame is a last bi-predictive frame, it is |
| 3108 | // needed next to show the BWDREF_FRAME, which is pointed by |
| 3109 | // the last_fb_idxes[0] after reference frame buffer update |
| 3110 | cpi->rc.is_last_bipred_frame = 0; |
| 3111 | cm->show_existing_frame = 1; |
| 3112 | cpi->existing_fb_idx_to_show = cpi->lst_fb_idxes[0]; |
| 3113 | } else if (cpi->is_arf_filter_off[which_arf] && |
| 3114 | (next_frame_update_type == OVERLAY_UPDATE || |
| 3115 | next_frame_update_type == INTNL_OVERLAY_UPDATE)) { |
| 3116 | // Other parameters related to OVERLAY_UPDATE will be taken care of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3117 | // in av1_rc_get_second_pass_params(cpi) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3118 | cm->show_existing_frame = 1; |
| 3119 | cpi->rc.is_src_frame_alt_ref = 1; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3120 | cpi->existing_fb_idx_to_show = (next_frame_update_type == OVERLAY_UPDATE) |
| 3121 | ? cpi->alt_fb_idx |
| 3122 | : cpi->alt2_fb_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3123 | cpi->is_arf_filter_off[which_arf] = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3124 | } |
| 3125 | cpi->rc.is_src_frame_ext_arf = 0; |
| 3126 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 3127 | #endif // CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3128 | |
| 3129 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3130 | 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] | 3131 | uint8_t *src = s->y_buffer; |
| 3132 | int h = cm->height; |
| 3133 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3134 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3135 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 3136 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 3137 | |
| 3138 | do { |
| 3139 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 3140 | src16 += s->y_stride; |
| 3141 | } while (--h); |
| 3142 | |
| 3143 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 3144 | h = s->uv_height; |
| 3145 | |
| 3146 | do { |
| 3147 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3148 | src16 += s->uv_stride; |
| 3149 | } while (--h); |
| 3150 | |
| 3151 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 3152 | h = s->uv_height; |
| 3153 | |
| 3154 | do { |
| 3155 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 3156 | src16 += s->uv_stride; |
| 3157 | } while (--h); |
| 3158 | |
| 3159 | fflush(yuv_rec_file); |
| 3160 | return; |
| 3161 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3162 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3163 | |
| 3164 | do { |
| 3165 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 3166 | src += s->y_stride; |
| 3167 | } while (--h); |
| 3168 | |
| 3169 | src = s->u_buffer; |
| 3170 | h = s->uv_height; |
| 3171 | |
| 3172 | do { |
| 3173 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3174 | src += s->uv_stride; |
| 3175 | } while (--h); |
| 3176 | |
| 3177 | src = s->v_buffer; |
| 3178 | h = s->uv_height; |
| 3179 | |
| 3180 | do { |
| 3181 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 3182 | src += s->uv_stride; |
| 3183 | } while (--h); |
| 3184 | |
| 3185 | fflush(yuv_rec_file); |
| 3186 | } |
| 3187 | #endif // OUTPUT_YUV_REC |
| 3188 | |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3189 | #if CONFIG_GLOBAL_MOTION |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 3190 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3191 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 3192 | int i; |
| 3193 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3194 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3195 | AV1_COMMON *const cm = &cpi->common; |
| 3196 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3197 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3198 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3199 | cpi->gmparams_cost[i]) { |
Sarah Parker | 4c10a3c | 2017-04-10 19:37:59 -0700 | [diff] [blame] | 3200 | set_default_warp_params(&cm->global_motion[i]); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 3201 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 3202 | recode = 1; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 3203 | recode |= (rdc->global_motion_used[i] > 0); |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3204 | } |
| 3205 | } |
| 3206 | return recode; |
| 3207 | } |
| 3208 | #endif // CONFIG_GLOBAL_MOTION |
| 3209 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3210 | // Function to test for conditions that indicate we should loop |
| 3211 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3212 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 3213 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3214 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3215 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3216 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 3217 | int force_recode = 0; |
| 3218 | |
| 3219 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 3220 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 3221 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3222 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 3223 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 3224 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 3225 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3226 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3227 | // Deal with frame undershoot and whether or not we are |
| 3228 | // below the automatically set cq level. |
| 3229 | if (q > oxcf->cq_level && |
| 3230 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 3231 | force_recode = 1; |
| 3232 | } |
| 3233 | } |
| 3234 | } |
| 3235 | return force_recode; |
| 3236 | } |
| 3237 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3238 | #define DUMP_REF_FRAME_IMAGES 0 |
| 3239 | |
| 3240 | #if DUMP_REF_FRAME_IMAGES == 1 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3241 | static int dump_one_image(AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3242 | const YV12_BUFFER_CONFIG *const ref_buf, |
| 3243 | char *file_name) { |
| 3244 | int h; |
| 3245 | FILE *f_ref = NULL; |
| 3246 | |
| 3247 | if (ref_buf == NULL) { |
| 3248 | printf("Frame data buffer is NULL.\n"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3249 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | if ((f_ref = fopen(file_name, "wb")) == NULL) { |
| 3253 | printf("Unable to open file %s to write.\n", file_name); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3254 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | // --- Y --- |
| 3258 | for (h = 0; h < cm->height; ++h) { |
| 3259 | fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref); |
| 3260 | } |
| 3261 | // --- U --- |
| 3262 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3263 | fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3264 | f_ref); |
| 3265 | } |
| 3266 | // --- V --- |
| 3267 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3268 | fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3269 | f_ref); |
| 3270 | } |
| 3271 | |
| 3272 | fclose(f_ref); |
| 3273 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3274 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3275 | } |
| 3276 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3277 | static void dump_ref_frame_images(AV1_COMP *cpi) { |
| 3278 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3279 | MV_REFERENCE_FRAME ref_frame; |
| 3280 | |
| 3281 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3282 | char file_name[256] = ""; |
| 3283 | snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv", |
| 3284 | cm->current_video_frame, ref_frame); |
| 3285 | dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name); |
| 3286 | } |
| 3287 | } |
| 3288 | #endif // DUMP_REF_FRAME_IMAGES == 1 |
| 3289 | |
| 3290 | #if CONFIG_EXT_REFS |
| 3291 | // This function is used to shift the virtual indices of last reference frames |
| 3292 | // as follows: |
| 3293 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3294 | // when the LAST_FRAME is updated. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3295 | static INLINE void shift_last_ref_frames(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3296 | int ref_frame; |
| 3297 | for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) { |
| 3298 | cpi->lst_fb_idxes[ref_frame] = cpi->lst_fb_idxes[ref_frame - 1]; |
| 3299 | |
| 3300 | // [0] is allocated to the current coded frame. The statistics for the |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3301 | // reference frames start at [LAST_FRAME], i.e. [1]. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3302 | if (!cpi->rc.is_src_frame_alt_ref) { |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3303 | memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME], |
| 3304 | cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME], |
| 3305 | sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3306 | } |
| 3307 | } |
| 3308 | } |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3309 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3310 | |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 3311 | #if CONFIG_VAR_REFS |
| 3312 | static void enc_check_valid_ref_frames(AV1_COMP *const cpi) { |
| 3313 | AV1_COMMON *const cm = &cpi->common; |
| 3314 | MV_REFERENCE_FRAME ref_frame; |
| 3315 | |
| 3316 | // TODO(zoeliu): To handle ALTREF_FRAME the same way as do with other |
| 3317 | // reference frames. Current encoder invalid ALTREF when ALTREF |
| 3318 | // is the same as LAST, but invalid all the other references |
| 3319 | // when they are the same as ALTREF. |
| 3320 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3321 | int ref_buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3322 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 3323 | |
| 3324 | if (ref_buf_idx != INVALID_IDX) { |
| 3325 | ref_buf->is_valid = 1; |
| 3326 | |
| 3327 | MV_REFERENCE_FRAME ref; |
| 3328 | for (ref = LAST_FRAME; ref < ref_frame; ++ref) { |
| 3329 | int buf_idx = get_ref_frame_buf_idx(cpi, ref); |
| 3330 | RefBuffer *const buf = &cm->frame_refs[ref - LAST_FRAME]; |
| 3331 | if (buf->is_valid && buf_idx == ref_buf_idx) { |
| 3332 | if (ref_frame != ALTREF_FRAME || ref == LAST_FRAME) { |
| 3333 | ref_buf->is_valid = 0; |
| 3334 | break; |
| 3335 | } else { |
| 3336 | buf->is_valid = 0; |
| 3337 | } |
| 3338 | } |
| 3339 | } |
| 3340 | } else { |
| 3341 | ref_buf->is_valid = 0; |
| 3342 | } |
| 3343 | } |
| 3344 | } |
| 3345 | #endif // CONFIG_VAR_REFS |
| 3346 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3347 | void av1_update_reference_frames(AV1_COMP *cpi) { |
| 3348 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3349 | BufferPool *const pool = cm->buffer_pool; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3350 | |
| 3351 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 3352 | // for the purpose to verify no mismatch between encoder and decoder. |
| 3353 | if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx; |
| 3354 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3355 | // At this point the new frame has been encoded. |
| 3356 | // If any buffer copy / swapping is signaled it should be done here. |
| 3357 | if (cm->frame_type == KEY_FRAME) { |
| 3358 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3359 | cm->new_fb_idx); |
| 3360 | #if CONFIG_EXT_REFS |
| 3361 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3362 | cm->new_fb_idx); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3363 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3364 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3365 | #endif // CONFIG_EXT_REFS |
| 3366 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3367 | cm->new_fb_idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3368 | } else if (av1_preserve_existing_gf(cpi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3369 | // We have decided to preserve the previously existing golden frame as our |
| 3370 | // new ARF frame. However, in the short term in function |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3371 | // 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] | 3372 | // we're updating the GF with the current decoded frame, we save it to the |
| 3373 | // ARF slot instead. |
| 3374 | // We now have to update the ARF with the current frame and swap gld_fb_idx |
| 3375 | // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF |
| 3376 | // slot and, if we're updating the GF, the current frame becomes the new GF. |
| 3377 | int tmp; |
| 3378 | |
| 3379 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3380 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3381 | tmp = cpi->alt_fb_idx; |
| 3382 | cpi->alt_fb_idx = cpi->gld_fb_idx; |
| 3383 | cpi->gld_fb_idx = tmp; |
| 3384 | |
| 3385 | #if CONFIG_EXT_REFS |
| 3386 | // We need to modify the mapping accordingly |
| 3387 | cpi->arf_map[0] = cpi->alt_fb_idx; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3388 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3389 | // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to |
| 3390 | // cpi->interp_filter_selected[GOLDEN_FRAME]? |
| 3391 | #if CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3392 | } else if (cpi->rc.is_src_frame_ext_arf && cm->show_existing_frame) { |
| 3393 | // Deal with the special case for showing existing internal ALTREF_FRAME |
| 3394 | // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME |
| 3395 | // by updating the virtual indices. |
| 3396 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3397 | const int which_arf = gf_group->arf_ref_idx[gf_group->index]; |
| 3398 | assert(gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3399 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3400 | const int tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3401 | shift_last_ref_frames(cpi); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3402 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3403 | cpi->lst_fb_idxes[0] = cpi->alt2_fb_idx; |
| 3404 | cpi->alt2_fb_idx = tmp; |
| 3405 | // We need to modify the mapping accordingly |
| 3406 | cpi->arf_map[which_arf] = cpi->alt2_fb_idx; |
| 3407 | |
| 3408 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3409 | cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3410 | sizeof(cpi->interp_filter_selected[ALTREF2_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3411 | #endif // CONFIG_EXT_REFS |
| 3412 | } else { /* For non key/golden frames */ |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3413 | // === ALTREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3414 | if (cpi->refresh_alt_ref_frame) { |
| 3415 | int arf_idx = cpi->alt_fb_idx; |
| 3416 | int which_arf = 0; |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 3417 | #if !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3418 | if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { |
| 3419 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3420 | arf_idx = gf_group->arf_update_idx[gf_group->index]; |
| 3421 | } |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 3422 | #endif // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3423 | 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] | 3424 | |
| 3425 | memcpy(cpi->interp_filter_selected[ALTREF_FRAME + which_arf], |
| 3426 | cpi->interp_filter_selected[0], |
| 3427 | sizeof(cpi->interp_filter_selected[0])); |
| 3428 | } |
| 3429 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3430 | // === GOLDEN_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3431 | if (cpi->refresh_golden_frame) { |
| 3432 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3433 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3434 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3435 | #if !CONFIG_EXT_REFS |
| 3436 | if (!cpi->rc.is_src_frame_alt_ref) |
| 3437 | #endif // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3438 | memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], |
| 3439 | cpi->interp_filter_selected[0], |
| 3440 | sizeof(cpi->interp_filter_selected[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3444 | // === BWDREF_FRAME === |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3445 | if (cpi->refresh_bwd_ref_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3446 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3447 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3448 | |
| 3449 | memcpy(cpi->interp_filter_selected[BWDREF_FRAME], |
| 3450 | cpi->interp_filter_selected[0], |
| 3451 | sizeof(cpi->interp_filter_selected[0])); |
| 3452 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3453 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3454 | // === ALTREF2_FRAME === |
| 3455 | if (cpi->refresh_alt2_ref_frame) { |
| 3456 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt2_fb_idx], |
| 3457 | cm->new_fb_idx); |
| 3458 | |
| 3459 | memcpy(cpi->interp_filter_selected[ALTREF2_FRAME], |
| 3460 | cpi->interp_filter_selected[0], |
| 3461 | sizeof(cpi->interp_filter_selected[0])); |
| 3462 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3463 | #endif // CONFIG_EXT_REFS |
| 3464 | } |
| 3465 | |
| 3466 | if (cpi->refresh_last_frame) { |
| 3467 | #if CONFIG_EXT_REFS |
| 3468 | // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame |
| 3469 | // reference to the reference frame buffer virtual index; and then (2) from |
| 3470 | // the virtual index to the reference frame buffer physical index: |
| 3471 | // |
| 3472 | // LAST_FRAME, ..., LAST3_FRAME, ..., ALTREF_FRAME |
| 3473 | // | | | |
| 3474 | // v v v |
| 3475 | // lst_fb_idxes[0], ..., lst_fb_idxes[2], ..., alt_fb_idx |
| 3476 | // | | | |
| 3477 | // v v v |
| 3478 | // ref_frame_map[], ..., ref_frame_map[], ..., ref_frame_map[] |
| 3479 | // |
| 3480 | // When refresh_last_frame is set, it is intended to retire LAST3_FRAME, |
| 3481 | // have the other 2 LAST reference frames shifted as follows: |
| 3482 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3483 | // , and then have LAST_FRAME refreshed by the newly coded frame. |
| 3484 | // |
| 3485 | // To fulfill it, the decoder will be notified to execute following 2 steps: |
| 3486 | // |
| 3487 | // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME |
| 3488 | // to point to the newly coded frame, i.e. |
| 3489 | // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx; |
| 3490 | // |
| 3491 | // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the |
| 3492 | // original virtual index of LAST3_FRAME and have the other mappings |
| 3493 | // shifted as follows: |
| 3494 | // LAST_FRAME, LAST2_FRAME, LAST3_FRAME |
| 3495 | // | | | |
| 3496 | // v v v |
| 3497 | // lst_fb_idxes[2], lst_fb_idxes[0], lst_fb_idxes[1] |
| 3498 | int ref_frame; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3499 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3500 | if (cm->frame_type == KEY_FRAME) { |
| 3501 | for (ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) { |
| 3502 | ref_cnt_fb(pool->frame_bufs, |
| 3503 | &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]], |
| 3504 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3505 | } |
| 3506 | } else { |
| 3507 | int tmp; |
| 3508 | |
| 3509 | ref_cnt_fb(pool->frame_bufs, |
| 3510 | &cm->ref_frame_map[cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]], |
| 3511 | cm->new_fb_idx); |
| 3512 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3513 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3514 | |
| 3515 | shift_last_ref_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3516 | cpi->lst_fb_idxes[0] = tmp; |
| 3517 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3518 | assert(cm->show_existing_frame == 0); |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3519 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3520 | cpi->interp_filter_selected[0], |
| 3521 | sizeof(cpi->interp_filter_selected[0])); |
Zoe Liu | aff92d5 | 2017-07-11 21:35:08 -0700 | [diff] [blame] | 3522 | |
| 3523 | if (cpi->rc.is_last_bipred_frame) { |
| 3524 | // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the |
| 3525 | // LAST3_FRAME by updating the virtual indices. |
| 3526 | // |
| 3527 | // NOTE: The source frame for BWDREF does not have a holding position as |
| 3528 | // the OVERLAY frame for ALTREF's. Hence, to resolve the reference |
| 3529 | // virtual index reshuffling for BWDREF, the encoder always |
| 3530 | // specifies a LAST_BIPRED right before BWDREF and completes the |
| 3531 | // reshuffling job accordingly. |
| 3532 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3533 | |
| 3534 | shift_last_ref_frames(cpi); |
| 3535 | cpi->lst_fb_idxes[0] = cpi->bwd_fb_idx; |
| 3536 | cpi->bwd_fb_idx = tmp; |
| 3537 | |
| 3538 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3539 | cpi->interp_filter_selected[BWDREF_FRAME], |
| 3540 | sizeof(cpi->interp_filter_selected[BWDREF_FRAME])); |
| 3541 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3542 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3543 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3544 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->lst_fb_idx], |
| 3545 | cm->new_fb_idx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3546 | if (!cpi->rc.is_src_frame_alt_ref) { |
| 3547 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3548 | cpi->interp_filter_selected[0], |
| 3549 | sizeof(cpi->interp_filter_selected[0])); |
| 3550 | } |
| 3551 | #endif // CONFIG_EXT_REFS |
| 3552 | } |
| 3553 | |
| 3554 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3555 | // Dump out all reference frame images. |
| 3556 | dump_ref_frame_images(cpi); |
| 3557 | #endif // DUMP_REF_FRAME_IMAGES |
| 3558 | } |
| 3559 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3560 | 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] | 3561 | assert(buffer_idx != INVALID_IDX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3562 | RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 3563 | ensure_mv_buffer(new_fb_ptr, cm); |
| 3564 | new_fb_ptr->width = cm->width; |
| 3565 | new_fb_ptr->height = cm->height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3566 | } |
| 3567 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3568 | void av1_scale_references(AV1_COMP *cpi) { |
| 3569 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3570 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3571 | const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = { |
| 3572 | AOM_LAST_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3573 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3574 | AOM_LAST2_FLAG, |
| 3575 | AOM_LAST3_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3576 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3577 | AOM_GOLD_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3578 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3579 | AOM_BWD_FLAG, |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3580 | AOM_ALT2_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3581 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3582 | AOM_ALT_FLAG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3583 | }; |
| 3584 | |
| 3585 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3586 | // 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] | 3587 | if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 3588 | BufferPool *const pool = cm->buffer_pool; |
| 3589 | const YV12_BUFFER_CONFIG *const ref = |
| 3590 | get_ref_frame_buffer(cpi, ref_frame); |
| 3591 | |
| 3592 | if (ref == NULL) { |
| 3593 | cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3594 | continue; |
| 3595 | } |
| 3596 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3597 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3598 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3599 | RefCntBuffer *new_fb_ptr = NULL; |
| 3600 | int force_scaling = 0; |
| 3601 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3602 | if (new_fb == INVALID_IDX) { |
| 3603 | new_fb = get_free_fb(cm); |
| 3604 | force_scaling = 1; |
| 3605 | } |
| 3606 | if (new_fb == INVALID_IDX) return; |
| 3607 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3608 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3609 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3610 | if (aom_realloc_frame_buffer( |
| 3611 | &new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x, |
| 3612 | cm->subsampling_y, cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 3613 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3614 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3615 | "Failed to allocate frame buffer"); |
Debargha Mukherjee | 405c857 | 2017-07-10 09:29:17 -0700 | [diff] [blame] | 3616 | av1_resize_and_extend_frame(ref, &new_fb_ptr->buf, |
| 3617 | (int)cm->bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3618 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3619 | alloc_frame_mvs(cm, new_fb); |
| 3620 | } |
| 3621 | #else |
| 3622 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3623 | RefCntBuffer *new_fb_ptr = NULL; |
| 3624 | int force_scaling = 0; |
| 3625 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3626 | if (new_fb == INVALID_IDX) { |
| 3627 | new_fb = get_free_fb(cm); |
| 3628 | force_scaling = 1; |
| 3629 | } |
| 3630 | if (new_fb == INVALID_IDX) return; |
| 3631 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3632 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3633 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3634 | 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] | 3635 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3636 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
| 3637 | NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3638 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3639 | "Failed to allocate frame buffer"); |
Debargha Mukherjee | 405c857 | 2017-07-10 09:29:17 -0700 | [diff] [blame] | 3640 | av1_resize_and_extend_frame(ref, &new_fb_ptr->buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3641 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3642 | alloc_frame_mvs(cm, new_fb); |
| 3643 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3644 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3645 | } else { |
| 3646 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3647 | RefCntBuffer *const buf = &pool->frame_bufs[buf_idx]; |
| 3648 | buf->buf.y_crop_width = ref->y_crop_width; |
| 3649 | buf->buf.y_crop_height = ref->y_crop_height; |
| 3650 | cpi->scaled_ref_idx[ref_frame - 1] = buf_idx; |
| 3651 | ++buf->ref_count; |
| 3652 | } |
| 3653 | } else { |
| 3654 | if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3655 | } |
| 3656 | } |
| 3657 | } |
| 3658 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3659 | static void release_scaled_references(AV1_COMP *cpi) { |
| 3660 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3661 | int i; |
| 3662 | if (cpi->oxcf.pass == 0) { |
| 3663 | // Only release scaled references under certain conditions: |
| 3664 | // if reference will be updated, or if scaled reference has same resolution. |
| 3665 | int refresh[INTER_REFS_PER_FRAME]; |
| 3666 | refresh[0] = (cpi->refresh_last_frame) ? 1 : 0; |
| 3667 | #if CONFIG_EXT_REFS |
| 3668 | refresh[1] = refresh[2] = 0; |
| 3669 | refresh[3] = (cpi->refresh_golden_frame) ? 1 : 0; |
| 3670 | refresh[4] = (cpi->refresh_bwd_ref_frame) ? 1 : 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3671 | refresh[5] = (cpi->refresh_alt2_ref_frame) ? 1 : 0; |
| 3672 | refresh[6] = (cpi->refresh_alt_ref_frame) ? 1 : 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 3673 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3674 | refresh[1] = (cpi->refresh_golden_frame) ? 1 : 0; |
| 3675 | refresh[2] = (cpi->refresh_alt_ref_frame) ? 1 : 0; |
| 3676 | #endif // CONFIG_EXT_REFS |
| 3677 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3678 | const int idx = cpi->scaled_ref_idx[i - 1]; |
| 3679 | RefCntBuffer *const buf = |
| 3680 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 3681 | const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, i); |
| 3682 | if (buf != NULL && |
| 3683 | (refresh[i - 1] || (buf->buf.y_crop_width == ref->y_crop_width && |
| 3684 | buf->buf.y_crop_height == ref->y_crop_height))) { |
| 3685 | --buf->ref_count; |
| 3686 | cpi->scaled_ref_idx[i - 1] = INVALID_IDX; |
| 3687 | } |
| 3688 | } |
| 3689 | } else { |
| 3690 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) { |
| 3691 | const int idx = cpi->scaled_ref_idx[i]; |
| 3692 | RefCntBuffer *const buf = |
| 3693 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 3694 | if (buf != NULL) { |
| 3695 | --buf->ref_count; |
| 3696 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 3697 | } |
| 3698 | } |
| 3699 | } |
| 3700 | } |
| 3701 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3702 | #if 0 && CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3703 | static void output_frame_level_debug_stats(AV1_COMP *cpi) { |
| 3704 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3705 | FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); |
| 3706 | int64_t recon_err; |
| 3707 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3708 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3709 | |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3710 | 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] | 3711 | |
| 3712 | if (cpi->twopass.total_left_stats.coded_error != 0.0) |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 3713 | fprintf(f, "%10u %dx%d %d %d %10d %10d %10d %10d" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3714 | "%10"PRId64" %10"PRId64" %5d %5d %10"PRId64" " |
| 3715 | "%10"PRId64" %10"PRId64" %10d " |
| 3716 | "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" |
| 3717 | "%6d %6d %5d %5d %5d " |
| 3718 | "%10"PRId64" %10.3lf" |
| 3719 | "%10lf %8u %10"PRId64" %10d %10d %10d\n", |
| 3720 | cpi->common.current_video_frame, |
| 3721 | cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3722 | cpi->rc.source_alt_ref_pending, |
| 3723 | cpi->rc.source_alt_ref_active, |
| 3724 | cpi->rc.this_frame_target, |
| 3725 | cpi->rc.projected_frame_size, |
| 3726 | cpi->rc.projected_frame_size / cpi->common.MBs, |
| 3727 | (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), |
| 3728 | cpi->rc.vbr_bits_off_target, |
| 3729 | cpi->rc.vbr_bits_off_target_fast, |
| 3730 | cpi->twopass.extend_minq, |
| 3731 | cpi->twopass.extend_minq_fast, |
| 3732 | cpi->rc.total_target_vs_actual, |
| 3733 | (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), |
| 3734 | cpi->rc.total_actual_bits, cm->base_qindex, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3735 | av1_convert_qindex_to_q(cm->base_qindex, cm->bit_depth), |
| 3736 | (double)av1_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0, |
| 3737 | av1_convert_qindex_to_q(cpi->twopass.active_worst_quality, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3738 | cm->bit_depth), |
| 3739 | cpi->rc.avg_q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3740 | av1_convert_qindex_to_q(cpi->oxcf.cq_level, cm->bit_depth), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3741 | cpi->refresh_last_frame, cpi->refresh_golden_frame, |
| 3742 | cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, |
| 3743 | cpi->twopass.bits_left, |
| 3744 | cpi->twopass.total_left_stats.coded_error, |
| 3745 | cpi->twopass.bits_left / |
| 3746 | (1 + cpi->twopass.total_left_stats.coded_error), |
| 3747 | cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost, |
| 3748 | cpi->twopass.kf_zeromotion_pct, |
| 3749 | cpi->twopass.fr_content_type); |
| 3750 | |
| 3751 | fclose(f); |
| 3752 | |
| 3753 | if (0) { |
| 3754 | FILE *const fmodes = fopen("Modes.stt", "a"); |
| 3755 | int i; |
| 3756 | |
| 3757 | fprintf(fmodes, "%6d:%1d:%1d:%1d ", cpi->common.current_video_frame, |
| 3758 | cm->frame_type, cpi->refresh_golden_frame, |
| 3759 | cpi->refresh_alt_ref_frame); |
| 3760 | |
| 3761 | for (i = 0; i < MAX_MODES; ++i) |
| 3762 | fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]); |
| 3763 | |
| 3764 | fprintf(fmodes, "\n"); |
| 3765 | |
| 3766 | fclose(fmodes); |
| 3767 | } |
| 3768 | } |
| 3769 | #endif |
| 3770 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3771 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 3772 | const AV1_COMMON *const cm = &cpi->common; |
| 3773 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3774 | |
| 3775 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3776 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3777 | |
| 3778 | if (cpi->sf.mv.auto_mv_step_size) { |
| 3779 | if (frame_is_intra_only(cm)) { |
| 3780 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 3781 | // after a key/intra-only frame. |
| 3782 | cpi->max_mv_magnitude = max_mv_def; |
| 3783 | } else { |
| 3784 | if (cm->show_frame) { |
| 3785 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 3786 | // in the previous frame, capped by the default max_mv_magnitude based |
| 3787 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3788 | cpi->mv_step_param = av1_init_search_range( |
| 3789 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3790 | } |
| 3791 | cpi->max_mv_magnitude = 0; |
| 3792 | } |
| 3793 | } |
| 3794 | } |
| 3795 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3796 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3797 | #if CONFIG_GLOBAL_MOTION |
| 3798 | int i; |
| 3799 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
Sarah Parker | 4c10a3c | 2017-04-10 19:37:59 -0700 | [diff] [blame] | 3800 | set_default_warp_params(&cpi->common.global_motion[i]); |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3801 | } |
| 3802 | cpi->global_motion_search_done = 0; |
| 3803 | #endif // CONFIG_GLOBAL_MOTION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3804 | av1_set_speed_features_framesize_independent(cpi); |
| 3805 | av1_set_rd_speed_thresholds(cpi); |
| 3806 | av1_set_rd_speed_thresholds_sub8x8(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3807 | cpi->common.interp_filter = cpi->sf.default_interp_filter; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3808 | #if CONFIG_EXT_INTER |
| 3809 | if (!frame_is_intra_only(&cpi->common)) set_compound_tools(&cpi->common); |
| 3810 | #endif // CONFIG_EXT_INTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3811 | } |
| 3812 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3813 | 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] | 3814 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3815 | AV1_COMMON *const cm = &cpi->common; |
| 3816 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3817 | |
| 3818 | // Setup variables that depend on the dimensions of the frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3819 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3820 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 3821 | // Decide q and q bounds. |
| 3822 | #if CONFIG_XIPHRC |
| 3823 | int frame_type = cm->frame_type == KEY_FRAME ? OD_I_FRAME : OD_P_FRAME; |
| 3824 | *q = od_enc_rc_select_quantizers_and_lambdas( |
| 3825 | &cpi->od_rc, cpi->refresh_golden_frame, cpi->refresh_alt_ref_frame, |
| 3826 | frame_type, bottom_index, top_index); |
| 3827 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3828 | *q = av1_rc_pick_q_and_bounds(cpi, bottom_index, top_index); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 3829 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3830 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 3831 | if (!frame_is_intra_only(cm)) { |
| 3832 | av1_set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH); |
| 3833 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3834 | |
| 3835 | // Configure experimental use of segmentation for enhanced coding of |
| 3836 | // static regions if indicated. |
| 3837 | // Only allowed in the second pass of a two pass encode, as it requires |
| 3838 | // lagged coding, and if the relevant speed feature flag is set. |
| 3839 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 3840 | configure_static_seg_features(cpi); |
| 3841 | } |
| 3842 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3843 | static void init_motion_estimation(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3844 | int y_stride = cpi->scaled_source.y_stride; |
| 3845 | |
| 3846 | if (cpi->sf.mv.search_method == NSTEP) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3847 | av1_init3smotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3848 | } else if (cpi->sf.mv.search_method == DIAMOND) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3849 | av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3850 | } |
| 3851 | } |
| 3852 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3853 | #if CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3854 | #define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0 |
| 3855 | 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] | 3856 | RestorationInfo *rst) { |
| 3857 | (void)width; |
| 3858 | (void)height; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3859 | (void)sx; |
| 3860 | (void)sy; |
| 3861 | #if COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3862 | int s = AOMMIN(sx, sy); |
| 3863 | #else |
| 3864 | int s = 0; |
| 3865 | #endif // !COUPLED_CHROMA_FROM_LUMA_RESTORATION |
| 3866 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3867 | rst[0].restoration_tilesize = (RESTORATION_TILESIZE_MAX >> 1); |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3868 | rst[1].restoration_tilesize = rst[0].restoration_tilesize >> s; |
| 3869 | rst[2].restoration_tilesize = rst[1].restoration_tilesize; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3870 | } |
| 3871 | #endif // CONFIG_LOOP_RESTORATION |
| 3872 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3873 | static void set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3874 | AV1_COMMON *const cm = &cpi->common; |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3875 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3876 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3877 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3878 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 3879 | // There has been a change in the encoded frame size |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3880 | av1_set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3881 | set_mv_search_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3882 | } |
| 3883 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 3884 | #if !CONFIG_XIPHRC |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3885 | if (cpi->oxcf.pass == 2) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3886 | av1_set_target_rate(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3887 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 3888 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3889 | |
| 3890 | alloc_frame_mvs(cm, cm->new_fb_idx); |
| 3891 | |
| 3892 | // Reset the frame pointers to the current frame size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3893 | 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] | 3894 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3895 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3896 | cm->use_highbitdepth, |
| 3897 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3898 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 3899 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3900 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3901 | "Failed to allocate frame buffer"); |
| 3902 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3903 | #if CONFIG_LOOP_RESTORATION |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 3904 | set_restoration_tilesize( |
| 3905 | #if CONFIG_FRAME_SUPERRES |
| 3906 | cm->superres_upscaled_width, cm->superres_upscaled_height, |
| 3907 | #else |
| 3908 | cm->width, cm->height, |
| 3909 | #endif // CONFIG_FRAME_SUPERRES |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 3910 | cm->subsampling_x, cm->subsampling_y, cm->rst_info); |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3911 | for (int i = 0; i < MAX_MB_PLANE; ++i) |
| 3912 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
| 3913 | av1_alloc_restoration_buffers(cm); |
| 3914 | for (int i = 0; i < MAX_MB_PLANE; ++i) { |
| 3915 | cpi->rst_search[i].restoration_tilesize = |
| 3916 | cm->rst_info[i].restoration_tilesize; |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 3917 | av1_alloc_restoration_struct(cm, &cpi->rst_search[i], |
| 3918 | #if CONFIG_FRAME_SUPERRES |
| 3919 | cm->superres_upscaled_width, |
| 3920 | cm->superres_upscaled_height); |
| 3921 | #else |
| 3922 | cm->width, cm->height); |
| 3923 | #endif // CONFIG_FRAME_SUPERRES |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3924 | } |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 3925 | #endif // CONFIG_LOOP_RESTORATION |
| 3926 | alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3927 | init_motion_estimation(cpi); |
| 3928 | |
| 3929 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3930 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 3931 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3932 | |
| 3933 | ref_buf->idx = buf_idx; |
| 3934 | |
| 3935 | if (buf_idx != INVALID_IDX) { |
| 3936 | YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf; |
| 3937 | ref_buf->buf = buf; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3938 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3939 | av1_setup_scale_factors_for_frame( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3940 | &ref_buf->sf, buf->y_crop_width, buf->y_crop_height, cm->width, |
| 3941 | cm->height, (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0); |
| 3942 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3943 | av1_setup_scale_factors_for_frame(&ref_buf->sf, buf->y_crop_width, |
| 3944 | buf->y_crop_height, cm->width, |
| 3945 | cm->height); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3946 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3947 | if (av1_is_scaled(&ref_buf->sf)) aom_extend_frame_borders(buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3948 | } else { |
| 3949 | ref_buf->buf = NULL; |
| 3950 | } |
| 3951 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 3952 | |
| 3953 | #if CONFIG_VAR_REFS |
| 3954 | // Check duplicate reference frames |
| 3955 | enc_check_valid_ref_frames(cpi); |
| 3956 | #endif // CONFIG_VAR_REFS |
| 3957 | |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 3958 | #if CONFIG_INTRABC |
| 3959 | #if CONFIG_HIGHBITDEPTH |
Sebastien Alaiwan | 1dcb707 | 2017-05-12 11:13:05 +0200 | [diff] [blame] | 3960 | av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height, |
| 3961 | cm->width, cm->height, |
| 3962 | cm->use_highbitdepth); |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 3963 | #else |
| 3964 | av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height, |
| 3965 | cm->width, cm->height); |
| 3966 | #endif // CONFIG_HIGHBITDEPTH |
| 3967 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3968 | |
| 3969 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 3970 | } |
| 3971 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3972 | static void setup_frame_size(AV1_COMP *cpi) { |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 3973 | int encode_width = cpi->oxcf.width; |
| 3974 | int encode_height = cpi->oxcf.height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3975 | |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 3976 | uint8_t resize_num = av1_calculate_next_resize_scale(cpi); |
Fergus Simpson | bfbf6a5 | 2017-06-14 23:13:12 -0700 | [diff] [blame] | 3977 | av1_calculate_scaled_size(&encode_width, &encode_height, resize_num); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3978 | |
| 3979 | #if CONFIG_FRAME_SUPERRES |
| 3980 | AV1_COMMON *cm = &cpi->common; |
| 3981 | cm->superres_upscaled_width = encode_width; |
| 3982 | cm->superres_upscaled_height = encode_height; |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 3983 | cm->superres_scale_numerator = |
Urvang Joshi | 0b90540 | 2017-08-02 10:56:23 -0700 | [diff] [blame] | 3984 | av1_calculate_next_superres_scale(cpi, encode_width, encode_height); |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 3985 | av1_calculate_scaled_size(&encode_width, &encode_height, |
Fergus Simpson | bfbf6a5 | 2017-06-14 23:13:12 -0700 | [diff] [blame] | 3986 | cm->superres_scale_numerator); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3987 | #endif // CONFIG_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3988 | |
| 3989 | set_frame_size(cpi, encode_width, encode_height); |
| 3990 | } |
| 3991 | |
| 3992 | #if CONFIG_FRAME_SUPERRES |
| 3993 | static void superres_post_encode(AV1_COMP *cpi) { |
| 3994 | AV1_COMMON *cm = &cpi->common; |
| 3995 | |
| 3996 | if (av1_superres_unscaled(cm)) return; |
| 3997 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3998 | av1_superres_upscale(cm, NULL); |
| 3999 | |
| 4000 | // If regular resizing is occurring the source will need to be downscaled to |
| 4001 | // match the upscaled superres resolution. Otherwise the original source is |
| 4002 | // used. |
| 4003 | if (av1_resize_unscaled(cm)) { |
| 4004 | cpi->source = cpi->unscaled_source; |
| 4005 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 4006 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 4007 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 4008 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4009 | // Do downscale. cm->(width|height) has been updated by av1_superres_upscale |
| 4010 | if (aom_realloc_frame_buffer( |
| 4011 | &cpi->scaled_source, cm->superres_upscaled_width, |
| 4012 | cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y, |
| 4013 | #if CONFIG_HIGHBITDEPTH |
| 4014 | cm->use_highbitdepth, |
| 4015 | #endif // CONFIG_HIGHBITDEPTH |
| 4016 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
| 4017 | aom_internal_error( |
| 4018 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 4019 | "Failed to reallocate scaled source buffer for superres"); |
| 4020 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 4021 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
| 4022 | #if CONFIG_HIGHBITDEPTH |
| 4023 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
| 4024 | (int)cm->bit_depth); |
| 4025 | #else |
| 4026 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source); |
| 4027 | #endif // CONFIG_HIGHBITDEPTH |
| 4028 | cpi->source = &cpi->scaled_source; |
| 4029 | } |
| 4030 | } |
| 4031 | #endif // CONFIG_FRAME_SUPERRES |
| 4032 | |
| 4033 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
| 4034 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
| 4035 | struct loopfilter *lf = &cm->lf; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4036 | int no_loopfilter = 0; |
| 4037 | |
| 4038 | if (is_lossless_requested(&cpi->oxcf)) no_loopfilter = 1; |
| 4039 | |
| 4040 | #if CONFIG_EXT_TILE |
| 4041 | // 0 loopfilter level is only necessary if individual tile |
| 4042 | // decoding is required. |
| 4043 | if (cm->single_tile_decoding) no_loopfilter = 1; |
| 4044 | #endif // CONFIG_EXT_TILE |
| 4045 | |
| 4046 | if (no_loopfilter) { |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4047 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4048 | lf->filter_level[0] = 0; |
| 4049 | lf->filter_level[1] = 0; |
| 4050 | #else |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4051 | lf->filter_level = 0; |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4052 | #endif |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4053 | } else { |
| 4054 | struct aom_usec_timer timer; |
| 4055 | |
| 4056 | aom_clear_system_state(); |
| 4057 | |
| 4058 | aom_usec_timer_start(&timer); |
| 4059 | |
| 4060 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
| 4061 | |
| 4062 | aom_usec_timer_mark(&timer); |
| 4063 | cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer); |
| 4064 | } |
| 4065 | |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4066 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4067 | if (lf->filter_level[0] || lf->filter_level[1]) |
| 4068 | #else |
| 4069 | if (lf->filter_level > 0) |
| 4070 | #endif |
| 4071 | { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4072 | #if CONFIG_VAR_TX || CONFIG_EXT_PARTITION || CONFIG_CB4X4 |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4073 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 4074 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level[0], |
| 4075 | lf->filter_level[1], 0, 0); |
| 4076 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_u, |
| 4077 | lf->filter_level_u, 1, 0); |
| 4078 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_v, |
| 4079 | lf->filter_level_v, 2, 0); |
| 4080 | |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 4081 | #else |
| 4082 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0); |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 4083 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4084 | #else |
| 4085 | if (cpi->num_workers > 1) |
| 4086 | av1_loop_filter_frame_mt(cm->frame_to_show, cm, xd->plane, |
| 4087 | lf->filter_level, 0, 0, cpi->workers, |
| 4088 | cpi->num_workers, &cpi->lf_row_sync); |
| 4089 | else |
| 4090 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0); |
| 4091 | #endif |
| 4092 | } |
| 4093 | #if CONFIG_CDEF |
| 4094 | if (is_lossless_requested(&cpi->oxcf)) { |
| 4095 | cm->cdef_bits = 0; |
| 4096 | cm->cdef_strengths[0] = 0; |
| 4097 | cm->nb_cdef_strengths = 1; |
| 4098 | } else { |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 4099 | // Find CDEF parameters |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4100 | av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd, |
| 4101 | cpi->oxcf.speed > 0); |
| 4102 | |
| 4103 | // Apply the filter |
| 4104 | av1_cdef_frame(cm->frame_to_show, cm, xd); |
| 4105 | } |
| 4106 | #endif |
| 4107 | |
| 4108 | #if CONFIG_FRAME_SUPERRES |
| 4109 | superres_post_encode(cpi); |
| 4110 | #endif // CONFIG_FRAME_SUPERRES |
| 4111 | |
| 4112 | #if CONFIG_LOOP_RESTORATION |
| 4113 | av1_pick_filter_restoration(cpi->source, cpi, cpi->sf.lpf_pick); |
| 4114 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 4115 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 4116 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
| 4117 | av1_loop_restoration_frame(cm->frame_to_show, cm, cm->rst_info, 7, 0, NULL); |
| 4118 | } |
| 4119 | #endif // CONFIG_LOOP_RESTORATION |
| 4120 | // TODO(debargha): Fix mv search range on encoder side |
| 4121 | // aom_extend_frame_inner_borders(cm->frame_to_show); |
| 4122 | aom_extend_frame_borders(cm->frame_to_show); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4123 | } |
| 4124 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4125 | static void encode_without_recode_loop(AV1_COMP *cpi) { |
| 4126 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4127 | int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4128 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4129 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4130 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4131 | set_size_independent_vars(cpi); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4132 | setup_frame_size(cpi); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4133 | assert(cm->width == cpi->scaled_source.y_crop_width); |
| 4134 | assert(cm->height == cpi->scaled_source.y_crop_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 4135 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4136 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4137 | |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4138 | cpi->source = |
| 4139 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
| 4140 | if (cpi->unscaled_last_source != NULL) |
| 4141 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4142 | &cpi->scaled_last_source); |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4143 | #if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION |
| 4144 | cpi->source->buf_8bit_valid = 0; |
| 4145 | #endif |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 4146 | |
| 4147 | if (frame_is_intra_only(cm) == 0) { |
| 4148 | av1_scale_references(cpi); |
| 4149 | } |
| 4150 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4151 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4152 | setup_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4153 | suppress_active_map(cpi); |
hui su | ed5a30f | 2017-04-27 16:02:49 -0700 | [diff] [blame] | 4154 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4155 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4156 | // exclusive. |
| 4157 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4158 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4159 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4160 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4161 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4162 | av1_cyclic_refresh_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4163 | } |
| 4164 | apply_active_map(cpi); |
| 4165 | |
| 4166 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4167 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4168 | |
| 4169 | // Update some stats from cyclic refresh, and check if we should not update |
| 4170 | // golden reference, for 1 pass CBR. |
| 4171 | 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] | 4172 | (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR)) |
| 4173 | av1_cyclic_refresh_check_golden_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4174 | |
| 4175 | // Update the skip mb flag probabilities based on the distribution |
| 4176 | // seen in the last encoder iteration. |
| 4177 | // update_base_skip_probs(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4178 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4179 | } |
| 4180 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4181 | static void encode_with_recode_loop(AV1_COMP *cpi, size_t *size, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4182 | uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4183 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4184 | RATE_CONTROL *const rc = &cpi->rc; |
| 4185 | int bottom_index, top_index; |
| 4186 | int loop_count = 0; |
| 4187 | int loop_at_this_size = 0; |
| 4188 | int loop = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4189 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4190 | int overshoot_seen = 0; |
| 4191 | int undershoot_seen = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4192 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4193 | int frame_over_shoot_limit; |
| 4194 | int frame_under_shoot_limit; |
| 4195 | int q = 0, q_low = 0, q_high = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4196 | |
| 4197 | set_size_independent_vars(cpi); |
| 4198 | |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 4199 | #if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION |
| 4200 | cpi->source->buf_8bit_valid = 0; |
| 4201 | #endif |
| 4202 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4203 | do { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4204 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4205 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4206 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4207 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4208 | if (loop_count == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4209 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4210 | |
| 4211 | // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. |
| 4212 | set_mv_search_params(cpi); |
| 4213 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4214 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4215 | // Reset the loop state for new frame size. |
| 4216 | overshoot_seen = 0; |
| 4217 | undershoot_seen = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4218 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4219 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4220 | q_low = bottom_index; |
| 4221 | q_high = top_index; |
| 4222 | |
| 4223 | loop_at_this_size = 0; |
| 4224 | } |
| 4225 | |
| 4226 | // Decide frame size bounds first time through. |
| 4227 | if (loop_count == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4228 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4229 | &frame_under_shoot_limit, |
| 4230 | &frame_over_shoot_limit); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4231 | } |
| 4232 | |
Debargha Mukherjee | 17e7b08 | 2017-08-13 09:33:03 -0700 | [diff] [blame] | 4233 | cpi->source = |
| 4234 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
| 4235 | #if CONFIG_GLOBAL_MOTION |
| 4236 | // if frame was scaled calculate global_motion_search again if already done |
| 4237 | if (cpi->source != cpi->unscaled_source) cpi->global_motion_search_done = 0; |
| 4238 | #endif // CONFIG_GLOBAL_MOTION |
| 4239 | if (cpi->unscaled_last_source != NULL) |
| 4240 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
| 4241 | &cpi->scaled_last_source); |
| 4242 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4243 | if (frame_is_intra_only(cm) == 0) { |
| 4244 | if (loop_count > 0) { |
| 4245 | release_scaled_references(cpi); |
| 4246 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4247 | av1_scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4248 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4249 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4250 | |
| 4251 | if (loop_count == 0) setup_frame(cpi); |
| 4252 | |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 4253 | #if CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4254 | // Base q-index may have changed, so we need to assign proper default coef |
| 4255 | // probs before every iteration. |
| 4256 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
| 4257 | int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4258 | av1_default_coef_probs(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4259 | if (cm->frame_type == KEY_FRAME || cm->error_resilient_mode || |
| 4260 | cm->reset_frame_context == RESET_FRAME_CONTEXT_ALL) { |
| 4261 | for (i = 0; i < FRAME_CONTEXTS; ++i) cm->frame_contexts[i] = *cm->fc; |
| 4262 | } else if (cm->reset_frame_context == RESET_FRAME_CONTEXT_CURRENT) { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 4263 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 4264 | if (cm->frame_refs[0].idx >= 0) { |
| 4265 | cm->frame_contexts[cm->frame_refs[0].idx] = *cm->fc; |
| 4266 | } |
| 4267 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4268 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 4269 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4270 | } |
| 4271 | } |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 4272 | #endif // CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4273 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4274 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4275 | // exclusive. |
| 4276 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4277 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4278 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4279 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4280 | } |
| 4281 | |
| 4282 | // transform / motion compensation build reconstruction frame |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4283 | save_coding_context(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4284 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4285 | |
| 4286 | // Update the skip mb flag probabilities based on the distribution |
| 4287 | // seen in the last encoder iteration. |
| 4288 | // update_base_skip_probs(cpi); |
| 4289 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4290 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4291 | |
| 4292 | // Dummy pack of the bitstream using up to date stats to get an |
| 4293 | // accurate estimate of output frame size to determine if we need |
| 4294 | // to recode. |
| 4295 | if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4296 | restore_coding_context(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4297 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4298 | |
| 4299 | rc->projected_frame_size = (int)(*size) << 3; |
| 4300 | restore_coding_context(cpi); |
| 4301 | |
| 4302 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4303 | } |
| 4304 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4305 | if (cpi->oxcf.rc_mode == AOM_Q) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4306 | loop = 0; |
| 4307 | } else { |
| 4308 | if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced && |
| 4309 | (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
| 4310 | int last_q = q; |
| 4311 | int64_t kf_err; |
| 4312 | |
| 4313 | int64_t high_err_target = cpi->ambient_err; |
| 4314 | int64_t low_err_target = cpi->ambient_err >> 1; |
| 4315 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4316 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4317 | if (cm->use_highbitdepth) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4318 | 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] | 4319 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4320 | 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] | 4321 | } |
| 4322 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4323 | 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] | 4324 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4325 | |
| 4326 | // Prevent possible divide by zero error below for perfect KF |
| 4327 | kf_err += !kf_err; |
| 4328 | |
| 4329 | // The key frame is not good enough or we can afford |
| 4330 | // to make it better without undue risk of popping. |
| 4331 | if ((kf_err > high_err_target && |
| 4332 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4333 | (kf_err > low_err_target && |
| 4334 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4335 | // Lower q_high |
| 4336 | q_high = q > q_low ? q - 1 : q_low; |
| 4337 | |
| 4338 | // Adjust Q |
| 4339 | q = (int)((q * high_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4340 | q = AOMMIN(q, (q_high + q_low) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4341 | } else if (kf_err < low_err_target && |
| 4342 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4343 | // The key frame is much better than the previous frame |
| 4344 | // Raise q_low |
| 4345 | q_low = q < q_high ? q + 1 : q_high; |
| 4346 | |
| 4347 | // Adjust Q |
| 4348 | q = (int)((q * low_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4349 | q = AOMMIN(q, (q_high + q_low + 1) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | // Clamp Q to upper and lower limits: |
| 4353 | q = clamp(q, q_low, q_high); |
| 4354 | |
| 4355 | loop = q != last_q; |
| 4356 | } else if (recode_loop_test(cpi, frame_over_shoot_limit, |
| 4357 | frame_under_shoot_limit, q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4358 | AOMMAX(q_high, top_index), bottom_index)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4359 | // Is the projected frame size out of range and are we allowed |
| 4360 | // to attempt to recode. |
| 4361 | int last_q = q; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4362 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4363 | int retries = 0; |
| 4364 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4365 | // Frame size out of permitted range: |
| 4366 | // Update correction factor & compute new Q to try... |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4367 | // Frame is too large |
| 4368 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 4369 | // Special case if the projected size is > the max allowed. |
| 4370 | if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
| 4371 | q_high = rc->worst_quality; |
| 4372 | |
| 4373 | // Raise Qlow as to at least the current value |
| 4374 | q_low = q < q_high ? q + 1 : q_high; |
| 4375 | |
| 4376 | if (undershoot_seen || loop_at_this_size > 1) { |
| 4377 | // Update rate_correction_factor unless |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4378 | av1_rc_update_rate_correction_factors(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4379 | |
| 4380 | q = (q_high + q_low + 1) / 2; |
| 4381 | } else { |
| 4382 | // Update rate_correction_factor unless |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4383 | av1_rc_update_rate_correction_factors(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4384 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4385 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4386 | AOMMAX(q_high, top_index)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4387 | |
| 4388 | while (q < q_low && retries < 10) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4389 | av1_rc_update_rate_correction_factors(cpi); |
| 4390 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4391 | AOMMAX(q_high, top_index)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4392 | retries++; |
| 4393 | } |
| 4394 | } |
| 4395 | |
| 4396 | overshoot_seen = 1; |
| 4397 | } else { |
| 4398 | // Frame is too small |
| 4399 | q_high = q > q_low ? q - 1 : q_low; |
| 4400 | |
| 4401 | if (overshoot_seen || loop_at_this_size > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4402 | av1_rc_update_rate_correction_factors(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4403 | q = (q_high + q_low) / 2; |
| 4404 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4405 | av1_rc_update_rate_correction_factors(cpi); |
| 4406 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4407 | top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4408 | // Special case reset for qlow for constrained quality. |
| 4409 | // This should only trigger where there is very substantial |
| 4410 | // undershoot on a frame and the auto cq level is above |
| 4411 | // the user passsed in value. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4412 | if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4413 | q_low = q; |
| 4414 | } |
| 4415 | |
| 4416 | while (q > q_high && retries < 10) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4417 | av1_rc_update_rate_correction_factors(cpi); |
| 4418 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4419 | top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4420 | retries++; |
| 4421 | } |
| 4422 | } |
| 4423 | |
| 4424 | undershoot_seen = 1; |
| 4425 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4426 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4427 | |
| 4428 | // Clamp Q to upper and lower limits: |
| 4429 | q = clamp(q, q_low, q_high); |
| 4430 | |
| 4431 | loop = (q != last_q); |
| 4432 | } else { |
| 4433 | loop = 0; |
| 4434 | } |
| 4435 | } |
| 4436 | |
| 4437 | // Special case for overlay frame. |
| 4438 | if (rc->is_src_frame_alt_ref && |
| 4439 | rc->projected_frame_size < rc->max_frame_bandwidth) |
| 4440 | loop = 0; |
| 4441 | |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4442 | #if CONFIG_GLOBAL_MOTION |
| 4443 | if (recode_loop_test_global_motion(cpi)) { |
| 4444 | loop = 1; |
| 4445 | } |
| 4446 | #endif // CONFIG_GLOBAL_MOTION |
| 4447 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4448 | if (loop) { |
| 4449 | ++loop_count; |
| 4450 | ++loop_at_this_size; |
| 4451 | |
| 4452 | #if CONFIG_INTERNAL_STATS |
| 4453 | ++cpi->tot_recode_hits; |
| 4454 | #endif |
| 4455 | } |
| 4456 | } while (loop); |
| 4457 | } |
| 4458 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4459 | static int get_ref_frame_flags(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4460 | const int *const map = cpi->common.ref_frame_map; |
| 4461 | |
| 4462 | #if CONFIG_EXT_REFS |
| 4463 | const int last2_is_last = |
| 4464 | map[cpi->lst_fb_idxes[1]] == map[cpi->lst_fb_idxes[0]]; |
| 4465 | const int last3_is_last = |
| 4466 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[0]]; |
| 4467 | 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] | 4468 | #if CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 4469 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4470 | const int last3_is_last2 = |
| 4471 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]]; |
| 4472 | const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4473 | 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] | 4474 | #else // !CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4475 | const int bwd_is_last = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4476 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4477 | |
| 4478 | const int last3_is_last2 = |
| 4479 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]]; |
| 4480 | const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4481 | const int bwd_is_last2 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4482 | |
| 4483 | const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 4484 | const int bwd_is_last3 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 4485 | |
| 4486 | 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] | 4487 | #endif // CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4488 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4489 | const int alt2_is_last = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4490 | const int alt2_is_last2 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4491 | const int alt2_is_last3 = map[cpi->alt2_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 4492 | const int alt2_is_gld = map[cpi->alt2_fb_idx] == map[cpi->gld_fb_idx]; |
| 4493 | const int alt2_is_bwd = map[cpi->alt2_fb_idx] == map[cpi->bwd_fb_idx]; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4494 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4495 | const int last2_is_alt = map[cpi->lst_fb_idxes[1]] == map[cpi->alt_fb_idx]; |
| 4496 | const int last3_is_alt = map[cpi->lst_fb_idxes[2]] == map[cpi->alt_fb_idx]; |
| 4497 | const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 4498 | 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] | 4499 | const int alt2_is_alt = map[cpi->alt2_fb_idx] == map[cpi->alt_fb_idx]; |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 4500 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4501 | const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx]; |
| 4502 | const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 4503 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx]; |
| 4504 | #endif // CONFIG_EXT_REFS |
| 4505 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4506 | int flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4507 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4508 | if (gld_is_last || gld_is_alt) flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4509 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4510 | 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] | 4511 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4512 | if (alt_is_last) flags &= ~AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4513 | |
| 4514 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4515 | if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4516 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4517 | 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] | 4518 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4519 | if (gld_is_last2 || gld_is_last3) flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4520 | |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4521 | #if CONFIG_ONE_SIDED_COMPOUND && \ |
| 4522 | !CONFIG_EXT_COMP_REFS // Changes LL & HL bitstream |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 4523 | /* Allow biprediction between two identical frames (e.g. bwd_is_last = 1) */ |
| 4524 | if (bwd_is_alt && (flags & AOM_BWD_FLAG)) flags &= ~AOM_BWD_FLAG; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4525 | #else // !CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4526 | if ((bwd_is_last || bwd_is_last2 || bwd_is_last3 || bwd_is_gld || |
| 4527 | bwd_is_alt) && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4528 | (flags & AOM_BWD_FLAG)) |
| 4529 | flags &= ~AOM_BWD_FLAG; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 4530 | #endif // CONFIG_ONE_SIDED_COMPOUND && !CONFIG_EXT_COMP_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4531 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4532 | if ((alt2_is_last || alt2_is_last2 || alt2_is_last3 || alt2_is_gld || |
| 4533 | alt2_is_bwd || alt2_is_alt) && |
| 4534 | (flags & AOM_ALT2_FLAG)) |
| 4535 | flags &= ~AOM_ALT2_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4536 | #endif // CONFIG_EXT_REFS |
| 4537 | |
| 4538 | return flags; |
| 4539 | } |
| 4540 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4541 | static void set_ext_overrides(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4542 | // Overrides the defaults with the externally supplied values with |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4543 | // av1_update_reference() and av1_update_entropy() calls |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4544 | // Note: The overrides are valid only for the next frame passed |
| 4545 | // to encode_frame_to_data_rate() function |
| 4546 | if (cpi->ext_refresh_frame_context_pending) { |
| 4547 | cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context; |
| 4548 | cpi->ext_refresh_frame_context_pending = 0; |
| 4549 | } |
| 4550 | if (cpi->ext_refresh_frame_flags_pending) { |
| 4551 | cpi->refresh_last_frame = cpi->ext_refresh_last_frame; |
| 4552 | cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame; |
| 4553 | cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; |
| 4554 | cpi->ext_refresh_frame_flags_pending = 0; |
| 4555 | } |
| 4556 | } |
| 4557 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4558 | static void set_arf_sign_bias(AV1_COMP *cpi) { |
| 4559 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4560 | int arf_sign_bias; |
| 4561 | #if CONFIG_EXT_REFS |
| 4562 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 4563 | // The arf_sign_bias will be one for internal ARFs' |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4564 | arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 4565 | (!cpi->refresh_alt_ref_frame || |
| 4566 | gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4567 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4568 | if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { |
| 4569 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 4570 | arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 4571 | (!cpi->refresh_alt_ref_frame || |
| 4572 | (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)); |
| 4573 | } else { |
| 4574 | arf_sign_bias = |
| 4575 | (cpi->rc.source_alt_ref_active && !cpi->refresh_alt_ref_frame); |
| 4576 | } |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 4577 | #endif // CONFIG_EXT_REFS |
| 4578 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4579 | cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; |
| 4580 | #if CONFIG_EXT_REFS |
| 4581 | 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] | 4582 | cm->ref_frame_sign_bias[ALTREF2_FRAME] = |
| 4583 | cm->ref_frame_sign_bias[ALTREF_FRAME]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4584 | #endif // CONFIG_EXT_REFS |
| 4585 | } |
| 4586 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4587 | static int setup_interp_filter_search_mask(AV1_COMP *cpi) { |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 4588 | InterpFilter ifilter; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4589 | int ref_total[TOTAL_REFS_PER_FRAME] = { 0 }; |
| 4590 | MV_REFERENCE_FRAME ref; |
| 4591 | int mask = 0; |
| 4592 | int arf_idx = ALTREF_FRAME; |
| 4593 | |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 4594 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4595 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame || |
| 4596 | cpi->refresh_alt2_ref_frame) |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 4597 | #else // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4598 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame) |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 4599 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4600 | return mask; |
| 4601 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4602 | for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) |
| 4603 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) |
| 4604 | ref_total[ref] += cpi->interp_filter_selected[ref][ifilter]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4605 | |
| 4606 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) { |
| 4607 | if ((ref_total[LAST_FRAME] && |
| 4608 | cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) && |
| 4609 | #if CONFIG_EXT_REFS |
| 4610 | (ref_total[LAST2_FRAME] == 0 || |
| 4611 | cpi->interp_filter_selected[LAST2_FRAME][ifilter] * 50 < |
| 4612 | ref_total[LAST2_FRAME]) && |
| 4613 | (ref_total[LAST3_FRAME] == 0 || |
| 4614 | cpi->interp_filter_selected[LAST3_FRAME][ifilter] * 50 < |
| 4615 | ref_total[LAST3_FRAME]) && |
| 4616 | #endif // CONFIG_EXT_REFS |
| 4617 | (ref_total[GOLDEN_FRAME] == 0 || |
| 4618 | cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50 < |
| 4619 | ref_total[GOLDEN_FRAME]) && |
| 4620 | #if CONFIG_EXT_REFS |
| 4621 | (ref_total[BWDREF_FRAME] == 0 || |
| 4622 | cpi->interp_filter_selected[BWDREF_FRAME][ifilter] * 50 < |
| 4623 | ref_total[BWDREF_FRAME]) && |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4624 | (ref_total[ALTREF2_FRAME] == 0 || |
| 4625 | cpi->interp_filter_selected[ALTREF2_FRAME][ifilter] * 50 < |
| 4626 | ref_total[ALTREF2_FRAME]) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4627 | #endif // CONFIG_EXT_REFS |
| 4628 | (ref_total[ALTREF_FRAME] == 0 || |
| 4629 | cpi->interp_filter_selected[arf_idx][ifilter] * 50 < |
| 4630 | ref_total[ALTREF_FRAME])) |
| 4631 | mask |= 1 << ifilter; |
| 4632 | } |
| 4633 | return mask; |
| 4634 | } |
| 4635 | |
| 4636 | #define DUMP_RECON_FRAMES 0 |
| 4637 | |
| 4638 | #if DUMP_RECON_FRAMES == 1 |
| 4639 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4640 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 4641 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4642 | const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show; |
| 4643 | int h; |
| 4644 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 4645 | FILE *f_recon = NULL; |
| 4646 | |
| 4647 | if (recon_buf == NULL || !cm->show_frame) { |
| 4648 | printf("Frame %d is not ready or no show to dump.\n", |
| 4649 | cm->current_video_frame); |
| 4650 | return; |
| 4651 | } |
| 4652 | |
| 4653 | if (cm->current_video_frame == 0) { |
| 4654 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 4655 | printf("Unable to open file %s to write.\n", file_name); |
| 4656 | return; |
| 4657 | } |
| 4658 | } else { |
| 4659 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 4660 | printf("Unable to open file %s to append.\n", file_name); |
| 4661 | return; |
| 4662 | } |
| 4663 | } |
| 4664 | printf( |
| 4665 | "\nFrame=%5d, encode_update_type[%5d]=%1d, show_existing_frame=%d, " |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 4666 | "source_alt_ref_active=%d, refresh_alt_ref_frame=%d, rf_level=%d, " |
| 4667 | "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] | 4668 | cm->current_video_frame, cpi->twopass.gf_group.index, |
| 4669 | cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 4670 | cm->show_existing_frame, cpi->rc.source_alt_ref_active, |
| 4671 | cpi->refresh_alt_ref_frame, |
| 4672 | cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index], |
| 4673 | recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4674 | #if 0 |
| 4675 | int ref_frame; |
| 4676 | printf("get_ref_frame_map_idx: ["); |
| 4677 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) |
| 4678 | printf(" %d", get_ref_frame_map_idx(cpi, ref_frame)); |
| 4679 | printf(" ]\n"); |
| 4680 | printf("cm->new_fb_idx = %d\n", cm->new_fb_idx); |
| 4681 | printf("cm->ref_frame_map = ["); |
| 4682 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 4683 | printf(" %d", cm->ref_frame_map[ref_frame - LAST_FRAME]); |
| 4684 | } |
| 4685 | printf(" ]\n"); |
| 4686 | #endif // 0 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4687 | |
| 4688 | // --- Y --- |
| 4689 | for (h = 0; h < cm->height; ++h) { |
| 4690 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 4691 | f_recon); |
| 4692 | } |
| 4693 | // --- U --- |
| 4694 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4695 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4696 | f_recon); |
| 4697 | } |
| 4698 | // --- V --- |
| 4699 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4700 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4701 | f_recon); |
| 4702 | } |
| 4703 | |
| 4704 | fclose(f_recon); |
| 4705 | } |
| 4706 | #endif // DUMP_RECON_FRAMES |
| 4707 | |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 4708 | static void make_update_tile_list_enc(AV1_COMP *cpi, const int tile_rows, |
| 4709 | const int tile_cols, |
| 4710 | FRAME_CONTEXT *ec_ctxs[]) { |
| 4711 | int i; |
| 4712 | for (i = 0; i < tile_rows * tile_cols; ++i) |
| 4713 | ec_ctxs[i] = &cpi->tile_data[i].tctx; |
| 4714 | } |
| 4715 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4716 | 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] | 4717 | uint8_t *dest, int skip_adapt, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4718 | unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4719 | AV1_COMMON *const cm = &cpi->common; |
| 4720 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4721 | struct segmentation *const seg = &cm->seg; |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 4722 | FRAME_CONTEXT **tile_ctxs = aom_malloc(cm->tile_rows * cm->tile_cols * |
| 4723 | sizeof(&cpi->tile_data[0].tctx)); |
| 4724 | aom_cdf_prob **cdf_ptrs = |
| 4725 | aom_malloc(cm->tile_rows * cm->tile_cols * |
| 4726 | sizeof(&cpi->tile_data[0].tctx.partition_cdf[0][0])); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4727 | #if CONFIG_XIPHRC |
| 4728 | int frame_type; |
| 4729 | int drop_this_frame = 0; |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 4730 | #endif // CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4731 | set_ext_overrides(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4732 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4733 | |
| 4734 | // Set the arf sign bias for this frame. |
| 4735 | set_arf_sign_bias(cpi); |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 4736 | #if CONFIG_TEMPMV_SIGNALING |
| 4737 | // frame type has been decided outside of this function call |
| 4738 | cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only; |
| 4739 | cm->use_prev_frame_mvs = |
| 4740 | !cpi->oxcf.disable_tempmv && !cm->cur_frame->intra_only; |
| 4741 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4742 | |
| 4743 | #if CONFIG_EXT_REFS |
| 4744 | // NOTE: |
| 4745 | // (1) Move the setup of the ref_frame_flags upfront as it would be |
| 4746 | // determined by the current frame properties; |
| 4747 | // (2) The setup of the ref_frame_flags applies to both show_existing_frame's |
| 4748 | // and the other cases. |
| 4749 | if (cm->current_video_frame > 0) |
| 4750 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 4751 | |
| 4752 | if (cm->show_existing_frame) { |
| 4753 | // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current |
| 4754 | // BWDREF_FRAME in the reference frame buffer. |
| 4755 | cm->frame_type = INTER_FRAME; |
| 4756 | cm->show_frame = 1; |
| 4757 | cpi->frame_flags = *frame_flags; |
| 4758 | |
| 4759 | // In the case of show_existing frame, we will not send fresh flag |
| 4760 | // to decoder. Any change in the reference frame buffer can be done by |
| 4761 | // switching the virtual indices. |
| 4762 | |
| 4763 | cpi->refresh_last_frame = 0; |
| 4764 | cpi->refresh_golden_frame = 0; |
| 4765 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4766 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4767 | cpi->refresh_alt_ref_frame = 0; |
| 4768 | |
| 4769 | cpi->rc.is_bwd_ref_frame = 0; |
| 4770 | cpi->rc.is_last_bipred_frame = 0; |
| 4771 | cpi->rc.is_bipred_frame = 0; |
| 4772 | |
Jingning Han | 8f66160 | 2017-08-19 08:16:50 -0700 | [diff] [blame] | 4773 | restore_coding_context(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4774 | // Build the bitstream |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4775 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4776 | |
| 4777 | // Set up frame to show to get ready for stats collection. |
| 4778 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 4779 | |
| 4780 | #if DUMP_RECON_FRAMES == 1 |
| 4781 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 4782 | dump_filtered_recon_frames(cpi); |
| 4783 | #endif // DUMP_RECON_FRAMES |
| 4784 | |
| 4785 | // Update the LAST_FRAME in the reference frame buffer. |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 4786 | // NOTE: |
| 4787 | // (1) For BWDREF_FRAME as the show_existing_frame, the reference frame |
| 4788 | // update has been done previously when handling the LAST_BIPRED_FRAME |
| 4789 | // right before BWDREF_FRAME (in the display order); |
| 4790 | // (2) For INTNL_OVERLAY as the show_existing_frame, the reference frame |
| 4791 | // update will be done when the following is called, which will exchange |
| 4792 | // the virtual indexes between LAST_FRAME and ALTREF2_FRAME, so that |
| 4793 | // LAST3 will get retired, LAST2 becomes LAST3, LAST becomes LAST2, and |
| 4794 | // ALTREF2_FRAME will serve as the new LAST_FRAME. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4795 | av1_update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4796 | |
| 4797 | // Update frame flags |
| 4798 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 4799 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 4800 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 4801 | |
| 4802 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 4803 | |
| 4804 | // Update the frame type |
| 4805 | cm->last_frame_type = cm->frame_type; |
| 4806 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4807 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 4808 | // to do post-encoding update accordingly. |
| 4809 | if (cpi->rc.is_src_frame_alt_ref) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4810 | av1_set_target_rate(cpi); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4811 | #if CONFIG_XIPHRC |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 4812 | 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] | 4813 | drop_this_frame = od_enc_rc_update_state( |
| 4814 | &cpi->od_rc, *size << 3, cpi->refresh_golden_frame, |
| 4815 | cpi->refresh_alt_ref_frame, frame_type, cpi->droppable); |
| 4816 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4817 | av1_rc_postencode_update(cpi, *size); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4818 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4819 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4820 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4821 | ++cm->current_video_frame; |
| 4822 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 4823 | aom_free(tile_ctxs); |
| 4824 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4825 | return; |
| 4826 | } |
| 4827 | #endif // CONFIG_EXT_REFS |
| 4828 | |
| 4829 | // Set default state for segment based loop filter update flags. |
| 4830 | cm->lf.mode_ref_delta_update = 0; |
| 4831 | |
| 4832 | if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search) |
| 4833 | cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi); |
| 4834 | |
| 4835 | // Set various flags etc to special state if it is a key frame. |
| 4836 | if (frame_is_intra_only(cm)) { |
| 4837 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4838 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4839 | |
| 4840 | // If segmentation is enabled force a map update for key frames. |
| 4841 | if (seg->enabled) { |
| 4842 | seg->update_map = 1; |
| 4843 | seg->update_data = 1; |
| 4844 | } |
| 4845 | |
| 4846 | // The alternate reference frame cannot be active for a key frame. |
| 4847 | cpi->rc.source_alt_ref_active = 0; |
| 4848 | |
| 4849 | cm->error_resilient_mode = oxcf->error_resilient_mode; |
| 4850 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 4851 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4852 | // By default, encoder assumes decoder can use prev_mi. |
| 4853 | if (cm->error_resilient_mode) { |
| 4854 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
| 4855 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 4856 | } else if (cm->intra_only) { |
| 4857 | // Only reset the current context. |
| 4858 | cm->reset_frame_context = RESET_FRAME_CONTEXT_CURRENT; |
| 4859 | } |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 4860 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4861 | } |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4862 | if (cpi->oxcf.mtu == 0) { |
| 4863 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 4864 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 4865 | // Use a default value for the purposes of weighting costs in probability |
| 4866 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4867 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 4868 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4869 | |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 4870 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 4871 | cm->large_scale_tile = cpi->oxcf.large_scale_tile; |
| 4872 | cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 4873 | #endif // CONFIG_EXT_TILE |
| 4874 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4875 | #if CONFIG_XIPHRC |
| 4876 | if (drop_this_frame) { |
| 4877 | av1_rc_postencode_update_drop_frame(cpi); |
| 4878 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 4879 | aom_free(tile_ctxs); |
| 4880 | aom_free(cdf_ptrs); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4881 | return; |
| 4882 | } |
| 4883 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4884 | // For 1 pass CBR, check if we are dropping this frame. |
| 4885 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4886 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4887 | cm->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4888 | if (av1_rc_drop_frame(cpi)) { |
| 4889 | av1_rc_postencode_update_drop_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4890 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 4891 | aom_free(tile_ctxs); |
| 4892 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4893 | return; |
| 4894 | } |
| 4895 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4896 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4897 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4898 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4899 | |
| 4900 | #if CONFIG_INTERNAL_STATS |
| 4901 | memset(cpi->mode_chosen_counts, 0, |
| 4902 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 4903 | #endif |
| 4904 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4905 | #if CONFIG_REFERENCE_BUFFER |
| 4906 | { |
| 4907 | /* Non-normative definition of current_frame_id ("frame counter" with |
| 4908 | * wraparound) */ |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 4909 | const int frame_id_length = FRAME_ID_LENGTH_MINUS7 + 7; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4910 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4911 | int lsb, msb; |
Arild Fuldseth (arilfuld) | bac17c1 | 2016-12-02 12:01:06 +0100 | [diff] [blame] | 4912 | /* quasi-random initialization of current_frame_id for a key frame */ |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4913 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4914 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 4915 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 4916 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4917 | } else { |
| 4918 | #endif |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4919 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 4920 | msb = cpi->source->y_buffer[1] & 0xff; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4921 | #if CONFIG_HIGHBITDEPTH |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4922 | } |
Arild Fuldseth (arilfuld) | bac17c1 | 2016-12-02 12:01:06 +0100 | [diff] [blame] | 4923 | #endif |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 4924 | cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4925 | } else { |
| 4926 | cm->current_frame_id = |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 4927 | (cm->current_frame_id + 1 + (1 << frame_id_length)) % |
| 4928 | (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4929 | } |
| 4930 | } |
| 4931 | #endif |
| 4932 | |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 4933 | #if CONFIG_EXT_DELTA_Q |
| 4934 | cm->delta_q_present_flag = cpi->oxcf.deltaq_mode != NO_DELTA_Q; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 4935 | cm->delta_lf_present_flag = cpi->oxcf.deltaq_mode == DELTA_Q_LF; |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 4936 | #endif |
| 4937 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4938 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 4939 | encode_without_recode_loop(cpi); |
| 4940 | } else { |
| 4941 | encode_with_recode_loop(cpi, size, dest); |
| 4942 | } |
| 4943 | |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 4944 | cm->last_tile_cols = cm->tile_cols; |
| 4945 | cm->last_tile_rows = cm->tile_rows; |
| 4946 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4947 | #ifdef OUTPUT_YUV_SKINMAP |
| 4948 | if (cpi->common.current_video_frame > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4949 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4950 | } |
| 4951 | #endif // OUTPUT_YUV_SKINMAP |
| 4952 | |
| 4953 | // Special case code to reduce pulsing when key frames are forced at a |
| 4954 | // fixed interval. Note the reconstruction error if it is the frame before |
| 4955 | // the force key frame |
| 4956 | 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] | 4957 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4958 | if (cm->use_highbitdepth) { |
| 4959 | cpi->ambient_err = |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4960 | aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4961 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4962 | 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] | 4963 | } |
| 4964 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4965 | 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] | 4966 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4967 | } |
| 4968 | |
| 4969 | // If the encoder forced a KEY_FRAME decision |
| 4970 | if (cm->frame_type == KEY_FRAME) { |
| 4971 | cpi->refresh_last_frame = 1; |
| 4972 | } |
| 4973 | |
| 4974 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 4975 | cm->frame_to_show->color_space = cm->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 4976 | #if CONFIG_COLORSPACE_HEADERS |
| 4977 | cm->frame_to_show->transfer_function = cm->transfer_function; |
| 4978 | cm->frame_to_show->chroma_sample_position = cm->chroma_sample_position; |
| 4979 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4980 | cm->frame_to_show->color_range = cm->color_range; |
| 4981 | cm->frame_to_show->render_width = cm->render_width; |
| 4982 | cm->frame_to_show->render_height = cm->render_height; |
| 4983 | |
| 4984 | #if CONFIG_EXT_REFS |
| 4985 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 4986 | // off. |
| 4987 | #endif // CONFIG_EXT_REFS |
| 4988 | |
| 4989 | // Pick the loop filter level for the frame. |
| 4990 | loopfilter_frame(cpi, cm); |
| 4991 | |
| 4992 | // Build the bitstream |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4993 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4994 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 4995 | if (skip_adapt) { |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 4996 | aom_free(tile_ctxs); |
| 4997 | aom_free(cdf_ptrs); |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 4998 | return; |
| 4999 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5000 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5001 | #if CONFIG_REFERENCE_BUFFER |
| 5002 | { |
| 5003 | int i; |
| 5004 | /* Update reference frame id values based on the value of refresh_mask */ |
| 5005 | for (i = 0; i < REF_FRAMES; i++) { |
| 5006 | if ((cm->refresh_mask >> i) & 1) { |
| 5007 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 5008 | } |
| 5009 | } |
| 5010 | } |
| 5011 | #endif |
| 5012 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5013 | #if DUMP_RECON_FRAMES == 1 |
| 5014 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 5015 | if (cm->show_frame) dump_filtered_recon_frames(cpi); |
| 5016 | #endif // DUMP_RECON_FRAMES |
| 5017 | |
| 5018 | if (cm->seg.update_map) update_reference_segmentation_map(cpi); |
| 5019 | |
| 5020 | if (frame_is_intra_only(cm) == 0) { |
| 5021 | release_scaled_references(cpi); |
| 5022 | } |
| 5023 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5024 | av1_update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5025 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5026 | #if CONFIG_ENTROPY_STATS |
| 5027 | av1_accumulate_frame_counts(&aggregate_fc, &cm->counts); |
Zoe Liu | a56f916 | 2017-06-21 22:49:57 -0700 | [diff] [blame] | 5028 | assert(cm->frame_context_idx < FRAME_CONTEXTS); |
| 5029 | av1_accumulate_frame_counts(&aggregate_fc_per_type[cm->frame_context_idx], |
| 5030 | &cm->counts); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 5031 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5032 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
hui su | b53682f | 2017-08-01 17:09:18 -0700 | [diff] [blame] | 5033 | #if CONFIG_LV_MAP |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5034 | av1_adapt_coef_probs(cm); |
hui su | b53682f | 2017-08-01 17:09:18 -0700 | [diff] [blame] | 5035 | #endif // CONFIG_LV_MAP |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5036 | av1_adapt_intra_frame_probs(cm); |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5037 | 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] | 5038 | av1_average_tile_coef_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5039 | cm->tile_rows * cm->tile_cols); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5040 | av1_average_tile_intra_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5041 | cm->tile_rows * cm->tile_cols); |
Yushin Cho | b188ea1 | 2017-03-13 13:45:23 -0700 | [diff] [blame] | 5042 | #if CONFIG_PVQ |
| 5043 | av1_average_tile_pvq_cdfs(cpi->common.fc, tile_ctxs, |
| 5044 | cm->tile_rows * cm->tile_cols); |
| 5045 | #endif // CONFIG_PVQ |
hui su | ff0da2b | 2017-03-07 15:51:37 -0800 | [diff] [blame] | 5046 | #if CONFIG_ADAPT_SCAN |
| 5047 | av1_adapt_scan_order(cm); |
| 5048 | #endif // CONFIG_ADAPT_SCAN |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5049 | } |
| 5050 | |
| 5051 | if (!frame_is_intra_only(cm)) { |
| 5052 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5053 | av1_adapt_inter_frame_probs(cm); |
| 5054 | av1_adapt_mv_probs(cm, cm->allow_high_precision_mv); |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5055 | av1_average_tile_inter_cdfs(&cpi->common, cpi->common.fc, tile_ctxs, |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5056 | cdf_ptrs, cm->tile_rows * cm->tile_cols); |
| 5057 | av1_average_tile_mv_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 5058 | cm->tile_rows * cm->tile_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5059 | } |
| 5060 | } |
| 5061 | |
| 5062 | if (cpi->refresh_golden_frame == 1) |
| 5063 | cpi->frame_flags |= FRAMEFLAGS_GOLDEN; |
| 5064 | else |
| 5065 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 5066 | |
| 5067 | if (cpi->refresh_alt_ref_frame == 1) |
| 5068 | cpi->frame_flags |= FRAMEFLAGS_ALTREF; |
| 5069 | else |
| 5070 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 5071 | |
| 5072 | #if CONFIG_EXT_REFS |
| 5073 | if (cpi->refresh_bwd_ref_frame == 1) |
| 5074 | cpi->frame_flags |= FRAMEFLAGS_BWDREF; |
| 5075 | else |
| 5076 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 5077 | #endif // CONFIG_EXT_REFS |
| 5078 | |
| 5079 | #if !CONFIG_EXT_REFS |
| 5080 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 5081 | #endif // !CONFIG_EXT_REFS |
| 5082 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5083 | cm->last_frame_type = cm->frame_type; |
| 5084 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5085 | #if CONFIG_XIPHRC |
| 5086 | frame_type = cm->frame_type == KEY_FRAME ? OD_I_FRAME : OD_P_FRAME; |
| 5087 | |
| 5088 | drop_this_frame = |
| 5089 | od_enc_rc_update_state(&cpi->od_rc, *size << 3, cpi->refresh_golden_frame, |
| 5090 | cpi->refresh_alt_ref_frame, frame_type, 0); |
| 5091 | if (drop_this_frame) { |
| 5092 | av1_rc_postencode_update_drop_frame(cpi); |
| 5093 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 5094 | aom_free(tile_ctxs); |
| 5095 | aom_free(cdf_ptrs); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5096 | return; |
| 5097 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5098 | #else // !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5099 | av1_rc_postencode_update(cpi, *size); |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5100 | #endif // CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5101 | |
| 5102 | #if 0 |
| 5103 | output_frame_level_debug_stats(cpi); |
| 5104 | #endif |
| 5105 | |
| 5106 | if (cm->frame_type == KEY_FRAME) { |
| 5107 | // Tell the caller that the frame was coded as a key frame |
| 5108 | *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY; |
| 5109 | } else { |
| 5110 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 5111 | } |
| 5112 | |
| 5113 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 5114 | // filter deltas. |
| 5115 | cm->seg.update_map = 0; |
| 5116 | cm->seg.update_data = 0; |
| 5117 | cm->lf.mode_ref_delta_update = 0; |
| 5118 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5119 | if (cm->show_frame) { |
| 5120 | #if CONFIG_EXT_REFS |
| 5121 | // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that are |
| 5122 | // being used as reference. |
| 5123 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5124 | av1_swap_mi_and_prev_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5125 | // Don't increment frame counters if this was an altref buffer |
| 5126 | // update not a real frame |
| 5127 | ++cm->current_video_frame; |
| 5128 | } |
| 5129 | |
| 5130 | #if CONFIG_EXT_REFS |
| 5131 | // NOTE: Shall not refer to any frame not used as reference. |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5132 | if (cm->is_reference_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5133 | #endif // CONFIG_EXT_REFS |
| 5134 | cm->prev_frame = cm->cur_frame; |
Fergus Simpson | 2b4ea11 | 2017-06-19 11:33:59 -0700 | [diff] [blame] | 5135 | // keep track of the last coded dimensions |
| 5136 | cm->last_width = cm->width; |
| 5137 | cm->last_height = cm->height; |
| 5138 | |
| 5139 | // reset to normal state now that we are done. |
| 5140 | cm->last_show_frame = cm->show_frame; |
| 5141 | #if CONFIG_EXT_REFS |
| 5142 | } |
| 5143 | #endif // CONFIG_EXT_REFS |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 5144 | |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 5145 | aom_free(tile_ctxs); |
| 5146 | aom_free(cdf_ptrs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5147 | } |
| 5148 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5149 | static void Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5150 | int skip_adapt, unsigned int *frame_flags) { |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5151 | #if CONFIG_XIPHRC |
| 5152 | int64_t ip_count; |
| 5153 | int frame_type, is_golden, is_altref; |
| 5154 | |
| 5155 | /* Not updated during init so update it here */ |
| 5156 | if (cpi->oxcf.rc_mode == AOM_Q) cpi->od_rc.quality = cpi->oxcf.cq_level; |
| 5157 | |
| 5158 | frame_type = od_frame_type(&cpi->od_rc, cpi->od_rc.cur_frame, &is_golden, |
| 5159 | &is_altref, &ip_count); |
| 5160 | |
| 5161 | if (frame_type == OD_I_FRAME) { |
| 5162 | frame_type = KEY_FRAME; |
| 5163 | cpi->frame_flags &= FRAMEFLAGS_KEY; |
| 5164 | } else if (frame_type == OD_P_FRAME) { |
| 5165 | frame_type = INTER_FRAME; |
| 5166 | } |
| 5167 | |
| 5168 | if (is_altref) { |
| 5169 | cpi->refresh_alt_ref_frame = 1; |
| 5170 | cpi->rc.source_alt_ref_active = 1; |
| 5171 | } |
| 5172 | |
| 5173 | cpi->refresh_golden_frame = is_golden; |
| 5174 | cpi->common.frame_type = frame_type; |
| 5175 | if (is_golden) cpi->frame_flags &= FRAMEFLAGS_GOLDEN; |
| 5176 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5177 | if (cpi->oxcf.rc_mode == AOM_CBR) { |
| 5178 | av1_rc_get_one_pass_cbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5179 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5180 | av1_rc_get_one_pass_vbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5181 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5182 | #endif |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5183 | encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5186 | #if !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5187 | static void Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5188 | unsigned int *frame_flags) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5189 | encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5190 | |
| 5191 | #if CONFIG_EXT_REFS |
| 5192 | // Do not do post-encoding update for those frames that do not have a spot in |
| 5193 | // a gf group, but note that an OVERLAY frame always has a spot in a gf group, |
| 5194 | // even when show_existing_frame is used. |
| 5195 | 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] | 5196 | av1_twopass_postencode_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5197 | } |
| 5198 | check_show_existing_frame(cpi); |
| 5199 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5200 | av1_twopass_postencode_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5201 | #endif // CONFIG_EXT_REFS |
| 5202 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5203 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5204 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5205 | static void init_ref_frame_bufs(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5206 | int i; |
| 5207 | BufferPool *const pool = cm->buffer_pool; |
| 5208 | cm->new_fb_idx = INVALID_IDX; |
| 5209 | for (i = 0; i < REF_FRAMES; ++i) { |
| 5210 | cm->ref_frame_map[i] = INVALID_IDX; |
| 5211 | pool->frame_bufs[i].ref_count = 0; |
| 5212 | } |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 5213 | #if CONFIG_HASH_ME |
| 5214 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 5215 | av1_hash_table_init(&pool->frame_bufs[i].hash_table); |
| 5216 | } |
| 5217 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5218 | } |
| 5219 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5220 | static void check_initial_width(AV1_COMP *cpi, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5221 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5222 | int use_highbitdepth, |
| 5223 | #endif |
| 5224 | int subsampling_x, int subsampling_y) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5225 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5226 | |
| 5227 | if (!cpi->initial_width || |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5228 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5229 | cm->use_highbitdepth != use_highbitdepth || |
| 5230 | #endif |
| 5231 | cm->subsampling_x != subsampling_x || |
| 5232 | cm->subsampling_y != subsampling_y) { |
| 5233 | cm->subsampling_x = subsampling_x; |
| 5234 | cm->subsampling_y = subsampling_y; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5235 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5236 | cm->use_highbitdepth = use_highbitdepth; |
| 5237 | #endif |
| 5238 | |
| 5239 | alloc_raw_frame_buffers(cpi); |
| 5240 | init_ref_frame_bufs(cm); |
| 5241 | alloc_util_frame_buffers(cpi); |
| 5242 | |
| 5243 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 5244 | |
| 5245 | cpi->initial_width = cm->width; |
| 5246 | cpi->initial_height = cm->height; |
| 5247 | cpi->initial_mbs = cm->MBs; |
| 5248 | } |
| 5249 | } |
| 5250 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 5251 | 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] | 5252 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 5253 | int64_t end_time) { |
| 5254 | AV1_COMMON *const cm = &cpi->common; |
| 5255 | struct aom_usec_timer timer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5256 | int res = 0; |
| 5257 | const int subsampling_x = sd->subsampling_x; |
| 5258 | const int subsampling_y = sd->subsampling_y; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5259 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5260 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
| 5261 | #endif |
| 5262 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5263 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5264 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
| 5265 | #else |
| 5266 | check_initial_width(cpi, subsampling_x, subsampling_y); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5267 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5268 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5269 | aom_usec_timer_start(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5270 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5271 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5272 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5273 | use_highbitdepth, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5274 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5275 | frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5276 | res = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5277 | aom_usec_timer_mark(&timer); |
| 5278 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5279 | |
| 5280 | if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && |
| 5281 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5282 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5283 | "Non-4:2:0 color format requires profile 1 or 3"); |
| 5284 | res = -1; |
| 5285 | } |
| 5286 | if ((cm->profile == PROFILE_1 || cm->profile == PROFILE_3) && |
| 5287 | (subsampling_x == 1 && subsampling_y == 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5288 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5289 | "4:2:0 color format requires profile 0 or 2"); |
| 5290 | res = -1; |
| 5291 | } |
| 5292 | |
| 5293 | return res; |
| 5294 | } |
| 5295 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5296 | static int frame_is_reference(const AV1_COMP *cpi) { |
| 5297 | const AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5298 | |
| 5299 | return cm->frame_type == KEY_FRAME || cpi->refresh_last_frame || |
| 5300 | cpi->refresh_golden_frame || |
| 5301 | #if CONFIG_EXT_REFS |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5302 | cpi->refresh_bwd_ref_frame || cpi->refresh_alt2_ref_frame || |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5303 | #endif // CONFIG_EXT_REFS |
| 5304 | cpi->refresh_alt_ref_frame || !cm->error_resilient_mode || |
| 5305 | cm->lf.mode_ref_delta_update || cm->seg.update_map || |
| 5306 | cm->seg.update_data; |
| 5307 | } |
| 5308 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5309 | static void adjust_frame_rate(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5310 | const struct lookahead_entry *source) { |
| 5311 | int64_t this_duration; |
| 5312 | int step = 0; |
| 5313 | |
| 5314 | if (source->ts_start == cpi->first_time_stamp_ever) { |
| 5315 | this_duration = source->ts_end - source->ts_start; |
| 5316 | step = 1; |
| 5317 | } else { |
| 5318 | int64_t last_duration = |
| 5319 | cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen; |
| 5320 | |
| 5321 | this_duration = source->ts_end - cpi->last_end_time_stamp_seen; |
| 5322 | |
| 5323 | // do a step update if the duration changes by 10% |
| 5324 | if (last_duration) |
| 5325 | step = (int)((this_duration - last_duration) * 10 / last_duration); |
| 5326 | } |
| 5327 | |
| 5328 | if (this_duration) { |
| 5329 | if (step) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5330 | av1_new_framerate(cpi, 10000000.0 / this_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5331 | } else { |
| 5332 | // Average this frame's rate into the last second's average |
| 5333 | // frame rate. If we haven't seen 1 second yet, then average |
| 5334 | // over the whole interval seen. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5335 | const double interval = AOMMIN( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5336 | (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0); |
| 5337 | double avg_duration = 10000000.0 / cpi->framerate; |
| 5338 | avg_duration *= (interval - avg_duration + this_duration); |
| 5339 | avg_duration /= interval; |
| 5340 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5341 | av1_new_framerate(cpi, 10000000.0 / avg_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5342 | } |
| 5343 | } |
| 5344 | cpi->last_time_stamp_seen = source->ts_start; |
| 5345 | cpi->last_end_time_stamp_seen = source->ts_end; |
| 5346 | } |
| 5347 | |
| 5348 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5349 | // used as the arf midpoint. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5350 | static int get_arf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5351 | RATE_CONTROL *const rc = &cpi->rc; |
| 5352 | int arf_src_index = 0; |
| 5353 | if (is_altref_enabled(cpi)) { |
| 5354 | if (cpi->oxcf.pass == 2) { |
| 5355 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5356 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 5357 | arf_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5358 | } |
| 5359 | } else if (rc->source_alt_ref_pending) { |
| 5360 | arf_src_index = rc->frames_till_gf_update_due; |
| 5361 | } |
| 5362 | } |
| 5363 | return arf_src_index; |
| 5364 | } |
| 5365 | |
| 5366 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5367 | static int get_brf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5368 | int brf_src_index = 0; |
| 5369 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5370 | |
| 5371 | // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup |
| 5372 | // flag. |
| 5373 | if (gf_group->bidir_pred_enabled[gf_group->index]) { |
| 5374 | if (cpi->oxcf.pass == 2) { |
| 5375 | if (gf_group->update_type[gf_group->index] == BRF_UPDATE) |
| 5376 | brf_src_index = gf_group->brf_src_offset[gf_group->index]; |
| 5377 | } else { |
| 5378 | // TODO(zoeliu): To re-visit the setup for this scenario |
| 5379 | brf_src_index = cpi->rc.bipred_group_interval - 1; |
| 5380 | } |
| 5381 | } |
| 5382 | |
| 5383 | return brf_src_index; |
| 5384 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5385 | |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5386 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5387 | // used as the arf midpoint. |
| 5388 | static int get_arf2_src_index(AV1_COMP *cpi) { |
| 5389 | int arf2_src_index = 0; |
| 5390 | if (is_altref_enabled(cpi) && cpi->num_extra_arfs) { |
| 5391 | if (cpi->oxcf.pass == 2) { |
| 5392 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5393 | if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) { |
| 5394 | arf2_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5395 | } |
| 5396 | } |
| 5397 | } |
| 5398 | return arf2_src_index; |
| 5399 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5400 | #endif // CONFIG_EXT_REFS |
| 5401 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5402 | static void check_src_altref(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5403 | const struct lookahead_entry *source) { |
| 5404 | RATE_CONTROL *const rc = &cpi->rc; |
| 5405 | |
| 5406 | // If pass == 2, the parameters set here will be reset in |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5407 | // av1_rc_get_second_pass_params() |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5408 | |
| 5409 | if (cpi->oxcf.pass == 2) { |
| 5410 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5411 | rc->is_src_frame_alt_ref = |
| 5412 | #if CONFIG_EXT_REFS |
| 5413 | (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) || |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 5414 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5415 | (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5416 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5417 | rc->is_src_frame_ext_arf = |
| 5418 | gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE; |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5419 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5420 | } else { |
| 5421 | rc->is_src_frame_alt_ref = |
| 5422 | cpi->alt_ref_source && (source == cpi->alt_ref_source); |
| 5423 | } |
| 5424 | |
| 5425 | if (rc->is_src_frame_alt_ref) { |
| 5426 | // Current frame is an ARF overlay frame. |
| 5427 | cpi->alt_ref_source = NULL; |
| 5428 | |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5429 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5430 | if (rc->is_src_frame_ext_arf && !cpi->common.show_existing_frame) { |
| 5431 | // For INTNL_OVERLAY, when show_existing_frame == 0, they do need to |
| 5432 | // refresh the LAST_FRAME, i.e. LAST3 gets retired, LAST2 becomes LAST3, |
| 5433 | // LAST becomes LAST2, and INTNL_OVERLAY becomes LAST. |
| 5434 | cpi->refresh_last_frame = 1; |
| 5435 | } else { |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5436 | #endif // CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5437 | // Don't refresh the last buffer for an ARF overlay frame. It will |
| 5438 | // become the GF so preserve last as an alternative prediction option. |
| 5439 | cpi->refresh_last_frame = 0; |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5440 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5441 | } |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5442 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5443 | } |
| 5444 | } |
| 5445 | |
| 5446 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5447 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 5448 | const unsigned char *img2, int img2_pitch, |
| 5449 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5450 | |
| 5451 | static void adjust_image_stat(double y, double u, double v, double all, |
| 5452 | ImageStat *s) { |
| 5453 | s->stat[Y] += y; |
| 5454 | s->stat[U] += u; |
| 5455 | s->stat[V] += v; |
| 5456 | s->stat[ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5457 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5458 | } |
| 5459 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5460 | static void compute_internal_stats(AV1_COMP *cpi, int frame_bytes) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5461 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5462 | double samples = 0.0; |
| 5463 | uint32_t in_bit_depth = 8; |
| 5464 | uint32_t bit_depth = 8; |
| 5465 | |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5466 | #if CONFIG_INTER_STATS_ONLY |
Yaowu Xu | 1b4ffc4 | 2017-07-26 09:54:07 -0700 | [diff] [blame] | 5467 | if (cm->frame_type == KEY_FRAME) return; // skip key frame |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5468 | #endif |
| 5469 | cpi->bytes += frame_bytes; |
| 5470 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5471 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5472 | if (cm->use_highbitdepth) { |
| 5473 | in_bit_depth = cpi->oxcf.input_bit_depth; |
| 5474 | bit_depth = cm->bit_depth; |
| 5475 | } |
| 5476 | #endif |
| 5477 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5478 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5479 | const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; |
| 5480 | double y, u, v, frame_all; |
| 5481 | |
| 5482 | cpi->count++; |
| 5483 | if (cpi->b_calculate_psnr) { |
| 5484 | PSNR_STATS psnr; |
| 5485 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5486 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5487 | // TODO(yaowu): unify these two versions into one. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5488 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5489 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5490 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5491 | aom_calc_psnr(orig, recon, &psnr); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5492 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5493 | |
| 5494 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 5495 | &cpi->psnr); |
| 5496 | cpi->total_sq_error += psnr.sse[0]; |
| 5497 | cpi->total_samples += psnr.samples[0]; |
| 5498 | samples = psnr.samples[0]; |
| 5499 | // TODO(yaowu): unify these two versions into one. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5500 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5501 | if (cm->use_highbitdepth) |
| 5502 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5503 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5504 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5505 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5506 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5507 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5508 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5509 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5510 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5511 | cpi->summed_quality += frame_ssim2 * weight; |
| 5512 | cpi->summed_weights += weight; |
| 5513 | |
| 5514 | #if 0 |
| 5515 | { |
| 5516 | FILE *f = fopen("q_used.stt", "a"); |
| 5517 | fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", |
| 5518 | cpi->common.current_video_frame, y2, u2, v2, |
| 5519 | frame_psnr2, frame_ssim2); |
| 5520 | fclose(f); |
| 5521 | } |
| 5522 | #endif |
| 5523 | } |
| 5524 | if (cpi->b_calculate_blockiness) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5525 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5526 | if (!cm->use_highbitdepth) |
| 5527 | #endif |
| 5528 | { |
| 5529 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5530 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 5531 | recon->y_stride, orig->y_width, orig->y_height); |
| 5532 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5533 | cpi->total_blockiness += frame_blockiness; |
| 5534 | } |
| 5535 | |
| 5536 | if (cpi->b_calculate_consistency) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5537 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5538 | if (!cm->use_highbitdepth) |
| 5539 | #endif |
| 5540 | { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5541 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5542 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 5543 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 5544 | |
| 5545 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 5546 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5547 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5548 | if (consistency > 0.0) |
| 5549 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5550 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5551 | cpi->total_inconsistency += this_inconsistency; |
| 5552 | } |
| 5553 | } |
| 5554 | } |
| 5555 | |
| 5556 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5557 | 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] | 5558 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5559 | 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] | 5560 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 5561 | } |
| 5562 | } |
| 5563 | #endif // CONFIG_INTERNAL_STATS |
| 5564 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5565 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 5566 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 5567 | int64_t *time_end, int flush) { |
| 5568 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 5569 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5570 | BufferPool *const pool = cm->buffer_pool; |
| 5571 | RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5572 | struct aom_usec_timer cmptimer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5573 | YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
| 5574 | struct lookahead_entry *last_source = NULL; |
| 5575 | struct lookahead_entry *source = NULL; |
| 5576 | int arf_src_index; |
| 5577 | #if CONFIG_EXT_REFS |
| 5578 | int brf_src_index; |
| 5579 | #endif // CONFIG_EXT_REFS |
| 5580 | int i; |
| 5581 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5582 | #if CONFIG_XIPHRC |
| 5583 | cpi->od_rc.end_of_input = flush; |
| 5584 | #endif |
| 5585 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5586 | #if CONFIG_BITSTREAM_DEBUG |
| 5587 | assert(cpi->oxcf.max_threads == 0 && |
| 5588 | "bitstream debug tool does not support multithreading"); |
| 5589 | bitstream_queue_record_write(); |
Angie Chiang | cb9a9eb | 2016-09-01 16:10:50 -0700 | [diff] [blame] | 5590 | 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] | 5591 | #endif |
| 5592 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5593 | aom_usec_timer_start(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5594 | |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 5595 | av1_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5596 | |
| 5597 | // Is multi-arf enabled. |
| 5598 | // Note that at the moment multi_arf is only configured for 2 pass VBR |
| 5599 | if ((oxcf->pass == 2) && (cpi->oxcf.enable_auto_arf > 1)) |
| 5600 | cpi->multi_arf_allowed = 1; |
| 5601 | else |
| 5602 | cpi->multi_arf_allowed = 0; |
| 5603 | |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 5604 | // Normal defaults |
| 5605 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5606 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 5607 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5608 | cm->refresh_frame_context = |
| 5609 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 5610 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 5611 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
| 5612 | |
| 5613 | cpi->refresh_last_frame = 1; |
| 5614 | cpi->refresh_golden_frame = 0; |
| 5615 | #if CONFIG_EXT_REFS |
| 5616 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5617 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5618 | #endif // CONFIG_EXT_REFS |
| 5619 | cpi->refresh_alt_ref_frame = 0; |
| 5620 | |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5621 | #if CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5622 | if (oxcf->pass == 2 && cm->show_existing_frame) { |
| 5623 | // Manage the source buffer and flush out the source frame that has been |
| 5624 | // coded already; Also get prepared for PSNR calculation if needed. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5625 | if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5626 | *size = 0; |
| 5627 | return -1; |
| 5628 | } |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5629 | cpi->source = &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5630 | // TODO(zoeliu): To track down to determine whether it's needed to adjust |
| 5631 | // the frame rate. |
| 5632 | *time_stamp = source->ts_start; |
| 5633 | *time_end = source->ts_end; |
| 5634 | |
| 5635 | // We need to adjust frame rate for an overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5636 | 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] | 5637 | |
| 5638 | // Find a free buffer for the new frame, releasing the reference previously |
| 5639 | // held. |
| 5640 | if (cm->new_fb_idx != INVALID_IDX) { |
| 5641 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 5642 | } |
| 5643 | cm->new_fb_idx = get_free_fb(cm); |
| 5644 | |
| 5645 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 5646 | |
| 5647 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5648 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5649 | |
| 5650 | // Start with a 0 size frame. |
| 5651 | *size = 0; |
| 5652 | |
| 5653 | // We need to update the gf_group for show_existing overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5654 | 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] | 5655 | |
| 5656 | Pass2Encode(cpi, size, dest, frame_flags); |
| 5657 | |
| 5658 | if (cpi->b_calculate_psnr) generate_psnr_packet(cpi); |
| 5659 | |
| 5660 | #if CONFIG_INTERNAL_STATS |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 5661 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5662 | #endif // CONFIG_INTERNAL_STATS |
| 5663 | |
| 5664 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5665 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5666 | |
| 5667 | cm->show_existing_frame = 0; |
| 5668 | return 0; |
| 5669 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5670 | #endif // CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5671 | |
| 5672 | // Should we encode an arf frame. |
| 5673 | arf_src_index = get_arf_src_index(cpi); |
| 5674 | if (arf_src_index) { |
| 5675 | for (i = 0; i <= arf_src_index; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5676 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5677 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 5678 | if (e == NULL) { |
| 5679 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5680 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5681 | arf_src_index = 0; |
| 5682 | flush = 1; |
| 5683 | break; |
| 5684 | } |
| 5685 | } |
| 5686 | } |
| 5687 | |
| 5688 | if (arf_src_index) { |
| 5689 | assert(arf_src_index <= rc->frames_to_key); |
| 5690 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5691 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5692 | cpi->alt_ref_source = source; |
| 5693 | |
| 5694 | if (oxcf->arnr_max_frames > 0) { |
Todd Nguyen | 302d097 | 2017-06-16 16:16:29 -0700 | [diff] [blame] | 5695 | // Produce the filtered ARF frame. |
| 5696 | #if CONFIG_BGSPRITE |
| 5697 | int bgsprite_ret = av1_background_sprite(cpi, arf_src_index); |
Todd Nguyen | 2fc2309 | 2017-07-11 12:00:36 -0700 | [diff] [blame] | 5698 | // Do temporal filter if bgsprite not generated. |
| 5699 | if (bgsprite_ret != 0) |
Todd Nguyen | 302d097 | 2017-06-16 16:16:29 -0700 | [diff] [blame] | 5700 | #endif // CONFIG_BGSPRITE |
Todd Nguyen | 8493f91 | 2017-07-20 12:45:12 -0700 | [diff] [blame] | 5701 | av1_temporal_filter(cpi, |
| 5702 | #if CONFIG_BGSPRITE |
Todd Nguyen | 1fd99c2 | 2017-07-31 17:50:41 -0700 | [diff] [blame] | 5703 | NULL, &cpi->alt_ref_buffer, |
Todd Nguyen | 8493f91 | 2017-07-20 12:45:12 -0700 | [diff] [blame] | 5704 | #endif // CONFIG_BGSPRITE |
| 5705 | arf_src_index); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5706 | aom_extend_frame_borders(&cpi->alt_ref_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5707 | force_src_buffer = &cpi->alt_ref_buffer; |
| 5708 | } |
| 5709 | |
| 5710 | cm->show_frame = 0; |
| 5711 | cm->intra_only = 0; |
| 5712 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5713 | cpi->refresh_last_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5714 | cpi->refresh_golden_frame = 0; |
| 5715 | #if CONFIG_EXT_REFS |
| 5716 | cpi->refresh_bwd_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5717 | cpi->refresh_alt2_ref_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5718 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5719 | rc->is_src_frame_alt_ref = 0; |
| 5720 | } |
| 5721 | rc->source_alt_ref_pending = 0; |
| 5722 | } |
| 5723 | |
| 5724 | #if CONFIG_EXT_REFS |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5725 | // Should we encode an arf2 frame. |
| 5726 | arf_src_index = get_arf2_src_index(cpi); |
| 5727 | if (arf_src_index) { |
| 5728 | for (i = 0; i <= arf_src_index; ++i) { |
| 5729 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
| 5730 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 5731 | if (e == NULL) { |
| 5732 | break; |
| 5733 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
| 5734 | arf_src_index = 0; |
| 5735 | flush = 1; |
| 5736 | break; |
| 5737 | } |
| 5738 | } |
| 5739 | } |
| 5740 | |
| 5741 | if (arf_src_index) { |
| 5742 | assert(arf_src_index <= rc->frames_to_key); |
| 5743 | |
| 5744 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
| 5745 | cpi->alt_ref_source = source; |
| 5746 | |
| 5747 | if (oxcf->arnr_max_frames > 0) { |
| 5748 | // Produce the filtered ARF frame. |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5749 | av1_temporal_filter(cpi, |
| 5750 | #if CONFIG_BGSPRITE |
| 5751 | NULL, NULL, |
| 5752 | #endif // CONFIG_BGSPRITE |
| 5753 | arf_src_index); |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5754 | aom_extend_frame_borders(&cpi->alt_ref_buffer); |
| 5755 | force_src_buffer = &cpi->alt_ref_buffer; |
| 5756 | } |
| 5757 | |
| 5758 | cm->show_frame = 0; |
| 5759 | cm->intra_only = 0; |
| 5760 | cpi->refresh_alt2_ref_frame = 1; |
| 5761 | cpi->refresh_last_frame = 0; |
| 5762 | cpi->refresh_golden_frame = 0; |
| 5763 | cpi->refresh_bwd_ref_frame = 0; |
| 5764 | cpi->refresh_alt_ref_frame = 0; |
| 5765 | rc->is_src_frame_alt_ref = 0; |
| 5766 | rc->is_src_frame_ext_arf = 0; |
| 5767 | } |
| 5768 | rc->source_alt_ref_pending = 0; |
| 5769 | } |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5770 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5771 | rc->is_bwd_ref_frame = 0; |
| 5772 | brf_src_index = get_brf_src_index(cpi); |
| 5773 | if (brf_src_index) { |
| 5774 | assert(brf_src_index <= rc->frames_to_key); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5775 | if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5776 | cm->show_frame = 0; |
| 5777 | cm->intra_only = 0; |
| 5778 | |
| 5779 | cpi->refresh_bwd_ref_frame = 1; |
| 5780 | cpi->refresh_last_frame = 0; |
| 5781 | cpi->refresh_golden_frame = 0; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 5782 | cpi->refresh_alt2_ref_frame = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5783 | cpi->refresh_alt_ref_frame = 0; |
| 5784 | |
| 5785 | rc->is_bwd_ref_frame = 1; |
| 5786 | } |
| 5787 | } |
| 5788 | #endif // CONFIG_EXT_REFS |
| 5789 | |
| 5790 | if (!source) { |
| 5791 | // Get last frame source. |
| 5792 | if (cm->current_video_frame > 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5793 | if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5794 | return -1; |
| 5795 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5796 | if (cm->current_video_frame > 0) assert(last_source != NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5797 | // Read in the source frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5798 | source = av1_lookahead_pop(cpi->lookahead, flush); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5799 | |
| 5800 | if (source != NULL) { |
| 5801 | cm->show_frame = 1; |
| 5802 | cm->intra_only = 0; |
| 5803 | |
| 5804 | // Check to see if the frame should be encoded as an arf overlay. |
| 5805 | check_src_altref(cpi, source); |
| 5806 | } |
| 5807 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5808 | if (source) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5809 | cpi->unscaled_source = cpi->source = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5810 | force_src_buffer ? force_src_buffer : &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5811 | cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL; |
| 5812 | |
| 5813 | *time_stamp = source->ts_start; |
| 5814 | *time_end = source->ts_end; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5815 | *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5816 | |
| 5817 | } else { |
| 5818 | *size = 0; |
| 5819 | if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5820 | #if CONFIG_XIPHRC |
| 5821 | od_enc_rc_2pass_out(&cpi->od_rc, cpi->output_pkt_list, 1); |
| 5822 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5823 | av1_end_first_pass(cpi); /* get last stats packet */ |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5824 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5825 | cpi->twopass.first_pass_done = 1; |
| 5826 | } |
| 5827 | return -1; |
| 5828 | } |
| 5829 | |
| 5830 | if (source->ts_start < cpi->first_time_stamp_ever) { |
| 5831 | cpi->first_time_stamp_ever = source->ts_start; |
| 5832 | cpi->last_end_time_stamp_seen = source->ts_start; |
| 5833 | } |
| 5834 | |
| 5835 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5836 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5837 | |
| 5838 | // adjust frame rates based on timestamps given |
| 5839 | if (cm->show_frame) adjust_frame_rate(cpi, source); |
| 5840 | |
| 5841 | // Find a free buffer for the new frame, releasing the reference previously |
| 5842 | // held. |
| 5843 | if (cm->new_fb_idx != INVALID_IDX) { |
| 5844 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 5845 | } |
| 5846 | cm->new_fb_idx = get_free_fb(cm); |
| 5847 | |
| 5848 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 5849 | |
| 5850 | cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; |
Yaowu Xu | 9b0f703 | 2017-07-31 11:01:19 -0700 | [diff] [blame] | 5851 | #if CONFIG_HIGHBITDEPTH && CONFIG_GLOBAL_MOTION |
| 5852 | cm->cur_frame->buf.buf_8bit_valid = 0; |
| 5853 | #endif |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5854 | #if !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5855 | if (cpi->multi_arf_allowed) { |
| 5856 | if (cm->frame_type == KEY_FRAME) { |
| 5857 | init_buffer_indices(cpi); |
| 5858 | } else if (oxcf->pass == 2) { |
| 5859 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5860 | cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; |
| 5861 | } |
| 5862 | } |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 5863 | #endif // !CONFIG_EXT_REFS |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 5864 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5865 | // Start with a 0 size frame. |
| 5866 | *size = 0; |
| 5867 | |
| 5868 | cpi->frame_flags = *frame_flags; |
| 5869 | |
| 5870 | if (oxcf->pass == 2) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5871 | #if CONFIG_XIPHRC |
| 5872 | if (od_enc_rc_2pass_in(&cpi->od_rc) < 0) return -1; |
| 5873 | } |
| 5874 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5875 | av1_rc_get_second_pass_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5876 | } else if (oxcf->pass == 1) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 5877 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5878 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5879 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5880 | |
| 5881 | if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) { |
| 5882 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) |
| 5883 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 5884 | } |
| 5885 | |
| 5886 | #if CONFIG_AOM_QM |
| 5887 | cm->using_qmatrix = cpi->oxcf.using_qm; |
| 5888 | cm->min_qmlevel = cpi->oxcf.qm_minlevel; |
| 5889 | cm->max_qmlevel = cpi->oxcf.qm_maxlevel; |
| 5890 | #endif |
| 5891 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5892 | #if CONFIG_REFERENCE_BUFFER |
| 5893 | if (*time_stamp == 0) { |
| 5894 | cpi->common.current_frame_id = -1; |
| 5895 | } |
| 5896 | #endif |
| 5897 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5898 | #if CONFIG_XIPHRC |
| 5899 | if (oxcf->pass == 1) { |
| 5900 | size_t tmp; |
| 5901 | if (cpi->od_rc.cur_frame == 0) Pass0Encode(cpi, &tmp, dest, 1, frame_flags); |
| 5902 | cpi->od_rc.firstpass_quant = cpi->od_rc.target_quantizer; |
| 5903 | Pass0Encode(cpi, &tmp, dest, 0, frame_flags); |
| 5904 | od_enc_rc_2pass_out(&cpi->od_rc, cpi->output_pkt_list, 0); |
| 5905 | } else if (oxcf->pass == 2) { |
| 5906 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
| 5907 | } else { |
| 5908 | if (cpi->od_rc.cur_frame == 0) { |
| 5909 | size_t tmp; |
| 5910 | Pass0Encode(cpi, &tmp, dest, 1, frame_flags); |
| 5911 | } |
| 5912 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
| 5913 | } |
| 5914 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5915 | if (oxcf->pass == 1) { |
| 5916 | cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5917 | av1_first_pass(cpi, source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5918 | } else if (oxcf->pass == 2) { |
| 5919 | Pass2Encode(cpi, size, dest, frame_flags); |
| 5920 | } else { |
| 5921 | // One pass encode |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5922 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5923 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5924 | #endif |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 5925 | #if CONFIG_HASH_ME |
| 5926 | if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools) { |
| 5927 | // add to hash table |
| 5928 | const int pic_width = cpi->source->y_crop_width; |
| 5929 | const int pic_height = cpi->source->y_crop_height; |
| 5930 | uint32_t *block_hash_values[2][2]; |
| 5931 | int8_t *is_block_same[2][3]; |
| 5932 | int k, j; |
| 5933 | |
| 5934 | for (k = 0; k < 2; k++) { |
| 5935 | for (j = 0; j < 2; j++) { |
| 5936 | CHECK_MEM_ERROR(cm, block_hash_values[k][j], |
| 5937 | aom_malloc(sizeof(uint32_t) * pic_width * pic_height)); |
| 5938 | } |
| 5939 | |
| 5940 | for (j = 0; j < 3; j++) { |
| 5941 | CHECK_MEM_ERROR(cm, is_block_same[k][j], |
| 5942 | aom_malloc(sizeof(int8_t) * pic_width * pic_height)); |
| 5943 | } |
| 5944 | } |
| 5945 | |
| 5946 | av1_hash_table_create(&cm->cur_frame->hash_table); |
| 5947 | av1_generate_block_2x2_hash_value(cpi->source, block_hash_values[0], |
| 5948 | is_block_same[0]); |
| 5949 | av1_generate_block_hash_value(cpi->source, 4, block_hash_values[0], |
| 5950 | block_hash_values[1], is_block_same[0], |
| 5951 | is_block_same[1]); |
| 5952 | av1_generate_block_hash_value(cpi->source, 8, block_hash_values[1], |
| 5953 | block_hash_values[0], is_block_same[1], |
| 5954 | is_block_same[0]); |
| 5955 | av1_add_to_hash_map_by_row_with_precal_data( |
| 5956 | &cm->cur_frame->hash_table, block_hash_values[0], is_block_same[0][2], |
| 5957 | pic_width, pic_height, 8); |
| 5958 | av1_generate_block_hash_value(cpi->source, 16, block_hash_values[0], |
| 5959 | block_hash_values[1], is_block_same[0], |
| 5960 | is_block_same[1]); |
| 5961 | av1_add_to_hash_map_by_row_with_precal_data( |
| 5962 | &cm->cur_frame->hash_table, block_hash_values[1], is_block_same[1][2], |
| 5963 | pic_width, pic_height, 16); |
| 5964 | av1_generate_block_hash_value(cpi->source, 32, block_hash_values[1], |
| 5965 | block_hash_values[0], is_block_same[1], |
| 5966 | is_block_same[0]); |
| 5967 | av1_add_to_hash_map_by_row_with_precal_data( |
| 5968 | &cm->cur_frame->hash_table, block_hash_values[0], is_block_same[0][2], |
| 5969 | pic_width, pic_height, 32); |
| 5970 | av1_generate_block_hash_value(cpi->source, 64, block_hash_values[0], |
| 5971 | block_hash_values[1], is_block_same[0], |
| 5972 | is_block_same[1]); |
| 5973 | av1_add_to_hash_map_by_row_with_precal_data( |
| 5974 | &cm->cur_frame->hash_table, block_hash_values[1], is_block_same[1][2], |
| 5975 | pic_width, pic_height, 64); |
| 5976 | |
| 5977 | for (k = 0; k < 2; k++) { |
| 5978 | for (j = 0; j < 2; j++) { |
| 5979 | aom_free(block_hash_values[k][j]); |
| 5980 | } |
| 5981 | |
| 5982 | for (j = 0; j < 3; j++) { |
| 5983 | aom_free(is_block_same[k][j]); |
| 5984 | } |
| 5985 | } |
| 5986 | } |
| 5987 | |
| 5988 | #endif |
| 5989 | |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 5990 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 5991 | cm->frame_contexts[cm->new_fb_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 5992 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5993 | if (!cm->error_resilient_mode) |
| 5994 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 5995 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5996 | |
| 5997 | // No frame encoded, or frame was dropped, release scaled references. |
| 5998 | if ((*size == 0) && (frame_is_intra_only(cm) == 0)) { |
| 5999 | release_scaled_references(cpi); |
| 6000 | } |
| 6001 | |
| 6002 | if (*size > 0) { |
| 6003 | cpi->droppable = !frame_is_reference(cpi); |
| 6004 | } |
| 6005 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6006 | aom_usec_timer_mark(&cmptimer); |
| 6007 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6008 | |
| 6009 | if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame) |
| 6010 | generate_psnr_packet(cpi); |
| 6011 | |
| 6012 | #if CONFIG_INTERNAL_STATS |
| 6013 | if (oxcf->pass != 1) { |
Angie Chiang | 08a22a6 | 2017-07-17 17:29:17 -0700 | [diff] [blame] | 6014 | compute_internal_stats(cpi, (int)(*size)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6015 | } |
| 6016 | #endif // CONFIG_INTERNAL_STATS |
| 6017 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 6018 | #if CONFIG_XIPHRC |
| 6019 | cpi->od_rc.cur_frame++; |
| 6020 | #endif |
| 6021 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6022 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6023 | |
| 6024 | return 0; |
| 6025 | } |
| 6026 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6027 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 6028 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6029 | if (!cm->show_frame) { |
| 6030 | return -1; |
| 6031 | } else { |
| 6032 | int ret; |
| 6033 | if (cm->frame_to_show) { |
| 6034 | *dest = *cm->frame_to_show; |
| 6035 | dest->y_width = cm->width; |
| 6036 | dest->y_height = cm->height; |
| 6037 | dest->uv_width = cm->width >> cm->subsampling_x; |
| 6038 | dest->uv_height = cm->height >> cm->subsampling_y; |
| 6039 | ret = 0; |
| 6040 | } else { |
| 6041 | ret = -1; |
| 6042 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6043 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6044 | return ret; |
| 6045 | } |
| 6046 | } |
| 6047 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6048 | 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] | 6049 | if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1; |
| 6050 | |
| 6051 | *frame = |
| 6052 | cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf; |
| 6053 | return 0; |
| 6054 | } |
| 6055 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6056 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 6057 | AOM_SCALING vert_mode) { |
| 6058 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6059 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 6060 | |
| 6061 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 6062 | |
| 6063 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 6064 | Scale2Ratio(vert_mode, &vr, &vs); |
| 6065 | |
| 6066 | // always go to the next whole number |
| 6067 | cm->width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 6068 | cm->height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
| 6069 | assert(cm->width <= cpi->initial_width); |
| 6070 | assert(cm->height <= cpi->initial_height); |
| 6071 | |
| 6072 | update_frame_size(cpi); |
| 6073 | |
| 6074 | return 0; |
| 6075 | } |
| 6076 | |
Fergus Simpson | 0a30c88 | 2017-05-16 16:54:51 -0700 | [diff] [blame] | 6077 | int av1_set_size_literal(AV1_COMP *cpi, int width, int height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6078 | AV1_COMMON *cm = &cpi->common; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6079 | #if CONFIG_HIGHBITDEPTH |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 6080 | check_initial_width(cpi, cm->use_highbitdepth, cm->subsampling_x, |
| 6081 | cm->subsampling_y); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6082 | #else |
Debargha Mukherjee | 887069f | 2017-06-16 18:54:36 -0700 | [diff] [blame] | 6083 | check_initial_width(cpi, cm->subsampling_x, cm->subsampling_y); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 6084 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6085 | |
Fergus Simpson | 0a30c88 | 2017-05-16 16:54:51 -0700 | [diff] [blame] | 6086 | if (width <= 0 || height <= 0) return 1; |
| 6087 | |
| 6088 | cm->width = width; |
| 6089 | if (cm->width > cpi->initial_width) { |
| 6090 | cm->width = cpi->initial_width; |
| 6091 | printf("Warning: Desired width too large, changed to %d\n", cm->width); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6092 | } |
| 6093 | |
Fergus Simpson | 0a30c88 | 2017-05-16 16:54:51 -0700 | [diff] [blame] | 6094 | cm->height = height; |
| 6095 | if (cm->height > cpi->initial_height) { |
| 6096 | cm->height = cpi->initial_height; |
| 6097 | printf("Warning: Desired height too large, changed to %d\n", cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6098 | } |
Fergus Simpson | 0a30c88 | 2017-05-16 16:54:51 -0700 | [diff] [blame] | 6099 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6100 | assert(cm->width <= cpi->initial_width); |
| 6101 | assert(cm->height <= cpi->initial_height); |
| 6102 | |
| 6103 | update_frame_size(cpi); |
| 6104 | |
| 6105 | return 0; |
| 6106 | } |
| 6107 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6108 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6109 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6110 | 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] | 6111 | if (flags & |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6112 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF)) { |
| 6113 | int ref = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6114 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6115 | if (flags & AOM_EFLAG_NO_REF_LAST) { |
| 6116 | ref ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6117 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6118 | ref ^= AOM_LAST2_FLAG; |
| 6119 | ref ^= AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6120 | #endif // CONFIG_EXT_REFS |
| 6121 | } |
| 6122 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6123 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6124 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6125 | if (flags & AOM_EFLAG_NO_REF_ARF) ref ^= AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6126 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6127 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6128 | } |
| 6129 | |
| 6130 | if (flags & |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6131 | (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF | |
| 6132 | AOM_EFLAG_FORCE_GF | AOM_EFLAG_FORCE_ARF)) { |
| 6133 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6134 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6135 | if (flags & AOM_EFLAG_NO_UPD_LAST) { |
| 6136 | upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6137 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6138 | upd ^= AOM_LAST2_FLAG; |
| 6139 | upd ^= AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6140 | #endif // CONFIG_EXT_REFS |
| 6141 | } |
| 6142 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6143 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6144 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6145 | if (flags & AOM_EFLAG_NO_UPD_ARF) upd ^= AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6146 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6147 | av1_update_reference(cpi, upd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6148 | } |
| 6149 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 6150 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 6151 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 6152 | } |
| 6153 | } |