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" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 21 | #include "av1/common/clpf.h" |
Jean-Marc Valin | 0143513 | 2017-02-18 14:12:53 -0500 | [diff] [blame] | 22 | #endif // CONFIG_CDEF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 23 | #include "av1/common/filter.h" |
| 24 | #include "av1/common/idct.h" |
| 25 | #include "av1/common/reconinter.h" |
| 26 | #include "av1/common/reconintra.h" |
Fergus Simpson | d056500 | 2017-03-27 16:51:52 -0700 | [diff] [blame] | 27 | #include "av1/common/resize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 28 | #include "av1/common/tile_common.h" |
| 29 | |
| 30 | #include "av1/encoder/aq_complexity.h" |
| 31 | #include "av1/encoder/aq_cyclicrefresh.h" |
| 32 | #include "av1/encoder/aq_variance.h" |
| 33 | #include "av1/encoder/bitstream.h" |
| 34 | #if CONFIG_ANS |
Alex Converse | 1ac1ae7 | 2016-09-17 15:11:16 -0700 | [diff] [blame] | 35 | #include "aom_dsp/buf_ans.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 36 | #endif |
| 37 | #include "av1/encoder/context_tree.h" |
| 38 | #include "av1/encoder/encodeframe.h" |
| 39 | #include "av1/encoder/encodemv.h" |
| 40 | #include "av1/encoder/encoder.h" |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 41 | #if CONFIG_LV_MAP |
| 42 | #include "av1/encoder/encodetxb.h" |
| 43 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 44 | #include "av1/encoder/ethread.h" |
| 45 | #include "av1/encoder/firstpass.h" |
| 46 | #include "av1/encoder/mbgraph.h" |
| 47 | #include "av1/encoder/picklpf.h" |
| 48 | #if CONFIG_LOOP_RESTORATION |
| 49 | #include "av1/encoder/pickrst.h" |
| 50 | #endif // CONFIG_LOOP_RESTORATION |
| 51 | #include "av1/encoder/ratectrl.h" |
| 52 | #include "av1/encoder/rd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 53 | #include "av1/encoder/segmentation.h" |
| 54 | #include "av1/encoder/speed_features.h" |
| 55 | #include "av1/encoder/temporal_filter.h" |
| 56 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 57 | #include "./av1_rtcd.h" |
| 58 | #include "./aom_dsp_rtcd.h" |
| 59 | #include "./aom_scale_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 60 | #include "aom_dsp/psnr.h" |
| 61 | #if CONFIG_INTERNAL_STATS |
| 62 | #include "aom_dsp/ssim.h" |
| 63 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 64 | #include "aom_dsp/aom_dsp_common.h" |
| 65 | #include "aom_dsp/aom_filter.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 66 | #include "aom_ports/aom_timer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 67 | #include "aom_ports/mem.h" |
| 68 | #include "aom_ports/system_state.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 69 | #include "aom_scale/aom_scale.h" |
Angie Chiang | 6062a8b | 2016-09-21 16:01:04 -0700 | [diff] [blame] | 70 | #if CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 71 | #include "aom_util/debug_util.h" |
Angie Chiang | 6062a8b | 2016-09-21 16:01:04 -0700 | [diff] [blame] | 72 | #endif // CONFIG_BITSTREAM_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 73 | |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 74 | #if CONFIG_ENTROPY_STATS |
| 75 | FRAME_COUNTS aggregate_fc; |
| 76 | #endif // CONFIG_ENTROPY_STATS |
| 77 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 78 | #define AM_SEGMENT_ID_INACTIVE 7 |
| 79 | #define AM_SEGMENT_ID_ACTIVE 0 |
| 80 | |
| 81 | #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ |
| 82 | |
| 83 | #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv |
| 84 | // for altref computation. |
| 85 | #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision |
| 86 | // mv. Choose a very high value for |
| 87 | // now so that HIGH_PRECISION is always |
| 88 | // chosen. |
| 89 | // #define OUTPUT_YUV_REC |
| 90 | #ifdef OUTPUT_YUV_DENOISED |
| 91 | FILE *yuv_denoised_file = NULL; |
| 92 | #endif |
| 93 | #ifdef OUTPUT_YUV_SKINMAP |
| 94 | FILE *yuv_skinmap_file = NULL; |
| 95 | #endif |
| 96 | #ifdef OUTPUT_YUV_REC |
| 97 | FILE *yuv_rec_file; |
| 98 | #define FILE_NAME_LEN 100 |
| 99 | #endif |
| 100 | |
| 101 | #if 0 |
| 102 | FILE *framepsnr; |
| 103 | FILE *kf_list; |
| 104 | FILE *keyfile; |
| 105 | #endif |
| 106 | |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 107 | #if CONFIG_CFL |
| 108 | CFL_CTX NULL_CFL; |
| 109 | #endif |
| 110 | |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 111 | #if CONFIG_INTERNAL_STATS |
| 112 | typedef enum { Y, U, V, ALL } STAT_TYPE; |
| 113 | #endif // CONFIG_INTERNAL_STATS |
| 114 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 115 | static INLINE void Scale2Ratio(AOM_SCALING mode, int *hr, int *hs) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 116 | switch (mode) { |
| 117 | case NORMAL: |
| 118 | *hr = 1; |
| 119 | *hs = 1; |
| 120 | break; |
| 121 | case FOURFIVE: |
| 122 | *hr = 4; |
| 123 | *hs = 5; |
| 124 | break; |
| 125 | case THREEFIVE: |
| 126 | *hr = 3; |
| 127 | *hs = 5; |
| 128 | break; |
| 129 | case ONETWO: |
| 130 | *hr = 1; |
| 131 | *hs = 2; |
| 132 | break; |
| 133 | default: |
| 134 | *hr = 1; |
| 135 | *hs = 1; |
| 136 | assert(0); |
| 137 | break; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | // Mark all inactive blocks as active. Other segmentation features may be set |
| 142 | // so memset cannot be used, instead only inactive blocks should be reset. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 143 | static void suppress_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 144 | unsigned char *const seg_map = cpi->segmentation_map; |
| 145 | int i; |
| 146 | if (cpi->active_map.enabled || cpi->active_map.update) |
| 147 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 148 | if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) |
| 149 | seg_map[i] = AM_SEGMENT_ID_ACTIVE; |
| 150 | } |
| 151 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 152 | static void apply_active_map(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 153 | struct segmentation *const seg = &cpi->common.seg; |
| 154 | unsigned char *const seg_map = cpi->segmentation_map; |
| 155 | const unsigned char *const active_map = cpi->active_map.map; |
| 156 | int i; |
| 157 | |
| 158 | assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE); |
| 159 | |
| 160 | if (frame_is_intra_only(&cpi->common)) { |
| 161 | cpi->active_map.enabled = 0; |
| 162 | cpi->active_map.update = 1; |
| 163 | } |
| 164 | |
| 165 | if (cpi->active_map.update) { |
| 166 | if (cpi->active_map.enabled) { |
| 167 | for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) |
| 168 | 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] | 169 | av1_enable_segmentation(seg); |
| 170 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
| 171 | av1_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 172 | // Setting the data to -MAX_LOOP_FILTER will result in the computed loop |
| 173 | // filter level being zero regardless of the value of seg->abs_delta. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 174 | av1_set_segdata(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF, |
| 175 | -MAX_LOOP_FILTER); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 176 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 177 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP); |
| 178 | av1_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 179 | if (seg->enabled) { |
| 180 | seg->update_data = 1; |
| 181 | seg->update_map = 1; |
| 182 | } |
| 183 | } |
| 184 | cpi->active_map.update = 0; |
| 185 | } |
| 186 | } |
| 187 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 188 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 189 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 190 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
| 191 | unsigned char *const active_map_8x8 = cpi->active_map.map; |
| 192 | const int mi_rows = cpi->common.mi_rows; |
| 193 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 194 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 195 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 196 | cpi->active_map.update = 1; |
| 197 | if (new_map_16x16) { |
| 198 | int r, c; |
| 199 | for (r = 0; r < mi_rows; ++r) { |
| 200 | for (c = 0; c < mi_cols; ++c) { |
| 201 | active_map_8x8[r * mi_cols + c] = |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 202 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 203 | ? AM_SEGMENT_ID_ACTIVE |
| 204 | : AM_SEGMENT_ID_INACTIVE; |
| 205 | } |
| 206 | } |
| 207 | cpi->active_map.enabled = 1; |
| 208 | } else { |
| 209 | cpi->active_map.enabled = 0; |
| 210 | } |
| 211 | return 0; |
| 212 | } else { |
| 213 | return -1; |
| 214 | } |
| 215 | } |
| 216 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 217 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *new_map_16x16, int rows, |
| 218 | int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 219 | if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols && |
| 220 | new_map_16x16) { |
| 221 | unsigned char *const seg_map_8x8 = cpi->segmentation_map; |
| 222 | const int mi_rows = cpi->common.mi_rows; |
| 223 | const int mi_cols = cpi->common.mi_cols; |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 224 | const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2; |
| 225 | const int col_scale = mi_size_wide[BLOCK_16X16] == 2 ? 1 : 2; |
| 226 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 227 | memset(new_map_16x16, !cpi->active_map.enabled, rows * cols); |
| 228 | if (cpi->active_map.enabled) { |
| 229 | int r, c; |
| 230 | for (r = 0; r < mi_rows; ++r) { |
| 231 | for (c = 0; c < mi_cols; ++c) { |
| 232 | // Cyclic refresh segments are considered active despite not having |
| 233 | // AM_SEGMENT_ID_ACTIVE |
Jingning Han | 9d53302 | 2017-04-07 10:14:42 -0700 | [diff] [blame] | 234 | new_map_16x16[(r >> row_scale) * cols + (c >> col_scale)] |= |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 235 | seg_map_8x8[r * mi_cols + c] != AM_SEGMENT_ID_INACTIVE; |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | return 0; |
| 240 | } else { |
| 241 | return -1; |
| 242 | } |
| 243 | } |
| 244 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 245 | void av1_set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 246 | MACROBLOCK *const mb = &cpi->td.mb; |
| 247 | cpi->common.allow_high_precision_mv = allow_high_precision_mv; |
| 248 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 249 | if (cpi->common.allow_high_precision_mv) { |
| 250 | int i; |
| 251 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 252 | mb->mv_cost_stack[i] = mb->nmvcost_hp[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 253 | } |
| 254 | } else { |
| 255 | int i; |
| 256 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 257 | mb->mv_cost_stack[i] = mb->nmvcost[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 258 | } |
| 259 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 262 | static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 263 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 264 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_64X64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 265 | return BLOCK_64X64; |
| 266 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 267 | if (cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_128X128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 268 | return BLOCK_128X128; |
| 269 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 270 | assert(cpi->oxcf.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 271 | |
| 272 | assert(IMPLIES(cpi->common.tile_cols > 1, |
| 273 | cpi->common.tile_width % MAX_MIB_SIZE == 0)); |
| 274 | assert(IMPLIES(cpi->common.tile_rows > 1, |
| 275 | cpi->common.tile_height % MAX_MIB_SIZE == 0)); |
| 276 | |
| 277 | // TODO(any): Possibly could improve this with a heuristic. |
| 278 | return BLOCK_128X128; |
| 279 | #else |
| 280 | (void)cpi; |
| 281 | return BLOCK_64X64; |
| 282 | #endif // CONFIG_EXT_PARTITION |
| 283 | } |
| 284 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 285 | static void setup_frame(AV1_COMP *cpi) { |
| 286 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 287 | // Set up entropy context depending on frame type. The decoder mandates |
| 288 | // the use of the default context, index 0, for keyframes and inter |
| 289 | // frames where the error_resilient_mode or intra_only flag is set. For |
| 290 | // other inter-frames the encoder currently uses only two contexts; |
| 291 | // context 1 for ALTREF frames and context 0 for the others. |
| 292 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 293 | av1_setup_past_independence(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 294 | } else { |
| 295 | #if CONFIG_EXT_REFS |
| 296 | const GF_GROUP *gf_group = &cpi->twopass.gf_group; |
| 297 | if (gf_group->rf_level[gf_group->index] == GF_ARF_LOW) |
| 298 | cm->frame_context_idx = EXT_ARF_FRAME; |
| 299 | else if (cpi->refresh_alt_ref_frame) |
| 300 | cm->frame_context_idx = ARF_FRAME; |
| 301 | #else |
| 302 | if (cpi->refresh_alt_ref_frame) cm->frame_context_idx = ARF_FRAME; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 303 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 304 | else if (cpi->rc.is_src_frame_alt_ref) |
| 305 | cm->frame_context_idx = OVERLAY_FRAME; |
| 306 | else if (cpi->refresh_golden_frame) |
| 307 | cm->frame_context_idx = GLD_FRAME; |
| 308 | #if CONFIG_EXT_REFS |
| 309 | else if (cpi->refresh_bwd_ref_frame) |
| 310 | cm->frame_context_idx = BRF_FRAME; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 311 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 312 | else |
| 313 | cm->frame_context_idx = REGULAR_FRAME; |
| 314 | } |
| 315 | |
| 316 | if (cm->frame_type == KEY_FRAME) { |
| 317 | cpi->refresh_golden_frame = 1; |
| 318 | cpi->refresh_alt_ref_frame = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 319 | av1_zero(cpi->interp_filter_selected); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 320 | } else { |
| 321 | *cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 322 | av1_zero(cpi->interp_filter_selected[0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 323 | } |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 324 | #if CONFIG_EXT_REFS |
Arild Fuldseth (arilfuld) | 78bfc28 | 2017-05-24 12:06:35 +0200 | [diff] [blame] | 325 | #if CONFIG_ONE_SIDED_COMPOUND // No change to bitstream |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 326 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 327 | cpi->refresh_bwd_ref_frame = cpi->refresh_last_frame; |
| 328 | cpi->rc.is_bipred_frame = 1; |
| 329 | } |
| 330 | #endif |
| 331 | #endif |
Thomas Daede | 10e1da9 | 2017-04-26 13:22:21 -0700 | [diff] [blame] | 332 | cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 333 | |
| 334 | cpi->vaq_refresh = 0; |
| 335 | |
| 336 | set_sb_size(cm, select_sb_size(cpi)); |
| 337 | } |
| 338 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 339 | static void av1_enc_setup_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 340 | int i; |
| 341 | cm->mi = cm->mip + cm->mi_stride + 1; |
| 342 | memset(cm->mip, 0, cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip)); |
| 343 | cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 344 | // Clear top border row |
| 345 | memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride); |
| 346 | // Clear left border column |
| 347 | for (i = 1; i < cm->mi_rows + 1; ++i) |
| 348 | memset(&cm->prev_mip[i * cm->mi_stride], 0, sizeof(*cm->prev_mip)); |
| 349 | |
| 350 | cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; |
| 351 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; |
| 352 | |
| 353 | memset(cm->mi_grid_base, 0, |
| 354 | cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mi_grid_base)); |
| 355 | } |
| 356 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 357 | static int av1_enc_alloc_mi(AV1_COMMON *cm, int mi_size) { |
| 358 | cm->mip = aom_calloc(mi_size, sizeof(*cm->mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 359 | if (!cm->mip) return 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 360 | cm->prev_mip = aom_calloc(mi_size, sizeof(*cm->prev_mip)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 361 | if (!cm->prev_mip) return 1; |
| 362 | cm->mi_alloc_size = mi_size; |
| 363 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 364 | 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] | 365 | if (!cm->mi_grid_base) return 1; |
| 366 | cm->prev_mi_grid_base = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 367 | (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 368 | if (!cm->prev_mi_grid_base) return 1; |
| 369 | |
| 370 | return 0; |
| 371 | } |
| 372 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 373 | static void av1_enc_free_mi(AV1_COMMON *cm) { |
| 374 | aom_free(cm->mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 375 | cm->mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 376 | aom_free(cm->prev_mip); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 377 | cm->prev_mip = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 378 | aom_free(cm->mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 379 | cm->mi_grid_base = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 380 | aom_free(cm->prev_mi_grid_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 381 | cm->prev_mi_grid_base = NULL; |
| 382 | } |
| 383 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 384 | static void av1_swap_mi_and_prev_mi(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 385 | // Current mip will be the prev_mip for the next frame. |
| 386 | MODE_INFO **temp_base = cm->prev_mi_grid_base; |
| 387 | MODE_INFO *temp = cm->prev_mip; |
| 388 | cm->prev_mip = cm->mip; |
| 389 | cm->mip = temp; |
| 390 | |
| 391 | // Update the upper left visible macroblock ptrs. |
| 392 | cm->mi = cm->mip + cm->mi_stride + 1; |
| 393 | cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 394 | |
| 395 | cm->prev_mi_grid_base = cm->mi_grid_base; |
| 396 | cm->mi_grid_base = temp_base; |
| 397 | cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1; |
| 398 | cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mi_stride + 1; |
| 399 | } |
| 400 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 401 | void av1_initialize_enc(void) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 402 | static volatile int init_done = 0; |
| 403 | |
| 404 | if (!init_done) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 405 | av1_rtcd(); |
| 406 | aom_dsp_rtcd(); |
| 407 | aom_scale_rtcd(); |
| 408 | av1_init_intra_predictors(); |
| 409 | av1_init_me_luts(); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 410 | #if !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 411 | av1_rc_init_minq_luts(); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 412 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 413 | av1_entropy_mv_init(); |
| 414 | av1_encode_token_init(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 415 | #if CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 416 | av1_init_wedge_masks(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 417 | #endif |
| 418 | init_done = 1; |
| 419 | } |
| 420 | } |
| 421 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 422 | static void dealloc_compressor_data(AV1_COMP *cpi) { |
| 423 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 424 | int i; |
| 425 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 426 | aom_free(cpi->mbmi_ext_base); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 427 | cpi->mbmi_ext_base = NULL; |
| 428 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 429 | #if CONFIG_PVQ |
| 430 | if (cpi->oxcf.pass != 1) { |
Yushin Cho | 749c057 | 2017-04-07 10:36:47 -0700 | [diff] [blame] | 431 | const int tile_cols = cm->tile_cols; |
| 432 | const int tile_rows = cm->tile_rows; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 433 | int tile_col, tile_row; |
| 434 | |
| 435 | for (tile_row = 0; tile_row < tile_rows; ++tile_row) |
| 436 | for (tile_col = 0; tile_col < tile_cols; ++tile_col) { |
| 437 | TileDataEnc *tile_data = |
| 438 | &cpi->tile_data[tile_row * tile_cols + tile_col]; |
| 439 | aom_free(tile_data->pvq_q.buf); |
| 440 | } |
| 441 | } |
| 442 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 443 | aom_free(cpi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 444 | cpi->tile_data = NULL; |
| 445 | |
| 446 | // Delete sementation map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 447 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 448 | cpi->segmentation_map = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 449 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 450 | av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 451 | cpi->cyclic_refresh = NULL; |
| 452 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 453 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 454 | cpi->active_map.map = NULL; |
| 455 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 456 | #if CONFIG_MOTION_VAR |
| 457 | aom_free(cpi->td.mb.above_pred_buf); |
| 458 | cpi->td.mb.above_pred_buf = NULL; |
| 459 | |
| 460 | aom_free(cpi->td.mb.left_pred_buf); |
| 461 | cpi->td.mb.left_pred_buf = NULL; |
| 462 | |
| 463 | aom_free(cpi->td.mb.wsrc_buf); |
| 464 | cpi->td.mb.wsrc_buf = NULL; |
| 465 | |
| 466 | aom_free(cpi->td.mb.mask_buf); |
| 467 | cpi->td.mb.mask_buf = NULL; |
| 468 | #endif |
| 469 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 470 | // Free up-sampled reference buffers. |
| 471 | for (i = 0; i < (REF_FRAMES + 1); i++) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 472 | aom_free_frame_buffer(&cpi->upsampled_ref_bufs[i].buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 473 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 474 | av1_free_ref_frame_buffers(cm->buffer_pool); |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 475 | #if CONFIG_LV_MAP |
| 476 | av1_free_txb_buf(cpi); |
| 477 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 478 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 479 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 480 | aom_free_frame_buffer(&cpi->last_frame_uf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 481 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 482 | av1_free_restoration_buffers(cm); |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 483 | aom_free_frame_buffer(&cpi->last_frame_db); |
| 484 | aom_free_frame_buffer(&cpi->trial_frame_rst); |
| 485 | aom_free(cpi->extra_rstbuf); |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 486 | for (i = 0; i < MAX_MB_PLANE; ++i) |
| 487 | av1_free_restoration_struct(&cpi->rst_search[i]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 488 | #endif // CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 489 | aom_free_frame_buffer(&cpi->scaled_source); |
| 490 | aom_free_frame_buffer(&cpi->scaled_last_source); |
| 491 | aom_free_frame_buffer(&cpi->alt_ref_buffer); |
| 492 | av1_lookahead_destroy(cpi->lookahead); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 493 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 494 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 495 | cpi->tile_tok[0][0] = 0; |
| 496 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 497 | av1_free_pc_tree(&cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 498 | |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 499 | #if CONFIG_PALETTE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 500 | if (cpi->common.allow_screen_content_tools) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 501 | aom_free(cpi->td.mb.palette_buffer); |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 502 | #endif // CONFIG_PALETTE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 503 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 504 | #if CONFIG_ANS |
Alex Converse | 1ac1ae7 | 2016-09-17 15:11:16 -0700 | [diff] [blame] | 505 | aom_buf_ans_free(&cpi->buf_ans); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 506 | #endif // CONFIG_ANS |
| 507 | } |
| 508 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 509 | static void save_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 510 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 511 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 512 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 513 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 514 | // Stores a snapshot of key state variables which can subsequently be |
| 515 | // restored with a call to av1_restore_coding_context. These functions are |
| 516 | // intended for use in a re-code loop in av1_compress_frame where the |
| 517 | // quantizer value is adjusted between loop iterations. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 518 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 519 | av1_copy(cc->nmv_vec_cost[i], cpi->td.mb.nmv_vec_cost[i]); |
Urvang Joshi | bffc0b5 | 2016-07-25 13:38:49 -0700 | [diff] [blame] | 520 | av1_copy(cc->nmv_costs, cpi->nmv_costs); |
| 521 | av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 522 | } |
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 | av1_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); |
| 525 | av1_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 526 | |
| 527 | cc->fc = *cm->fc; |
| 528 | } |
| 529 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 530 | static void restore_coding_context(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 531 | CODING_CONTEXT *const cc = &cpi->coding_context; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 532 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 533 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 534 | |
Sebastien Alaiwan | e140c50 | 2017-04-27 09:52:34 +0200 | [diff] [blame] | 535 | // Restore key state variables to the snapshot state stored in the |
| 536 | // previous call to av1_save_coding_context. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 537 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 538 | av1_copy(cpi->td.mb.nmv_vec_cost[i], cc->nmv_vec_cost[i]); |
Urvang Joshi | bffc0b5 | 2016-07-25 13:38:49 -0700 | [diff] [blame] | 539 | av1_copy(cpi->nmv_costs, cc->nmv_costs); |
| 540 | av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 541 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 542 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 543 | av1_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); |
| 544 | av1_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 545 | |
| 546 | *cm->fc = cc->fc; |
| 547 | } |
| 548 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 549 | static void configure_static_seg_features(AV1_COMP *cpi) { |
| 550 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 551 | const RATE_CONTROL *const rc = &cpi->rc; |
| 552 | struct segmentation *const seg = &cm->seg; |
| 553 | |
| 554 | int high_q = (int)(rc->avg_q > 48.0); |
| 555 | int qi_delta; |
| 556 | |
| 557 | // Disable and clear down for KF |
| 558 | if (cm->frame_type == KEY_FRAME) { |
| 559 | // Clear down the global segmentation map |
| 560 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 561 | seg->update_map = 0; |
| 562 | seg->update_data = 0; |
| 563 | cpi->static_mb_pct = 0; |
| 564 | |
| 565 | // Disable segmentation |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 566 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 567 | |
| 568 | // Clear down the segment features. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 569 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 570 | } else if (cpi->refresh_alt_ref_frame) { |
| 571 | // If this is an alt ref frame |
| 572 | // Clear down the global segmentation map |
| 573 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 574 | seg->update_map = 0; |
| 575 | seg->update_data = 0; |
| 576 | cpi->static_mb_pct = 0; |
| 577 | |
| 578 | // Disable segmentation and individual segment features by default |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 579 | av1_disable_segmentation(seg); |
| 580 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 581 | |
| 582 | // Scan frames from current to arf frame. |
| 583 | // This function re-enables segmentation if appropriate. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 584 | av1_update_mbgraph_stats(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 585 | |
| 586 | // If segmentation was enabled set those features needed for the |
| 587 | // arf itself. |
| 588 | if (seg->enabled) { |
| 589 | seg->update_map = 1; |
| 590 | seg->update_data = 1; |
| 591 | |
| 592 | qi_delta = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 593 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875, cm->bit_depth); |
| 594 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
| 595 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 596 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 597 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
| 598 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 599 | |
| 600 | // Where relevant assume segment data is delta data |
| 601 | seg->abs_delta = SEGMENT_DELTADATA; |
| 602 | } |
| 603 | } else if (seg->enabled) { |
| 604 | // All other frames if segmentation has been enabled |
| 605 | |
| 606 | // First normal frame in a valid gf or alt ref group |
| 607 | if (rc->frames_since_golden == 0) { |
| 608 | // Set up segment features for normal frames in an arf group |
| 609 | if (rc->source_alt_ref_active) { |
| 610 | seg->update_map = 0; |
| 611 | seg->update_data = 1; |
| 612 | seg->abs_delta = SEGMENT_DELTADATA; |
| 613 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 614 | qi_delta = |
| 615 | av1_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125, cm->bit_depth); |
| 616 | av1_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
| 617 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 618 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 619 | av1_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
| 620 | av1_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 621 | |
| 622 | // Segment coding disabled for compred testing |
| 623 | if (high_q || (cpi->static_mb_pct == 100)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 624 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 625 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
| 626 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 627 | } |
| 628 | } else { |
| 629 | // Disable segmentation and clear down features if alt ref |
| 630 | // is not active for this group |
| 631 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 632 | av1_disable_segmentation(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 633 | |
| 634 | memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 635 | |
| 636 | seg->update_map = 0; |
| 637 | seg->update_data = 0; |
| 638 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 639 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 640 | } |
| 641 | } else if (rc->is_src_frame_alt_ref) { |
| 642 | // Special case where we are coding over the top of a previous |
| 643 | // alt ref frame. |
| 644 | // Segment coding disabled for compred testing |
| 645 | |
| 646 | // Enable ref frame features for segment 0 as well |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 647 | av1_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
| 648 | av1_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 649 | |
| 650 | // All mbs should use ALTREF_FRAME |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 651 | av1_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
| 652 | av1_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
| 653 | av1_clear_segdata(seg, 1, SEG_LVL_REF_FRAME); |
| 654 | av1_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 655 | |
| 656 | // Skip all MBs if high Q (0,0 mv and skip coeffs) |
| 657 | if (high_q) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 658 | av1_enable_segfeature(seg, 0, SEG_LVL_SKIP); |
| 659 | av1_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 660 | } |
| 661 | // Enable data update |
| 662 | seg->update_data = 1; |
| 663 | } else { |
| 664 | // All other frames. |
| 665 | |
| 666 | // No updates.. leave things as they are. |
| 667 | seg->update_map = 0; |
| 668 | seg->update_data = 0; |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 673 | static void update_reference_segmentation_map(AV1_COMP *cpi) { |
| 674 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 675 | MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible; |
| 676 | uint8_t *cache_ptr = cm->last_frame_seg_map; |
| 677 | int row, col; |
| 678 | |
| 679 | for (row = 0; row < cm->mi_rows; row++) { |
| 680 | MODE_INFO **mi_8x8 = mi_8x8_ptr; |
| 681 | uint8_t *cache = cache_ptr; |
| 682 | for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) |
| 683 | cache[0] = mi_8x8[0]->mbmi.segment_id; |
| 684 | mi_8x8_ptr += cm->mi_stride; |
| 685 | cache_ptr += cm->mi_cols; |
| 686 | } |
| 687 | } |
| 688 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 689 | static void alloc_raw_frame_buffers(AV1_COMP *cpi) { |
| 690 | AV1_COMMON *cm = &cpi->common; |
| 691 | const AV1EncoderConfig *oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 692 | |
| 693 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 694 | cpi->lookahead = av1_lookahead_init(oxcf->width, oxcf->height, |
| 695 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 696 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 697 | cm->use_highbitdepth, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 698 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 699 | oxcf->lag_in_frames); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 700 | if (!cpi->lookahead) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 701 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 702 | "Failed to allocate lag buffers"); |
| 703 | |
| 704 | // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 705 | 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] | 706 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 707 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 708 | cm->use_highbitdepth, |
| 709 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 710 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 711 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 712 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 713 | "Failed to allocate altref buffer"); |
| 714 | } |
| 715 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 716 | static void alloc_util_frame_buffers(AV1_COMP *cpi) { |
| 717 | AV1_COMMON *const cm = &cpi->common; |
| 718 | 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] | 719 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 720 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 721 | cm->use_highbitdepth, |
| 722 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 723 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 724 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 725 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 726 | "Failed to allocate last frame buffer"); |
| 727 | |
| 728 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 729 | 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] | 730 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 731 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 732 | cm->use_highbitdepth, |
| 733 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 734 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 735 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 736 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 737 | "Failed to allocate last frame deblocked buffer"); |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame^] | 738 | if (aom_realloc_frame_buffer( |
| 739 | &cpi->trial_frame_rst, |
| 740 | #if CONFIG_FRAME_SUPERRES |
| 741 | cm->superres_upscaled_width, cm->superres_upscaled_height, |
| 742 | #else |
| 743 | cm->width, cm->height, |
| 744 | #endif // CONFIG_FRAME_SUPERRES |
| 745 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 746 | #if CONFIG_HIGHBITDEPTH |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame^] | 747 | cm->use_highbitdepth, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 748 | #endif |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame^] | 749 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 750 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 751 | "Failed to allocate trial restored frame buffer"); |
Alex Converse | 232e384 | 2017-02-24 12:24:36 -0800 | [diff] [blame] | 752 | int extra_rstbuf_sz = RESTORATION_EXTBUF_SIZE; |
Debargha Mukherjee | b3c43bc | 2017-02-01 13:09:03 -0800 | [diff] [blame] | 753 | if (extra_rstbuf_sz > 0) { |
Alex Converse | 7f094f1 | 2017-02-23 17:29:40 -0800 | [diff] [blame] | 754 | aom_free(cpi->extra_rstbuf); |
Alex Converse | 232e384 | 2017-02-24 12:24:36 -0800 | [diff] [blame] | 755 | CHECK_MEM_ERROR(cm, cpi->extra_rstbuf, |
Alex Converse | 7f094f1 | 2017-02-23 17:29:40 -0800 | [diff] [blame] | 756 | (uint8_t *)aom_malloc(extra_rstbuf_sz)); |
Debargha Mukherjee | b3c43bc | 2017-02-01 13:09:03 -0800 | [diff] [blame] | 757 | } else { |
| 758 | cpi->extra_rstbuf = NULL; |
| 759 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 760 | #endif // CONFIG_LOOP_RESTORATION |
| 761 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 762 | if (aom_realloc_frame_buffer(&cpi->scaled_source, cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 763 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 764 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 765 | cm->use_highbitdepth, |
| 766 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 767 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 768 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 769 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 770 | "Failed to allocate scaled source buffer"); |
| 771 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 772 | 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] | 773 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 774 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 775 | cm->use_highbitdepth, |
| 776 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 777 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 778 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 779 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 780 | "Failed to allocate scaled last source buffer"); |
| 781 | } |
| 782 | |
Yunqing Wang | f5dc71e | 2017-05-04 18:20:17 -0700 | [diff] [blame] | 783 | static void alloc_context_buffers_ext(AV1_COMP *cpi) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 784 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 785 | int mi_size = cm->mi_cols * cm->mi_rows; |
| 786 | |
Yunqing Wang | f5dc71e | 2017-05-04 18:20:17 -0700 | [diff] [blame] | 787 | CHECK_MEM_ERROR(cm, cpi->mbmi_ext_base, |
| 788 | aom_calloc(mi_size, sizeof(*cpi->mbmi_ext_base))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 791 | void av1_alloc_compressor_data(AV1_COMP *cpi) { |
| 792 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 793 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 794 | av1_alloc_context_buffers(cm, cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 795 | |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 796 | #if CONFIG_LV_MAP |
| 797 | av1_alloc_txb_buf(cpi); |
| 798 | #endif |
| 799 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 800 | alloc_context_buffers_ext(cpi); |
| 801 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 802 | aom_free(cpi->tile_tok[0][0]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 803 | |
| 804 | { |
| 805 | unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols); |
| 806 | CHECK_MEM_ERROR(cm, cpi->tile_tok[0][0], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 807 | aom_calloc(tokens, sizeof(*cpi->tile_tok[0][0]))); |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 808 | #if CONFIG_ANS && !ANS_MAX_SYMBOLS |
| 809 | aom_buf_ans_alloc(&cpi->buf_ans, &cm->error, (int)tokens); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 810 | #endif // CONFIG_ANS |
| 811 | } |
| 812 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 813 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 816 | void av1_new_framerate(AV1_COMP *cpi, double framerate) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 817 | cpi->framerate = framerate < 0.1 ? 30 : framerate; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 818 | #if CONFIG_XIPHRC |
| 819 | if (!cpi->od_rc.cur_frame) return; |
| 820 | cpi->od_rc.framerate = cpi->framerate; |
| 821 | od_enc_rc_resize(&cpi->od_rc); |
| 822 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 823 | av1_rc_update_framerate(cpi); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 824 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 827 | static void set_tile_info(AV1_COMP *cpi) { |
| 828 | AV1_COMMON *const cm = &cpi->common; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 829 | #if CONFIG_TILE_GROUPS && CONFIG_DEPENDENT_HORZTILES |
| 830 | int tile_row, tile_col, num_tiles_in_tg; |
| 831 | int tg_row_start, tg_col_start; |
| 832 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 833 | #if CONFIG_EXT_TILE |
| 834 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 835 | if (cpi->oxcf.superblock_size != AOM_SUPERBLOCK_SIZE_64X64) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 836 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 32); |
| 837 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 32); |
| 838 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 839 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
| 840 | } else { |
| 841 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 842 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
| 843 | cm->tile_width <<= MAX_MIB_SIZE_LOG2 - 1; |
| 844 | cm->tile_height <<= MAX_MIB_SIZE_LOG2 - 1; |
| 845 | } |
| 846 | #else |
| 847 | cm->tile_width = clamp(cpi->oxcf.tile_columns, 1, 64); |
| 848 | cm->tile_height = clamp(cpi->oxcf.tile_rows, 1, 64); |
| 849 | cm->tile_width <<= MAX_MIB_SIZE_LOG2; |
| 850 | cm->tile_height <<= MAX_MIB_SIZE_LOG2; |
| 851 | #endif // CONFIG_EXT_PARTITION |
| 852 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 853 | cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols); |
| 854 | cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 855 | |
| 856 | assert(cm->tile_width >> MAX_MIB_SIZE <= 32); |
| 857 | assert(cm->tile_height >> MAX_MIB_SIZE <= 32); |
| 858 | |
| 859 | // Get the number of tiles |
| 860 | cm->tile_cols = 1; |
| 861 | while (cm->tile_cols * cm->tile_width < cm->mi_cols) ++cm->tile_cols; |
| 862 | |
| 863 | cm->tile_rows = 1; |
| 864 | while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows; |
| 865 | #else |
| 866 | int min_log2_tile_cols, max_log2_tile_cols; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 867 | 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] | 868 | |
| 869 | cm->log2_tile_cols = |
| 870 | clamp(cpi->oxcf.tile_columns, min_log2_tile_cols, max_log2_tile_cols); |
| 871 | cm->log2_tile_rows = cpi->oxcf.tile_rows; |
| 872 | |
| 873 | cm->tile_cols = 1 << cm->log2_tile_cols; |
| 874 | cm->tile_rows = 1 << cm->log2_tile_rows; |
| 875 | |
| 876 | cm->tile_width = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); |
| 877 | cm->tile_width >>= cm->log2_tile_cols; |
| 878 | cm->tile_height = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); |
| 879 | cm->tile_height >>= cm->log2_tile_rows; |
| 880 | |
| 881 | // round to integer multiples of max superblock size |
| 882 | cm->tile_width = ALIGN_POWER_OF_TWO(cm->tile_width, MAX_MIB_SIZE_LOG2); |
| 883 | cm->tile_height = ALIGN_POWER_OF_TWO(cm->tile_height, MAX_MIB_SIZE_LOG2); |
| 884 | #endif // CONFIG_EXT_TILE |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 885 | |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 886 | #if CONFIG_DEPENDENT_HORZTILES |
| 887 | cm->dependent_horz_tiles = cpi->oxcf.dependent_horz_tiles; |
Fangwen Fu | 70bcb89 | 2017-05-06 17:05:19 -0700 | [diff] [blame] | 888 | #if CONFIG_EXT_TILE |
| 889 | if (cm->tile_rows <= 1) cm->dependent_horz_tiles = 0; |
| 890 | #else |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 891 | if (cm->log2_tile_rows == 0) cm->dependent_horz_tiles = 0; |
Fangwen Fu | 70bcb89 | 2017-05-06 17:05:19 -0700 | [diff] [blame] | 892 | #endif |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 893 | #if CONFIG_TILE_GROUPS |
| 894 | if (cpi->oxcf.mtu == 0) { |
| 895 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 896 | } else { |
| 897 | // Use a default value for the purposes of weighting costs in probability |
| 898 | // updates |
| 899 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 900 | } |
| 901 | num_tiles_in_tg = |
| 902 | (cm->tile_cols * cm->tile_rows + cm->num_tg - 1) / cm->num_tg; |
| 903 | tg_row_start = 0; |
| 904 | tg_col_start = 0; |
| 905 | for (tile_row = 0; tile_row < cm->tile_rows; ++tile_row) { |
| 906 | for (tile_col = 0; tile_col < cm->tile_cols; ++tile_col) { |
| 907 | if ((tile_row * cm->tile_cols + tile_col) % num_tiles_in_tg == 0) { |
| 908 | tg_row_start = tile_row; |
| 909 | tg_col_start = tile_col; |
| 910 | } |
| 911 | cm->tile_group_start_row[tile_row][tile_col] = tg_row_start; |
| 912 | cm->tile_group_start_col[tile_row][tile_col] = tg_col_start; |
| 913 | } |
| 914 | } |
| 915 | #endif |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 916 | #endif |
| 917 | |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 918 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 919 | cm->loop_filter_across_tiles_enabled = |
| 920 | cpi->oxcf.loop_filter_across_tiles_enabled; |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 921 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 924 | static void update_frame_size(AV1_COMP *cpi) { |
| 925 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 926 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
| 927 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 928 | av1_set_mb_mi(cm, cm->width, cm->height); |
| 929 | av1_init_context_buffers(cm); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 930 | av1_init_macroblockd(cm, xd, |
| 931 | #if CONFIG_PVQ |
| 932 | NULL, |
| 933 | #endif |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 934 | #if CONFIG_CFL |
| 935 | &NULL_CFL, |
| 936 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 937 | NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 938 | memset(cpi->mbmi_ext_base, 0, |
| 939 | cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
| 940 | |
| 941 | set_tile_info(cpi); |
| 942 | } |
| 943 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 944 | static void init_buffer_indices(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 945 | #if CONFIG_EXT_REFS |
| 946 | int fb_idx; |
| 947 | for (fb_idx = 0; fb_idx < LAST_REF_FRAMES; ++fb_idx) |
| 948 | cpi->lst_fb_idxes[fb_idx] = fb_idx; |
| 949 | cpi->gld_fb_idx = LAST_REF_FRAMES; |
| 950 | cpi->bwd_fb_idx = LAST_REF_FRAMES + 1; |
| 951 | cpi->alt_fb_idx = LAST_REF_FRAMES + 2; |
| 952 | for (fb_idx = 0; fb_idx < MAX_EXT_ARFS + 1; ++fb_idx) |
| 953 | cpi->arf_map[fb_idx] = LAST_REF_FRAMES + 2 + fb_idx; |
| 954 | #else |
| 955 | cpi->lst_fb_idx = 0; |
| 956 | cpi->gld_fb_idx = 1; |
| 957 | cpi->alt_fb_idx = 2; |
| 958 | #endif // CONFIG_EXT_REFS |
| 959 | } |
| 960 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 961 | static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) { |
| 962 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 963 | |
| 964 | cpi->oxcf = *oxcf; |
| 965 | cpi->framerate = oxcf->init_framerate; |
| 966 | |
| 967 | cm->profile = oxcf->profile; |
| 968 | cm->bit_depth = oxcf->bit_depth; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 969 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 970 | cm->use_highbitdepth = oxcf->use_highbitdepth; |
| 971 | #endif |
| 972 | cm->color_space = oxcf->color_space; |
| 973 | cm->color_range = oxcf->color_range; |
| 974 | |
| 975 | cm->width = oxcf->width; |
| 976 | cm->height = oxcf->height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 977 | av1_alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 978 | |
| 979 | // Single thread case: use counts in common. |
| 980 | cpi->td.counts = &cm->counts; |
| 981 | |
| 982 | // change includes all joint functionality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 983 | av1_change_config(cpi, oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 984 | |
| 985 | cpi->static_mb_pct = 0; |
| 986 | cpi->ref_frame_flags = 0; |
| 987 | |
| 988 | init_buffer_indices(cpi); |
| 989 | } |
| 990 | |
| 991 | static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 992 | const AV1EncoderConfig *oxcf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 993 | const int64_t bandwidth = oxcf->target_bandwidth; |
| 994 | const int64_t starting = oxcf->starting_buffer_level_ms; |
| 995 | const int64_t optimal = oxcf->optimal_buffer_level_ms; |
| 996 | const int64_t maximum = oxcf->maximum_buffer_size_ms; |
| 997 | |
| 998 | rc->starting_buffer_level = starting * bandwidth / 1000; |
| 999 | rc->optimal_buffer_level = |
| 1000 | (optimal == 0) ? bandwidth / 8 : optimal * bandwidth / 1000; |
| 1001 | rc->maximum_buffer_size = |
| 1002 | (maximum == 0) ? bandwidth / 8 : maximum * bandwidth / 1000; |
| 1003 | } |
| 1004 | |
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 | #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 1007 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 1008 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1009 | cpi->fn_ptr[BT].vf = VF; \ |
| 1010 | cpi->fn_ptr[BT].svf = SVF; \ |
| 1011 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1012 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 1013 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 1014 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
| 1015 | |
| 1016 | #define MAKE_BFP_SAD_WRAPPER(fnname) \ |
| 1017 | static unsigned int fnname##_bits8(const uint8_t *src_ptr, \ |
| 1018 | int source_stride, \ |
| 1019 | const uint8_t *ref_ptr, int ref_stride) { \ |
| 1020 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \ |
| 1021 | } \ |
| 1022 | static unsigned int fnname##_bits10( \ |
| 1023 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1024 | int ref_stride) { \ |
| 1025 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \ |
| 1026 | } \ |
| 1027 | static unsigned int fnname##_bits12( \ |
| 1028 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1029 | int ref_stride) { \ |
| 1030 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \ |
| 1031 | } |
| 1032 | |
| 1033 | #define MAKE_BFP_SADAVG_WRAPPER(fnname) \ |
| 1034 | static unsigned int fnname##_bits8( \ |
| 1035 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1036 | int ref_stride, const uint8_t *second_pred) { \ |
| 1037 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \ |
| 1038 | } \ |
| 1039 | static unsigned int fnname##_bits10( \ |
| 1040 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1041 | int ref_stride, const uint8_t *second_pred) { \ |
| 1042 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1043 | 2; \ |
| 1044 | } \ |
| 1045 | static unsigned int fnname##_bits12( \ |
| 1046 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1047 | int ref_stride, const uint8_t *second_pred) { \ |
| 1048 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \ |
| 1049 | 4; \ |
| 1050 | } |
| 1051 | |
| 1052 | #define MAKE_BFP_SAD3_WRAPPER(fnname) \ |
| 1053 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1054 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1055 | unsigned int *sad_array) { \ |
| 1056 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1057 | } \ |
| 1058 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1059 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1060 | unsigned int *sad_array) { \ |
| 1061 | int i; \ |
| 1062 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1063 | for (i = 0; i < 3; i++) sad_array[i] >>= 2; \ |
| 1064 | } \ |
| 1065 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1066 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1067 | unsigned int *sad_array) { \ |
| 1068 | int i; \ |
| 1069 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1070 | for (i = 0; i < 3; i++) sad_array[i] >>= 4; \ |
| 1071 | } |
| 1072 | |
| 1073 | #define MAKE_BFP_SAD8_WRAPPER(fnname) \ |
| 1074 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1075 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1076 | unsigned int *sad_array) { \ |
| 1077 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1078 | } \ |
| 1079 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1080 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1081 | unsigned int *sad_array) { \ |
| 1082 | int i; \ |
| 1083 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1084 | for (i = 0; i < 8; i++) sad_array[i] >>= 2; \ |
| 1085 | } \ |
| 1086 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1087 | const uint8_t *ref_ptr, int ref_stride, \ |
| 1088 | unsigned int *sad_array) { \ |
| 1089 | int i; \ |
| 1090 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1091 | for (i = 0; i < 8; i++) sad_array[i] >>= 4; \ |
| 1092 | } |
| 1093 | #define MAKE_BFP_SAD4D_WRAPPER(fnname) \ |
| 1094 | static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \ |
| 1095 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1096 | unsigned int *sad_array) { \ |
| 1097 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1098 | } \ |
| 1099 | static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \ |
| 1100 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1101 | unsigned int *sad_array) { \ |
| 1102 | int i; \ |
| 1103 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1104 | for (i = 0; i < 4; i++) sad_array[i] >>= 2; \ |
| 1105 | } \ |
| 1106 | static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \ |
| 1107 | const uint8_t *const ref_ptr[], int ref_stride, \ |
| 1108 | unsigned int *sad_array) { \ |
| 1109 | int i; \ |
| 1110 | fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \ |
| 1111 | for (i = 0; i < 4; i++) sad_array[i] >>= 4; \ |
| 1112 | } |
| 1113 | |
| 1114 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1115 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128) |
| 1116 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg) |
| 1117 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad128x128x3) |
| 1118 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad128x128x8) |
| 1119 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d) |
| 1120 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64) |
| 1121 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg) |
| 1122 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d) |
| 1123 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128) |
| 1124 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg) |
| 1125 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1126 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1127 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16) |
| 1128 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg) |
| 1129 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d) |
| 1130 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32) |
| 1131 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg) |
| 1132 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d) |
| 1133 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32) |
| 1134 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg) |
| 1135 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d) |
| 1136 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64) |
| 1137 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg) |
| 1138 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d) |
| 1139 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32) |
| 1140 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg) |
| 1141 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad32x32x3) |
| 1142 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad32x32x8) |
| 1143 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d) |
| 1144 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64) |
| 1145 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg) |
| 1146 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad64x64x3) |
| 1147 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad64x64x8) |
| 1148 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d) |
| 1149 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16) |
| 1150 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg) |
| 1151 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x16x3) |
| 1152 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x16x8) |
| 1153 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d) |
| 1154 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8) |
| 1155 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg) |
| 1156 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad16x8x3) |
| 1157 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad16x8x8) |
| 1158 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d) |
| 1159 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16) |
| 1160 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg) |
| 1161 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x16x3) |
| 1162 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x16x8) |
| 1163 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d) |
| 1164 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8) |
| 1165 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg) |
| 1166 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad8x8x3) |
| 1167 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x8x8) |
| 1168 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d) |
| 1169 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4) |
| 1170 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg) |
| 1171 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad8x4x8) |
| 1172 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d) |
| 1173 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8) |
| 1174 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg) |
| 1175 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x8x8) |
| 1176 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d) |
| 1177 | MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4) |
| 1178 | MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg) |
| 1179 | MAKE_BFP_SAD3_WRAPPER(aom_highbd_sad4x4x3) |
| 1180 | MAKE_BFP_SAD8_WRAPPER(aom_highbd_sad4x4x8) |
| 1181 | MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1182 | |
| 1183 | #if CONFIG_EXT_INTER |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 1184 | #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \ |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1185 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 1186 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1187 | |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 1188 | #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \ |
| 1189 | static unsigned int fnname##_bits8( \ |
| 1190 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1191 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1192 | int m_stride, int invert_mask) { \ |
| 1193 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1194 | second_pred_ptr, m, m_stride, invert_mask); \ |
| 1195 | } \ |
| 1196 | static unsigned int fnname##_bits10( \ |
| 1197 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1198 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1199 | int m_stride, int invert_mask) { \ |
| 1200 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1201 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1202 | 2; \ |
| 1203 | } \ |
| 1204 | static unsigned int fnname##_bits12( \ |
| 1205 | const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \ |
| 1206 | int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \ |
| 1207 | int m_stride, int invert_mask) { \ |
| 1208 | return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \ |
| 1209 | second_pred_ptr, m, m_stride, invert_mask) >> \ |
| 1210 | 4; \ |
| 1211 | } |
| 1212 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1213 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1214 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128) |
| 1215 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64) |
| 1216 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1217 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1218 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64) |
| 1219 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32) |
| 1220 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64) |
| 1221 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32) |
| 1222 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16) |
| 1223 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32) |
| 1224 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16) |
| 1225 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8) |
| 1226 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16) |
| 1227 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8) |
| 1228 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4) |
| 1229 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8) |
| 1230 | MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1231 | #endif // CONFIG_EXT_INTER |
| 1232 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1233 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1234 | #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \ |
| 1235 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 1236 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 1237 | cpi->fn_ptr[BT].osvf = OSVF; |
| 1238 | |
| 1239 | #define MAKE_OBFP_SAD_WRAPPER(fnname) \ |
| 1240 | static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \ |
| 1241 | const int32_t *wsrc, \ |
| 1242 | const int32_t *msk) { \ |
| 1243 | return fnname(ref, ref_stride, wsrc, msk); \ |
| 1244 | } \ |
| 1245 | static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \ |
| 1246 | const int32_t *wsrc, \ |
| 1247 | const int32_t *msk) { \ |
| 1248 | return fnname(ref, ref_stride, wsrc, msk) >> 2; \ |
| 1249 | } \ |
| 1250 | static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \ |
| 1251 | const int32_t *wsrc, \ |
| 1252 | const int32_t *msk) { \ |
| 1253 | return fnname(ref, ref_stride, wsrc, msk) >> 4; \ |
| 1254 | } |
| 1255 | |
| 1256 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1257 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128) |
| 1258 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64) |
| 1259 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1260 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1261 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64) |
| 1262 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32) |
| 1263 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64) |
| 1264 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32) |
| 1265 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16) |
| 1266 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32) |
| 1267 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16) |
| 1268 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8) |
| 1269 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16) |
| 1270 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8) |
| 1271 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4) |
| 1272 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8) |
| 1273 | MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4) |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1274 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1275 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1276 | static void highbd_set_var_fns(AV1_COMP *const cpi) { |
| 1277 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1278 | if (cm->use_highbitdepth) { |
| 1279 | switch (cm->bit_depth) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1280 | case AOM_BITS_8: |
| 1281 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits8, |
| 1282 | aom_highbd_sad32x16_avg_bits8, aom_highbd_8_variance32x16, |
| 1283 | aom_highbd_8_sub_pixel_variance32x16, |
| 1284 | aom_highbd_8_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1285 | aom_highbd_sad32x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1286 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1287 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits8, |
| 1288 | aom_highbd_sad16x32_avg_bits8, aom_highbd_8_variance16x32, |
| 1289 | aom_highbd_8_sub_pixel_variance16x32, |
| 1290 | aom_highbd_8_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1291 | aom_highbd_sad16x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1292 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1293 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits8, |
| 1294 | aom_highbd_sad64x32_avg_bits8, aom_highbd_8_variance64x32, |
| 1295 | aom_highbd_8_sub_pixel_variance64x32, |
| 1296 | aom_highbd_8_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1297 | aom_highbd_sad64x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1298 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1299 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits8, |
| 1300 | aom_highbd_sad32x64_avg_bits8, aom_highbd_8_variance32x64, |
| 1301 | aom_highbd_8_sub_pixel_variance32x64, |
| 1302 | aom_highbd_8_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1303 | aom_highbd_sad32x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1304 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1305 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits8, |
| 1306 | aom_highbd_sad32x32_avg_bits8, aom_highbd_8_variance32x32, |
| 1307 | aom_highbd_8_sub_pixel_variance32x32, |
| 1308 | aom_highbd_8_sub_pixel_avg_variance32x32, |
| 1309 | aom_highbd_sad32x32x3_bits8, aom_highbd_sad32x32x8_bits8, |
| 1310 | aom_highbd_sad32x32x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1311 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1312 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits8, |
| 1313 | aom_highbd_sad64x64_avg_bits8, aom_highbd_8_variance64x64, |
| 1314 | aom_highbd_8_sub_pixel_variance64x64, |
| 1315 | aom_highbd_8_sub_pixel_avg_variance64x64, |
| 1316 | aom_highbd_sad64x64x3_bits8, aom_highbd_sad64x64x8_bits8, |
| 1317 | aom_highbd_sad64x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1318 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1319 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits8, |
| 1320 | aom_highbd_sad16x16_avg_bits8, aom_highbd_8_variance16x16, |
| 1321 | aom_highbd_8_sub_pixel_variance16x16, |
| 1322 | aom_highbd_8_sub_pixel_avg_variance16x16, |
| 1323 | aom_highbd_sad16x16x3_bits8, aom_highbd_sad16x16x8_bits8, |
| 1324 | aom_highbd_sad16x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1325 | |
| 1326 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1327 | BLOCK_16X8, aom_highbd_sad16x8_bits8, aom_highbd_sad16x8_avg_bits8, |
| 1328 | aom_highbd_8_variance16x8, aom_highbd_8_sub_pixel_variance16x8, |
| 1329 | aom_highbd_8_sub_pixel_avg_variance16x8, aom_highbd_sad16x8x3_bits8, |
| 1330 | aom_highbd_sad16x8x8_bits8, aom_highbd_sad16x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1331 | |
| 1332 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1333 | BLOCK_8X16, aom_highbd_sad8x16_bits8, aom_highbd_sad8x16_avg_bits8, |
| 1334 | aom_highbd_8_variance8x16, aom_highbd_8_sub_pixel_variance8x16, |
| 1335 | aom_highbd_8_sub_pixel_avg_variance8x16, aom_highbd_sad8x16x3_bits8, |
| 1336 | aom_highbd_sad8x16x8_bits8, aom_highbd_sad8x16x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1337 | |
| 1338 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1339 | BLOCK_8X8, aom_highbd_sad8x8_bits8, aom_highbd_sad8x8_avg_bits8, |
| 1340 | aom_highbd_8_variance8x8, aom_highbd_8_sub_pixel_variance8x8, |
| 1341 | aom_highbd_8_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits8, |
| 1342 | aom_highbd_sad8x8x8_bits8, aom_highbd_sad8x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1343 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1344 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits8, |
| 1345 | aom_highbd_sad8x4_avg_bits8, aom_highbd_8_variance8x4, |
| 1346 | aom_highbd_8_sub_pixel_variance8x4, |
| 1347 | aom_highbd_8_sub_pixel_avg_variance8x4, NULL, |
| 1348 | aom_highbd_sad8x4x8_bits8, aom_highbd_sad8x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1349 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1350 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits8, |
| 1351 | aom_highbd_sad4x8_avg_bits8, aom_highbd_8_variance4x8, |
| 1352 | aom_highbd_8_sub_pixel_variance4x8, |
| 1353 | aom_highbd_8_sub_pixel_avg_variance4x8, NULL, |
| 1354 | aom_highbd_sad4x8x8_bits8, aom_highbd_sad4x8x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1355 | |
| 1356 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1357 | BLOCK_4X4, aom_highbd_sad4x4_bits8, aom_highbd_sad4x4_avg_bits8, |
| 1358 | aom_highbd_8_variance4x4, aom_highbd_8_sub_pixel_variance4x4, |
| 1359 | aom_highbd_8_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits8, |
| 1360 | aom_highbd_sad4x4x8_bits8, aom_highbd_sad4x4x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1361 | |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1362 | #if CONFIG_CB4X4 |
| 1363 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_8_variance2x2, NULL, NULL, |
| 1364 | NULL, NULL, NULL) |
| 1365 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_8_variance4x2, NULL, NULL, |
| 1366 | NULL, NULL, NULL) |
| 1367 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_8_variance2x4, NULL, NULL, |
| 1368 | NULL, NULL, NULL) |
| 1369 | #endif |
| 1370 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1371 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1372 | HIGHBD_BFP(BLOCK_128X128, aom_highbd_sad128x128_bits8, |
| 1373 | aom_highbd_sad128x128_avg_bits8, |
| 1374 | aom_highbd_8_variance128x128, |
| 1375 | aom_highbd_8_sub_pixel_variance128x128, |
| 1376 | aom_highbd_8_sub_pixel_avg_variance128x128, |
| 1377 | aom_highbd_sad128x128x3_bits8, aom_highbd_sad128x128x8_bits8, |
| 1378 | aom_highbd_sad128x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1379 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1380 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits8, |
| 1381 | aom_highbd_sad128x64_avg_bits8, aom_highbd_8_variance128x64, |
| 1382 | aom_highbd_8_sub_pixel_variance128x64, |
| 1383 | aom_highbd_8_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1384 | aom_highbd_sad128x64x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1385 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1386 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits8, |
| 1387 | aom_highbd_sad64x128_avg_bits8, aom_highbd_8_variance64x128, |
| 1388 | aom_highbd_8_sub_pixel_variance64x128, |
| 1389 | aom_highbd_8_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1390 | aom_highbd_sad64x128x4d_bits8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1391 | #endif // CONFIG_EXT_PARTITION |
| 1392 | |
| 1393 | #if CONFIG_EXT_INTER |
| 1394 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1395 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits8, |
| 1396 | aom_highbd_8_masked_sub_pixel_variance128x128) |
| 1397 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits8, |
| 1398 | aom_highbd_8_masked_sub_pixel_variance128x64) |
| 1399 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits8, |
| 1400 | aom_highbd_8_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1401 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1402 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits8, |
| 1403 | aom_highbd_8_masked_sub_pixel_variance64x64) |
| 1404 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits8, |
| 1405 | aom_highbd_8_masked_sub_pixel_variance64x32) |
| 1406 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits8, |
| 1407 | aom_highbd_8_masked_sub_pixel_variance32x64) |
| 1408 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits8, |
| 1409 | aom_highbd_8_masked_sub_pixel_variance32x32) |
| 1410 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits8, |
| 1411 | aom_highbd_8_masked_sub_pixel_variance32x16) |
| 1412 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits8, |
| 1413 | aom_highbd_8_masked_sub_pixel_variance16x32) |
| 1414 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits8, |
| 1415 | aom_highbd_8_masked_sub_pixel_variance16x16) |
| 1416 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits8, |
| 1417 | aom_highbd_8_masked_sub_pixel_variance8x16) |
| 1418 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits8, |
| 1419 | aom_highbd_8_masked_sub_pixel_variance16x8) |
| 1420 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits8, |
| 1421 | aom_highbd_8_masked_sub_pixel_variance8x8) |
| 1422 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits8, |
| 1423 | aom_highbd_8_masked_sub_pixel_variance4x8) |
| 1424 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits8, |
| 1425 | aom_highbd_8_masked_sub_pixel_variance8x4) |
| 1426 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits8, |
| 1427 | aom_highbd_8_masked_sub_pixel_variance4x4) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1428 | #endif // CONFIG_EXT_INTER |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1429 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1430 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1431 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits8, |
| 1432 | aom_highbd_obmc_variance128x128, |
| 1433 | aom_highbd_obmc_sub_pixel_variance128x128) |
| 1434 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits8, |
| 1435 | aom_highbd_obmc_variance128x64, |
| 1436 | aom_highbd_obmc_sub_pixel_variance128x64) |
| 1437 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits8, |
| 1438 | aom_highbd_obmc_variance64x128, |
| 1439 | aom_highbd_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1440 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1441 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits8, |
| 1442 | aom_highbd_obmc_variance64x64, |
| 1443 | aom_highbd_obmc_sub_pixel_variance64x64) |
| 1444 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits8, |
| 1445 | aom_highbd_obmc_variance64x32, |
| 1446 | aom_highbd_obmc_sub_pixel_variance64x32) |
| 1447 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits8, |
| 1448 | aom_highbd_obmc_variance32x64, |
| 1449 | aom_highbd_obmc_sub_pixel_variance32x64) |
| 1450 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits8, |
| 1451 | aom_highbd_obmc_variance32x32, |
| 1452 | aom_highbd_obmc_sub_pixel_variance32x32) |
| 1453 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits8, |
| 1454 | aom_highbd_obmc_variance32x16, |
| 1455 | aom_highbd_obmc_sub_pixel_variance32x16) |
| 1456 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits8, |
| 1457 | aom_highbd_obmc_variance16x32, |
| 1458 | aom_highbd_obmc_sub_pixel_variance16x32) |
| 1459 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits8, |
| 1460 | aom_highbd_obmc_variance16x16, |
| 1461 | aom_highbd_obmc_sub_pixel_variance16x16) |
| 1462 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits8, |
| 1463 | aom_highbd_obmc_variance8x16, |
| 1464 | aom_highbd_obmc_sub_pixel_variance8x16) |
| 1465 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits8, |
| 1466 | aom_highbd_obmc_variance16x8, |
| 1467 | aom_highbd_obmc_sub_pixel_variance16x8) |
| 1468 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits8, |
| 1469 | aom_highbd_obmc_variance8x8, |
| 1470 | aom_highbd_obmc_sub_pixel_variance8x8) |
| 1471 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits8, |
| 1472 | aom_highbd_obmc_variance4x8, |
| 1473 | aom_highbd_obmc_sub_pixel_variance4x8) |
| 1474 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits8, |
| 1475 | aom_highbd_obmc_variance8x4, |
| 1476 | aom_highbd_obmc_sub_pixel_variance8x4) |
| 1477 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits8, |
| 1478 | aom_highbd_obmc_variance4x4, |
| 1479 | aom_highbd_obmc_sub_pixel_variance4x4) |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1480 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1481 | break; |
| 1482 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1483 | case AOM_BITS_10: |
| 1484 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits10, |
| 1485 | aom_highbd_sad32x16_avg_bits10, aom_highbd_10_variance32x16, |
| 1486 | aom_highbd_10_sub_pixel_variance32x16, |
| 1487 | aom_highbd_10_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1488 | aom_highbd_sad32x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1489 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1490 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits10, |
| 1491 | aom_highbd_sad16x32_avg_bits10, aom_highbd_10_variance16x32, |
| 1492 | aom_highbd_10_sub_pixel_variance16x32, |
| 1493 | aom_highbd_10_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1494 | aom_highbd_sad16x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1495 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1496 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits10, |
| 1497 | aom_highbd_sad64x32_avg_bits10, aom_highbd_10_variance64x32, |
| 1498 | aom_highbd_10_sub_pixel_variance64x32, |
| 1499 | aom_highbd_10_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1500 | aom_highbd_sad64x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1501 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1502 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits10, |
| 1503 | aom_highbd_sad32x64_avg_bits10, aom_highbd_10_variance32x64, |
| 1504 | aom_highbd_10_sub_pixel_variance32x64, |
| 1505 | aom_highbd_10_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1506 | aom_highbd_sad32x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1507 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1508 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits10, |
| 1509 | aom_highbd_sad32x32_avg_bits10, aom_highbd_10_variance32x32, |
| 1510 | aom_highbd_10_sub_pixel_variance32x32, |
| 1511 | aom_highbd_10_sub_pixel_avg_variance32x32, |
| 1512 | aom_highbd_sad32x32x3_bits10, aom_highbd_sad32x32x8_bits10, |
| 1513 | aom_highbd_sad32x32x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1514 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1515 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits10, |
| 1516 | aom_highbd_sad64x64_avg_bits10, aom_highbd_10_variance64x64, |
| 1517 | aom_highbd_10_sub_pixel_variance64x64, |
| 1518 | aom_highbd_10_sub_pixel_avg_variance64x64, |
| 1519 | aom_highbd_sad64x64x3_bits10, aom_highbd_sad64x64x8_bits10, |
| 1520 | aom_highbd_sad64x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1521 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1522 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits10, |
| 1523 | aom_highbd_sad16x16_avg_bits10, aom_highbd_10_variance16x16, |
| 1524 | aom_highbd_10_sub_pixel_variance16x16, |
| 1525 | aom_highbd_10_sub_pixel_avg_variance16x16, |
| 1526 | aom_highbd_sad16x16x3_bits10, aom_highbd_sad16x16x8_bits10, |
| 1527 | aom_highbd_sad16x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1528 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1529 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits10, |
| 1530 | aom_highbd_sad16x8_avg_bits10, aom_highbd_10_variance16x8, |
| 1531 | aom_highbd_10_sub_pixel_variance16x8, |
| 1532 | aom_highbd_10_sub_pixel_avg_variance16x8, |
| 1533 | aom_highbd_sad16x8x3_bits10, aom_highbd_sad16x8x8_bits10, |
| 1534 | aom_highbd_sad16x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1535 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1536 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits10, |
| 1537 | aom_highbd_sad8x16_avg_bits10, aom_highbd_10_variance8x16, |
| 1538 | aom_highbd_10_sub_pixel_variance8x16, |
| 1539 | aom_highbd_10_sub_pixel_avg_variance8x16, |
| 1540 | aom_highbd_sad8x16x3_bits10, aom_highbd_sad8x16x8_bits10, |
| 1541 | aom_highbd_sad8x16x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1542 | |
| 1543 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1544 | BLOCK_8X8, aom_highbd_sad8x8_bits10, aom_highbd_sad8x8_avg_bits10, |
| 1545 | aom_highbd_10_variance8x8, aom_highbd_10_sub_pixel_variance8x8, |
| 1546 | aom_highbd_10_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits10, |
| 1547 | aom_highbd_sad8x8x8_bits10, aom_highbd_sad8x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1548 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1549 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits10, |
| 1550 | aom_highbd_sad8x4_avg_bits10, aom_highbd_10_variance8x4, |
| 1551 | aom_highbd_10_sub_pixel_variance8x4, |
| 1552 | aom_highbd_10_sub_pixel_avg_variance8x4, NULL, |
| 1553 | aom_highbd_sad8x4x8_bits10, aom_highbd_sad8x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1554 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1555 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits10, |
| 1556 | aom_highbd_sad4x8_avg_bits10, aom_highbd_10_variance4x8, |
| 1557 | aom_highbd_10_sub_pixel_variance4x8, |
| 1558 | aom_highbd_10_sub_pixel_avg_variance4x8, NULL, |
| 1559 | aom_highbd_sad4x8x8_bits10, aom_highbd_sad4x8x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1560 | |
| 1561 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1562 | BLOCK_4X4, aom_highbd_sad4x4_bits10, aom_highbd_sad4x4_avg_bits10, |
| 1563 | aom_highbd_10_variance4x4, aom_highbd_10_sub_pixel_variance4x4, |
| 1564 | aom_highbd_10_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits10, |
| 1565 | aom_highbd_sad4x4x8_bits10, aom_highbd_sad4x4x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1566 | |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1567 | #if CONFIG_CB4X4 |
| 1568 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_10_variance2x2, NULL, NULL, |
| 1569 | NULL, NULL, NULL) |
| 1570 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_10_variance4x2, NULL, NULL, |
| 1571 | NULL, NULL, NULL) |
| 1572 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_10_variance2x4, NULL, NULL, |
| 1573 | NULL, NULL, NULL) |
| 1574 | #endif |
| 1575 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1576 | #if CONFIG_EXT_PARTITION |
| 1577 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1578 | BLOCK_128X128, aom_highbd_sad128x128_bits10, |
| 1579 | aom_highbd_sad128x128_avg_bits10, aom_highbd_10_variance128x128, |
| 1580 | aom_highbd_10_sub_pixel_variance128x128, |
| 1581 | aom_highbd_10_sub_pixel_avg_variance128x128, |
| 1582 | aom_highbd_sad128x128x3_bits10, aom_highbd_sad128x128x8_bits10, |
| 1583 | aom_highbd_sad128x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1584 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1585 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits10, |
| 1586 | aom_highbd_sad128x64_avg_bits10, |
| 1587 | aom_highbd_10_variance128x64, |
| 1588 | aom_highbd_10_sub_pixel_variance128x64, |
| 1589 | aom_highbd_10_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1590 | aom_highbd_sad128x64x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1591 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1592 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits10, |
| 1593 | aom_highbd_sad64x128_avg_bits10, |
| 1594 | aom_highbd_10_variance64x128, |
| 1595 | aom_highbd_10_sub_pixel_variance64x128, |
| 1596 | aom_highbd_10_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1597 | aom_highbd_sad64x128x4d_bits10) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1598 | #endif // CONFIG_EXT_PARTITION |
| 1599 | |
| 1600 | #if CONFIG_EXT_INTER |
| 1601 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1602 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits10, |
| 1603 | aom_highbd_10_masked_sub_pixel_variance128x128) |
| 1604 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits10, |
| 1605 | aom_highbd_10_masked_sub_pixel_variance128x64) |
| 1606 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits10, |
| 1607 | aom_highbd_10_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1608 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1609 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits10, |
| 1610 | aom_highbd_10_masked_sub_pixel_variance64x64) |
| 1611 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits10, |
| 1612 | aom_highbd_10_masked_sub_pixel_variance64x32) |
| 1613 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits10, |
| 1614 | aom_highbd_10_masked_sub_pixel_variance32x64) |
| 1615 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits10, |
| 1616 | aom_highbd_10_masked_sub_pixel_variance32x32) |
| 1617 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits10, |
| 1618 | aom_highbd_10_masked_sub_pixel_variance32x16) |
| 1619 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits10, |
| 1620 | aom_highbd_10_masked_sub_pixel_variance16x32) |
| 1621 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits10, |
| 1622 | aom_highbd_10_masked_sub_pixel_variance16x16) |
| 1623 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits10, |
| 1624 | aom_highbd_10_masked_sub_pixel_variance8x16) |
| 1625 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits10, |
| 1626 | aom_highbd_10_masked_sub_pixel_variance16x8) |
| 1627 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits10, |
| 1628 | aom_highbd_10_masked_sub_pixel_variance8x8) |
| 1629 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits10, |
| 1630 | aom_highbd_10_masked_sub_pixel_variance4x8) |
| 1631 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits10, |
| 1632 | aom_highbd_10_masked_sub_pixel_variance8x4) |
| 1633 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits10, |
| 1634 | aom_highbd_10_masked_sub_pixel_variance4x4) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1635 | #endif // CONFIG_EXT_INTER |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1636 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1637 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1638 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits10, |
| 1639 | aom_highbd_10_obmc_variance128x128, |
| 1640 | aom_highbd_10_obmc_sub_pixel_variance128x128) |
| 1641 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits10, |
| 1642 | aom_highbd_10_obmc_variance128x64, |
| 1643 | aom_highbd_10_obmc_sub_pixel_variance128x64) |
| 1644 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits10, |
| 1645 | aom_highbd_10_obmc_variance64x128, |
| 1646 | aom_highbd_10_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1647 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1648 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits10, |
| 1649 | aom_highbd_10_obmc_variance64x64, |
| 1650 | aom_highbd_10_obmc_sub_pixel_variance64x64) |
| 1651 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits10, |
| 1652 | aom_highbd_10_obmc_variance64x32, |
| 1653 | aom_highbd_10_obmc_sub_pixel_variance64x32) |
| 1654 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits10, |
| 1655 | aom_highbd_10_obmc_variance32x64, |
| 1656 | aom_highbd_10_obmc_sub_pixel_variance32x64) |
| 1657 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits10, |
| 1658 | aom_highbd_10_obmc_variance32x32, |
| 1659 | aom_highbd_10_obmc_sub_pixel_variance32x32) |
| 1660 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits10, |
| 1661 | aom_highbd_10_obmc_variance32x16, |
| 1662 | aom_highbd_10_obmc_sub_pixel_variance32x16) |
| 1663 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits10, |
| 1664 | aom_highbd_10_obmc_variance16x32, |
| 1665 | aom_highbd_10_obmc_sub_pixel_variance16x32) |
| 1666 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits10, |
| 1667 | aom_highbd_10_obmc_variance16x16, |
| 1668 | aom_highbd_10_obmc_sub_pixel_variance16x16) |
| 1669 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits10, |
| 1670 | aom_highbd_10_obmc_variance8x16, |
| 1671 | aom_highbd_10_obmc_sub_pixel_variance8x16) |
| 1672 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits10, |
| 1673 | aom_highbd_10_obmc_variance16x8, |
| 1674 | aom_highbd_10_obmc_sub_pixel_variance16x8) |
| 1675 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits10, |
| 1676 | aom_highbd_10_obmc_variance8x8, |
| 1677 | aom_highbd_10_obmc_sub_pixel_variance8x8) |
| 1678 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits10, |
| 1679 | aom_highbd_10_obmc_variance4x8, |
| 1680 | aom_highbd_10_obmc_sub_pixel_variance4x8) |
| 1681 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits10, |
| 1682 | aom_highbd_10_obmc_variance8x4, |
| 1683 | aom_highbd_10_obmc_sub_pixel_variance8x4) |
| 1684 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits10, |
| 1685 | aom_highbd_10_obmc_variance4x4, |
| 1686 | aom_highbd_10_obmc_sub_pixel_variance4x4) |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1687 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1688 | break; |
| 1689 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1690 | case AOM_BITS_12: |
| 1691 | HIGHBD_BFP(BLOCK_32X16, aom_highbd_sad32x16_bits12, |
| 1692 | aom_highbd_sad32x16_avg_bits12, aom_highbd_12_variance32x16, |
| 1693 | aom_highbd_12_sub_pixel_variance32x16, |
| 1694 | aom_highbd_12_sub_pixel_avg_variance32x16, NULL, NULL, |
| 1695 | aom_highbd_sad32x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1696 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1697 | HIGHBD_BFP(BLOCK_16X32, aom_highbd_sad16x32_bits12, |
| 1698 | aom_highbd_sad16x32_avg_bits12, aom_highbd_12_variance16x32, |
| 1699 | aom_highbd_12_sub_pixel_variance16x32, |
| 1700 | aom_highbd_12_sub_pixel_avg_variance16x32, NULL, NULL, |
| 1701 | aom_highbd_sad16x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1702 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1703 | HIGHBD_BFP(BLOCK_64X32, aom_highbd_sad64x32_bits12, |
| 1704 | aom_highbd_sad64x32_avg_bits12, aom_highbd_12_variance64x32, |
| 1705 | aom_highbd_12_sub_pixel_variance64x32, |
| 1706 | aom_highbd_12_sub_pixel_avg_variance64x32, NULL, NULL, |
| 1707 | aom_highbd_sad64x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1708 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1709 | HIGHBD_BFP(BLOCK_32X64, aom_highbd_sad32x64_bits12, |
| 1710 | aom_highbd_sad32x64_avg_bits12, aom_highbd_12_variance32x64, |
| 1711 | aom_highbd_12_sub_pixel_variance32x64, |
| 1712 | aom_highbd_12_sub_pixel_avg_variance32x64, NULL, NULL, |
| 1713 | aom_highbd_sad32x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1714 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1715 | HIGHBD_BFP(BLOCK_32X32, aom_highbd_sad32x32_bits12, |
| 1716 | aom_highbd_sad32x32_avg_bits12, aom_highbd_12_variance32x32, |
| 1717 | aom_highbd_12_sub_pixel_variance32x32, |
| 1718 | aom_highbd_12_sub_pixel_avg_variance32x32, |
| 1719 | aom_highbd_sad32x32x3_bits12, aom_highbd_sad32x32x8_bits12, |
| 1720 | aom_highbd_sad32x32x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1721 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1722 | HIGHBD_BFP(BLOCK_64X64, aom_highbd_sad64x64_bits12, |
| 1723 | aom_highbd_sad64x64_avg_bits12, aom_highbd_12_variance64x64, |
| 1724 | aom_highbd_12_sub_pixel_variance64x64, |
| 1725 | aom_highbd_12_sub_pixel_avg_variance64x64, |
| 1726 | aom_highbd_sad64x64x3_bits12, aom_highbd_sad64x64x8_bits12, |
| 1727 | aom_highbd_sad64x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1728 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1729 | HIGHBD_BFP(BLOCK_16X16, aom_highbd_sad16x16_bits12, |
| 1730 | aom_highbd_sad16x16_avg_bits12, aom_highbd_12_variance16x16, |
| 1731 | aom_highbd_12_sub_pixel_variance16x16, |
| 1732 | aom_highbd_12_sub_pixel_avg_variance16x16, |
| 1733 | aom_highbd_sad16x16x3_bits12, aom_highbd_sad16x16x8_bits12, |
| 1734 | aom_highbd_sad16x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1735 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1736 | HIGHBD_BFP(BLOCK_16X8, aom_highbd_sad16x8_bits12, |
| 1737 | aom_highbd_sad16x8_avg_bits12, aom_highbd_12_variance16x8, |
| 1738 | aom_highbd_12_sub_pixel_variance16x8, |
| 1739 | aom_highbd_12_sub_pixel_avg_variance16x8, |
| 1740 | aom_highbd_sad16x8x3_bits12, aom_highbd_sad16x8x8_bits12, |
| 1741 | aom_highbd_sad16x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1742 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1743 | HIGHBD_BFP(BLOCK_8X16, aom_highbd_sad8x16_bits12, |
| 1744 | aom_highbd_sad8x16_avg_bits12, aom_highbd_12_variance8x16, |
| 1745 | aom_highbd_12_sub_pixel_variance8x16, |
| 1746 | aom_highbd_12_sub_pixel_avg_variance8x16, |
| 1747 | aom_highbd_sad8x16x3_bits12, aom_highbd_sad8x16x8_bits12, |
| 1748 | aom_highbd_sad8x16x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1749 | |
| 1750 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1751 | BLOCK_8X8, aom_highbd_sad8x8_bits12, aom_highbd_sad8x8_avg_bits12, |
| 1752 | aom_highbd_12_variance8x8, aom_highbd_12_sub_pixel_variance8x8, |
| 1753 | aom_highbd_12_sub_pixel_avg_variance8x8, aom_highbd_sad8x8x3_bits12, |
| 1754 | aom_highbd_sad8x8x8_bits12, aom_highbd_sad8x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1755 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1756 | HIGHBD_BFP(BLOCK_8X4, aom_highbd_sad8x4_bits12, |
| 1757 | aom_highbd_sad8x4_avg_bits12, aom_highbd_12_variance8x4, |
| 1758 | aom_highbd_12_sub_pixel_variance8x4, |
| 1759 | aom_highbd_12_sub_pixel_avg_variance8x4, NULL, |
| 1760 | aom_highbd_sad8x4x8_bits12, aom_highbd_sad8x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1761 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1762 | HIGHBD_BFP(BLOCK_4X8, aom_highbd_sad4x8_bits12, |
| 1763 | aom_highbd_sad4x8_avg_bits12, aom_highbd_12_variance4x8, |
| 1764 | aom_highbd_12_sub_pixel_variance4x8, |
| 1765 | aom_highbd_12_sub_pixel_avg_variance4x8, NULL, |
| 1766 | aom_highbd_sad4x8x8_bits12, aom_highbd_sad4x8x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1767 | |
| 1768 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1769 | BLOCK_4X4, aom_highbd_sad4x4_bits12, aom_highbd_sad4x4_avg_bits12, |
| 1770 | aom_highbd_12_variance4x4, aom_highbd_12_sub_pixel_variance4x4, |
| 1771 | aom_highbd_12_sub_pixel_avg_variance4x4, aom_highbd_sad4x4x3_bits12, |
| 1772 | aom_highbd_sad4x4x8_bits12, aom_highbd_sad4x4x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1773 | |
Jingning Han | cc5bdf4 | 2016-12-19 11:14:30 -0800 | [diff] [blame] | 1774 | #if CONFIG_CB4X4 |
| 1775 | HIGHBD_BFP(BLOCK_2X2, NULL, NULL, aom_highbd_12_variance2x2, NULL, NULL, |
| 1776 | NULL, NULL, NULL) |
| 1777 | HIGHBD_BFP(BLOCK_4X2, NULL, NULL, aom_highbd_12_variance4x2, NULL, NULL, |
| 1778 | NULL, NULL, NULL) |
| 1779 | HIGHBD_BFP(BLOCK_2X4, NULL, NULL, aom_highbd_12_variance2x4, NULL, NULL, |
| 1780 | NULL, NULL, NULL) |
| 1781 | #endif |
| 1782 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1783 | #if CONFIG_EXT_PARTITION |
| 1784 | HIGHBD_BFP( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1785 | BLOCK_128X128, aom_highbd_sad128x128_bits12, |
| 1786 | aom_highbd_sad128x128_avg_bits12, aom_highbd_12_variance128x128, |
| 1787 | aom_highbd_12_sub_pixel_variance128x128, |
| 1788 | aom_highbd_12_sub_pixel_avg_variance128x128, |
| 1789 | aom_highbd_sad128x128x3_bits12, aom_highbd_sad128x128x8_bits12, |
| 1790 | aom_highbd_sad128x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1791 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1792 | HIGHBD_BFP(BLOCK_128X64, aom_highbd_sad128x64_bits12, |
| 1793 | aom_highbd_sad128x64_avg_bits12, |
| 1794 | aom_highbd_12_variance128x64, |
| 1795 | aom_highbd_12_sub_pixel_variance128x64, |
| 1796 | aom_highbd_12_sub_pixel_avg_variance128x64, NULL, NULL, |
| 1797 | aom_highbd_sad128x64x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1798 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1799 | HIGHBD_BFP(BLOCK_64X128, aom_highbd_sad64x128_bits12, |
| 1800 | aom_highbd_sad64x128_avg_bits12, |
| 1801 | aom_highbd_12_variance64x128, |
| 1802 | aom_highbd_12_sub_pixel_variance64x128, |
| 1803 | aom_highbd_12_sub_pixel_avg_variance64x128, NULL, NULL, |
| 1804 | aom_highbd_sad64x128x4d_bits12) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1805 | #endif // CONFIG_EXT_PARTITION |
| 1806 | |
| 1807 | #if CONFIG_EXT_INTER |
| 1808 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1809 | HIGHBD_MBFP(BLOCK_128X128, aom_highbd_masked_sad128x128_bits12, |
| 1810 | aom_highbd_12_masked_sub_pixel_variance128x128) |
| 1811 | HIGHBD_MBFP(BLOCK_128X64, aom_highbd_masked_sad128x64_bits12, |
| 1812 | aom_highbd_12_masked_sub_pixel_variance128x64) |
| 1813 | HIGHBD_MBFP(BLOCK_64X128, aom_highbd_masked_sad64x128_bits12, |
| 1814 | aom_highbd_12_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1815 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 1816 | HIGHBD_MBFP(BLOCK_64X64, aom_highbd_masked_sad64x64_bits12, |
| 1817 | aom_highbd_12_masked_sub_pixel_variance64x64) |
| 1818 | HIGHBD_MBFP(BLOCK_64X32, aom_highbd_masked_sad64x32_bits12, |
| 1819 | aom_highbd_12_masked_sub_pixel_variance64x32) |
| 1820 | HIGHBD_MBFP(BLOCK_32X64, aom_highbd_masked_sad32x64_bits12, |
| 1821 | aom_highbd_12_masked_sub_pixel_variance32x64) |
| 1822 | HIGHBD_MBFP(BLOCK_32X32, aom_highbd_masked_sad32x32_bits12, |
| 1823 | aom_highbd_12_masked_sub_pixel_variance32x32) |
| 1824 | HIGHBD_MBFP(BLOCK_32X16, aom_highbd_masked_sad32x16_bits12, |
| 1825 | aom_highbd_12_masked_sub_pixel_variance32x16) |
| 1826 | HIGHBD_MBFP(BLOCK_16X32, aom_highbd_masked_sad16x32_bits12, |
| 1827 | aom_highbd_12_masked_sub_pixel_variance16x32) |
| 1828 | HIGHBD_MBFP(BLOCK_16X16, aom_highbd_masked_sad16x16_bits12, |
| 1829 | aom_highbd_12_masked_sub_pixel_variance16x16) |
| 1830 | HIGHBD_MBFP(BLOCK_8X16, aom_highbd_masked_sad8x16_bits12, |
| 1831 | aom_highbd_12_masked_sub_pixel_variance8x16) |
| 1832 | HIGHBD_MBFP(BLOCK_16X8, aom_highbd_masked_sad16x8_bits12, |
| 1833 | aom_highbd_12_masked_sub_pixel_variance16x8) |
| 1834 | HIGHBD_MBFP(BLOCK_8X8, aom_highbd_masked_sad8x8_bits12, |
| 1835 | aom_highbd_12_masked_sub_pixel_variance8x8) |
| 1836 | HIGHBD_MBFP(BLOCK_4X8, aom_highbd_masked_sad4x8_bits12, |
| 1837 | aom_highbd_12_masked_sub_pixel_variance4x8) |
| 1838 | HIGHBD_MBFP(BLOCK_8X4, aom_highbd_masked_sad8x4_bits12, |
| 1839 | aom_highbd_12_masked_sub_pixel_variance8x4) |
| 1840 | HIGHBD_MBFP(BLOCK_4X4, aom_highbd_masked_sad4x4_bits12, |
| 1841 | aom_highbd_12_masked_sub_pixel_variance4x4) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1842 | #endif // CONFIG_EXT_INTER |
| 1843 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1844 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1845 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1846 | HIGHBD_OBFP(BLOCK_128X128, aom_highbd_obmc_sad128x128_bits12, |
| 1847 | aom_highbd_12_obmc_variance128x128, |
| 1848 | aom_highbd_12_obmc_sub_pixel_variance128x128) |
| 1849 | HIGHBD_OBFP(BLOCK_128X64, aom_highbd_obmc_sad128x64_bits12, |
| 1850 | aom_highbd_12_obmc_variance128x64, |
| 1851 | aom_highbd_12_obmc_sub_pixel_variance128x64) |
| 1852 | HIGHBD_OBFP(BLOCK_64X128, aom_highbd_obmc_sad64x128_bits12, |
| 1853 | aom_highbd_12_obmc_variance64x128, |
| 1854 | aom_highbd_12_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1855 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1856 | HIGHBD_OBFP(BLOCK_64X64, aom_highbd_obmc_sad64x64_bits12, |
| 1857 | aom_highbd_12_obmc_variance64x64, |
| 1858 | aom_highbd_12_obmc_sub_pixel_variance64x64) |
| 1859 | HIGHBD_OBFP(BLOCK_64X32, aom_highbd_obmc_sad64x32_bits12, |
| 1860 | aom_highbd_12_obmc_variance64x32, |
| 1861 | aom_highbd_12_obmc_sub_pixel_variance64x32) |
| 1862 | HIGHBD_OBFP(BLOCK_32X64, aom_highbd_obmc_sad32x64_bits12, |
| 1863 | aom_highbd_12_obmc_variance32x64, |
| 1864 | aom_highbd_12_obmc_sub_pixel_variance32x64) |
| 1865 | HIGHBD_OBFP(BLOCK_32X32, aom_highbd_obmc_sad32x32_bits12, |
| 1866 | aom_highbd_12_obmc_variance32x32, |
| 1867 | aom_highbd_12_obmc_sub_pixel_variance32x32) |
| 1868 | HIGHBD_OBFP(BLOCK_32X16, aom_highbd_obmc_sad32x16_bits12, |
| 1869 | aom_highbd_12_obmc_variance32x16, |
| 1870 | aom_highbd_12_obmc_sub_pixel_variance32x16) |
| 1871 | HIGHBD_OBFP(BLOCK_16X32, aom_highbd_obmc_sad16x32_bits12, |
| 1872 | aom_highbd_12_obmc_variance16x32, |
| 1873 | aom_highbd_12_obmc_sub_pixel_variance16x32) |
| 1874 | HIGHBD_OBFP(BLOCK_16X16, aom_highbd_obmc_sad16x16_bits12, |
| 1875 | aom_highbd_12_obmc_variance16x16, |
| 1876 | aom_highbd_12_obmc_sub_pixel_variance16x16) |
| 1877 | HIGHBD_OBFP(BLOCK_8X16, aom_highbd_obmc_sad8x16_bits12, |
| 1878 | aom_highbd_12_obmc_variance8x16, |
| 1879 | aom_highbd_12_obmc_sub_pixel_variance8x16) |
| 1880 | HIGHBD_OBFP(BLOCK_16X8, aom_highbd_obmc_sad16x8_bits12, |
| 1881 | aom_highbd_12_obmc_variance16x8, |
| 1882 | aom_highbd_12_obmc_sub_pixel_variance16x8) |
| 1883 | HIGHBD_OBFP(BLOCK_8X8, aom_highbd_obmc_sad8x8_bits12, |
| 1884 | aom_highbd_12_obmc_variance8x8, |
| 1885 | aom_highbd_12_obmc_sub_pixel_variance8x8) |
| 1886 | HIGHBD_OBFP(BLOCK_4X8, aom_highbd_obmc_sad4x8_bits12, |
| 1887 | aom_highbd_12_obmc_variance4x8, |
| 1888 | aom_highbd_12_obmc_sub_pixel_variance4x8) |
| 1889 | HIGHBD_OBFP(BLOCK_8X4, aom_highbd_obmc_sad8x4_bits12, |
| 1890 | aom_highbd_12_obmc_variance8x4, |
| 1891 | aom_highbd_12_obmc_sub_pixel_variance8x4) |
| 1892 | HIGHBD_OBFP(BLOCK_4X4, aom_highbd_obmc_sad4x4_bits12, |
| 1893 | aom_highbd_12_obmc_variance4x4, |
| 1894 | aom_highbd_12_obmc_sub_pixel_variance4x4) |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1895 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1896 | break; |
| 1897 | |
| 1898 | default: |
| 1899 | assert(0 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1900 | "cm->bit_depth should be AOM_BITS_8, " |
| 1901 | "AOM_BITS_10 or AOM_BITS_12"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1902 | } |
| 1903 | } |
| 1904 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1905 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1906 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1907 | static void realloc_segmentation_maps(AV1_COMP *cpi) { |
| 1908 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1909 | |
| 1910 | // Create the encoder segmentation map and set all entries to 0 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1911 | aom_free(cpi->segmentation_map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1912 | CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1913 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1914 | |
| 1915 | // Create a map used for cyclic background refresh. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1916 | if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1917 | CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1918 | av1_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1919 | |
| 1920 | // Create a map used to mark inactive areas. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1921 | aom_free(cpi->active_map.map); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1922 | CHECK_MEM_ERROR(cm, cpi->active_map.map, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1923 | aom_calloc(cm->mi_rows * cm->mi_cols, 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1924 | } |
| 1925 | |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 1926 | #if CONFIG_EXT_INTER |
| 1927 | void set_compound_tools(AV1_COMMON *cm) { |
| 1928 | (void)cm; |
| 1929 | #if CONFIG_INTERINTRA |
| 1930 | cm->allow_interintra_compound = 1; |
| 1931 | #endif // CONFIG_INTERINTRA |
| 1932 | #if CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT |
| 1933 | cm->allow_masked_compound = 1; |
| 1934 | #endif // CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT |
| 1935 | } |
| 1936 | #endif // CONFIG_EXT_INTER |
| 1937 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1938 | void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) { |
| 1939 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1940 | RATE_CONTROL *const rc = &cpi->rc; |
| 1941 | |
| 1942 | if (cm->profile != oxcf->profile) cm->profile = oxcf->profile; |
| 1943 | cm->bit_depth = oxcf->bit_depth; |
| 1944 | cm->color_space = oxcf->color_space; |
| 1945 | cm->color_range = oxcf->color_range; |
| 1946 | |
| 1947 | if (cm->profile <= PROFILE_1) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1948 | assert(cm->bit_depth == AOM_BITS_8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1949 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1950 | assert(cm->bit_depth > AOM_BITS_8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1951 | |
| 1952 | cpi->oxcf = *oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1953 | cpi->td.mb.e_mbd.bd = (int)cm->bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1954 | #if CONFIG_GLOBAL_MOTION |
| 1955 | cpi->td.mb.e_mbd.global_motion = cm->global_motion; |
| 1956 | #endif // CONFIG_GLOBAL_MOTION |
| 1957 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1958 | if ((oxcf->pass == 0) && (oxcf->rc_mode == AOM_Q)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1959 | rc->baseline_gf_interval = FIXED_GF_INTERVAL; |
| 1960 | } else { |
| 1961 | rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2; |
| 1962 | } |
| 1963 | |
| 1964 | cpi->refresh_last_frame = 1; |
| 1965 | cpi->refresh_golden_frame = 0; |
| 1966 | #if CONFIG_EXT_REFS |
| 1967 | cpi->refresh_bwd_ref_frame = 0; |
| 1968 | #endif // CONFIG_EXT_REFS |
| 1969 | |
| 1970 | cm->refresh_frame_context = |
| 1971 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 1972 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 1973 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
| 1974 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
| 1975 | |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 1976 | #if CONFIG_PALETTE |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1977 | cm->allow_screen_content_tools = (cpi->oxcf.content == AOM_CONTENT_SCREEN); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1978 | if (cm->allow_screen_content_tools) { |
| 1979 | MACROBLOCK *x = &cpi->td.mb; |
| 1980 | if (x->palette_buffer == 0) { |
| 1981 | CHECK_MEM_ERROR(cm, x->palette_buffer, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1982 | aom_memalign(16, sizeof(*x->palette_buffer))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1983 | } |
| 1984 | // Reallocate the pc_tree, as it's contents depends on |
| 1985 | // the state of cm->allow_screen_content_tools |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1986 | av1_free_pc_tree(&cpi->td); |
| 1987 | av1_setup_pc_tree(&cpi->common, &cpi->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1988 | } |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 1989 | #endif // CONFIG_PALETTE |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 1990 | #if CONFIG_EXT_INTER |
| 1991 | set_compound_tools(cm); |
| 1992 | #endif // CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1993 | av1_reset_segment_features(cm); |
| 1994 | av1_set_high_precision_mv(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1995 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1996 | set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 1997 | |
| 1998 | // Under a configuration change, where maximum_buffer_size may change, |
| 1999 | // keep buffer level clipped to the maximum allowed buffer size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2000 | rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 2001 | rc->buffer_level = AOMMIN(rc->buffer_level, rc->maximum_buffer_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2002 | |
| 2003 | // Set up frame rate and related parameters rate control values. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2004 | av1_new_framerate(cpi, cpi->framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2005 | |
| 2006 | // Set absolute upper and lower quality limits |
| 2007 | rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 2008 | rc->best_quality = cpi->oxcf.best_allowed_q; |
| 2009 | |
| 2010 | cm->interp_filter = cpi->sf.default_interp_filter; |
| 2011 | |
| 2012 | if (cpi->oxcf.render_width > 0 && cpi->oxcf.render_height > 0) { |
| 2013 | cm->render_width = cpi->oxcf.render_width; |
| 2014 | cm->render_height = cpi->oxcf.render_height; |
| 2015 | } else { |
| 2016 | cm->render_width = cpi->oxcf.width; |
| 2017 | cm->render_height = cpi->oxcf.height; |
| 2018 | } |
| 2019 | cm->width = cpi->oxcf.width; |
| 2020 | cm->height = cpi->oxcf.height; |
| 2021 | |
| 2022 | if (cpi->initial_width) { |
| 2023 | if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2024 | av1_free_context_buffers(cm); |
| 2025 | av1_alloc_compressor_data(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2026 | realloc_segmentation_maps(cpi); |
| 2027 | cpi->initial_width = cpi->initial_height = 0; |
| 2028 | } |
| 2029 | } |
| 2030 | update_frame_size(cpi); |
| 2031 | |
| 2032 | cpi->alt_ref_source = NULL; |
| 2033 | rc->is_src_frame_alt_ref = 0; |
| 2034 | |
| 2035 | #if CONFIG_EXT_REFS |
| 2036 | rc->is_bwd_ref_frame = 0; |
| 2037 | rc->is_last_bipred_frame = 0; |
| 2038 | rc->is_bipred_frame = 0; |
| 2039 | #endif // CONFIG_EXT_REFS |
| 2040 | |
| 2041 | #if 0 |
| 2042 | // Experimental RD Code |
| 2043 | cpi->frame_distortion = 0; |
| 2044 | cpi->last_frame_distortion = 0; |
| 2045 | #endif |
| 2046 | |
| 2047 | set_tile_info(cpi); |
| 2048 | |
| 2049 | cpi->ext_refresh_frame_flags_pending = 0; |
| 2050 | cpi->ext_refresh_frame_context_pending = 0; |
| 2051 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2052 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2053 | highbd_set_var_fns(cpi); |
| 2054 | #endif |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2055 | |
| 2056 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 2057 | cpi->common.ans_window_size_log2 = cpi->oxcf.ans_window_size_log2; |
| 2058 | if (cpi->buf_ans.size != (1 << cpi->common.ans_window_size_log2)) { |
| 2059 | aom_buf_ans_free(&cpi->buf_ans); |
| 2060 | aom_buf_ans_alloc(&cpi->buf_ans, &cpi->common.error, |
| 2061 | 1 << cpi->common.ans_window_size_log2); |
| 2062 | } |
| 2063 | #endif // CONFIG_ANS && ANS_MAX_SYMBOLS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2066 | static INLINE void init_upsampled_ref_frame_bufs(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2067 | int i; |
| 2068 | |
| 2069 | for (i = 0; i < (REF_FRAMES + 1); ++i) { |
| 2070 | cpi->upsampled_ref_bufs[i].ref_count = 0; |
| 2071 | cpi->upsampled_ref_idx[i] = INVALID_IDX; |
| 2072 | } |
| 2073 | } |
| 2074 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2075 | AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 2076 | BufferPool *const pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2077 | unsigned int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2078 | AV1_COMP *volatile const cpi = aom_memalign(32, sizeof(AV1_COMP)); |
| 2079 | AV1_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2080 | |
| 2081 | if (!cm) return NULL; |
| 2082 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2083 | av1_zero(*cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2084 | |
| 2085 | if (setjmp(cm->error.jmp)) { |
| 2086 | cm->error.setjmp = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2087 | av1_remove_compressor(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2088 | return 0; |
| 2089 | } |
| 2090 | |
| 2091 | cm->error.setjmp = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2092 | cm->alloc_mi = av1_enc_alloc_mi; |
| 2093 | cm->free_mi = av1_enc_free_mi; |
| 2094 | cm->setup_mi = av1_enc_setup_mi; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2095 | |
Angie Chiang | a5d96c4 | 2016-10-21 16:16:56 -0700 | [diff] [blame] | 2096 | CHECK_MEM_ERROR(cm, cm->fc, |
| 2097 | (FRAME_CONTEXT *)aom_memalign(32, sizeof(*cm->fc))); |
| 2098 | CHECK_MEM_ERROR(cm, cm->frame_contexts, |
| 2099 | (FRAME_CONTEXT *)aom_memalign( |
| 2100 | 32, FRAME_CONTEXTS * sizeof(*cm->frame_contexts))); |
| 2101 | memset(cm->fc, 0, sizeof(*cm->fc)); |
| 2102 | memset(cm->frame_contexts, 0, FRAME_CONTEXTS * sizeof(*cm->frame_contexts)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2103 | |
| 2104 | cpi->resize_state = 0; |
| 2105 | cpi->resize_avg_qp = 0; |
| 2106 | cpi->resize_buffer_underflow = 0; |
Fergus Simpson | ddc846e | 2017-04-24 18:09:13 -0700 | [diff] [blame] | 2107 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2108 | cpi->common.buffer_pool = pool; |
| 2109 | |
| 2110 | init_config(cpi, oxcf); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2111 | #if CONFIG_XIPHRC |
| 2112 | cpi->od_rc.framerate = cpi->framerate; |
| 2113 | cpi->od_rc.frame_width = cm->render_width; |
| 2114 | cpi->od_rc.frame_height = cm->render_height; |
| 2115 | cpi->od_rc.keyframe_rate = oxcf->key_freq; |
| 2116 | cpi->od_rc.goldenframe_rate = FIXED_GF_INTERVAL; |
| 2117 | cpi->od_rc.altref_rate = 25; |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2118 | cpi->od_rc.firstpass_quant = 1; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2119 | cpi->od_rc.bit_depth = cm->bit_depth; |
| 2120 | cpi->od_rc.minq = oxcf->best_allowed_q; |
| 2121 | cpi->od_rc.maxq = oxcf->worst_allowed_q; |
| 2122 | if (cpi->oxcf.rc_mode == AOM_CQ) cpi->od_rc.minq = cpi->od_rc.quality; |
| 2123 | cpi->od_rc.quality = cpi->oxcf.rc_mode == AOM_Q ? oxcf->cq_level : -1; |
| 2124 | cpi->od_rc.periodic_boosts = oxcf->frame_periodic_boost; |
| 2125 | od_enc_rc_init(&cpi->od_rc, |
| 2126 | cpi->oxcf.rc_mode == AOM_Q ? -1 : oxcf->target_bandwidth, |
| 2127 | oxcf->maximum_buffer_size_ms); |
| 2128 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2129 | av1_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 2130 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2131 | |
| 2132 | cm->current_video_frame = 0; |
| 2133 | cpi->partition_search_skippable_frame = 0; |
| 2134 | cpi->tile_data = NULL; |
| 2135 | cpi->last_show_frame_buf_idx = INVALID_IDX; |
| 2136 | |
| 2137 | realloc_segmentation_maps(cpi); |
| 2138 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2139 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
Urvang Joshi | bffc0b5 | 2016-07-25 13:38:49 -0700 | [diff] [blame] | 2140 | memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs)); |
| 2141 | memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2142 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2143 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2144 | for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0])); |
| 2145 | i++) { |
| 2146 | CHECK_MEM_ERROR( |
| 2147 | cm, cpi->mbgraph_stats[i].mb_stats, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2148 | aom_calloc(cm->MBs * sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | #if CONFIG_FP_MB_STATS |
| 2152 | cpi->use_fp_mb_stats = 0; |
| 2153 | if (cpi->use_fp_mb_stats) { |
| 2154 | // a place holder used to store the first pass mb stats in the first pass |
| 2155 | CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2156 | aom_calloc(cm->MBs * sizeof(uint8_t), 1)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2157 | } else { |
| 2158 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2159 | } |
| 2160 | #endif |
| 2161 | |
| 2162 | cpi->refresh_alt_ref_frame = 0; |
| 2163 | cpi->multi_arf_last_grp_enabled = 0; |
| 2164 | |
| 2165 | cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 2166 | #if CONFIG_INTERNAL_STATS |
| 2167 | cpi->b_calculate_blockiness = 1; |
| 2168 | cpi->b_calculate_consistency = 1; |
| 2169 | cpi->total_inconsistency = 0; |
| 2170 | cpi->psnr.worst = 100.0; |
| 2171 | cpi->worst_ssim = 100.0; |
| 2172 | |
| 2173 | cpi->count = 0; |
| 2174 | cpi->bytes = 0; |
| 2175 | |
| 2176 | if (cpi->b_calculate_psnr) { |
| 2177 | cpi->total_sq_error = 0; |
| 2178 | cpi->total_samples = 0; |
| 2179 | cpi->tot_recode_hits = 0; |
| 2180 | cpi->summed_quality = 0; |
| 2181 | cpi->summed_weights = 0; |
| 2182 | } |
| 2183 | |
| 2184 | cpi->fastssim.worst = 100.0; |
| 2185 | cpi->psnrhvs.worst = 100.0; |
| 2186 | |
| 2187 | if (cpi->b_calculate_blockiness) { |
| 2188 | cpi->total_blockiness = 0; |
| 2189 | cpi->worst_blockiness = 0.0; |
| 2190 | } |
| 2191 | |
| 2192 | if (cpi->b_calculate_consistency) { |
| 2193 | CHECK_MEM_ERROR(cm, cpi->ssim_vars, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2194 | aom_malloc(sizeof(*cpi->ssim_vars) * 4 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2195 | cpi->common.mi_rows * cpi->common.mi_cols)); |
| 2196 | cpi->worst_consistency = 100.0; |
| 2197 | } |
| 2198 | #endif |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2199 | #if CONFIG_ENTROPY_STATS |
| 2200 | av1_zero(aggregate_fc); |
| 2201 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2202 | |
| 2203 | cpi->first_time_stamp_ever = INT64_MAX; |
| 2204 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2205 | for (i = 0; i < NMV_CONTEXTS; ++i) { |
| 2206 | cpi->td.mb.nmvcost[i][0] = &cpi->nmv_costs[i][0][MV_MAX]; |
| 2207 | cpi->td.mb.nmvcost[i][1] = &cpi->nmv_costs[i][1][MV_MAX]; |
| 2208 | cpi->td.mb.nmvcost_hp[i][0] = &cpi->nmv_costs_hp[i][0][MV_MAX]; |
| 2209 | cpi->td.mb.nmvcost_hp[i][1] = &cpi->nmv_costs_hp[i][1][MV_MAX]; |
| 2210 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2211 | |
| 2212 | #ifdef OUTPUT_YUV_SKINMAP |
| 2213 | yuv_skinmap_file = fopen("skinmap.yuv", "ab"); |
| 2214 | #endif |
| 2215 | #ifdef OUTPUT_YUV_REC |
| 2216 | yuv_rec_file = fopen("rec.yuv", "wb"); |
| 2217 | #endif |
| 2218 | |
| 2219 | #if 0 |
| 2220 | framepsnr = fopen("framepsnr.stt", "a"); |
| 2221 | kf_list = fopen("kf_list.stt", "w"); |
| 2222 | #endif |
| 2223 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2224 | #if CONFIG_XIPHRC |
| 2225 | if (oxcf->pass == 2) { |
| 2226 | cpi->od_rc.twopass_allframes_buf = oxcf->two_pass_stats_in.buf; |
| 2227 | cpi->od_rc.twopass_allframes_buf_size = oxcf->two_pass_stats_in.sz; |
| 2228 | } |
| 2229 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2230 | if (oxcf->pass == 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2231 | av1_init_first_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2232 | } else if (oxcf->pass == 2) { |
| 2233 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 2234 | const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 2235 | |
| 2236 | #if CONFIG_FP_MB_STATS |
| 2237 | if (cpi->use_fp_mb_stats) { |
| 2238 | const size_t psz = cpi->common.MBs * sizeof(uint8_t); |
| 2239 | const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz); |
| 2240 | |
| 2241 | cpi->twopass.firstpass_mb_stats.mb_stats_start = |
| 2242 | oxcf->firstpass_mb_stats_in.buf; |
| 2243 | cpi->twopass.firstpass_mb_stats.mb_stats_end = |
| 2244 | cpi->twopass.firstpass_mb_stats.mb_stats_start + |
| 2245 | (ps - 1) * cpi->common.MBs * sizeof(uint8_t); |
| 2246 | } |
| 2247 | #endif |
| 2248 | |
| 2249 | cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 2250 | cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 2251 | cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 2252 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2253 | av1_init_second_pass(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2254 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 2255 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2256 | |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2257 | #if CONFIG_MOTION_VAR |
| 2258 | #if CONFIG_HIGHBITDEPTH |
| 2259 | int buf_scaler = 2; |
| 2260 | #else |
| 2261 | int buf_scaler = 1; |
| 2262 | #endif |
| 2263 | CHECK_MEM_ERROR( |
| 2264 | cm, cpi->td.mb.above_pred_buf, |
| 2265 | (uint8_t *)aom_memalign(16, buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2266 | sizeof(*cpi->td.mb.above_pred_buf))); |
| 2267 | CHECK_MEM_ERROR( |
| 2268 | cm, cpi->td.mb.left_pred_buf, |
| 2269 | (uint8_t *)aom_memalign(16, buf_scaler * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 2270 | sizeof(*cpi->td.mb.left_pred_buf))); |
| 2271 | |
| 2272 | CHECK_MEM_ERROR(cm, cpi->td.mb.wsrc_buf, |
| 2273 | (int32_t *)aom_memalign( |
| 2274 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.wsrc_buf))); |
| 2275 | |
| 2276 | CHECK_MEM_ERROR(cm, cpi->td.mb.mask_buf, |
| 2277 | (int32_t *)aom_memalign( |
| 2278 | 16, MAX_SB_SQUARE * sizeof(*cpi->td.mb.mask_buf))); |
| 2279 | |
| 2280 | #endif |
| 2281 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2282 | init_upsampled_ref_frame_bufs(cpi); |
| 2283 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2284 | av1_set_speed_features_framesize_independent(cpi); |
| 2285 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2286 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2287 | #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF) \ |
| 2288 | cpi->fn_ptr[BT].sdf = SDF; \ |
| 2289 | cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 2290 | cpi->fn_ptr[BT].vf = VF; \ |
| 2291 | cpi->fn_ptr[BT].svf = SVF; \ |
| 2292 | cpi->fn_ptr[BT].svaf = SVAF; \ |
| 2293 | cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 2294 | cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 2295 | cpi->fn_ptr[BT].sdx4df = SDX4DF; |
| 2296 | |
| 2297 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2298 | BFP(BLOCK_128X128, aom_sad128x128, aom_sad128x128_avg, aom_variance128x128, |
| 2299 | aom_sub_pixel_variance128x128, aom_sub_pixel_avg_variance128x128, |
| 2300 | aom_sad128x128x3, aom_sad128x128x8, aom_sad128x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2301 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2302 | BFP(BLOCK_128X64, aom_sad128x64, aom_sad128x64_avg, aom_variance128x64, |
| 2303 | aom_sub_pixel_variance128x64, aom_sub_pixel_avg_variance128x64, NULL, |
| 2304 | NULL, aom_sad128x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2305 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2306 | BFP(BLOCK_64X128, aom_sad64x128, aom_sad64x128_avg, aom_variance64x128, |
| 2307 | aom_sub_pixel_variance64x128, aom_sub_pixel_avg_variance64x128, NULL, |
| 2308 | NULL, aom_sad64x128x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2309 | #endif // CONFIG_EXT_PARTITION |
| 2310 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2311 | BFP(BLOCK_32X16, aom_sad32x16, aom_sad32x16_avg, aom_variance32x16, |
| 2312 | aom_sub_pixel_variance32x16, aom_sub_pixel_avg_variance32x16, NULL, NULL, |
| 2313 | aom_sad32x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2314 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2315 | BFP(BLOCK_16X32, aom_sad16x32, aom_sad16x32_avg, aom_variance16x32, |
| 2316 | aom_sub_pixel_variance16x32, aom_sub_pixel_avg_variance16x32, NULL, NULL, |
| 2317 | aom_sad16x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2318 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2319 | BFP(BLOCK_64X32, aom_sad64x32, aom_sad64x32_avg, aom_variance64x32, |
| 2320 | aom_sub_pixel_variance64x32, aom_sub_pixel_avg_variance64x32, NULL, NULL, |
| 2321 | aom_sad64x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2322 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2323 | BFP(BLOCK_32X64, aom_sad32x64, aom_sad32x64_avg, aom_variance32x64, |
| 2324 | aom_sub_pixel_variance32x64, aom_sub_pixel_avg_variance32x64, NULL, NULL, |
| 2325 | aom_sad32x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2326 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2327 | BFP(BLOCK_32X32, aom_sad32x32, aom_sad32x32_avg, aom_variance32x32, |
| 2328 | aom_sub_pixel_variance32x32, aom_sub_pixel_avg_variance32x32, |
| 2329 | aom_sad32x32x3, aom_sad32x32x8, aom_sad32x32x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2330 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2331 | BFP(BLOCK_64X64, aom_sad64x64, aom_sad64x64_avg, aom_variance64x64, |
| 2332 | aom_sub_pixel_variance64x64, aom_sub_pixel_avg_variance64x64, |
| 2333 | aom_sad64x64x3, aom_sad64x64x8, aom_sad64x64x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2334 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2335 | BFP(BLOCK_16X16, aom_sad16x16, aom_sad16x16_avg, aom_variance16x16, |
| 2336 | aom_sub_pixel_variance16x16, aom_sub_pixel_avg_variance16x16, |
| 2337 | aom_sad16x16x3, aom_sad16x16x8, aom_sad16x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2338 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2339 | BFP(BLOCK_16X8, aom_sad16x8, aom_sad16x8_avg, aom_variance16x8, |
| 2340 | aom_sub_pixel_variance16x8, aom_sub_pixel_avg_variance16x8, aom_sad16x8x3, |
| 2341 | aom_sad16x8x8, aom_sad16x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2342 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2343 | BFP(BLOCK_8X16, aom_sad8x16, aom_sad8x16_avg, aom_variance8x16, |
| 2344 | aom_sub_pixel_variance8x16, aom_sub_pixel_avg_variance8x16, aom_sad8x16x3, |
| 2345 | aom_sad8x16x8, aom_sad8x16x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2346 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2347 | BFP(BLOCK_8X8, aom_sad8x8, aom_sad8x8_avg, aom_variance8x8, |
| 2348 | aom_sub_pixel_variance8x8, aom_sub_pixel_avg_variance8x8, aom_sad8x8x3, |
| 2349 | aom_sad8x8x8, aom_sad8x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2350 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2351 | BFP(BLOCK_8X4, aom_sad8x4, aom_sad8x4_avg, aom_variance8x4, |
| 2352 | aom_sub_pixel_variance8x4, aom_sub_pixel_avg_variance8x4, NULL, |
| 2353 | aom_sad8x4x8, aom_sad8x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2354 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2355 | BFP(BLOCK_4X8, aom_sad4x8, aom_sad4x8_avg, aom_variance4x8, |
| 2356 | aom_sub_pixel_variance4x8, aom_sub_pixel_avg_variance4x8, NULL, |
| 2357 | aom_sad4x8x8, aom_sad4x8x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2358 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2359 | BFP(BLOCK_4X4, aom_sad4x4, aom_sad4x4_avg, aom_variance4x4, |
| 2360 | aom_sub_pixel_variance4x4, aom_sub_pixel_avg_variance4x4, aom_sad4x4x3, |
| 2361 | aom_sad4x4x8, aom_sad4x4x4d) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2362 | |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 2363 | #if CONFIG_CB4X4 |
| 2364 | BFP(BLOCK_2X2, NULL, NULL, aom_variance2x2, NULL, NULL, NULL, NULL, NULL) |
Jingning Han | e2ffaf8 | 2016-12-14 15:26:30 -0800 | [diff] [blame] | 2365 | BFP(BLOCK_2X4, NULL, NULL, aom_variance2x4, NULL, NULL, NULL, NULL, NULL) |
| 2366 | BFP(BLOCK_4X2, NULL, NULL, aom_variance4x2, NULL, NULL, NULL, NULL, NULL) |
Jingning Han | 9e7c49f | 2016-12-06 11:20:10 -0800 | [diff] [blame] | 2367 | #endif |
| 2368 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2369 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2370 | #define OBFP(BT, OSDF, OVF, OSVF) \ |
| 2371 | cpi->fn_ptr[BT].osdf = OSDF; \ |
| 2372 | cpi->fn_ptr[BT].ovf = OVF; \ |
| 2373 | cpi->fn_ptr[BT].osvf = OSVF; |
| 2374 | |
| 2375 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2376 | OBFP(BLOCK_128X128, aom_obmc_sad128x128, aom_obmc_variance128x128, |
| 2377 | aom_obmc_sub_pixel_variance128x128) |
| 2378 | OBFP(BLOCK_128X64, aom_obmc_sad128x64, aom_obmc_variance128x64, |
| 2379 | aom_obmc_sub_pixel_variance128x64) |
| 2380 | OBFP(BLOCK_64X128, aom_obmc_sad64x128, aom_obmc_variance64x128, |
| 2381 | aom_obmc_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2382 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2383 | OBFP(BLOCK_64X64, aom_obmc_sad64x64, aom_obmc_variance64x64, |
| 2384 | aom_obmc_sub_pixel_variance64x64) |
| 2385 | OBFP(BLOCK_64X32, aom_obmc_sad64x32, aom_obmc_variance64x32, |
| 2386 | aom_obmc_sub_pixel_variance64x32) |
| 2387 | OBFP(BLOCK_32X64, aom_obmc_sad32x64, aom_obmc_variance32x64, |
| 2388 | aom_obmc_sub_pixel_variance32x64) |
| 2389 | OBFP(BLOCK_32X32, aom_obmc_sad32x32, aom_obmc_variance32x32, |
| 2390 | aom_obmc_sub_pixel_variance32x32) |
| 2391 | OBFP(BLOCK_32X16, aom_obmc_sad32x16, aom_obmc_variance32x16, |
| 2392 | aom_obmc_sub_pixel_variance32x16) |
| 2393 | OBFP(BLOCK_16X32, aom_obmc_sad16x32, aom_obmc_variance16x32, |
| 2394 | aom_obmc_sub_pixel_variance16x32) |
| 2395 | OBFP(BLOCK_16X16, aom_obmc_sad16x16, aom_obmc_variance16x16, |
| 2396 | aom_obmc_sub_pixel_variance16x16) |
| 2397 | OBFP(BLOCK_16X8, aom_obmc_sad16x8, aom_obmc_variance16x8, |
| 2398 | aom_obmc_sub_pixel_variance16x8) |
| 2399 | OBFP(BLOCK_8X16, aom_obmc_sad8x16, aom_obmc_variance8x16, |
| 2400 | aom_obmc_sub_pixel_variance8x16) |
| 2401 | OBFP(BLOCK_8X8, aom_obmc_sad8x8, aom_obmc_variance8x8, |
| 2402 | aom_obmc_sub_pixel_variance8x8) |
| 2403 | OBFP(BLOCK_4X8, aom_obmc_sad4x8, aom_obmc_variance4x8, |
| 2404 | aom_obmc_sub_pixel_variance4x8) |
| 2405 | OBFP(BLOCK_8X4, aom_obmc_sad8x4, aom_obmc_variance8x4, |
| 2406 | aom_obmc_sub_pixel_variance8x4) |
| 2407 | OBFP(BLOCK_4X4, aom_obmc_sad4x4, aom_obmc_variance4x4, |
| 2408 | aom_obmc_sub_pixel_variance4x4) |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 2409 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2410 | |
| 2411 | #if CONFIG_EXT_INTER |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2412 | #define MBFP(BT, MCSDF, MCSVF) \ |
| 2413 | cpi->fn_ptr[BT].msdf = MCSDF; \ |
| 2414 | cpi->fn_ptr[BT].msvf = MCSVF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2415 | |
| 2416 | #if CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2417 | MBFP(BLOCK_128X128, aom_masked_sad128x128, |
| 2418 | aom_masked_sub_pixel_variance128x128) |
| 2419 | MBFP(BLOCK_128X64, aom_masked_sad128x64, aom_masked_sub_pixel_variance128x64) |
| 2420 | MBFP(BLOCK_64X128, aom_masked_sad64x128, aom_masked_sub_pixel_variance64x128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2421 | #endif // CONFIG_EXT_PARTITION |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 2422 | MBFP(BLOCK_64X64, aom_masked_sad64x64, aom_masked_sub_pixel_variance64x64) |
| 2423 | MBFP(BLOCK_64X32, aom_masked_sad64x32, aom_masked_sub_pixel_variance64x32) |
| 2424 | MBFP(BLOCK_32X64, aom_masked_sad32x64, aom_masked_sub_pixel_variance32x64) |
| 2425 | MBFP(BLOCK_32X32, aom_masked_sad32x32, aom_masked_sub_pixel_variance32x32) |
| 2426 | MBFP(BLOCK_32X16, aom_masked_sad32x16, aom_masked_sub_pixel_variance32x16) |
| 2427 | MBFP(BLOCK_16X32, aom_masked_sad16x32, aom_masked_sub_pixel_variance16x32) |
| 2428 | MBFP(BLOCK_16X16, aom_masked_sad16x16, aom_masked_sub_pixel_variance16x16) |
| 2429 | MBFP(BLOCK_16X8, aom_masked_sad16x8, aom_masked_sub_pixel_variance16x8) |
| 2430 | MBFP(BLOCK_8X16, aom_masked_sad8x16, aom_masked_sub_pixel_variance8x16) |
| 2431 | MBFP(BLOCK_8X8, aom_masked_sad8x8, aom_masked_sub_pixel_variance8x8) |
| 2432 | MBFP(BLOCK_4X8, aom_masked_sad4x8, aom_masked_sub_pixel_variance4x8) |
| 2433 | MBFP(BLOCK_8X4, aom_masked_sad8x4, aom_masked_sub_pixel_variance8x4) |
| 2434 | MBFP(BLOCK_4X4, aom_masked_sad4x4, aom_masked_sub_pixel_variance4x4) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2435 | #endif // CONFIG_EXT_INTER |
| 2436 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2437 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2438 | highbd_set_var_fns(cpi); |
| 2439 | #endif |
| 2440 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2441 | /* av1_init_quantizer() is first called here. Add check in |
| 2442 | * av1_frame_init_quantizer() so that av1_init_quantizer is only |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2443 | * called later when needed. This will avoid unnecessary calls of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2444 | * av1_init_quantizer() for every frame. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2445 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2446 | av1_init_quantizer(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2447 | #if CONFIG_AOM_QM |
| 2448 | aom_qm_init(cm); |
| 2449 | #endif |
| 2450 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2451 | av1_loop_filter_init(cm); |
Fergus Simpson | dac6aff | 2017-05-18 15:11:38 -0700 | [diff] [blame] | 2452 | #if CONFIG_FRAME_SUPERRES |
| 2453 | cm->superres_scale_numerator = SUPERRES_SCALE_DENOMINATOR; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 2454 | cm->superres_upscaled_width = oxcf->scaled_frame_width; |
| 2455 | cm->superres_upscaled_height = oxcf->scaled_frame_height; |
Fergus Simpson | dac6aff | 2017-05-18 15:11:38 -0700 | [diff] [blame] | 2456 | #endif // CONFIG_FRAME_SUPERRES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2457 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2458 | av1_loop_restoration_precal(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2459 | #endif // CONFIG_LOOP_RESTORATION |
| 2460 | |
| 2461 | cm->error.setjmp = 0; |
| 2462 | |
| 2463 | return cpi; |
| 2464 | } |
| 2465 | |
| 2466 | #define SNPRINT(H, T) snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T)) |
| 2467 | |
| 2468 | #define SNPRINT2(H, T, V) \ |
| 2469 | snprintf((H) + strlen(H), sizeof(H) - strlen(H), (T), (V)) |
| 2470 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2471 | void av1_remove_compressor(AV1_COMP *cpi) { |
| 2472 | AV1_COMMON *cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2473 | unsigned int i; |
| 2474 | int t; |
| 2475 | |
| 2476 | if (!cpi) return; |
| 2477 | |
| 2478 | cm = &cpi->common; |
| 2479 | if (cm->current_video_frame > 0) { |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 2480 | #if CONFIG_ENTROPY_STATS |
| 2481 | if (cpi->oxcf.pass != 1) { |
| 2482 | fprintf(stderr, "Writing counts.stt\n"); |
| 2483 | FILE *f = fopen("counts.stt", "wb"); |
| 2484 | fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f); |
| 2485 | fclose(f); |
| 2486 | } |
| 2487 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2488 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2489 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2490 | |
| 2491 | if (cpi->oxcf.pass != 1) { |
| 2492 | char headings[512] = { 0 }; |
| 2493 | char results[512] = { 0 }; |
| 2494 | FILE *f = fopen("opsnr.stt", "a"); |
| 2495 | double time_encoded = |
| 2496 | (cpi->last_end_time_stamp_seen - cpi->first_time_stamp_ever) / |
| 2497 | 10000000.000; |
| 2498 | double total_encode_time = |
| 2499 | (cpi->time_receive_data + cpi->time_compress_data) / 1000.000; |
| 2500 | const double dr = |
| 2501 | (double)cpi->bytes * (double)8 / (double)1000 / time_encoded; |
| 2502 | const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 2503 | const double target_rate = (double)cpi->oxcf.target_bandwidth / 1000; |
| 2504 | const double rate_err = ((100.0 * (dr - target_rate)) / target_rate); |
| 2505 | |
| 2506 | if (cpi->b_calculate_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2507 | const double total_psnr = aom_sse_to_psnr( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2508 | (double)cpi->total_samples, peak, (double)cpi->total_sq_error); |
| 2509 | const double total_ssim = |
| 2510 | 100 * pow(cpi->summed_quality / cpi->summed_weights, 8.0); |
| 2511 | snprintf(headings, sizeof(headings), |
| 2512 | "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2513 | "AOMSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2514 | "WstPsnr\tWstSsim\tWstFast\tWstHVS"); |
| 2515 | snprintf(results, sizeof(results), |
| 2516 | "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 2517 | "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 2518 | "%7.3f\t%7.3f\t%7.3f\t%7.3f", |
| 2519 | dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr, |
| 2520 | cpi->psnr.stat[ALL] / cpi->count, total_psnr, total_ssim, |
| 2521 | total_ssim, cpi->fastssim.stat[ALL] / cpi->count, |
| 2522 | cpi->psnrhvs.stat[ALL] / cpi->count, cpi->psnr.worst, |
| 2523 | cpi->worst_ssim, cpi->fastssim.worst, cpi->psnrhvs.worst); |
| 2524 | |
| 2525 | if (cpi->b_calculate_blockiness) { |
| 2526 | SNPRINT(headings, "\t Block\tWstBlck"); |
| 2527 | SNPRINT2(results, "\t%7.3f", cpi->total_blockiness / cpi->count); |
| 2528 | SNPRINT2(results, "\t%7.3f", cpi->worst_blockiness); |
| 2529 | } |
| 2530 | |
| 2531 | if (cpi->b_calculate_consistency) { |
| 2532 | double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2533 | aom_sse_to_psnr((double)cpi->total_samples, peak, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2534 | (double)cpi->total_inconsistency); |
| 2535 | |
| 2536 | SNPRINT(headings, "\tConsist\tWstCons"); |
| 2537 | SNPRINT2(results, "\t%7.3f", consistency); |
| 2538 | SNPRINT2(results, "\t%7.3f", cpi->worst_consistency); |
| 2539 | } |
Sarah Parker | f97b786 | 2016-08-25 17:42:57 -0700 | [diff] [blame] | 2540 | fprintf(f, "%s\t Time\tRcErr\tAbsErr\n", headings); |
| 2541 | 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] | 2542 | rate_err, fabs(rate_err)); |
| 2543 | } |
| 2544 | |
| 2545 | fclose(f); |
| 2546 | } |
| 2547 | |
| 2548 | #endif |
| 2549 | |
| 2550 | #if 0 |
| 2551 | { |
| 2552 | printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); |
| 2553 | printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); |
| 2554 | printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, |
| 2555 | cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, |
| 2556 | cpi->time_compress_data / 1000, |
| 2557 | (cpi->time_receive_data + cpi->time_compress_data) / 1000); |
| 2558 | } |
| 2559 | #endif |
| 2560 | } |
| 2561 | |
| 2562 | for (t = 0; t < cpi->num_workers; ++t) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2563 | AVxWorker *const worker = &cpi->workers[t]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2564 | EncWorkerData *const thread_data = &cpi->tile_thr_data[t]; |
| 2565 | |
| 2566 | // Deallocate allocated threads. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2567 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2568 | |
| 2569 | // Deallocate allocated thread data. |
| 2570 | if (t < cpi->num_workers - 1) { |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 2571 | #if CONFIG_PALETTE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2572 | if (cpi->common.allow_screen_content_tools) |
hui su | 5d49314 | 2017-05-08 12:06:12 -0700 | [diff] [blame] | 2573 | aom_free(thread_data->td->palette_buffer); |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 2574 | #endif // CONFIG_PALETTE |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 2575 | #if CONFIG_MOTION_VAR |
| 2576 | aom_free(thread_data->td->above_pred_buf); |
| 2577 | aom_free(thread_data->td->left_pred_buf); |
| 2578 | aom_free(thread_data->td->wsrc_buf); |
| 2579 | aom_free(thread_data->td->mask_buf); |
| 2580 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2581 | aom_free(thread_data->td->counts); |
| 2582 | av1_free_pc_tree(thread_data->td); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2583 | aom_free(thread_data->td); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2584 | } |
| 2585 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2586 | aom_free(cpi->tile_thr_data); |
| 2587 | aom_free(cpi->workers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2588 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2589 | 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] | 2590 | |
| 2591 | dealloc_compressor_data(cpi); |
| 2592 | |
| 2593 | for (i = 0; i < sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]); |
| 2594 | ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2595 | aom_free(cpi->mbgraph_stats[i].mb_stats); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | #if CONFIG_FP_MB_STATS |
| 2599 | if (cpi->use_fp_mb_stats) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2600 | aom_free(cpi->twopass.frame_mb_stats_buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2601 | cpi->twopass.frame_mb_stats_buf = NULL; |
| 2602 | } |
| 2603 | #endif |
Debargha Mukherjee | 5d15721 | 2017-01-10 14:44:47 -0800 | [diff] [blame] | 2604 | #if CONFIG_INTERNAL_STATS |
| 2605 | aom_free(cpi->ssim_vars); |
| 2606 | cpi->ssim_vars = NULL; |
| 2607 | #endif // CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2608 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2609 | av1_remove_common(cm); |
| 2610 | av1_free_ref_frame_buffers(cm->buffer_pool); |
| 2611 | aom_free(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2612 | |
| 2613 | #ifdef OUTPUT_YUV_SKINMAP |
| 2614 | fclose(yuv_skinmap_file); |
| 2615 | #endif |
| 2616 | #ifdef OUTPUT_YUV_REC |
| 2617 | fclose(yuv_rec_file); |
| 2618 | #endif |
| 2619 | |
| 2620 | #if 0 |
| 2621 | |
| 2622 | if (keyfile) |
| 2623 | fclose(keyfile); |
| 2624 | |
| 2625 | if (framepsnr) |
| 2626 | fclose(framepsnr); |
| 2627 | |
| 2628 | if (kf_list) |
| 2629 | fclose(kf_list); |
| 2630 | |
| 2631 | #endif |
| 2632 | } |
| 2633 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2634 | static void generate_psnr_packet(AV1_COMP *cpi) { |
| 2635 | struct aom_codec_cx_pkt pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2636 | int i; |
| 2637 | PSNR_STATS psnr; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2638 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 2639 | aom_calc_highbd_psnr(cpi->source, cpi->common.frame_to_show, &psnr, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2640 | cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
| 2641 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 2642 | aom_calc_psnr(cpi->source, cpi->common.frame_to_show, &psnr); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2643 | #endif |
| 2644 | |
| 2645 | for (i = 0; i < 4; ++i) { |
| 2646 | pkt.data.psnr.samples[i] = psnr.samples[i]; |
| 2647 | pkt.data.psnr.sse[i] = psnr.sse[i]; |
| 2648 | pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
| 2649 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2650 | pkt.kind = AOM_CODEC_PSNR_PKT; |
| 2651 | aom_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2652 | } |
| 2653 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2654 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2655 | if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1)) return -1; |
| 2656 | |
| 2657 | cpi->ref_frame_flags = ref_frame_flags; |
| 2658 | return 0; |
| 2659 | } |
| 2660 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2661 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags) { |
| 2662 | cpi->ext_refresh_golden_frame = (ref_frame_flags & AOM_GOLD_FLAG) != 0; |
| 2663 | cpi->ext_refresh_alt_ref_frame = (ref_frame_flags & AOM_ALT_FLAG) != 0; |
| 2664 | cpi->ext_refresh_last_frame = (ref_frame_flags & AOM_LAST_FLAG) != 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2665 | cpi->ext_refresh_frame_flags_pending = 1; |
| 2666 | } |
| 2667 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2668 | static YV12_BUFFER_CONFIG *get_av1_ref_frame_buffer( |
| 2669 | AV1_COMP *cpi, AOM_REFFRAME ref_frame_flag) { |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 2670 | MV_REFERENCE_FRAME ref_frame = NONE_FRAME; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2671 | if (ref_frame_flag == AOM_LAST_FLAG) ref_frame = LAST_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2672 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2673 | else if (ref_frame_flag == AOM_LAST2_FLAG) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2674 | ref_frame = LAST2_FRAME; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2675 | else if (ref_frame_flag == AOM_LAST3_FLAG) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2676 | ref_frame = LAST3_FRAME; |
| 2677 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2678 | else if (ref_frame_flag == AOM_GOLD_FLAG) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2679 | ref_frame = GOLDEN_FRAME; |
| 2680 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2681 | else if (ref_frame_flag == AOM_BWD_FLAG) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2682 | ref_frame = BWDREF_FRAME; |
| 2683 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2684 | else if (ref_frame_flag == AOM_ALT_FLAG) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2685 | ref_frame = ALTREF_FRAME; |
| 2686 | |
Emil Keyder | 01770b3 | 2017-01-20 18:03:11 -0500 | [diff] [blame] | 2687 | return ref_frame == NONE_FRAME ? NULL : get_ref_frame_buffer(cpi, ref_frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2688 | } |
| 2689 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2690 | int av1_copy_reference_enc(AV1_COMP *cpi, AOM_REFFRAME ref_frame_flag, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2691 | YV12_BUFFER_CONFIG *sd) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2692 | YV12_BUFFER_CONFIG *cfg = get_av1_ref_frame_buffer(cpi, ref_frame_flag); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2693 | if (cfg) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2694 | aom_yv12_copy_frame(cfg, sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2695 | return 0; |
| 2696 | } else { |
| 2697 | return -1; |
| 2698 | } |
| 2699 | } |
| 2700 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2701 | int av1_set_reference_enc(AV1_COMP *cpi, AOM_REFFRAME ref_frame_flag, |
| 2702 | YV12_BUFFER_CONFIG *sd) { |
| 2703 | YV12_BUFFER_CONFIG *cfg = get_av1_ref_frame_buffer(cpi, ref_frame_flag); |
| 2704 | if (cfg) { |
| 2705 | aom_yv12_copy_frame(sd, cfg); |
| 2706 | return 0; |
| 2707 | } else { |
| 2708 | return -1; |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | int av1_update_entropy(AV1_COMP *cpi, int update) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2713 | cpi->ext_refresh_frame_context = update; |
| 2714 | cpi->ext_refresh_frame_context_pending = 1; |
| 2715 | return 0; |
| 2716 | } |
| 2717 | |
| 2718 | #if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) |
| 2719 | // The denoiser buffer is allocated as a YUV 440 buffer. This function writes it |
| 2720 | // as YUV 420. We simply use the top-left pixels of the UV buffers, since we do |
| 2721 | // not denoise the UV channels at this time. If ever we implement UV channel |
| 2722 | // denoising we will have to modify this. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2723 | void aom_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2724 | uint8_t *src = s->y_buffer; |
| 2725 | int h = s->y_height; |
| 2726 | |
| 2727 | do { |
| 2728 | fwrite(src, s->y_width, 1, f); |
| 2729 | src += s->y_stride; |
| 2730 | } while (--h); |
| 2731 | |
| 2732 | src = s->u_buffer; |
| 2733 | h = s->uv_height; |
| 2734 | |
| 2735 | do { |
| 2736 | fwrite(src, s->uv_width, 1, f); |
| 2737 | src += s->uv_stride; |
| 2738 | } while (--h); |
| 2739 | |
| 2740 | src = s->v_buffer; |
| 2741 | h = s->uv_height; |
| 2742 | |
| 2743 | do { |
| 2744 | fwrite(src, s->uv_width, 1, f); |
| 2745 | src += s->uv_stride; |
| 2746 | } while (--h); |
| 2747 | } |
| 2748 | #endif |
| 2749 | |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 2750 | #if CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2751 | static void check_show_existing_frame(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2752 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2753 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2754 | const FRAME_UPDATE_TYPE next_frame_update_type = |
| 2755 | gf_group->update_type[gf_group->index]; |
| 2756 | const int which_arf = gf_group->arf_update_idx[gf_group->index]; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 2757 | |
| 2758 | if (cm->show_existing_frame == 1) { |
| 2759 | cm->show_existing_frame = 0; |
| 2760 | } else if (cpi->rc.is_last_bipred_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2761 | // NOTE(zoeliu): If the current frame is a last bi-predictive frame, it is |
| 2762 | // needed next to show the BWDREF_FRAME, which is pointed by |
| 2763 | // the last_fb_idxes[0] after reference frame buffer update |
| 2764 | cpi->rc.is_last_bipred_frame = 0; |
| 2765 | cm->show_existing_frame = 1; |
| 2766 | cpi->existing_fb_idx_to_show = cpi->lst_fb_idxes[0]; |
| 2767 | } else if (cpi->is_arf_filter_off[which_arf] && |
| 2768 | (next_frame_update_type == OVERLAY_UPDATE || |
| 2769 | next_frame_update_type == INTNL_OVERLAY_UPDATE)) { |
| 2770 | // Other parameters related to OVERLAY_UPDATE will be taken care of |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2771 | // in av1_rc_get_second_pass_params(cpi) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2772 | cm->show_existing_frame = 1; |
| 2773 | cpi->rc.is_src_frame_alt_ref = 1; |
| 2774 | cpi->existing_fb_idx_to_show = cpi->alt_fb_idx; |
| 2775 | cpi->is_arf_filter_off[which_arf] = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2776 | } |
| 2777 | cpi->rc.is_src_frame_ext_arf = 0; |
| 2778 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 2779 | #endif // CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2780 | |
| 2781 | #ifdef OUTPUT_YUV_REC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2782 | 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] | 2783 | uint8_t *src = s->y_buffer; |
| 2784 | int h = cm->height; |
| 2785 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2786 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2787 | if (s->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 2788 | uint16_t *src16 = CONVERT_TO_SHORTPTR(s->y_buffer); |
| 2789 | |
| 2790 | do { |
| 2791 | fwrite(src16, s->y_width, 2, yuv_rec_file); |
| 2792 | src16 += s->y_stride; |
| 2793 | } while (--h); |
| 2794 | |
| 2795 | src16 = CONVERT_TO_SHORTPTR(s->u_buffer); |
| 2796 | h = s->uv_height; |
| 2797 | |
| 2798 | do { |
| 2799 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 2800 | src16 += s->uv_stride; |
| 2801 | } while (--h); |
| 2802 | |
| 2803 | src16 = CONVERT_TO_SHORTPTR(s->v_buffer); |
| 2804 | h = s->uv_height; |
| 2805 | |
| 2806 | do { |
| 2807 | fwrite(src16, s->uv_width, 2, yuv_rec_file); |
| 2808 | src16 += s->uv_stride; |
| 2809 | } while (--h); |
| 2810 | |
| 2811 | fflush(yuv_rec_file); |
| 2812 | return; |
| 2813 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2814 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2815 | |
| 2816 | do { |
| 2817 | fwrite(src, s->y_width, 1, yuv_rec_file); |
| 2818 | src += s->y_stride; |
| 2819 | } while (--h); |
| 2820 | |
| 2821 | src = s->u_buffer; |
| 2822 | h = s->uv_height; |
| 2823 | |
| 2824 | do { |
| 2825 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 2826 | src += s->uv_stride; |
| 2827 | } while (--h); |
| 2828 | |
| 2829 | src = s->v_buffer; |
| 2830 | h = s->uv_height; |
| 2831 | |
| 2832 | do { |
| 2833 | fwrite(src, s->uv_width, 1, yuv_rec_file); |
| 2834 | src += s->uv_stride; |
| 2835 | } while (--h); |
| 2836 | |
| 2837 | fflush(yuv_rec_file); |
| 2838 | } |
| 2839 | #endif // OUTPUT_YUV_REC |
| 2840 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2841 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2842 | static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src, |
| 2843 | YV12_BUFFER_CONFIG *dst, int planes, |
| 2844 | int bd) { |
| 2845 | #else |
| 2846 | static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src, |
| 2847 | YV12_BUFFER_CONFIG *dst, int planes) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2848 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2849 | const int src_w = src->y_crop_width; |
| 2850 | const int src_h = src->y_crop_height; |
| 2851 | const int dst_w = dst->y_crop_width; |
| 2852 | const int dst_h = dst->y_crop_height; |
| 2853 | const uint8_t *const srcs[3] = { src->y_buffer, src->u_buffer, |
| 2854 | src->v_buffer }; |
| 2855 | const int src_strides[3] = { src->y_stride, src->uv_stride, src->uv_stride }; |
| 2856 | uint8_t *const dsts[3] = { dst->y_buffer, dst->u_buffer, dst->v_buffer }; |
| 2857 | const int dst_strides[3] = { dst->y_stride, dst->uv_stride, dst->uv_stride }; |
| 2858 | const InterpFilterParams interp_filter_params = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2859 | av1_get_interp_filter_params(EIGHTTAP_REGULAR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2860 | const int16_t *kernel = interp_filter_params.filter_ptr; |
| 2861 | const int taps = interp_filter_params.taps; |
| 2862 | int x, y, i; |
| 2863 | |
Yaowu Xu | 637590c | 2016-11-16 15:15:46 -0800 | [diff] [blame] | 2864 | assert(planes <= 3); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2865 | for (y = 0; y < dst_h; y += 16) { |
| 2866 | for (x = 0; x < dst_w; x += 16) { |
| 2867 | for (i = 0; i < planes; ++i) { |
| 2868 | const int factor = (i == 0 || i == 3 ? 1 : 2); |
| 2869 | const int x_q4 = x * (16 / factor) * src_w / dst_w; |
| 2870 | const int y_q4 = y * (16 / factor) * src_h / dst_h; |
| 2871 | const int src_stride = src_strides[i]; |
| 2872 | const int dst_stride = dst_strides[i]; |
| 2873 | const uint8_t *src_ptr = srcs[i] + |
| 2874 | (y / factor) * src_h / dst_h * src_stride + |
| 2875 | (x / factor) * src_w / dst_w; |
| 2876 | uint8_t *dst_ptr = dsts[i] + (y / factor) * dst_stride + (x / factor); |
| 2877 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2878 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2879 | if (src->flags & YV12_FLAG_HIGHBITDEPTH) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2880 | aom_highbd_convolve8(src_ptr, src_stride, dst_ptr, dst_stride, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2881 | &kernel[(x_q4 & 0xf) * taps], 16 * src_w / dst_w, |
| 2882 | &kernel[(y_q4 & 0xf) * taps], 16 * src_h / dst_h, |
| 2883 | 16 / factor, 16 / factor, bd); |
| 2884 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2885 | aom_scaled_2d(src_ptr, src_stride, dst_ptr, dst_stride, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2886 | &kernel[(x_q4 & 0xf) * taps], 16 * src_w / dst_w, |
| 2887 | &kernel[(y_q4 & 0xf) * taps], 16 * src_h / dst_h, |
| 2888 | 16 / factor, 16 / factor); |
| 2889 | } |
| 2890 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2891 | aom_scaled_2d(src_ptr, src_stride, dst_ptr, dst_stride, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2892 | &kernel[(x_q4 & 0xf) * taps], 16 * src_w / dst_w, |
| 2893 | &kernel[(y_q4 & 0xf) * taps], 16 * src_h / dst_h, |
| 2894 | 16 / factor, 16 / factor); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2895 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2896 | } |
| 2897 | } |
| 2898 | } |
| 2899 | |
| 2900 | if (planes == 1) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2901 | aom_extend_frame_borders_y(dst); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2902 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2903 | aom_extend_frame_borders(dst); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2904 | } |
| 2905 | |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 2906 | #if CONFIG_GLOBAL_MOTION |
Debargha Mukherjee | 11f0e40 | 2017-03-29 07:42:40 -0700 | [diff] [blame] | 2907 | #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 2908 | static int recode_loop_test_global_motion(AV1_COMP *cpi) { |
| 2909 | int i; |
| 2910 | int recode = 0; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 2911 | RD_COUNTS *const rdc = &cpi->td.rd_counts; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 2912 | AV1_COMMON *const cm = &cpi->common; |
| 2913 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 2914 | if (cm->global_motion[i].wmtype != IDENTITY && |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 2915 | rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 2916 | cpi->gmparams_cost[i]) { |
Sarah Parker | 4c10a3c | 2017-04-10 19:37:59 -0700 | [diff] [blame] | 2917 | set_default_warp_params(&cm->global_motion[i]); |
Debargha Mukherjee | 265db6d | 2017-03-28 11:15:27 -0700 | [diff] [blame] | 2918 | cpi->gmparams_cost[i] = 0; |
David Barker | 43479c6 | 2016-11-30 10:34:20 +0000 | [diff] [blame] | 2919 | recode = 1; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 2920 | recode |= (rdc->global_motion_used[i] > 0); |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 2921 | } |
| 2922 | } |
| 2923 | return recode; |
| 2924 | } |
| 2925 | #endif // CONFIG_GLOBAL_MOTION |
| 2926 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2927 | // Function to test for conditions that indicate we should loop |
| 2928 | // back and recode a frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2929 | static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, |
| 2930 | int maxq, int minq) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2931 | const RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2932 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2933 | const int frame_is_kfgfarf = frame_is_kf_gf_arf(cpi); |
| 2934 | int force_recode = 0; |
| 2935 | |
| 2936 | if ((rc->projected_frame_size >= rc->max_frame_bandwidth) || |
| 2937 | (cpi->sf.recode_loop == ALLOW_RECODE) || |
| 2938 | (frame_is_kfgfarf && (cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2939 | // TODO(agrange) high_limit could be greater than the scale-down threshold. |
| 2940 | if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 2941 | (rc->projected_frame_size < low_limit && q > minq)) { |
| 2942 | force_recode = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2943 | } else if (cpi->oxcf.rc_mode == AOM_CQ) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2944 | // Deal with frame undershoot and whether or not we are |
| 2945 | // below the automatically set cq level. |
| 2946 | if (q > oxcf->cq_level && |
| 2947 | rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 2948 | force_recode = 1; |
| 2949 | } |
| 2950 | } |
| 2951 | } |
| 2952 | return force_recode; |
| 2953 | } |
| 2954 | |
| 2955 | static INLINE int get_free_upsampled_ref_buf(EncRefCntBuffer *ubufs) { |
| 2956 | int i; |
| 2957 | |
| 2958 | for (i = 0; i < (REF_FRAMES + 1); i++) { |
| 2959 | if (!ubufs[i].ref_count) { |
| 2960 | return i; |
| 2961 | } |
| 2962 | } |
| 2963 | return INVALID_IDX; |
| 2964 | } |
| 2965 | |
| 2966 | // Up-sample 1 reference frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2967 | static INLINE int upsample_ref_frame(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2968 | const YV12_BUFFER_CONFIG *const ref) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2969 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2970 | EncRefCntBuffer *ubufs = cpi->upsampled_ref_bufs; |
| 2971 | int new_uidx = get_free_upsampled_ref_buf(ubufs); |
| 2972 | |
| 2973 | if (new_uidx == INVALID_IDX) { |
| 2974 | return INVALID_IDX; |
| 2975 | } else { |
| 2976 | YV12_BUFFER_CONFIG *upsampled_ref = &ubufs[new_uidx].buf; |
| 2977 | |
| 2978 | // Can allocate buffer for Y plane only. |
| 2979 | if (upsampled_ref->buffer_alloc_sz < (ref->buffer_alloc_sz << 6)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2980 | if (aom_realloc_frame_buffer(upsampled_ref, (cm->width << 3), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2981 | (cm->height << 3), cm->subsampling_x, |
| 2982 | cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2983 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2984 | cm->use_highbitdepth, |
| 2985 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 2986 | (AOM_BORDER_IN_PIXELS << 3), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2987 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2988 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2989 | "Failed to allocate up-sampled frame buffer"); |
| 2990 | |
| 2991 | // Currently, only Y plane is up-sampled, U, V are not used. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2992 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2993 | scale_and_extend_frame(ref, upsampled_ref, 1, (int)cm->bit_depth); |
| 2994 | #else |
| 2995 | scale_and_extend_frame(ref, upsampled_ref, 1); |
| 2996 | #endif |
| 2997 | return new_uidx; |
| 2998 | } |
| 2999 | } |
| 3000 | |
| 3001 | #define DUMP_REF_FRAME_IMAGES 0 |
| 3002 | |
| 3003 | #if DUMP_REF_FRAME_IMAGES == 1 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3004 | static int dump_one_image(AV1_COMMON *cm, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3005 | const YV12_BUFFER_CONFIG *const ref_buf, |
| 3006 | char *file_name) { |
| 3007 | int h; |
| 3008 | FILE *f_ref = NULL; |
| 3009 | |
| 3010 | if (ref_buf == NULL) { |
| 3011 | printf("Frame data buffer is NULL.\n"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3012 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | if ((f_ref = fopen(file_name, "wb")) == NULL) { |
| 3016 | printf("Unable to open file %s to write.\n", file_name); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3017 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | // --- Y --- |
| 3021 | for (h = 0; h < cm->height; ++h) { |
| 3022 | fwrite(&ref_buf->y_buffer[h * ref_buf->y_stride], 1, cm->width, f_ref); |
| 3023 | } |
| 3024 | // --- U --- |
| 3025 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3026 | fwrite(&ref_buf->u_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3027 | f_ref); |
| 3028 | } |
| 3029 | // --- V --- |
| 3030 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 3031 | fwrite(&ref_buf->v_buffer[h * ref_buf->uv_stride], 1, (cm->width >> 1), |
| 3032 | f_ref); |
| 3033 | } |
| 3034 | |
| 3035 | fclose(f_ref); |
| 3036 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3037 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3040 | static void dump_ref_frame_images(AV1_COMP *cpi) { |
| 3041 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3042 | MV_REFERENCE_FRAME ref_frame; |
| 3043 | |
| 3044 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3045 | char file_name[256] = ""; |
| 3046 | snprintf(file_name, sizeof(file_name), "/tmp/enc_F%d_ref_%d.yuv", |
| 3047 | cm->current_video_frame, ref_frame); |
| 3048 | dump_one_image(cm, get_ref_frame_buffer(cpi, ref_frame), file_name); |
| 3049 | } |
| 3050 | } |
| 3051 | #endif // DUMP_REF_FRAME_IMAGES == 1 |
| 3052 | |
| 3053 | #if CONFIG_EXT_REFS |
| 3054 | // This function is used to shift the virtual indices of last reference frames |
| 3055 | // as follows: |
| 3056 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3057 | // when the LAST_FRAME is updated. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3058 | static INLINE void shift_last_ref_frames(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3059 | int ref_frame; |
| 3060 | for (ref_frame = LAST_REF_FRAMES - 1; ref_frame > 0; --ref_frame) { |
| 3061 | cpi->lst_fb_idxes[ref_frame] = cpi->lst_fb_idxes[ref_frame - 1]; |
| 3062 | |
| 3063 | // [0] is allocated to the current coded frame. The statistics for the |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3064 | // reference frames start at [LAST_FRAME], i.e. [1]. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3065 | if (!cpi->rc.is_src_frame_alt_ref) { |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3066 | memcpy(cpi->interp_filter_selected[ref_frame + LAST_FRAME], |
| 3067 | cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME], |
| 3068 | sizeof(cpi->interp_filter_selected[ref_frame - 1 + LAST_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3069 | } |
| 3070 | } |
| 3071 | } |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3072 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3073 | |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 3074 | #if CONFIG_VAR_REFS |
| 3075 | static void enc_check_valid_ref_frames(AV1_COMP *const cpi) { |
| 3076 | AV1_COMMON *const cm = &cpi->common; |
| 3077 | MV_REFERENCE_FRAME ref_frame; |
| 3078 | |
| 3079 | // TODO(zoeliu): To handle ALTREF_FRAME the same way as do with other |
| 3080 | // reference frames. Current encoder invalid ALTREF when ALTREF |
| 3081 | // is the same as LAST, but invalid all the other references |
| 3082 | // when they are the same as ALTREF. |
| 3083 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3084 | int ref_buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3085 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 3086 | |
| 3087 | if (ref_buf_idx != INVALID_IDX) { |
| 3088 | ref_buf->is_valid = 1; |
| 3089 | |
| 3090 | MV_REFERENCE_FRAME ref; |
| 3091 | for (ref = LAST_FRAME; ref < ref_frame; ++ref) { |
| 3092 | int buf_idx = get_ref_frame_buf_idx(cpi, ref); |
| 3093 | RefBuffer *const buf = &cm->frame_refs[ref - LAST_FRAME]; |
| 3094 | if (buf->is_valid && buf_idx == ref_buf_idx) { |
| 3095 | if (ref_frame != ALTREF_FRAME || ref == LAST_FRAME) { |
| 3096 | ref_buf->is_valid = 0; |
| 3097 | break; |
| 3098 | } else { |
| 3099 | buf->is_valid = 0; |
| 3100 | } |
| 3101 | } |
| 3102 | } |
| 3103 | } else { |
| 3104 | ref_buf->is_valid = 0; |
| 3105 | } |
| 3106 | } |
| 3107 | } |
| 3108 | #endif // CONFIG_VAR_REFS |
| 3109 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3110 | void av1_update_reference_frames(AV1_COMP *cpi) { |
| 3111 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3112 | BufferPool *const pool = cm->buffer_pool; |
| 3113 | const int use_upsampled_ref = cpi->sf.use_upsampled_references; |
| 3114 | int new_uidx = 0; |
| 3115 | |
| 3116 | // NOTE: Save the new show frame buffer index for --test-code=warn, i.e., |
| 3117 | // for the purpose to verify no mismatch between encoder and decoder. |
| 3118 | if (cm->show_frame) cpi->last_show_frame_buf_idx = cm->new_fb_idx; |
| 3119 | |
| 3120 | if (use_upsampled_ref) { |
| 3121 | #if CONFIG_EXT_REFS |
| 3122 | if (cm->show_existing_frame) { |
| 3123 | new_uidx = cpi->upsampled_ref_idx[cpi->existing_fb_idx_to_show]; |
| 3124 | // TODO(zoeliu): Once following is confirmed, remove it. |
| 3125 | assert(cpi->upsampled_ref_bufs[new_uidx].ref_count > 0); |
| 3126 | } else { |
| 3127 | #endif // CONFIG_EXT_REFS |
| 3128 | // Up-sample the current encoded frame. |
| 3129 | RefCntBuffer *bufs = pool->frame_bufs; |
| 3130 | const YV12_BUFFER_CONFIG *const ref = &bufs[cm->new_fb_idx].buf; |
| 3131 | |
| 3132 | new_uidx = upsample_ref_frame(cpi, ref); |
| 3133 | #if CONFIG_EXT_REFS |
| 3134 | assert(new_uidx != INVALID_IDX); |
| 3135 | } |
| 3136 | #endif // CONFIG_EXT_REFS |
| 3137 | } |
| 3138 | // At this point the new frame has been encoded. |
| 3139 | // If any buffer copy / swapping is signaled it should be done here. |
| 3140 | if (cm->frame_type == KEY_FRAME) { |
| 3141 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3142 | cm->new_fb_idx); |
| 3143 | #if CONFIG_EXT_REFS |
| 3144 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3145 | cm->new_fb_idx); |
| 3146 | #endif // CONFIG_EXT_REFS |
| 3147 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3148 | cm->new_fb_idx); |
| 3149 | |
| 3150 | if (use_upsampled_ref) { |
| 3151 | uref_cnt_fb(cpi->upsampled_ref_bufs, |
| 3152 | &cpi->upsampled_ref_idx[cpi->gld_fb_idx], new_uidx); |
| 3153 | #if CONFIG_EXT_REFS |
| 3154 | uref_cnt_fb(cpi->upsampled_ref_bufs, |
| 3155 | &cpi->upsampled_ref_idx[cpi->bwd_fb_idx], new_uidx); |
| 3156 | #endif // CONFIG_EXT_REFS |
| 3157 | uref_cnt_fb(cpi->upsampled_ref_bufs, |
| 3158 | &cpi->upsampled_ref_idx[cpi->alt_fb_idx], new_uidx); |
| 3159 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3160 | } else if (av1_preserve_existing_gf(cpi)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3161 | // We have decided to preserve the previously existing golden frame as our |
| 3162 | // new ARF frame. However, in the short term in function |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3163 | // 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] | 3164 | // we're updating the GF with the current decoded frame, we save it to the |
| 3165 | // ARF slot instead. |
| 3166 | // We now have to update the ARF with the current frame and swap gld_fb_idx |
| 3167 | // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF |
| 3168 | // slot and, if we're updating the GF, the current frame becomes the new GF. |
| 3169 | int tmp; |
| 3170 | |
| 3171 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->alt_fb_idx], |
| 3172 | cm->new_fb_idx); |
| 3173 | if (use_upsampled_ref) |
| 3174 | uref_cnt_fb(cpi->upsampled_ref_bufs, |
| 3175 | &cpi->upsampled_ref_idx[cpi->alt_fb_idx], new_uidx); |
| 3176 | |
| 3177 | tmp = cpi->alt_fb_idx; |
| 3178 | cpi->alt_fb_idx = cpi->gld_fb_idx; |
| 3179 | cpi->gld_fb_idx = tmp; |
| 3180 | |
| 3181 | #if CONFIG_EXT_REFS |
| 3182 | // We need to modify the mapping accordingly |
| 3183 | cpi->arf_map[0] = cpi->alt_fb_idx; |
| 3184 | #endif |
| 3185 | // TODO(zoeliu): Do we need to copy cpi->interp_filter_selected[0] over to |
| 3186 | // cpi->interp_filter_selected[GOLDEN_FRAME]? |
| 3187 | #if CONFIG_EXT_REFS |
| 3188 | } else if (cpi->rc.is_last_bipred_frame) { |
| 3189 | // Refresh the LAST_FRAME with the BWDREF_FRAME and retire the LAST3_FRAME |
| 3190 | // by updating the virtual indices. Note that the frame BWDREF_FRAME points |
| 3191 | // to now should be retired, and it should not be used before refreshed. |
| 3192 | int tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3193 | |
| 3194 | shift_last_ref_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3195 | cpi->lst_fb_idxes[0] = cpi->bwd_fb_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3196 | cpi->bwd_fb_idx = tmp; |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3197 | |
| 3198 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3199 | cpi->interp_filter_selected[BWDREF_FRAME], |
| 3200 | sizeof(cpi->interp_filter_selected[BWDREF_FRAME])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3201 | } else if (cpi->rc.is_src_frame_ext_arf && cm->show_existing_frame) { |
| 3202 | // Deal with the special case for showing existing internal ALTREF_FRAME |
| 3203 | // Refresh the LAST_FRAME with the ALTREF_FRAME and retire the LAST3_FRAME |
| 3204 | // by updating the virtual indices. |
| 3205 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3206 | int which_arf = gf_group->arf_ref_idx[gf_group->index]; |
| 3207 | int tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3208 | |
| 3209 | shift_last_ref_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3210 | cpi->lst_fb_idxes[0] = cpi->alt_fb_idx; |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3211 | cpi->alt_fb_idx = tmp; |
| 3212 | |
| 3213 | // We need to modify the mapping accordingly |
| 3214 | cpi->arf_map[which_arf] = cpi->alt_fb_idx; |
| 3215 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3216 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3217 | cpi->interp_filter_selected[ALTREF_FRAME + which_arf], |
| 3218 | sizeof(cpi->interp_filter_selected[ALTREF_FRAME + which_arf])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3219 | #endif // CONFIG_EXT_REFS |
| 3220 | } else { /* For non key/golden frames */ |
| 3221 | if (cpi->refresh_alt_ref_frame) { |
| 3222 | int arf_idx = cpi->alt_fb_idx; |
| 3223 | int which_arf = 0; |
| 3224 | #if CONFIG_EXT_REFS |
| 3225 | if (cpi->oxcf.pass == 2) { |
| 3226 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3227 | which_arf = gf_group->arf_update_idx[gf_group->index]; |
| 3228 | arf_idx = cpi->arf_map[which_arf]; |
| 3229 | } |
| 3230 | #else |
| 3231 | if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { |
| 3232 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3233 | arf_idx = gf_group->arf_update_idx[gf_group->index]; |
| 3234 | } |
| 3235 | #endif // CONFIG_EXT_REFS |
| 3236 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[arf_idx], cm->new_fb_idx); |
| 3237 | if (use_upsampled_ref) |
| 3238 | uref_cnt_fb(cpi->upsampled_ref_bufs, &cpi->upsampled_ref_idx[arf_idx], |
| 3239 | new_uidx); |
| 3240 | |
| 3241 | memcpy(cpi->interp_filter_selected[ALTREF_FRAME + which_arf], |
| 3242 | cpi->interp_filter_selected[0], |
| 3243 | sizeof(cpi->interp_filter_selected[0])); |
| 3244 | } |
| 3245 | |
| 3246 | if (cpi->refresh_golden_frame) { |
| 3247 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->gld_fb_idx], |
| 3248 | cm->new_fb_idx); |
| 3249 | if (use_upsampled_ref) |
| 3250 | uref_cnt_fb(cpi->upsampled_ref_bufs, |
| 3251 | &cpi->upsampled_ref_idx[cpi->gld_fb_idx], new_uidx); |
| 3252 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3253 | #if !CONFIG_EXT_REFS |
| 3254 | if (!cpi->rc.is_src_frame_alt_ref) |
| 3255 | #endif // !CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3256 | memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], |
| 3257 | cpi->interp_filter_selected[0], |
| 3258 | sizeof(cpi->interp_filter_selected[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
| 3261 | #if CONFIG_EXT_REFS |
| 3262 | if (cpi->refresh_bwd_ref_frame) { |
| 3263 | if (cpi->rc.is_bwd_ref_frame && cpi->num_extra_arfs) { |
| 3264 | // We have swapped the virtual indices to allow bwd_ref_frame to use |
| 3265 | // ALT0 as reference frame. We need to swap them back. |
| 3266 | // NOTE: The ALT_REFs' are indexed reversely, and ALT0 refers to the |
| 3267 | // farthest ALT_REF from the first frame in the gf group. |
| 3268 | int tmp = cpi->arf_map[0]; |
| 3269 | cpi->arf_map[0] = cpi->alt_fb_idx; |
| 3270 | cpi->alt_fb_idx = cpi->bwd_fb_idx; |
| 3271 | cpi->bwd_fb_idx = tmp; |
| 3272 | } |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3273 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3274 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->bwd_fb_idx], |
| 3275 | cm->new_fb_idx); |
| 3276 | if (use_upsampled_ref) |
| 3277 | uref_cnt_fb(cpi->upsampled_ref_bufs, |
| 3278 | &cpi->upsampled_ref_idx[cpi->bwd_fb_idx], new_uidx); |
| 3279 | |
| 3280 | memcpy(cpi->interp_filter_selected[BWDREF_FRAME], |
| 3281 | cpi->interp_filter_selected[0], |
| 3282 | sizeof(cpi->interp_filter_selected[0])); |
| 3283 | } |
| 3284 | #endif // CONFIG_EXT_REFS |
| 3285 | } |
| 3286 | |
| 3287 | if (cpi->refresh_last_frame) { |
| 3288 | #if CONFIG_EXT_REFS |
| 3289 | // NOTE(zoeliu): We have two layers of mapping (1) from the per-frame |
| 3290 | // reference to the reference frame buffer virtual index; and then (2) from |
| 3291 | // the virtual index to the reference frame buffer physical index: |
| 3292 | // |
| 3293 | // LAST_FRAME, ..., LAST3_FRAME, ..., ALTREF_FRAME |
| 3294 | // | | | |
| 3295 | // v v v |
| 3296 | // lst_fb_idxes[0], ..., lst_fb_idxes[2], ..., alt_fb_idx |
| 3297 | // | | | |
| 3298 | // v v v |
| 3299 | // ref_frame_map[], ..., ref_frame_map[], ..., ref_frame_map[] |
| 3300 | // |
| 3301 | // When refresh_last_frame is set, it is intended to retire LAST3_FRAME, |
| 3302 | // have the other 2 LAST reference frames shifted as follows: |
| 3303 | // LAST_FRAME -> LAST2_FRAME -> LAST3_FRAME |
| 3304 | // , and then have LAST_FRAME refreshed by the newly coded frame. |
| 3305 | // |
| 3306 | // To fulfill it, the decoder will be notified to execute following 2 steps: |
| 3307 | // |
| 3308 | // (a) To change ref_frame_map[] and have the virtual index of LAST3_FRAME |
| 3309 | // to point to the newly coded frame, i.e. |
| 3310 | // ref_frame_map[lst_fb_idexes[2]] => new_fb_idx; |
| 3311 | // |
| 3312 | // (b) To change the 1st layer mapping to have LAST_FRAME mapped to the |
| 3313 | // original virtual index of LAST3_FRAME and have the other mappings |
| 3314 | // shifted as follows: |
| 3315 | // LAST_FRAME, LAST2_FRAME, LAST3_FRAME |
| 3316 | // | | | |
| 3317 | // v v v |
| 3318 | // lst_fb_idxes[2], lst_fb_idxes[0], lst_fb_idxes[1] |
| 3319 | int ref_frame; |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3320 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3321 | if (cpi->rc.is_bwd_ref_frame && cpi->num_extra_arfs) { |
| 3322 | // We have swapped the virtual indices to use ALT0 as BWD_REF |
| 3323 | // and we need to swap them back. |
| 3324 | int tmp = cpi->arf_map[0]; |
| 3325 | cpi->arf_map[0] = cpi->alt_fb_idx; |
| 3326 | cpi->alt_fb_idx = cpi->bwd_fb_idx; |
| 3327 | cpi->bwd_fb_idx = tmp; |
| 3328 | } |
Zoe Liu | 5fca724 | 2016-10-10 17:18:57 -0700 | [diff] [blame] | 3329 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3330 | if (cm->frame_type == KEY_FRAME) { |
| 3331 | for (ref_frame = 0; ref_frame < LAST_REF_FRAMES; ++ref_frame) { |
| 3332 | ref_cnt_fb(pool->frame_bufs, |
| 3333 | &cm->ref_frame_map[cpi->lst_fb_idxes[ref_frame]], |
| 3334 | cm->new_fb_idx); |
| 3335 | |
| 3336 | if (use_upsampled_ref) |
| 3337 | uref_cnt_fb(cpi->upsampled_ref_bufs, |
| 3338 | &cpi->upsampled_ref_idx[cpi->lst_fb_idxes[ref_frame]], |
| 3339 | new_uidx); |
| 3340 | } |
| 3341 | } else { |
| 3342 | int tmp; |
| 3343 | |
| 3344 | ref_cnt_fb(pool->frame_bufs, |
| 3345 | &cm->ref_frame_map[cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]], |
| 3346 | cm->new_fb_idx); |
| 3347 | |
| 3348 | if (use_upsampled_ref) |
| 3349 | uref_cnt_fb( |
| 3350 | cpi->upsampled_ref_bufs, |
| 3351 | &cpi->upsampled_ref_idx[cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]], |
| 3352 | new_uidx); |
| 3353 | |
| 3354 | tmp = cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]; |
| 3355 | |
| 3356 | shift_last_ref_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3357 | cpi->lst_fb_idxes[0] = tmp; |
| 3358 | |
Zoe Liu | f0e4669 | 2016-10-12 12:31:43 -0700 | [diff] [blame] | 3359 | assert(cm->show_existing_frame == 0); |
| 3360 | // NOTE: Currently only LF_UPDATE and INTNL_OVERLAY_UPDATE frames are to |
| 3361 | // refresh the LAST_FRAME. |
| 3362 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3363 | cpi->interp_filter_selected[0], |
| 3364 | sizeof(cpi->interp_filter_selected[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3365 | } |
| 3366 | #else |
| 3367 | ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[cpi->lst_fb_idx], |
| 3368 | cm->new_fb_idx); |
| 3369 | if (use_upsampled_ref) |
| 3370 | uref_cnt_fb(cpi->upsampled_ref_bufs, |
| 3371 | &cpi->upsampled_ref_idx[cpi->lst_fb_idx], new_uidx); |
| 3372 | if (!cpi->rc.is_src_frame_alt_ref) { |
| 3373 | memcpy(cpi->interp_filter_selected[LAST_FRAME], |
| 3374 | cpi->interp_filter_selected[0], |
| 3375 | sizeof(cpi->interp_filter_selected[0])); |
| 3376 | } |
| 3377 | #endif // CONFIG_EXT_REFS |
| 3378 | } |
| 3379 | |
| 3380 | #if DUMP_REF_FRAME_IMAGES == 1 |
| 3381 | // Dump out all reference frame images. |
| 3382 | dump_ref_frame_images(cpi); |
| 3383 | #endif // DUMP_REF_FRAME_IMAGES |
| 3384 | } |
| 3385 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3386 | static INLINE void alloc_frame_mvs(AV1_COMMON *const cm, int buffer_idx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3387 | RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; |
| 3388 | if (new_fb_ptr->mvs == NULL || new_fb_ptr->mi_rows < cm->mi_rows || |
| 3389 | new_fb_ptr->mi_cols < cm->mi_cols) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3390 | aom_free(new_fb_ptr->mvs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3391 | CHECK_MEM_ERROR(cm, new_fb_ptr->mvs, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3392 | (MV_REF *)aom_calloc(cm->mi_rows * cm->mi_cols, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3393 | sizeof(*new_fb_ptr->mvs))); |
| 3394 | new_fb_ptr->mi_rows = cm->mi_rows; |
| 3395 | new_fb_ptr->mi_cols = cm->mi_cols; |
| 3396 | } |
| 3397 | } |
| 3398 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3399 | void av1_scale_references(AV1_COMP *cpi) { |
| 3400 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3401 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3402 | const AOM_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = { |
| 3403 | AOM_LAST_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3404 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3405 | AOM_LAST2_FLAG, |
| 3406 | AOM_LAST3_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3407 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3408 | AOM_GOLD_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3409 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3410 | AOM_BWD_FLAG, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3411 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3412 | AOM_ALT_FLAG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3413 | }; |
| 3414 | |
| 3415 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3416 | // 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] | 3417 | if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 3418 | BufferPool *const pool = cm->buffer_pool; |
| 3419 | const YV12_BUFFER_CONFIG *const ref = |
| 3420 | get_ref_frame_buffer(cpi, ref_frame); |
| 3421 | |
| 3422 | if (ref == NULL) { |
| 3423 | cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3424 | continue; |
| 3425 | } |
| 3426 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3427 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3428 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3429 | RefCntBuffer *new_fb_ptr = NULL; |
| 3430 | int force_scaling = 0; |
| 3431 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3432 | if (new_fb == INVALID_IDX) { |
| 3433 | new_fb = get_free_fb(cm); |
| 3434 | force_scaling = 1; |
| 3435 | } |
| 3436 | if (new_fb == INVALID_IDX) return; |
| 3437 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3438 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3439 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3440 | if (aom_realloc_frame_buffer( |
| 3441 | &new_fb_ptr->buf, cm->width, cm->height, cm->subsampling_x, |
| 3442 | cm->subsampling_y, cm->use_highbitdepth, AOM_BORDER_IN_PIXELS, |
| 3443 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3444 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3445 | "Failed to allocate frame buffer"); |
| 3446 | scale_and_extend_frame(ref, &new_fb_ptr->buf, MAX_MB_PLANE, |
| 3447 | (int)cm->bit_depth); |
| 3448 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3449 | alloc_frame_mvs(cm, new_fb); |
| 3450 | } |
| 3451 | #else |
| 3452 | if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 3453 | RefCntBuffer *new_fb_ptr = NULL; |
| 3454 | int force_scaling = 0; |
| 3455 | int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 3456 | if (new_fb == INVALID_IDX) { |
| 3457 | new_fb = get_free_fb(cm); |
| 3458 | force_scaling = 1; |
| 3459 | } |
| 3460 | if (new_fb == INVALID_IDX) return; |
| 3461 | new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 3462 | if (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3463 | new_fb_ptr->buf.y_crop_height != cm->height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3464 | 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] | 3465 | cm->subsampling_x, cm->subsampling_y, |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3466 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
| 3467 | NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3468 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3469 | "Failed to allocate frame buffer"); |
| 3470 | scale_and_extend_frame(ref, &new_fb_ptr->buf, MAX_MB_PLANE); |
| 3471 | cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 3472 | alloc_frame_mvs(cm, new_fb); |
| 3473 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3474 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3475 | |
| 3476 | if (cpi->sf.use_upsampled_references && |
| 3477 | (force_scaling || new_fb_ptr->buf.y_crop_width != cm->width || |
| 3478 | new_fb_ptr->buf.y_crop_height != cm->height)) { |
| 3479 | const int map_idx = get_ref_frame_map_idx(cpi, ref_frame); |
| 3480 | EncRefCntBuffer *ubuf = |
| 3481 | &cpi->upsampled_ref_bufs[cpi->upsampled_ref_idx[map_idx]]; |
| 3482 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3483 | if (aom_realloc_frame_buffer(&ubuf->buf, (cm->width << 3), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3484 | (cm->height << 3), cm->subsampling_x, |
| 3485 | cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3486 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3487 | cm->use_highbitdepth, |
| 3488 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3489 | (AOM_BORDER_IN_PIXELS << 3), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3490 | cm->byte_alignment, NULL, NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3491 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3492 | "Failed to allocate up-sampled frame buffer"); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3493 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3494 | scale_and_extend_frame(&new_fb_ptr->buf, &ubuf->buf, 1, |
| 3495 | (int)cm->bit_depth); |
| 3496 | #else |
| 3497 | scale_and_extend_frame(&new_fb_ptr->buf, &ubuf->buf, 1); |
| 3498 | #endif |
| 3499 | } |
| 3500 | } else { |
| 3501 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3502 | RefCntBuffer *const buf = &pool->frame_bufs[buf_idx]; |
| 3503 | buf->buf.y_crop_width = ref->y_crop_width; |
| 3504 | buf->buf.y_crop_height = ref->y_crop_height; |
| 3505 | cpi->scaled_ref_idx[ref_frame - 1] = buf_idx; |
| 3506 | ++buf->ref_count; |
| 3507 | } |
| 3508 | } else { |
| 3509 | if (cpi->oxcf.pass != 0) cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX; |
| 3510 | } |
| 3511 | } |
| 3512 | } |
| 3513 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3514 | static void release_scaled_references(AV1_COMP *cpi) { |
| 3515 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3516 | int i; |
| 3517 | if (cpi->oxcf.pass == 0) { |
| 3518 | // Only release scaled references under certain conditions: |
| 3519 | // if reference will be updated, or if scaled reference has same resolution. |
| 3520 | int refresh[INTER_REFS_PER_FRAME]; |
| 3521 | refresh[0] = (cpi->refresh_last_frame) ? 1 : 0; |
| 3522 | #if CONFIG_EXT_REFS |
| 3523 | refresh[1] = refresh[2] = 0; |
| 3524 | refresh[3] = (cpi->refresh_golden_frame) ? 1 : 0; |
| 3525 | refresh[4] = (cpi->refresh_bwd_ref_frame) ? 1 : 0; |
| 3526 | refresh[5] = (cpi->refresh_alt_ref_frame) ? 1 : 0; |
| 3527 | #else |
| 3528 | refresh[1] = (cpi->refresh_golden_frame) ? 1 : 0; |
| 3529 | refresh[2] = (cpi->refresh_alt_ref_frame) ? 1 : 0; |
| 3530 | #endif // CONFIG_EXT_REFS |
| 3531 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3532 | const int idx = cpi->scaled_ref_idx[i - 1]; |
| 3533 | RefCntBuffer *const buf = |
| 3534 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 3535 | const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, i); |
| 3536 | if (buf != NULL && |
| 3537 | (refresh[i - 1] || (buf->buf.y_crop_width == ref->y_crop_width && |
| 3538 | buf->buf.y_crop_height == ref->y_crop_height))) { |
| 3539 | --buf->ref_count; |
| 3540 | cpi->scaled_ref_idx[i - 1] = INVALID_IDX; |
| 3541 | } |
| 3542 | } |
| 3543 | } else { |
| 3544 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) { |
| 3545 | const int idx = cpi->scaled_ref_idx[i]; |
| 3546 | RefCntBuffer *const buf = |
| 3547 | idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[idx] : NULL; |
| 3548 | if (buf != NULL) { |
| 3549 | --buf->ref_count; |
| 3550 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 3551 | } |
| 3552 | } |
| 3553 | } |
| 3554 | } |
| 3555 | |
| 3556 | static void full_to_model_count(unsigned int *model_count, |
| 3557 | unsigned int *full_count) { |
| 3558 | int n; |
| 3559 | model_count[ZERO_TOKEN] = full_count[ZERO_TOKEN]; |
| 3560 | model_count[ONE_TOKEN] = full_count[ONE_TOKEN]; |
| 3561 | model_count[TWO_TOKEN] = full_count[TWO_TOKEN]; |
| 3562 | for (n = THREE_TOKEN; n < EOB_TOKEN; ++n) |
| 3563 | model_count[TWO_TOKEN] += full_count[n]; |
| 3564 | model_count[EOB_MODEL_TOKEN] = full_count[EOB_TOKEN]; |
| 3565 | } |
| 3566 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3567 | void av1_full_to_model_counts(av1_coeff_count_model *model_count, |
| 3568 | av1_coeff_count *full_count) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3569 | int i, j, k, l; |
| 3570 | |
| 3571 | for (i = 0; i < PLANE_TYPES; ++i) |
| 3572 | for (j = 0; j < REF_TYPES; ++j) |
| 3573 | for (k = 0; k < COEF_BANDS; ++k) |
| 3574 | for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) |
| 3575 | full_to_model_count(model_count[i][j][k][l], full_count[i][j][k][l]); |
| 3576 | } |
| 3577 | |
| 3578 | #if 0 && CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3579 | static void output_frame_level_debug_stats(AV1_COMP *cpi) { |
| 3580 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3581 | FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); |
| 3582 | int64_t recon_err; |
| 3583 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3584 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3585 | |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3586 | 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] | 3587 | |
| 3588 | if (cpi->twopass.total_left_stats.coded_error != 0.0) |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 3589 | fprintf(f, "%10u %dx%d %d %d %10d %10d %10d %10d" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3590 | "%10"PRId64" %10"PRId64" %5d %5d %10"PRId64" " |
| 3591 | "%10"PRId64" %10"PRId64" %10d " |
| 3592 | "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" |
| 3593 | "%6d %6d %5d %5d %5d " |
| 3594 | "%10"PRId64" %10.3lf" |
| 3595 | "%10lf %8u %10"PRId64" %10d %10d %10d\n", |
| 3596 | cpi->common.current_video_frame, |
| 3597 | cm->width, cm->height, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3598 | cpi->rc.source_alt_ref_pending, |
| 3599 | cpi->rc.source_alt_ref_active, |
| 3600 | cpi->rc.this_frame_target, |
| 3601 | cpi->rc.projected_frame_size, |
| 3602 | cpi->rc.projected_frame_size / cpi->common.MBs, |
| 3603 | (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), |
| 3604 | cpi->rc.vbr_bits_off_target, |
| 3605 | cpi->rc.vbr_bits_off_target_fast, |
| 3606 | cpi->twopass.extend_minq, |
| 3607 | cpi->twopass.extend_minq_fast, |
| 3608 | cpi->rc.total_target_vs_actual, |
| 3609 | (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), |
| 3610 | cpi->rc.total_actual_bits, cm->base_qindex, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3611 | av1_convert_qindex_to_q(cm->base_qindex, cm->bit_depth), |
| 3612 | (double)av1_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0, |
| 3613 | av1_convert_qindex_to_q(cpi->twopass.active_worst_quality, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3614 | cm->bit_depth), |
| 3615 | cpi->rc.avg_q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3616 | av1_convert_qindex_to_q(cpi->oxcf.cq_level, cm->bit_depth), |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3617 | cpi->refresh_last_frame, cpi->refresh_golden_frame, |
| 3618 | cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, |
| 3619 | cpi->twopass.bits_left, |
| 3620 | cpi->twopass.total_left_stats.coded_error, |
| 3621 | cpi->twopass.bits_left / |
| 3622 | (1 + cpi->twopass.total_left_stats.coded_error), |
| 3623 | cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost, |
| 3624 | cpi->twopass.kf_zeromotion_pct, |
| 3625 | cpi->twopass.fr_content_type); |
| 3626 | |
| 3627 | fclose(f); |
| 3628 | |
| 3629 | if (0) { |
| 3630 | FILE *const fmodes = fopen("Modes.stt", "a"); |
| 3631 | int i; |
| 3632 | |
| 3633 | fprintf(fmodes, "%6d:%1d:%1d:%1d ", cpi->common.current_video_frame, |
| 3634 | cm->frame_type, cpi->refresh_golden_frame, |
| 3635 | cpi->refresh_alt_ref_frame); |
| 3636 | |
| 3637 | for (i = 0; i < MAX_MODES; ++i) |
| 3638 | fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]); |
| 3639 | |
| 3640 | fprintf(fmodes, "\n"); |
| 3641 | |
| 3642 | fclose(fmodes); |
| 3643 | } |
| 3644 | } |
| 3645 | #endif |
| 3646 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3647 | static void set_mv_search_params(AV1_COMP *cpi) { |
| 3648 | const AV1_COMMON *const cm = &cpi->common; |
| 3649 | const unsigned int max_mv_def = AOMMIN(cm->width, cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3650 | |
| 3651 | // Default based on max resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3652 | cpi->mv_step_param = av1_init_search_range(max_mv_def); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3653 | |
| 3654 | if (cpi->sf.mv.auto_mv_step_size) { |
| 3655 | if (frame_is_intra_only(cm)) { |
| 3656 | // Initialize max_mv_magnitude for use in the first INTER frame |
| 3657 | // after a key/intra-only frame. |
| 3658 | cpi->max_mv_magnitude = max_mv_def; |
| 3659 | } else { |
| 3660 | if (cm->show_frame) { |
| 3661 | // Allow mv_steps to correspond to twice the max mv magnitude found |
| 3662 | // in the previous frame, capped by the default max_mv_magnitude based |
| 3663 | // on resolution. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3664 | cpi->mv_step_param = av1_init_search_range( |
| 3665 | AOMMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3666 | } |
| 3667 | cpi->max_mv_magnitude = 0; |
| 3668 | } |
| 3669 | } |
| 3670 | } |
| 3671 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3672 | static void set_size_independent_vars(AV1_COMP *cpi) { |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3673 | #if CONFIG_GLOBAL_MOTION |
| 3674 | int i; |
| 3675 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
Sarah Parker | 4c10a3c | 2017-04-10 19:37:59 -0700 | [diff] [blame] | 3676 | set_default_warp_params(&cpi->common.global_motion[i]); |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 3677 | } |
| 3678 | cpi->global_motion_search_done = 0; |
| 3679 | #endif // CONFIG_GLOBAL_MOTION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3680 | av1_set_speed_features_framesize_independent(cpi); |
| 3681 | av1_set_rd_speed_thresholds(cpi); |
| 3682 | av1_set_rd_speed_thresholds_sub8x8(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3683 | cpi->common.interp_filter = cpi->sf.default_interp_filter; |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3684 | #if CONFIG_EXT_INTER |
| 3685 | if (!frame_is_intra_only(&cpi->common)) set_compound_tools(&cpi->common); |
| 3686 | #endif // CONFIG_EXT_INTER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3687 | } |
| 3688 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3689 | 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] | 3690 | int *top_index) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3691 | AV1_COMMON *const cm = &cpi->common; |
| 3692 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3693 | |
| 3694 | // Setup variables that depend on the dimensions of the frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3695 | av1_set_speed_features_framesize_dependent(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3696 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 3697 | // Decide q and q bounds. |
| 3698 | #if CONFIG_XIPHRC |
| 3699 | int frame_type = cm->frame_type == KEY_FRAME ? OD_I_FRAME : OD_P_FRAME; |
| 3700 | *q = od_enc_rc_select_quantizers_and_lambdas( |
| 3701 | &cpi->od_rc, cpi->refresh_golden_frame, cpi->refresh_alt_ref_frame, |
| 3702 | frame_type, bottom_index, top_index); |
| 3703 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3704 | *q = av1_rc_pick_q_and_bounds(cpi, bottom_index, top_index); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 3705 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3706 | |
| 3707 | if (!frame_is_intra_only(cm)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3708 | av1_set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | // Configure experimental use of segmentation for enhanced coding of |
| 3712 | // static regions if indicated. |
| 3713 | // Only allowed in the second pass of a two pass encode, as it requires |
| 3714 | // lagged coding, and if the relevant speed feature flag is set. |
| 3715 | if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 3716 | configure_static_seg_features(cpi); |
| 3717 | } |
| 3718 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3719 | static void init_motion_estimation(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3720 | int y_stride = cpi->scaled_source.y_stride; |
| 3721 | |
| 3722 | if (cpi->sf.mv.search_method == NSTEP) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3723 | av1_init3smotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3724 | } else if (cpi->sf.mv.search_method == DIAMOND) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3725 | av1_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3726 | } |
| 3727 | } |
| 3728 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3729 | #if CONFIG_LOOP_RESTORATION |
| 3730 | static void set_restoration_tilesize(int width, int height, |
| 3731 | RestorationInfo *rst) { |
| 3732 | (void)width; |
| 3733 | (void)height; |
| 3734 | rst[0].restoration_tilesize = (RESTORATION_TILESIZE_MAX >> 1); |
| 3735 | rst[1].restoration_tilesize = rst[0].restoration_tilesize; |
| 3736 | rst[2].restoration_tilesize = rst[0].restoration_tilesize; |
| 3737 | } |
| 3738 | #endif // CONFIG_LOOP_RESTORATION |
| 3739 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3740 | static void set_frame_size(AV1_COMP *cpi, int width, int height) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3741 | AV1_COMMON *const cm = &cpi->common; |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3742 | MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3743 | int ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3744 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3745 | if (width != cm->width || height != cm->height) { |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 3746 | // There has been a change in the encoded frame size |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3747 | av1_set_size_literal(cpi, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3748 | set_mv_search_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3749 | } |
| 3750 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 3751 | #if !CONFIG_XIPHRC |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3752 | if (cpi->oxcf.pass == 2) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3753 | av1_set_target_rate(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3754 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 3755 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3756 | |
| 3757 | alloc_frame_mvs(cm, cm->new_fb_idx); |
| 3758 | |
| 3759 | // Reset the frame pointers to the current frame size. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3760 | 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] | 3761 | cm->subsampling_x, cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3762 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3763 | cm->use_highbitdepth, |
| 3764 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 3765 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, |
| 3766 | NULL, NULL)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3767 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3768 | "Failed to allocate frame buffer"); |
| 3769 | |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3770 | #if CONFIG_LOOP_RESTORATION |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame^] | 3771 | set_restoration_tilesize( |
| 3772 | #if CONFIG_FRAME_SUPERRES |
| 3773 | cm->superres_upscaled_width, cm->superres_upscaled_height, |
| 3774 | #else |
| 3775 | cm->width, cm->height, |
| 3776 | #endif // CONFIG_FRAME_SUPERRES |
| 3777 | cm->rst_info); |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3778 | for (int i = 0; i < MAX_MB_PLANE; ++i) |
| 3779 | cm->rst_info[i].frame_restoration_type = RESTORE_NONE; |
| 3780 | av1_alloc_restoration_buffers(cm); |
| 3781 | for (int i = 0; i < MAX_MB_PLANE; ++i) { |
| 3782 | cpi->rst_search[i].restoration_tilesize = |
| 3783 | cm->rst_info[i].restoration_tilesize; |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame^] | 3784 | av1_alloc_restoration_struct(cm, &cpi->rst_search[i], |
| 3785 | #if CONFIG_FRAME_SUPERRES |
| 3786 | cm->superres_upscaled_width, |
| 3787 | cm->superres_upscaled_height); |
| 3788 | #else |
| 3789 | cm->width, cm->height); |
| 3790 | #endif // CONFIG_FRAME_SUPERRES |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 3791 | } |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame^] | 3792 | #endif // CONFIG_LOOP_RESTORATION |
| 3793 | alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3794 | init_motion_estimation(cpi); |
| 3795 | |
| 3796 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3797 | RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; |
| 3798 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 3799 | |
| 3800 | ref_buf->idx = buf_idx; |
| 3801 | |
| 3802 | if (buf_idx != INVALID_IDX) { |
| 3803 | YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf; |
| 3804 | ref_buf->buf = buf; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3805 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3806 | av1_setup_scale_factors_for_frame( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3807 | &ref_buf->sf, buf->y_crop_width, buf->y_crop_height, cm->width, |
| 3808 | cm->height, (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0); |
| 3809 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3810 | av1_setup_scale_factors_for_frame(&ref_buf->sf, buf->y_crop_width, |
| 3811 | buf->y_crop_height, cm->width, |
| 3812 | cm->height); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 3813 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3814 | if (av1_is_scaled(&ref_buf->sf)) aom_extend_frame_borders(buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3815 | } else { |
| 3816 | ref_buf->buf = NULL; |
| 3817 | } |
| 3818 | } |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 3819 | |
| 3820 | #if CONFIG_VAR_REFS |
| 3821 | // Check duplicate reference frames |
| 3822 | enc_check_valid_ref_frames(cpi); |
| 3823 | #endif // CONFIG_VAR_REFS |
| 3824 | |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 3825 | #if CONFIG_INTRABC |
| 3826 | #if CONFIG_HIGHBITDEPTH |
Sebastien Alaiwan | 1dcb707 | 2017-05-12 11:13:05 +0200 | [diff] [blame] | 3827 | av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height, |
| 3828 | cm->width, cm->height, |
| 3829 | cm->use_highbitdepth); |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 3830 | #else |
| 3831 | av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height, |
| 3832 | cm->width, cm->height); |
| 3833 | #endif // CONFIG_HIGHBITDEPTH |
| 3834 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3835 | |
| 3836 | set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 3837 | } |
| 3838 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3839 | static void setup_frame_size(AV1_COMP *cpi) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3840 | int encode_width; |
| 3841 | int encode_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3842 | |
| 3843 | av1_calculate_next_scaled_size(cpi, &encode_width, &encode_height); |
| 3844 | |
| 3845 | #if CONFIG_FRAME_SUPERRES |
| 3846 | AV1_COMMON *cm = &cpi->common; |
| 3847 | cm->superres_upscaled_width = encode_width; |
| 3848 | cm->superres_upscaled_height = encode_height; |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame^] | 3849 | cpi->common.superres_scale_numerator = |
| 3850 | av1_calculate_next_superres_scale(cpi, encode_width, encode_width); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3851 | av1_calculate_superres_size(cm, &encode_width, &encode_height); |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame^] | 3852 | // printf("Resize/superres %d x %d -> %d x %d\n", encode_width, encode_height, |
| 3853 | // cm->superres_upscaled_width, cm->superres_upscaled_height); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3854 | #endif // CONFIG_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3855 | |
| 3856 | set_frame_size(cpi, encode_width, encode_height); |
| 3857 | } |
| 3858 | |
| 3859 | #if CONFIG_FRAME_SUPERRES |
| 3860 | static void superres_post_encode(AV1_COMP *cpi) { |
| 3861 | AV1_COMMON *cm = &cpi->common; |
| 3862 | |
| 3863 | if (av1_superres_unscaled(cm)) return; |
| 3864 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3865 | av1_superres_upscale(cm, NULL); |
| 3866 | |
| 3867 | // If regular resizing is occurring the source will need to be downscaled to |
| 3868 | // match the upscaled superres resolution. Otherwise the original source is |
| 3869 | // used. |
| 3870 | if (av1_resize_unscaled(cm)) { |
| 3871 | cpi->source = cpi->unscaled_source; |
| 3872 | if (cpi->last_source != NULL) cpi->last_source = cpi->unscaled_last_source; |
| 3873 | } else { |
Fergus Simpson | abd4343 | 2017-06-12 15:54:43 -0700 | [diff] [blame] | 3874 | assert(cpi->unscaled_source->y_crop_width != cm->superres_upscaled_width); |
| 3875 | assert(cpi->unscaled_source->y_crop_height != cm->superres_upscaled_height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3876 | // Do downscale. cm->(width|height) has been updated by av1_superres_upscale |
| 3877 | if (aom_realloc_frame_buffer( |
| 3878 | &cpi->scaled_source, cm->superres_upscaled_width, |
| 3879 | cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y, |
| 3880 | #if CONFIG_HIGHBITDEPTH |
| 3881 | cm->use_highbitdepth, |
| 3882 | #endif // CONFIG_HIGHBITDEPTH |
| 3883 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL)) |
| 3884 | aom_internal_error( |
| 3885 | &cm->error, AOM_CODEC_MEM_ERROR, |
| 3886 | "Failed to reallocate scaled source buffer for superres"); |
| 3887 | assert(cpi->scaled_source.y_crop_width == cm->superres_upscaled_width); |
| 3888 | assert(cpi->scaled_source.y_crop_height == cm->superres_upscaled_height); |
| 3889 | #if CONFIG_HIGHBITDEPTH |
| 3890 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source, |
| 3891 | (int)cm->bit_depth); |
| 3892 | #else |
| 3893 | av1_resize_and_extend_frame(cpi->unscaled_source, &cpi->scaled_source); |
| 3894 | #endif // CONFIG_HIGHBITDEPTH |
| 3895 | cpi->source = &cpi->scaled_source; |
| 3896 | } |
| 3897 | } |
| 3898 | #endif // CONFIG_FRAME_SUPERRES |
| 3899 | |
| 3900 | static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) { |
| 3901 | MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
| 3902 | struct loopfilter *lf = &cm->lf; |
| 3903 | if (is_lossless_requested(&cpi->oxcf)) { |
| 3904 | lf->filter_level = 0; |
| 3905 | } else { |
| 3906 | struct aom_usec_timer timer; |
| 3907 | |
| 3908 | aom_clear_system_state(); |
| 3909 | |
| 3910 | aom_usec_timer_start(&timer); |
| 3911 | |
| 3912 | av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick); |
| 3913 | |
| 3914 | aom_usec_timer_mark(&timer); |
| 3915 | cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer); |
| 3916 | } |
| 3917 | |
| 3918 | if (lf->filter_level > 0) { |
| 3919 | #if CONFIG_VAR_TX || CONFIG_EXT_PARTITION || CONFIG_CB4X4 |
| 3920 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0); |
| 3921 | #else |
| 3922 | if (cpi->num_workers > 1) |
| 3923 | av1_loop_filter_frame_mt(cm->frame_to_show, cm, xd->plane, |
| 3924 | lf->filter_level, 0, 0, cpi->workers, |
| 3925 | cpi->num_workers, &cpi->lf_row_sync); |
| 3926 | else |
| 3927 | av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0); |
| 3928 | #endif |
| 3929 | } |
| 3930 | #if CONFIG_CDEF |
| 3931 | if (is_lossless_requested(&cpi->oxcf)) { |
| 3932 | cm->cdef_bits = 0; |
| 3933 | cm->cdef_strengths[0] = 0; |
| 3934 | cm->nb_cdef_strengths = 1; |
| 3935 | } else { |
| 3936 | // Find cm->dering_level, cm->clpf_strength_u and cm->clpf_strength_v |
| 3937 | av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd, |
| 3938 | cpi->oxcf.speed > 0); |
| 3939 | |
| 3940 | // Apply the filter |
| 3941 | av1_cdef_frame(cm->frame_to_show, cm, xd); |
| 3942 | } |
| 3943 | #endif |
| 3944 | |
| 3945 | #if CONFIG_FRAME_SUPERRES |
| 3946 | superres_post_encode(cpi); |
| 3947 | #endif // CONFIG_FRAME_SUPERRES |
| 3948 | |
| 3949 | #if CONFIG_LOOP_RESTORATION |
| 3950 | av1_pick_filter_restoration(cpi->source, cpi, cpi->sf.lpf_pick); |
| 3951 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 3952 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 3953 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
| 3954 | av1_loop_restoration_frame(cm->frame_to_show, cm, cm->rst_info, 7, 0, NULL); |
| 3955 | } |
| 3956 | #endif // CONFIG_LOOP_RESTORATION |
| 3957 | // TODO(debargha): Fix mv search range on encoder side |
| 3958 | // aom_extend_frame_inner_borders(cm->frame_to_show); |
| 3959 | aom_extend_frame_borders(cm->frame_to_show); |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3960 | } |
| 3961 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3962 | static void reset_use_upsampled_references(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3963 | MV_REFERENCE_FRAME ref_frame; |
| 3964 | |
| 3965 | // reset up-sampled reference buffer structure. |
| 3966 | init_upsampled_ref_frame_bufs(cpi); |
| 3967 | |
| 3968 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3969 | const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi, ref_frame); |
| 3970 | int new_uidx = upsample_ref_frame(cpi, ref); |
| 3971 | |
| 3972 | // Update the up-sampled reference index. |
| 3973 | cpi->upsampled_ref_idx[get_ref_frame_map_idx(cpi, ref_frame)] = new_uidx; |
| 3974 | cpi->upsampled_ref_bufs[new_uidx].ref_count++; |
| 3975 | } |
| 3976 | } |
| 3977 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3978 | static void encode_without_recode_loop(AV1_COMP *cpi) { |
| 3979 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3980 | int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. |
| 3981 | const int use_upsampled_ref = cpi->sf.use_upsampled_references; |
| 3982 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3983 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3984 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 3985 | setup_frame_size(cpi); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3986 | assert(cm->width == cpi->scaled_source.y_crop_width); |
| 3987 | assert(cm->height == cpi->scaled_source.y_crop_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 3988 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3989 | // For 1 pass CBR under dynamic resize mode: use faster scaling for source. |
| 3990 | // Only for 2x2 scaling for now. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3991 | if (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3992 | cpi->oxcf.resize_mode == RESIZE_DYNAMIC && |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3993 | cpi->unscaled_source->y_width == (cm->width << 1) && |
| 3994 | cpi->unscaled_source->y_height == (cm->height << 1)) { |
| 3995 | cpi->source = av1_scale_if_required_fast(cm, cpi->unscaled_source, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3996 | &cpi->scaled_source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3997 | if (cpi->unscaled_last_source != NULL) |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 3998 | cpi->last_source = av1_scale_if_required_fast( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3999 | cm, cpi->unscaled_last_source, &cpi->scaled_last_source); |
| 4000 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4001 | cpi->source = |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4002 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4003 | if (cpi->unscaled_last_source != NULL) |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4004 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4005 | &cpi->scaled_last_source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | if (frame_is_intra_only(cm) == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4009 | av1_scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | set_size_independent_vars(cpi); |
| 4013 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4014 | |
| 4015 | // cpi->sf.use_upsampled_references can be different from frame to frame. |
| 4016 | // Every time when cpi->sf.use_upsampled_references is changed from 0 to 1. |
| 4017 | // The reference frames for this frame have to be up-sampled before encoding. |
Yunqing Wang | fe1e58e | 2016-12-12 14:14:41 -0800 | [diff] [blame] | 4018 | if (!use_upsampled_ref && cpi->sf.use_upsampled_references && |
| 4019 | cm->frame_type != KEY_FRAME) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4020 | reset_use_upsampled_references(cpi); |
| 4021 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4022 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4023 | setup_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4024 | suppress_active_map(cpi); |
hui su | ed5a30f | 2017-04-27 16:02:49 -0700 | [diff] [blame] | 4025 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4026 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4027 | // exclusive. |
| 4028 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4029 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4030 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4031 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4032 | } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4033 | av1_cyclic_refresh_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4034 | } |
| 4035 | apply_active_map(cpi); |
| 4036 | |
| 4037 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4038 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4039 | |
| 4040 | // Update some stats from cyclic refresh, and check if we should not update |
| 4041 | // golden reference, for 1 pass CBR. |
| 4042 | 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] | 4043 | (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == AOM_CBR)) |
| 4044 | av1_cyclic_refresh_check_golden_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4045 | |
| 4046 | // Update the skip mb flag probabilities based on the distribution |
| 4047 | // seen in the last encoder iteration. |
| 4048 | // update_base_skip_probs(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4049 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4050 | } |
| 4051 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4052 | static void encode_with_recode_loop(AV1_COMP *cpi, size_t *size, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4053 | uint8_t *dest) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4054 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4055 | RATE_CONTROL *const rc = &cpi->rc; |
| 4056 | int bottom_index, top_index; |
| 4057 | int loop_count = 0; |
| 4058 | int loop_at_this_size = 0; |
| 4059 | int loop = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4060 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4061 | int overshoot_seen = 0; |
| 4062 | int undershoot_seen = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4063 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4064 | int frame_over_shoot_limit; |
| 4065 | int frame_under_shoot_limit; |
| 4066 | int q = 0, q_low = 0, q_high = 0; |
| 4067 | const int use_upsampled_ref = cpi->sf.use_upsampled_references; |
| 4068 | |
| 4069 | set_size_independent_vars(cpi); |
| 4070 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4071 | do { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4072 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4073 | |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 4074 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4075 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4076 | if (loop_count == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4077 | set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 4078 | |
Thomas Daede | 919bd6a | 2016-10-24 16:31:05 -0700 | [diff] [blame] | 4079 | // cpi->sf.use_upsampled_references can be different from frame to frame. |
| 4080 | // Every time when cpi->sf.use_upsampled_references is changed from 0 to |
| 4081 | // 1. |
| 4082 | // The reference frames for this frame have to be up-sampled before |
| 4083 | // encoding. |
Yunqing Wang | fe1e58e | 2016-12-12 14:14:41 -0800 | [diff] [blame] | 4084 | if (!use_upsampled_ref && cpi->sf.use_upsampled_references && |
| 4085 | cm->frame_type != KEY_FRAME) |
Thomas Daede | 919bd6a | 2016-10-24 16:31:05 -0700 | [diff] [blame] | 4086 | reset_use_upsampled_references(cpi); |
| 4087 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4088 | // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. |
| 4089 | set_mv_search_params(cpi); |
| 4090 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4091 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4092 | // Reset the loop state for new frame size. |
| 4093 | overshoot_seen = 0; |
| 4094 | undershoot_seen = 0; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4095 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4096 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4097 | q_low = bottom_index; |
| 4098 | q_high = top_index; |
| 4099 | |
| 4100 | loop_at_this_size = 0; |
| 4101 | } |
| 4102 | |
| 4103 | // Decide frame size bounds first time through. |
| 4104 | if (loop_count == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4105 | av1_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 4106 | &frame_under_shoot_limit, |
| 4107 | &frame_over_shoot_limit); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4108 | } |
| 4109 | |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4110 | cpi->source = |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 4111 | av1_scale_if_required(cm, cpi->unscaled_source, &cpi->scaled_source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4112 | if (cpi->unscaled_last_source != NULL) |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4113 | cpi->last_source = av1_scale_if_required(cm, cpi->unscaled_last_source, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4114 | &cpi->scaled_last_source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4115 | |
| 4116 | if (frame_is_intra_only(cm) == 0) { |
| 4117 | if (loop_count > 0) { |
| 4118 | release_scaled_references(cpi); |
| 4119 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4120 | av1_scale_references(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4121 | } |
| 4122 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4123 | av1_set_quantizer(cm, q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4124 | |
| 4125 | if (loop_count == 0) setup_frame(cpi); |
| 4126 | |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 4127 | #if CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4128 | // Base q-index may have changed, so we need to assign proper default coef |
| 4129 | // probs before every iteration. |
| 4130 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
| 4131 | int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4132 | av1_default_coef_probs(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4133 | if (cm->frame_type == KEY_FRAME || cm->error_resilient_mode || |
| 4134 | cm->reset_frame_context == RESET_FRAME_CONTEXT_ALL) { |
| 4135 | for (i = 0; i < FRAME_CONTEXTS; ++i) cm->frame_contexts[i] = *cm->fc; |
| 4136 | } else if (cm->reset_frame_context == RESET_FRAME_CONTEXT_CURRENT) { |
| 4137 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
| 4138 | } |
| 4139 | } |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 4140 | #endif // CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4141 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4142 | // Variance adaptive and in frame q adjustment experiments are mutually |
| 4143 | // exclusive. |
| 4144 | if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4145 | av1_vaq_frame_setup(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4146 | } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4147 | av1_setup_in_frame_q_adj(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | // transform / motion compensation build reconstruction frame |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4151 | av1_encode_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4152 | |
| 4153 | // Update the skip mb flag probabilities based on the distribution |
| 4154 | // seen in the last encoder iteration. |
| 4155 | // update_base_skip_probs(cpi); |
| 4156 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4157 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4158 | |
| 4159 | // Dummy pack of the bitstream using up to date stats to get an |
| 4160 | // accurate estimate of output frame size to determine if we need |
| 4161 | // to recode. |
| 4162 | if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
| 4163 | save_coding_context(cpi); |
| 4164 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4165 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4166 | |
| 4167 | rc->projected_frame_size = (int)(*size) << 3; |
| 4168 | restore_coding_context(cpi); |
| 4169 | |
| 4170 | if (frame_over_shoot_limit == 0) frame_over_shoot_limit = 1; |
| 4171 | } |
| 4172 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4173 | if (cpi->oxcf.rc_mode == AOM_Q) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4174 | loop = 0; |
| 4175 | } else { |
| 4176 | if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced && |
| 4177 | (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
| 4178 | int last_q = q; |
| 4179 | int64_t kf_err; |
| 4180 | |
| 4181 | int64_t high_err_target = cpi->ambient_err; |
| 4182 | int64_t low_err_target = cpi->ambient_err >> 1; |
| 4183 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4184 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4185 | if (cm->use_highbitdepth) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4186 | 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] | 4187 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4188 | 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] | 4189 | } |
| 4190 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4191 | 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] | 4192 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4193 | |
| 4194 | // Prevent possible divide by zero error below for perfect KF |
| 4195 | kf_err += !kf_err; |
| 4196 | |
| 4197 | // The key frame is not good enough or we can afford |
| 4198 | // to make it better without undue risk of popping. |
| 4199 | if ((kf_err > high_err_target && |
| 4200 | rc->projected_frame_size <= frame_over_shoot_limit) || |
| 4201 | (kf_err > low_err_target && |
| 4202 | rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 4203 | // Lower q_high |
| 4204 | q_high = q > q_low ? q - 1 : q_low; |
| 4205 | |
| 4206 | // Adjust Q |
| 4207 | q = (int)((q * high_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4208 | q = AOMMIN(q, (q_high + q_low) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4209 | } else if (kf_err < low_err_target && |
| 4210 | rc->projected_frame_size >= frame_under_shoot_limit) { |
| 4211 | // The key frame is much better than the previous frame |
| 4212 | // Raise q_low |
| 4213 | q_low = q < q_high ? q + 1 : q_high; |
| 4214 | |
| 4215 | // Adjust Q |
| 4216 | q = (int)((q * low_err_target) / kf_err); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4217 | q = AOMMIN(q, (q_high + q_low + 1) >> 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4218 | } |
| 4219 | |
| 4220 | // Clamp Q to upper and lower limits: |
| 4221 | q = clamp(q, q_low, q_high); |
| 4222 | |
| 4223 | loop = q != last_q; |
| 4224 | } else if (recode_loop_test(cpi, frame_over_shoot_limit, |
| 4225 | frame_under_shoot_limit, q, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4226 | AOMMAX(q_high, top_index), bottom_index)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4227 | // Is the projected frame size out of range and are we allowed |
| 4228 | // to attempt to recode. |
| 4229 | int last_q = q; |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4230 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4231 | int retries = 0; |
| 4232 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4233 | // Frame size out of permitted range: |
| 4234 | // Update correction factor & compute new Q to try... |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4235 | // Frame is too large |
| 4236 | if (rc->projected_frame_size > rc->this_frame_target) { |
| 4237 | // Special case if the projected size is > the max allowed. |
| 4238 | if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
| 4239 | q_high = rc->worst_quality; |
| 4240 | |
| 4241 | // Raise Qlow as to at least the current value |
| 4242 | q_low = q < q_high ? q + 1 : q_high; |
| 4243 | |
| 4244 | if (undershoot_seen || loop_at_this_size > 1) { |
| 4245 | // Update rate_correction_factor unless |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4246 | av1_rc_update_rate_correction_factors(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4247 | |
| 4248 | q = (q_high + q_low + 1) / 2; |
| 4249 | } else { |
| 4250 | // Update rate_correction_factor unless |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4251 | av1_rc_update_rate_correction_factors(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4252 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4253 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4254 | AOMMAX(q_high, top_index)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4255 | |
| 4256 | while (q < q_low && retries < 10) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4257 | av1_rc_update_rate_correction_factors(cpi); |
| 4258 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4259 | AOMMAX(q_high, top_index)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4260 | retries++; |
| 4261 | } |
| 4262 | } |
| 4263 | |
| 4264 | overshoot_seen = 1; |
| 4265 | } else { |
| 4266 | // Frame is too small |
| 4267 | q_high = q > q_low ? q - 1 : q_low; |
| 4268 | |
| 4269 | if (overshoot_seen || loop_at_this_size > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4270 | av1_rc_update_rate_correction_factors(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4271 | q = (q_high + q_low) / 2; |
| 4272 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4273 | av1_rc_update_rate_correction_factors(cpi); |
| 4274 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4275 | top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4276 | // Special case reset for qlow for constrained quality. |
| 4277 | // This should only trigger where there is very substantial |
| 4278 | // undershoot on a frame and the auto cq level is above |
| 4279 | // the user passsed in value. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4280 | if (cpi->oxcf.rc_mode == AOM_CQ && q < q_low) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4281 | q_low = q; |
| 4282 | } |
| 4283 | |
| 4284 | while (q > q_high && retries < 10) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4285 | av1_rc_update_rate_correction_factors(cpi); |
| 4286 | q = av1_rc_regulate_q(cpi, rc->this_frame_target, bottom_index, |
| 4287 | top_index); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4288 | retries++; |
| 4289 | } |
| 4290 | } |
| 4291 | |
| 4292 | undershoot_seen = 1; |
| 4293 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4294 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4295 | |
| 4296 | // Clamp Q to upper and lower limits: |
| 4297 | q = clamp(q, q_low, q_high); |
| 4298 | |
| 4299 | loop = (q != last_q); |
| 4300 | } else { |
| 4301 | loop = 0; |
| 4302 | } |
| 4303 | } |
| 4304 | |
| 4305 | // Special case for overlay frame. |
| 4306 | if (rc->is_src_frame_alt_ref && |
| 4307 | rc->projected_frame_size < rc->max_frame_bandwidth) |
| 4308 | loop = 0; |
| 4309 | |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 4310 | #if CONFIG_GLOBAL_MOTION |
| 4311 | if (recode_loop_test_global_motion(cpi)) { |
| 4312 | loop = 1; |
| 4313 | } |
| 4314 | #endif // CONFIG_GLOBAL_MOTION |
| 4315 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4316 | if (loop) { |
| 4317 | ++loop_count; |
| 4318 | ++loop_at_this_size; |
| 4319 | |
| 4320 | #if CONFIG_INTERNAL_STATS |
| 4321 | ++cpi->tot_recode_hits; |
| 4322 | #endif |
| 4323 | } |
| 4324 | } while (loop); |
| 4325 | } |
| 4326 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4327 | static int get_ref_frame_flags(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4328 | const int *const map = cpi->common.ref_frame_map; |
| 4329 | |
| 4330 | #if CONFIG_EXT_REFS |
| 4331 | const int last2_is_last = |
| 4332 | map[cpi->lst_fb_idxes[1]] == map[cpi->lst_fb_idxes[0]]; |
| 4333 | const int last3_is_last = |
| 4334 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[0]]; |
| 4335 | const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
Arild Fuldseth (arilfuld) | 78bfc28 | 2017-05-24 12:06:35 +0200 | [diff] [blame] | 4336 | #if CONFIG_ONE_SIDED_COMPOUND |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 4337 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4338 | const int last3_is_last2 = |
| 4339 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]]; |
| 4340 | const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4341 | const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 4342 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4343 | const int bwd_is_last = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4344 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idxes[0]]; |
| 4345 | |
| 4346 | const int last3_is_last2 = |
| 4347 | map[cpi->lst_fb_idxes[2]] == map[cpi->lst_fb_idxes[1]]; |
| 4348 | const int gld_is_last2 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4349 | const int bwd_is_last2 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[1]]; |
| 4350 | |
| 4351 | const int gld_is_last3 = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 4352 | const int bwd_is_last3 = map[cpi->bwd_fb_idx] == map[cpi->lst_fb_idxes[2]]; |
| 4353 | |
| 4354 | const int bwd_is_gld = map[cpi->bwd_fb_idx] == map[cpi->gld_fb_idx]; |
| 4355 | |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 4356 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4357 | const int last2_is_alt = map[cpi->lst_fb_idxes[1]] == map[cpi->alt_fb_idx]; |
| 4358 | const int last3_is_alt = map[cpi->lst_fb_idxes[2]] == map[cpi->alt_fb_idx]; |
| 4359 | const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 4360 | const int bwd_is_alt = map[cpi->bwd_fb_idx] == map[cpi->alt_fb_idx]; |
| 4361 | #else |
| 4362 | const int gld_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx]; |
| 4363 | const int gld_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 4364 | const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx]; |
| 4365 | #endif // CONFIG_EXT_REFS |
| 4366 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4367 | int flags = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4368 | |
| 4369 | #if CONFIG_EXT_REFS |
| 4370 | // Disable the use of BWDREF_FRAME for non-bipredictive frames. |
| 4371 | if (!(cpi->rc.is_bipred_frame || cpi->rc.is_last_bipred_frame || |
| 4372 | (cpi->rc.is_bwd_ref_frame && cpi->num_extra_arfs))) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4373 | flags &= ~AOM_BWD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4374 | #endif // CONFIG_EXT_REFS |
| 4375 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4376 | if (gld_is_last || gld_is_alt) flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4377 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4378 | 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] | 4379 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4380 | if (alt_is_last) flags &= ~AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4381 | |
| 4382 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4383 | if (last2_is_last || last2_is_alt) flags &= ~AOM_LAST2_FLAG; |
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 | 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] | 4386 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4387 | if (gld_is_last2 || gld_is_last3) flags &= ~AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4388 | |
Arild Fuldseth (arilfuld) | 78bfc28 | 2017-05-24 12:06:35 +0200 | [diff] [blame] | 4389 | #if CONFIG_ONE_SIDED_COMPOUND // Changes LL & HL bitstream |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 4390 | /* Allow biprediction between two identical frames (e.g. bwd_is_last = 1) */ |
| 4391 | if (bwd_is_alt && (flags & AOM_BWD_FLAG)) flags &= ~AOM_BWD_FLAG; |
| 4392 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4393 | if ((bwd_is_last || bwd_is_last2 || bwd_is_last3 || bwd_is_gld || |
| 4394 | bwd_is_alt) && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4395 | (flags & AOM_BWD_FLAG)) |
| 4396 | flags &= ~AOM_BWD_FLAG; |
Arild Fuldseth (arilfuld) | 3f42908 | 2017-04-28 15:54:28 +0200 | [diff] [blame] | 4397 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4398 | #endif // CONFIG_EXT_REFS |
| 4399 | |
| 4400 | return flags; |
| 4401 | } |
| 4402 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4403 | static void set_ext_overrides(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4404 | // Overrides the defaults with the externally supplied values with |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4405 | // av1_update_reference() and av1_update_entropy() calls |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4406 | // Note: The overrides are valid only for the next frame passed |
| 4407 | // to encode_frame_to_data_rate() function |
| 4408 | if (cpi->ext_refresh_frame_context_pending) { |
| 4409 | cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context; |
| 4410 | cpi->ext_refresh_frame_context_pending = 0; |
| 4411 | } |
| 4412 | if (cpi->ext_refresh_frame_flags_pending) { |
| 4413 | cpi->refresh_last_frame = cpi->ext_refresh_last_frame; |
| 4414 | cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame; |
| 4415 | cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; |
| 4416 | cpi->ext_refresh_frame_flags_pending = 0; |
| 4417 | } |
| 4418 | } |
| 4419 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4420 | static void set_arf_sign_bias(AV1_COMP *cpi) { |
| 4421 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4422 | int arf_sign_bias; |
| 4423 | #if CONFIG_EXT_REFS |
| 4424 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 4425 | // The arf_sign_bias will be one for internal ARFs' |
| 4426 | arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 4427 | (!cpi->refresh_alt_ref_frame || |
| 4428 | (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)); |
| 4429 | #else |
| 4430 | if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { |
| 4431 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 4432 | arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 4433 | (!cpi->refresh_alt_ref_frame || |
| 4434 | (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)); |
| 4435 | } else { |
| 4436 | arf_sign_bias = |
| 4437 | (cpi->rc.source_alt_ref_active && !cpi->refresh_alt_ref_frame); |
| 4438 | } |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 4439 | #endif // CONFIG_EXT_REFS |
| 4440 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4441 | cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; |
| 4442 | #if CONFIG_EXT_REFS |
| 4443 | cm->ref_frame_sign_bias[BWDREF_FRAME] = cm->ref_frame_sign_bias[ALTREF_FRAME]; |
| 4444 | #endif // CONFIG_EXT_REFS |
| 4445 | } |
| 4446 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4447 | static int setup_interp_filter_search_mask(AV1_COMP *cpi) { |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 4448 | InterpFilter ifilter; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4449 | int ref_total[TOTAL_REFS_PER_FRAME] = { 0 }; |
| 4450 | MV_REFERENCE_FRAME ref; |
| 4451 | int mask = 0; |
| 4452 | int arf_idx = ALTREF_FRAME; |
| 4453 | |
| 4454 | #if CONFIG_EXT_REFS |
| 4455 | // Get which arf used as ALTREF_FRAME |
| 4456 | if (cpi->oxcf.pass == 2) |
| 4457 | arf_idx += cpi->twopass.gf_group.arf_ref_idx[cpi->twopass.gf_group.index]; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 4458 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4459 | |
| 4460 | if (cpi->common.last_frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame) |
| 4461 | return mask; |
| 4462 | |
| 4463 | #if CONFIG_EXT_REFS |
| 4464 | for (ref = LAST_FRAME; ref < ALTREF_FRAME; ++ref) |
| 4465 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) |
| 4466 | ref_total[ref] += cpi->interp_filter_selected[ref][ifilter]; |
| 4467 | |
| 4468 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) |
| 4469 | ref_total[ref] += cpi->interp_filter_selected[arf_idx][ifilter]; |
| 4470 | #else |
| 4471 | for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) |
| 4472 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) |
| 4473 | ref_total[ref] += cpi->interp_filter_selected[ref][ifilter]; |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 4474 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4475 | |
| 4476 | for (ifilter = EIGHTTAP_REGULAR; ifilter < SWITCHABLE_FILTERS; ++ifilter) { |
| 4477 | if ((ref_total[LAST_FRAME] && |
| 4478 | cpi->interp_filter_selected[LAST_FRAME][ifilter] == 0) && |
| 4479 | #if CONFIG_EXT_REFS |
| 4480 | (ref_total[LAST2_FRAME] == 0 || |
| 4481 | cpi->interp_filter_selected[LAST2_FRAME][ifilter] * 50 < |
| 4482 | ref_total[LAST2_FRAME]) && |
| 4483 | (ref_total[LAST3_FRAME] == 0 || |
| 4484 | cpi->interp_filter_selected[LAST3_FRAME][ifilter] * 50 < |
| 4485 | ref_total[LAST3_FRAME]) && |
| 4486 | #endif // CONFIG_EXT_REFS |
| 4487 | (ref_total[GOLDEN_FRAME] == 0 || |
| 4488 | cpi->interp_filter_selected[GOLDEN_FRAME][ifilter] * 50 < |
| 4489 | ref_total[GOLDEN_FRAME]) && |
| 4490 | #if CONFIG_EXT_REFS |
| 4491 | (ref_total[BWDREF_FRAME] == 0 || |
| 4492 | cpi->interp_filter_selected[BWDREF_FRAME][ifilter] * 50 < |
| 4493 | ref_total[BWDREF_FRAME]) && |
| 4494 | #endif // CONFIG_EXT_REFS |
| 4495 | (ref_total[ALTREF_FRAME] == 0 || |
| 4496 | cpi->interp_filter_selected[arf_idx][ifilter] * 50 < |
| 4497 | ref_total[ALTREF_FRAME])) |
| 4498 | mask |= 1 << ifilter; |
| 4499 | } |
| 4500 | return mask; |
| 4501 | } |
| 4502 | |
| 4503 | #define DUMP_RECON_FRAMES 0 |
| 4504 | |
| 4505 | #if DUMP_RECON_FRAMES == 1 |
| 4506 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4507 | static void dump_filtered_recon_frames(AV1_COMP *cpi) { |
| 4508 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4509 | const YV12_BUFFER_CONFIG *recon_buf = cm->frame_to_show; |
| 4510 | int h; |
| 4511 | char file_name[256] = "/tmp/enc_filtered_recon.yuv"; |
| 4512 | FILE *f_recon = NULL; |
| 4513 | |
| 4514 | if (recon_buf == NULL || !cm->show_frame) { |
| 4515 | printf("Frame %d is not ready or no show to dump.\n", |
| 4516 | cm->current_video_frame); |
| 4517 | return; |
| 4518 | } |
| 4519 | |
| 4520 | if (cm->current_video_frame == 0) { |
| 4521 | if ((f_recon = fopen(file_name, "wb")) == NULL) { |
| 4522 | printf("Unable to open file %s to write.\n", file_name); |
| 4523 | return; |
| 4524 | } |
| 4525 | } else { |
| 4526 | if ((f_recon = fopen(file_name, "ab")) == NULL) { |
| 4527 | printf("Unable to open file %s to append.\n", file_name); |
| 4528 | return; |
| 4529 | } |
| 4530 | } |
| 4531 | printf( |
| 4532 | "\nFrame=%5d, encode_update_type[%5d]=%1d, show_existing_frame=%d, " |
| 4533 | "y_stride=%4d, uv_stride=%4d, width=%4d, height=%4d\n", |
| 4534 | cm->current_video_frame, cpi->twopass.gf_group.index, |
| 4535 | cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
| 4536 | cm->show_existing_frame, recon_buf->y_stride, recon_buf->uv_stride, |
| 4537 | cm->width, cm->height); |
| 4538 | |
| 4539 | // --- Y --- |
| 4540 | for (h = 0; h < cm->height; ++h) { |
| 4541 | fwrite(&recon_buf->y_buffer[h * recon_buf->y_stride], 1, cm->width, |
| 4542 | f_recon); |
| 4543 | } |
| 4544 | // --- U --- |
| 4545 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4546 | fwrite(&recon_buf->u_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4547 | f_recon); |
| 4548 | } |
| 4549 | // --- V --- |
| 4550 | for (h = 0; h < (cm->height >> 1); ++h) { |
| 4551 | fwrite(&recon_buf->v_buffer[h * recon_buf->uv_stride], 1, (cm->width >> 1), |
| 4552 | f_recon); |
| 4553 | } |
| 4554 | |
| 4555 | fclose(f_recon); |
| 4556 | } |
| 4557 | #endif // DUMP_RECON_FRAMES |
| 4558 | |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 4559 | #if CONFIG_EC_ADAPT |
| 4560 | |
| 4561 | static void make_update_tile_list_enc(AV1_COMP *cpi, const int tile_rows, |
| 4562 | const int tile_cols, |
| 4563 | FRAME_CONTEXT *ec_ctxs[]) { |
| 4564 | int i; |
| 4565 | for (i = 0; i < tile_rows * tile_cols; ++i) |
| 4566 | ec_ctxs[i] = &cpi->tile_data[i].tctx; |
| 4567 | } |
| 4568 | |
| 4569 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4570 | 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] | 4571 | uint8_t *dest, int skip_adapt, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4572 | unsigned int *frame_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4573 | AV1_COMMON *const cm = &cpi->common; |
| 4574 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4575 | struct segmentation *const seg = &cm->seg; |
| 4576 | TX_SIZE t; |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 4577 | #if CONFIG_EC_ADAPT |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 4578 | FRAME_CONTEXT **tile_ctxs = aom_malloc(cm->tile_rows * cm->tile_cols * |
| 4579 | sizeof(&cpi->tile_data[0].tctx)); |
| 4580 | aom_cdf_prob **cdf_ptrs = |
| 4581 | aom_malloc(cm->tile_rows * cm->tile_cols * |
| 4582 | sizeof(&cpi->tile_data[0].tctx.partition_cdf[0][0])); |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 4583 | #endif |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4584 | #if CONFIG_XIPHRC |
| 4585 | int frame_type; |
| 4586 | int drop_this_frame = 0; |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 4587 | #endif // CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4588 | set_ext_overrides(cpi); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4589 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4590 | |
| 4591 | // Set the arf sign bias for this frame. |
| 4592 | set_arf_sign_bias(cpi); |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 4593 | #if CONFIG_TEMPMV_SIGNALING |
| 4594 | // frame type has been decided outside of this function call |
| 4595 | cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only; |
| 4596 | cm->use_prev_frame_mvs = |
| 4597 | !cpi->oxcf.disable_tempmv && !cm->cur_frame->intra_only; |
| 4598 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4599 | |
| 4600 | #if CONFIG_EXT_REFS |
| 4601 | // NOTE: |
| 4602 | // (1) Move the setup of the ref_frame_flags upfront as it would be |
| 4603 | // determined by the current frame properties; |
| 4604 | // (2) The setup of the ref_frame_flags applies to both show_existing_frame's |
| 4605 | // and the other cases. |
| 4606 | if (cm->current_video_frame > 0) |
| 4607 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 4608 | |
| 4609 | if (cm->show_existing_frame) { |
| 4610 | // NOTE(zoeliu): In BIDIR_PRED, the existing frame to show is the current |
| 4611 | // BWDREF_FRAME in the reference frame buffer. |
| 4612 | cm->frame_type = INTER_FRAME; |
| 4613 | cm->show_frame = 1; |
| 4614 | cpi->frame_flags = *frame_flags; |
| 4615 | |
| 4616 | // In the case of show_existing frame, we will not send fresh flag |
| 4617 | // to decoder. Any change in the reference frame buffer can be done by |
| 4618 | // switching the virtual indices. |
| 4619 | |
| 4620 | cpi->refresh_last_frame = 0; |
| 4621 | cpi->refresh_golden_frame = 0; |
| 4622 | cpi->refresh_bwd_ref_frame = 0; |
| 4623 | cpi->refresh_alt_ref_frame = 0; |
| 4624 | |
| 4625 | cpi->rc.is_bwd_ref_frame = 0; |
| 4626 | cpi->rc.is_last_bipred_frame = 0; |
| 4627 | cpi->rc.is_bipred_frame = 0; |
| 4628 | |
| 4629 | // Build the bitstream |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4630 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4631 | |
| 4632 | // Set up frame to show to get ready for stats collection. |
| 4633 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 4634 | |
| 4635 | #if DUMP_RECON_FRAMES == 1 |
| 4636 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 4637 | dump_filtered_recon_frames(cpi); |
| 4638 | #endif // DUMP_RECON_FRAMES |
| 4639 | |
| 4640 | // Update the LAST_FRAME in the reference frame buffer. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4641 | av1_update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4642 | |
| 4643 | // Update frame flags |
| 4644 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 4645 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 4646 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 4647 | |
| 4648 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 4649 | |
| 4650 | // Update the frame type |
| 4651 | cm->last_frame_type = cm->frame_type; |
| 4652 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4653 | // Since we allocate a spot for the OVERLAY frame in the gf group, we need |
| 4654 | // to do post-encoding update accordingly. |
| 4655 | if (cpi->rc.is_src_frame_alt_ref) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4656 | av1_set_target_rate(cpi); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4657 | #if CONFIG_XIPHRC |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 4658 | 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] | 4659 | drop_this_frame = od_enc_rc_update_state( |
| 4660 | &cpi->od_rc, *size << 3, cpi->refresh_golden_frame, |
| 4661 | cpi->refresh_alt_ref_frame, frame_type, cpi->droppable); |
| 4662 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4663 | av1_rc_postencode_update(cpi, *size); |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4664 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4665 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4666 | |
| 4667 | cm->last_width = cm->width; |
| 4668 | cm->last_height = cm->height; |
| 4669 | |
| 4670 | ++cm->current_video_frame; |
| 4671 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 4672 | #if CONFIG_EC_ADAPT |
| 4673 | aom_free(tile_ctxs); |
| 4674 | aom_free(cdf_ptrs); |
| 4675 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4676 | return; |
| 4677 | } |
| 4678 | #endif // CONFIG_EXT_REFS |
| 4679 | |
| 4680 | // Set default state for segment based loop filter update flags. |
| 4681 | cm->lf.mode_ref_delta_update = 0; |
| 4682 | |
| 4683 | if (cpi->oxcf.pass == 2 && cpi->sf.adaptive_interp_filter_search) |
| 4684 | cpi->sf.interp_filter_search_mask = setup_interp_filter_search_mask(cpi); |
| 4685 | |
| 4686 | // Set various flags etc to special state if it is a key frame. |
| 4687 | if (frame_is_intra_only(cm)) { |
| 4688 | // Reset the loop filter deltas and segmentation map. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4689 | av1_reset_segment_features(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4690 | |
| 4691 | // If segmentation is enabled force a map update for key frames. |
| 4692 | if (seg->enabled) { |
| 4693 | seg->update_map = 1; |
| 4694 | seg->update_data = 1; |
| 4695 | } |
| 4696 | |
| 4697 | // The alternate reference frame cannot be active for a key frame. |
| 4698 | cpi->rc.source_alt_ref_active = 0; |
| 4699 | |
| 4700 | cm->error_resilient_mode = oxcf->error_resilient_mode; |
| 4701 | |
| 4702 | // By default, encoder assumes decoder can use prev_mi. |
| 4703 | if (cm->error_resilient_mode) { |
| 4704 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
| 4705 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 4706 | } else if (cm->intra_only) { |
| 4707 | // Only reset the current context. |
| 4708 | cm->reset_frame_context = RESET_FRAME_CONTEXT_CURRENT; |
| 4709 | } |
| 4710 | } |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 4711 | #if CONFIG_TILE_GROUPS |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4712 | if (cpi->oxcf.mtu == 0) { |
| 4713 | cm->num_tg = cpi->oxcf.num_tile_groups; |
| 4714 | } else { |
Yaowu Xu | 859a527 | 2016-11-10 15:32:21 -0800 | [diff] [blame] | 4715 | // Use a default value for the purposes of weighting costs in probability |
| 4716 | // updates |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 4717 | cm->num_tg = DEFAULT_MAX_NUM_TG; |
| 4718 | } |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 4719 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4720 | |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 4721 | #if CONFIG_EXT_TILE |
| 4722 | cm->tile_encoding_mode = cpi->oxcf.tile_encoding_mode; |
| 4723 | #endif // CONFIG_EXT_TILE |
| 4724 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4725 | #if CONFIG_XIPHRC |
| 4726 | if (drop_this_frame) { |
| 4727 | av1_rc_postencode_update_drop_frame(cpi); |
| 4728 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 4729 | #if CONFIG_EC_ADAPT |
| 4730 | aom_free(tile_ctxs); |
| 4731 | aom_free(cdf_ptrs); |
| 4732 | #endif |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4733 | return; |
| 4734 | } |
| 4735 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4736 | // For 1 pass CBR, check if we are dropping this frame. |
| 4737 | // Never drop on key frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4738 | if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4739 | cm->frame_type != KEY_FRAME) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4740 | if (av1_rc_drop_frame(cpi)) { |
| 4741 | av1_rc_postencode_update_drop_frame(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4742 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 4743 | #if CONFIG_EC_ADAPT |
| 4744 | aom_free(tile_ctxs); |
| 4745 | aom_free(cdf_ptrs); |
| 4746 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4747 | return; |
| 4748 | } |
| 4749 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4750 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4751 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4752 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4753 | |
| 4754 | #if CONFIG_INTERNAL_STATS |
| 4755 | memset(cpi->mode_chosen_counts, 0, |
| 4756 | MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 4757 | #endif |
| 4758 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4759 | #if CONFIG_REFERENCE_BUFFER |
| 4760 | { |
| 4761 | /* Non-normative definition of current_frame_id ("frame counter" with |
| 4762 | * wraparound) */ |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 4763 | const int frame_id_length = FRAME_ID_LENGTH_MINUS7 + 7; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4764 | if (cm->current_frame_id == -1) { |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4765 | int lsb, msb; |
Arild Fuldseth (arilfuld) | bac17c1 | 2016-12-02 12:01:06 +0100 | [diff] [blame] | 4766 | /* quasi-random initialization of current_frame_id for a key frame */ |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4767 | #if CONFIG_HIGHBITDEPTH |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4768 | if (cpi->source->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 4769 | lsb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[0] & 0xff; |
| 4770 | msb = CONVERT_TO_SHORTPTR(cpi->source->y_buffer)[1] & 0xff; |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4771 | } else { |
| 4772 | #endif |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4773 | lsb = cpi->source->y_buffer[0] & 0xff; |
| 4774 | msb = cpi->source->y_buffer[1] & 0xff; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 4775 | #if CONFIG_HIGHBITDEPTH |
David Barker | 49a7656 | 2016-12-07 14:50:21 +0000 | [diff] [blame] | 4776 | } |
Arild Fuldseth (arilfuld) | bac17c1 | 2016-12-02 12:01:06 +0100 | [diff] [blame] | 4777 | #endif |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 4778 | cm->current_frame_id = ((msb << 8) + lsb) % (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4779 | } else { |
| 4780 | cm->current_frame_id = |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 4781 | (cm->current_frame_id + 1 + (1 << frame_id_length)) % |
| 4782 | (1 << frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4783 | } |
| 4784 | } |
| 4785 | #endif |
| 4786 | |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 4787 | #if CONFIG_EXT_DELTA_Q |
| 4788 | cm->delta_q_present_flag = cpi->oxcf.deltaq_mode != NO_DELTA_Q; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 4789 | cm->delta_lf_present_flag = cpi->oxcf.deltaq_mode == DELTA_Q_LF; |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 4790 | #endif |
| 4791 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4792 | if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 4793 | encode_without_recode_loop(cpi); |
| 4794 | } else { |
| 4795 | encode_with_recode_loop(cpi, size, dest); |
| 4796 | } |
| 4797 | |
| 4798 | #ifdef OUTPUT_YUV_SKINMAP |
| 4799 | if (cpi->common.current_video_frame > 1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4800 | av1_compute_skin_map(cpi, yuv_skinmap_file); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4801 | } |
| 4802 | #endif // OUTPUT_YUV_SKINMAP |
| 4803 | |
| 4804 | // Special case code to reduce pulsing when key frames are forced at a |
| 4805 | // fixed interval. Note the reconstruction error if it is the frame before |
| 4806 | // the force key frame |
| 4807 | 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] | 4808 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4809 | if (cm->use_highbitdepth) { |
| 4810 | cpi->ambient_err = |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4811 | aom_highbd_get_y_sse(cpi->source, get_frame_new_buffer(cm)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4812 | } else { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4813 | 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] | 4814 | } |
| 4815 | #else |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 4816 | 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] | 4817 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | // If the encoder forced a KEY_FRAME decision |
| 4821 | if (cm->frame_type == KEY_FRAME) { |
| 4822 | cpi->refresh_last_frame = 1; |
| 4823 | } |
| 4824 | |
| 4825 | cm->frame_to_show = get_frame_new_buffer(cm); |
| 4826 | cm->frame_to_show->color_space = cm->color_space; |
| 4827 | cm->frame_to_show->color_range = cm->color_range; |
| 4828 | cm->frame_to_show->render_width = cm->render_width; |
| 4829 | cm->frame_to_show->render_height = cm->render_height; |
| 4830 | |
| 4831 | #if CONFIG_EXT_REFS |
| 4832 | // TODO(zoeliu): For non-ref frames, loop filtering may need to be turned |
| 4833 | // off. |
| 4834 | #endif // CONFIG_EXT_REFS |
| 4835 | |
| 4836 | // Pick the loop filter level for the frame. |
| 4837 | loopfilter_frame(cpi, cm); |
| 4838 | |
| 4839 | // Build the bitstream |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4840 | av1_pack_bitstream(cpi, dest, size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4841 | |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 4842 | if (skip_adapt) { |
| 4843 | #if CONFIG_EC_ADAPT |
| 4844 | aom_free(tile_ctxs); |
| 4845 | aom_free(cdf_ptrs); |
| 4846 | #endif |
| 4847 | return; |
| 4848 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 4849 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4850 | #if CONFIG_REFERENCE_BUFFER |
| 4851 | { |
| 4852 | int i; |
| 4853 | /* Update reference frame id values based on the value of refresh_mask */ |
| 4854 | for (i = 0; i < REF_FRAMES; i++) { |
| 4855 | if ((cm->refresh_mask >> i) & 1) { |
| 4856 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 4857 | } |
| 4858 | } |
| 4859 | } |
| 4860 | #endif |
| 4861 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4862 | #if DUMP_RECON_FRAMES == 1 |
| 4863 | // NOTE(zoeliu): For debug - Output the filtered reconstructed video. |
| 4864 | if (cm->show_frame) dump_filtered_recon_frames(cpi); |
| 4865 | #endif // DUMP_RECON_FRAMES |
| 4866 | |
| 4867 | if (cm->seg.update_map) update_reference_segmentation_map(cpi); |
| 4868 | |
| 4869 | if (frame_is_intra_only(cm) == 0) { |
| 4870 | release_scaled_references(cpi); |
| 4871 | } |
| 4872 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4873 | av1_update_reference_frames(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4874 | |
Jingning Han | 6de954c | 2016-12-16 09:52:04 -0800 | [diff] [blame] | 4875 | for (t = 0; t < TX_SIZES; t++) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4876 | av1_full_to_model_counts(cpi->td.counts->coef[t], |
| 4877 | cpi->td.rd_counts.coef_counts[t]); |
Debargha Mukherjee | 5802ebe | 2016-12-21 04:17:24 -0800 | [diff] [blame] | 4878 | #if CONFIG_ENTROPY_STATS |
| 4879 | av1_accumulate_frame_counts(&aggregate_fc, &cm->counts); |
| 4880 | #endif // CONFIG_ENTROPY_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4881 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4882 | av1_adapt_coef_probs(cm); |
| 4883 | av1_adapt_intra_frame_probs(cm); |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 4884 | #if CONFIG_EC_ADAPT |
| 4885 | 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] | 4886 | av1_average_tile_coef_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 4887 | cm->tile_rows * cm->tile_cols); |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 4888 | av1_average_tile_intra_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 4889 | cm->tile_rows * cm->tile_cols); |
Yushin Cho | b188ea1 | 2017-03-13 13:45:23 -0700 | [diff] [blame] | 4890 | #if CONFIG_PVQ |
| 4891 | av1_average_tile_pvq_cdfs(cpi->common.fc, tile_ctxs, |
| 4892 | cm->tile_rows * cm->tile_cols); |
| 4893 | #endif // CONFIG_PVQ |
| 4894 | #endif // CONFIG_EC_ADAPT |
hui su | ff0da2b | 2017-03-07 15:51:37 -0800 | [diff] [blame] | 4895 | #if CONFIG_ADAPT_SCAN |
| 4896 | av1_adapt_scan_order(cm); |
| 4897 | #endif // CONFIG_ADAPT_SCAN |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | if (!frame_is_intra_only(cm)) { |
| 4901 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4902 | av1_adapt_inter_frame_probs(cm); |
| 4903 | av1_adapt_mv_probs(cm, cm->allow_high_precision_mv); |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 4904 | #if CONFIG_EC_ADAPT |
| 4905 | av1_average_tile_inter_cdfs(&cpi->common, cpi->common.fc, tile_ctxs, |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 4906 | cdf_ptrs, cm->tile_rows * cm->tile_cols); |
| 4907 | av1_average_tile_mv_cdfs(cpi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 4908 | cm->tile_rows * cm->tile_cols); |
| 4909 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4910 | } |
| 4911 | } |
| 4912 | |
| 4913 | if (cpi->refresh_golden_frame == 1) |
| 4914 | cpi->frame_flags |= FRAMEFLAGS_GOLDEN; |
| 4915 | else |
| 4916 | cpi->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 4917 | |
| 4918 | if (cpi->refresh_alt_ref_frame == 1) |
| 4919 | cpi->frame_flags |= FRAMEFLAGS_ALTREF; |
| 4920 | else |
| 4921 | cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 4922 | |
| 4923 | #if CONFIG_EXT_REFS |
| 4924 | if (cpi->refresh_bwd_ref_frame == 1) |
| 4925 | cpi->frame_flags |= FRAMEFLAGS_BWDREF; |
| 4926 | else |
| 4927 | cpi->frame_flags &= ~FRAMEFLAGS_BWDREF; |
| 4928 | #endif // CONFIG_EXT_REFS |
| 4929 | |
| 4930 | #if !CONFIG_EXT_REFS |
| 4931 | cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
| 4932 | #endif // !CONFIG_EXT_REFS |
| 4933 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4934 | cm->last_frame_type = cm->frame_type; |
| 4935 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4936 | #if CONFIG_XIPHRC |
| 4937 | frame_type = cm->frame_type == KEY_FRAME ? OD_I_FRAME : OD_P_FRAME; |
| 4938 | |
| 4939 | drop_this_frame = |
| 4940 | od_enc_rc_update_state(&cpi->od_rc, *size << 3, cpi->refresh_golden_frame, |
| 4941 | cpi->refresh_alt_ref_frame, frame_type, 0); |
| 4942 | if (drop_this_frame) { |
| 4943 | av1_rc_postencode_update_drop_frame(cpi); |
| 4944 | ++cm->current_video_frame; |
Jingning Han | f6214b9 | 2017-04-12 11:43:37 -0700 | [diff] [blame] | 4945 | #if CONFIG_EC_ADAPT |
| 4946 | aom_free(tile_ctxs); |
| 4947 | aom_free(cdf_ptrs); |
| 4948 | #endif |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 4949 | return; |
| 4950 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 4951 | #else // !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4952 | av1_rc_postencode_update(cpi, *size); |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 4953 | #endif // CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4954 | |
| 4955 | #if 0 |
| 4956 | output_frame_level_debug_stats(cpi); |
| 4957 | #endif |
| 4958 | |
| 4959 | if (cm->frame_type == KEY_FRAME) { |
| 4960 | // Tell the caller that the frame was coded as a key frame |
| 4961 | *frame_flags = cpi->frame_flags | FRAMEFLAGS_KEY; |
| 4962 | } else { |
| 4963 | *frame_flags = cpi->frame_flags & ~FRAMEFLAGS_KEY; |
| 4964 | } |
| 4965 | |
| 4966 | // Clear the one shot update flags for segmentation map and mode/ref loop |
| 4967 | // filter deltas. |
| 4968 | cm->seg.update_map = 0; |
| 4969 | cm->seg.update_data = 0; |
| 4970 | cm->lf.mode_ref_delta_update = 0; |
| 4971 | |
| 4972 | // keep track of the last coded dimensions |
| 4973 | cm->last_width = cm->width; |
| 4974 | cm->last_height = cm->height; |
| 4975 | |
| 4976 | // reset to normal state now that we are done. |
| 4977 | if (!cm->show_existing_frame) cm->last_show_frame = cm->show_frame; |
| 4978 | |
| 4979 | if (cm->show_frame) { |
| 4980 | #if CONFIG_EXT_REFS |
| 4981 | // TODO(zoeliu): We may only swamp mi and prev_mi for those frames that are |
| 4982 | // being used as reference. |
| 4983 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4984 | av1_swap_mi_and_prev_mi(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4985 | // Don't increment frame counters if this was an altref buffer |
| 4986 | // update not a real frame |
| 4987 | ++cm->current_video_frame; |
| 4988 | } |
| 4989 | |
| 4990 | #if CONFIG_EXT_REFS |
| 4991 | // NOTE: Shall not refer to any frame not used as reference. |
| 4992 | if (cm->is_reference_frame) |
| 4993 | #endif // CONFIG_EXT_REFS |
| 4994 | cm->prev_frame = cm->cur_frame; |
Thomas Davies | 493623e | 2017-03-31 16:12:25 +0100 | [diff] [blame] | 4995 | #if CONFIG_EC_ADAPT |
| 4996 | aom_free(tile_ctxs); |
| 4997 | aom_free(cdf_ptrs); |
| 4998 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4999 | } |
| 5000 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5001 | static void Pass0Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5002 | int skip_adapt, unsigned int *frame_flags) { |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5003 | #if CONFIG_XIPHRC |
| 5004 | int64_t ip_count; |
| 5005 | int frame_type, is_golden, is_altref; |
| 5006 | |
| 5007 | /* Not updated during init so update it here */ |
| 5008 | if (cpi->oxcf.rc_mode == AOM_Q) cpi->od_rc.quality = cpi->oxcf.cq_level; |
| 5009 | |
| 5010 | frame_type = od_frame_type(&cpi->od_rc, cpi->od_rc.cur_frame, &is_golden, |
| 5011 | &is_altref, &ip_count); |
| 5012 | |
| 5013 | if (frame_type == OD_I_FRAME) { |
| 5014 | frame_type = KEY_FRAME; |
| 5015 | cpi->frame_flags &= FRAMEFLAGS_KEY; |
| 5016 | } else if (frame_type == OD_P_FRAME) { |
| 5017 | frame_type = INTER_FRAME; |
| 5018 | } |
| 5019 | |
| 5020 | if (is_altref) { |
| 5021 | cpi->refresh_alt_ref_frame = 1; |
| 5022 | cpi->rc.source_alt_ref_active = 1; |
| 5023 | } |
| 5024 | |
| 5025 | cpi->refresh_golden_frame = is_golden; |
| 5026 | cpi->common.frame_type = frame_type; |
| 5027 | if (is_golden) cpi->frame_flags &= FRAMEFLAGS_GOLDEN; |
| 5028 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5029 | if (cpi->oxcf.rc_mode == AOM_CBR) { |
| 5030 | av1_rc_get_one_pass_cbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5031 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5032 | av1_rc_get_one_pass_vbr_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5033 | } |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5034 | #endif |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5035 | encode_frame_to_data_rate(cpi, size, dest, skip_adapt, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5036 | } |
| 5037 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5038 | #if !CONFIG_XIPHRC |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5039 | static void Pass2Encode(AV1_COMP *cpi, size_t *size, uint8_t *dest, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5040 | unsigned int *frame_flags) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5041 | encode_frame_to_data_rate(cpi, size, dest, 0, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5042 | |
| 5043 | #if CONFIG_EXT_REFS |
| 5044 | // Do not do post-encoding update for those frames that do not have a spot in |
| 5045 | // a gf group, but note that an OVERLAY frame always has a spot in a gf group, |
| 5046 | // even when show_existing_frame is used. |
| 5047 | 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] | 5048 | av1_twopass_postencode_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5049 | } |
| 5050 | check_show_existing_frame(cpi); |
| 5051 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5052 | av1_twopass_postencode_update(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5053 | #endif // CONFIG_EXT_REFS |
| 5054 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5055 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5056 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5057 | static void init_ref_frame_bufs(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5058 | int i; |
| 5059 | BufferPool *const pool = cm->buffer_pool; |
| 5060 | cm->new_fb_idx = INVALID_IDX; |
| 5061 | for (i = 0; i < REF_FRAMES; ++i) { |
| 5062 | cm->ref_frame_map[i] = INVALID_IDX; |
| 5063 | pool->frame_bufs[i].ref_count = 0; |
| 5064 | } |
| 5065 | } |
| 5066 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5067 | static void check_initial_width(AV1_COMP *cpi, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5068 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5069 | int use_highbitdepth, |
| 5070 | #endif |
| 5071 | int subsampling_x, int subsampling_y) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5072 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5073 | |
| 5074 | if (!cpi->initial_width || |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5075 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5076 | cm->use_highbitdepth != use_highbitdepth || |
| 5077 | #endif |
| 5078 | cm->subsampling_x != subsampling_x || |
| 5079 | cm->subsampling_y != subsampling_y) { |
| 5080 | cm->subsampling_x = subsampling_x; |
| 5081 | cm->subsampling_y = subsampling_y; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5082 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5083 | cm->use_highbitdepth = use_highbitdepth; |
| 5084 | #endif |
| 5085 | |
| 5086 | alloc_raw_frame_buffers(cpi); |
| 5087 | init_ref_frame_bufs(cm); |
| 5088 | alloc_util_frame_buffers(cpi); |
| 5089 | |
| 5090 | init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 5091 | |
| 5092 | cpi->initial_width = cm->width; |
| 5093 | cpi->initial_height = cm->height; |
| 5094 | cpi->initial_mbs = cm->MBs; |
| 5095 | } |
| 5096 | } |
| 5097 | |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 5098 | 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] | 5099 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 5100 | int64_t end_time) { |
| 5101 | AV1_COMMON *const cm = &cpi->common; |
| 5102 | struct aom_usec_timer timer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5103 | int res = 0; |
| 5104 | const int subsampling_x = sd->subsampling_x; |
| 5105 | const int subsampling_y = sd->subsampling_y; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5106 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5107 | const int use_highbitdepth = (sd->flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
| 5108 | #endif |
| 5109 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5110 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5111 | check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
| 5112 | #else |
| 5113 | check_initial_width(cpi, subsampling_x, subsampling_y); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5114 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5115 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5116 | aom_usec_timer_start(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5117 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5118 | if (av1_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5119 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5120 | use_highbitdepth, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5121 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5122 | frame_flags)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5123 | res = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5124 | aom_usec_timer_mark(&timer); |
| 5125 | cpi->time_receive_data += aom_usec_timer_elapsed(&timer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5126 | |
| 5127 | if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && |
| 5128 | (subsampling_x != 1 || subsampling_y != 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5129 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5130 | "Non-4:2:0 color format requires profile 1 or 3"); |
| 5131 | res = -1; |
| 5132 | } |
| 5133 | if ((cm->profile == PROFILE_1 || cm->profile == PROFILE_3) && |
| 5134 | (subsampling_x == 1 && subsampling_y == 1)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5135 | aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5136 | "4:2:0 color format requires profile 0 or 2"); |
| 5137 | res = -1; |
| 5138 | } |
| 5139 | |
| 5140 | return res; |
| 5141 | } |
| 5142 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5143 | static int frame_is_reference(const AV1_COMP *cpi) { |
| 5144 | const AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5145 | |
| 5146 | return cm->frame_type == KEY_FRAME || cpi->refresh_last_frame || |
| 5147 | cpi->refresh_golden_frame || |
| 5148 | #if CONFIG_EXT_REFS |
| 5149 | cpi->refresh_bwd_ref_frame || |
| 5150 | #endif // CONFIG_EXT_REFS |
| 5151 | cpi->refresh_alt_ref_frame || !cm->error_resilient_mode || |
| 5152 | cm->lf.mode_ref_delta_update || cm->seg.update_map || |
| 5153 | cm->seg.update_data; |
| 5154 | } |
| 5155 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5156 | static void adjust_frame_rate(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5157 | const struct lookahead_entry *source) { |
| 5158 | int64_t this_duration; |
| 5159 | int step = 0; |
| 5160 | |
| 5161 | if (source->ts_start == cpi->first_time_stamp_ever) { |
| 5162 | this_duration = source->ts_end - source->ts_start; |
| 5163 | step = 1; |
| 5164 | } else { |
| 5165 | int64_t last_duration = |
| 5166 | cpi->last_end_time_stamp_seen - cpi->last_time_stamp_seen; |
| 5167 | |
| 5168 | this_duration = source->ts_end - cpi->last_end_time_stamp_seen; |
| 5169 | |
| 5170 | // do a step update if the duration changes by 10% |
| 5171 | if (last_duration) |
| 5172 | step = (int)((this_duration - last_duration) * 10 / last_duration); |
| 5173 | } |
| 5174 | |
| 5175 | if (this_duration) { |
| 5176 | if (step) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5177 | av1_new_framerate(cpi, 10000000.0 / this_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5178 | } else { |
| 5179 | // Average this frame's rate into the last second's average |
| 5180 | // frame rate. If we haven't seen 1 second yet, then average |
| 5181 | // over the whole interval seen. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5182 | const double interval = AOMMIN( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5183 | (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0); |
| 5184 | double avg_duration = 10000000.0 / cpi->framerate; |
| 5185 | avg_duration *= (interval - avg_duration + this_duration); |
| 5186 | avg_duration /= interval; |
| 5187 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5188 | av1_new_framerate(cpi, 10000000.0 / avg_duration); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5189 | } |
| 5190 | } |
| 5191 | cpi->last_time_stamp_seen = source->ts_start; |
| 5192 | cpi->last_end_time_stamp_seen = source->ts_end; |
| 5193 | } |
| 5194 | |
| 5195 | // Returns 0 if this is not an alt ref else the offset of the source frame |
| 5196 | // used as the arf midpoint. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5197 | static int get_arf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5198 | RATE_CONTROL *const rc = &cpi->rc; |
| 5199 | int arf_src_index = 0; |
| 5200 | if (is_altref_enabled(cpi)) { |
| 5201 | if (cpi->oxcf.pass == 2) { |
| 5202 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5203 | if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 5204 | arf_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 5205 | } |
| 5206 | } else if (rc->source_alt_ref_pending) { |
| 5207 | arf_src_index = rc->frames_till_gf_update_due; |
| 5208 | } |
| 5209 | } |
| 5210 | return arf_src_index; |
| 5211 | } |
| 5212 | |
| 5213 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5214 | static int get_brf_src_index(AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5215 | int brf_src_index = 0; |
| 5216 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5217 | |
| 5218 | // TODO(zoeliu): We need to add the check on the -bwd_ref command line setup |
| 5219 | // flag. |
| 5220 | if (gf_group->bidir_pred_enabled[gf_group->index]) { |
| 5221 | if (cpi->oxcf.pass == 2) { |
| 5222 | if (gf_group->update_type[gf_group->index] == BRF_UPDATE) |
| 5223 | brf_src_index = gf_group->brf_src_offset[gf_group->index]; |
| 5224 | } else { |
| 5225 | // TODO(zoeliu): To re-visit the setup for this scenario |
| 5226 | brf_src_index = cpi->rc.bipred_group_interval - 1; |
| 5227 | } |
| 5228 | } |
| 5229 | |
| 5230 | return brf_src_index; |
| 5231 | } |
| 5232 | #endif // CONFIG_EXT_REFS |
| 5233 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5234 | static void check_src_altref(AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5235 | const struct lookahead_entry *source) { |
| 5236 | RATE_CONTROL *const rc = &cpi->rc; |
| 5237 | |
| 5238 | // If pass == 2, the parameters set here will be reset in |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5239 | // av1_rc_get_second_pass_params() |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5240 | |
| 5241 | if (cpi->oxcf.pass == 2) { |
| 5242 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5243 | rc->is_src_frame_alt_ref = |
| 5244 | #if CONFIG_EXT_REFS |
| 5245 | (gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE) || |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 5246 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5247 | (gf_group->update_type[gf_group->index] == OVERLAY_UPDATE); |
| 5248 | } else { |
| 5249 | rc->is_src_frame_alt_ref = |
| 5250 | cpi->alt_ref_source && (source == cpi->alt_ref_source); |
| 5251 | } |
| 5252 | |
| 5253 | if (rc->is_src_frame_alt_ref) { |
| 5254 | // Current frame is an ARF overlay frame. |
| 5255 | cpi->alt_ref_source = NULL; |
| 5256 | |
| 5257 | // Don't refresh the last buffer for an ARF overlay frame. It will |
| 5258 | // become the GF so preserve last as an alternative prediction option. |
| 5259 | cpi->refresh_last_frame = 0; |
| 5260 | } |
| 5261 | } |
| 5262 | |
| 5263 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5264 | extern double av1_get_blockiness(const unsigned char *img1, int img1_pitch, |
| 5265 | const unsigned char *img2, int img2_pitch, |
| 5266 | int width, int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5267 | |
| 5268 | static void adjust_image_stat(double y, double u, double v, double all, |
| 5269 | ImageStat *s) { |
| 5270 | s->stat[Y] += y; |
| 5271 | s->stat[U] += u; |
| 5272 | s->stat[V] += v; |
| 5273 | s->stat[ALL] += all; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5274 | s->worst = AOMMIN(s->worst, all); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5275 | } |
| 5276 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5277 | static void compute_internal_stats(AV1_COMP *cpi) { |
| 5278 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5279 | double samples = 0.0; |
| 5280 | uint32_t in_bit_depth = 8; |
| 5281 | uint32_t bit_depth = 8; |
| 5282 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5283 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5284 | if (cm->use_highbitdepth) { |
| 5285 | in_bit_depth = cpi->oxcf.input_bit_depth; |
| 5286 | bit_depth = cm->bit_depth; |
| 5287 | } |
| 5288 | #endif |
| 5289 | if (cm->show_frame) { |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5290 | const YV12_BUFFER_CONFIG *orig = cpi->source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5291 | const YV12_BUFFER_CONFIG *recon = cpi->common.frame_to_show; |
| 5292 | double y, u, v, frame_all; |
| 5293 | |
| 5294 | cpi->count++; |
| 5295 | if (cpi->b_calculate_psnr) { |
| 5296 | PSNR_STATS psnr; |
| 5297 | double frame_ssim2 = 0.0, weight = 0.0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5298 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5299 | // TODO(yaowu): unify these two versions into one. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5300 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5301 | aom_calc_highbd_psnr(orig, recon, &psnr, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5302 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5303 | aom_calc_psnr(orig, recon, &psnr); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5304 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5305 | |
| 5306 | adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], psnr.psnr[0], |
| 5307 | &cpi->psnr); |
| 5308 | cpi->total_sq_error += psnr.sse[0]; |
| 5309 | cpi->total_samples += psnr.samples[0]; |
| 5310 | samples = psnr.samples[0]; |
| 5311 | // TODO(yaowu): unify these two versions into one. |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5312 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5313 | if (cm->use_highbitdepth) |
| 5314 | frame_ssim2 = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5315 | aom_highbd_calc_ssim(orig, recon, &weight, bit_depth, in_bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5316 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5317 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5318 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5319 | frame_ssim2 = aom_calc_ssim(orig, recon, &weight); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5320 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5321 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5322 | cpi->worst_ssim = AOMMIN(cpi->worst_ssim, frame_ssim2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5323 | cpi->summed_quality += frame_ssim2 * weight; |
| 5324 | cpi->summed_weights += weight; |
| 5325 | |
| 5326 | #if 0 |
| 5327 | { |
| 5328 | FILE *f = fopen("q_used.stt", "a"); |
| 5329 | fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", |
| 5330 | cpi->common.current_video_frame, y2, u2, v2, |
| 5331 | frame_psnr2, frame_ssim2); |
| 5332 | fclose(f); |
| 5333 | } |
| 5334 | #endif |
| 5335 | } |
| 5336 | if (cpi->b_calculate_blockiness) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5337 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5338 | if (!cm->use_highbitdepth) |
| 5339 | #endif |
| 5340 | { |
| 5341 | const double frame_blockiness = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5342 | av1_get_blockiness(orig->y_buffer, orig->y_stride, recon->y_buffer, |
| 5343 | recon->y_stride, orig->y_width, orig->y_height); |
| 5344 | cpi->worst_blockiness = AOMMAX(cpi->worst_blockiness, frame_blockiness); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5345 | cpi->total_blockiness += frame_blockiness; |
| 5346 | } |
| 5347 | |
| 5348 | if (cpi->b_calculate_consistency) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5349 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5350 | if (!cm->use_highbitdepth) |
| 5351 | #endif |
| 5352 | { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5353 | const double this_inconsistency = aom_get_ssim_metrics( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5354 | orig->y_buffer, orig->y_stride, recon->y_buffer, recon->y_stride, |
| 5355 | orig->y_width, orig->y_height, cpi->ssim_vars, &cpi->metrics, 1); |
| 5356 | |
| 5357 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 5358 | const double consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5359 | aom_sse_to_psnr(samples, peak, cpi->total_inconsistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5360 | if (consistency > 0.0) |
| 5361 | cpi->worst_consistency = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5362 | AOMMIN(cpi->worst_consistency, consistency); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5363 | cpi->total_inconsistency += this_inconsistency; |
| 5364 | } |
| 5365 | } |
| 5366 | } |
| 5367 | |
| 5368 | frame_all = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5369 | 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] | 5370 | adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5371 | 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] | 5372 | adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 5373 | } |
| 5374 | } |
| 5375 | #endif // CONFIG_INTERNAL_STATS |
| 5376 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5377 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 5378 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 5379 | int64_t *time_end, int flush) { |
| 5380 | const AV1EncoderConfig *const oxcf = &cpi->oxcf; |
| 5381 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5382 | BufferPool *const pool = cm->buffer_pool; |
| 5383 | RATE_CONTROL *const rc = &cpi->rc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5384 | struct aom_usec_timer cmptimer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5385 | YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
| 5386 | struct lookahead_entry *last_source = NULL; |
| 5387 | struct lookahead_entry *source = NULL; |
| 5388 | int arf_src_index; |
| 5389 | #if CONFIG_EXT_REFS |
| 5390 | int brf_src_index; |
| 5391 | #endif // CONFIG_EXT_REFS |
| 5392 | int i; |
| 5393 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5394 | #if CONFIG_XIPHRC |
| 5395 | cpi->od_rc.end_of_input = flush; |
| 5396 | #endif |
| 5397 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5398 | #if CONFIG_BITSTREAM_DEBUG |
| 5399 | assert(cpi->oxcf.max_threads == 0 && |
| 5400 | "bitstream debug tool does not support multithreading"); |
| 5401 | bitstream_queue_record_write(); |
Angie Chiang | cb9a9eb | 2016-09-01 16:10:50 -0700 | [diff] [blame] | 5402 | 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] | 5403 | #endif |
| 5404 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5405 | aom_usec_timer_start(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5406 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5407 | av1_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5408 | |
| 5409 | // Is multi-arf enabled. |
| 5410 | // Note that at the moment multi_arf is only configured for 2 pass VBR |
| 5411 | if ((oxcf->pass == 2) && (cpi->oxcf.enable_auto_arf > 1)) |
| 5412 | cpi->multi_arf_allowed = 1; |
| 5413 | else |
| 5414 | cpi->multi_arf_allowed = 0; |
| 5415 | |
| 5416 | // Normal defaults |
| 5417 | cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; |
| 5418 | cm->refresh_frame_context = |
| 5419 | (oxcf->error_resilient_mode || oxcf->frame_parallel_decoding_mode) |
| 5420 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 5421 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
| 5422 | |
| 5423 | cpi->refresh_last_frame = 1; |
| 5424 | cpi->refresh_golden_frame = 0; |
| 5425 | #if CONFIG_EXT_REFS |
| 5426 | cpi->refresh_bwd_ref_frame = 0; |
| 5427 | #endif // CONFIG_EXT_REFS |
| 5428 | cpi->refresh_alt_ref_frame = 0; |
| 5429 | |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5430 | #if CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5431 | if (oxcf->pass == 2 && cm->show_existing_frame) { |
| 5432 | // Manage the source buffer and flush out the source frame that has been |
| 5433 | // coded already; Also get prepared for PSNR calculation if needed. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5434 | if ((source = av1_lookahead_pop(cpi->lookahead, flush)) == NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5435 | *size = 0; |
| 5436 | return -1; |
| 5437 | } |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 5438 | cpi->source = &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5439 | // TODO(zoeliu): To track down to determine whether it's needed to adjust |
| 5440 | // the frame rate. |
| 5441 | *time_stamp = source->ts_start; |
| 5442 | *time_end = source->ts_end; |
| 5443 | |
| 5444 | // We need to adjust frame rate for an overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5445 | 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] | 5446 | |
| 5447 | // Find a free buffer for the new frame, releasing the reference previously |
| 5448 | // held. |
| 5449 | if (cm->new_fb_idx != INVALID_IDX) { |
| 5450 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 5451 | } |
| 5452 | cm->new_fb_idx = get_free_fb(cm); |
| 5453 | |
| 5454 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 5455 | |
| 5456 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5457 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5458 | |
| 5459 | // Start with a 0 size frame. |
| 5460 | *size = 0; |
| 5461 | |
| 5462 | // We need to update the gf_group for show_existing overlay frame |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5463 | 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] | 5464 | |
| 5465 | Pass2Encode(cpi, size, dest, frame_flags); |
| 5466 | |
| 5467 | if (cpi->b_calculate_psnr) generate_psnr_packet(cpi); |
| 5468 | |
| 5469 | #if CONFIG_INTERNAL_STATS |
| 5470 | compute_internal_stats(cpi); |
| 5471 | cpi->bytes += (int)(*size); |
| 5472 | #endif // CONFIG_INTERNAL_STATS |
| 5473 | |
| 5474 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5475 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5476 | |
| 5477 | cm->show_existing_frame = 0; |
| 5478 | return 0; |
| 5479 | } |
Zoe Liu | e04abf7 | 2017-04-19 15:37:11 -0700 | [diff] [blame] | 5480 | #endif // CONFIG_EXT_REFS && !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5481 | |
| 5482 | // Should we encode an arf frame. |
| 5483 | arf_src_index = get_arf_src_index(cpi); |
| 5484 | if (arf_src_index) { |
| 5485 | for (i = 0; i <= arf_src_index; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5486 | struct lookahead_entry *e = av1_lookahead_peek(cpi->lookahead, i); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5487 | // Avoid creating an alt-ref if there's a forced keyframe pending. |
| 5488 | if (e == NULL) { |
| 5489 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5490 | } else if (e->flags == AOM_EFLAG_FORCE_KF) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5491 | arf_src_index = 0; |
| 5492 | flush = 1; |
| 5493 | break; |
| 5494 | } |
| 5495 | } |
| 5496 | } |
| 5497 | |
| 5498 | if (arf_src_index) { |
| 5499 | assert(arf_src_index <= rc->frames_to_key); |
| 5500 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5501 | if ((source = av1_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5502 | cpi->alt_ref_source = source; |
| 5503 | |
| 5504 | if (oxcf->arnr_max_frames > 0) { |
| 5505 | // Produce the filtered ARF frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5506 | av1_temporal_filter(cpi, arf_src_index); |
| 5507 | aom_extend_frame_borders(&cpi->alt_ref_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5508 | force_src_buffer = &cpi->alt_ref_buffer; |
| 5509 | } |
| 5510 | |
| 5511 | cm->show_frame = 0; |
| 5512 | cm->intra_only = 0; |
| 5513 | cpi->refresh_alt_ref_frame = 1; |
| 5514 | cpi->refresh_golden_frame = 0; |
| 5515 | cpi->refresh_last_frame = 0; |
| 5516 | rc->is_src_frame_alt_ref = 0; |
| 5517 | } |
| 5518 | rc->source_alt_ref_pending = 0; |
| 5519 | } |
| 5520 | |
| 5521 | #if CONFIG_EXT_REFS |
| 5522 | rc->is_bwd_ref_frame = 0; |
| 5523 | brf_src_index = get_brf_src_index(cpi); |
| 5524 | if (brf_src_index) { |
| 5525 | assert(brf_src_index <= rc->frames_to_key); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5526 | if ((source = av1_lookahead_peek(cpi->lookahead, brf_src_index)) != NULL) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5527 | cm->show_frame = 0; |
| 5528 | cm->intra_only = 0; |
| 5529 | |
| 5530 | cpi->refresh_bwd_ref_frame = 1; |
| 5531 | cpi->refresh_last_frame = 0; |
| 5532 | cpi->refresh_golden_frame = 0; |
| 5533 | cpi->refresh_alt_ref_frame = 0; |
| 5534 | |
| 5535 | rc->is_bwd_ref_frame = 1; |
| 5536 | } |
| 5537 | } |
| 5538 | #endif // CONFIG_EXT_REFS |
| 5539 | |
| 5540 | if (!source) { |
| 5541 | // Get last frame source. |
| 5542 | if (cm->current_video_frame > 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5543 | if ((last_source = av1_lookahead_peek(cpi->lookahead, -1)) == NULL) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5544 | return -1; |
| 5545 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5546 | if (cm->current_video_frame > 0) assert(last_source != NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5547 | // Read in the source frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5548 | source = av1_lookahead_pop(cpi->lookahead, flush); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5549 | |
| 5550 | if (source != NULL) { |
| 5551 | cm->show_frame = 1; |
| 5552 | cm->intra_only = 0; |
| 5553 | |
| 5554 | // Check to see if the frame should be encoded as an arf overlay. |
| 5555 | check_src_altref(cpi, source); |
| 5556 | } |
| 5557 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5558 | if (source) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5559 | cpi->unscaled_source = cpi->source = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5560 | force_src_buffer ? force_src_buffer : &source->img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5561 | cpi->unscaled_last_source = last_source != NULL ? &last_source->img : NULL; |
| 5562 | |
| 5563 | *time_stamp = source->ts_start; |
| 5564 | *time_end = source->ts_end; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5565 | *frame_flags = (source->flags & AOM_EFLAG_FORCE_KF) ? FRAMEFLAGS_KEY : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5566 | |
| 5567 | } else { |
| 5568 | *size = 0; |
| 5569 | if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5570 | #if CONFIG_XIPHRC |
| 5571 | od_enc_rc_2pass_out(&cpi->od_rc, cpi->output_pkt_list, 1); |
| 5572 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5573 | av1_end_first_pass(cpi); /* get last stats packet */ |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5574 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5575 | cpi->twopass.first_pass_done = 1; |
| 5576 | } |
| 5577 | return -1; |
| 5578 | } |
| 5579 | |
| 5580 | if (source->ts_start < cpi->first_time_stamp_ever) { |
| 5581 | cpi->first_time_stamp_ever = source->ts_start; |
| 5582 | cpi->last_end_time_stamp_seen = source->ts_start; |
| 5583 | } |
| 5584 | |
| 5585 | // Clear down mmx registers |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5586 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5587 | |
| 5588 | // adjust frame rates based on timestamps given |
| 5589 | if (cm->show_frame) adjust_frame_rate(cpi, source); |
| 5590 | |
| 5591 | // Find a free buffer for the new frame, releasing the reference previously |
| 5592 | // held. |
| 5593 | if (cm->new_fb_idx != INVALID_IDX) { |
| 5594 | --pool->frame_bufs[cm->new_fb_idx].ref_count; |
| 5595 | } |
| 5596 | cm->new_fb_idx = get_free_fb(cm); |
| 5597 | |
| 5598 | if (cm->new_fb_idx == INVALID_IDX) return -1; |
| 5599 | |
| 5600 | cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; |
| 5601 | |
| 5602 | #if CONFIG_EXT_REFS |
| 5603 | if (oxcf->pass == 2) { |
| 5604 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5605 | cpi->alt_fb_idx = cpi->arf_map[gf_group->arf_ref_idx[gf_group->index]]; |
| 5606 | } |
| 5607 | #else |
| 5608 | if (cpi->multi_arf_allowed) { |
| 5609 | if (cm->frame_type == KEY_FRAME) { |
| 5610 | init_buffer_indices(cpi); |
| 5611 | } else if (oxcf->pass == 2) { |
| 5612 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5613 | cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; |
| 5614 | } |
| 5615 | } |
Zoe Liu | 6cfaff9 | 2016-10-18 17:12:11 -0700 | [diff] [blame] | 5616 | #endif // CONFIG_EXT_REFS |
| 5617 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5618 | // Start with a 0 size frame. |
| 5619 | *size = 0; |
| 5620 | |
| 5621 | cpi->frame_flags = *frame_flags; |
| 5622 | |
| 5623 | if (oxcf->pass == 2) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5624 | #if CONFIG_XIPHRC |
| 5625 | if (od_enc_rc_2pass_in(&cpi->od_rc) < 0) return -1; |
| 5626 | } |
| 5627 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5628 | av1_rc_get_second_pass_params(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5629 | } else if (oxcf->pass == 1) { |
Fergus Simpson | bc18993 | 2017-05-16 17:02:39 -0700 | [diff] [blame] | 5630 | setup_frame_size(cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5631 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5632 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5633 | |
| 5634 | if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) { |
| 5635 | for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) |
| 5636 | cpi->scaled_ref_idx[i] = INVALID_IDX; |
| 5637 | } |
| 5638 | |
| 5639 | #if CONFIG_AOM_QM |
| 5640 | cm->using_qmatrix = cpi->oxcf.using_qm; |
| 5641 | cm->min_qmlevel = cpi->oxcf.qm_minlevel; |
| 5642 | cm->max_qmlevel = cpi->oxcf.qm_maxlevel; |
| 5643 | #endif |
| 5644 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 5645 | #if CONFIG_REFERENCE_BUFFER |
| 5646 | if (*time_stamp == 0) { |
| 5647 | cpi->common.current_frame_id = -1; |
| 5648 | } |
| 5649 | #endif |
| 5650 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5651 | #if CONFIG_XIPHRC |
| 5652 | if (oxcf->pass == 1) { |
| 5653 | size_t tmp; |
| 5654 | if (cpi->od_rc.cur_frame == 0) Pass0Encode(cpi, &tmp, dest, 1, frame_flags); |
| 5655 | cpi->od_rc.firstpass_quant = cpi->od_rc.target_quantizer; |
| 5656 | Pass0Encode(cpi, &tmp, dest, 0, frame_flags); |
| 5657 | od_enc_rc_2pass_out(&cpi->od_rc, cpi->output_pkt_list, 0); |
| 5658 | } else if (oxcf->pass == 2) { |
| 5659 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
| 5660 | } else { |
| 5661 | if (cpi->od_rc.cur_frame == 0) { |
| 5662 | size_t tmp; |
| 5663 | Pass0Encode(cpi, &tmp, dest, 1, frame_flags); |
| 5664 | } |
| 5665 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
| 5666 | } |
| 5667 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5668 | if (oxcf->pass == 1) { |
| 5669 | cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(oxcf); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5670 | av1_first_pass(cpi, source); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5671 | } else if (oxcf->pass == 2) { |
| 5672 | Pass2Encode(cpi, size, dest, frame_flags); |
| 5673 | } else { |
| 5674 | // One pass encode |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5675 | Pass0Encode(cpi, size, dest, 0, frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5676 | } |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 5677 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5678 | |
| 5679 | if (!cm->error_resilient_mode) |
| 5680 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
| 5681 | |
| 5682 | // No frame encoded, or frame was dropped, release scaled references. |
| 5683 | if ((*size == 0) && (frame_is_intra_only(cm) == 0)) { |
| 5684 | release_scaled_references(cpi); |
| 5685 | } |
| 5686 | |
| 5687 | if (*size > 0) { |
| 5688 | cpi->droppable = !frame_is_reference(cpi); |
| 5689 | } |
| 5690 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5691 | aom_usec_timer_mark(&cmptimer); |
| 5692 | cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5693 | |
| 5694 | if (cpi->b_calculate_psnr && oxcf->pass != 1 && cm->show_frame) |
| 5695 | generate_psnr_packet(cpi); |
| 5696 | |
| 5697 | #if CONFIG_INTERNAL_STATS |
| 5698 | if (oxcf->pass != 1) { |
| 5699 | compute_internal_stats(cpi); |
| 5700 | cpi->bytes += (int)(*size); |
| 5701 | } |
| 5702 | #endif // CONFIG_INTERNAL_STATS |
| 5703 | |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 5704 | #if CONFIG_XIPHRC |
| 5705 | cpi->od_rc.cur_frame++; |
| 5706 | #endif |
| 5707 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5708 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5709 | |
| 5710 | return 0; |
| 5711 | } |
| 5712 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5713 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) { |
| 5714 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5715 | if (!cm->show_frame) { |
| 5716 | return -1; |
| 5717 | } else { |
| 5718 | int ret; |
| 5719 | if (cm->frame_to_show) { |
| 5720 | *dest = *cm->frame_to_show; |
| 5721 | dest->y_width = cm->width; |
| 5722 | dest->y_height = cm->height; |
| 5723 | dest->uv_width = cm->width >> cm->subsampling_x; |
| 5724 | dest->uv_height = cm->height >> cm->subsampling_y; |
| 5725 | ret = 0; |
| 5726 | } else { |
| 5727 | ret = -1; |
| 5728 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5729 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5730 | return ret; |
| 5731 | } |
| 5732 | } |
| 5733 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5734 | 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] | 5735 | if (cpi->last_show_frame_buf_idx == INVALID_IDX) return -1; |
| 5736 | |
| 5737 | *frame = |
| 5738 | cpi->common.buffer_pool->frame_bufs[cpi->last_show_frame_buf_idx].buf; |
| 5739 | return 0; |
| 5740 | } |
| 5741 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5742 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 5743 | AOM_SCALING vert_mode) { |
| 5744 | AV1_COMMON *cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5745 | int hr = 0, hs = 0, vr = 0, vs = 0; |
| 5746 | |
| 5747 | if (horiz_mode > ONETWO || vert_mode > ONETWO) return -1; |
| 5748 | |
| 5749 | Scale2Ratio(horiz_mode, &hr, &hs); |
| 5750 | Scale2Ratio(vert_mode, &vr, &vs); |
| 5751 | |
| 5752 | // always go to the next whole number |
| 5753 | cm->width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 5754 | cm->height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
| 5755 | assert(cm->width <= cpi->initial_width); |
| 5756 | assert(cm->height <= cpi->initial_height); |
| 5757 | |
| 5758 | update_frame_size(cpi); |
| 5759 | |
| 5760 | return 0; |
| 5761 | } |
| 5762 | |
Fergus Simpson | 0a30c88 | 2017-05-16 16:54:51 -0700 | [diff] [blame] | 5763 | int av1_set_size_literal(AV1_COMP *cpi, int width, int height) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5764 | AV1_COMMON *cm = &cpi->common; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5765 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5766 | check_initial_width(cpi, cm->use_highbitdepth, 1, 1); |
| 5767 | #else |
| 5768 | check_initial_width(cpi, 1, 1); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 5769 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5770 | |
Fergus Simpson | 0a30c88 | 2017-05-16 16:54:51 -0700 | [diff] [blame] | 5771 | if (width <= 0 || height <= 0) return 1; |
| 5772 | |
| 5773 | cm->width = width; |
| 5774 | if (cm->width > cpi->initial_width) { |
| 5775 | cm->width = cpi->initial_width; |
| 5776 | printf("Warning: Desired width too large, changed to %d\n", cm->width); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
Fergus Simpson | 0a30c88 | 2017-05-16 16:54:51 -0700 | [diff] [blame] | 5779 | cm->height = height; |
| 5780 | if (cm->height > cpi->initial_height) { |
| 5781 | cm->height = cpi->initial_height; |
| 5782 | printf("Warning: Desired height too large, changed to %d\n", cm->height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5783 | } |
Fergus Simpson | 0a30c88 | 2017-05-16 16:54:51 -0700 | [diff] [blame] | 5784 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5785 | assert(cm->width <= cpi->initial_width); |
| 5786 | assert(cm->height <= cpi->initial_height); |
| 5787 | |
| 5788 | update_frame_size(cpi); |
| 5789 | |
| 5790 | return 0; |
| 5791 | } |
| 5792 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5793 | int av1_get_quantizer(AV1_COMP *cpi) { return cpi->common.base_qindex; } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5794 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5795 | 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] | 5796 | if (flags & |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5797 | (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF)) { |
| 5798 | int ref = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5799 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5800 | if (flags & AOM_EFLAG_NO_REF_LAST) { |
| 5801 | ref ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5802 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5803 | ref ^= AOM_LAST2_FLAG; |
| 5804 | ref ^= AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5805 | #endif // CONFIG_EXT_REFS |
| 5806 | } |
| 5807 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5808 | if (flags & AOM_EFLAG_NO_REF_GF) ref ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5809 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5810 | if (flags & AOM_EFLAG_NO_REF_ARF) ref ^= AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5811 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5812 | av1_use_as_reference(cpi, ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5813 | } |
| 5814 | |
| 5815 | if (flags & |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5816 | (AOM_EFLAG_NO_UPD_LAST | AOM_EFLAG_NO_UPD_GF | AOM_EFLAG_NO_UPD_ARF | |
| 5817 | AOM_EFLAG_FORCE_GF | AOM_EFLAG_FORCE_ARF)) { |
| 5818 | int upd = AOM_REFFRAME_ALL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5819 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5820 | if (flags & AOM_EFLAG_NO_UPD_LAST) { |
| 5821 | upd ^= AOM_LAST_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5822 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5823 | upd ^= AOM_LAST2_FLAG; |
| 5824 | upd ^= AOM_LAST3_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5825 | #endif // CONFIG_EXT_REFS |
| 5826 | } |
| 5827 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5828 | if (flags & AOM_EFLAG_NO_UPD_GF) upd ^= AOM_GOLD_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5829 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5830 | if (flags & AOM_EFLAG_NO_UPD_ARF) upd ^= AOM_ALT_FLAG; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5831 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5832 | av1_update_reference(cpi, upd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5833 | } |
| 5834 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5835 | if (flags & AOM_EFLAG_NO_UPD_ENTROPY) { |
| 5836 | av1_update_entropy(cpi, 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5837 | } |
| 5838 | } |